<commit_before>/*
 * Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
 * @author tags. See the copyright.txt file in the distribution for a full
 * listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This software is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this software; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
 * site: http://www.fsf.org.
 */
package org.zanata.feature.document;

import java.io.File;

import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.BasicAcceptanceTest;
import org.zanata.feature.DetailedTest;
import org.zanata.page.projectversion.VersionLanguagesPage;
import org.zanata.page.projectversion.versionsettings.VersionDocumentsTab;
import org.zanata.util.CleanDocumentStorageRule;
import org.zanata.util.NoScreenshot;
import org.zanata.util.SampleProjectRule;
import org.zanata.util.TestFileGenerator;
import org.zanata.workflow.BasicWorkFlow;
import org.zanata.workflow.LoginWorkFlow;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.zanata.util.FunctionalTestHelper.assumeFalse;
import static org.zanata.util.FunctionalTestHelper.assumeTrue;

/**
 * @author <NAME> <a
 *         href="mailto:<EMAIL>"><EMAIL></a>
 */
@Category(DetailedTest.class)
@NoScreenshot
public class UploadTest {

    @Rule
    public SampleProjectRule sampleProjectRule = new SampleProjectRule();

    @Rule
    public CleanDocumentStorageRule documentStorageRule =
            new CleanDocumentStorageRule();

    private TestFileGenerator testFileGenerator = new TestFileGenerator();
    private String documentStorageDirectory;

    @Before
    public void before() {
        new BasicWorkFlow().goToHome().deleteCookiesAndRefresh();
        documentStorageDirectory =
                CleanDocumentStorageRule.getDocumentStoragePath()
                        .concat(File.separator).concat("documents")
                        .concat(File.separator);
        assumeFalse("", new File(documentStorageDirectory).exists());
    }

    @Test
    @Category(BasicAcceptanceTest.class)
    public void uploadedDocumentIsInFilesystem() {
        File originalFile =
                testFileGenerator.generateTestFileWithContent(
                        "uploadedDocumentIsInFilesystem", ".txt",
                        "This is a test file");
        String testFileName = originalFile.getName();
        String successfullyUploaded = "Document " + testFileName + " uploaded.";

        VersionLanguagesPage projectVersionPage =
                new LoginWorkFlow().signIn("admin", "admin").goToProjects()
                        .goToProject("about fedora").gotoVersion("master")
                        .gotoSettingsTab().gotoSettingsDocumentsTab()
                        .pressUploadFileButton()
                        .enterFilePath(originalFile.getAbsolutePath())
                        .submitUpload();

        // We should be able to assume the new file is the only file
        assertThat("There is only one uploaded source file", new File(
                documentStorageDirectory).list().length, Matchers.equalTo(1));

        File newlyCreatedFile =
                new File(
                        documentStorageDirectory,
                        testFileGenerator
                                .getFirstFileNameInDirectory(documentStorageDirectory));

        assertThat("The contents of the file were also uploaded",
                testFileGenerator.getTestFileContent(newlyCreatedFile),
                Matchers.equalTo("This is a test file"));

        assertThat("Document uploaded notification shows",
                projectVersionPage.getNotificationMessage(),
                Matchers.equalTo(successfullyUploaded));
        assertThat("Document shows in table",
                projectVersionPage.sourceDocumentsContains(testFileName));
    }

    @Test
    public void cancelFileUpload() {
        File cancelUploadFile =
                testFileGenerator.generateTestFileWithContent(
                        "cancelFileUpload", ".txt", "Cancel File Upload Test");

        VersionDocumentsTab versionDocumentsTab = new LoginWorkFlow()
                .signIn("admin", "admin")
                .goToProjects()
                .goToProject("about fedora")
                .gotoVersion("master")
                .gotoSettingsTab()
                .gotoSettingsDocumentsTab()
                .pressUploadFileButton()
                .enterFilePath(cancelUploadFile.getAbsolutePath())
                .cancelUpload();

        assertThat("Document does not show in table",<commit_msg>Remove obsolete notification assert on upload file test<commit_after>/*
 * Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
 * @author tags. See the copyright.txt file in the distribution for a full
 * listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This software is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this software; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
 * site: http://www.fsf.org.
 */
package org.zanata.feature.document;

import java.io.File;

import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.BasicAcceptanceTest;
import org.zanata.feature.DetailedTest;
import org.zanata.page.projectversion.VersionLanguagesPage;
import org.zanata.page.projectversion.versionsettings.VersionDocumentsTab;
import org.zanata.util.CleanDocumentStorageRule;
import org.zanata.util.NoScreenshot;
import org.zanata.util.SampleProjectRule;
import org.zanata.util.TestFileGenerator;
import org.zanata.workflow.BasicWorkFlow;
import org.zanata.workflow.LoginWorkFlow;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.zanata.util.FunctionalTestHelper.assumeFalse;
import static org.zanata.util.FunctionalTestHelper.assumeTrue;

/**
 * @author <NAME> <a
 *         href="mailto:<EMAIL>"><EMAIL></a>
 */
@Category(DetailedTest.class)
@NoScreenshot
public class UploadTest {

    @Rule
    public SampleProjectRule sampleProjectRule = new SampleProjectRule();

    @Rule
    public CleanDocumentStorageRule documentStorageRule =
            new CleanDocumentStorageRule();

    private TestFileGenerator testFileGenerator = new TestFileGenerator();
    private String documentStorageDirectory;

    @Before
    public void before() {
        new BasicWorkFlow().goToHome().deleteCookiesAndRefresh();
        documentStorageDirectory =
                CleanDocumentStorageRule.getDocumentStoragePath()
                        .concat(File.separator).concat("documents")
                        .concat(File.separator);
        assumeFalse("", new File(documentStorageDirectory).exists());
    }

    @Test
    @Category(BasicAcceptanceTest.class)
    public void uploadedDocumentIsInFilesystem() {
        File originalFile =
                testFileGenerator.generateTestFileWithContent(
                        "uploadedDocumentIsInFilesystem", ".txt",
                        "This is a test file");
        String testFileName = originalFile.getName();

        VersionLanguagesPage projectVersionPage =
                new LoginWorkFlow().signIn("admin", "admin").goToProjects()
                        .goToProject("about fedora").gotoVersion("master")
                        .gotoSettingsTab().gotoSettingsDocumentsTab()
                        .pressUploadFileButton()
                        .enterFilePath(originalFile.getAbsolutePath())
                        .submitUpload();

        // We should be able to assume the new file is the only file
        assertThat("There is only one uploaded source file", new File(
                documentStorageDirectory).list().length, Matchers.equalTo(1));

        File newlyCreatedFile =
                new File(
                        documentStorageDirectory,
                        testFileGenerator
                                .getFirstFileNameInDirectory(documentStorageDirectory));

        assertThat("The contents of the file were also uploaded",
                testFileGenerator.getTestFileContent(newlyCreatedFile),
                Matchers.equalTo("This is a test file"));
        assertThat("Document shows in table",
                projectVersionPage.sourceDocumentsContains(testFileName));
    }

    @Test
    public void cancelFileUpload() {
        File cancelUploadFile =
                testFileGenerator.generateTestFileWithContent(
                        "cancelFileUpload", ".txt", "Cancel File Upload Test");

        VersionDocumentsTab versionDocumentsTab = new LoginWorkFlow()
                .signIn("admin", "admin")
                .goToProjects()
                .goToProject("about fedora")
                .gotoVersion("master")
                .gotoSettingsTab()
                .gotoSettingsDocumentsTab()
                .pressUploadFileButton()
                .enterFilePath(cancelUploadFile.getAbsolutePath())
                .cancelUpload();

        assertThat("Document does not show in table",
{'fraction_non_alphanumeric': 0.08220753089968381, 'fraction_numerical': 0.0034492670307559644, 'mean_word_length': 2.7439024390243905, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3404769', 'n_tokens_mistral': 2625, 'n_tokens_neox': 2455, 'n_words': 717}