Repository: shiro Updated Branches: refs/heads/master 31492eae9 -> 2f4d63585
Cleaned up duplicated integration test code The AbstractContainerIT was getting copied around a bit, this has been moved to a new 'integration-tests/support' module. Project: http://git-wip-us.apache.org/repos/asf/shiro/repo Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/e6db45c7 Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/e6db45c7 Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/e6db45c7 Branch: refs/heads/master Commit: e6db45c7c59b9ea7f45224ff29103678aa4631d4 Parents: 31492ea Author: Brian Demers <[email protected]> Authored: Thu Oct 20 11:06:39 2016 -0400 Committer: Brian Demers <[email protected]> Committed: Thu Oct 20 18:00:59 2016 -0400 ---------------------------------------------------------------------- integration-tests/guice3/pom.xml | 7 +- .../samples/guice/AbstractContainerIT.java | 142 ----------------- .../samples/guice/ContainerIntegrationIT.java | 2 + integration-tests/guice4/pom.xml | 5 +- .../samples/guice/AbstractContainerIT.java | 142 ----------------- .../samples/guice/ContainerIntegrationIT.java | 2 + integration-tests/pom.xml | 1 + integration-tests/support/pom.xml | 96 ++++++++++++ .../shiro/testing/web/AbstractContainerIT.java | 153 +++++++++++++++++++ pom.xml | 18 ++- samples/guice/pom.xml | 13 +- .../samples/guice/AbstractContainerIT.java | 142 ----------------- .../samples/guice/ContainerIntegrationIT.java | 1 + samples/jaxrs/pom.xml | 5 +- .../web/jaxrs/ContainerIntegrationIT.groovy | 1 + .../shiro/web/jaxrs/AbstractContainerIT.java | 148 ------------------ samples/servlet-plugin/pom.xml | 8 +- .../apache/shiro/test/AbstractContainerIT.java | 147 ------------------ .../shiro/test/ContainerIntegrationIT.java | 1 + samples/web/pom.xml | 13 +- .../apache/shiro/test/AbstractContainerIT.java | 145 ------------------ .../shiro/test/ContainerIntegrationIT.java | 1 + 22 files changed, 292 insertions(+), 901 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/integration-tests/guice3/pom.xml ---------------------------------------------------------------------- diff --git a/integration-tests/guice3/pom.xml b/integration-tests/guice3/pom.xml index 92efc51..1d4d5b8 100644 --- a/integration-tests/guice3/pom.xml +++ b/integration-tests/guice3/pom.xml @@ -91,7 +91,6 @@ <dependency> <groupId>net.sourceforge.htmlunit</groupId> <artifactId>htmlunit</artifactId> - <version>2.6</version> <scope>test</scope> </dependency> <dependency> @@ -108,9 +107,9 @@ <scope>test</scope> </dependency> <dependency> - <groupId>com.github.mjeanroy</groupId> - <artifactId>junit-servers-jetty</artifactId> - <scope>test</scope> + <groupId>org.apache.shiro.integrationtests</groupId> + <artifactId>shiro-its-support</artifactId> + <scope>test</scope> </dependency> </dependencies> http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java ---------------------------------------------------------------------- diff --git a/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java b/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java deleted file mode 100644 index dcd47e1..0000000 --- a/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java +++ /dev/null @@ -1,142 +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.samples.guice; - -import com.gargoylesoftware.htmlunit.WebClient; -import com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty; -import com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration; -import org.eclipse.jetty.annotations.AnnotationConfiguration; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.resource.FileResource; -import org.eclipse.jetty.webapp.Configuration; -import org.eclipse.jetty.webapp.FragmentConfiguration; -import org.eclipse.jetty.webapp.JettyWebXmlConfiguration; -import org.eclipse.jetty.webapp.MetaInfConfiguration; -import org.eclipse.jetty.webapp.WebAppContext; -import org.eclipse.jetty.webapp.WebInfConfiguration; -import org.eclipse.jetty.webapp.WebXmlConfiguration; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; - -import java.io.File; -import java.io.FilenameFilter; - -import static com.github.mjeanroy.junit.servers.commons.Strings.isNotBlank; -import static org.eclipse.jetty.util.resource.Resource.newResource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public abstract class AbstractContainerIT { - - protected static EmbeddedJetty jetty; - - protected final WebClient webClient = new WebClient(); - - @BeforeClass - public static void startContainer() throws Exception { - - EmbeddedJettyConfiguration config = EmbeddedJettyConfiguration.builder() - .withWebapp(getWarDir()) - .build(); - - jetty = new EmbeddedJetty(config) { - - /** - * Overriding with contents of this pull request, to make fragment scanning work. - * https://github.com/mjeanroy/junit-servers/pull/3 - */ - protected WebAppContext createdWebAppContext() throws Exception { - final String path = configuration.getPath(); - final String webapp = configuration.getWebapp(); - final String classpath = configuration.getClasspath(); - - WebAppContext ctx = new WebAppContext(); - ctx.setClassLoader(Thread.currentThread().getContextClassLoader()); - ctx.setContextPath(path); - - // Useful for WebXmlConfiguration - ctx.setBaseResource(newResource(webapp)); - - ctx.setConfigurations(new Configuration[]{ - new WebInfConfiguration(), - new WebXmlConfiguration(), - new AnnotationConfiguration(), - new JettyWebXmlConfiguration(), - new MetaInfConfiguration(), - new FragmentConfiguration(), - }); - - if (isNotBlank(classpath)) { - // Fix to scan Spring WebApplicationInitializer - // This will add compiled classes to jetty classpath - // See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration - // And more precisely: http://stackoverflow.com/a/18449506/1215828 - File classes = new File(classpath); - FileResource containerResources = new FileResource(classes.toURI()); - ctx.getMetaData().addContainerResource(containerResources); - } - - Server server = getDelegate(); - - ctx.setParentLoaderPriority(true); - ctx.setWar(webapp); - ctx.setServer(server); - - // Add server context - server.setHandler(ctx); - - return ctx; - } - }; - - jetty.start(); - - assertTrue(jetty.isStarted()); - } - - protected static String getBaseUri() { - return "http://localhost:" + jetty.getPort() + "/"; - } - - 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); - } - - @AfterClass - public static void stopContainer() { - if (jetty != null) { - jetty.stop(); - } - } -} http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java ---------------------------------------------------------------------- diff --git a/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java b/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java index 4ebc6c7..1288c84 100644 --- a/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java +++ b/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java @@ -18,6 +18,8 @@ */ package org.apache.shiro.samples.guice; +import org.apache.shiro.testing.web.AbstractContainerIT; + import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.WebAssert; http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/integration-tests/guice4/pom.xml ---------------------------------------------------------------------- diff --git a/integration-tests/guice4/pom.xml b/integration-tests/guice4/pom.xml index 1ff877b..be7d85f 100644 --- a/integration-tests/guice4/pom.xml +++ b/integration-tests/guice4/pom.xml @@ -105,7 +105,6 @@ <dependency> <groupId>net.sourceforge.htmlunit</groupId> <artifactId>htmlunit</artifactId> - <version>2.6</version> <scope>test</scope> </dependency> <dependency> @@ -122,8 +121,8 @@ <scope>test</scope> </dependency> <dependency> - <groupId>com.github.mjeanroy</groupId> - <artifactId>junit-servers-jetty</artifactId> + <groupId>org.apache.shiro.integrationtests</groupId> + <artifactId>shiro-its-support</artifactId> <scope>test</scope> </dependency> </dependencies> http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java ---------------------------------------------------------------------- diff --git a/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java b/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java deleted file mode 100644 index dcd47e1..0000000 --- a/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java +++ /dev/null @@ -1,142 +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.samples.guice; - -import com.gargoylesoftware.htmlunit.WebClient; -import com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty; -import com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration; -import org.eclipse.jetty.annotations.AnnotationConfiguration; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.resource.FileResource; -import org.eclipse.jetty.webapp.Configuration; -import org.eclipse.jetty.webapp.FragmentConfiguration; -import org.eclipse.jetty.webapp.JettyWebXmlConfiguration; -import org.eclipse.jetty.webapp.MetaInfConfiguration; -import org.eclipse.jetty.webapp.WebAppContext; -import org.eclipse.jetty.webapp.WebInfConfiguration; -import org.eclipse.jetty.webapp.WebXmlConfiguration; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; - -import java.io.File; -import java.io.FilenameFilter; - -import static com.github.mjeanroy.junit.servers.commons.Strings.isNotBlank; -import static org.eclipse.jetty.util.resource.Resource.newResource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public abstract class AbstractContainerIT { - - protected static EmbeddedJetty jetty; - - protected final WebClient webClient = new WebClient(); - - @BeforeClass - public static void startContainer() throws Exception { - - EmbeddedJettyConfiguration config = EmbeddedJettyConfiguration.builder() - .withWebapp(getWarDir()) - .build(); - - jetty = new EmbeddedJetty(config) { - - /** - * Overriding with contents of this pull request, to make fragment scanning work. - * https://github.com/mjeanroy/junit-servers/pull/3 - */ - protected WebAppContext createdWebAppContext() throws Exception { - final String path = configuration.getPath(); - final String webapp = configuration.getWebapp(); - final String classpath = configuration.getClasspath(); - - WebAppContext ctx = new WebAppContext(); - ctx.setClassLoader(Thread.currentThread().getContextClassLoader()); - ctx.setContextPath(path); - - // Useful for WebXmlConfiguration - ctx.setBaseResource(newResource(webapp)); - - ctx.setConfigurations(new Configuration[]{ - new WebInfConfiguration(), - new WebXmlConfiguration(), - new AnnotationConfiguration(), - new JettyWebXmlConfiguration(), - new MetaInfConfiguration(), - new FragmentConfiguration(), - }); - - if (isNotBlank(classpath)) { - // Fix to scan Spring WebApplicationInitializer - // This will add compiled classes to jetty classpath - // See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration - // And more precisely: http://stackoverflow.com/a/18449506/1215828 - File classes = new File(classpath); - FileResource containerResources = new FileResource(classes.toURI()); - ctx.getMetaData().addContainerResource(containerResources); - } - - Server server = getDelegate(); - - ctx.setParentLoaderPriority(true); - ctx.setWar(webapp); - ctx.setServer(server); - - // Add server context - server.setHandler(ctx); - - return ctx; - } - }; - - jetty.start(); - - assertTrue(jetty.isStarted()); - } - - protected static String getBaseUri() { - return "http://localhost:" + jetty.getPort() + "/"; - } - - 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); - } - - @AfterClass - public static void stopContainer() { - if (jetty != null) { - jetty.stop(); - } - } -} http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java ---------------------------------------------------------------------- diff --git a/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java b/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java index 4ebc6c7..1288c84 100644 --- a/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java +++ b/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java @@ -18,6 +18,8 @@ */ package org.apache.shiro.samples.guice; +import org.apache.shiro.testing.web.AbstractContainerIT; + import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.WebAssert; http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/integration-tests/pom.xml ---------------------------------------------------------------------- diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 1f72a99..82dede2 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -34,6 +34,7 @@ <packaging>pom</packaging> <modules> + <module>support</module> <module>guice3</module> <module>guice4</module> </modules> http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/integration-tests/support/pom.xml ---------------------------------------------------------------------- diff --git a/integration-tests/support/pom.xml b/integration-tests/support/pom.xml new file mode 100644 index 0000000..13901fe --- /dev/null +++ b/integration-tests/support/pom.xml @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.shiro.integrationtests</groupId> + <artifactId>shiro-integration-tests</artifactId> + <version>1.4.0-SNAPSHOT</version> + </parent> + + <artifactId>shiro-its-support</artifactId> + <name>Apache Shiro :: ITs :: Support</name> + + <dependencies> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jstl</artifactId> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>net.sourceforge.htmlunit</groupId> + <artifactId>htmlunit</artifactId> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>apache-jsp</artifactId> + <version>${jetty.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>apache-jstl</artifactId> + <version>${jetty.version}</version> + <type>pom</type> + </dependency> + <dependency> + <groupId>com.github.mjeanroy</groupId> + <artifactId>junit-servers-jetty</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>compile</scope> + </dependency> + + <!-- dependency on the Base64 class + in 2.0 this is split out, so this dep will be removed + in the future + --> + <dependency> + <groupId>org.apache.shiro</groupId> + <artifactId>shiro-core</artifactId> + </dependency> + + </dependencies> + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/integration-tests/support/src/main/java/org/apache/shiro/testing/web/AbstractContainerIT.java ---------------------------------------------------------------------- diff --git a/integration-tests/support/src/main/java/org/apache/shiro/testing/web/AbstractContainerIT.java b/integration-tests/support/src/main/java/org/apache/shiro/testing/web/AbstractContainerIT.java new file mode 100644 index 0000000..5d3fcc0 --- /dev/null +++ b/integration-tests/support/src/main/java/org/apache/shiro/testing/web/AbstractContainerIT.java @@ -0,0 +1,153 @@ +/* + * 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.testing.web; + +import org.apache.shiro.codec.Base64; + +import com.gargoylesoftware.htmlunit.WebClient; +import com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty; +import com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration; +import org.eclipse.jetty.annotations.AnnotationConfiguration; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.resource.FileResource; +import org.eclipse.jetty.webapp.Configuration; +import org.eclipse.jetty.webapp.FragmentConfiguration; +import org.eclipse.jetty.webapp.JettyWebXmlConfiguration; +import org.eclipse.jetty.webapp.MetaInfConfiguration; +import org.eclipse.jetty.webapp.WebAppContext; +import org.eclipse.jetty.webapp.WebInfConfiguration; +import org.eclipse.jetty.webapp.WebXmlConfiguration; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.UnsupportedEncodingException; + +import static com.github.mjeanroy.junit.servers.commons.Strings.isNotBlank; +import static org.eclipse.jetty.util.resource.Resource.newResource; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public abstract class AbstractContainerIT { + + protected static EmbeddedJetty jetty; + + protected final WebClient webClient = new WebClient(); + + @BeforeClass + public static void startContainer() throws Exception { + + EmbeddedJettyConfiguration config = EmbeddedJettyConfiguration.builder() + .withWebapp(getWarDir()) + .build(); + + jetty = new EmbeddedJetty(config) { + + /** + * Overriding with contents of this pull request, to make fragment scanning work. + * https://github.com/mjeanroy/junit-servers/pull/3 + */ + protected WebAppContext createdWebAppContext() throws Exception { + final String path = configuration.getPath(); + final String webapp = configuration.getWebapp(); + final String classpath = configuration.getClasspath(); + + WebAppContext ctx = new WebAppContext(); + ctx.setClassLoader(Thread.currentThread().getContextClassLoader()); + ctx.setContextPath(path); + + // Useful for WebXmlConfiguration + ctx.setBaseResource(newResource(webapp)); + + ctx.setConfigurations(new Configuration[]{ + new WebInfConfiguration(), + new WebXmlConfiguration(), + new AnnotationConfiguration(), + new JettyWebXmlConfiguration(), + new MetaInfConfiguration(), + new FragmentConfiguration(), + }); + + if (isNotBlank(classpath)) { + // Fix to scan Spring WebApplicationInitializer + // This will add compiled classes to jetty classpath + // See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration + // And more precisely: http://stackoverflow.com/a/18449506/1215828 + File classes = new File(classpath); + FileResource containerResources = new FileResource(classes.toURI()); + ctx.getMetaData().addContainerResource(containerResources); + } + + Server server = getDelegate(); + + ctx.setParentLoaderPriority(true); + ctx.setWar(webapp); + ctx.setServer(server); + + // Add server context + server.setHandler(ctx); + + return ctx; + } + }; + + jetty.start(); + + assertTrue(jetty.isStarted()); + } + + protected static String getBaseUri() { + return "http://localhost:" + jetty.getPort() + "/"; + } + + 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$", ""); + } + + protected static String getBasicAuthorizationHeaderValue(String username, String password) throws UnsupportedEncodingException { + String authorizationHeader = username + ":" + password; + byte[] valueBytes; + valueBytes = authorizationHeader.getBytes("UTF-8"); + authorizationHeader = new String(Base64.encode(valueBytes)); + return "Basic " + authorizationHeader; + } + + @Before + public void beforeTest() { + webClient.getOptions().setThrowExceptionOnFailingStatusCode(true); + } + + @AfterClass + public static void stopContainer() { + if (jetty != null) { + jetty.stop(); + } + } +} http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 114de77..271538b 100644 --- a/pom.xml +++ b/pom.xml @@ -585,7 +585,6 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> @@ -760,8 +759,19 @@ <type>test-jar</type> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.shiro.integrationtests</groupId> + <artifactId>shiro-its-support</artifactId> + <version>1.4.0-SNAPSHOT</version> + </dependency> <!-- 3rd party dependencies --> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${junit.version}</version> + </dependency> <dependency> <!-- used for the 'hashpass' command line tool: --> <groupId>commons-cli</groupId> @@ -927,6 +937,11 @@ <version>3.7.2</version> </dependency> <dependency> + <groupId>net.sourceforge.htmlunit</groupId> + <artifactId>htmlunit</artifactId> + <version>2.23</version> + </dependency> + <dependency> <!-- Used for sample applications only - not required for the framework: --> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> @@ -1117,7 +1132,6 @@ <groupId>com.github.mjeanroy</groupId> <artifactId>junit-servers-jetty</artifactId> <version>0.4.2</version> - <scope>test</scope> </dependency> </dependencies> </dependencyManagement> http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/samples/guice/pom.xml ---------------------------------------------------------------------- diff --git a/samples/guice/pom.xml b/samples/guice/pom.xml index e8ae907..417966a 100644 --- a/samples/guice/pom.xml +++ b/samples/guice/pom.xml @@ -87,7 +87,6 @@ <dependency> <groupId>net.sourceforge.htmlunit</groupId> <artifactId>htmlunit</artifactId> - <version>2.6</version> <scope>test</scope> </dependency> <dependency> @@ -103,12 +102,12 @@ <type>pom</type> <scope>test</scope> </dependency> - <dependency> - <groupId>com.github.mjeanroy</groupId> - <artifactId>junit-servers-jetty</artifactId> - <version>0.4.2</version> - <scope>test</scope> - </dependency> + + <dependency> + <groupId>org.apache.shiro.integrationtests</groupId> + <artifactId>shiro-its-support</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/samples/guice/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java ---------------------------------------------------------------------- diff --git a/samples/guice/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java b/samples/guice/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java deleted file mode 100644 index dcd47e1..0000000 --- a/samples/guice/src/test/java/org/apache/shiro/samples/guice/AbstractContainerIT.java +++ /dev/null @@ -1,142 +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.samples.guice; - -import com.gargoylesoftware.htmlunit.WebClient; -import com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty; -import com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration; -import org.eclipse.jetty.annotations.AnnotationConfiguration; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.resource.FileResource; -import org.eclipse.jetty.webapp.Configuration; -import org.eclipse.jetty.webapp.FragmentConfiguration; -import org.eclipse.jetty.webapp.JettyWebXmlConfiguration; -import org.eclipse.jetty.webapp.MetaInfConfiguration; -import org.eclipse.jetty.webapp.WebAppContext; -import org.eclipse.jetty.webapp.WebInfConfiguration; -import org.eclipse.jetty.webapp.WebXmlConfiguration; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; - -import java.io.File; -import java.io.FilenameFilter; - -import static com.github.mjeanroy.junit.servers.commons.Strings.isNotBlank; -import static org.eclipse.jetty.util.resource.Resource.newResource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public abstract class AbstractContainerIT { - - protected static EmbeddedJetty jetty; - - protected final WebClient webClient = new WebClient(); - - @BeforeClass - public static void startContainer() throws Exception { - - EmbeddedJettyConfiguration config = EmbeddedJettyConfiguration.builder() - .withWebapp(getWarDir()) - .build(); - - jetty = new EmbeddedJetty(config) { - - /** - * Overriding with contents of this pull request, to make fragment scanning work. - * https://github.com/mjeanroy/junit-servers/pull/3 - */ - protected WebAppContext createdWebAppContext() throws Exception { - final String path = configuration.getPath(); - final String webapp = configuration.getWebapp(); - final String classpath = configuration.getClasspath(); - - WebAppContext ctx = new WebAppContext(); - ctx.setClassLoader(Thread.currentThread().getContextClassLoader()); - ctx.setContextPath(path); - - // Useful for WebXmlConfiguration - ctx.setBaseResource(newResource(webapp)); - - ctx.setConfigurations(new Configuration[]{ - new WebInfConfiguration(), - new WebXmlConfiguration(), - new AnnotationConfiguration(), - new JettyWebXmlConfiguration(), - new MetaInfConfiguration(), - new FragmentConfiguration(), - }); - - if (isNotBlank(classpath)) { - // Fix to scan Spring WebApplicationInitializer - // This will add compiled classes to jetty classpath - // See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration - // And more precisely: http://stackoverflow.com/a/18449506/1215828 - File classes = new File(classpath); - FileResource containerResources = new FileResource(classes.toURI()); - ctx.getMetaData().addContainerResource(containerResources); - } - - Server server = getDelegate(); - - ctx.setParentLoaderPriority(true); - ctx.setWar(webapp); - ctx.setServer(server); - - // Add server context - server.setHandler(ctx); - - return ctx; - } - }; - - jetty.start(); - - assertTrue(jetty.isStarted()); - } - - protected static String getBaseUri() { - return "http://localhost:" + jetty.getPort() + "/"; - } - - 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); - } - - @AfterClass - public static void stopContainer() { - if (jetty != null) { - jetty.stop(); - } - } -} http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/samples/guice/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java ---------------------------------------------------------------------- diff --git a/samples/guice/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java b/samples/guice/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java index 4ebc6c7..579357e 100644 --- a/samples/guice/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java +++ b/samples/guice/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java @@ -25,6 +25,7 @@ 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.apache.shiro.testing.web.AbstractContainerIT; import org.junit.Before; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/samples/jaxrs/pom.xml ---------------------------------------------------------------------- diff --git a/samples/jaxrs/pom.xml b/samples/jaxrs/pom.xml index bfe191a..33758e5 100644 --- a/samples/jaxrs/pom.xml +++ b/samples/jaxrs/pom.xml @@ -93,9 +93,8 @@ </dependency> <dependency> - <groupId>com.github.mjeanroy</groupId> - <artifactId>junit-servers-jetty</artifactId> - <version>0.4.2</version> + <groupId>org.apache.shiro.integrationtests</groupId> + <artifactId>shiro-its-support</artifactId> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/samples/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ContainerIntegrationIT.groovy ---------------------------------------------------------------------- diff --git a/samples/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ContainerIntegrationIT.groovy b/samples/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ContainerIntegrationIT.groovy index 6fb66c0..84899d7 100644 --- a/samples/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ContainerIntegrationIT.groovy +++ b/samples/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ContainerIntegrationIT.groovy @@ -18,6 +18,7 @@ */ package org.apache.shiro.web.jaxrs +import org.apache.shiro.testing.web.AbstractContainerIT import org.junit.Test; import static com.jayway.restassured.RestAssured.* http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/samples/jaxrs/src/test/java/org/apache/shiro/web/jaxrs/AbstractContainerIT.java ---------------------------------------------------------------------- diff --git a/samples/jaxrs/src/test/java/org/apache/shiro/web/jaxrs/AbstractContainerIT.java b/samples/jaxrs/src/test/java/org/apache/shiro/web/jaxrs/AbstractContainerIT.java deleted file mode 100644 index 192f9e3..0000000 --- a/samples/jaxrs/src/test/java/org/apache/shiro/web/jaxrs/AbstractContainerIT.java +++ /dev/null @@ -1,148 +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.web.jaxrs; - -import com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty; -import com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration; -import org.apache.shiro.codec.Base64; -import org.eclipse.jetty.annotations.AnnotationConfiguration; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.resource.FileResource; -import org.eclipse.jetty.webapp.Configuration; -import org.eclipse.jetty.webapp.FragmentConfiguration; -import org.eclipse.jetty.webapp.JettyWebXmlConfiguration; -import org.eclipse.jetty.webapp.MetaInfConfiguration; -import org.eclipse.jetty.webapp.WebAppContext; -import org.eclipse.jetty.webapp.WebInfConfiguration; -import org.eclipse.jetty.webapp.WebXmlConfiguration; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; - -import java.io.File; -import java.io.FilenameFilter; -import java.io.UnsupportedEncodingException; - -import static com.github.mjeanroy.junit.servers.commons.Strings.isNotBlank; -import static org.eclipse.jetty.util.resource.Resource.newResource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public abstract class AbstractContainerIT { - - private static EmbeddedJetty jetty; - - private static int port = 0; - - @BeforeClass - public static void startContainer() throws Exception { - - EmbeddedJettyConfiguration config = EmbeddedJettyConfiguration.builder() - .withWebapp(getWarDir()) - .build(); - - jetty = new EmbeddedJetty(config) { - - /** - * Overriding with contents of this pull request, to make fragment scanning work. - * https://github.com/mjeanroy/junit-servers/pull/3 - */ - protected WebAppContext createdWebAppContext() throws Exception { - final String path = configuration.getPath(); - final String webapp = configuration.getWebapp(); - final String classpath = configuration.getClasspath(); - - WebAppContext ctx = new WebAppContext(); - ctx.setClassLoader(Thread.currentThread().getContextClassLoader()); - ctx.setContextPath(path); - - // Useful for WebXmlConfiguration - ctx.setBaseResource(newResource(webapp)); - - ctx.setConfigurations(new Configuration[]{ - new WebInfConfiguration(), - new WebXmlConfiguration(), - new AnnotationConfiguration(), - new JettyWebXmlConfiguration(), - new MetaInfConfiguration(), - new FragmentConfiguration(), - }); - - if (isNotBlank(classpath)) { - // Fix to scan Spring WebApplicationInitializer - // This will add compiled classes to jetty classpath - // See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration - // And more precisely: http://stackoverflow.com/a/18449506/1215828 - File classes = new File(classpath); - FileResource containerResources = new FileResource(classes.toURI()); - ctx.getMetaData().addContainerResource(containerResources); - } - - Server server = getDelegate(); - - ctx.setParentLoaderPriority(true); - ctx.setWar(webapp); - ctx.setServer(server); - - // Add server context - server.setHandler(ctx); - - return ctx; - } - }; - - jetty.start(); - port = jetty.getPort(); - - assertTrue(jetty.isStarted()); - } - - protected static String getBaseUri() { - 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$", ""); - } - - @AfterClass - public static void stopContainer() { - if (jetty != null) { - jetty.stop(); - } - } - - protected static String getBasicAuthorizationHeaderValue(String username, String password) throws UnsupportedEncodingException { - String authorizationHeader = username + ":" + password; - byte[] valueBytes; - valueBytes = authorizationHeader.getBytes("UTF-8"); - authorizationHeader = new String(Base64.encode(valueBytes)); - return "Basic " + authorizationHeader; - } - -} http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/samples/servlet-plugin/pom.xml ---------------------------------------------------------------------- diff --git a/samples/servlet-plugin/pom.xml b/samples/servlet-plugin/pom.xml index 4f32143..66cce9c 100644 --- a/samples/servlet-plugin/pom.xml +++ b/samples/servlet-plugin/pom.xml @@ -84,7 +84,6 @@ <dependency> <groupId>net.sourceforge.htmlunit</groupId> <artifactId>htmlunit</artifactId> - <version>2.6</version> <scope>test</scope> </dependency> <dependency> @@ -103,14 +102,13 @@ <dependency> <groupId>com.github.mjeanroy</groupId> <artifactId>junit-servers-jetty</artifactId> - <version>0.4.2</version> <scope>test</scope> </dependency> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - <scope>runtime</scope> + <groupId>org.apache.shiro.integrationtests</groupId> + <artifactId>shiro-its-support</artifactId> + <scope>test</scope> </dependency> </dependencies> http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/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 deleted file mode 100644 index da02a0b..0000000 --- a/samples/servlet-plugin/src/test/java/org/apache/shiro/test/AbstractContainerIT.java +++ /dev/null @@ -1,147 +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.eclipse.jetty.util.resource.Resource.newResource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty; -import com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration; -import org.eclipse.jetty.annotations.AnnotationConfiguration; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.resource.FileResource; -import org.eclipse.jetty.webapp.Configuration; -import org.eclipse.jetty.webapp.FragmentConfiguration; -import org.eclipse.jetty.webapp.JettyWebXmlConfiguration; -import org.eclipse.jetty.webapp.MetaInfConfiguration; -import org.eclipse.jetty.webapp.WebAppContext; -import org.eclipse.jetty.webapp.WebInfConfiguration; -import org.eclipse.jetty.webapp.WebXmlConfiguration; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; - -import java.io.File; -import java.io.FilenameFilter; - -import static com.github.mjeanroy.junit.servers.commons.Strings.isNotBlank; - -public abstract class AbstractContainerIT { - - private static EmbeddedJetty jetty; - - private static int port = 0; - - protected final WebClient webClient = new WebClient(); - - @BeforeClass - public static void startContainer() throws Exception { - - EmbeddedJettyConfiguration config = EmbeddedJettyConfiguration.builder() - .withWebapp(getWarDir()) - .build(); - - jetty = new EmbeddedJetty(config) { - - /** - * Overriding with contents of this pull request, to make fragment scanning work. - * https://github.com/mjeanroy/junit-servers/pull/3 - */ - protected WebAppContext createdWebAppContext() throws Exception { - final String path = configuration.getPath(); - final String webapp = configuration.getWebapp(); - final String classpath = configuration.getClasspath(); - - WebAppContext ctx = new WebAppContext(); - ctx.setClassLoader(Thread.currentThread().getContextClassLoader()); - ctx.setContextPath(path); - - // Useful for WebXmlConfiguration - ctx.setBaseResource(newResource(webapp)); - - ctx.setConfigurations(new Configuration[]{ - new WebInfConfiguration(), - new WebXmlConfiguration(), - new AnnotationConfiguration(), - new JettyWebXmlConfiguration(), - new MetaInfConfiguration(), - new FragmentConfiguration(), - }); - - if (isNotBlank(classpath)) { - // Fix to scan Spring WebApplicationInitializer - // This will add compiled classes to jetty classpath - // See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration - // And more precisely: http://stackoverflow.com/a/18449506/1215828 - File classes = new File(classpath); - FileResource containerResources = new FileResource(classes.toURI()); - ctx.getMetaData().addContainerResource(containerResources); - } - - Server server = getDelegate(); - - ctx.setParentLoaderPriority(true); - ctx.setWar(webapp); - ctx.setServer(server); - - // Add server context - server.setHandler(ctx); - - return ctx; - } - }; - - jetty.start(); - port = jetty.getPort(); - - assertTrue(jetty.isStarted()); - } - - protected static String getBaseUri() { - 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); - } - - @AfterClass - public static void stopContainer() { - if (jetty != null) { - jetty.stop(); - } - } -} http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/samples/servlet-plugin/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java ---------------------------------------------------------------------- diff --git a/samples/servlet-plugin/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java b/samples/servlet-plugin/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java index 4cef226..658415a 100644 --- a/samples/servlet-plugin/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java +++ b/samples/servlet-plugin/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java @@ -23,6 +23,7 @@ import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import org.apache.shiro.testing.web.AbstractContainerIT; import org.junit.Before; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/samples/web/pom.xml ---------------------------------------------------------------------- diff --git a/samples/web/pom.xml b/samples/web/pom.xml index 0d7dbb0..b2b2e28 100644 --- a/samples/web/pom.xml +++ b/samples/web/pom.xml @@ -85,7 +85,6 @@ <dependency> <groupId>net.sourceforge.htmlunit</groupId> <artifactId>htmlunit</artifactId> - <version>2.6</version> <scope>test</scope> </dependency> <dependency> @@ -105,13 +104,6 @@ <artifactId>jcl-over-slf4j</artifactId> <scope>runtime</scope> </dependency> - - <dependency> - <groupId>net.sourceforge.htmlunit</groupId> - <artifactId>htmlunit</artifactId> - <version>2.6</version> - <scope>test</scope> - </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>apache-jsp</artifactId> @@ -126,9 +118,8 @@ <scope>test</scope> </dependency> <dependency> - <groupId>com.github.mjeanroy</groupId> - <artifactId>junit-servers-jetty</artifactId> - <version>0.4.2</version> + <groupId>org.apache.shiro.integrationtests</groupId> + <artifactId>shiro-its-support</artifactId> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/samples/web/src/test/java/org/apache/shiro/test/AbstractContainerIT.java ---------------------------------------------------------------------- diff --git a/samples/web/src/test/java/org/apache/shiro/test/AbstractContainerIT.java b/samples/web/src/test/java/org/apache/shiro/test/AbstractContainerIT.java deleted file mode 100644 index 4e3e598..0000000 --- a/samples/web/src/test/java/org/apache/shiro/test/AbstractContainerIT.java +++ /dev/null @@ -1,145 +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 com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty; -import com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration; -import org.eclipse.jetty.annotations.AnnotationConfiguration; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.resource.FileResource; -import org.eclipse.jetty.webapp.Configuration; -import org.eclipse.jetty.webapp.FragmentConfiguration; -import org.eclipse.jetty.webapp.JettyWebXmlConfiguration; -import org.eclipse.jetty.webapp.MetaInfConfiguration; -import org.eclipse.jetty.webapp.WebAppContext; -import org.eclipse.jetty.webapp.WebInfConfiguration; -import org.eclipse.jetty.webapp.WebXmlConfiguration; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; - -import java.io.File; -import java.io.FilenameFilter; - -import static com.github.mjeanroy.junit.servers.commons.Strings.isNotBlank; -import static org.eclipse.jetty.util.resource.Resource.newResource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public abstract class AbstractContainerIT { - - private static EmbeddedJetty jetty; - - private static int port = 0; - - protected final WebClient webClient = new WebClient(); - - @BeforeClass - public static void startContainer() throws Exception { - - EmbeddedJettyConfiguration config = EmbeddedJettyConfiguration.builder() - .withWebapp(getWarDir()) - .build(); - - jetty = new EmbeddedJetty(config) { - - /** - * Overriding with contents of this pull request, to make fragment scanning work. - * https://github.com/mjeanroy/junit-servers/pull/3 - */ - protected WebAppContext createdWebAppContext() throws Exception { - final String path = configuration.getPath(); - final String webapp = configuration.getWebapp(); - final String classpath = configuration.getClasspath(); - - WebAppContext ctx = new WebAppContext(); - ctx.setClassLoader(Thread.currentThread().getContextClassLoader()); - ctx.setContextPath(path); - - // Useful for WebXmlConfiguration - ctx.setBaseResource(newResource(webapp)); - - ctx.setConfigurations(new Configuration[]{ - new WebInfConfiguration(), - new WebXmlConfiguration(), - new AnnotationConfiguration(), - new JettyWebXmlConfiguration(), - new MetaInfConfiguration(), - new FragmentConfiguration(), - }); - - if (isNotBlank(classpath)) { - // Fix to scan Spring WebApplicationInitializer - // This will add compiled classes to jetty classpath - // See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration - // And more precisely: http://stackoverflow.com/a/18449506/1215828 - File classes = new File(classpath); - FileResource containerResources = new FileResource(classes.toURI()); - ctx.getMetaData().addContainerResource(containerResources); - } - - Server server = getDelegate(); - - ctx.setParentLoaderPriority(true); - ctx.setWar(webapp); - ctx.setServer(server); - - // Add server context - server.setHandler(ctx); - - return ctx; - } - }; - - jetty.start(); - port = jetty.getPort(); - - assertTrue(jetty.isStarted()); - } - - protected static String getBaseUri() { - 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); - } - - @AfterClass - public static void stopContainer() { - if (jetty != null) { - jetty.stop(); - } - } -} http://git-wip-us.apache.org/repos/asf/shiro/blob/e6db45c7/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 index 52709ee..3b8e5b8 100644 --- a/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java +++ b/samples/web/src/test/java/org/apache/shiro/test/ContainerIntegrationIT.java @@ -24,6 +24,7 @@ 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.apache.shiro.testing.web.AbstractContainerIT; import org.junit.Before; import org.junit.Test;
