[java-idp-integration-tests] 03/08: Unpack and configure Servlet containers optionally.

Tom Zeller tzeller at dragonacea.biz
Tue Aug 2 13:28:49 EDT 2016


This is an automated email from the git hooks/post-receive script.

tzeller pushed a commit to branch master
in repository java-idp-integration-tests.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=0f35b5e680832257de666c3aed7e90ec25e837d4

commit 0f35b5e680832257de666c3aed7e90ec25e837d4
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Mon Jul 18 16:04:54 2016 -0500

    Unpack and configure Servlet containers optionally.
---
 pom.xml                                            | 287 ++++++++++++---------
 .../shibboleth/idp/test/BaseIntegrationTest.java   | 225 ++++++++--------
 .../shibboleth/idp/test/TomcatServerProcess.java   |  15 ++
 3 files changed, 299 insertions(+), 228 deletions(-)

diff --git a/pom.xml b/pom.xml
index adbff56..7ea1b4c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -329,82 +329,6 @@
                             <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}</outputDirectory>
                         </configuration>
                     </execution>
-                    <!-- Unpack idp-jetty-base. -->
-                    <execution>
-                        <id>unpack-idp-jetty-base</id>
-                        <phase>compile</phase>
-                        <goals>
-                            <goal>unpack</goal>
-                        </goals>
-                        <configuration>
-                            <artifactItems>
-                                <artifactItem>
-                                    <groupId>net.shibboleth.idp</groupId>
-                                    <artifactId>idp-jetty-base</artifactId>
-                                    <version>${idp-jetty-base.version}</version>
-                                    <type>tar.gz</type>
-                                </artifactItem>
-                            </artifactItems>
-                            <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}</outputDirectory>
-                        </configuration>
-                    </execution>
-                    <!-- Unpack idp-tomcat-base. -->
-                    <execution>
-                        <id>unpack-idp-tomcat-base</id>
-                        <phase>compile</phase>
-                        <goals>
-                            <goal>unpack</goal>
-                        </goals>
-                        <configuration>
-                            <artifactItems>
-                                <artifactItem>
-                                    <groupId>net.shibboleth.idp</groupId>
-                                    <artifactId>idp-tomcat-base</artifactId>
-                                    <version>${idp-tomcat-base.version}</version>
-                                    <type>tar.gz</type>
-                                </artifactItem>
-                            </artifactItems>
-                            <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}</outputDirectory>
-                        </configuration>
-                    </execution>
-                    <!-- Unpack jetty-distribution to test-distributions directory. -->
-                    <execution>
-                        <id>unpack-jetty-distribution</id>
-                        <phase>compile</phase>
-                        <goals>
-                            <goal>unpack</goal>
-                        </goals>
-                        <configuration>
-                            <artifactItems>
-                                <artifactItem>
-                                    <groupId>org.eclipse.jetty</groupId>
-                                    <artifactId>jetty-distribution</artifactId>
-                                    <version>${jetty.version}</version>
-                                    <type>zip</type>
-                                </artifactItem>
-                            </artifactItems>
-                            <outputDirectory>${test-distributions.directory}</outputDirectory>
-                        </configuration>
-                    </execution>
-                    <!-- Unpack Tomcat to test-distributions directory. -->
-                    <execution>
-                        <id>unpack-tomcat-distribution</id>
-                        <phase>compile</phase>
-                        <goals>
-                            <goal>unpack</goal>
-                        </goals>
-                        <configuration>
-                            <artifactItems>
-                                <artifactItem>
-                                    <groupId>org.apache.tomcat</groupId>
-                                    <artifactId>tomcat</artifactId>
-                                    <version>${tomcat.version}</version>
-                                    <type>tar.gz</type>
-                                </artifactItem>
-                            </artifactItems>
-                            <outputDirectory>${test-distributions.directory}</outputDirectory>
-                        </configuration>
-                    </execution>
                     <!-- Copy testbed war to IdP distribution directory. -->
                     <execution>
                         <id>copy-testbed-war</id>
@@ -445,48 +369,6 @@
                             <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}/webapp/WEB-INF/lib/</outputDirectory>
                         </configuration>
                     </execution>
-                    <!-- Copy testbed deployment descriptor from testbed jar to Jetty. -->
-                    <execution>
-                        <id>copy-testbed-deployment-descriptor-jetty</id>
-                        <phase>compile</phase>
-                        <goals>
-                            <goal>unpack</goal>
-                        </goals>
-                        <configuration>
-                            <artifactItems>
-                                <artifactItem>
-                                   <groupId>net.shibboleth.idp</groupId>
-                                    <artifactId>idp-testbed</artifactId>
-                                    <version>${testbed.version}</version>
-                                    <type>jar</type>
-                                    <classifier>${testbed.classifier}</classifier>
-                                    <includes>webapps/0-idp-testbed.xml</includes>
-                                </artifactItem>
-                            </artifactItems>
-                            <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}/jetty-base/</outputDirectory>
-                        </configuration>
-                    </execution>
-                    <!-- Copy testbed context descriptor from testbed jar to Tomcat. -->
-                    <execution>
-                        <id>copy-testbed-context-descriptor-tomcat</id>
-                        <phase>compile</phase>
-                        <goals>
-                            <goal>unpack</goal>
-                        </goals>
-                        <configuration>
-                            <artifactItems>
-                                <artifactItem>
-                                   <groupId>net.shibboleth.idp</groupId>
-                                    <artifactId>idp-testbed</artifactId>
-                                    <version>${testbed.version}</version>
-                                    <type>jar</type>
-                                    <classifier>${testbed.classifier}</classifier>
-                                    <includes>conf/Catalina/localhost/ROOT.xml</includes>
-                                </artifactItem>
-                            </artifactItems>
-                            <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}/tomcat-base/</outputDirectory>
-                        </configuration>
-                    </execution>
                 </executions>
             </plugin>
             <!-- Also delete the test-distributions directory during clean. -->
@@ -547,11 +429,11 @@
 
     </build>
 
-    <!--
+    <profiles>
+        <!--
         Remove the testbed dependency classifier when using Eclipse, but not from the command line.
         See https://wiki.eclipse.org/M2E-WTP_FAQ
-    -->
-    <profiles>
+        -->
         <profile>
             <id>m2e</id>
             <activation>
@@ -563,6 +445,169 @@
                 <testbed.classifier></testbed.classifier>
             </properties>
         </profile>
+        <!--
+        The jetty profile unpacks Jetty, idp-jetty-base, and adds the testbed to Jetty.
+        The jetty profile is active by default and not active if the 'tomcat' system property is present.
+        -->
+        <profile>
+            <id>jetty</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+                <property>
+                    <name>!tomcat</name>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-dependency-plugin</artifactId>
+                        <executions>
+                            <!-- Unpack jetty-distribution to test-distributions directory. -->
+                            <execution>
+                                <id>unpack-jetty-distribution</id>
+                                <phase>compile</phase>
+                                <goals>
+                                    <goal>unpack</goal>
+                                </goals>
+                                <configuration>
+                                    <artifactItems>
+                                        <artifactItem>
+                                            <groupId>org.eclipse.jetty</groupId>
+                                            <artifactId>jetty-distribution</artifactId>
+                                            <version>${jetty.version}</version>
+                                            <type>zip</type>
+                                        </artifactItem>
+                                    </artifactItems>
+                                    <outputDirectory>${test-distributions.directory}</outputDirectory>
+                                </configuration>
+                            </execution>
+                            <!-- Unpack idp-jetty-base. -->
+                            <execution>
+                                <id>unpack-idp-jetty-base</id>
+                                <phase>compile</phase>
+                                <goals>
+                                    <goal>unpack</goal>
+                                </goals>
+                                <configuration>
+                                    <artifactItems>
+                                        <artifactItem>
+                                            <groupId>net.shibboleth.idp</groupId>
+                                            <artifactId>idp-jetty-base</artifactId>
+                                            <version>${idp-jetty-base.version}</version>
+                                            <type>tar.gz</type>
+                                        </artifactItem>
+                                    </artifactItems>
+                                    <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}</outputDirectory>
+                                </configuration>
+                            </execution>
+                            <!-- Copy testbed deployment descriptor from testbed jar to Jetty. -->
+                            <execution>
+                                <id>copy-testbed-deployment-descriptor-jetty</id>
+                                <phase>compile</phase>
+                                <goals>
+                                    <goal>unpack</goal>
+                                </goals>
+                                <configuration>
+                                    <artifactItems>
+                                        <artifactItem>
+                                            <groupId>net.shibboleth.idp</groupId>
+                                            <artifactId>idp-testbed</artifactId>
+                                            <version>${testbed.version}</version>
+                                            <type>jar</type>
+                                            <classifier>${testbed.classifier}</classifier>
+                                            <includes>webapps/0-idp-testbed.xml</includes>
+                                        </artifactItem>
+                                    </artifactItems>
+                                    <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}/jetty-base/</outputDirectory>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <!--
+        The tomcat profile unpacks Tomcat, idp-tomcat-base, and adds the testbed webapp to Tomcat.
+        The tomcat profile is active if the 'tomcat' system property is present.
+        -->
+        <profile>
+            <id>tomcat</id>
+            <activation>
+                <property>
+                    <name>tomcat</name>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-dependency-plugin</artifactId>
+                        <executions>
+                            <!-- Unpack Tomcat to test-distributions directory. -->
+                            <execution>
+                                <id>unpack-tomcat-distribution</id>
+                                <phase>compile</phase>
+                                <goals>
+                                    <goal>unpack</goal>
+                                </goals>
+                                <configuration>
+                                    <artifactItems>
+                                        <artifactItem>
+                                            <groupId>org.apache.tomcat</groupId>
+                                            <artifactId>tomcat</artifactId>
+                                            <version>${tomcat.version}</version>
+                                            <type>tar.gz</type>
+                                        </artifactItem>
+                                    </artifactItems>
+                                    <outputDirectory>${test-distributions.directory}</outputDirectory>
+                                </configuration>
+                            </execution>
+                            <!-- Unpack idp-tomcat-base. -->
+                            <execution>
+                                <id>unpack-idp-tomcat-base</id>
+                                <phase>compile</phase>
+                                <goals>
+                                    <goal>unpack</goal>
+                                </goals>
+                                <configuration>
+                                    <artifactItems>
+                                        <artifactItem>
+                                            <groupId>net.shibboleth.idp</groupId>
+                                            <artifactId>idp-tomcat-base</artifactId>
+                                            <version>${idp-tomcat-base.version}</version>
+                                            <type>tar.gz</type>
+                                        </artifactItem>
+                                    </artifactItems>
+                                    <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}</outputDirectory>
+                                </configuration>
+                            </execution>
+                            <!-- Copy testbed context descriptor from testbed jar to Tomcat. -->
+                            <execution>
+                                <id>copy-testbed-context-descriptor-tomcat</id>
+                                <phase>compile</phase>
+                                <goals>
+                                    <goal>unpack</goal>
+                                </goals>
+                                <configuration>
+                                    <artifactItems>
+                                        <artifactItem>
+                                            <groupId>net.shibboleth.idp</groupId>
+                                            <artifactId>idp-testbed</artifactId>
+                                            <version>${testbed.version}</version>
+                                            <type>jar</type>
+                                            <classifier>${testbed.classifier}</classifier>
+                                            <includes>conf/Catalina/localhost/ROOT.xml</includes>
+                                        </artifactItem>
+                                    </artifactItems>
+                                    <outputDirectory>${test-distributions.directory}/shibboleth-identity-provider-${idp.version}/tomcat-base/</outputDirectory>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
     </profiles>
 
 </project>
diff --git a/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
index cce45db..6919693 100644
--- a/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
@@ -255,16 +255,16 @@ public abstract class BaseIntegrationTest
     @NonnullAfterInit protected Path pathToLDAPProperties;
 
     /** Path to jetty.base. */
-    @NonnullAfterInit protected Path pathToJettyBase;
+    @Nullable protected Path pathToJettyBase;
 
     /** Path to jetty.home. */
-    @NonnullAfterInit protected Path pathToJettyHome;
+    @Nullable protected Path pathToJettyHome;
     
     /** Path to tomcat.base. */
-    @NonnullAfterInit protected Path pathToTomcatBase;
+    @Nullable protected Path pathToTomcatBase;
 
     /** Path to tomcat.home. */
-    @NonnullAfterInit protected Path pathToTomcatHome;
+    @Nullable protected Path pathToTomcatHome;
 
     /** Pattern used when creating per test idp.home directory. Defaults to yyyyMMdd-HHmmssSS. **/
     @Nullable protected String idpHomePattern = "yyyyMMdd-HHmmssSS";
@@ -324,44 +324,18 @@ public abstract class BaseIntegrationTest
     @Nonnull private final Logger log = LoggerFactory.getLogger(BaseIntegrationTest.class);
 
     /**
-     * Setup paths to the IdP and Jetty.
+     * Set up paths to the IdP.
      * 
      * @throws Exception if an error occurs
      */
     @BeforeClass
-    public void setUpPaths() throws Exception {
+    public void setUpIdPPaths() throws Exception {
 
         // Path to the project build directory.
         final Path buildPath = Paths.get(TEST_DISTRIBUTIONS_DIRECTORY);
         log.debug("Path to build directory '{}'", buildPath.toAbsolutePath());
         Assert.assertTrue(buildPath.toAbsolutePath().toFile().exists(), "Path to build directory not found");
 
-        // Path to Jetty distribution
-        try (DirectoryStream<Path> stream = Files.newDirectoryStream(buildPath, "*jetty-distribution-*")) {
-            for (Path entry : stream) {
-                pathToJettyHome = entry;
-                break;
-            }
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-        log.debug("Path to jetty.home '{}'", pathToJettyHome.toAbsolutePath());
-        Assert.assertNotNull(pathToJettyHome, "Path to jetty.home not found");
-        Assert.assertTrue(pathToJettyHome.toAbsolutePath().toFile().exists(), "Path to jetty.home not found");
-        
-        // Path to Tomcat distribution
-        try (DirectoryStream<Path> stream = Files.newDirectoryStream(buildPath, "*apache-tomcat-*")) {
-            for (Path entry : stream) {
-                pathToTomcatHome = entry;
-                break;
-            }
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-        log.debug("Path to tomcat.home '{}'", pathToTomcatHome.toAbsolutePath());
-        Assert.assertNotNull(pathToTomcatHome, "Path to tomcat.home not found");
-        Assert.assertTrue(pathToTomcatHome.toAbsolutePath().toFile().exists(), "Path to tomcat.home not found");
-
         // Path to idp.home from distribution.
         Path pathToDistIdPHome = null;
         try (DirectoryStream<Path> stream = Files.newDirectoryStream(buildPath, "*shibboleth-identity-provider-*")) {
@@ -391,18 +365,6 @@ public abstract class BaseIntegrationTest
         // Set idp.home system property, replace '\' with '/' for Windows
         System.setProperty("idp.home", pathToIdPHome.toAbsolutePath().toString().replace('\\', '/'));
 
-        // Path to jetty.base
-        pathToJettyBase = pathToIdPHome.resolve(Paths.get("jetty-base"));
-        log.debug("Path to jetty.base '{}'", pathToJettyBase.toAbsolutePath());
-        Assert.assertNotNull(pathToJettyBase, "Path to jetty.base not found");
-        Assert.assertTrue(pathToJettyBase.toAbsolutePath().toFile().exists(), "Path to jetty.base not found");
-
-        // Path to tomcat.base
-        pathToTomcatBase = pathToIdPHome.resolve(Paths.get("tomcat-base"));
-        log.debug("Path to tomcat.base '{}'", pathToTomcatBase.toAbsolutePath());
-        Assert.assertNotNull(pathToTomcatBase, "Path to tomcat.base not found");
-        Assert.assertTrue(pathToTomcatBase.toAbsolutePath().toFile().exists(), "Path to tomcat.base not found");
-        
         // Path to conf/idp.properties
         pathToIdPProperties = Paths.get(pathToIdPHome.toAbsolutePath().toString(), "conf", "idp.properties");
         Assert.assertTrue(pathToIdPProperties.toFile().exists(), "Path to conf/idp.properties not found");
@@ -410,10 +372,96 @@ public abstract class BaseIntegrationTest
         // Path to conf/ldap.properties
         pathToLDAPProperties = Paths.get(pathToIdPHome.toAbsolutePath().toString(), "conf", "ldap.properties");
         Assert.assertTrue(pathToLDAPProperties.toFile().exists(), "Path to conf/ldap.properties not found");
+    }
+
+    /**
+     * Set up paths to Tomcat if they exist.
+     * 
+     * @throws Exception if an error occurs
+     */
+    @BeforeClass
+    public void setUpTomcatPaths() throws Exception {
+
+        // Path to the project build directory.
+        final Path buildPath = Paths.get(TEST_DISTRIBUTIONS_DIRECTORY);
+        log.debug("Path to build directory '{}'", buildPath.toAbsolutePath());
+        Assert.assertTrue(buildPath.toAbsolutePath().toFile().exists(), "Path to build directory not found");
 
-        // Make tmp directories exist
-        Assert.assertTrue(pathToJettyBase.resolve("tmp").toFile().exists(), "Path to jetty.base/tmp/ not found");
-        Assert.assertTrue(pathToTomcatBase.resolve("temp").toFile().exists(), "Path to tomcat.base/temp/ not found");
+        // Path to Tomcat distribution
+        try (DirectoryStream<Path> stream = Files.newDirectoryStream(buildPath, "*apache-tomcat-*")) {
+            for (Path entry : stream) {
+                pathToTomcatHome = entry;
+                break;
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        log.debug("Path to tomcat.home '{}'", pathToTomcatHome);
+
+        if (pathToTomcatHome != null) {
+            log.debug("Path to tomcat.home '{}'", pathToTomcatHome.toAbsolutePath());
+            Assert.assertTrue(pathToTomcatHome.toAbsolutePath().toFile().exists(), "Path to tomcat.home not found");
+
+            // Path to tomcat.base
+            pathToTomcatBase = pathToIdPHome.resolve(Paths.get("tomcat-base"));
+            log.debug("Path to tomcat.base '{}'", pathToTomcatBase.toAbsolutePath());
+            Assert.assertNotNull(pathToTomcatBase, "Path to tomcat.base not found");
+            Assert.assertTrue(pathToTomcatBase.toAbsolutePath().toFile().exists(), "Path to tomcat.base not found");
+
+            // Make tmp directories exist
+            Assert.assertTrue(pathToTomcatBase.resolve("temp").toFile().exists(), "Path to temp/ not found");
+            
+            // Modify setenv.sh with per-test idp.home directory
+            final Path pathToSetenvSh = pathToTomcatBase.resolve(Paths.get("bin", "setenv.sh"));
+            Assert.assertTrue(pathToSetenvSh.toAbsolutePath().toFile().exists(), "Path to setenv.sh not found");
+            final String oldTextSetenvSh = "-Didp.home=/opt/shibboleth-idp";
+            final String newTextSetenvSh = "-Didp.home=" + pathToIdPHome.toAbsolutePath().toString();
+            replaceFile(pathToSetenvSh, oldTextSetenvSh, newTextSetenvSh);
+
+            // Modify context descriptor with per-test idp.home directory
+            final Path pathToIdpXML = pathToTomcatBase.resolve(Paths.get("conf", "Catalina", "localhost", "idp.xml"));
+            Assert.assertTrue(pathToIdpXML.toAbsolutePath().toFile().exists(), "Path to idp.xml not found");
+            replaceFile(pathToIdpXML, "/war/idp.war\"", "/webapp/\"");
+        }
+    }
+
+    /**
+     * Set up paths to Jetty if they exist.
+     * 
+     * @throws Exception if an error occurs
+     */
+    @BeforeClass
+    public void setUpJettyPaths() throws Exception {
+
+        // Path to the project build directory.
+        final Path buildPath = Paths.get(TEST_DISTRIBUTIONS_DIRECTORY);
+        log.debug("Path to build directory '{}'", buildPath.toAbsolutePath());
+        Assert.assertTrue(buildPath.toAbsolutePath().toFile().exists(), "Path to build directory not found");
+
+        // Path to Jetty distribution
+        try (DirectoryStream<Path> stream = Files.newDirectoryStream(buildPath, "*jetty-distribution-*")) {
+            for (Path entry : stream) {
+                pathToJettyHome = entry;
+                break;
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        log.debug("Path to jetty.home '{}'", pathToJettyHome);
+
+        if (pathToJettyHome != null) {
+            log.debug("Path to jetty.home '{}'", pathToJettyHome.toAbsolutePath());
+            Assert.assertTrue(pathToJettyHome.toAbsolutePath().toFile().exists(), "Path to jetty.home not found");
+
+            // Path to jetty.base
+            pathToJettyBase = pathToIdPHome.resolve(Paths.get("jetty-base"));
+            log.debug("Path to jetty.base '{}'", pathToJettyBase.toAbsolutePath());
+            Assert.assertNotNull(pathToJettyBase, "Path to jetty.base not found");
+            Assert.assertTrue(pathToJettyBase.toAbsolutePath().toFile().exists(), "Path to jetty.base not found");
+
+            // Make tmp directories exist
+            Assert.assertTrue(pathToJettyBase.resolve("tmp").toFile().exists(), "Path to jetty.base/tmp/ not found");
+        }
     }
 
     /**
@@ -508,7 +556,7 @@ public abstract class BaseIntegrationTest
      * 
      * @throws Exception if an error occurs.
      */
-    @BeforeClass(dependsOnMethods = {"setUpBaseURLs", "setUpPaths", "setUpSauceLabsClientIPRange"})
+    @BeforeClass(dependsOnMethods = {"setUpBaseURLs", "setUpIdPPaths", "setUpJettyPaths", "setUpTomcatPaths", "setUpSauceLabsClientIPRange"})
     public void setUpEndpoints() throws Exception {
 
         // Access control from non-localhost.
@@ -521,20 +569,24 @@ public abstract class BaseIntegrationTest
         replaceLDAPProperty("idp.authn.LDAP.ldapURL", "ldap://localhost:" + ldapPort);
 
         // Jetty endpoints.
-        final Path pathToJettyIdPIni = pathToJettyBase.resolve(Paths.get("start.d", "idp.ini"));
-        replaceProperty(pathToJettyIdPIni, "jetty.host", privateSecureAddress);
-        replaceProperty(pathToJettyIdPIni, "jetty.https.port", Integer.toString(securePort));
-        replaceProperty(pathToJettyIdPIni, "jetty.backchannel.port", Integer.toString(backchannelPort));
-        replaceProperty(pathToJettyIdPIni, "jetty.nonhttps.host", privateAddress);
-        replaceProperty(pathToJettyIdPIni, "jetty.nonhttps.port", Integer.toString(port));
+        if (pathToJettyBase != null) {
+            final Path pathToJettyIdPIni = pathToJettyBase.resolve(Paths.get("start.d", "idp.ini"));
+            replaceProperty(pathToJettyIdPIni, "jetty.host", privateSecureAddress);
+            replaceProperty(pathToJettyIdPIni, "jetty.https.port", Integer.toString(securePort));
+            replaceProperty(pathToJettyIdPIni, "jetty.backchannel.port", Integer.toString(backchannelPort));
+            replaceProperty(pathToJettyIdPIni, "jetty.nonhttps.host", privateAddress);
+            replaceProperty(pathToJettyIdPIni, "jetty.nonhttps.port", Integer.toString(port));
+        }
         
         // Tomcat endpoints.
-        final Path pathToCatalinaProperties = pathToTomcatBase.resolve(Paths.get("conf", "catalina.properties"));
-        replaceFile(pathToCatalinaProperties, "tomcat.host=.*", "tomcat.host=" + privateSecureAddress);
-        replaceFile(pathToCatalinaProperties, "tomcat.https.port=.*", "tomcat.https.port=" + Integer.toString(securePort));
-        replaceFile(pathToCatalinaProperties, "tomcat.backchannel.port=.*", "tomcat.backchannel.port=" + Integer.toString(backchannelPort));
-        replaceFile(pathToCatalinaProperties, "tomcat.nonhttps.host=.*", "tomcat.nonhttps.host=" + privateAddress);
-        replaceFile(pathToCatalinaProperties, "tomcat.nonhttps.port=.*", "tomcat.nonhttps.port=" + Integer.toString(port));
+        if (pathToTomcatBase != null) {
+            final Path pathToCatalinaProperties = pathToTomcatBase.resolve(Paths.get("conf", "catalina.properties"));
+            replaceFile(pathToCatalinaProperties, "tomcat.host=.*", "tomcat.host=" + privateSecureAddress);
+            replaceFile(pathToCatalinaProperties, "tomcat.https.port=.*", "tomcat.https.port=" + Integer.toString(securePort));
+            replaceFile(pathToCatalinaProperties, "tomcat.backchannel.port=.*", "tomcat.backchannel.port=" + Integer.toString(backchannelPort));
+            replaceFile(pathToCatalinaProperties, "tomcat.nonhttps.host=.*", "tomcat.nonhttps.host=" + privateAddress);
+            replaceFile(pathToCatalinaProperties, "tomcat.nonhttps.port=.*", "tomcat.nonhttps.port=" + Integer.toString(port));
+        }
 
         // Metadata.
         replaceIdPHomeFile(Paths.get("metadata", "example-metadata.xml"), "http://localhost:8080", baseURL);
@@ -546,7 +598,7 @@ public abstract class BaseIntegrationTest
      * 
      * @throws Exception
      */
-    @BeforeClass(enabled = true, dependsOnMethods = {"setUpPaths"})
+    @BeforeClass(enabled = true, dependsOnMethods = {"setUpIdPPaths"})
     public void setUpDebugLogging() throws Exception {
         final Path pathToLogbackXML = Paths.get("conf", "logback.xml");
 
@@ -566,7 +618,7 @@ public abstract class BaseIntegrationTest
      * 
      * @throws Exception
      */
-    @BeforeClass(enabled = true, dependsOnMethods = {"setUpPaths"})
+    @BeforeClass(enabled = true, dependsOnMethods = {"setUpIdPPaths"})
     public void setUpExampleMetadataProvider() throws Exception {
         final Path pathToMetadataProvidersXML = Paths.get("conf", "metadata-providers.xml");
 
@@ -582,7 +634,7 @@ public abstract class BaseIntegrationTest
      * 
      * @throws Exception
      */
-    @BeforeClass(enabled = true, dependsOnMethods = {"setUpPaths"})
+    @BeforeClass(enabled = true, dependsOnMethods = {"setUpIdPPaths"})
     public void setUpStorageServlet() throws Exception {
 
         final Path pathToIdPWebXML = pathToIdPHome.resolve(Paths.get("webapp", "WEB-INF", "web.xml"));
@@ -612,42 +664,6 @@ public abstract class BaseIntegrationTest
     }
 
     /**
-     * Set per-test idp.home in setenv.sh. Use expanded IdP webapp.
-     * 
-     * @throws IOException
-     */
-    @BeforeClass(dependsOnMethods = {"setUpAddresses", "setUpAvailablePorts"})
-    public void setUpTomcatIdPHome() throws IOException {
-        final Path pathToSetenvSh = pathToTomcatBase.resolve(Paths.get("bin", "setenv.sh"));
-        Assert.assertTrue(pathToSetenvSh.toAbsolutePath().toFile().exists(), "Path to setenv.sh not found");
-
-        final String oldTextSetenvSh = "-Didp.home=/opt/shibboleth-idp";
-        final String newTextSetenvSh = "-Didp.home=" + pathToIdPHome.toAbsolutePath().toString();
-        replaceFile(pathToSetenvSh, oldTextSetenvSh, newTextSetenvSh);
-
-        final Path pathToIdpXML = pathToTomcatBase.resolve(Paths.get("conf", "Catalina", "localhost", "idp.xml"));
-        Assert.assertTrue(pathToIdpXML.toAbsolutePath().toFile().exists(), "Path to idp.xml not found");
-
-        replaceFile(pathToIdpXML, "/war/idp.war\"", "/webapp/\"");
-    }
-
-    /**
-     * Append additional server commands to Tomcat setenv.sh.
-     * 
-     * @throws IOException
-     */
-    public void setUpTomcatServerCommands() throws IOException {
-        final Path pathToSetenvSh = pathToTomcatBase.resolve(Paths.get("bin", "setenv.sh"));
-        Assert.assertTrue(pathToSetenvSh.toAbsolutePath().toFile().exists(), "Path to setenv.sh not found");
-
-        for (final String serverCommand : serverCommands) {
-            if (serverCommand.startsWith("-D")) {
-                replaceFile(pathToSetenvSh, "\"$", " " + serverCommand + "\"");
-            }
-        }
-    }
-
-    /**
      * Set the {@link #IDP_XML_SECURITY_MANAGER_PROP_NAME} property to {@link #IDP_XML_SECURITY_MANAGER_PROP_VALUE}.
      * Save the previous value.
      */
@@ -684,7 +700,7 @@ public abstract class BaseIntegrationTest
      *
      * @throws Exception
      */
-    @BeforeClass(dependsOnMethods = {"setUpPaths"})
+    @BeforeClass(dependsOnMethods = {"setUpIdPPaths"})
     public void disableLDAPSTARTTLS() throws Exception {
         replaceLDAPProperty("idp.authn.LDAP.useStartTLS", "false");
     }
@@ -769,11 +785,7 @@ public abstract class BaseIntegrationTest
         server = new TomcatServerProcess();
         server.setServletContainerBasePath(pathToTomcatBase);
         server.setServletContainerHomePath(pathToTomcatHome);
-        try {
-            setUpTomcatServerCommands();
-        } catch (IOException e) {
-            throw new ComponentInitializationException(e);
-        }
+        server.setAdditionalCommands(serverCommands);
         server.setStatusPageURL(getBaseURL() + StatusTest.statusPath);
         server.initialize();
         server.start();
@@ -867,8 +879,7 @@ public abstract class BaseIntegrationTest
      * @param replacement string to be substituted for each match
      * @throws IOException if the file cannot be overwritten
      */
-    public static void replaceFile(@Nonnull final Path pathToFile,
-            @Nonnull @NotEmpty final String regex,
+    public static void replaceFile(@Nonnull final Path pathToFile, @Nonnull @NotEmpty final String regex,
             @Nonnull @NotEmpty final String replacement) throws IOException {
         LoggerFactory.getLogger(BaseIntegrationTest.class).debug("Replacing regex '{}' with '{}' in file '{}'", regex,
                 replacement, pathToFile);
diff --git a/src/test/java/net/shibboleth/idp/test/TomcatServerProcess.java b/src/test/java/net/shibboleth/idp/test/TomcatServerProcess.java
index da9ccdc..c80d394 100644
--- a/src/test/java/net/shibboleth/idp/test/TomcatServerProcess.java
+++ b/src/test/java/net/shibboleth/idp/test/TomcatServerProcess.java
@@ -28,6 +28,7 @@ import javax.annotation.Nonnull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.SocketUtils;
+import org.testng.Assert;
 
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 
@@ -41,6 +42,20 @@ public class TomcatServerProcess extends AbstractServerProcess {
     @Override
     protected void doInitialize() throws ComponentInitializationException {
         super.doInitialize();
+        
+        final Path pathToSetenvSh = getServletContainerBasePath().resolve(Paths.get("bin", "setenv.sh"));
+        Assert.assertTrue(pathToSetenvSh.toAbsolutePath().toFile().exists(), "Path to setenv.sh not found");
+
+        for (final String serverCommand : getAdditionalCommands()) {
+            if (serverCommand.startsWith("-D")) {
+                try {
+                    BaseIntegrationTest.replaceFile(pathToSetenvSh, "\"$", " " + serverCommand + "\"");
+                } catch (IOException e) {
+                    log.error("Unable to replace file", e);
+                    throw new ComponentInitializationException(e);
+                }
+            }
+        }
 
         // Add CATALINA_BASE to environment
         getProcessBuilder().environment().put("CATALINA_BASE", getServletContainerBasePath().toAbsolutePath().toString());

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list