mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
Added the tests again, but excluding them from beeing run with excludes in pom.xml
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@595575 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -40,6 +40,21 @@
|
||||
<url>http://svn.apache.org/viewcvs.cgi/struts/struts2/trunk/apps/portlet/</url>
|
||||
</scm>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- Excluded so the integration tests don't run in the main Bamboo build -->
|
||||
<excludes>
|
||||
<exclude>org/apache/struts2/portlet/test/*</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>pluto</id>
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package org.apache.struts2.portlet.test;
|
||||
|
||||
import net.sourceforge.jwebunit.junit.WebTestCase;
|
||||
|
||||
import org.apache.pluto.core.PortletServlet;
|
||||
import org.mortbay.jetty.Server;
|
||||
import org.mortbay.jetty.servlet.ServletHolder;
|
||||
import org.mortbay.jetty.webapp.WebAppContext;
|
||||
|
||||
public abstract class BasePortletTest extends WebTestCase {
|
||||
|
||||
protected Server server;
|
||||
|
||||
private int port = 9876;
|
||||
|
||||
private String contextPath = "/test";
|
||||
|
||||
public void setUp() throws Exception {
|
||||
System.setProperty("org.apache.pluto.embedded.portletId", getPortletName());
|
||||
server = new Server(port);
|
||||
WebAppContext webapp = new WebAppContext("src/main/webapp", contextPath);
|
||||
webapp.setDefaultsDescriptor("/WEB-INF/jetty-pluto-web-default.xml");
|
||||
ServletHolder portletServlet = new ServletHolder(new PortletServlet());
|
||||
portletServlet.setInitParameter("portlet-name", getPortletName());
|
||||
portletServlet.setInitOrder(1);
|
||||
webapp.addServlet(portletServlet, "/PlutoInvoker/" + getPortletName());
|
||||
server.addHandler(webapp);
|
||||
server.start();
|
||||
getTestContext().setBaseUrl("http://localhost:" + port + contextPath);
|
||||
}
|
||||
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
server.stop();
|
||||
}
|
||||
|
||||
public void minimizeWindow() {
|
||||
clickElementByXPath("//span[@class='minimized']/..");
|
||||
}
|
||||
|
||||
public void maximizeWindow() {
|
||||
clickElementByXPath("//span[@class='minimized']/..");
|
||||
}
|
||||
|
||||
public void restoreWindow() {
|
||||
clickElementByXPath("//span[@class='normal']/..");
|
||||
}
|
||||
|
||||
public void switchEdit() {
|
||||
clickElementByXPath("//span[@class='edit']/..");
|
||||
}
|
||||
|
||||
public void switchView() {
|
||||
clickElementByXPath("//span[@class='view']/..");
|
||||
}
|
||||
|
||||
public void switchHelp() {
|
||||
clickElementByXPath("//span[@class='help']/..");
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
if(!contextPath.startsWith("/")) {
|
||||
this.contextPath = "/" + contextPath;
|
||||
}
|
||||
else {
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String getPortletName();
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package org.apache.struts2.portlet.test;
|
||||
|
||||
public class Struts2PortletTest extends BasePortletTest {
|
||||
|
||||
private final static String PORTLET_NAME = "StrutsPortlet";
|
||||
|
||||
public void testIndexPage() throws Exception {
|
||||
beginAt("pluto/index.jsp");
|
||||
assertTextPresent("Welcome to the Struts example portlet");
|
||||
assertLinkPresentWithExactText("A simple form");
|
||||
assertLinkPresentWithExactText("Validation");
|
||||
}
|
||||
|
||||
public void testFormExample() throws Exception {
|
||||
beginAt("pluto/index.jsp");
|
||||
clickLinkWithExactText("A simple form");
|
||||
assertFormPresent("processFormExample");
|
||||
assertTextPresent("Input your name");
|
||||
setWorkingForm("processFormExample");
|
||||
setTextField("firstName", "Nils-Helge");
|
||||
setTextField("lastName", "Garli");
|
||||
submit();
|
||||
assertTextPresent("Hello Nils-Helge Garli");
|
||||
}
|
||||
|
||||
public void testValidationExample() throws Exception {
|
||||
beginAt("pluto/index.jsp");
|
||||
clickLinkWithExactText("Validation");
|
||||
assertFormPresent("processValidationExample");
|
||||
assertTextPresent("Input your name");
|
||||
setWorkingForm("processValidationExample");
|
||||
setTextField("firstName", "Nils-Helge");
|
||||
submit();
|
||||
assertTextFieldEquals("firstName", "Nils-Helge");
|
||||
assertTextPresent("You must enter a last name");
|
||||
setTextField("lastName", "Garli");
|
||||
submit();
|
||||
assertTextPresent("Hello Nils-Helge Garli");
|
||||
}
|
||||
|
||||
public void testValidationErrorMessagesStickBetweenWindowStateChanges() throws Exception {
|
||||
beginAt("pluto/index.jsp");
|
||||
clickLinkWithExactText("Validation");
|
||||
assertFormPresent("processValidationExample");
|
||||
assertTextPresent("Input your name");
|
||||
setWorkingForm("processValidationExample");
|
||||
setTextField("firstName", "Nils-Helge");
|
||||
submit();
|
||||
assertTextFieldEquals("firstName", "Nils-Helge");
|
||||
assertTextPresent("You must enter a last name");
|
||||
minimizeWindow();
|
||||
assertTextNotPresent("Input your name");
|
||||
restoreWindow();
|
||||
assertTextPresent("Input your name");
|
||||
assertTextPresent("You must enter a last name");
|
||||
}
|
||||
|
||||
public void testTokenExample() throws Exception {
|
||||
beginAt("pluto/index.jsp");
|
||||
clickLinkWithText("Token");
|
||||
setWorkingForm(0);
|
||||
setTextField("theValue", "something");
|
||||
submit();
|
||||
assertTextPresent("ERROR");
|
||||
setWorkingForm(1);
|
||||
setTextField("theValue", "somethingElse");
|
||||
submit();
|
||||
assertTextPresent("The form was successfully submitted with a valid token");
|
||||
}
|
||||
|
||||
public void testSwitchFromViewToEditShouldGoToDefaultEditPage() throws Exception {
|
||||
beginAt("pluto/index.jsp");
|
||||
assertTextPresent("Welcome to the Struts example portlet");
|
||||
switchEdit();
|
||||
assertTextPresent("Back to view mode");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPortletName() {
|
||||
return PORTLET_NAME;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user