[jboss-cvs] JBossAS SVN: r92522 - in projects/bootstrap/trunk: impl-mc and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 18 08:11:14 EDT 2009


Author: johnbailey
Date: 2009-08-18 08:11:13 -0400 (Tue, 18 Aug 2009)
New Revision: 92522

Added:
   projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/InvalidBootstrapURLException.java
   projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/AbstractMCServerTest.java
   projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerBootstrapUrlTestCase.java
   projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap-starting-slash.xml
   projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap-urls.xml
   projects/bootstrap/trunk/impl-mc/src/test/resources/pojo2.xml
Modified:
   projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/AbstractBasicConfigurationInitializer.java
   projects/bootstrap/trunk/impl-mc/pom.xml
   projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java
   projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java
Log:
[JBBOOT-43] - Added support for bootstrapping from URLs that aren't files.  It should now handle relative URLs based on the bootstrapUrl not the bootstrapHome.

Modified: projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/AbstractBasicConfigurationInitializer.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/AbstractBasicConfigurationInitializer.java	2009-08-18 12:06:44 UTC (rev 92521)
+++ projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/AbstractBasicConfigurationInitializer.java	2009-08-18 12:11:13 UTC (rev 92522)
@@ -51,6 +51,11 @@
 
    private static final Logger log = Logger.getLogger(AbstractBasicConfigurationInitializer.class);
 
+   /**
+    * Represents a slash
+    */
+   private static final String SLASH = "/";
+
    //-------------------------------------------------------------------------------------||
    // Required Implementations -----------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
@@ -108,6 +113,14 @@
             log.trace("No bootstrap URL defined, constructing it from home and name...");
          }
 
+         //  Bootstrap name should not start with a slash when being treated as a relative URL 
+         //  to the bootstrap home.
+         if (name.startsWith(SLASH))
+         {
+            throw new InvalidBootstrapURLException("Invalid bootstrap name: " + name
+                  + ".  Bootstrap name can not start with '" + SLASH + "'.");
+         }
+
          // Construct
          URL newBootstrapUrl = null;
          try

Added: projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/InvalidBootstrapURLException.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/InvalidBootstrapURLException.java	                        (rev 0)
+++ projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/InvalidBootstrapURLException.java	2009-08-18 12:11:13 UTC (rev 92522)
@@ -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.base.config;
+
+/**
+ * InvalidBootstrapURLException
+ * 
+ * Indicates that a bootstrap URL is not valid.  Such as a relative URL starting with a slash.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public class InvalidBootstrapURLException extends RuntimeException
+{
+
+   /**
+    * 
+    */
+   private static final long serialVersionUID = 1L;
+
+   /**
+    * 
+    */
+   public InvalidBootstrapURLException()
+   {
+      super();
+   }
+
+   /**
+    * @param message
+    * @param cause
+    */
+   public InvalidBootstrapURLException(String message, Throwable cause)
+   {
+      super(message, cause);
+   }
+
+   /**
+    * @param message
+    */
+   public InvalidBootstrapURLException(String message)
+   {
+      super(message);
+   }
+
+   /**
+    * @param cause
+    */
+   public InvalidBootstrapURLException(Throwable cause)
+   {
+      super(cause);
+   }
+
+}

Modified: projects/bootstrap/trunk/impl-mc/pom.xml
===================================================================
--- projects/bootstrap/trunk/impl-mc/pom.xml	2009-08-18 12:06:44 UTC (rev 92521)
+++ projects/bootstrap/trunk/impl-mc/pom.xml	2009-08-18 12:11:13 UTC (rev 92522)
@@ -28,6 +28,7 @@
     <version.org.jboss.bootstrap_jboss.bootstrap.impl.base>2.0.0-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.impl.base>
     <version.org.jboss.bootstrap_jboss.bootstrap.spi.mc>2.0.0-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.spi.mc>
     <version.org.jboss.man_jboss.managed>2.1.0.SP1</version.org.jboss.man_jboss.managed>
+    <version.jetty>6.1.16</version.jetty>
 
   </properties>
 
@@ -45,6 +46,13 @@
       <artifactId>junit</artifactId>
     </dependency>
 
+	<!-- org.mortbay.jetty:jetty -->
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty</artifactId>
+      <version>${version.jetty}</version>
+    </dependency>
+
     <!-- org.jboss.bootstrap:jboss-bootstrap-impl-base -->
     <dependency>
       <groupId>org.jboss.bootstrap</groupId>
@@ -81,6 +89,6 @@
       <groupId>org.jboss.microcontainer</groupId>
       <artifactId>jboss-kernel</artifactId>
     </dependency>
-
+    
   </dependencies>
 </project>

Modified: projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java	2009-08-18 12:06:44 UTC (rev 92521)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java	2009-08-18 12:11:13 UTC (rev 92522)
@@ -32,6 +32,7 @@
 import org.jboss.bootstrap.api.config.ServerConfig;
 import org.jboss.bootstrap.api.lifecycle.LifecycleEventException;
 import org.jboss.bootstrap.api.server.Server;
+import org.jboss.bootstrap.impl.base.config.InvalidBootstrapURLException;
 import org.jboss.bootstrap.impl.base.server.AbstractServer;
 import org.jboss.bootstrap.impl.base.xml.BootstrapParser;
 import org.jboss.bootstrap.impl.mc.deployer.TempBasicXMLDeployer;
@@ -66,6 +67,11 @@
 
    private static final Logger log = Logger.getLogger(AbstractMCServerBase.class);
 
+   /**
+    * Represents a slash
+    */
+   private static final String SLASH = "/";
+
    //-------------------------------------------------------------------------------------||
    // Instance Members -------------------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
@@ -298,9 +304,15 @@
       try
       {
          // Deploy the bootstrap urls
-         for (String bootstrapURL : bootstrapURLs)
+         for (String childBootstrapURL : bootstrapURLs)
          {
-            final URL suburl = new URL(homeUrl, bootstrapURL);
+            // Check if child bootstrap URL is valid 
+            if (childBootstrapURL.startsWith(SLASH))
+            {
+               throw new InvalidBootstrapURLException("Invlaid bootstrap URL: " + childBootstrapURL
+                     + ".  Bootstrap URLs  can not start with a '" + SLASH + "'");
+            }
+            final URL suburl = new URL(bootstrapUrl, childBootstrapURL);
             log.debug("Deploying bootstrap xml: " + suburl);
             kernelDeployer.deploy(suburl);
          }

Added: projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/AbstractMCServerTest.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/AbstractMCServerTest.java	                        (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/AbstractMCServerTest.java	2009-08-18 12:11:13 UTC (rev 92522)
@@ -0,0 +1,220 @@
+/*
+ * 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.mc.server.unit;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.bootstrap.api.lifecycle.LifecycleState;
+import org.jboss.bootstrap.api.mc.config.MCServerConfig;
+import org.jboss.bootstrap.api.mc.server.MCServer;
+import org.jboss.bootstrap.impl.mc.config.BasicMCServerConfig;
+import org.jboss.bootstrap.impl.mc.server.MCServerImpl;
+import org.jboss.bootstrap.impl.mc.server.Pojo;
+import org.jboss.bootstrap.spi.mc.server.MCServerProvider;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * AbstractMCServerTest
+ * 
+ * Abstract test class used to setup basic functionality for MCServer testing
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public class AbstractMCServerTest
+{
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(AbstractMCServerTest.class);
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * The server to test
+    */
+   private MCServer server;
+
+   //-------------------------------------------------------------------------------------||
+   // Lifecycle --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Creates the server
+    */
+   @Before
+   public void createServer() throws Throwable
+   {
+      // Create the server
+      final MCServerConfig config = createServerConfig();
+      this.server = new MCServerImpl(config);
+      log.info("Created: " + this.server);
+   }
+
+   /**
+    * If started, shuts down the server
+    * @throws Throwable
+    */
+   @After
+   public void shutdownServerAndClear() throws Throwable
+   {
+      final MCServer server = this.server;
+      if (server.getState().equals(LifecycleState.STARTED))
+      {
+         server.shutdown();
+      }
+      // Server didn't start up cleanly, so manually run init cleanup
+      else
+      {
+         final MCServerProvider provider = (MCServerProvider) server;
+         provider.getServerInitializer().cleanup(provider);
+      }
+
+      // Clear the server
+      this.server = null;
+      log.info("Server cleared");
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Internal Helper Methods ------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Return the configured {@link MCServer}
+    * @return MCServer
+    */
+   protected MCServer getServer()
+   {
+      return server;
+   }
+
+   /**
+    * Obtains a server configuration populated with all URLs and name
+    */
+   private MCServerConfig createServerConfig()
+   {
+      // Get the home
+      final URL home = this.getHome();
+
+      // Populate and return
+      return new BasicMCServerConfig().bootstrapHome(home);
+   }
+
+   /**
+    * Obtains the home relative to this test location
+    * @return
+    */
+   protected URL getHome()
+   {
+      return this.getClass().getProtectionDomain().getCodeSource().getLocation();
+   }
+
+   /**
+    * Installs a POJO into the specified server
+    * 
+    * @param server
+    * @throws Throwable
+    */
+   protected void installPojo(final MCServer server, final String mcBindName) throws Throwable
+   {
+      // Construct BeanMetaData
+      final Pojo pojo = new Pojo();
+      final BeanMetaData beanMD = BeanMetaDataBuilder.createBuilder(mcBindName, pojo.getClass().getName())
+            .getBeanMetaData();
+
+      // Get the controller and install
+      log.info("Installing test POJO under name " + mcBindName + " into " + server + "...");
+      server.getKernel().getController().install(beanMD, pojo);
+   }
+
+   /**
+    * Ensures that the POJO is installed at {@link AbstractMCServerTest#BIND_NAME_POJO}
+    * and has no expected value
+    * 
+    * @param mcBindName
+    * @throws Throwable
+    */
+   protected void assertPojo(final String mcBindName) throws Throwable
+   {
+      this.assertPojo(mcBindName, null);
+   }
+
+   /**
+    * Ensures that the POJO is installed in the provided bind name
+    * and has the expected value
+    * 
+    * @param mcBindName
+    * @param expectedValue
+    * @throws Throwable
+    */
+   protected void assertPojo(final String mcBindName, final String expectedValue) throws Throwable
+   {
+      // Log
+      log.trace("Asserting POJO installed as expected...");
+
+      // Get the underlying bean context
+      final KernelController controller = this.server.getKernel().getController();
+      final ControllerContext beanContext = controller.getContext(mcBindName, null);
+      TestCase.assertNotNull("beanContext from " + mcBindName + " is null", beanContext);
+      final ControllerState beanState = beanContext.getState();
+      TestCase.assertEquals("POJO did not properly install, error was: " + beanContext.getError(),
+            ControllerState.INSTALLED, beanState);
+
+      // Get Pojo
+      final Object target = beanContext.getTarget();
+      TestCase.assertNotNull("POJO could not be found in MC at: " + mcBindName, target);
+      Pojo pojo = null;
+      try
+      {
+         pojo = Pojo.class.cast(target);
+      }
+      catch (ClassCastException cce)
+      {
+         TestCase.fail("Test pojo was not expected type: " + cce);
+      }
+
+      // Test Lifecycle was invoked by MC
+      final boolean pojoStarted = pojo.isStarted();
+      TestCase.assertTrue("Start lifecycle was not called upon the POJO", pojoStarted);
+
+      // Test expected value
+      final String actualvalue = pojo.getValue();
+      TestCase.assertEquals("POJO did not have expected value", expectedValue, actualvalue);
+
+      // Log
+      log.info("POJO installed as expected with value: " + actualvalue);
+   }
+}

Added: projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerBootstrapUrlTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerBootstrapUrlTestCase.java	                        (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerBootstrapUrlTestCase.java	2009-08-18 12:11:13 UTC (rev 92522)
@@ -0,0 +1,356 @@
+/*
+ * 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.mc.server.unit;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.URL;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.bootstrap.api.mc.server.MCServer;
+import org.jboss.bootstrap.impl.base.config.InvalidBootstrapURLException;
+import org.jboss.logging.Logger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.AbstractHandler;
+
+/**
+ * MCServerBootstrapUrlTestCase
+ * 
+ * Test Cases to ensure that the MC Server Implementation handles the bootstrapUrl correctly.
+ * 
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $    
+ */
+public class MCServerBootstrapUrlTestCase extends AbstractMCServerTest
+{
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(MCServerBootstrapUrlTestCase.class);
+
+   private static final String NAME_BOOTSTRAP_POJO = "bootstrap-pojo.xml";
+
+   private static final String NAME_BOOTSTRAP_URLS = "bootstrap-urls.xml";
+
+   private static final String NAME_BOOTSTRAP_SLASH = "bootstrap-starting-slash.xml";
+
+   private static final String BIND_NAME_POJO = "org.jboss.bootstrap.test.POJO";
+
+   private static final String BIND_NAME_POJO_TWO = "org.jboss.bootstrap.test.POJO_2";
+
+   private static final int HTTP_TEST_BIND_PORT = 12345;
+
+   private static final String CONTENT_TYPE_XML = "text/xml";
+
+   private static final String TEST_HTTP_ROOT = "http://localhost:" + HTTP_TEST_BIND_PORT;
+
+   private static final String TEST_HTTP_PATH_BASE = "/path/";
+
+   private static final String TEST_HTTP_URL = TEST_HTTP_ROOT + TEST_HTTP_PATH_BASE + NAME_BOOTSTRAP_POJO;
+
+   private static final String TEST_HTTP_MULTI_URL = TEST_HTTP_ROOT + TEST_HTTP_PATH_BASE + NAME_BOOTSTRAP_URLS;
+
+   private static Server httpServer;
+
+   //-------------------------------------------------------------------------------------||
+   // Lifecycle --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Starts up an embedded HTTP Server to serve out the Mock 
+    * 
+    * file:/ URLs)
+    */
+   @BeforeClass
+   public static void startHttpServer()
+   {
+      // Start an Embedded HTTP Server
+      final Handler handler = new StaticFileHandler();
+      httpServer = new Server(HTTP_TEST_BIND_PORT);
+      httpServer.setHandler(handler);
+      try
+      {
+         httpServer.start();
+      }
+      catch (final Exception e)
+      {
+         throw new RuntimeException("Could not start server");
+      }
+      log.info("HTTP Server Started: " + httpServer);
+   }
+
+   /**
+    * Shuts down and clears the Embedded HTTP Server
+    */
+   @AfterClass
+   public static void shutdownHttpServer()
+   {
+      if (httpServer != null)
+      {
+         try
+         {
+            httpServer.stop();
+         }
+         catch (final Exception e)
+         {
+            // Swallow
+            log.error("Could not stop HTTP Server cleanly", e);
+         }
+         log.info("HTTP Server Stopped: " + httpServer);
+         httpServer = null;
+      }
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Tests ------------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that any valid http:// URL can be processed as a bootstrapUrl.
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testBootstrapHttpUrl() throws Throwable
+   {
+      // Log
+      log.info("testBootstrapHttpUrl");
+
+      final MCServer server = getServer();
+
+      // Initialize
+      server.getConfiguration().bootstrapUrl(TEST_HTTP_URL);
+
+      // Start the server
+      server.start();
+
+      assertPojo(BIND_NAME_POJO);
+   }
+
+   /**
+    * Ensures that <url> elements support both relative and fully qualified format
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testBootstrapHttpUrlMultiNested() throws Throwable
+   {
+      // Log
+      log.info("testBootstrapHttpUrlMultiNested");
+
+      final MCServer server = getServer();
+
+      // Initialize
+      server.getConfiguration().bootstrapUrl(TEST_HTTP_MULTI_URL);
+
+      // Start the server
+      server.start();
+
+      assertPojo(BIND_NAME_POJO);
+      assertPojo(BIND_NAME_POJO_TWO);
+   }
+
+   /**
+    * Ensures that any valid file:// URL can be processed as a bootstrapUrl.
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testBootstrapFileUrl() throws Throwable
+   {
+      // Log
+      log.info("testBootstrapFileUrl");
+
+      final MCServer server = getServer();
+
+      URL bootstrapUrl = new URL(getHome(), NAME_BOOTSTRAP_POJO);
+
+      // Initialize
+      server.getConfiguration().bootstrapUrl(bootstrapUrl);
+
+      // Start the server
+      server.start();
+
+      assertPojo(BIND_NAME_POJO);
+   }
+
+   /**
+    * Ensures that any valid file:// URL can be processed as a bootstrapUrl and will 
+    * correctly handle both relative and fully qualified <url> elements.
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testBootstrapFileUrlMultiNested() throws Throwable
+   {
+      // Log
+      log.info("testBootstrapFileUrlMultiNested");
+
+      final MCServer server = getServer();
+
+      URL bootstrapUrl = new URL(getHome(), NAME_BOOTSTRAP_URLS);
+
+      // Initialize
+      server.getConfiguration().bootstrapUrl(bootstrapUrl);
+
+      // Start the server
+      server.start();
+
+      assertPojo(BIND_NAME_POJO);
+      assertPojo(BIND_NAME_POJO_TWO);
+   }
+
+   /**
+    * Ensures a bootstrapUrl created by the bootstrapHome property functions correctly for both 
+    * relative and fully qualified <url> elements  
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testBootstrapUrlFromBootstrapHome() throws Throwable
+   {
+      // Log
+      log.info("testBootstrapUrlFromBootstrapHome");
+
+      final MCServer server = getServer();
+
+      // Set name to deploy a test POJO via XML
+      server.getConfiguration().bootstrapName(NAME_BOOTSTRAP_URLS);
+
+      // Start the server
+      server.start();
+
+      assertPojo(BIND_NAME_POJO);
+      assertPojo(BIND_NAME_POJO_TWO);
+   }
+
+   /**
+    * Test to show relative URL will not function with a starting slash in the bootstrapUrl. 
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testBootstrapUrlStartsWithSlash() throws Throwable
+   {
+      // Log
+      log.info("testBootstrapUrlStartsWithSlash");
+
+      MCServer server = getServer();
+
+      server.getConfiguration().bootstrapName("/" + NAME_BOOTSTRAP_POJO);
+
+      try
+      {
+         // Start the server
+         server.start();
+         fail("Should have thrown InvalidBootstrapUrlFormatException");
+      }
+      catch (InvalidBootstrapURLException expectedException)
+      {
+         // Ignore expected InvalidBootstrapUrlFormatException
+      }
+   }
+
+   /**
+    * Test to show relative URL will not function with a starting slash in a <url> element  
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testNestedUrlStartsWithSlash() throws Throwable
+   {
+      // Log
+      log.info("testNestedUrlStartsWithSlash");
+
+      final MCServer server = getServer();
+
+      server.getConfiguration().bootstrapName(NAME_BOOTSTRAP_SLASH);
+
+      try
+      {
+         // Start the server
+         server.start();
+         fail("Should have thrown InvalidBootstrapUrlFormatException");
+      }
+      catch (Exception expectedException)
+      {
+         assertTrue(expectedException.getCause() instanceof InvalidBootstrapURLException);
+      }
+
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Internal Classes--------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Jetty Handler to serve a file contents over HTTP
+    */
+   private static class StaticFileHandler extends AbstractHandler implements Handler
+   {
+      /*
+       * (non-Javadoc)
+       * @see org.mortbay.jetty.Handler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
+       */
+      public void handle(final String target, final HttpServletRequest request, final HttpServletResponse response,
+            final int dispatch) throws IOException, ServletException
+      {
+         // Set content type and status before we write anything to the stream
+         response.setContentType(CONTENT_TYPE_XML);
+         response.setStatus(HttpServletResponse.SC_OK);
+
+         // Get local path (removed /path from the target)
+         final String localPath = target.replace(TEST_HTTP_PATH_BASE, "/");
+
+         //  Get local stream
+         final InputStream stream = this.getClass().getResourceAsStream(localPath);
+
+         // Write out each line
+         final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
+         final PrintWriter writer = response.getWriter();
+         String line = null;
+         while ((line = reader.readLine()) != null)
+         {
+            writer.println(line);
+         }
+         writer.flush();
+         reader.close();
+         writer.close();
+      }
+   }
+
+}

Modified: projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java	2009-08-18 12:06:44 UTC (rev 92521)
+++ projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java	2009-08-18 12:11:13 UTC (rev 92522)
@@ -22,27 +22,15 @@
 
 package org.jboss.bootstrap.impl.mc.server.unit;
 
-import java.net.URL;
 import java.util.Map;
 
 import junit.framework.TestCase;
 
-import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
 import org.jboss.bootstrap.api.lifecycle.LifecycleState;
-import org.jboss.bootstrap.api.mc.config.MCServerConfig;
 import org.jboss.bootstrap.api.mc.server.MCServer;
-import org.jboss.bootstrap.impl.mc.config.BasicMCServerConfig;
-import org.jboss.bootstrap.impl.mc.server.MCServerImpl;
-import org.jboss.bootstrap.impl.mc.server.Pojo;
 import org.jboss.bootstrap.spi.mc.server.MCServerProvider;
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.dependency.spi.ControllerState;
-import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.kernel.spi.deployment.KernelDeployment;
 import org.jboss.logging.Logger;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 
 /**
@@ -54,7 +42,7 @@
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
  */
-public class MCServerUnitTestCase
+public class MCServerUnitTestCase extends AbstractMCServerTest
 {
    //-------------------------------------------------------------------------------------||
    // Class Members ----------------------------------------------------------------------||
@@ -67,49 +55,6 @@
    private static final String BIND_NAME_POJO = "org.jboss.bootstrap.test.POJO";
 
    //-------------------------------------------------------------------------------------||
-   // Instance Members -------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * The server to test
-    */
-   private MCServer server;
-
-   //-------------------------------------------------------------------------------------||
-   // Lifecycle --------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Creates the server
-    */
-   @Before
-   public void createServer() throws Throwable
-   {
-      // Create the server
-      final MCServerConfig config = createServerConfig();
-      this.server = new MCServerImpl(config);
-      log.info("Created: " + this.server);
-   }
-
-   /**
-    * If started, shuts down the server
-    * @throws Throwable
-    */
-   @After
-   public void shutdownServerAndClear() throws Throwable
-   {
-      final MCServer server = this.server;
-      if (server.getState().equals(LifecycleState.STARTED))
-      {
-         server.shutdown();
-      }
-
-      // Clear the server
-      this.server = null;
-      log.info("Server cleared");
-   }
-
-   //-------------------------------------------------------------------------------------||
    // Tests ------------------------------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
 
@@ -125,6 +70,9 @@
       // Log
       log.info("testMcIntegration");
 
+      // Initialize
+      final MCServer server = getServer();
+
       // Precondition check
       LifecycleState state = server.getState();
       TestCase.assertTrue("Server should not yet be started", !state.equals(LifecycleState.STARTED));
@@ -142,8 +90,8 @@
        * Install a test MC bean into the Server, ensure MC takes
        * over and lifecycle is invoked
        */
-      this.installPojo(server);
-      this.assertPojo();
+      this.installPojo(server, BIND_NAME_POJO);
+      this.assertPojo(BIND_NAME_POJO);
    }
 
    /**
@@ -156,6 +104,9 @@
       // Log
       log.info("testKernelDeployments");
 
+      // Initialize
+      final MCServer server = getServer();
+
       // Set name to deploy a test POJO via XML
       server.getConfiguration().bootstrapName(NAME_BOOTSTRAP_POJO);
 
@@ -184,7 +135,7 @@
       log.info("testBootstrapDeployment");
 
       // Initialize
-      final MCServer server = this.server;
+      final MCServer server = getServer();
 
       // Set name to deploy a test POJO via XML
       server.getConfiguration().bootstrapName(NAME_BOOTSTRAP_POJO);
@@ -193,7 +144,7 @@
       server.start();
 
       // Test the POJO
-      this.assertPojo();
+      this.assertPojo(BIND_NAME_POJO);
    }
 
    /**
@@ -210,7 +161,7 @@
       log.info("testRestart");
 
       // Initialize
-      final MCServer server = this.server;
+      final MCServer server = getServer();
 
       // Start the server
       server.start();
@@ -234,104 +185,4 @@
       TestCase.assertTrue("The server did not restart as expected", restartedOk);
    }
 
-   //-------------------------------------------------------------------------------------||
-   // Internal Helper Methods ------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Obtains a server configuration populated with all URLs and name
-    */
-   private MCServerConfig createServerConfig()
-   {
-      // Get the home
-      final URL home = this.getHome();
-
-      // Populate and return
-      return new BasicMCServerConfig().bootstrapHome(home);
-   }
-
-   /**
-    * Obtains the home relative to this test location
-    * @return
-    */
-   private URL getHome()
-   {
-      return this.getClass().getProtectionDomain().getCodeSource().getLocation();
-   }
-
-   /**
-    * Installs a POJO into the specified server
-    * 
-    * @param server
-    * @throws Throwable
-    */
-   private void installPojo(final MCServer server) throws Throwable
-   {
-      // Construct BeanMetaData
-      final Pojo pojo = new Pojo();
-      final String mcBindName = BIND_NAME_POJO;
-      final BeanMetaData beanMD = BeanMetaDataBuilder.createBuilder(mcBindName, pojo.getClass().getName())
-            .getBeanMetaData();
-
-      // Get the controller and install
-      log.info("Installing test POJO under name " + mcBindName + " into " + server + "...");
-      server.getKernel().getController().install(beanMD, pojo);
-   }
-
-   /**
-    * Ensures that the POJO is installed at {@link MCServerUnitTestCase#BIND_NAME_POJO}
-    * and has no expected value
-    * 
-    * @throws Throwable
-    */
-   private void assertPojo() throws Throwable
-   {
-      this.assertPojo(null);
-   }
-
-   /**
-    * Ensures that the POJO is installed at {@link MCServerUnitTestCase#BIND_NAME_POJO}
-    * and has the expected value
-    * 
-    * @param expectedValue
-    * @throws Throwable
-    */
-   private void assertPojo(final String expectedValue) throws Throwable
-   {
-      // Log
-      log.trace("Asserting POJO installed as expected...");
-
-      // Get the underlying bean context
-      final String mcBindName = BIND_NAME_POJO;
-      final KernelController controller = this.server.getKernel().getController();
-      final ControllerContext beanContext = controller.getContext(mcBindName, null);
-      TestCase.assertNotNull("beanContext from " + mcBindName + " is null", beanContext);
-      final ControllerState beanState = beanContext.getState();
-      TestCase.assertEquals("POJO did not properly install, error was: " + beanContext.getError(),
-            ControllerState.INSTALLED, beanState);
-
-      // Get Pojo
-      final Object target = beanContext.getTarget();
-      TestCase.assertNotNull("POJO could not be found in MC at: " + mcBindName, target);
-      Pojo pojo = null;
-      try
-      {
-         pojo = Pojo.class.cast(target);
-      }
-      catch (ClassCastException cce)
-      {
-         TestCase.fail("Test pojo was not expected type: " + cce);
-      }
-
-      // Test Lifecycle was invoked by MC
-      final boolean pojoStarted = pojo.isStarted();
-      TestCase.assertTrue("Start lifecycle was not called upon the POJO", pojoStarted);
-
-      // Test expected value
-      final String actualvalue = pojo.getValue();
-      TestCase.assertEquals("POJO did not have expected value", expectedValue, actualvalue);
-
-      // Log
-      log.info("POJO installed as expected with value: " + actualvalue);
-   }
 }

Added: projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap-starting-slash.xml
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap-starting-slash.xml	                        (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap-starting-slash.xml	2009-08-18 12:11:13 UTC (rev 92522)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<bootstrap xmlns="urn:jboss:bootstrap:1.0">
+
+  <url>/pojo.xml</url>
+
+</bootstrap>
+

Added: projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap-urls.xml
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap-urls.xml	                        (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap-urls.xml	2009-08-18 12:11:13 UTC (rev 92522)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<bootstrap xmlns="urn:jboss:bootstrap:1.0">
+
+  <url>http://localhost:12345/pojo.xml</url>
+  <url>pojo2.xml</url>
+
+</bootstrap>
+

Added: projects/bootstrap/trunk/impl-mc/src/test/resources/pojo2.xml
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/resources/pojo2.xml	                        (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/resources/pojo2.xml	2009-08-18 12:11:13 UTC (rev 92522)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+  Test POJO
+  
+  Deploys a POJO with no value
+  
+-->
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+  <bean name="org.jboss.bootstrap.test.POJO_2" class="org.jboss.bootstrap.impl.mc.server.Pojo" />
+
+</deployment>




More information about the jboss-cvs-commits mailing list