[jboss-cvs] JBossAS SVN: r87119 - in projects/bootstrap/trunk/spi/src: test/java/org/jboss/bootstrap/spi and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Apr 10 06:56:39 EDT 2009
Author: ALRubinger
Date: 2009-04-10 06:56:39 -0400 (Fri, 10 Apr 2009)
New Revision: 87119
Added:
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/
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/ConfigValidationTestCase.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/TestNoOpServer.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerLifecycleTestCase.java
Removed:
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/ConfigInitializationTestCase.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/ConfigValidationTestCase.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestNoOpServer.java
Modified:
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractBasicServerInitializer.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/CountingConfigurationValidator.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/CountingServerInitializer.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigFactory.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigurationValidator.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestServerConfig.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestServerInitializer.java
Log:
[JBBOOT-26] Lifecycle tests for Server
Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractBasicServerInitializer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractBasicServerInitializer.java 2009-04-10 10:42:21 UTC (rev 87118)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractBasicServerInitializer.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -117,10 +117,7 @@
}
// Log
- if (log.isTraceEnabled())
- {
- log.trace("New bootstrap URL: " + newBootstrapUrl.toExternalForm());
- }
+ log.debug("New bootstrap URL: " + newBootstrapUrl.toExternalForm());
// Set
config.setBootstrapUrl(newBootstrapUrl);
@@ -140,7 +137,9 @@
{
try
{
- newConf = new URL(home.toExternalForm());
+ String homeExternal = home.toExternalForm();
+ newConf = new URL(homeExternal);
+ log.debug("Defaulted bootstrapConf from bootstrap home: " + homeExternal);
}
catch (MalformedURLException e)
{
@@ -155,6 +154,7 @@
String bootstrapUrlString = bootstrapUrl.toExternalForm();
String bootstrapUrlBase = bootstrapUrlString.substring(0, bootstrapUrlString.lastIndexOf("/") + 1);
newConf = new URL(bootstrapUrlBase);
+ log.debug("Defaulted bootstrapConf from bootstrapURL's base: " + bootstrapUrlBase);
}
catch (MalformedURLException e)
{
Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java 2009-04-10 10:42:21 UTC (rev 87118)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -316,8 +316,11 @@
log.debug("No initializer defined, skipping initialization of " + this);
}
- // Freeze
+ // Freeze config
config.freeze();
+
+ // Set state
+ this.setState(LifecycleState.IDLE);
}
/* (non-Javadoc)
Deleted: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/ConfigInitializationTestCase.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/ConfigInitializationTestCase.java 2009-04-10 10:42:21 UTC (rev 87118)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/ConfigInitializationTestCase.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -1,232 +0,0 @@
-/*
- * 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;
-
-import java.net.URL;
-
-import junit.framework.TestCase;
-
-import org.jboss.logging.Logger;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * ConfigInitializationTestCase
- *
- * Ensures that the base configuration initialization is correct
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ConfigInitializationTestCase
-{
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- private static final Logger log = Logger.getLogger(ConfigValidationTestCase.class);
-
- private static CountingServerInitializer initializer;
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- private TestNoOpServer server;
-
- //-------------------------------------------------------------------------------------||
- // Lifecycle --------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- @BeforeClass
- public static void createInitializer() throws Throwable
- {
- initializer = new TestServerInitializer();
- log.info("Created: " + initializer);
- }
-
- @Before
- public void createServer()
- {
- this.server = new TestNoOpServer();
- log.info("Created: " + this.server);
- }
-
- @After
- public void resetServer()
- {
- this.server = null;
- log.info("Cleaned up server to null");
- }
-
- //-------------------------------------------------------------------------------------||
- // Tests ------------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Ensures that the conf is defaulted from home
- *
- * @throws Throwable
- */
- @Test
- public void testBootstrapConfDefaultedInInitializationFromHome() throws Throwable
- {
- // Log
- log.info("testBootstrapConfDefaultedInInitializationFromHome");
-
- // Get a populated config and server
- final TestServerConfig configuration = TestConfigFactory.createConfiguration();
- final TestNoOpServer server = this.server;
-
- // Remove conf and set on server
- configuration.setBootstrapConfLocation(null);
- server.setConfiguration(configuration);
-
- // Initialize
- initializer.initialize(server);
-
- // Create the expected URL
- final URL expectedConfigurationURL = configuration.getBootstrapHome();
-
- // Get the actual URL
- final URL confURL = configuration.getBootstrapConfLocation();
-
- // Test
- TestCase.assertNotNull("Configuration URL was not initialized", confURL);
- TestCase.assertEquals("Initialized configuration is to incorrect location", expectedConfigurationURL, confURL);
- log.info("Got expected Configuration URL: " + confURL);
- }
-
- /**
- * Ensures that the conf is required by validation if no home is provided
- *
- * @throws Throwable
- */
- @Test
- public void testBootstrapConfDefaultedInInitializationFromBootstrapUrlBase() throws Throwable
- {
- // Get a populated config and server
- final TestServerConfig configuration = TestConfigFactory.createConfiguration();
- final TestNoOpServer server = this.server;
-
- // Remove conf and home
- configuration.setBootstrapHome(null).setBootstrapConfLocation(null);
- server.setConfiguration(configuration);
-
- // Initialize
- initializer.initialize(server);
-
- // Create the expected URL
- final URL expectedConfigurationURL = TestConfigFactory.getResourcesBase();
-
- // Get the actual URL
- final URL confURL = configuration.getBootstrapConfLocation();
-
- // Test
- TestCase.assertNotNull("Configuration URL was not initialized", confURL);
- TestCase.assertEquals("Initialized configuration is to incorrect location", expectedConfigurationURL, confURL);
- }
-
- /**
- * Ensures that setting a configuration results in proper defaulting
- * of the bootstrap URL if it's not been explicitly specified
- *
- * @throws Throwable
- */
- @Test
- public void testBootstrapUrlDefaultedInInitialization() throws Throwable
- {
- // Get a populated config and server
- final TestServerConfig configuration = TestConfigFactory.createConfiguration();
- final TestNoOpServer server = this.server;
-
- // Remove bootstrapURL
- configuration.setBootstrapUrl(null);
- server.setConfiguration(configuration);
-
- // Initialize
- initializer.initialize(server);
-
- // Create the expected URL
- final URL home = configuration.getBootstrapHome();
- final String name = configuration.getBootstrapName();
- final URL expectedBootstrapURL = new URL(home, name);
-
- // Get the actual URL
- final URL bootstrapUrl = configuration.getBootstrapUrl();
-
- // Test
- TestCase.assertNotNull("Bootstrap URL was not initialized", bootstrapUrl);
- TestCase.assertEquals("Initialized bootstrap is to incorrect location", expectedBootstrapURL, bootstrapUrl);
- }
-
- /**
- * Ensures that the properties backing the configuration are set
- * both on the configuration itself and in the System props
- *
- * @throws Throwable
- */
- @Test
- public void testPropertiesSetInInitialization() throws Throwable
- {
- // Get a populated config and server
- TestServerConfig configuration = TestConfigFactory.createConfiguration();
- final TestNoOpServer server = this.server;
- server.setConfiguration(configuration);
-
- // Initialize
- initializer.initialize(server);
-
- // Get Properties from Configuration
- final String homeFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_HOME_URL);
- final String bootstrapURLFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_URL);
- final String confFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_CONF_URL);
- final String nameFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_NAME);
-
- // Get Properties from System
- final String homeFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_HOME_URL);
- final String bootstrapURLFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_URL);
- final String confFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_CONF_URL);
- final String nameFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_NAME);
-
- // Get Expected Values
- final String home = configuration.getBootstrapHome().toExternalForm();
- final String bootstrapURL = configuration.getBootstrapUrl().toExternalForm();
- final String conf = configuration.getBootstrapConfLocation().toExternalForm();
- final String name = configuration.getBootstrapName();
-
- // Ensure all equal
- TestCase.assertEquals("home in configuration must match the config property", home, homeFromConfigProp);
- TestCase.assertEquals("home in configuration must match the system property", home, homeFromSystem);
- TestCase.assertEquals("bootstrapURL in configuration must match the config property", bootstrapURL,
- bootstrapURLFromConfigProp);
- TestCase.assertEquals("bootstrapURL in configuration must match the system property", bootstrapURL,
- bootstrapURLFromSystem);
- TestCase.assertEquals("conf in configuration must match the config property", conf, confFromConfigProp);
- TestCase.assertEquals("conf in configuration must match the system property", conf, confFromSystem);
- TestCase.assertEquals("name in configuration must match the config property", name, nameFromConfigProp);
- TestCase.assertEquals("name in configuration must match the system property", name, nameFromSystem);
- }
-}
Deleted: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/ConfigValidationTestCase.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/ConfigValidationTestCase.java 2009-04-10 10:42:21 UTC (rev 87118)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/ConfigValidationTestCase.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -1,175 +0,0 @@
-/*
- * 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;
-
-import junit.framework.TestCase;
-
-import org.jboss.logging.Logger;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * ConfigValidationTestCase
- *
- * Ensures that the base configuration validation is correct
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ConfigValidationTestCase
-{
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- private static final Logger log = Logger.getLogger(ConfigValidationTestCase.class);
-
- private static ConfigurationValidator<TestServerConfig> validator;
-
- //-------------------------------------------------------------------------------------||
- // Lifecycle --------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- @BeforeClass
- public static void createValidator() throws Throwable
- {
- validator = new TestConfigurationValidator();
- }
-
- //-------------------------------------------------------------------------------------||
- // Tests ------------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Ensures that a fully-populated config is returned from
- * the factory (as a control)
- */
- @Test
- public void testControl() throws Throwable
- {
- // Log
- log.info("testControl");
-
- // Get a populated config
- final TestServerConfig configuration = TestConfigFactory.createConfiguration();
-
- // Test
- TestCase.assertNotNull("actualClass was not populated", configuration.getActualClass());
- TestCase.assertNotNull("conf was not populated", configuration.getBootstrapConfLocation());
- TestCase.assertNotNull("home was not populated", configuration.getBootstrapHome());
- TestCase.assertNotNull("name was not populated", configuration.getBootstrapName());
- TestCase.assertNotNull("URL was not populated", configuration.getBootstrapUrl());
- }
-
- /**
- * Ensures that a fully-populated config is valid
- */
- @Test
- public void testValidationPopulatedBootstrap() throws Throwable
- {
- // Log
- log.info("testValidationPopulatedBootstrap");
-
- // Get a populated config
- final TestServerConfig configuration = TestConfigFactory.createConfiguration();
-
- // Validate
- try
- {
- validator.validate(configuration);
- }
- catch (InvalidConfigurationException ice)
- {
- TestCase.fail("Configuration fully-populated should be valid, but instead got " + ice.getMessage());
- }
-
- // OK
- return;
- }
-
- /**
- * Ensures that an explicit bootstrapURL with no name or home set passes validation
- *
- * @throws Throwable
- */
- @Test
- public void testValidationExplicitBootstrapUrlWithNoHomeOrName() throws Throwable
- {
- // Log
- log.info("testValidationExplicitBootstrapUrlWithNoHomeOrName");
-
- // Get a populated config
- final TestServerConfig configuration = TestConfigFactory.createConfiguration();
-
- // Remove home and name
- configuration.setBootstrapHome(null).setBootstrapName(null);
-
- // Validate
- try
- {
- validator.validate(configuration);
- }
- catch (InvalidConfigurationException ice)
- {
- TestCase.fail("Configuration with bootstrapURL but no home or name should be valid, but instead got "
- + ice.getMessage());
- }
-
- // OK
- return;
- }
-
- /**
- * Ensures that a configuration with no home, bootstrapURL, or name set fails validation
- *
- * @throws Throwable
- */
- @Test
- public void testValidationNoBootstrapUrlWithNoHomeOrName() throws Throwable
- {
- // Log
- log.info("testValidationNoBootstrapUrlWithNoHomeOrName");
-
- // Get a populated config
- final TestServerConfig configuration = TestConfigFactory.createConfiguration();
-
- // Remove home, name, bootstrapURL
- configuration.setBootstrapHome(null).setBootstrapName(null).setBootstrapUrl(null);
-
- // Validate
- boolean validationFailed = false;
- try
- {
- validator.validate(configuration);
- }
- catch (InvalidConfigurationException ice)
- {
- // Expected
- validationFailed = true;
- }
-
- // Test
- TestCase.assertTrue("Configuration with no home, name or bootstrapURL must fail validation", validationFailed);
- }
-
-}
Modified: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/CountingConfigurationValidator.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/CountingConfigurationValidator.java 2009-04-10 10:42:21 UTC (rev 87118)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/CountingConfigurationValidator.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -31,7 +31,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-interface CountingConfigurationValidator<T extends ServerConfig<?>> extends ConfigurationValidator<T>, Counter
+public interface CountingConfigurationValidator<T extends ServerConfig<?>> extends ConfigurationValidator<T>, Counter
{
}
Modified: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/CountingServerInitializer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/CountingServerInitializer.java 2009-04-10 10:42:21 UTC (rev 87118)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/CountingServerInitializer.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -23,6 +23,7 @@
package org.jboss.bootstrap.spi.config;
import org.jboss.bootstrap.spi.server.ServerInitializer;
+import org.jboss.bootstrap.spi.server.TestNoOpServer;
/**
* CountingServerInitializer
@@ -33,7 +34,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-interface CountingServerInitializer extends ServerInitializer<TestNoOpServer, TestServerConfig>, Counter
+public interface CountingServerInitializer extends ServerInitializer<TestNoOpServer, TestServerConfig>, Counter
{
}
Modified: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigFactory.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigFactory.java 2009-04-10 10:42:21 UTC (rev 87118)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigFactory.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -33,7 +33,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-class TestConfigFactory
+public class TestConfigFactory
{
//-------------------------------------------------------------------------------------||
// Class Members ----------------------------------------------------------------------||
@@ -59,7 +59,7 @@
// Functional Methods -----------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
- static TestServerConfig createConfiguration()
+ public static TestServerConfig createConfiguration()
{
// Create a configuration
final TestServerConfig config = new TestServerConfig();
@@ -85,16 +85,12 @@
NAME_BOOTSTRAP);
}
- //-------------------------------------------------------------------------------------||
- // Internal Helper Methods ------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
/**
* Returns the base of these resources
*
* @return
*/
- static URL getResourcesBase()
+ public static URL getResourcesBase()
{
// Obtain from codesource
final URL base = TestConfigFactory.class.getProtectionDomain().getCodeSource().getLocation();
Modified: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigurationValidator.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigurationValidator.java 2009-04-10 10:42:21 UTC (rev 87118)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigurationValidator.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -32,7 +32,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-class TestConfigurationValidator extends AbstractBasicConfigurationValidator<TestServerConfig>
+public class TestConfigurationValidator extends AbstractBasicConfigurationValidator<TestServerConfig>
implements
CountingConfigurationValidator<TestServerConfig>
{
Deleted: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestNoOpServer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestNoOpServer.java 2009-04-10 10:42:21 UTC (rev 87118)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestNoOpServer.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -1,70 +0,0 @@
-/*
- * 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;
-
-import org.jboss.bootstrap.spi.server.AbstractServer;
-import org.jboss.bootstrap.spi.server.Server;
-import org.jboss.logging.Logger;
-
-/**
- * TestServer
- *
- * A simple server used in testing
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-class TestNoOpServer extends AbstractServer<TestNoOpServer, TestServerConfig>
- implements
- Server<TestNoOpServer, TestServerConfig>
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- private static final Logger log = Logger.getLogger(TestNoOpServer.class);
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /* (non-Javadoc)
- * @see org.jboss.bootstrap.spi.server.AbstractServer#doShutdown()
- */
- @Override
- protected void doShutdown() throws Exception
- {
- log.debug("NOOP doShutdown");
- }
-
- /* (non-Javadoc)
- * @see org.jboss.bootstrap.spi.server.AbstractServer#doStart()
- */
- @Override
- protected void doStart() throws Exception
- {
- log.debug("NOOP doStart");
- }
-
-}
Modified: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestServerConfig.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestServerConfig.java 2009-04-10 10:42:21 UTC (rev 87118)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestServerConfig.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -30,13 +30,15 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-class TestServerConfig extends AbstractBasicServerConfig<TestServerConfig> implements ServerConfig<TestServerConfig>
+public class TestServerConfig extends AbstractBasicServerConfig<TestServerConfig>
+ implements
+ ServerConfig<TestServerConfig>
{
//-------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
- TestServerConfig()
+ public TestServerConfig()
{
super(TestServerConfig.class);
}
Modified: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestServerInitializer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestServerInitializer.java 2009-04-10 10:42:21 UTC (rev 87118)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestServerInitializer.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -26,6 +26,7 @@
import org.jboss.bootstrap.spi.server.AbstractBasicServerInitializer;
import org.jboss.bootstrap.spi.server.Server;
+import org.jboss.bootstrap.spi.server.TestNoOpServer;
/**
* TestServerInitializer
@@ -35,7 +36,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-class TestServerInitializer extends AbstractBasicServerInitializer<TestNoOpServer, TestServerConfig>
+public class TestServerInitializer extends AbstractBasicServerInitializer<TestNoOpServer, TestServerConfig>
implements
CountingServerInitializer
{
Copied: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java (from rev 87115, projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/ConfigInitializationTestCase.java)
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -0,0 +1,238 @@
+/*
+ * 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.CountingServerInitializer;
+import org.jboss.bootstrap.spi.config.ServerConfig;
+import org.jboss.bootstrap.spi.config.TestConfigFactory;
+import org.jboss.bootstrap.spi.config.TestServerConfig;
+import org.jboss.bootstrap.spi.config.TestServerInitializer;
+import org.jboss.bootstrap.spi.server.TestNoOpServer;
+import org.jboss.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * ConfigInitializationTestCase
+ *
+ * Ensures that the base configuration initialization is correct
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ConfigInitializationTestCase
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ConfigValidationTestCase.class);
+
+ private static CountingServerInitializer initializer;
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private TestNoOpServer server;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ @BeforeClass
+ public static void createInitializer() throws Throwable
+ {
+ initializer = new TestServerInitializer();
+ log.info("Created: " + initializer);
+ }
+
+ @Before
+ public void createServer()
+ {
+ this.server = new TestNoOpServer();
+ log.info("Created: " + this.server);
+ }
+
+ @After
+ public void resetServer()
+ {
+ this.server = null;
+ log.info("Cleaned up server to null");
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the conf is defaulted from home
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testBootstrapConfDefaultedInInitializationFromHome() throws Throwable
+ {
+ // Log
+ log.info("testBootstrapConfDefaultedInInitializationFromHome");
+
+ // Get a populated config and server
+ final TestServerConfig configuration = TestConfigFactory.createConfiguration();
+ final TestNoOpServer server = this.server;
+
+ // Remove conf and set on server
+ configuration.setBootstrapConfLocation(null);
+ server.setConfiguration(configuration);
+
+ // Initialize
+ initializer.initialize(server);
+
+ // Create the expected URL
+ final URL expectedConfigurationURL = configuration.getBootstrapHome();
+
+ // Get the actual URL
+ final URL confURL = configuration.getBootstrapConfLocation();
+
+ // Test
+ TestCase.assertNotNull("Configuration URL was not initialized", confURL);
+ TestCase.assertEquals("Initialized configuration is to incorrect location", expectedConfigurationURL, confURL);
+ log.info("Got expected Configuration URL: " + confURL);
+ }
+
+ /**
+ * Ensures that the conf is required by validation if no home is provided
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testBootstrapConfDefaultedInInitializationFromBootstrapUrlBase() throws Throwable
+ {
+ // Get a populated config and server
+ final TestServerConfig configuration = TestConfigFactory.createConfiguration();
+ final TestNoOpServer server = this.server;
+
+ // Remove conf and home
+ configuration.setBootstrapHome(null).setBootstrapConfLocation(null);
+ server.setConfiguration(configuration);
+
+ // Initialize
+ initializer.initialize(server);
+
+ // Create the expected URL
+ final URL expectedConfigurationURL = TestConfigFactory.getResourcesBase();
+
+ // Get the actual URL
+ final URL confURL = configuration.getBootstrapConfLocation();
+
+ // Test
+ TestCase.assertNotNull("Configuration URL was not initialized", confURL);
+ TestCase.assertEquals("Initialized configuration is to incorrect location", expectedConfigurationURL, confURL);
+ }
+
+ /**
+ * Ensures that setting a configuration results in proper defaulting
+ * of the bootstrap URL if it's not been explicitly specified
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testBootstrapUrlDefaultedInInitialization() throws Throwable
+ {
+ // Get a populated config and server
+ final TestServerConfig configuration = TestConfigFactory.createConfiguration();
+ final TestNoOpServer server = this.server;
+
+ // Remove bootstrapURL
+ configuration.setBootstrapUrl(null);
+ server.setConfiguration(configuration);
+
+ // Initialize
+ initializer.initialize(server);
+
+ // Create the expected URL
+ final URL home = configuration.getBootstrapHome();
+ final String name = configuration.getBootstrapName();
+ final URL expectedBootstrapURL = new URL(home, name);
+
+ // Get the actual URL
+ final URL bootstrapUrl = configuration.getBootstrapUrl();
+
+ // Test
+ TestCase.assertNotNull("Bootstrap URL was not initialized", bootstrapUrl);
+ TestCase.assertEquals("Initialized bootstrap is to incorrect location", expectedBootstrapURL, bootstrapUrl);
+ }
+
+ /**
+ * Ensures that the properties backing the configuration are set
+ * both on the configuration itself and in the System props
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testPropertiesSetInInitialization() throws Throwable
+ {
+ // Get a populated config and server
+ TestServerConfig configuration = TestConfigFactory.createConfiguration();
+ final TestNoOpServer server = this.server;
+ server.setConfiguration(configuration);
+
+ // Initialize
+ initializer.initialize(server);
+
+ // Get Properties from Configuration
+ final String homeFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_HOME_URL);
+ final String bootstrapURLFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_URL);
+ final String confFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_CONF_URL);
+ final String nameFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_NAME);
+
+ // Get Properties from System
+ final String homeFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_HOME_URL);
+ final String bootstrapURLFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_URL);
+ final String confFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_CONF_URL);
+ final String nameFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_NAME);
+
+ // Get Expected Values
+ final String home = configuration.getBootstrapHome().toExternalForm();
+ final String bootstrapURL = configuration.getBootstrapUrl().toExternalForm();
+ final String conf = configuration.getBootstrapConfLocation().toExternalForm();
+ final String name = configuration.getBootstrapName();
+
+ // Ensure all equal
+ TestCase.assertEquals("home in configuration must match the config property", home, homeFromConfigProp);
+ TestCase.assertEquals("home in configuration must match the system property", home, homeFromSystem);
+ TestCase.assertEquals("bootstrapURL in configuration must match the config property", bootstrapURL,
+ bootstrapURLFromConfigProp);
+ TestCase.assertEquals("bootstrapURL in configuration must match the system property", bootstrapURL,
+ bootstrapURLFromSystem);
+ TestCase.assertEquals("conf in configuration must match the config property", conf, confFromConfigProp);
+ TestCase.assertEquals("conf in configuration must match the system property", conf, confFromSystem);
+ TestCase.assertEquals("name in configuration must match the config property", name, nameFromConfigProp);
+ TestCase.assertEquals("name in configuration must match the system property", name, nameFromSystem);
+ }
+}
Property changes on: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigValidationTestCase.java (from rev 87115, projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/ConfigValidationTestCase.java)
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigValidationTestCase.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigValidationTestCase.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -0,0 +1,179 @@
+/*
+ * 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 junit.framework.TestCase;
+
+import org.jboss.bootstrap.spi.config.ConfigurationValidator;
+import org.jboss.bootstrap.spi.config.InvalidConfigurationException;
+import org.jboss.bootstrap.spi.config.TestConfigFactory;
+import org.jboss.bootstrap.spi.config.TestConfigurationValidator;
+import org.jboss.bootstrap.spi.config.TestServerConfig;
+import org.jboss.logging.Logger;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * ConfigValidationTestCase
+ *
+ * Ensures that the base configuration validation is correct
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ConfigValidationTestCase
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ConfigValidationTestCase.class);
+
+ private static ConfigurationValidator<TestServerConfig> validator;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ @BeforeClass
+ public static void createValidator() throws Throwable
+ {
+ validator = new TestConfigurationValidator();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that a fully-populated config is returned from
+ * the factory (as a control)
+ */
+ @Test
+ public void testControl() throws Throwable
+ {
+ // Log
+ log.info("testControl");
+
+ // Get a populated config
+ final TestServerConfig configuration = TestConfigFactory.createConfiguration();
+
+ // Test
+ TestCase.assertNotNull("conf was not populated", configuration.getBootstrapConfLocation());
+ TestCase.assertNotNull("home was not populated", configuration.getBootstrapHome());
+ TestCase.assertNotNull("name was not populated", configuration.getBootstrapName());
+ TestCase.assertNotNull("URL was not populated", configuration.getBootstrapUrl());
+ }
+
+ /**
+ * Ensures that a fully-populated config is valid
+ */
+ @Test
+ public void testValidationPopulatedBootstrap() throws Throwable
+ {
+ // Log
+ log.info("testValidationPopulatedBootstrap");
+
+ // Get a populated config
+ final TestServerConfig configuration = TestConfigFactory.createConfiguration();
+
+ // Validate
+ try
+ {
+ validator.validate(configuration);
+ }
+ catch (InvalidConfigurationException ice)
+ {
+ TestCase.fail("Configuration fully-populated should be valid, but instead got " + ice.getMessage());
+ }
+
+ // OK
+ return;
+ }
+
+ /**
+ * Ensures that an explicit bootstrapURL with no name or home set passes validation
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testValidationExplicitBootstrapUrlWithNoHomeOrName() throws Throwable
+ {
+ // Log
+ log.info("testValidationExplicitBootstrapUrlWithNoHomeOrName");
+
+ // Get a populated config
+ final TestServerConfig configuration = TestConfigFactory.createConfiguration();
+
+ // Remove home and name
+ configuration.setBootstrapHome(null).setBootstrapName(null);
+
+ // Validate
+ try
+ {
+ validator.validate(configuration);
+ }
+ catch (InvalidConfigurationException ice)
+ {
+ TestCase.fail("Configuration with bootstrapURL but no home or name should be valid, but instead got "
+ + ice.getMessage());
+ }
+
+ // OK
+ return;
+ }
+
+ /**
+ * Ensures that a configuration with no home, bootstrapURL, or name set fails validation
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testValidationNoBootstrapUrlWithNoHomeOrName() throws Throwable
+ {
+ // Log
+ log.info("testValidationNoBootstrapUrlWithNoHomeOrName");
+
+ // Get a populated config
+ final TestServerConfig configuration = TestConfigFactory.createConfiguration();
+
+ // Remove home, name, bootstrapURL
+ configuration.setBootstrapHome(null).setBootstrapName(null).setBootstrapUrl(null);
+
+ // Validate
+ boolean validationFailed = false;
+ try
+ {
+ validator.validate(configuration);
+ }
+ catch (InvalidConfigurationException ice)
+ {
+ // Expected
+ validationFailed = true;
+ }
+
+ // Test
+ TestCase.assertTrue("Configuration with no home, name or bootstrapURL must fail validation", validationFailed);
+ }
+
+}
Property changes on: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigValidationTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/TestNoOpServer.java (from rev 87115, projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestNoOpServer.java)
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/TestNoOpServer.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/TestNoOpServer.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -0,0 +1,69 @@
+/*
+ * 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.server;
+
+import org.jboss.bootstrap.spi.config.TestServerConfig;
+import org.jboss.logging.Logger;
+
+/**
+ * TestServer
+ *
+ * A simple server used in testing
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class TestNoOpServer extends AbstractServer<TestNoOpServer, TestServerConfig>
+ implements
+ Server<TestNoOpServer, TestServerConfig>
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(TestNoOpServer.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.server.AbstractServer#doShutdown()
+ */
+ @Override
+ protected void doShutdown() throws Exception
+ {
+ log.debug("NOOP doShutdown");
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.server.AbstractServer#doStart()
+ */
+ @Override
+ protected void doStart() throws Exception
+ {
+ log.debug("NOOP doStart");
+ }
+
+}
Property changes on: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/TestNoOpServer.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerLifecycleTestCase.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerLifecycleTestCase.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerLifecycleTestCase.java 2009-04-10 10:56:39 UTC (rev 87119)
@@ -0,0 +1,189 @@
+/*
+ * 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.server.unit;
+
+import junit.framework.TestCase;
+
+import org.jboss.bootstrap.spi.config.CountingConfigurationValidator;
+import org.jboss.bootstrap.spi.config.CountingServerInitializer;
+import org.jboss.bootstrap.spi.config.TestConfigFactory;
+import org.jboss.bootstrap.spi.config.TestConfigurationValidator;
+import org.jboss.bootstrap.spi.config.TestServerConfig;
+import org.jboss.bootstrap.spi.config.TestServerInitializer;
+import org.jboss.bootstrap.spi.config.unit.ConfigValidationTestCase;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
+import org.jboss.bootstrap.spi.server.TestNoOpServer;
+import org.jboss.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * ServerLifecycleTestCase
+ *
+ * Ensures that lifecycle events take place as expected
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ServerLifecycleTestCase
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ConfigValidationTestCase.class);
+
+ private static CountingServerInitializer initializer;
+
+ private static CountingConfigurationValidator<TestServerConfig> validator;
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private TestNoOpServer server;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ @BeforeClass
+ public static void createInitializerAndValidator()
+ {
+ initializer = new TestServerInitializer();
+ validator = new TestConfigurationValidator();
+ }
+
+ /**
+ * Creates and populates the server
+ */
+ @Before
+ public void createServer()
+ {
+ TestNoOpServer server = new TestNoOpServer();
+ server.setInitializer(initializer);
+ server.setValidator(validator);
+ TestServerConfig config = TestConfigFactory.createConfiguration();
+ server.setConfiguration(config);
+ this.server = server;
+ log.info("Created server: " + server);
+ }
+
+ @After
+ public void removeServer()
+ {
+ this.server = null;
+ log.info("Server reference removed");
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Test to ensure that initialization is run when server start is invoked
+ */
+ @Test
+ public void testInitializationRunOnStart() throws Throwable
+ {
+ // Log
+ log.info("testInitializationRunOnStart");
+
+ // Initialize
+ final int countBefore = initializer.getUsedCount();
+
+ // Get the server and start
+ final TestNoOpServer server = this.server;
+ server.start();
+
+ // Get the new count
+ final int countAfter = initializer.getUsedCount();
+
+ // Ensure incremented by 1
+ TestCase.assertTrue("Initialization was not run on server start", countAfter == countBefore + 1);
+ }
+
+ /**
+ * Test to ensure that validation is run when server start is invoked
+ */
+ @Test
+ public void testValidationRunOnStart() throws Throwable
+ {
+ // Log
+ log.info("testValidationRunOnStart");
+
+ // Initialize
+ final int countBefore = validator.getUsedCount();
+
+ // Get the server and start
+ final TestNoOpServer server = this.server;
+ server.start();
+
+ // Get the new count
+ final int countAfter = validator.getUsedCount();
+
+ // Ensure incremented by 1
+ TestCase.assertTrue("Validation was not run on server start", countAfter == countBefore + 1);
+ }
+
+ /**
+ * Test to ensure that lifecycle reports as expected
+ */
+ @Test
+ public void testLifecycleState() throws Throwable
+ {
+ // Log
+ log.info("testLifecycleState");
+
+ // Get the server
+ final TestNoOpServer server = this.server;
+
+ // Ensure reports as pre-init
+ LifecycleState state = server.getState();
+ TestCase.assertEquals("Lifecycle should be preinit", LifecycleState.PRE_INIT, state);
+
+ // Init
+ server.initialize();
+
+ // Ensure reports as idle
+ state = server.getState();
+ TestCase.assertEquals("Lifecycle should be idle", LifecycleState.IDLE, state);
+
+ // Start
+ server.start();
+
+ // Ensure reports as started
+ state = server.getState();
+ TestCase.assertEquals("Lifecycle should be started", LifecycleState.STARTED, state);
+
+ // Stop
+ server.shutdown();
+
+ // Ensure reports as idle
+ state = server.getState();
+ TestCase.assertEquals("Lifecycle should be idle after shutdown", LifecycleState.IDLE, state);
+ }
+
+}
More information about the jboss-cvs-commits
mailing list