shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdem...@apache.org
Subject [05/20] shiro git commit: Fixed and enabled web sample test
Date Fri, 14 Oct 2016 19:36:08 GMT
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/ea2b4833
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/ea2b4833
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/ea2b4833

Branch: refs/heads/1.4.x
Commit: ea2b48330ad7b031741ea9c1ae2f739e4679863e
Parents: b05a48f
Author: Brian Demers <bdemers@apache.org>
Authored: Fri Sep 30 11:57:15 2016 -0400
Committer: Brian Demers <bdemers@apache.org>
Committed: Fri Oct 14 15:15:50 2016 -0400

----------------------------------------------------------------------
 .../apache/shiro/test/AbstractContainerIT.java  |  26 ++--
 samples/web/pom.xml                             | 130 ++++++++++++++-----
 .../shiro/test/AbstractContainerTest.java       |  88 -------------
 .../shiro/test/ContainerIntegrationIT.java      |  66 ++++++++++
 .../shiro/test/ContainerIntegrationTest.java    |  81 ------------
 5 files changed, 181 insertions(+), 210 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/shiro/blob/ea2b4833/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/ea2b4833/samples/web/pom.xml
----------------------------------------------------------------------
diff --git a/samples/web/pom.xml b/samples/web/pom.xml
index a875aa6..cf53c2b 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>
@@ -100,22 +122,72 @@
             <artifactId>shiro-web</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.mortbay.jetty</groupId>
-            <artifactId>jetty</artifactId>
-            <version>${jetty.version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.mortbay.jetty</groupId>
-            <artifactId>jsp-2.1-jetty</artifactId>
-            <version>${jetty.version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>jcl-over-slf4j</artifactId>
             <scope>runtime</scope>
         </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/ea2b4833/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/ea2b4833/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..e8f7b48
--- /dev/null
+++ b/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java
@@ -0,0 +1,66 @@
+/*
+ * 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/ea2b4833/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 7123cc4..0000000
--- a/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationTest.java
+++ /dev/null
@@ -1,81 +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.Ignore;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-
-@Ignore
-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");
-    }
-
-}


Mime
View raw message