This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Uploaded source files testing. Handles success and error case. Exception located in error cases, these tests are expect fail. Added a 'Critical Error' check to BasePage and some hard defaults for the document storage dir. Added an action to delete the stored files on database reset. Slight modification of ids in Source Documents pages.
- Loading branch information
1 parent
5fec7d8
commit 357ce0a
Showing
11 changed files
with
297 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
functional-test/src/main/java/org/zanata/page/projects/ProjectSourceDocumentsPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2010, 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.projects; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Lists; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.zanata.page.BasePage; | ||
import org.zanata.page.webtrans.DocumentsViewPage; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
public class ProjectSourceDocumentsPage extends BasePage | ||
{ | ||
@FindBy(id = "iterationDocumentsForm:data_table:tb") | ||
private WebElement documentTableTBody; | ||
|
||
@FindBy(id = "uploadSidebar:uploadDocumentButton") | ||
private WebElement uploadDocumentButton; | ||
|
||
@FindBy(id = "uploadDocForm:uploadFilename") | ||
private WebElement uploadFilenameInput; | ||
|
||
@FindBy(id = "uploadDocForm:uploadButton") | ||
private WebElement uploadButton; | ||
|
||
@FindBy(id = "uploadDocForm:cancelUploadButton") | ||
private WebElement cancelUploadButton; | ||
|
||
public ProjectSourceDocumentsPage(final WebDriver driver) | ||
{ | ||
super(driver); | ||
} | ||
|
||
public ProjectSourceDocumentsPage pressUploadFileButton() | ||
{ | ||
uploadDocumentButton.click(); | ||
return new ProjectSourceDocumentsPage(getDriver()); | ||
} | ||
|
||
public ProjectSourceDocumentsPage enterFilePath(String filePath) | ||
{ | ||
uploadFilenameInput.sendKeys(filePath); | ||
return new ProjectSourceDocumentsPage(getDriver()); | ||
} | ||
|
||
public ProjectSourceDocumentsPage cancelUpload() | ||
{ | ||
cancelUploadButton.click(); | ||
return new ProjectSourceDocumentsPage(getDriver()); | ||
} | ||
|
||
public ProjectSourceDocumentsPage submitUpload() | ||
{ | ||
uploadButton.click(); | ||
return new ProjectSourceDocumentsPage(getDriver()); | ||
} | ||
|
||
private List<WebElement> getDocumentTableRows() | ||
{ | ||
return documentTableTBody.findElements(By.tagName("tr")); | ||
} | ||
|
||
|
||
public boolean sourceDocumentsContains(String document) | ||
{ | ||
List<WebElement> documentTableRows = getDocumentTableRows(); | ||
for (WebElement tableRow : documentTableRows) | ||
{ | ||
if (tableRow.findElements(By.tagName("td")).get(1).getText().equals(document)) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
functional-test/src/test/java/org/zanata/feature/document/UploadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* 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 org.hamcrest.Matchers; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.zanata.feature.DetailedTest; | ||
import org.zanata.page.projects.ProjectSourceDocumentsPage; | ||
import org.zanata.util.PropertiesHolder; | ||
import org.zanata.util.ResetDatabaseRule; | ||
import org.zanata.workflow.LoginWorkFlow; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
/** | ||
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a> | ||
*/ | ||
@Category(DetailedTest.class) | ||
public class UploadTest | ||
{ | ||
@ClassRule | ||
public static ResetDatabaseRule resetDatabaseRule = new ResetDatabaseRule(ResetDatabaseRule.Config.WithData); | ||
|
||
@Test | ||
public void uploadedDocumentIsInFilesystem() | ||
{ | ||
String successfullyUploaded = "Document file uploadedDocumentIsInFilesystem.txt uploaded."; | ||
String testFileName = "uploadedDocumentIsInFilesystem.txt"; | ||
String filePath = PropertiesHolder.getProperty("zanata.testdata.directory") | ||
.concat(File.separator) | ||
.concat(testFileName); | ||
|
||
assertThat("Data file "+testFileName+" exists", new File(filePath).exists()); | ||
|
||
ProjectSourceDocumentsPage projectSourceDocumentsPage = new LoginWorkFlow().signIn("admin", "admin") | ||
.goToProjects() | ||
.goToProject("about fedora") | ||
.goToVersion("master") | ||
.goToSourceDocuments() | ||
.pressUploadFileButton() | ||
.enterFilePath(filePath) | ||
.submitUpload(); | ||
assertThat("Document uploaded notification shows", | ||
projectSourceDocumentsPage.getNotificationMessage(), Matchers.equalTo(successfullyUploaded)); | ||
assertThat("Document shows in table", projectSourceDocumentsPage.sourceDocumentsContains(testFileName)); | ||
} | ||
|
||
@Test | ||
public void cancelFileUpload() | ||
{ | ||
String testFileName = "cancelFileUpload.txt"; | ||
String filePath = PropertiesHolder.getProperty("zanata.testdata.directory") | ||
.concat(File.separator) | ||
.concat(testFileName); | ||
|
||
assertThat("Data file "+testFileName+" exists", new File(filePath).exists()); | ||
ProjectSourceDocumentsPage projectSourceDocumentsPage = new LoginWorkFlow().signIn("admin", "admin") | ||
.goToProjects() | ||
.goToProject("about fedora") | ||
.goToVersion("master") | ||
.goToSourceDocuments() | ||
.pressUploadFileButton() | ||
.enterFilePath(filePath) | ||
.cancelUpload(); | ||
assertThat("Document does not show in table", | ||
!projectSourceDocumentsPage.sourceDocumentsContains(testFileName)); | ||
} | ||
|
||
@Test(expected = RuntimeException.class) | ||
public void emptyFilenameUpload() | ||
{ | ||
ProjectSourceDocumentsPage projectSourceDocumentsPage = new LoginWorkFlow().signIn("admin", "admin") | ||
.goToProjects() | ||
.goToProject("about fedora") | ||
.goToVersion("master") | ||
.goToSourceDocuments() | ||
.pressUploadFileButton() | ||
.submitUpload(); | ||
|
||
// RHBZ-990373 | ||
projectSourceDocumentsPage.assertNoCriticalErrors(); | ||
// TODO: Verify graceful handling of scenario | ||
} | ||
|
||
@Test(expected = RuntimeException.class) | ||
public void failOnInvalidFileUpload() | ||
{ | ||
File noFile; | ||
try { | ||
noFile = File.createTempFile("thereIsNoSpoon", "txt"); | ||
} catch(IOException ioException) | ||
{ | ||
throw new RuntimeException("failOnInvalidFileUpload:Unable to create temporary file"); | ||
} | ||
assertThat("Data file "+noFile.getName()+" exists", noFile.exists()); | ||
|
||
ProjectSourceDocumentsPage projectSourceDocumentsPage = new LoginWorkFlow().signIn("admin", "admin") | ||
.goToProjects() | ||
.goToProject("about fedora") | ||
.goToVersion("master") | ||
.goToSourceDocuments() | ||
.pressUploadFileButton() | ||
.enterFilePath(noFile.getAbsolutePath()); | ||
|
||
noFile.delete(); | ||
assertThat("Data file " + noFile.getName() + " does not exists", !noFile.exists()); | ||
projectSourceDocumentsPage = projectSourceDocumentsPage.submitUpload(); | ||
|
||
// RHBZ-990373 | ||
projectSourceDocumentsPage.assertNoCriticalErrors(); | ||
// TODO: Verify graceful handling of scenario | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a cancel upload test file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a test file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters