[jboss-cvs] JBossAS SVN: r87710 - in projects/bootstrap/trunk/impl-as/src: test/java/org/jboss/bootstrap/impl/as and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 23 03:28:10 EDT 2009
Author: ALRubinger
Date: 2009-04-23 03:28:09 -0400 (Thu, 23 Apr 2009)
New Revision: 87710
Added:
projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/common/
projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/common/TestUtils.java
Modified:
projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationInitializerImpl.java
projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationInitializationTestCase.java
projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/JBossASServerInitializationTestCase.java
Log:
[JBBOOT-31] Remove all environment-specific testing elements to make the tests reproducible
Modified: projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationInitializerImpl.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationInitializerImpl.java 2009-04-23 07:14:22 UTC (rev 87709)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationInitializerImpl.java 2009-04-23 07:28:09 UTC (rev 87710)
@@ -101,9 +101,13 @@
final URL bootLibLocation = config.getBootLibraryLocation();
final String bootLibDefault = jbossHome + JBossASConfigurationInitializer.DEFAULT_VALUE_LIBRARY_URL_SUFFIX;
final String currentBootLibLocation = bootLibLocation != null ? bootLibLocation.toExternalForm() : null;
- final String resolvedbootLibLocation = this.resolvePropertyValue(
- JBossASServerConfig.PROP_KEY_JBOSSAS_BOOT_LIBRARY_URL, currentBootLibLocation, bootLibDefault, configProps);
- config.bootLibraryLocation(resolvedbootLibLocation);
+ String resolvedBootLibLocation = this.resolvePropertyValue(JBossASServerConfig.PROP_KEY_JBOSSAS_BOOT_LIBRARY_URL,
+ currentBootLibLocation, bootLibDefault, configProps);
+ if (!resolvedBootLibLocation.endsWith(trailingSlash))
+ {
+ resolvedBootLibLocation = resolvedBootLibLocation + trailingSlash;
+ }
+ config.bootLibraryLocation(resolvedBootLibLocation);
}
Added: projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/common/TestUtils.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/common/TestUtils.java (rev 0)
+++ projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/common/TestUtils.java 2009-04-23 07:28:09 UTC (rev 87710)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.impl.as.common;
+
+import java.net.URL;
+
+/**
+ * TestUtils
+ *
+ * Common Test Utilities
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class TestUtils
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Location of $JBOSS_HOME relative to the test resources root
+ */
+ private static final String LOCATION_JBOSS_HOME = "jbossas/";
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor, no external instanciation
+ */
+ private TestUtils()
+ {
+ // NOOP
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Returns a valid JBOSS_HOME for use in testing
+ * @return
+ * @throws Throwable
+ */
+ public static URL getJBossHome() throws Throwable
+ {
+ final URL testBase = TestUtils.class.getProtectionDomain().getCodeSource().getLocation();
+ final URL jbossHome = new URL(testBase, LOCATION_JBOSS_HOME);
+ return jbossHome;
+ }
+
+}
Modified: projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationInitializationTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationInitializationTestCase.java 2009-04-23 07:14:22 UTC (rev 87709)
+++ projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationInitializationTestCase.java 2009-04-23 07:28:09 UTC (rev 87710)
@@ -22,10 +22,11 @@
package org.jboss.bootstrap.impl.as.config;
-import java.io.File;
+import java.net.URL;
import junit.framework.TestCase;
+import org.jboss.bootstrap.impl.as.common.TestUtils;
import org.jboss.logging.Logger;
import org.junit.After;
import org.junit.Before;
@@ -57,11 +58,6 @@
*/
private static JBossASConfigurationInitializer initializer;
- /**
- * Denotes the present working directory
- */
- private static final File FILE_PWD = new File(".");
-
//-------------------------------------------------------------------------------||
// Instance Members -------------------------------------------------------------||
//-------------------------------------------------------------------------------||
@@ -108,30 +104,6 @@
//-------------------------------------------------------------------------------||
/**
- * Ensures that when not explicitly set, the JBOSS_HOME
- * is defaulted as expected
- */
- @Test
- public void testJBossHomeDefaulted() throws Throwable
- {
- // Log
- log.info("testJBossHomeDefaultsToPwd");
-
- // Initialize the blank config
- initializer.initialize(config);
-
- // Get the expected value
- final String expected = this.getDefaultJBossHome();
-
- // Get the actual
- final String actual = config.getJBossHome().toExternalForm();
-
- // Test
- TestCase.assertEquals("JBOSS_HOME was not initialized to the proper default", expected, actual);
- log.info("Got expected JBOSS_HOME from config: " + expected);
- }
-
- /**
* Ensures that jboss.bind.address defaults to loopback
* @throws Throwable
*/
@@ -189,14 +161,16 @@
// Log
log.info("testBootLibDefault");
- // Initialize the blank config
+ // Initialize the config, giving it a proper jboss home
+ final URL jbossHome = TestUtils.getJBossHome();
+ config.jbossHome(jbossHome);
initializer.initialize(config);
// Get out the boot library location
final String actual = config.getBootLibraryLocation().toExternalForm();
// Get expected value
- final String expected = this.getDefaultJBossHome()
+ final String expected = jbossHome.toExternalForm()
+ JBossASConfigurationInitializer.DEFAULT_VALUE_LIBRARY_URL_SUFFIX;
// Test
@@ -204,36 +178,4 @@
log.info("Got expected: " + expected);
}
- //-------------------------------------------------------------------------------------||
- // Internal Helper Methods ------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Obtains the default JBOSS_HOME value:
- *
- * 1) Environment Variable $JBOSS_HOME, or, if not set,
- * 2) Present working directory
- *
- * There's nothing we can do to test the real default, as we cannot
- * set environment variables from within this test.
- */
- private String getDefaultJBossHome() throws Throwable
- {
- String jbossHome = FILE_PWD.toURI().toURL().toExternalForm();
- final String envVarJBossHomeName = JBossASServerConfig.ENV_VAR_JBOSSAS_HOME;
- final String jbossHomeFromEnvVar = System.getenv(envVarJBossHomeName);
- if (jbossHomeFromEnvVar != null)
- {
- log.warn("This test cannot account for true defaults of JBoss Home, unset environment variable "
- + envVarJBossHomeName);
- jbossHome = new File(jbossHomeFromEnvVar).toURI().toURL().toExternalForm();
- final String trailingSlash = "/";
- if (!jbossHome.endsWith(trailingSlash))
- {
- jbossHome = jbossHome + trailingSlash;
- }
- }
- return jbossHome;
- }
-
}
Modified: projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/JBossASServerInitializationTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/JBossASServerInitializationTestCase.java 2009-04-23 07:14:22 UTC (rev 87709)
+++ projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/JBossASServerInitializationTestCase.java 2009-04-23 07:28:09 UTC (rev 87710)
@@ -28,6 +28,7 @@
import junit.framework.TestCase;
+import org.jboss.bootstrap.impl.as.common.TestUtils;
import org.jboss.bootstrap.impl.as.config.JBossASServerConfig;
import org.jboss.logging.Logger;
import org.junit.After;
@@ -70,6 +71,11 @@
// Create a server that skips real start/stop
this.server = new NoOpJBossASServer();
+ // Set some JBOSS_HOME explicitly so the tests are reproducible
+ // (environment properties cannot be mutated via the test env, and we need
+ // to be sure no $JBOSS_HOME default is picked up)
+ this.server.getConfiguration().jbossHome(TestUtils.getJBossHome());
+
// Initialize via start (Though this is a no-op, so we won't *really* start anything)
server.start();
More information about the jboss-cvs-commits
mailing list