You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bd...@apache.org on 2016/10/18 18:56:41 UTC
[07/23] shiro git commit: Fixed and enabled web sample test
Fixed and enabled web sample test
Project: http://git-wip-us.apache.org/repos/asf/shiro/repo
Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/57b2ae28
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/57b2ae28
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/57b2ae28
Branch: refs/heads/master
Commit: 57b2ae2888d9fd799b32f83621d621084ade8192
Parents: 2fbf623
Author: Brian Demers <bd...@apache.org>
Authored: Fri Sep 30 11:57:15 2016 -0400
Committer: Brian Demers <bd...@apache.org>
Committed: Tue Oct 18 12:06:38 2016 -0400
----------------------------------------------------------------------
.../apache/shiro/test/AbstractContainerIT.java | 26 ++--
samples/web/pom.xml | 118 ++++++++++++++++---
.../shiro/test/AbstractContainerTest.java | 88 --------------
.../shiro/test/ContainerIntegrationIT.java | 65 ++++++++++
.../shiro/test/ContainerIntegrationTest.java | 79 -------------
5 files changed, 180 insertions(+), 196 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/shiro/blob/57b2ae28/samples/servlet-plugin/src/test/java/org/apache/shiro/test/AbstractContainerIT.java
----------------------------------------------------------------------
diff --git a/samples/servlet-plugin/src/test/java/org/apache/shiro/test/AbstractContainerIT.java b/samples/servlet-plugin/src/test/java/org/apache/shiro/test/AbstractContainerIT.java
index f5b44f7..da02a0b 100644
--- a/samples/servlet-plugin/src/test/java/org/apache/shiro/test/AbstractContainerIT.java
+++ b/samples/servlet-plugin/src/test/java/org/apache/shiro/test/AbstractContainerIT.java
@@ -56,19 +56,8 @@ public abstract class AbstractContainerIT {
@BeforeClass
public static void startContainer() throws Exception {
- File[] warFiles = new File("target").listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(".war");
- }
- });
-
- assertEquals("Expected only one war file in target directory, run 'mvn clean' and try again", 1, warFiles.length);
-
- String warDir = warFiles[0].getAbsolutePath().replaceFirst("\\.war$", "");
-
EmbeddedJettyConfiguration config = EmbeddedJettyConfiguration.builder()
- .withWebapp(warDir)
+ .withWebapp(getWarDir())
.build();
jetty = new EmbeddedJetty(config) {
@@ -131,6 +120,19 @@ public abstract class AbstractContainerIT {
return "http://localhost:" + port + "/";
}
+ protected static String getWarDir() {
+ File[] warFiles = new File("target").listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".war");
+ }
+ });
+
+ assertEquals("Expected only one war file in target directory, run 'mvn clean' and try again", 1, warFiles.length);
+
+ return warFiles[0].getAbsolutePath().replaceFirst("\\.war$", "");
+ }
+
@Before
public void beforeTest() {
webClient.setThrowExceptionOnFailingStatusCode(true);
http://git-wip-us.apache.org/repos/asf/shiro/blob/57b2ae28/samples/web/pom.xml
----------------------------------------------------------------------
diff --git a/samples/web/pom.xml b/samples/web/pom.xml
index c29648d..4629ec3 100644
--- a/samples/web/pom.xml
+++ b/samples/web/pom.xml
@@ -32,7 +32,46 @@
<name>Apache Shiro :: Samples :: Web</name>
<packaging>war</packaging>
+ <properties>
+ <jetty.port>9080</jetty.port>
+ <jetty.postIT.sleep>1</jetty.postIT.sleep>
+ </properties>
+
<build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <version>${jetty.version}</version>
+ <configuration>
+ <contextPath>/</contextPath>
+ <stopPort>8005</stopPort>
+ <stopKey>STOP</stopKey>
+ <connectors>
+ <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
+ <port>${jetty.port}</port>
+ <maxIdleTime>60000</maxIdleTime>
+ </connector>
+ </connectors>
+ <requestLog implementation="org.mortbay.jetty.NCSARequestLog">
+ <filename>./target/yyyy_mm_dd.request.log</filename>
+ <retainDays>90</retainDays>
+ <append>true</append>
+ <extended>false</extended>
+ <logTimeZone>GMT</logTimeZone>
+ </requestLog>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jsp-2.1-jetty</artifactId>
+ <version>${jetty.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
@@ -43,23 +82,6 @@
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
- <version>${jetty.version}</version>
- <configuration>
- <contextPath>/</contextPath>
- <connectors>
- <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
- <port>9080</port>
- <maxIdleTime>60000</maxIdleTime>
- </connector>
- </connectors>
- <requestLog implementation="org.mortbay.jetty.NCSARequestLog">
- <filename>./target/yyyy_mm_dd.request.log</filename>
- <retainDays>90</retainDays>
- <append>true</append>
- <extended>false</extended>
- <logTimeZone>GMT</logTimeZone>
- </requestLog>
- </configuration>
</plugin>
</plugins>
</build>
@@ -122,4 +144,66 @@
</dependency>
</dependencies>
+ <profiles>
+ <profile>
+ <id>run-ITs</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <executions>
+ <!-- start jetty before ITs -->
+ <execution>
+ <id>start-jetty</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <scanIntervalSeconds>0</scanIntervalSeconds>
+ <daemon>true</daemon>
+ </configuration>
+ </execution>
+ <!-- Stop jetty after ITs -->
+ <execution>
+ <id>stop-jetty</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.8</version>
+ <executions>
+ <execution>
+ <id>sleep-for-a-while</id>
+ <phase>post-integration-test</phase>
+ <configuration>
+ <target>
+ <!-- This is dirty looking, but this old version needs it or the shutdown
+ hook will print exceptions, the build will still pass, so it is mostly cosmetic.
+ -->
+ <echo>Waiting for Jetty to stop</echo>
+ <sleep seconds="${jetty.postIT.sleep}" />
+ </target>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
</project>
http://git-wip-us.apache.org/repos/asf/shiro/blob/57b2ae28/samples/web/src/test/java/org/apache/shiro/test/AbstractContainerTest.java
----------------------------------------------------------------------
diff --git a/samples/web/src/test/java/org/apache/shiro/test/AbstractContainerTest.java b/samples/web/src/test/java/org/apache/shiro/test/AbstractContainerTest.java
deleted file mode 100644
index 6a0c6e8..0000000
--- a/samples/web/src/test/java/org/apache/shiro/test/AbstractContainerTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.test;
-
-import com.gargoylesoftware.htmlunit.WebClient;
-import static org.junit.Assert.assertTrue;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.mortbay.jetty.Connector;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.nio.SelectChannelConnector;
-import org.mortbay.jetty.webapp.WebAppContext;
-
-import java.net.BindException;
-
-public abstract class AbstractContainerTest {
- public static final int MAX_PORT = 9200;
-
- protected static PauseableServer server;
-
- private static int port = 9180;
-
- protected final WebClient webClient = new WebClient();
-
- @BeforeClass
- public static void startContainer() throws Exception {
- while (server == null && port < MAX_PORT) {
- try {
- server = createAndStartServer(port);
- } catch (BindException e) {
- System.err.printf("Unable to listen on port %d. Trying next port.", port);
- port++;
- }
- }
- assertTrue(server.isStarted());
- }
-
- private static PauseableServer createAndStartServer(final int port) throws Exception {
- PauseableServer server = new PauseableServer();
- Connector connector = new SelectChannelConnector();
- connector.setPort(port);
- server.setConnectors(new Connector[]{connector});
- server.setHandler(new WebAppContext("src/main/webapp", "/"));
- server.start();
- return server;
- }
-
- protected static String getBaseUri() {
- return "http://localhost:" + port + "/";
- }
-
- @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) {
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/shiro/blob/57b2ae28/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java
----------------------------------------------------------------------
diff --git a/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java b/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java
new file mode 100644
index 0000000..0d077e9
--- /dev/null
+++ b/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.test;
+
+import com.gargoylesoftware.htmlunit.ElementNotFoundException;
+import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+public class ContainerIntegrationIT {
+
+ protected final WebClient webClient = new WebClient();
+
+ @Before
+ public void logOut() throws IOException {
+ // Make sure we are logged out
+ final HtmlPage homePage = webClient.getPage(getBaseUri());
+ try {
+ homePage.getAnchorByHref("/logout").click();
+ }
+ catch (ElementNotFoundException e) {
+ //Ignore
+ }
+ }
+
+ protected static String getBaseUri() {
+ String port = System.getProperty("jetty.port", "9080");
+ return "http://localhost:" + port + "/";
+ }
+
+ @Test
+ public void logIn() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException {
+
+ HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
+ HtmlForm form = page.getFormByName("loginform");
+ form.<HtmlInput>getInputByName("username").setValueAttribute("root");
+ form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
+ page = form.<HtmlInput>getInputByName("submit").click();
+ // This'll throw an expection if not logged in
+ page.getAnchorByHref("/logout");
+ }
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/57b2ae28/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java b/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java
deleted file mode 100644
index 7efd360..0000000
--- a/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.test;
-
-import com.gargoylesoftware.htmlunit.ElementNotFoundException;
-import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
-import com.gargoylesoftware.htmlunit.WebAssert;
-import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
-import com.gargoylesoftware.htmlunit.html.HtmlForm;
-import com.gargoylesoftware.htmlunit.html.HtmlInput;
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-
-public class ContainerIntegrationTest extends AbstractContainerTest {
-
- @Before
- public void logOut() throws IOException {
- // Make sure we are logged out
- final HtmlPage homePage = webClient.getPage(getBaseUri());
- try {
- homePage.getAnchorByHref("/logout").click();
- }
- catch (ElementNotFoundException e) {
- //Ignore
- }
- }
-
- @Test
- public void logIn() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException {
-
- HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
- HtmlForm form = page.getFormByName("loginform");
- form.<HtmlInput>getInputByName("username").setValueAttribute("root");
- form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
- page = form.<HtmlInput>getInputByName("submit").click();
- // This'll throw an expection if not logged in
- page.getAnchorByHref("/logout");
- }
-
- @Test
- public void logInAndRememberMe() throws Exception {
- HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
- HtmlForm form = page.getFormByName("loginform");
- form.<HtmlInput>getInputByName("username").setValueAttribute("root");
- form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
- HtmlCheckBoxInput checkbox = form.getInputByName("rememberMe");
- checkbox.setChecked(true);
- page = form.<HtmlInput>getInputByName("submit").click();
- server.stop();
- server.start();
- page = webClient.getPage(getBaseUri());
- // page.getAnchorByHref("/logout");
- WebAssert.assertLinkPresentWithText(page, "Log out");
- page = page.getAnchorByHref("/account").click();
- // login page should be shown again - user remembered but not authenticated
- WebAssert.assertFormPresent(page, "loginform");
- }
-
-}