Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Add file tests, clean up and simplify
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 1471008
Author: Damian Jansen <djansen@redhat.com>
Date:   Mon Nov 10 12:35:03 2014 +1000

    Move apikey to constant, and html file data to static var

commit 37edef8
Author: Damian Jansen <djansen@redhat.com>
Date:   Thu Sep 4 15:39:20 2014 +1000

    Add file tests, clean up and simplify

    - Test html, idml, dtd, odg/p/s/t File type upload
    - Use ZanataRestCaller rather than manually creating projects, versions
    - Remove unused imports
    - Add a null pointer check on opening files
  • Loading branch information
djansen-redhat committed Nov 10, 2014
1 parent 395a7d5 commit 569e138
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 131 deletions.
1 change: 1 addition & 0 deletions functional-test/pom.xml
Expand Up @@ -43,6 +43,7 @@
<zanata.test.war.name>zanata-test-${project.version}</zanata.test.war.name>
<zanata.instance.url>http://${cargo.host}:${cargo.servlet.port}/${context.path}/</zanata.instance.url>
<zanata.apikey>b6d7044e9ee3b2447c28fb7c50d86d98</zanata.apikey>
<zanata.translatorkey>d83882201764f7d339e97c4b087f0806</zanata.translatorkey>
<zanata.sample.projects.basedir>${project.build.testOutputDirectory}/sample-projects</zanata.sample.projects.basedir>

<webdriver.log.file>${project.build.directory}/browser_console.log</webdriver.log.file>
Expand Down
3 changes: 2 additions & 1 deletion functional-test/src/main/java/org/zanata/util/Constants.java
Expand Up @@ -30,7 +30,8 @@ public enum Constants {
propFile("setup.properties"), zanataInstance("zanata.instance.url"),
projectsLink("Projects"), webDriverType("webdriver.type"), chrome, firefox,
htmlUnit, sampleProjects("zanata.sample.projects.basedir"), zanataApiKey(
"zanata.apikey"), webDriverWait("webdriver.wait");
"zanata.apikey"), zanataTranslatorKey("zanata.translatorkey"),
webDriverWait("webdriver.wait");

public static final int FIFTY_SEC = 50000;
private String value;
Expand Down
Expand Up @@ -238,9 +238,11 @@ private static class ZanataXml {
}

public File openTestFile(String filename) {
URL url = Thread.currentThread().getContextClassLoader()
.getResource(filename);
File testFile = new File(url.getPath());
File testFile;
URL url = Thread.currentThread()
.getContextClassLoader().getResource(filename);
Preconditions.checkNotNull(url, "File %s url is null", filename);
testFile = new File(url.getPath());
Preconditions.checkArgument(testFile.exists(), "%s not found", testFile);
return testFile;
}
Expand Down
Expand Up @@ -33,6 +33,8 @@
import org.zanata.feature.testharness.TestPlan.DetailedTest;
import org.zanata.page.projectversion.VersionLanguagesPage;
import org.zanata.rest.dto.resource.TranslationsResource;
import org.zanata.util.Constants;
import org.zanata.util.PropertiesHolder;
import org.zanata.util.SampleProjectRule;
import org.zanata.util.ZanataRestCaller;
import org.zanata.workflow.BasicWorkFlow;
Expand Down Expand Up @@ -96,7 +98,8 @@ public void pushTransAndCopyTransTest() {
// translator creates the project and become maintainer
ZanataRestCaller restCaller =
new ZanataRestCaller("translator",
"d83882201764f7d339e97c4b087f0806");
PropertiesHolder.getProperty(
Constants.zanataTranslatorKey.value()));
restCaller.createProjectAndVersion("plurals", "master", "podir");
List<String> output =
client.callWithTimeout(projectRootPath,
Expand Down Expand Up @@ -147,9 +150,9 @@ public void pushTransAndCopyTransTest() {
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 136564)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void projectMaintainerPullTest() throws IOException {
ZanataRestCaller restCaller =
new ZanataRestCaller("translator",
"d83882201764f7d339e97c4b087f0806");
ZanataRestCaller restCaller = new ZanataRestCaller("translator",
PropertiesHolder
.getProperty(Constants.zanataTranslatorKey.value()));
File workDir = Files.createTempDir();
String projectSlug = "pull-test";
String iterationSlug = "master";
Expand Down
Expand Up @@ -21,13 +21,15 @@
package org.zanata.feature.document;

import lombok.extern.slf4j.Slf4j;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.experimental.categories.Category;
import org.junit.experimental.theories.DataPoint;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import org.zanata.feature.Feature;
import org.zanata.feature.testharness.TestPlan.BasicAcceptanceTest;
import org.zanata.feature.testharness.TestPlan.DetailedTest;
import org.zanata.feature.testharness.ZanataTestCase;
Expand All @@ -36,6 +38,7 @@
import org.zanata.util.CleanDocumentStorageRule;
import org.zanata.util.SampleProjectRule;
import org.zanata.util.TestFileGenerator;
import org.zanata.util.ZanataRestCaller;
import org.zanata.workflow.LoginWorkFlow;
import org.zanata.workflow.ProjectWorkFlow;

Expand All @@ -50,24 +53,34 @@
@Slf4j
@RunWith(Theories.class)
@Category(DetailedTest.class)
public class DocTypeUploadTest extends ZanataTestCase {
public class FileTypeUploadTest extends ZanataTestCase {

@ClassRule
public static SampleProjectRule sampleProjectRule = new SampleProjectRule();
@Rule
public SampleProjectRule sampleProjectRule = new SampleProjectRule();

@ClassRule
public static CleanDocumentStorageRule documentStorageRule =
new CleanDocumentStorageRule();

@BeforeClass
public static void beforeClass() {
@Before
public void before() {
new ZanataRestCaller().createProjectAndVersion("doctype-test",
"doctype-upload", "File");
new LoginWorkFlow().signIn("admin", "admin");
new ProjectWorkFlow().createNewProjectVersion(
"about fedora", "doctype-upload", "File")
.logout();
}

private static String testString = "Test text 1";
private static String htmlString = "<html><title>"+testString+"</title>"+
"<body/> </html>";
@DataPoint
public static File TXT_FILE = new TestFileGenerator()
.generateTestFileWithContent( "testtxtfile", ".txt", testString);

@DataPoint
public static File DTD_FILE = new TestFileGenerator()
.generateTestFileWithContent(
"testdtdfile", ".dtd",
"<!ENTITY firstField \"" + testString + "\">");

@DataPoint
public static File SRT_FILE = new TestFileGenerator()
Expand Down Expand Up @@ -97,16 +110,46 @@ public static void beforeClass() {
"00:04:35.03,00:04:38.82" +
sep() + testString);

@DataPoint
public static File HTM_FILE = new TestFileGenerator()
.generateTestFileWithContent("testhtmfile", ".htm", htmlString);

@DataPoint
public static File HTML_FILE = new TestFileGenerator()
.generateTestFileWithContent("testhtmlfile", ".html", htmlString);

@DataPoint
public static File IDML_FILE = new TestFileGenerator()
.openTestFile("upload-idml.idml");

@DataPoint
public static File ODT_FILE = new TestFileGenerator()
.openTestFile("upload-odt.odt");

@DataPoint
public static File ODS_FILE = new TestFileGenerator()
.openTestFile("upload-ods.ods");

@DataPoint
public static File ODG_FILE = new TestFileGenerator()
.openTestFile("upload-odg.odg");

@DataPoint
public static File ODP_FILE = new TestFileGenerator()
.openTestFile("upload-odp.odp");

@Theory
@Category(BasicAcceptanceTest.class)
public void uploadFile(File testFile) throws Exception {
@Feature(bugzilla = 980670,
summary = "The administrator can upload raw files for translation",
tcmsTestCaseIds = { 377743 },
tcmsTestPlanIds = { 5316 } )
public void uploadFileTypeDocument(File testFile) throws Exception {
String testFileName = testFile.getName();
log.info("[uploadFile] "+testFileName);

VersionDocumentsPage versionDocumentsPage = new LoginWorkFlow()
.signIn("admin", "admin")
.goToProjects()
.goToProject("about fedora")
VersionDocumentsPage versionDocumentsPage = new ProjectWorkFlow()
.goToProjectByName("doctype-test")
.gotoVersion("doctype-upload")
.gotoSettingsTab()
.gotoSettingsDocumentsTab()
Expand Down
Expand Up @@ -22,8 +22,9 @@

import java.io.File;

import org.junit.BeforeClass;
import org.junit.ClassRule;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.Feature;
Expand All @@ -32,10 +33,12 @@
import org.zanata.page.projectversion.VersionDocumentsPage;
import org.zanata.page.projectversion.versionsettings.VersionDocumentsTab;
import org.zanata.page.webtrans.EditorPage;
import org.zanata.util.Constants;
import org.zanata.util.PropertiesHolder;
import org.zanata.util.SampleProjectRule;
import org.zanata.util.TestFileGenerator;
import org.zanata.util.ZanataRestCaller;
import org.zanata.workflow.LoginWorkFlow;
import org.zanata.page.projects.projectsettings.ProjectPermissionsTab;
import org.zanata.workflow.ProjectWorkFlow;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -47,71 +50,19 @@
@Category(DetailedTest.class)
public class HTMLDocumentTypeTest extends ZanataTestCase {

@ClassRule
public static SampleProjectRule sampleProjectRule = new SampleProjectRule();
@Rule
public SampleProjectRule sampleProjectRule = new SampleProjectRule();

private TestFileGenerator testFileGenerator = new TestFileGenerator();

@BeforeClass
public static void beforeClass() {
ProjectPermissionsTab projectPermissionsTab = new LoginWorkFlow()
.signIn("admin", "admin")
.goToProjects()
.goToProject("about fedora")
.gotoSettingsTab()
.gotoSettingsPermissionsTab()
.enterSearchMaintainer("translator")
.selectSearchMaintainer("translator");
projectPermissionsTab.expectNotification(
"Maintainer \"translator\" has been added to project.");
projectPermissionsTab = projectPermissionsTab.clickRemoveOn("admin");
projectPermissionsTab.expectNotification("Maintainer \"Administrator\" " +
"has been removed from project.");
new ProjectWorkFlow().createNewProjectVersion(
"about fedora", "html-upload", "File")
.logout();
}

@Feature(bugzilla = 980670,
summary = "Administrator can upload a HTML file for translation",
tcmsTestCaseIds = { 377743 },
tcmsTestPlanIds = { 5316 } )
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void uploadHTMLFileAsAdministrator() throws Exception {
File htmlfile = testFileGenerator.generateTestFileWithContent(
"testhtmlfile", ".html",
"<html><title>Test content</title>" +
"<br>This is <b>Bold</b> text</html>");
String testFileName = htmlfile.getName();
VersionDocumentsTab versionDocumentsTab = new LoginWorkFlow()
.signIn("admin", "admin")
.goToProjects()
.goToProject("about fedora")
.gotoVersion("html-upload")
.gotoSettingsTab()
.gotoSettingsDocumentsTab()
.pressUploadFileButton()
.enterFilePath(htmlfile.getAbsolutePath())
.submitUpload()
.clickUploadDone();

VersionDocumentsPage versionDocumentsPage =
versionDocumentsTab.gotoDocumentTab();

assertThat(versionDocumentsPage.
sourceDocumentsContains(htmlfile.getName()))
.as("Document shows in table");

EditorPage editorPage = versionDocumentsPage
.gotoLanguageTab()
.translate("pl", testFileName);

assertThat(editorPage.getMessageSourceAtRowIndex(0))
.isEqualTo("Test content")
.as("The first translation source is correct");
assertThat(editorPage.getMessageSourceAtRowIndex(1))
.isEqualTo("This is <g2>Bold</g2> text")
.as("The second translation source is correct");
@Before
public void before() {
System.out.println(PropertiesHolder
.getProperty(Constants.zanataTranslatorKey.value()));
new ZanataRestCaller("translator", PropertiesHolder.getProperty(
Constants.zanataTranslatorKey.value()))
.createProjectAndVersion("html-project", "html-upload", "file");
new LoginWorkFlow().signIn("translator", "translator");
}

@Feature(bugzilla = 980670,
Expand All @@ -123,13 +74,11 @@ public void uploadHTMLFileAsMaintainer() throws Exception {
File htmlfile = testFileGenerator.generateTestFileWithContent(
"testhtmlfile", ".html",
"<html><title>Test content</title>" +
"<br>This is <b>Bold</b> text</html>"
"<br>This is <b>Bold</b> text</html>"
);
String testFileName = htmlfile.getName();
VersionDocumentsTab versionDocumentsTab = new LoginWorkFlow()
.signIn("translator", "translator")
.goToProjects()
.goToProject("about fedora")
VersionDocumentsTab versionDocumentsTab = new ProjectWorkFlow()
.goToProjectByName("html-project")
.gotoVersion("html-upload")
.gotoSettingsTab()
.gotoSettingsDocumentsTab()
Expand Down
Expand Up @@ -41,7 +41,7 @@

/**
* Covers more detailed testing of the subtitle formats
* @see DocTypeUploadTest
* @see FileTypeUploadTest
* @author Damian Jansen
* <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
Expand Down
Expand Up @@ -70,8 +70,8 @@ public class RateLimitRestAndUITest extends ZanataTestCase {
public AddUsersRule addUsersRule = new AddUsersRule();

private static final String TRANSLATOR = "translator";
private static final String TRANSLATOR_API =
"d83882201764f7d339e97c4b087f0806";
private static final String TRANSLATOR_API = Constants.zanataTranslatorKey
.value();
private String maxConcurrentPathParam = "c/max.concurrent.req.per.apikey";
private String maxActivePathParam = "c/max.active.req.per.apikey";

Expand Down

0 comments on commit 569e138

Please sign in to comment.