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

Commit

Permalink
Merge pull request #514 from zanata/assertj-projectversion
Browse files Browse the repository at this point in the history
Update project version tests to assertj
  • Loading branch information
Patrick Huang committed Jul 2, 2014
2 parents 8785707 + dc6dbf9 commit b41269c
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 182 deletions.
Expand Up @@ -24,6 +24,7 @@
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.Feature;
import org.zanata.feature.testharness.ZanataTestCase;
import org.zanata.feature.testharness.TestPlan.BasicAcceptanceTest;
import org.zanata.feature.testharness.TestPlan.DetailedTest;
Expand All @@ -34,10 +35,7 @@
import org.zanata.workflow.LoginWorkFlow;
import org.zanata.workflow.ProjectWorkFlow;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Damian Jansen <a
Expand All @@ -49,9 +47,11 @@ public class CreateProjectVersionTest extends ZanataTestCase {
@ClassRule
public static SampleProjectRule sampleProjectRule = new SampleProjectRule();

@Feature(summary = "The administrator can create a project version",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 136517)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
@Category(BasicAcceptanceTest.class)
public void createASimpleProjectVersion() {
public void createASimpleProjectVersion() throws Exception {
VersionLanguagesPage versionLanguagesPage = new LoginWorkFlow()
.signIn("admin", "admin")
.goToProjects()
Expand All @@ -60,26 +60,33 @@ public void createASimpleProjectVersion() {
.inputVersionId("my-aboutfedora-version")
.saveVersion();

assertThat("The version is created with correct ID",
versionLanguagesPage.getProjectVersionName(),
equalTo("my-aboutfedora-version"));
assertThat(versionLanguagesPage.getProjectVersionName())
.isEqualTo("my-aboutfedora-version")
.as("The version is created with correct ID");
}

@Feature(summary = "The user must enter an id to create a project version",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void idFieldMustNotBeEmpty() {
CreateVersionPage createVersionPage =
new LoginWorkFlow().signIn("admin", "admin").goToProjects()
.goToProject("about fedora").clickCreateVersionLink()
.inputVersionId("");
public void idFieldMustNotBeEmpty() throws Exception {
CreateVersionPage createVersionPage = new LoginWorkFlow()
.signIn("admin", "admin")
.goToProjects()
.goToProject("about fedora")
.clickCreateVersionLink()
.inputVersionId("");
createVersionPage.defocus();

assertThat("The empty value is rejected",
createVersionPage.getErrors(),
hasItem("value is required"));
assertThat(createVersionPage.getErrors())
.contains("value is required")
.as("The empty value is rejected");
}

@Feature(summary = "The user must enter an id that starts and ends with " +
"alphanumeric character to create a project version",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void idStartsAndEndsWithAlphanumeric() {
public void idStartsAndEndsWithAlphanumeric() throws Exception {
CreateVersionPage createVersionPage = new LoginWorkFlow()
.signIn("admin", "admin")
.goToProjects()
Expand All @@ -88,63 +95,70 @@ public void idStartsAndEndsWithAlphanumeric() {
.inputVersionId("-A");
createVersionPage.defocus();

assertThat("The input is rejected", createVersionPage.getErrors(),
hasItem(CreateVersionPage.VALIDATION_ERROR));
assertThat(createVersionPage.getErrors())
.contains(CreateVersionPage.VALIDATION_ERROR)
.as("The input is rejected");

createVersionPage = createVersionPage.inputVersionId("B-");
createVersionPage.defocus();
createVersionPage = createVersionPage.waitForNumErrors(1);

assertThat("The input is rejected", createVersionPage.getErrors(),
hasItem(CreateVersionPage.VALIDATION_ERROR));
assertThat(createVersionPage.getErrors())
.contains(CreateVersionPage.VALIDATION_ERROR)
.as("The input is rejected");

createVersionPage = createVersionPage.inputVersionId("_C_");
createVersionPage.defocus();
createVersionPage = createVersionPage.waitForNumErrors(1);

assertThat("The input is rejected", createVersionPage.getErrors(),
hasItem(CreateVersionPage.VALIDATION_ERROR));
assertThat(createVersionPage.getErrors())
.contains(CreateVersionPage.VALIDATION_ERROR)
.as("The input is rejected");

createVersionPage = createVersionPage.inputVersionId("A-B_C");
createVersionPage.defocus();
createVersionPage = createVersionPage.waitForNumErrors(0);

assertThat("The input is acceptable", createVersionPage.getErrors(),
not(hasItem(CreateVersionPage.VALIDATION_ERROR)));
assertThat(createVersionPage.getErrors())
.doesNotContain(CreateVersionPage.VALIDATION_ERROR)
.as("The input is acceptable");
}

@Feature(summary = "The system updates the project version counter " +
"when a project version is created",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void versionCounterIsUpdated() {

public void versionCounterIsUpdated() throws Exception {
String projectName = "version nums";

assertThat("Login as translator",
new LoginWorkFlow().signIn("translator", "translator")
.loggedInAs(),
equalTo("translator"));
assertThat(new LoginWorkFlow()
.signIn("translator", "translator")
.loggedInAs())
.isEqualTo("translator")
.as("Login as translator");

assertThat("The project is created",
new ProjectWorkFlow()
.createNewSimpleProject("version-nums", projectName)
.getProjectName(),
equalTo(projectName));
assertThat(new ProjectWorkFlow()
.createNewSimpleProject("version-nums", projectName)
.getProjectName())
.isEqualTo(projectName)
.as("The project is created");

ProjectVersionsPage projectVersionsPage = new ProjectWorkFlow()
.createNewProjectVersion(projectName, "alpha")
.clickProjectLink(projectName);
projectVersionsPage.waitForDisplayedVersions(1);

assertThat("The version count is 1",
projectVersionsPage.getNumberOfDisplayedVersions(),
equalTo(1));
assertThat(projectVersionsPage.getNumberOfDisplayedVersions())
.isEqualTo(1)
.as("The version count is 1");

projectVersionsPage = new ProjectWorkFlow()
.createNewProjectVersion("version nums", "bravo")
.clickProjectLink(projectName);
projectVersionsPage.waitForDisplayedVersions(2);

assertThat("The version count is 2",
projectVersionsPage.getNumberOfDisplayedVersions(),
equalTo(2));
assertThat(projectVersionsPage.getNumberOfDisplayedVersions())
.isEqualTo(2)
.as("The version count is 2");
}
}
Expand Up @@ -24,6 +24,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.Feature;
import org.zanata.feature.testharness.ZanataTestCase;
import org.zanata.feature.testharness.TestPlan.DetailedTest;
import org.zanata.page.projectversion.versionsettings.VersionLanguagesTab;
Expand All @@ -33,11 +34,7 @@

import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Damian Jansen
Expand All @@ -49,12 +46,16 @@ public class EditVersionLanguagesTest extends ZanataTestCase {
@Rule
public SampleProjectRule sampleProjectRule = new SampleProjectRule();

@Feature(summary = "The maintainer can override the available languages " +
"for a project version",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void changeVersionLanguages() {

assertThat("Admin user has logged in",
new LoginWorkFlow().signIn("admin", "admin").loggedInAs(),
equalTo("admin"));
public void changeVersionLanguages() throws Exception {
assertThat(new LoginWorkFlow()
.signIn("admin", "admin")
.loggedInAs())
.isEqualTo("admin")
.as("Admin user has logged in");

VersionLanguagesTab versionLanguagesTab = new ProjectWorkFlow()
.createNewSimpleProject("langoverride", "langoverride")
Expand All @@ -69,28 +70,25 @@ public void changeVersionLanguages() {
List<String> enabledLocaleList = versionLanguagesTab
.getEnabledLocaleList();

assertThat("The enabled list contains three languages",
enabledLocaleList,
contains("French[fr]", "Hindi[hi]", "Polish[pl]"));
assertThat(enabledLocaleList)
.contains("French[fr]", "Hindi[hi]", "Polish[pl]")
.as("The enabled list contains three languages");

assertThat("The enabled list does not contain " +
"'English (United States)[en-US]'",
enabledLocaleList,
not(hasItem("English (United States)[en-US]")));
assertThat(enabledLocaleList)
.doesNotContain("English (United States)[en-US]")
.as("The enabled list does not contain " +
"'English (United States)[en-US]'");

versionLanguagesTab = versionLanguagesTab.removeLocale("pl");
versionLanguagesTab.waitForLanguagesNotContains(
"English (United States)[en-US]");
versionLanguagesTab.waitForLanguagesNotContains("Polish[pl]");
enabledLocaleList = versionLanguagesTab.getEnabledLocaleList();

assertThat("The enabled list does not contain 'US English'",
enabledLocaleList,
not(hasItem("English (United States)[en-US]")));

assertThat("The enabled list does not contain 'Polish'",
enabledLocaleList,
not(hasItem("Polish[pl]")));
assertThat(enabledLocaleList)
.doesNotContain("English (United States)[en-US]")
.doesNotContain("Polish[pl]")
.as("The enabled list does not contain 'US English' or Polish");

versionLanguagesTab = versionLanguagesTab
.gotoSettingsTab()
Expand All @@ -102,10 +100,10 @@ public void changeVersionLanguages() {
"English (United States)[en-US]");
enabledLocaleList = versionLanguagesTab.getEnabledLocaleList();

assertThat("Three languages are available to translate",
enabledLocaleList,
contains("English (United States)[en-US]",
assertThat(enabledLocaleList)
.contains("English (United States)[en-US]",
"French[fr]",
"Hindi[hi]"));
"Hindi[hi]")
.as("Three languages are available to translate");
}
}

0 comments on commit b41269c

Please sign in to comment.