[jboss-cvs] JBossAS SVN: r87189 - in projects/bootstrap/trunk/impl-mc/src: main/java/org/jboss/bootstrap/impl/mc/server and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Apr 13 13:43:38 EDT 2009
Author: ALRubinger
Date: 2009-04-13 13:43:38 -0400 (Mon, 13 Apr 2009)
New Revision: 87189
Added:
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/MCConfigurationInitializer.java
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/MCConfigurationValidator.java
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/MCServerInitializer.java
projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap-pojo.xml
projects/bootstrap/trunk/impl-mc/src/test/resources/conf/
projects/bootstrap/trunk/impl-mc/src/test/resources/conf/pojo.xml
projects/bootstrap/trunk/impl-mc/src/test/resources/pojo.xml
Modified:
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java
projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/Pojo.java
projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java
Log:
[JBBOOT-35] Assert that bootstrap.xml and its referents are processed
Added: projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/MCConfigurationInitializer.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/MCConfigurationInitializer.java (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/MCConfigurationInitializer.java 2009-04-13 17:43:38 UTC (rev 87189)
@@ -0,0 +1,42 @@
+/*
+ * 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.config;
+
+import org.jboss.bootstrap.spi.config.AbstractBasicConfigurationInitializer;
+import org.jboss.bootstrap.spi.config.ConfigurationInitializer;
+import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
+
+/**
+ * MCConfigurationInitializer
+ *
+ * A Configuration Initializer for MC Servers
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MCConfigurationInitializer extends AbstractBasicConfigurationInitializer<MCServerConfig>
+ implements
+ ConfigurationInitializer<MCServerConfig>
+{
+ // Impl in superclass
+}
Added: projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/MCConfigurationValidator.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/MCConfigurationValidator.java (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/config/MCConfigurationValidator.java 2009-04-13 17:43:38 UTC (rev 87189)
@@ -0,0 +1,42 @@
+/*
+ * 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.config;
+
+import org.jboss.bootstrap.spi.config.AbstractBasicConfigurationValidator;
+import org.jboss.bootstrap.spi.config.ConfigurationValidator;
+import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
+
+/**
+ * MCConfigurationValidator
+ *
+ * A Configuration Validator for MC Servers
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MCConfigurationValidator extends AbstractBasicConfigurationValidator<MCServerConfig>
+ implements
+ ConfigurationValidator<MCServerConfig>
+{
+ // Impl in superclass
+}
Added: 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 (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java 2009-04-13 17:43:38 UTC (rev 87189)
@@ -0,0 +1,252 @@
+/*
+ * 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;
+
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.bootstrap.impl.mc.deployer.TempBasicXMLDeployer;
+import org.jboss.bootstrap.spi.mc.config.MCBasedServerConfig;
+import org.jboss.bootstrap.spi.mc.server.MCBasedServer;
+import org.jboss.bootstrap.spi.metadata.BootstrapMetaData;
+import org.jboss.bootstrap.spi.server.AbstractServer;
+import org.jboss.bootstrap.spi.xml.BootstrapParser;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.logging.Logger;
+
+/**
+ * AbstractMCServerBase
+ *
+ * Microcontainer implementation of a Server.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author Scott.Stark at jboss.org
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractMCServerBase<K extends MCBasedServer<K, T>, T extends MCBasedServerConfig<T>>
+ extends
+ AbstractServer<K, T> implements MCBasedServer<K, T>
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(AbstractMCServerBase.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The MC Bootstrap
+ */
+ private BasicBootstrap bootstrap;
+
+ /**
+ * The MC Kernel
+ */
+ private Kernel kernel;
+
+ /**
+ * The XML Deployer
+ */
+ private TempBasicXMLDeployer kernelDeployer;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ *
+ * Creates the server with no default configuration
+ */
+ protected AbstractMCServerBase()
+ {
+ this(null);
+ }
+
+ /**
+ * Constructor
+ *
+ * Creates the server from the specified configuration
+ *
+ * @param config
+ */
+ protected AbstractMCServerBase(final T config)
+ {
+ // Invoke super
+ super(config);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.mc.server.MCServer#getKernel()
+ */
+ public Kernel getKernel()
+ {
+ return this.kernel;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.server.AbstractServer#doShutdown()
+ */
+ @Override
+ protected void doShutdown() throws Exception
+ {
+ // Shutdown the deployer
+ try
+ {
+ if (kernelDeployer != null)
+ {
+ kernelDeployer.shutdown();
+ kernelDeployer = null;
+ }
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error stopping xml deployer", t);
+ }
+
+ // Shutdown the controller
+ try
+ {
+ Kernel currentKernel = null;
+ if (kernel != null)
+ {
+ currentKernel = kernel;
+ kernel = null;
+ }
+ else if (bootstrap != null)
+ {
+ currentKernel = bootstrap.getKernel();
+ }
+ bootstrap = null;
+
+ if (currentKernel != null)
+ {
+ KernelController controller = currentKernel.getController();
+ controller.shutdown();
+ }
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error stopping xml deployer", t);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.server.AbstractServer#doStart()
+ */
+ @Override
+ protected void doStart() throws Exception
+ {
+ // Bootstrap and set the kernel
+ final BasicBootstrap bootstrap = new BasicBootstrap();
+ bootstrap.run();
+ kernel = bootstrap.getKernel();
+ this.bootstrap = bootstrap;
+
+ // Register the server implementation
+ final String mcServerBindName = "JBossServer";
+ final KernelController controller = kernel.getController();
+ final BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(mcServerBindName, getClass().getName());
+ builder.addMethodInstallCallback("addBootstrap");
+ builder.addMethodUninstallCallback("removeBootstrap");
+ builder.ignoreStart(); // We invoke start manually, don't let MC do it
+ try
+ {
+ log.debug("Installing " + this + " into MC under key: " + mcServerBindName);
+ controller.install(builder.getBeanMetaData(), this);
+ }
+ catch (Throwable t)
+ {
+ throw new Exception("Error in installing " + mcServerBindName + " during startup", t);
+ }
+
+ // Determine the url for the bootstrap
+ final T config = this.getConfiguration();
+ final URL configURL = config.getBootstrapConfLocation();
+ final URL bootstrapUrl = config.getBootstrapUrl();
+ log.info("Starting Microcontainer, Main bootstrapURL=" + bootstrapUrl);
+
+ // Parse the bootstrap metadata
+ final BootstrapMetaData bootstrapMetaData = BootstrapParser.parse(bootstrapUrl);
+ List<String> bootstrapURLs = bootstrapMetaData.getBootstrapURLs();
+ if (bootstrapURLs == null)
+ {
+ bootstrapURLs = Collections.emptyList();
+ }
+ if (bootstrapURLs.isEmpty())
+ {
+ log.warn("No bootstrap urls in " + bootstrapUrl);
+ }
+ log.debug("BootstrapURLs=" + bootstrapURLs);
+ log.debug("Bootstrap URLs are relative to: " + configURL);
+
+ // Create an xml deployer
+ kernelDeployer = new TempBasicXMLDeployer(kernel);
+ try
+ {
+ // Deploy the bootstrap urls
+ for (String bootstrapURL : bootstrapURLs)
+ {
+ log.debug("BEFORE: " + bootstrapURL);
+ final URL suburl = new URL(configURL, bootstrapURL);
+ log.debug("Deploying bootstrap xml: " + suburl);
+ kernelDeployer.deploy(suburl);
+ }
+
+ // Check it is complete
+ kernelDeployer.validate();
+ }
+ catch (Throwable t)
+ {
+ try
+ {
+ kernelDeployer.shutdown();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ throw new Exception("Encountered exception in server startup", t);
+ }
+
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+}
Modified: projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java 2009-04-13 17:37:09 UTC (rev 87188)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java 2009-04-13 17:43:38 UTC (rev 87189)
@@ -22,212 +22,112 @@
package org.jboss.bootstrap.impl.mc.server;
-import java.net.URL;
-import java.util.Collections;
-import java.util.List;
-
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
-import org.jboss.bootstrap.impl.mc.deployer.TempBasicXMLDeployer;
-import org.jboss.bootstrap.spi.config.InvalidConfigurationException;
+import org.jboss.bootstrap.impl.mc.config.MCConfigurationInitializer;
+import org.jboss.bootstrap.impl.mc.config.MCConfigurationValidator;
import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
import org.jboss.bootstrap.spi.mc.server.MCServer;
-import org.jboss.bootstrap.spi.metadata.BootstrapMetaData;
-import org.jboss.bootstrap.spi.server.AbstractServer;
-import org.jboss.bootstrap.spi.xml.BootstrapParser;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
-import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.logging.Logger;
/**
* MCServerImpl
*
- * Microcontainer implementation of a Server.
+ * Concrete implementation of a basic Microcontainer-baked
+ * Server
*
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- * @author Scott.Stark at jboss.org
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public class MCServerImpl extends AbstractServer<MCServer, MCServerConfig> implements MCServer
+public class MCServerImpl extends AbstractMCServerBase<MCServer, MCServerConfig> implements MCServer
{
-
//-------------------------------------------------------------------------------------||
// Class Members ----------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
private static final Logger log = Logger.getLogger(MCServerImpl.class);
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * The MC Bootstrap
+ /**
+ * Config initializer instance
*/
- private BasicBootstrap bootstrap;
+ private static final MCConfigurationInitializer CONFIG_INITIALIZER = new MCConfigurationInitializer();
/**
- * The MC Kernel
+ * Config validator instance
*/
- private Kernel kernel;
+ private static final MCConfigurationValidator VALIDATOR = new MCConfigurationValidator();
/**
- * The XML Deployer
+ * Server Initializer instance
*/
- private TempBasicXMLDeployer kernelDeployer;
+ private static final MCServerInitializer SERVER_INITIALIZER = new MCServerInitializer();
//-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
- public MCServerImpl(final MCServerConfig config) throws InvalidConfigurationException, IllegalArgumentException
- {
- // Invoke super
- super(config);
-
- // Bootstrap and set the kernel
- BasicBootstrap bootstrap = new BasicBootstrap();
- bootstrap.run();
- kernel = bootstrap.getKernel();
-
- this.bootstrap = bootstrap;
- }
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /* (non-Javadoc)
- * @see org.jboss.bootstrap.spi.mc.server.MCServer#getKernel()
+ /**
+ * Constructor
+ *
+ * Creates the server with no initial configuration
*/
- public Kernel getKernel()
+ public MCServerImpl()
{
- return this.kernel;
+ this(null);
}
- /* (non-Javadoc)
- * @see org.jboss.bootstrap.spi.server.AbstractServer#doShutdown()
+ /**
+ * Creates the server with the specified initial configuration,
+ * defaulting the config initializer, server initializer, and
+ * config validator if not already set
+ *
+ * @param config
*/
- @Override
- protected void doShutdown() throws Exception
+ public MCServerImpl(final MCServerConfig config)
{
- // Shutdown the deployer
- try
- {
- if (kernelDeployer != null)
- {
- kernelDeployer.shutdown();
- kernelDeployer = null;
- }
- }
- catch (Throwable t)
- {
- log.warn("Error stopping xml deployer", t);
- }
-
- // Shutdown the controller
- try
- {
- Kernel currentKernel = null;
- if (kernel != null)
- {
- currentKernel = kernel;
- kernel = null;
- }
- else if (bootstrap != null)
- {
- currentKernel = bootstrap.getKernel();
- }
- bootstrap = null;
-
- if (currentKernel != null)
- {
- KernelController controller = currentKernel.getController();
- controller.shutdown();
- }
- }
- catch (Throwable t)
- {
- log.warn("Error stopping xml deployer", t);
- }
-
+ this(config, true);
}
- /* (non-Javadoc)
- * @see org.jboss.bootstrap.spi.server.AbstractServer#doStart()
+ /**
+ * Creates the server with the specified initial configuration,
+ * optionally defaulting the config initializer, server initializer, and
+ * config validator if not already set
+ *
+ * @param config
+ * @param defaultInit Whether to default the config initializer,
+ * server initializer, and config validator if not already set
*/
- @Override
- protected void doStart() throws Exception
+ public MCServerImpl(final MCServerConfig config, boolean defaultInit)
{
- // Register the server implementation
- final String mcServerBindName = "JBossServer";
- final KernelController controller = kernel.getController();
- final BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(mcServerBindName, getClass().getName());
- builder.addMethodInstallCallback("addBootstrap");
- builder.addMethodUninstallCallback("removeBootstrap");
- builder.ignoreStart(); // We invoke start manually, don't let MC do it
- try
- {
- log.debug("Installing " + this + " into MC under key: " + mcServerBindName);
- controller.install(builder.getBeanMetaData(), this);
- }
- catch (Throwable t)
- {
- throw new Exception("Error in installing " + mcServerBindName + " during startup", t);
- }
+ super(config);
- // Determine the url for the bootstrap
- final MCServerConfig config = this.getConfiguration();
- final URL configURL = config.getBootstrapConfLocation();
- URL url = config.getBootstrapUrl();
- log.info("Starting Microcontainer, bootstrapURL=" + url);
-
- // Parse the bootstrap metadata
- final BootstrapMetaData bootstrapMetaData = BootstrapParser.parse(url);
- List<String> bootstrapURLs = bootstrapMetaData.getBootstrapURLs();
- if (bootstrapURLs == null)
+ if (defaultInit)
{
- bootstrapURLs = Collections.emptyList();
- }
- if (bootstrapURLs.isEmpty())
- {
- log.warn("No bootstrap urls in " + url);
- }
- log.debug("BootstrapURLs=" + bootstrapURLs);
-
- // Create an xml deployer
- kernelDeployer = new TempBasicXMLDeployer(kernel);
- try
- {
- // Deploy the bootstrap urls
- for (String bootstrapURL : bootstrapURLs)
+ synchronized (this)
{
- log.debug("Deploying bootstrap xml:" + bootstrapURL);
- url = new URL(configURL, bootstrapURL);
- kernelDeployer.deploy(url);
+ // Set properties if not already set
+ if (this.getConfigInitializer() == null)
+ {
+ this.setConfigInitializer(CONFIG_INITIALIZER);
+ log.debug("Defaulted: " + CONFIG_INITIALIZER);
+ }
+ if (this.getValidator() == null)
+ {
+ this.setValidator(VALIDATOR);
+ log.debug("Defaulted: " + VALIDATOR);
+ }
+ if (this.getServerInitializer() == null)
+ {
+ this.setServerInitializer(SERVER_INITIALIZER);
+ log.debug("Defaulted: " + SERVER_INITIALIZER);
+ }
}
-
- // Check it is complete
- kernelDeployer.validate();
}
- catch (Throwable t)
+ else
{
- try
+ if (log.isTraceEnabled())
{
- kernelDeployer.shutdown();
+ log
+ .trace("defaultInit is not set, skipping defaulting of server initializer, config initializer, server validator");
}
- catch (Throwable ignored)
- {
- }
- throw new Exception("Encountered exception in server startup", t);
}
-
}
-
- //-------------------------------------------------------------------------------------||
- // Internal Helper Methods ------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
}
Added: projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerInitializer.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerInitializer.java (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerInitializer.java 2009-04-13 17:43:38 UTC (rev 87189)
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
+import org.jboss.bootstrap.spi.mc.server.MCServer;
+import org.jboss.bootstrap.spi.server.AbstractBasicServerInitializer;
+import org.jboss.bootstrap.spi.server.ServerInitializer;
+
+/**
+ * MCServerInitializer
+ *
+ * A Server Initializer for MC Servers
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MCServerInitializer extends AbstractBasicServerInitializer<MCServer, MCServerConfig>
+ implements
+ ServerInitializer<MCServer, MCServerConfig>
+{
+ // Impl in superclass
+}
Modified: projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/Pojo.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/Pojo.java 2009-04-13 17:37:09 UTC (rev 87188)
+++ projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/Pojo.java 2009-04-13 17:43:38 UTC (rev 87189)
@@ -48,6 +48,8 @@
private boolean started = false;
+ private String value;
+
//-------------------------------------------------------------------------------------||
// Functional Methods -----------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -70,4 +72,24 @@
{
return this.started;
}
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the value
+ */
+ public String getValue()
+ {
+ return value;
+ }
+
+ /**
+ * @param value the value to set
+ */
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
}
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-04-13 17:37:09 UTC (rev 87188)
+++ projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java 2009-04-13 17:43:38 UTC (rev 87189)
@@ -22,7 +22,6 @@
package org.jboss.bootstrap.impl.mc.server.unit;
-import java.net.MalformedURLException;
import java.net.URL;
import junit.framework.TestCase;
@@ -41,7 +40,6 @@
import org.jboss.logging.Logger;
import org.junit.After;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
/**
@@ -61,14 +59,22 @@
private static final Logger log = Logger.getLogger(MCServerUnitTestCase.class);
- private static final String NAME_CONF = "conf";
+ private static final String NAME_CONF = "conf/";
- private static final String NAME_BOOTSTRAP = "bootstrap.xml";
+ private static final String NAME_BOOTSTRAP_POJO = "bootstrap-pojo.xml";
+ private static final String BIND_NAME_POJO = "org.jboss.bootstrap.test.POJO";
+
+ private static final String VALUE_POJO_CONF_DEPLOYMENT = "deployedFromConf";
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
/**
* The server to test
*/
- private static MCServer server;
+ private MCServer server;
//-------------------------------------------------------------------------------------||
// Lifecycle --------------------------------------------------------------------------||
@@ -77,36 +83,31 @@
/**
* Creates the server
*/
- @BeforeClass
- public static void createServer() throws Throwable
+ @Before
+ public void createServer() throws Throwable
{
// Create the server
- final MCServerConfig config = getServerConfig();
- server = new MCServerImpl(config);
+ final MCServerConfig config = createServerConfig();
+ this.server = new MCServerImpl(config);
+ log.info("Created: " + this.server);
}
/**
- * Starts the server
- *
- * @throws Throwable
- */
- @Before
- public void startServer() throws Throwable
- {
- server.start();
- }
-
- /**
* If started, shuts down the server
* @throws Throwable
*/
@After
- public void shutdownServer() throws Throwable
+ 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");
}
//-------------------------------------------------------------------------------------||
@@ -123,10 +124,17 @@
public void testMcIntegration() throws Throwable
{
// Log
- log.info("Testing server for start and valid MC accessibility");
+ log.info("testMcIntegration");
+ // Precondition check
+ LifecycleState state = server.getState();
+ TestCase.assertTrue("Server should not yet be started", !state.equals(LifecycleState.STARTED));
+
+ // Start
+ server.start();
+
// Get state
- final LifecycleState state = server.getState();
+ state = server.getState();
// Ensure reports as started
TestCase.assertTrue("Server should report as started", state.equals(LifecycleState.STARTED));
@@ -136,21 +144,64 @@
* over and lifecycle is invoked
*/
final Pojo pojo = new Pojo();
- final String mcBindName = "org.jboss.bootstrap.test.POJO";
+ final String mcBindName = BIND_NAME_POJO;
final BeanMetaData beanMD = BeanMetaDataBuilder.createBuilder(mcBindName, pojo.getClass().getName())
.getBeanMetaData();
final KernelController controller = server.getKernel().getController();
controller.install(beanMD, pojo);
- final ControllerContext beanContext = controller.getContext(mcBindName, null);
- final ControllerState beanState = beanContext.getState();
- TestCase.assertEquals("POJO did not properly install, error was: " + beanContext.getError(),
- ControllerState.INSTALLED, beanState);
+ this.assertPojo();
+ }
- // Test Lifecycle was invoked by MC
- final boolean pojoStarted = pojo.isStarted();
- TestCase.assertTrue("Start lifecycle was not called upon the POJO", pojoStarted);
+ /**
+ * Ensures that deployment from a bootstrap.xml succeeds as expected
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testBootstrapDeployment() throws Throwable
+ {
+ // Log
+ log.info("testBootstrapDeployment");
+
+ // Initialize
+ final MCServer server = this.server;
+
+ // Set name to deploy a test POJO via XML
+ server.getConfiguration().bootstrapName(NAME_BOOTSTRAP_POJO);
+
+ // Start the server
+ server.start();
+
+ // Test the POJO
+ this.assertPojo();
}
+ /**
+ * Ensures that deployment from a bootstrap.xml is relative to
+ * an explicit bootstrap configuration directory
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testBootstrapDeploymentFromExplicitConf() throws Throwable
+ {
+ // Log
+ log.info("testBootstrapDeploymentFromExplicitConf");
+
+ // Initialize
+ final MCServer server = this.server;
+
+ // Set name to deploy a test POJO via XML with default value
+ final URL conf = new URL(this.getHome(), NAME_CONF);
+ server.getConfiguration().bootstrapName(NAME_BOOTSTRAP_POJO).bootstrapConfLocation(conf);
+
+ // Start the server
+ server.start();
+
+ // Test the POJO
+ this.assertPojo(VALUE_POJO_CONF_DEPLOYMENT);
+ }
+
//-------------------------------------------------------------------------------------||
// Internal Helper Methods ------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -158,26 +209,78 @@
/**
* Obtains a server configuration populated with all URLs and name
*/
- private static MCServerConfig getServerConfig()
+ private MCServerConfig createServerConfig()
{
// Get the home
- final URL home = MCServerUnitTestCase.class.getProtectionDomain().getCodeSource().getLocation();
+ final URL home = this.getHome();
- // Construct URLs
- URL conf = null;
- URL bootstrap = null;
+ // 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();
+ }
+
+ /**
+ * 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
{
- conf = new URL(home, NAME_CONF);
- bootstrap = new URL(home, NAME_BOOTSTRAP);
+ pojo = Pojo.class.cast(target);
}
- catch (MalformedURLException e)
+ catch (ClassCastException cce)
{
- throw new RuntimeException("Error in URL (improper test setup)", e);
+ TestCase.fail("Test pojo was not expected type: " + cce);
}
- // Populate and return
- return new BasicMCServerConfig().bootstrapHome(home).bootstrapConfLocation(conf).bootstrapUrl(bootstrap)
- .bootstrapName(NAME_BOOTSTRAP);
+ // 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-pojo.xml
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap-pojo.xml (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/resources/bootstrap-pojo.xml 2009-04-13 17:43:38 UTC (rev 87189)
@@ -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/conf/pojo.xml
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/resources/conf/pojo.xml (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/resources/conf/pojo.xml 2009-04-13 17:43:38 UTC (rev 87189)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+ Test POJO
+
+ Deploys a POJO with an initial value
+
+-->
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="org.jboss.bootstrap.test.POJO" class="org.jboss.bootstrap.impl.mc.server.Pojo">
+ <property name="value">deployedFromConf</property>
+ </bean>
+
+</deployment>
Added: projects/bootstrap/trunk/impl-mc/src/test/resources/pojo.xml
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/resources/pojo.xml (rev 0)
+++ projects/bootstrap/trunk/impl-mc/src/test/resources/pojo.xml 2009-04-13 17:43:38 UTC (rev 87189)
@@ -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" class="org.jboss.bootstrap.impl.mc.server.Pojo" />
+
+</deployment>
More information about the jboss-cvs-commits
mailing list