[jboss-cvs] JBossAS SVN: r87191 - in projects/bootstrap/trunk/spi/src: test/java/org/jboss/bootstrap/spi/config/unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 13 14:25:40 EDT 2009


Author: ALRubinger
Date: 2009-04-13 14:25:40 -0400 (Mon, 13 Apr 2009)
New Revision: 87191

Added:
   projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/BasicConfigurationTestCase.java
Modified:
   projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicServerConfig.java
   projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java
Log:
[JBBOOT-36] Set home/conf to a directory URL if no trailing slash is provided

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 18:01:12 UTC (rev 87190)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicServerConfig.java	2009-04-13 18:25:40 UTC (rev 87191)
@@ -53,6 +53,8 @@
 
    private static final Logger log = Logger.getLogger(AbstractBasicServerConfig.class);
 
+   private static final String TRAILING_SLASH = "/";
+
    //-------------------------------------------------------------------------------------||
    // Instance Members -------------------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
@@ -228,11 +230,14 @@
       // Precondition check
       this.checkMutable();
 
+      // Adjust
+      final URL newUrl = this.adjustToDirectory(confLocation);
+
       // Set property
-      this.setPropertyForUrl(PROP_KEY_BOOTSTRAP_CONF_URL, confLocation);
+      this.setPropertyForUrl(PROP_KEY_BOOTSTRAP_CONF_URL, newUrl);
 
       // Set URL
-      this.bootstrapConfLocation = confLocation;
+      this.bootstrapConfLocation = newUrl;
 
       // Return
       return this.covarientReturn();
@@ -246,11 +251,14 @@
       // Precondition check
       this.checkMutable();
 
+      // Adjust
+      final URL newUrl = this.adjustToDirectory(bootstrapHome);
+
       // Set property
-      this.setPropertyForUrl(PROP_KEY_BOOTSTRAP_HOME_URL, bootstrapHome);
+      this.setPropertyForUrl(PROP_KEY_BOOTSTRAP_HOME_URL, newUrl);
 
       // Set URL
-      this.bootstrapHome = bootstrapHome;
+      this.bootstrapHome = newUrl;
 
       // Return
       return this.covarientReturn();
@@ -406,6 +414,52 @@
    }
 
    /**
+    * If the specified URL denotes a directory (ie. trailing slash), 
+    * will return the argument.  Nulls are ignored and returned as-is.
+    * 
+    * @param url
+    * @return
+    */
+   protected URL adjustToDirectory(final URL url)
+   {
+      // Do nothing to nulls
+      if (url == null)
+      {
+         return null;
+      }
+
+      // Check
+      final String externalForm = url.toExternalForm();
+      if (externalForm.endsWith(TRAILING_SLASH))
+      {
+         // Return per normal
+         return url;
+      }
+
+      // Otherwise make a new URL
+      final String newLocation = externalForm + TRAILING_SLASH;
+      URL newUrl = null;
+      try
+      {
+         // Construct
+         newUrl = new URL(newLocation);
+      }
+      catch (MalformedURLException e)
+      {
+         throw new RuntimeException("Could not create new URL to point to directory", e);
+      }
+
+      // Log
+      if (log.isTraceEnabled())
+      {
+         log.trace("Appended trailing slash to " + url + " to point to directory: " + newUrl);
+      }
+
+      // Return it
+      return newUrl;
+   }
+
+   /**
     * Returns the actual types of this configuration, used in 
     * covarient return of the mutator methods
     * 

Added: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/BasicConfigurationTestCase.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/BasicConfigurationTestCase.java	                        (rev 0)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/BasicConfigurationTestCase.java	2009-04-13 18:25:40 UTC (rev 87191)
@@ -0,0 +1,121 @@
+/*
+ * 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.spi.config.unit;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.jboss.bootstrap.spi.config.TestServerConfig;
+import org.jboss.logging.Logger;
+import org.junit.Test;
+
+/**
+ * BasicConfigurationTestCase
+ * 
+ * Test Cases to assert the basic abstract configuration is working 
+ * as expected
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class BasicConfigurationTestCase
+{
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(BasicConfigurationTestCase.class);
+
+   private static final String TRAILING_SLASH = "/";
+
+   //-------------------------------------------------------------------------------------||
+   // Tests ------------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that the supplied conf location is a directory
+    * 
+    * JBBOOT-36
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testValidationConfIsDirectory() throws Throwable
+   {
+      // Log
+      log.info("testValidationConfIsDirectory");
+
+      // Make a config
+      final TestServerConfig configuration = new TestServerConfig();
+
+      // Make some URL to a non-directory
+      final URL url = new URL("http://manual");
+      final String externalForm = url.toExternalForm();
+      TestCase
+            .assertTrue("Test should not start by looking for trailing slash", !externalForm.endsWith(TRAILING_SLASH));
+
+      // Set
+      configuration.bootstrapConfLocation(url);
+
+      // Test
+      final URL newUrl = configuration.getBootstrapConfLocation();
+      TestCase.assertTrue("Conf location should have been adjusted to have a trailing slash", newUrl.toExternalForm()
+            .endsWith(TRAILING_SLASH));
+   }
+
+   /**
+    * Ensures that the supplied home location is a directory
+    * 
+    * JBBOOT-36
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testValidationHomeIsDirectory() throws Throwable
+   {
+      // Log
+      log.info("testValidationHomeIsDirectory");
+
+      // Make a config
+      final TestServerConfig configuration = new TestServerConfig();
+
+      // Make some URL to a non-directory
+      final URL url = new URL("http://manual");
+      final String externalForm = url.toExternalForm();
+      TestCase
+            .assertTrue("Test should not start by looking for trailing slash", !externalForm.endsWith(TRAILING_SLASH));
+
+      // Set
+      configuration.bootstrapHome(url);
+
+      // Test
+      final URL newUrl = configuration.getBootstrapHome();
+      TestCase.assertTrue("Home location should have been adjusted to have a trailing slash", newUrl.toExternalForm()
+            .endsWith(TRAILING_SLASH));
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Internal Helper Methods ------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+}

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 18:01:12 UTC (rev 87190)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java	2009-04-13 18:25:40 UTC (rev 87191)
@@ -231,7 +231,7 @@
       final TestServerConfig configuration = new TestServerConfig();
 
       // Make an explicit home and set it
-      final URL explicitHome = new URL("file://myhome");
+      final URL explicitHome = new URL("file://myhome/");
       configuration.bootstrapHome(explicitHome);
 
       // Test
@@ -253,8 +253,8 @@
 
       // Define some property values
       final String expectedBootstrapName = "overrideBootstrapName";
-      final String expectedBootstrapHome = "file://overrideBootstrapHome";
-      final String expectedBootstrapConf = "file://overrideBootstrapConf";
+      final String expectedBootstrapHome = "file://overrideBootstrapHome/";
+      final String expectedBootstrapConf = "file://overrideBootstrapConf/";
       final String expectedBootstrapUrl = "file://overrideBootstrapUrl";
 
       // Set as overrides




More information about the jboss-cvs-commits mailing list