[jboss-cvs] JBossAS SVN: r95540 - in projects/embedded/trunk/core/src: test/java/org/jboss/embedded/core/server and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 23 23:03:10 EDT 2009


Author: ALRubinger
Date: 2009-10-23 23:03:09 -0400 (Fri, 23 Oct 2009)
New Revision: 95540

Added:
   projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/server/ServerInitializationTestCase.java
Modified:
   projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
Log:
[EMB-57] Add tests for Embedded server initialization

Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java	2009-10-24 02:16:31 UTC (rev 95539)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java	2009-10-24 03:03:09 UTC (rev 95540)
@@ -28,6 +28,8 @@
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.jboss.bootstrap.api.as.config.JBossASServerConfig;
+import org.jboss.bootstrap.api.config.InvalidConfigurationException;
+import org.jboss.bootstrap.api.lifecycle.LifecycleEventException;
 import org.jboss.bootstrap.api.lifecycle.LifecycleEventHandler;
 import org.jboss.bootstrap.api.lifecycle.LifecycleState;
 import org.jboss.bootstrap.impl.as.config.BasicJBossASServerConfig;
@@ -138,9 +140,6 @@
          throw new IllegalStateException("JBOSS_HOME must be specified, either via environment variable \""
                + ENV_VAR_JBOSS_HOME + "\" or system property \"" + SYS_PROP_JBOSS_HOME + "\".");
       }
-
-      // Init
-      this.initialize(jbossHome);
    }
 
    /**
@@ -153,9 +152,6 @@
    {
       // Call super
       super(JBossASEmbeddedServer.class);
-
-      // Init
-      this.initialize(jbossHome);
    }
 
    //-------------------------------------------------------------------------------------||
@@ -305,23 +301,15 @@
    // Internal Helper Methods ------------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
 
-   /**
-    * Centralizes initialization for the constructors
-    * 
-    * @param jbossHome
-    * @throws IllegalArgumentException If JBOSS_HOME is not specified
+   /* (non-Javadoc)
+    * @see org.jboss.bootstrap.impl.as.server.AbstractJBossASServerBase#doInitialize()
     */
-   private void initialize(final String jbossHome) throws IllegalArgumentException
+   @Override
+   protected void doInitialize() throws IllegalStateException, InvalidConfigurationException, LifecycleEventException
    {
-      // Precondition check
-      if (jbossHome == null || jbossHome.length() == 0)
-      {
-         throw new IllegalArgumentException("JBOSS_HOME is required but was not specified");
-      }
+      // Invoke super
+      super.doInitialize();
 
-      // Set JBOSS_HOME
-      this.getConfiguration().jbossHome(jbossHome);
-
       // Set some lifecycle handlers
       @SuppressWarnings("deprecation")
       final LifecycleEventHandler ignoreXbOrder = new IgnoreXbUnorderedSequenceLifecycleEventHandler();

Added: projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/server/ServerInitializationTestCase.java
===================================================================
--- projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/server/ServerInitializationTestCase.java	                        (rev 0)
+++ projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/server/ServerInitializationTestCase.java	2009-10-24 03:03:09 UTC (rev 95540)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.embedded.core.server;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import junit.framework.TestCase;
+
+import org.jboss.bootstrap.spi.server.ServerProvider;
+import org.jboss.embedded.api.server.JBossASEmbeddedServer;
+import org.jboss.embedded.api.server.JBossASEmbeddedServerFactory;
+import org.jboss.logging.Logger;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * ServerInitializationTestCase
+ * 
+ * Test Cases to ensure that the Server Initialization contracts
+ * hold
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ServerInitializationTestCase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(ServerInitializationTestCase.class);
+
+   /**
+    * Server for testing
+    */
+   private static JBossASEmbeddedServer server;
+
+   //-------------------------------------------------------------------------------------||
+   // Lifecycle --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Creates and initializes the server
+    */
+   @BeforeClass
+   public static void createAndInitServer() throws Exception
+   {
+      // Create
+      server = JBossASEmbeddedServerFactory.createServer();
+      // Don't do any validation of JBOSS_HOME or related environment
+      ((ServerProvider<?, ?>) server).setValidator(null);
+      // Init
+      server.initialize();
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that JBossXB is configured to use the unordered sequence in parsing
+    */
+   @Test
+   public void testXbUnorderedSequence() throws Exception
+   {
+      this.assertSysProp("xb.builder.useUnorderedSequence", Boolean.TRUE.toString());
+   }
+
+   /**
+    * Ensures that the RMI server hostname is set to localhost
+    */
+   @Test
+   public void testRmiServerHostnameLocalhost() throws Exception
+   {
+      this.assertSysProp("java.rmi.server.hostname", "localhost");
+   }
+
+   /**
+    * Ensures that the Log Manager is set to JBoss LogManager
+    */
+   @Test
+   public void testLogManagerIsJBossLogManager() throws Exception
+   {
+      this.assertSysProp("java.util.logging.manager", "org.jboss.logmanager.LogManager");
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Helper Methods ---------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Ensures the system property of specified name has the specified value, 
+    * else fails the test
+    */
+   private void assertSysProp(final String propName, final String expectedValue)
+   {
+      // Get the prop value
+      final String propValue = AccessController.doPrivileged(new PrivilegedAction<String>()
+      {
+         @Override
+         public String run()
+         {
+            return System.getProperty(propName);
+         }
+
+      });
+      // Ensure expected
+      TestCase.assertEquals("Required system property was not set as expected", expectedValue, propValue);
+   }
+
+}




More information about the jboss-cvs-commits mailing list