From 23615ebeb190ee4be761a375982ed056b53304cd Mon Sep 17 00:00:00 2001 From: Damian Jansen Date: Tue, 3 Sep 2013 10:53:03 +1000 Subject: [PATCH] Translation Memory functional tests Tests: create, delete, import, clear, cancel clear/delete/delete after clear. Update to data sql script as some tables have changed. --- .../java/org/zanata/page/AbstractPage.java | 21 +- .../administration/AdministrationPage.java | 8 + .../TranslationMemoryEditPage.java | 81 +++++ .../administration/TranslationMemoryPage.java | 203 ++++++++++++ .../java/org/zanata/util/WebElementUtil.java | 15 +- .../workflow/TranslationMemoryWorkFlow.java | 49 +++ .../AdministrationTestSuite.java | 3 +- .../EditTranslationMemoryTest.java | 304 ++++++++++++++++++ .../org/zanata/feature/zanata_with_data.sql | 8 +- zanata-war/src/main/webapp/tm/home.xhtml | 2 +- 10 files changed, 683 insertions(+), 11 deletions(-) create mode 100644 functional-test/src/main/java/org/zanata/page/administration/TranslationMemoryEditPage.java create mode 100644 functional-test/src/main/java/org/zanata/page/administration/TranslationMemoryPage.java create mode 100644 functional-test/src/main/java/org/zanata/workflow/TranslationMemoryWorkFlow.java create mode 100644 functional-test/src/test/java/org/zanata/feature/administration/EditTranslationMemoryTest.java diff --git a/functional-test/src/main/java/org/zanata/page/AbstractPage.java b/functional-test/src/main/java/org/zanata/page/AbstractPage.java index 9c7bf0b8b5..ac2506f2dc 100644 --- a/functional-test/src/main/java/org/zanata/page/AbstractPage.java +++ b/functional-test/src/main/java/org/zanata/page/AbstractPage.java @@ -24,10 +24,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Predicate; import lombok.extern.slf4j.Slf4j; -import org.openqa.selenium.By; -import org.openqa.selenium.Cookie; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; +import org.openqa.selenium.*; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; import org.openqa.selenium.support.ui.FluentWait; @@ -143,6 +140,22 @@ public WebElement apply(WebDriver driver) } } + public Alert switchToAlert() + { + return waitForTenSec().until(new Function() { + @Override + public Alert apply(WebDriver driver) { + try { + return getDriver().switchTo().alert(); + } + catch (NoAlertPresentException noAlertPresent) + { + return null; + } + } + }); + } + protected

P refreshPageUntil(P currentPage, Predicate predicate) { waitForTenSec().until(predicate); diff --git a/functional-test/src/main/java/org/zanata/page/administration/AdministrationPage.java b/functional-test/src/main/java/org/zanata/page/administration/AdministrationPage.java index 3715b476f0..51b8cfd5ec 100644 --- a/functional-test/src/main/java/org/zanata/page/administration/AdministrationPage.java +++ b/functional-test/src/main/java/org/zanata/page/administration/AdministrationPage.java @@ -30,6 +30,8 @@ public class AdministrationPage extends BasePage private final By MANAGE_USER_LINK = By.id("Admin_Manage_users_home"); + private final By MANAGE_TM_LINK = By.id("Translation_Memory_home"); + public AdministrationPage(WebDriver driver) { super(driver); @@ -46,4 +48,10 @@ public ManageUserPage goToManageUserPage() clickLinkAfterAnimation(MANAGE_USER_LINK); return new ManageUserPage(getDriver()); } + + public TranslationMemoryPage goToTranslationMemoryPage() + { + clickLinkAfterAnimation(MANAGE_TM_LINK); + return new TranslationMemoryPage(getDriver()); + } } diff --git a/functional-test/src/main/java/org/zanata/page/administration/TranslationMemoryEditPage.java b/functional-test/src/main/java/org/zanata/page/administration/TranslationMemoryEditPage.java new file mode 100644 index 0000000000..d761885ef9 --- /dev/null +++ b/functional-test/src/main/java/org/zanata/page/administration/TranslationMemoryEditPage.java @@ -0,0 +1,81 @@ +/* + * 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.page.administration; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.zanata.page.BasePage; + +/** + * @author Damian Jansen djansen@redhat.com + */ +public class TranslationMemoryEditPage extends BasePage +{ + + @FindBy(id = "tmForm:slugField:slug") + private WebElement idField; + + @FindBy(id = "tmForm:descriptionField:description") + private WebElement descriptionField; + + @FindBy(id = "tmForm:save") + private WebElement saveButton; + + @FindBy(id = "tmForm:cancel") + private WebElement cancelButton; + + public TranslationMemoryEditPage(WebDriver driver) + { + super(driver); + } + + public TranslationMemoryEditPage enterMemoryID(String id) + { + idField.sendKeys(id); + return new TranslationMemoryEditPage(getDriver()); + } + + public TranslationMemoryEditPage enterMemoryDescription(String description) + { + descriptionField.sendKeys(description); + return new TranslationMemoryEditPage(getDriver()); + } + + public TranslationMemoryPage saveTM() + { + saveButton.click(); + return new TranslationMemoryPage(getDriver()); + } + + public TranslationMemoryEditPage clickSaveAndExpectFailure() + { + saveButton.click(); + return new TranslationMemoryEditPage(getDriver()); + } + + public TranslationMemoryPage cancelTM() + { + cancelButton.click(); + return new TranslationMemoryPage(getDriver()); + } + +} diff --git a/functional-test/src/main/java/org/zanata/page/administration/TranslationMemoryPage.java b/functional-test/src/main/java/org/zanata/page/administration/TranslationMemoryPage.java new file mode 100644 index 0000000000..d7d393a50c --- /dev/null +++ b/functional-test/src/main/java/org/zanata/page/administration/TranslationMemoryPage.java @@ -0,0 +1,203 @@ +/* + * 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.page.administration; + +import com.google.common.base.Function; +import com.google.common.base.Optional; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import org.openqa.selenium.*; +import org.openqa.selenium.support.FindBy; +import org.zanata.page.BasePage; +import org.zanata.util.TableRow; +import org.zanata.util.WebElementUtil; + +import java.util.List; + +/** + * @author Damian Jansen djansen@redhat.com + */ +public class TranslationMemoryPage extends BasePage +{ + private static final int ID_COLUMN = 0; + private static final int DESCRIPTION_COLUMN = 1; + private static final int ENTRIES_COLUMN = 2; + private static final int IMPORT_COLUMN = 4; + private static final int EXPORT_COLUMN = 5; + private static final int ACTIONS_COLUMN = 6; + + @FindBy(id = "createTmLink") + private WebElement createTmLink; + + @FindBy(id = "main_content:form:tmTable") + private WebElement tmList; + + private By tmListBy = By.id("main_content:form:tmTable"); + + public TranslationMemoryPage(WebDriver driver) + { + super(driver); + } + + public TranslationMemoryEditPage clickCreateNew() + { + createTmLink.click(); + return new TranslationMemoryEditPage(getDriver()); + } + + public TranslationMemoryPage clickImport(String tmName) + { + WebElement importButton = findRowByTMName(tmName) + .getCells() + .get(IMPORT_COLUMN) + .findElement(By.tagName("a")); + importButton.click(); + return new TranslationMemoryPage(getDriver()); + } + + public TranslationMemoryPage enterImportFileName(String importFileName) + { + getDriver().findElement(By.name("uploadedFile")).sendKeys(importFileName); + return new TranslationMemoryPage(getDriver()); + } + + public TranslationMemoryPage clickUploadButtonAndAcknowledge() + { + getDriver().findElement(By.name("uploadBtn")).click(); + switchToAlert().accept(); + return new TranslationMemoryPage(getDriver()); + } + + public Alert expectFailedUpload() + { + getDriver().findElement(By.name("uploadBtn")).click(); + return switchToAlert(); + } + + public TranslationMemoryPage clickClearTMAndAccept(String tmName) + { + clickTMAction(tmName, 0).accept(); + return new TranslationMemoryPage(getDriver()); + } + + public TranslationMemoryPage clickClearTMAndCancel(String tmName) + { + clickTMAction(tmName, 0).dismiss(); + return new TranslationMemoryPage(getDriver()); + } + + public TranslationMemoryPage clickDeleteTmAndAccept(String tmName) + { + clickTMAction(tmName, 1).accept(); + return new TranslationMemoryPage(getDriver()); + } + + public TranslationMemoryPage clickDeleteTmAndCancel(String tmName) + { + clickTMAction(tmName, 1).dismiss(); + return new TranslationMemoryPage(getDriver()); + } + + public TranslationMemoryPage dismissError() + { + switchToAlert().accept(); + return new TranslationMemoryPage(getDriver()); + } + + public List getListedTranslationMemorys() + { + return WebElementUtil.getColumnContents(getDriver(), tmListBy, ID_COLUMN); + } + + public String getDescription(String tmName) + { + return findRowByTMName(tmName) + .getCells() + .get(DESCRIPTION_COLUMN) + .getText(); + } + + public String getNumberOfEntries(String tmName) + { + return findRowByTMName(tmName) + .getCells() + .get(ENTRIES_COLUMN) + .getText(); + } + + public String waitForExpectedNumberOfEntries(final String tmName, final String expected) + { + return waitForTenSec().until(new Function() { + @Override + public String apply(WebDriver driver) { + return expected.equals(getNumberOfEntries(tmName)) ? getNumberOfEntries(tmName) : null; + } + }); + } + + public boolean canDelete(String tmName) + { + return findRowByTMName(tmName) + .getCells() + .get(ACTIONS_COLUMN) + .findElements(By.tagName("input")) + .get(1) + .isEnabled(); + } + + /* + * Get a row from the TM table that corresponds with tmName + */ + private TableRow findRowByTMName(final String tmName) + { + TableRow matchedRow = waitForTenSec().until(new Function() + { + @Override + public TableRow apply(WebDriver driver) + { + List tableRows = WebElementUtil.getTableRows(getDriver(), tmList); + Optional matchedRow = Iterables.tryFind(tableRows, new Predicate() { + @Override + public boolean apply(TableRow input) { + List cellContents = input.getCellContents(); + String localeCell = cellContents.get(ID_COLUMN).trim(); + return localeCell.equalsIgnoreCase(tmName); + } + }); + + // Keep looking for the TM entry until timeout + return matchedRow.isPresent() ? matchedRow.get() : null; + } + }); + return matchedRow; + } + + private Alert clickTMAction(String tmName, int position) + { + findRowByTMName(tmName) + .getCells() + .get(ACTIONS_COLUMN) + .findElements(By.tagName("input")) + .get(position) + .click(); + return switchToAlert(); + } +} diff --git a/functional-test/src/main/java/org/zanata/util/WebElementUtil.java b/functional-test/src/main/java/org/zanata/util/WebElementUtil.java index 25caea6240..de8c75d330 100644 --- a/functional-test/src/main/java/org/zanata/util/WebElementUtil.java +++ b/functional-test/src/main/java/org/zanata/util/WebElementUtil.java @@ -20,8 +20,7 @@ */ package org.zanata.util; -import java.util.Collection; -import java.util.List; +import java.util.*; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; @@ -81,7 +80,6 @@ public static List getTableRows(WebDriver driver, final WebElement tab @Override public List apply(WebDriver webDriver) { - List rows = table.findElements(By.xpath(".//tbody[1]/tr")); return ImmutableList.copyOf(Lists.transform(rows, WebElementTableRowFunction.FUNCTION)); } @@ -112,6 +110,16 @@ public static FluentWait waitForTenSeconds(WebDriver webDriver) public static List getColumnContents(WebDriver driver, final By by, final int columnIndex) { + try + { + driver.findElement(by); + } + catch(NoSuchElementException noElement) + { + // Some pages don't show a table, if there's no items to show + return Collections.emptyList(); + } + return waitForTenSeconds(driver).until(new Function>() { @Override @@ -132,6 +140,7 @@ public String apply(TableRow from) })); } }); + } public static List> getTwoDimensionList(WebDriver driver, final By by) diff --git a/functional-test/src/main/java/org/zanata/workflow/TranslationMemoryWorkFlow.java b/functional-test/src/main/java/org/zanata/workflow/TranslationMemoryWorkFlow.java new file mode 100644 index 0000000000..67262410aa --- /dev/null +++ b/functional-test/src/main/java/org/zanata/workflow/TranslationMemoryWorkFlow.java @@ -0,0 +1,49 @@ +/* + * 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.workflow; + +import org.zanata.page.administration.TranslationMemoryPage; + +/** + * @author Damian Jansen djansen@redhat.com + */ +public class TranslationMemoryWorkFlow extends AbstractWebWorkFlow +{ + public TranslationMemoryWorkFlow() + { + } + + public TranslationMemoryPage createTranslationMemory(String name) + { + return createTranslationMemory(name, ""); + } + + public TranslationMemoryPage createTranslationMemory(String name, String description) + { + return goToHome() + .goToAdministration() + .goToTranslationMemoryPage() + .clickCreateNew() + .enterMemoryID(name) + .enterMemoryDescription(description) + .saveTM(); + } +} diff --git a/functional-test/src/test/java/org/zanata/feature/administration/AdministrationTestSuite.java b/functional-test/src/test/java/org/zanata/feature/administration/AdministrationTestSuite.java index fb236d280c..09e3fa5503 100644 --- a/functional-test/src/test/java/org/zanata/feature/administration/AdministrationTestSuite.java +++ b/functional-test/src/test/java/org/zanata/feature/administration/AdministrationTestSuite.java @@ -31,7 +31,8 @@ ManageUsersTest.class, ManageUsersFullTest.class, AdministrationTest.class, - EditHomePageTest.class + EditHomePageTest.class, + EditTranslationMemoryTest.class }) public class AdministrationTestSuite { diff --git a/functional-test/src/test/java/org/zanata/feature/administration/EditTranslationMemoryTest.java b/functional-test/src/test/java/org/zanata/feature/administration/EditTranslationMemoryTest.java new file mode 100644 index 0000000000..7f3ed26de7 --- /dev/null +++ b/functional-test/src/test/java/org/zanata/feature/administration/EditTranslationMemoryTest.java @@ -0,0 +1,304 @@ +/* + * 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.administration; + +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.openqa.selenium.Alert; +import org.zanata.feature.DetailedTest; +import org.zanata.page.administration.TranslationMemoryEditPage; +import org.zanata.page.administration.TranslationMemoryPage; +import org.zanata.util.ResetDatabaseRule; +import org.zanata.util.TestFileGenerator; +import org.zanata.workflow.BasicWorkFlow; +import org.zanata.workflow.LoginWorkFlow; +import org.zanata.workflow.TranslationMemoryWorkFlow; + +import java.io.File; + +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * @author Damian Jansen djansen@redhat.com + */ +@Category(DetailedTest.class) +public class EditTranslationMemoryTest +{ + @ClassRule + public static ResetDatabaseRule resetDatabaseRule = new ResetDatabaseRule(); + TestFileGenerator testFileGenerator = new TestFileGenerator(); + + @Before + public void before() + { + assertThat("Admin is logged in", new LoginWorkFlow().signIn("admin", "admin").loggedInAs(), + Matchers.equalTo("admin")); + } + + @Test + public void createNewTranslationMemory() + { + String newTMId = "newtmtest"; + String tmDescription = "A new test TM"; + + TranslationMemoryPage translationMemoryPage = new TranslationMemoryWorkFlow() + .createTranslationMemory(newTMId, tmDescription); + + assertThat("The success message is displayed", + translationMemoryPage.getNotificationMessage(), Matchers.equalTo("Successfully created")); + + assertThat("The new Translation Memory is listed", + translationMemoryPage.getListedTranslationMemorys(), Matchers.hasItem(newTMId)); + + assertThat("The description is displayed correctly", + translationMemoryPage.getDescription(newTMId), Matchers.equalTo(tmDescription)); + } + + @Test + public void abortCreate() + { + String abortName = "aborttmtest"; + String abortDescription = "abort tm description"; + + TranslationMemoryPage translationMemoryPage = new BasicWorkFlow() + .goToHome() + .goToAdministration() + .goToTranslationMemoryPage() + .clickCreateNew() + .enterMemoryID(abortName) + .enterMemoryDescription(abortDescription) + .cancelTM(); + + assertThat("The Translation Memory was not created", + translationMemoryPage.getListedTranslationMemorys(), + Matchers.not(Matchers.hasItem(abortName))); + } + + @Test + public void translationMemoryIdsAreUnique() + { + String nonUniqueTMId = "doubletmtest"; + String nameError = "This Id is not available"; + + TranslationMemoryPage translationMemoryPage = new TranslationMemoryWorkFlow() + .createTranslationMemory(nonUniqueTMId); + + assertThat("The new Translation Memory is listed", + translationMemoryPage.getListedTranslationMemorys(), Matchers.hasItem(nonUniqueTMId)); + + TranslationMemoryEditPage translationMemoryEditPage = translationMemoryPage + .clickCreateNew() + .enterMemoryID(nonUniqueTMId) + .enterMemoryDescription("Meh"); + + assertThat("The Id Is Not Available error is displayed", + translationMemoryEditPage.waitForErrors(), Matchers.hasItem(nameError)); + + translationMemoryEditPage = translationMemoryEditPage.clickSaveAndExpectFailure(); + + translationMemoryEditPage.assertNoCriticalErrors(); // RHBZ-1010771 + + assertThat("The Id Is Not Available error is displayed", + translationMemoryEditPage.waitForErrors(), Matchers.hasItem(nameError)); + } + + @Test + public void importTranslationMemory() + { + String importTMId = "importmtest"; + File importFile = testFileGenerator.generateTestFileWithContent("importtmtest", ".tmx", + "\n" + + "\n" + + "\n" + + "

\n" + + " \n" + + "Fedora is an open, innovative, forward looking operating system and platform, based on Linux, that is always free for anyone to use, modify and distribute, now and forever. It is developed by a large community of people who strive to provide and maintain the very best in free, open source software and standards. Fedora is part of the Fedora Project, sponsored by Red Hat, Inc.This is a TM Import Test\n" + + " \n" + + ""); + + TranslationMemoryPage translationMemoryPage = new TranslationMemoryWorkFlow() + .createTranslationMemory(importTMId) + .clickImport(importTMId) + .enterImportFileName(importFile.getAbsolutePath()) + .clickUploadButtonAndAcknowledge(); + + assertThat("The Translation Memory has one entry", + translationMemoryPage.getNumberOfEntries(importTMId), Matchers.equalTo("1")); + + } + + @Test + public void rejectEmptyTranslation() + { + String rejectTMId = "rejectemptytmtest"; + + TranslationMemoryPage translationMemoryPage = new TranslationMemoryWorkFlow() + .createTranslationMemory(rejectTMId) + .clickImport(rejectTMId); + Alert uploadError = translationMemoryPage.expectFailedUpload(); + + assertThat("Error is displayed", uploadError.getText(), + Matchers.startsWith("There was an error uploading the file")); + + translationMemoryPage = translationMemoryPage.dismissError(); + + assertThat("No change is recorded", translationMemoryPage.getNumberOfEntries(rejectTMId), + Matchers.equalTo("0")); + } + + @Test + public void deleteTranslationMemory() + { + String deleteTMId = "deletetmtest"; + + TranslationMemoryPage translationMemoryPage = new TranslationMemoryWorkFlow() + .createTranslationMemory(deleteTMId); + + assertThat("The new Translation Memory is listed", + translationMemoryPage.getListedTranslationMemorys(), Matchers.hasItem(deleteTMId)); + + translationMemoryPage = translationMemoryPage + .clickDeleteTmAndAccept(deleteTMId); + + assertThat("The new Translation Memory is no longer listed", + translationMemoryPage.getListedTranslationMemorys(), + Matchers.not(Matchers.hasItem(deleteTMId))); + } + + @Test + public void dontDeleteTranslationMemory() + { + String dontDeleteTMId = "dontdeletetmtest"; + + TranslationMemoryPage translationMemoryPage = new TranslationMemoryWorkFlow() + .createTranslationMemory(dontDeleteTMId); + + assertThat("The new Translation Memory is listed", + translationMemoryPage.getListedTranslationMemorys(), Matchers.hasItem(dontDeleteTMId)); + + translationMemoryPage = translationMemoryPage + .clickDeleteTmAndCancel(dontDeleteTMId); + + assertThat("The new Translation Memory is still listed", + translationMemoryPage.getListedTranslationMemorys(), Matchers.hasItem(dontDeleteTMId)); + } + + @Test + public void clearTranslationMemory() + { + String clearTMId = "cleartmtest"; + File importFile = testFileGenerator.generateTestFileWithContent("cleartmtest", ".tmx", + "\n" + + "\n" + + "\n" + + "
\n" + + " \n" + + "Fedora is an open, innovative, forward looking operating system and platform, based on Linux, that is always free for anyone to use, modify and distribute, now and forever. It is developed by a large community of people who strive to provide and maintain the very best in free, open source software and standards. Fedora is part of the Fedora Project, sponsored by Red Hat, Inc.This is a TM Import Test\n" + + " \n" + + ""); + + TranslationMemoryPage translationMemoryPage = new TranslationMemoryWorkFlow() + .createTranslationMemory(clearTMId) + .clickImport(clearTMId) + .enterImportFileName(importFile.getAbsolutePath()) + .clickUploadButtonAndAcknowledge(); + + assertThat("The TM has one item", translationMemoryPage.getNumberOfEntries(clearTMId), + Matchers.equalTo("1")); + + translationMemoryPage = translationMemoryPage.clickClearTMAndAccept(clearTMId); + + assertThat("The translation memory entries is empty", + translationMemoryPage.waitForExpectedNumberOfEntries(clearTMId, "0"), + Matchers.equalTo("0")); + } + + @Test + public void dontClearTranslationMemory() + { + String clearTMId = "dontcleartmtest"; + File importFile = testFileGenerator.generateTestFileWithContent("cleartmtest", ".tmx", + "\n" + + "\n" + + "\n" + + "
\n" + + " \n" + + "Fedora is an open, innovative, forward looking operating system and platform, based on Linux, that is always free for anyone to use, modify and distribute, now and forever. It is developed by a large community of people who strive to provide and maintain the very best in free, open source software and standards. Fedora is part of the Fedora Project, sponsored by Red Hat, Inc.This is a TM Import Test\n" + + " \n" + + ""); + + TranslationMemoryPage translationMemoryPage = new TranslationMemoryWorkFlow() + .createTranslationMemory(clearTMId) + .clickImport(clearTMId) + .enterImportFileName(importFile.getAbsolutePath()) + .clickUploadButtonAndAcknowledge(); + + assertThat("The TM has one item", translationMemoryPage.getNumberOfEntries(clearTMId), + Matchers.equalTo("1")); + + translationMemoryPage = translationMemoryPage + .clickClearTMAndCancel(clearTMId); + + assertThat("The translation memory entries count is the same", + translationMemoryPage.getNumberOfEntries(clearTMId), + Matchers.equalTo("1")); + } + + @Test + public void mustClearBeforeDelete() + { + String forceClear = "forcecleartodelete"; + File importFile = testFileGenerator.generateTestFileWithContent("cleartmtest", ".tmx", + "\n" + + "\n" + + "\n" + + "
\n" + + " \n" + + "Fedora is an open, innovative, forward looking operating system and platform, based on Linux, that is always free for anyone to use, modify and distribute, now and forever. It is developed by a large community of people who strive to provide and maintain the very best in free, open source software and standards. Fedora is part of the Fedora Project, sponsored by Red Hat, Inc.This is a TM Import Test\n" + + " \n" + + ""); + + TranslationMemoryPage translationMemoryPage = new TranslationMemoryWorkFlow() + .createTranslationMemory(forceClear) + .clickImport(forceClear) + .enterImportFileName(importFile.getAbsolutePath()) + .clickUploadButtonAndAcknowledge(); + + assertThat("The TM has one item", translationMemoryPage.getNumberOfEntries(forceClear), + Matchers.equalTo("1")); + + assertThat("The item cannot yet be deleted", !translationMemoryPage.canDelete(forceClear)); + + translationMemoryPage = translationMemoryPage.clickClearTMAndAccept(forceClear); + translationMemoryPage.waitForExpectedNumberOfEntries(forceClear, "0"); + + assertThat("The item can be deleted", translationMemoryPage.canDelete(forceClear)); + + translationMemoryPage = translationMemoryPage.clickDeleteTmAndAccept(forceClear); + + assertThat("The item is deleted", translationMemoryPage.getListedTranslationMemorys(), + Matchers.not(Matchers.hasItem(forceClear))); + } + +} diff --git a/functional-test/src/test/resources/concordion/org/zanata/feature/zanata_with_data.sql b/functional-test/src/test/resources/concordion/org/zanata/feature/zanata_with_data.sql index 32d4bf2d0b..9ece59dbf0 100644 --- a/functional-test/src/test/resources/concordion/org/zanata/feature/zanata_with_data.sql +++ b/functional-test/src/test/resources/concordion/org/zanata/feature/zanata_with_data.sql @@ -954,6 +954,8 @@ CREATE CACHED TABLE PUBLIC.TRANSMEMORYUNIT( TM_ID BIGINT NOT NULL, UNIQUE_ID VARCHAR(255) NOT NULL, POSITION INT, + METADATA_TYPE VARCHAR(75), + METADATA LONGTEXT, ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_A46D148E_26EC_4ECC_80ED_A60EAB754F21) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_A46D148E_26EC_4ECC_80ED_A60EAB754F21, CREATIONDATE TIMESTAMP NOT NULL, LASTCHANGED TIMESTAMP NOT NULL, @@ -967,6 +969,8 @@ CREATE CACHED TABLE PUBLIC.TRANSMEMORYUNITVARIANT( TAGGED_SEGMENT LONGTEXT NOT NULL, PLAIN_TEXT_SEGMENT LONGTEXT NOT NULL, PLAIN_TEXT_SEGMENT_HASH CHAR(32) NOT NULL, + METADATA_TYPE VARCHAR(75), + METADATA LONGTEXT, ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_EC9A15B9_9726_4429_84EA_52688B8B7F91) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_EC9A15B9_9726_4429_84EA_52688B8B7F91, CREATIONDATE TIMESTAMP NOT NULL, LASTCHANGED TIMESTAMP NOT NULL, @@ -976,10 +980,10 @@ ALTER TABLE PUBLIC.TRANSMEMORYUNITVARIANT ADD CONSTRAINT PUBLIC.CONSTRAINT_B3 PR -- 0 +/- SELECT COUNT(*) FROM PUBLIC.TRANSMEMORYUNITVARIANT; CREATE CACHED TABLE PUBLIC.TRANSMEMORY_METADATA( TRANS_MEMORY_ID BIGINT NOT NULL, - METADATA_KEY VARCHAR(75) NOT NULL, + METADATA_TYPE VARCHAR(75) NOT NULL, METADATA LONGTEXT ); -ALTER TABLE PUBLIC.TRANSMEMORY_METADATA ADD CONSTRAINT PUBLIC.PK_TRANSMEMORY_METADATA PRIMARY KEY(TRANS_MEMORY_ID, METADATA_KEY); +ALTER TABLE PUBLIC.TRANSMEMORY_METADATA ADD CONSTRAINT PUBLIC.PK_TRANSMEMORY_METADATA PRIMARY KEY(TRANS_MEMORY_ID, METADATA_TYPE); -- 0 +/- SELECT COUNT(*) FROM PUBLIC.TRANSMEMORY_METADATA; ALTER TABLE PUBLIC.HDOCUMENTHISTORY ADD CONSTRAINT PUBLIC.CONSTRAINT_42 UNIQUE(DOCUMENT_ID, REVISION); ALTER TABLE PUBLIC.HITERATIONGROUP ADD CONSTRAINT PUBLIC.UKSLUG UNIQUE(SLUG); diff --git a/zanata-war/src/main/webapp/tm/home.xhtml b/zanata-war/src/main/webapp/tm/home.xhtml index f3cd5e27da..fbbe162acd 100644 --- a/zanata-war/src/main/webapp/tm/home.xhtml +++ b/zanata-war/src/main/webapp/tm/home.xhtml @@ -115,7 +115,7 @@ #{translationMemoryAction.processError} - + #{messages['jsf.transmemory.Id']}