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 email testing infrastructure and add test
- Loading branch information
Patrick Huang
committed
Feb 10, 2014
1 parent
02bd79c
commit fa21ac7
Showing
9 changed files
with
186 additions
and
2 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
43 changes: 43 additions & 0 deletions
43
functional-test/src/main/java/org/zanata/page/utility/ContactAdminFormPage.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,43 @@ | ||
package org.zanata.page.utility; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.zanata.page.BasePage; | ||
import org.zanata.util.WebElementUtil; | ||
|
||
/** | ||
* @author Patrick Huang <a | ||
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a> | ||
*/ | ||
public class ContactAdminFormPage extends BasePage { | ||
@FindBy(id = "contactAdminForm:subjectField:subject") | ||
private WebElement subjectField; | ||
|
||
@FindBy(id = "contactAdminForm:messageField:message") | ||
private WebElement messageField; | ||
|
||
@FindBy(id = "contactAdminForm:send") | ||
private WebElement sendButton; | ||
|
||
public ContactAdminFormPage(WebDriver driver) { | ||
super(driver); | ||
} | ||
|
||
public ContactAdminFormPage inputSubject(String subject) { | ||
subjectField.clear(); | ||
subjectField.sendKeys(subject); | ||
return new ContactAdminFormPage(getDriver()); | ||
} | ||
|
||
public ContactAdminFormPage inputMessage(String message) { | ||
WebElementUtil | ||
.setRichTextEditorContent(getDriver(), messageField, message); | ||
return new ContactAdminFormPage(getDriver()); | ||
} | ||
|
||
public HelpPage send() { | ||
sendButton.click(); | ||
return new HelpPage(getDriver()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
functional-test/src/main/java/org/zanata/page/utility/HelpPage.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,24 @@ | ||
package org.zanata.page.utility; | ||
|
||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.zanata.page.BasePage; | ||
|
||
/** | ||
* @author Patrick Huang | ||
* <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a> | ||
*/ | ||
public class HelpPage extends BasePage { | ||
@FindBy(linkText = "Contact Admin") | ||
private WebElement contactAdminLink; | ||
|
||
public HelpPage(WebDriver driver) { | ||
super(driver); | ||
} | ||
|
||
public ContactAdminFormPage clickContactAdmin() { | ||
contactAdminLink.click(); | ||
return new ContactAdminFormPage(getDriver()); | ||
} | ||
} |
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
77 changes: 77 additions & 0 deletions
77
functional-test/src/test/java/org/zanata/feature/misc/ContactAdminTest.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,77 @@ | ||
package org.zanata.feature.misc; | ||
|
||
import javax.mail.internet.MimeMultipart; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.subethamail.wiser.Wiser; | ||
import org.subethamail.wiser.WiserMessage; | ||
import org.zanata.feature.DetailedTest; | ||
import org.zanata.page.utility.ContactAdminFormPage; | ||
import org.zanata.page.utility.DashboardPage; | ||
import org.zanata.page.utility.HelpPage; | ||
import org.zanata.util.AddUsersRule; | ||
import org.zanata.util.PropertiesHolder; | ||
import org.zanata.workflow.LoginWorkFlow; | ||
import com.google.common.base.Throwables; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
/** | ||
* @author Patrick Huang <a | ||
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a> | ||
*/ | ||
@Category(DetailedTest.class) | ||
public class ContactAdminTest { | ||
@Rule | ||
public AddUsersRule addUsersRule = new AddUsersRule(); | ||
private Wiser wiser = new Wiser(); | ||
|
||
@Before | ||
public void setUp() { | ||
String port = PropertiesHolder.getProperty("smtp.port"); | ||
wiser.setPort(Integer.parseInt(port)); | ||
wiser.start(); | ||
} | ||
|
||
@After | ||
public void cleanUp() { | ||
wiser.stop(); | ||
} | ||
|
||
@Test | ||
public void testContactAdmin() { | ||
DashboardPage dashboard = | ||
new LoginWorkFlow().signIn("translator", "translator"); | ||
ContactAdminFormPage contactAdminFormPage = | ||
dashboard.goToHelp().clickContactAdmin(); | ||
|
||
HelpPage helpPage = | ||
contactAdminFormPage.inputSubject("hello admin") | ||
.inputMessage("I love Zanata").send(); | ||
|
||
assertThat( | ||
helpPage.getNotificationMessage(), | ||
Matchers.equalTo("Your message has been sent to the administrator")); | ||
assertThat(wiser.getMessages(), Matchers.hasSize(1)); | ||
WiserMessage wiserMessage = wiser.getMessages().get(0); | ||
assertThat(wiserMessage.getEnvelopeReceiver(), | ||
Matchers.equalTo("admin@example.com")); | ||
|
||
String content = getEmailContent(wiserMessage); | ||
assertThat(content, Matchers.containsString("I love Zanata")); | ||
} | ||
|
||
private static String getEmailContent(WiserMessage wiserMessage) { | ||
try { | ||
return ((MimeMultipart) wiserMessage.getMimeMessage().getContent()) | ||
.getBodyPart(0).getContent().toString(); | ||
} catch (Exception e) { | ||
throw Throwables.propagate(e); | ||
} | ||
} | ||
} |
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