[jboss-cvs] JBossAS SVN: r87703 - in projects/bootstrap/trunk/impl-as/src: main/java/org/jboss/bootstrap/impl/as/server and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 23 01:29:21 EDT 2009


Author: ALRubinger
Date: 2009-04-23 01:29:21 -0400 (Thu, 23 Apr 2009)
New Revision: 87703

Modified:
   projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/BasicJBossASServerConfig.java
   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/JBossASConfigurationValidator.java
   projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASServerConfig.java
   projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerInitializer.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/config/JBossASConfigurationValidationTestCase.java
   projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/JBossASServerInitializationTestCase.java
Log:
[JBBOOT-31] Remove duplicate tests, back JBOSS_HOME in config with a URL instead of a String

Modified: projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/BasicJBossASServerConfig.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/BasicJBossASServerConfig.java	2009-04-23 04:47:59 UTC (rev 87702)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/BasicJBossASServerConfig.java	2009-04-23 05:29:21 UTC (rev 87703)
@@ -22,6 +22,12 @@
 
 package org.jboss.bootstrap.impl.as.config;
 
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
 import org.jboss.bootstrap.impl.base.config.AbstractBasicServerConfig;
 import org.jboss.logging.Logger;
 
@@ -55,7 +61,7 @@
    /**
     * $JBOSS_HOME, root of the AS installation
     */
-   private String jbossHome;
+   private URL jbossHome;
 
    /**
     * The server configuration name
@@ -83,6 +89,9 @@
       // Set
       this.bindAddress = bindAddress;
 
+      // Set property
+      this.setPropertyForString(PROP_KEY_JBOSSAS_BIND_ADDRESS, bindAddress);
+
       // Return
       return this.covarientReturn();
    }
@@ -108,9 +117,56 @@
     */
    public JBossASServerConfig jbossHome(final String jbossHome) throws IllegalArgumentException
    {
+      // If null, just pass along
+      if (jbossHome == null)
+      {
+         return this.jbossHome((URL) null);
+      }
+
+      // Convert this String into a URL via File
+      final File jbossHomeFile = new File(jbossHome);
+      URL jbossHomeUrl = null;
+      try
+      {
+         jbossHomeUrl = jbossHomeFile.toURI().toURL();
+      }
+      catch (MalformedURLException e)
+      {
+         throw new IllegalArgumentException("Cannot construct URL for JBOSS_HOME given: " + jbossHome, e);
+      }
+
+      // Return
+      return this.jbossHome(jbossHomeUrl);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.bootstrap.impl.as.config.JBossASServerConfig#jbossHome(java.net.URL)
+    */
+   public JBossASServerConfig jbossHome(final URL jbossHome)
+   {
       // Set
       this.jbossHome = jbossHome;
 
+      // If we're not clearing the value
+      if (jbossHome != null)
+      {
+         // Set properties
+         this.setPropertyForUrl(PROP_KEY_JBOSSAS_HOME_URL, jbossHome);
+         URI jbossHomeUri;
+         try
+         {
+            jbossHomeUri = jbossHome.toURI();
+         }
+         catch (URISyntaxException e)
+         {
+            throw new RuntimeException("Error in format of JBOSS_HOME: " + jbossHome, e);
+         }
+         final File jbossHomeFile = new File(jbossHomeUri);
+         final String jbossHomeLocation = jbossHomeFile.getAbsolutePath();
+         this.setPropertyForString(PROP_KEY_JBOSSAS_HOME, jbossHomeLocation);
+         this.setPropertyForString(PROP_KEY_JBOSSAS_HOME_DIR, jbossHomeLocation);
+      }
+
       // Return
       return this.covarientReturn();
    }
@@ -123,6 +179,9 @@
       // Set
       this.serverName = serverName;
 
+      // Set property
+      this.setPropertyForString(PROP_KEY_JBOSSAS_SERVER_NAME, serverName);
+
       // Return
       return this.covarientReturn();
    }
@@ -130,7 +189,7 @@
    /* (non-Javadoc)
     * @see org.jboss.bootstrap.impl.as.config.JBossASServerConfig#getJBossHome()
     */
-   public String getJBossHome()
+   public URL getJBossHome()
    {
       return this.jbossHome;
    }

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 04:47:59 UTC (rev 87702)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationInitializerImpl.java	2009-04-23 05:29:21 UTC (rev 87703)
@@ -76,7 +76,7 @@
 
       // $JBOSS_HOME
       final String pwd = FILE_PRESENT_WORKING_DIRECTORY.getAbsolutePath();
-      final String currentJBossHome = config.getJBossHome() != null ? config.getJBossHome() : null;
+      final String currentJBossHome = config.getJBossHome() != null ? config.getJBossHome().toExternalForm() : null;
       final String jbossHome = this.resolvePropertyValue(JBossASServerConfig.PROP_KEY_JBOSSAS_HOME,
             JBossASServerConfig.ENV_VAR_JBOSSAS_HOME, currentJBossHome, pwd, configProps);
       config.jbossHome(jbossHome);

Modified: projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationValidator.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationValidator.java	2009-04-23 04:47:59 UTC (rev 87702)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationValidator.java	2009-04-23 05:29:21 UTC (rev 87703)
@@ -22,6 +22,10 @@
 
 package org.jboss.bootstrap.impl.as.config;
 
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+
 import org.jboss.bootstrap.impl.base.config.AbstractBasicConfigurationValidator;
 import org.jboss.bootstrap.spi.config.ConfigurationValidator;
 import org.jboss.bootstrap.spi.config.InvalidConfigurationException;
@@ -91,7 +95,7 @@
     * @throws InvalidConfigurationException If the specified argument is 
     *   either null or empty
     */
-   private void require(final String arg, final String propertyName) throws InvalidConfigurationException
+   protected void require(final String arg, final String propertyName) throws InvalidConfigurationException
    {
       // If not specified
       if (arg == null || arg.length() == 0)
@@ -101,4 +105,34 @@
       }
    }
 
+   /**
+    * Requires that the specified argument is both non-null and
+    * pointing to an existent location
+    * 
+    * @throws InvalidConfigurationException If the specified argument is 
+    *   either null or nonexistent
+    */
+   protected void require(final URL arg, final String propertyName) throws InvalidConfigurationException
+   {
+      // If not specified
+      if (arg == null)
+      {
+         // Throw
+         throw new InvalidConfigurationException(propertyName + " must be specified");
+      }
+
+      // Try to open a connection, to see if exists
+      try
+      {
+         final URLConnection connection = arg.openConnection();
+         connection.connect();
+      }
+      catch (IOException ioe)
+      {
+         throw new InvalidConfigurationException("Could not get a connection to the " + propertyName + ": "
+               + arg.toExternalForm(), ioe);
+      }
+
+   }
+
 }

Modified: projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASServerConfig.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASServerConfig.java	2009-04-23 04:47:59 UTC (rev 87702)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/config/JBossASServerConfig.java	2009-04-23 05:29:21 UTC (rev 87703)
@@ -22,6 +22,8 @@
 
 package org.jboss.bootstrap.impl.as.config;
 
+import java.net.URL;
+
 import org.jboss.bootstrap.spi.mc.config.MCBasedServerConfig;
 
 /**
@@ -118,7 +120,7 @@
     * 
     * @return
     */
-   String getJBossHome();
+   URL getJBossHome();
 
    /**
     * Sets $JBOSS_HOME, the path to the root location 
@@ -126,6 +128,17 @@
     * 
     * @param jbossHome The location to $JBOSS_HOME
     * @return This configuration
+    * @throws IllegalArgumentException If the specified argument 
+    *    is non-null and cannot be constructed into a URL
     */
-   JBossASServerConfig jbossHome(String jbossHome);
+   JBossASServerConfig jbossHome(String jbossHome) throws IllegalArgumentException;
+
+   /**
+    * Sets $JBOSS_HOME, the path to the root location 
+    * of the JBossAS installation.
+    * 
+    * @param jbossHome The location to $JBOSS_HOME
+    * @return This configuration
+    */
+   JBossASServerConfig jbossHome(URL jbossHome);
 }

Modified: projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerInitializer.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerInitializer.java	2009-04-23 04:47:59 UTC (rev 87702)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerInitializer.java	2009-04-23 05:29:21 UTC (rev 87703)
@@ -23,7 +23,8 @@
 package org.jboss.bootstrap.impl.as.server;
 
 import java.io.File;
-import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 
 import org.jboss.bootstrap.impl.as.config.JBossASServerConfig;
@@ -86,23 +87,24 @@
       super.setSystemProperties(configuration);
 
       // Get values to set
-      final String jbossHome = configuration.getJBossHome();
-      final File jbossHomeFile = new File(jbossHome);
-      final String jbossHomeDir = jbossHomeFile.getAbsolutePath();
-      URL jbossHomeUrl = null;
+      final URL jbossHome = configuration.getJBossHome();
+      URI jbossHomeUri = null;
       try
       {
-         jbossHomeUrl = jbossHomeFile.toURI().toURL();
+         jbossHomeUri = jbossHome.toURI();
       }
-      catch (MalformedURLException e)
+      catch (URISyntaxException e1)
       {
-         // Ignore
+         throw new RuntimeException("JBOSS_HOME could not be made into URI, formatting "
+               + "error should have been caught by config validation", e1);
       }
+      final File jbossHomeFile = new File(jbossHomeUri);
+      final String jbossHomeDir = jbossHomeFile.getAbsolutePath();
 
       // Set our system properties
-      this.setSystemProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_HOME, jbossHome);
+      this.setSystemProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_HOME, jbossHomeDir);
       this.setSystemProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_HOME_DIR, jbossHomeDir);
-      this.setSystemProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_HOME_URL, jbossHomeUrl);
+      this.setSystemProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_HOME_URL, jbossHome);
       this.setSystemProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_BIND_ADDRESS, configuration.getBindAddress());
       this.setSystemProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_SERVER_NAME, configuration.getServerName());
    }

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 04:47:59 UTC (rev 87702)
+++ projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationInitializationTestCase.java	2009-04-23 05:29:21 UTC (rev 87703)
@@ -124,10 +124,11 @@
       final String expected = this.getDefaultJBossHome();
 
       // Get the actual
-      final String actual = config.getJBossHome();
+      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);
    }
 
    /**
@@ -189,16 +190,16 @@
     * There's nothing we can do to test the real default, as we cannot
     * set environment variables from within this test.  
     */
-   private String getDefaultJBossHome()
+   private String getDefaultJBossHome() throws Throwable
    {
-      String jbossHome = FILE_PWD.getAbsolutePath();
+      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 = jbossHomeFromEnvVar;
+         jbossHome = new File(jbossHomeFromEnvVar).toURI().toURL().toExternalForm();
       }
       return jbossHome;
    }

Modified: projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationValidationTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationValidationTestCase.java	2009-04-23 04:47:59 UTC (rev 87702)
+++ projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/config/JBossASConfigurationValidationTestCase.java	2009-04-23 05:29:21 UTC (rev 87703)
@@ -156,7 +156,7 @@
       final JBossASServerConfig config = this.config;
 
       // Clear out
-      config.jbossHome(null);
+      config.jbossHome((URL) null);
 
       // Validate
       try
@@ -174,6 +174,45 @@
    }
 
    /**
+    * Ensures that an fake JBoss Home fails
+    */
+   @Test
+   public void testInvalidJBossHomeFails()
+   {
+      // Log
+      log.info("testInvalidJBossHomeFails");
+
+      // Initialize
+      boolean failed = false;
+
+      // Get config
+      final JBossASServerConfig config = this.config;
+
+      // Set to some bogus location
+      final String fake = "fake";
+      config.jbossHome(fake);
+
+      // Ensure our bogus location is actually bogus
+      final File hopefullyFake = new File(fake);
+      TestCase.assertFalse("Invalid test setup, fake location must not exist: " + hopefullyFake.getAbsolutePath(),
+            hopefullyFake.exists());
+
+      // Validate
+      try
+      {
+         validator.validate(config);
+
+      }
+      catch (InvalidConfigurationException ice)
+      {
+         failed = true;
+      }
+
+      // Test
+      TestCase.assertTrue("Validation on JBOSS_HOME pointing to an invalid location should have failed", failed);
+   }
+
+   /**
     * Ensures that an empty/null Bind Address fails
     */
    @Test

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 04:47:59 UTC (rev 87702)
+++ projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/JBossASServerInitializationTestCase.java	2009-04-23 05:29:21 UTC (rev 87703)
@@ -28,7 +28,6 @@
 
 import junit.framework.TestCase;
 
-import org.jboss.bootstrap.impl.as.config.JBossASConfigurationInitializer;
 import org.jboss.bootstrap.impl.as.config.JBossASServerConfig;
 import org.jboss.logging.Logger;
 import org.junit.After;
@@ -90,54 +89,6 @@
    //-------------------------------------------------------------------------------------||
 
    /**
-    * Ensures that when not explicitly set, the jboss.bind.address
-    * is defaulted as expected
-    */
-   @Test
-   public void testBindAddressDefaulted()
-   {
-      // Log
-      log.info("testBindAddressDefaults");
-
-      // Get an initialized server and config
-      final JBossASServer server = this.server;
-      final JBossASServerConfig configuration = server.getConfiguration();
-
-      // Get the expected value
-      final String expected = JBossASConfigurationInitializer.DEFAULT_VALUE_BIND_ADDRESS;
-
-      // Get the actual
-      final String actual = configuration.getBindAddress();
-
-      // Test
-      TestCase.assertEquals("Bind address was not initialized to the proper default", expected, actual);
-   }
-
-   /**
-    * Ensures that when not explicitly set, the jboss.server.name
-    * is defaulted as expected
-    */
-   @Test
-   public void testServerNameDefaulted()
-   {
-      // Log
-      log.info("testServerNameDefaulted");
-
-      // Get an initialized server and config
-      final JBossASServer server = this.server;
-      final JBossASServerConfig configuration = server.getConfiguration();
-
-      // Get the expected value
-      final String expected = JBossASConfigurationInitializer.DEFAULT_VALUE_SERVER_NAME;
-
-      // Get the actual
-      final String actual = configuration.getServerName();
-
-      // Test
-      TestCase.assertEquals("Server name was not initialized to the proper default", expected, actual);
-   }
-
-   /**
     * Ensures that the properties backing the configuration are set 
     * both on the configuration itself and in the System props.  Upon
     * cleanup, these properties must be cleared.
@@ -181,29 +132,26 @@
       final String serverNameFromSystem = System.getProperty(serverNamePropKey);
 
       // Get Expected Values
-      final String jbossHomeFromConf = configuration.getJBossHome();
-      final File jbossHomeFile = new File(jbossHomeFromConf);
+      final URL jbossHomeFromConf = configuration.getJBossHome();
+      final File jbossHomeFile = new File(jbossHomeFromConf.toURI());
       final String jbossHomeDirFromConf = jbossHomeFile.getAbsolutePath();
-      final URL jbossHomeUrl = jbossHomeFile.toURI().toURL();
-      final String jbossHomeUrlFromConf = jbossHomeUrl.toExternalForm();
+      final String jbossHomeUrlFromConf = jbossHomeFromConf.toExternalForm();
       final String bindAddressFromConf = configuration.getBindAddress();
       final String serverNameFromConf = configuration.getServerName();
 
       // Ensure all equal
-      TestCase.assertEquals("JBoss Home in configuration must match the config property", jbossHomeFromConf,
+      TestCase.assertEquals("JBoss Home in configuration must match the config property", jbossHomeDirFromConf,
             jbossHomeFromConfProp);
-      TestCase.assertEquals("JBoss Home in configuration must match the system property", jbossHomeFromConf,
+      TestCase.assertEquals("JBoss Home in configuration must match the system property", jbossHomeDirFromConf,
             jbossHomeFromSystem);
       TestCase.assertEquals("JBoss Home Dir in configuration must match the config property", jbossHomeDirFromConf,
             jbossHomeDirFromConfProp);
       TestCase.assertEquals("JBoss Home Dir in configuration must match the system property", jbossHomeDirFromConf,
             jbossHomeDirFromSystem);
-
       TestCase.assertEquals("JBoss Home URL in configuration must match the config property", jbossHomeUrlFromConf,
             jbossHomeUrlFromConfProp);
       TestCase.assertEquals("JBoss Home URL in configuration must match the system property", jbossHomeUrlFromConf,
             jbossHomeUrlFromSystem);
-
       TestCase.assertEquals("Bind Address in configuration must match the config property", bindAddressFromConf,
             bindAddressFromConfProp);
       TestCase.assertEquals("Bind Address in configuration must match the system property", bindAddressFromConf,




More information about the jboss-cvs-commits mailing list