[jboss-cvs] JBossAS SVN: r87184 - in projects/bootstrap/trunk/spi/src: main/java/org/jboss/bootstrap/spi/server and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 13 12:47:50 EDT 2009


Author: ALRubinger
Date: 2009-04-13 12:47:50 -0400 (Mon, 13 Apr 2009)
New Revision: 87184

Modified:
   projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicConfigurationInitializer.java
   projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicServerConfig.java
   projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ConfigurationInitializer.java
   projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java
   projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java
   projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java
Log:
[JBBOOT-34] Extend config initializer to apply defaults for bootstrapHome and bootstrapName

Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicConfigurationInitializer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicConfigurationInitializer.java	2009-04-13 13:48:51 UTC (rev 87183)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicConfigurationInitializer.java	2009-04-13 16:47:50 UTC (rev 87184)
@@ -154,6 +154,22 @@
          }
       }
 
+      // If there's no name, default it, then run this config again to 
+      // default other properties if necessary
+      if (name == null || name.length() == 0)
+      {
+         config.bootstrapName(ConfigurationInitializer.DEFAULT_NAME);
+         this.initialize(config);
+      }
+
+      // If there's no home, default it, then run this config again
+      if (home == null)
+      {
+         final URL newHome = SecurityActions.getCodeSourceLocation(this.getClass());
+         config.bootstrapHome(newHome);
+         this.initialize(config);
+      }
+
    }
 
    //-------------------------------------------------------------------------------------||
@@ -232,7 +248,7 @@
       String override = properties.get(propertyName);
 
       // Adjust to null if empty
-      if (override.length() == 0)
+      if (override != null && override.length() == 0)
       {
          override = null;
       }

Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicServerConfig.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicServerConfig.java	2009-04-13 13:48:51 UTC (rev 87183)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicServerConfig.java	2009-04-13 16:47:50 UTC (rev 87184)
@@ -474,7 +474,7 @@
     * @return
     * @throws IllegalArgumentException
     */
-   protected URL urlFromString(String url) throws IllegalArgumentException
+   protected final URL urlFromString(String url) throws IllegalArgumentException
    {
       try
       {

Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ConfigurationInitializer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ConfigurationInitializer.java	2009-04-13 13:48:51 UTC (rev 87183)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ConfigurationInitializer.java	2009-04-13 16:47:50 UTC (rev 87184)
@@ -34,6 +34,16 @@
  */
 public interface ConfigurationInitializer<T extends ServerConfig<?>>
 {
+   //-------------------------------------------------------------------------------------||
+   // Constants --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   String DEFAULT_NAME = "bootstrap.xml";
+
+   //-------------------------------------------------------------------------------------||
+   // Contracts --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
    /**
     * Initializes the specified configuration
     * 

Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java	2009-04-13 13:48:51 UTC (rev 87183)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java	2009-04-13 16:47:50 UTC (rev 87184)
@@ -37,7 +37,7 @@
 public interface ServerConfig<T extends ServerConfig<?>>
 {
    //-------------------------------------------------------------------------------------||
-   // Properties -------------------------------------------------------------------------||
+   // Constants --------------------------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
 
    /**

Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java	2009-04-13 13:48:51 UTC (rev 87183)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java	2009-04-13 16:47:50 UTC (rev 87184)
@@ -396,10 +396,6 @@
       this.validator = validator;
    }
 
-   /* (non-Javadoc)
-    * @see org.jboss.bootstrap.spi.server.Server#validate()
-    */
-
    //-------------------------------------------------------------------------------------||
    // Contracts --------------------------------------------------------------------------||
    //-------------------------------------------------------------------------------------||

Modified: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java	2009-04-13 13:48:51 UTC (rev 87183)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java	2009-04-13 16:47:50 UTC (rev 87184)
@@ -26,6 +26,7 @@
 
 import junit.framework.TestCase;
 
+import org.jboss.bootstrap.spi.config.ConfigurationInitializer;
 import org.jboss.bootstrap.spi.config.ServerConfig;
 import org.jboss.bootstrap.spi.config.TestConfigFactory;
 import org.jboss.bootstrap.spi.config.TestConfigurationInitializer;
@@ -163,6 +164,81 @@
    }
 
    /**
+    * Ensures that setting a configuration results in proper defaulting 
+    * of the bootstrap name if it's not been explicitly specified and 
+    * there's no bootstrapUrl
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testBootstrapNameDefaultedInInitialization() throws Throwable
+   {
+      // Get a populated config
+      final TestServerConfig configuration = TestConfigFactory.createConfiguration();
+
+      // Remove bootstrapURL and name
+      configuration.bootstrapUrl((String) null).bootstrapName(null);
+
+      // Initialize
+      configurationInitializer.initialize(configuration);
+
+      // Create the expected name
+      final String expectedName = ConfigurationInitializer.DEFAULT_NAME;
+
+      // Get the actual name
+      final String actualname = configuration.getBootstrapName();
+
+      // Test
+      TestCase.assertNotNull("Bootstrap name was not initialized", actualname);
+      TestCase.assertEquals("Initialized bootstrap is to incorrect name", expectedName, actualname);
+   }
+
+   /**
+    * Ensures that a completely empty configuration may be initialized
+    * to default values
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testEverythingDefaulted() throws Throwable
+   {
+      // Log
+      log.info("testEverythingDefaulted");
+
+      // Get an empty config
+      final TestServerConfig configuration = new TestServerConfig();
+
+      // Create the expected values
+      final URL expectedHome = TestServerConfig.class.getProtectionDomain().getCodeSource().getLocation();
+
+      // Test
+      this.assertAllProperties(expectedHome, configuration);
+   }
+
+   /**
+    * Ensures that specifying a bootstrap home will lead to defaulting
+    * all other properties
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testHomeOnlyDefaultsEverythingElse() throws Throwable
+   {
+      // Log
+      log.info("testHomeOnlyDefaultsEverythingElse");
+
+      // Get an empty config
+      final TestServerConfig configuration = new TestServerConfig();
+
+      // Make an explicit home and set it
+      final URL explicitHome = new URL("file://myhome");
+      configuration.bootstrapHome(explicitHome);
+
+      // Test
+      this.assertAllProperties(explicitHome, configuration);
+   }
+
+   /**
     * Ensures that each configuration value may be overridden 
     * by using the corresponding system property 
     */
@@ -199,4 +275,41 @@
       TestCase.assertEquals(failMessage, expectedBootstrapUrl, configuration.getBootstrapUrl().toExternalForm());
 
    }
+
+   //-------------------------------------------------------------------------------------||
+   // Internal Helper Methods ------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that all properties of the specified configuration
+    * are defaulted as expected, given the specified home
+    * 
+    * @param home
+    * @param configuration
+    * @throws Throwable
+    */
+   private void assertAllProperties(final URL home, final TestServerConfig configuration) throws Throwable
+   {
+      // Initialize
+      configurationInitializer.initialize(configuration);
+
+      // Create the expected values
+      final URL expectedHome = home;
+      final String defaultName = ConfigurationInitializer.DEFAULT_NAME;
+      final URL expectedUrl = new URL(expectedHome, defaultName);
+      final URL expectedConf = expectedHome;
+      final String expectedName = defaultName;
+
+      // Get the actual name
+      final URL actualHome = configuration.getBootstrapHome();
+      final URL actualUrl = configuration.getBootstrapUrl();
+      final URL actualConf = configuration.getBootstrapConfLocation();
+      final String actualname = configuration.getBootstrapName();
+
+      // Test
+      TestCase.assertEquals("Initialized bootstrap is to incorrect home", expectedHome, actualHome);
+      TestCase.assertEquals("Initialized bootstrap is to incorrect URL", expectedUrl, actualUrl);
+      TestCase.assertEquals("Initialized bootstrap is to incorrect conf", expectedConf, actualConf);
+      TestCase.assertEquals("Initialized bootstrap is to incorrect name", expectedName, actualname);
+   }
 }




More information about the jboss-cvs-commits mailing list