Index: pom.xml =================================================================== --- pom.xml (revision 810156) +++ pom.xml (working copy) @@ -19,7 +19,8 @@ maven-jetty-plugin ${jettyVersion} - /shiro + / + 9080 @@ -59,6 +60,13 @@ runtime + net.sourceforge.htmlunit + htmlunit + 2.5 + test + + + org.apache.shiro shiro-core @@ -66,6 +74,20 @@ org.apache.shiro shiro-web + + + org.mortbay.jetty + jetty + ${jettyVersion} + test + + + org.mortbay.jetty + jsp-2.1-jetty + ${jettyVersion} + test + taglibs standard Index: src/main/webapp/home.jsp =================================================================== --- src/main/webapp/home.jsp (revision 810156) +++ src/main/webapp/home.jsp (working copy) @@ -21,6 +21,7 @@ "/> + Apache Shiro Quickstart Index: src/test/java/org/apache/shiro/test/AbstractContainerTest.java =================================================================== --- src/test/java/org/apache/shiro/test/AbstractContainerTest.java (revision 0) +++ src/test/java/org/apache/shiro/test/AbstractContainerTest.java (revision 0) @@ -0,0 +1,75 @@ +package org.apache.shiro.test; + + +import static org.junit.Assert.assertTrue; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.mortbay.jetty.Connector; +import org.mortbay.jetty.Handler; +import org.mortbay.jetty.Server; +import org.mortbay.jetty.handler.DefaultHandler; +import org.mortbay.jetty.handler.HandlerCollection; +import org.mortbay.jetty.nio.SelectChannelConnector; +import org.mortbay.jetty.webapp.WebAppContext; + +import com.gargoylesoftware.htmlunit.WebClient; + +public abstract class AbstractContainerTest { + protected static PauseableServer server; + + protected static final int port = 8180; + + protected static final String BASEURI = "http://localhost:" + port + "/"; + + protected final WebClient webClient = new WebClient(); + + @BeforeClass + public static void startContainer() throws Exception { + if (server == null) { + server = new PauseableServer(); + Connector connector = new SelectChannelConnector(); + connector.setPort(port); + server.setConnectors(new Connector[] { connector }); + + WebAppContext context = new WebAppContext("src/main/webapp", "/"); + + HandlerCollection handlers = new HandlerCollection(); + handlers.setHandlers(new Handler[] { context, new DefaultHandler() }); + server.setHandler(handlers); + server.start(); + assertTrue(server.isStarted()); + + } + } + + @AfterClass + public static void stopContainer() throws Exception { + // Don't stop the server here, because it causes issues with already initialized + // statics - for example with file upload + // server.stop(); + // server = null; + } + + @Before + public void beforeTest() { + webClient.setThrowExceptionOnFailingStatusCode(true); + } + + public void pauseServer(boolean paused) { + if (server != null) server.pause(paused); + } + + public static class PauseableServer extends Server { + public synchronized void pause(boolean paused) { + try { + if (paused) for (Connector connector : getConnectors()) + connector.stop(); + else for (Connector connector : getConnectors()) + connector.start(); + } catch (Exception e) { + } + } + } +} Index: src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java =================================================================== --- src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java (revision 0) +++ src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java (revision 0) @@ -0,0 +1,20 @@ +package org.apache.shiro.test; + +import java.io.IOException; +import java.net.MalformedURLException; + +import org.junit.Test; +import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; +import com.gargoylesoftware.htmlunit.html.HtmlPage; + +import static com.gargoylesoftware.htmlunit.WebAssert.*; + +public class ContainerIntegrationTest extends AbstractContainerTest { + @Test + public void checkOrganizationsDisplayedOnIndexPage() throws FailingHttpStatusCodeException, MalformedURLException, IOException { + final HtmlPage page = webClient.getPage(BASEURI); + //assertTrue(page.getTitleText().contains("Apache Shiro Quickstart") ); + assertTitleEquals(page, "Apache Shiro Quickstart"); + + } +}