[jboss-cvs] JBossAS SVN: r109646 - in projects/jboss-jca/trunk/embedded/src: test/java/org/jboss/jca/embedded and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 2 10:13:53 EST 2010


Author: jesper.pedersen
Date: 2010-12-02 10:13:53 -0500 (Thu, 02 Dec 2010)
New Revision: 109646

Added:
   projects/jboss-jca/trunk/embedded/src/test/java/org/jboss/jca/embedded/EmbeddedTestCase.java
   projects/jboss-jca/trunk/embedded/src/test/resources/simple-deployment.xml
Modified:
   projects/jboss-jca/trunk/embedded/src/main/java/org/jboss/jca/embedded/EmbeddedJCA.java
   projects/jboss-jca/trunk/embedded/src/main/java/org/jboss/jca/embedded/SecurityActions.java
   projects/jboss-jca/trunk/embedded/src/test/resources/logging.properties
Log:
[JBJCA-474] Add EmbeddedTestCase

Modified: projects/jboss-jca/trunk/embedded/src/main/java/org/jboss/jca/embedded/EmbeddedJCA.java
===================================================================
--- projects/jboss-jca/trunk/embedded/src/main/java/org/jboss/jca/embedded/EmbeddedJCA.java	2010-12-02 15:13:14 UTC (rev 109645)
+++ projects/jboss-jca/trunk/embedded/src/main/java/org/jboss/jca/embedded/EmbeddedJCA.java	2010-12-02 15:13:53 UTC (rev 109646)
@@ -54,14 +54,8 @@
    /** ShrinkWrap deployments */
    private List<File> shrinkwrapDeployments;
 
-   /**
-    * Constructs an embedded JCA environment using
-    * the full JCA 1.6 profile
-    */
-   EmbeddedJCA()
-   {
-      this(true);
-   }
+   /** Started */
+   private boolean started;
 
    /**
     * Constructs an embedded JCA environment. If <code>fullProfile</code>
@@ -74,6 +68,7 @@
    {
       this.fullProfile = fullProfile;
       this.shrinkwrapDeployments = null;
+      this.started = false;
    }
 
    /**
@@ -82,6 +77,9 @@
     */
    public void startup() throws Throwable
    {
+      if (started)
+         throw new IllegalStateException("Container already started");
+
       List<String> order = new ArrayList<String>(3);
       order.add(".xml");
       order.add(".rar");
@@ -109,6 +107,8 @@
          deploy(EmbeddedJCA.class.getClassLoader(), "jca.xml");
          deploy(EmbeddedJCA.class.getClassLoader(), "ds.xml");
       }
+
+      started = true;
    }
 
    /**
@@ -117,6 +117,9 @@
     */
    public void shutdown() throws Throwable
    {
+      if (!started)
+         throw new IllegalStateException("Container not started");
+
       if (shrinkwrapDeployments != null && shrinkwrapDeployments.size() > 0)
       {
          List<File> copy = new ArrayList<File>(shrinkwrapDeployments);
@@ -136,6 +139,8 @@
       }
 
       kernel.shutdown();
+
+      started = false;
    }
 
    /**
@@ -153,6 +158,9 @@
       if (expectedType == null)
          throw new IllegalArgumentException("ExpectedType is null");
 
+      if (!started)
+         throw new IllegalStateException("Container not started");
+
       return kernel.getBean(name, expectedType);
    }
 
@@ -166,6 +174,9 @@
       if (url == null)
          throw new IllegalArgumentException("Url is null");      
 
+      if (!started)
+         throw new IllegalStateException("Container not started");
+
       kernel.getMainDeployer().deploy(url);
    }
 
@@ -182,6 +193,9 @@
       if (!raa.getName().endsWith(".rar"))
          throw new IllegalArgumentException(raa.getName() + " doesn't end with .rar");      
 
+      if (!started)
+         throw new IllegalStateException("Container not started");
+
       InputStream is = raa.as(ZipExporter.class).exportZip();
 
       File parentDirectory = new File(SecurityActions.getSystemProperty("java.io.tmpdir"));
@@ -256,6 +270,10 @@
          throw new IllegalArgumentException("Name is null");
 
       URL url = cl.getResource(name);
+
+      if (url == null)
+         throw new IllegalArgumentException("Resource is null");
+
       kernel.getMainDeployer().deploy(url);
    }
 
@@ -269,6 +287,9 @@
       if (url == null)
          throw new IllegalArgumentException("Url is null");      
 
+      if (!started)
+         throw new IllegalStateException("Container not started");
+
       kernel.getMainDeployer().undeploy(url);
    }
 
@@ -282,6 +303,9 @@
       if (raa == null)
          throw new IllegalArgumentException("Url is null");      
 
+      if (!started)
+         throw new IllegalStateException("Container not started");
+
       File parentDirectory = new File(SecurityActions.getSystemProperty("java.io.tmpdir"));
       File raaFile = new File(parentDirectory, raa.getName());
 

Modified: projects/jboss-jca/trunk/embedded/src/main/java/org/jboss/jca/embedded/SecurityActions.java
===================================================================
--- projects/jboss-jca/trunk/embedded/src/main/java/org/jboss/jca/embedded/SecurityActions.java	2010-12-02 15:13:14 UTC (rev 109645)
+++ projects/jboss-jca/trunk/embedded/src/main/java/org/jboss/jca/embedded/SecurityActions.java	2010-12-02 15:13:53 UTC (rev 109646)
@@ -22,11 +22,8 @@
 
 package org.jboss.jca.embedded;
 
-import java.net.URL;
-import java.net.URLClassLoader;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-import java.util.Properties;
 
 /**
  * Privileged Blocks
@@ -42,52 +39,6 @@
    }
 
    /**
-    * Get the thread context class loader
-    * @return The class loader
-    */
-   static ClassLoader getThreadContextClassLoader()
-   {
-      return (ClassLoader)AccessController.doPrivileged(new PrivilegedAction<Object>() 
-      {
-         public Object run()
-         {
-            return Thread.currentThread().getContextClassLoader();
-         }
-      });
-   }
-
-   /**
-    * Set the thread context class loader
-    * @param cl The class loader
-    */
-   static void setThreadContextClassLoader(final ClassLoader cl)
-   {
-      AccessController.doPrivileged(new PrivilegedAction<Object>() 
-      {
-         public Object run()
-         {
-            Thread.currentThread().setContextClassLoader(cl);
-            return null;
-         }
-      });
-   }
-
-   /**
-    * Get the system properties
-    * @return The properties
-    */
-   static Properties getSystemProperties()
-   {
-      return (Properties)AccessController.doPrivileged(new PrivilegedAction<Object>() 
-      {
-         public Object run()
-         {
-            return System.getProperties();
-         }
-      });
-   }
-
-   /**
     * Get a system property
     * @param name The property name
     * @return The property value
@@ -119,21 +70,4 @@
          }
       });
    }
-
-   /**
-    * Create an URLClassLoader
-    * @param urls The urls
-    * @param parent The parent class loader
-    * @return The class loader
-    */
-   static URLClassLoader createURLCLassLoader(final URL[] urls, final ClassLoader parent)
-   {
-      return (URLClassLoader)AccessController.doPrivileged(new PrivilegedAction<Object>() 
-      {
-         public Object run()
-         {
-            return new URLClassLoader(urls, parent);
-         }
-      });
-   }
 }

Added: projects/jboss-jca/trunk/embedded/src/test/java/org/jboss/jca/embedded/EmbeddedTestCase.java
===================================================================
--- projects/jboss-jca/trunk/embedded/src/test/java/org/jboss/jca/embedded/EmbeddedTestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/embedded/src/test/java/org/jboss/jca/embedded/EmbeddedTestCase.java	2010-12-02 15:13:53 UTC (rev 109646)
@@ -0,0 +1,296 @@
+/*
+ * 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.jca.embedded;
+
+import org.jboss.jca.embedded.Embedded;
+import org.jboss.jca.embedded.EmbeddedFactory;
+
+import java.net.URL;
+
+import org.jboss.logging.Logger;
+import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test cases for the embedded container
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class EmbeddedTestCase
+{
+
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static Logger log = Logger.getLogger(EmbeddedTestCase.class);
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Basic container
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test
+   public void testBasicContainerLifecycle() throws Throwable
+   {
+      Embedded embedded = EmbeddedFactory.create(false);
+      embedded.startup();
+      embedded.shutdown();
+      embedded = null;
+   }
+
+   /**
+    * Full container
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test
+   public void testFullContainerLifecycle() throws Throwable
+   {
+      Embedded embedded = EmbeddedFactory.create();
+      embedded.startup();
+      embedded.shutdown();
+      embedded = null;
+   }
+
+   /**
+    * Full container
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test
+   public void testFullContainerLifecycleBoolean() throws Throwable
+   {
+      Embedded embedded = EmbeddedFactory.create(true);
+      embedded.startup();
+      embedded.shutdown();
+      embedded = null;
+   }
+
+   /**
+    * Successful deployment
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test
+   public void testSuccessfulDeployment() throws Throwable
+   {
+      Embedded embedded = EmbeddedFactory.create(false);
+      embedded.startup();
+
+      URL test = EmbeddedTestCase.class.getClassLoader().getResource("simple-deployment.xml");
+      embedded.deploy(test);
+      embedded.undeploy(test);
+
+      embedded.shutdown();
+      embedded = null;
+   }
+
+   /**
+    * Fail double startup
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test(expected = IllegalStateException.class)
+   public void testFailDoubleStartup() throws Throwable
+   {
+      Embedded embedded = null;
+      try
+      {
+         embedded = EmbeddedFactory.create(false);
+         embedded.startup();
+         embedded.startup();
+      }
+      finally
+      {
+         if (embedded != null)
+         {
+            embedded.shutdown();
+            embedded = null;
+         }
+      }
+   }
+
+   /**
+    * Fail shutdown since container not started
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test(expected = IllegalStateException.class)
+   public void testFailShutdownSinceNotStarted() throws Throwable
+   {
+      Embedded embedded = EmbeddedFactory.create(false);
+      embedded.shutdown();
+   }
+
+   /**
+    * Fail deployment since container not started
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test(expected = IllegalStateException.class)
+   public void testFailDeploymentSinceNotStarted() throws Throwable
+   {
+      Embedded embedded = EmbeddedFactory.create(false);
+
+      URL test = EmbeddedTestCase.class.getClassLoader().getResource("simple-deployment.xml");
+      embedded.deploy(test);
+   }
+
+   /**
+    * Fail undeployment since container not started
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test(expected = IllegalStateException.class)
+   public void testFailUndeploymentSinceNotStarted() throws Throwable
+   {
+      Embedded embedded = EmbeddedFactory.create(false);
+
+      URL test = EmbeddedTestCase.class.getClassLoader().getResource("simple-deployment.xml");
+      embedded.undeploy(test);
+   }
+
+   /**
+    * Fail null deployment
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test(expected = IllegalArgumentException.class)
+   public void testFailNullURLDeployment() throws Throwable
+   {
+      Embedded embedded = null;
+      URL deployment = null;
+      try
+      {
+         embedded = EmbeddedFactory.create(false);
+         embedded.startup();
+         embedded.deploy(deployment);
+      }
+      finally
+      {
+         if (embedded != null)
+         {
+            embedded.shutdown();
+            embedded = null;
+         }
+      }
+   }
+
+   /**
+    * Fail null undeployment
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test(expected = IllegalArgumentException.class)
+   public void testFailNullURLUndeployment() throws Throwable
+   {
+      Embedded embedded = null;
+      URL deployment = null;
+      try
+      {
+         embedded = EmbeddedFactory.create(false);
+         embedded.startup();
+         embedded.undeploy(deployment);
+      }
+      finally
+      {
+         if (embedded != null)
+         {
+            embedded.shutdown();
+            embedded = null;
+         }
+      }
+   }
+
+   /**
+    * Fail null deployment
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test(expected = IllegalArgumentException.class)
+   public void testFailNullShrinkWrapDeployment() throws Throwable
+   {
+      Embedded embedded = null;
+      ResourceAdapterArchive deployment = null;
+      try
+      {
+         embedded = EmbeddedFactory.create(false);
+         embedded.startup();
+         embedded.deploy(deployment);
+      }
+      finally
+      {
+         if (embedded != null)
+         {
+            embedded.shutdown();
+            embedded = null;
+         }
+      }
+   }
+
+   /**
+    * Fail null undeployment
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test(expected = IllegalArgumentException.class)
+   public void testFailNullShrinkWrapUndeployment() throws Throwable
+   {
+      Embedded embedded = null;
+      ResourceAdapterArchive deployment = null;
+      try
+      {
+         embedded = EmbeddedFactory.create(false);
+         embedded.startup();
+         embedded.undeploy(deployment);
+      }
+      finally
+      {
+         if (embedded != null)
+         {
+            embedded.shutdown();
+            embedded = null;
+         }
+      }
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Lifecycle start, before the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @BeforeClass
+   public static void beforeClass() throws Throwable
+   {
+   }
+
+   /**
+    * Lifecycle stop, after the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @AfterClass
+   public static void afterClass() throws Throwable
+   {
+   }
+}

Modified: projects/jboss-jca/trunk/embedded/src/test/resources/logging.properties
===================================================================
--- projects/jboss-jca/trunk/embedded/src/test/resources/logging.properties	2010-12-02 15:13:14 UTC (rev 109645)
+++ projects/jboss-jca/trunk/embedded/src/test/resources/logging.properties	2010-12-02 15:13:53 UTC (rev 109646)
@@ -53,7 +53,7 @@
 handler.FILE.level=${iron.jacamar.log.file.level:DEBUG}
 handler.FILE.properties=autoFlush,fileName
 handler.FILE.autoFlush=true
-handler.FILE.fileName=${test.dir}/deployers/test.log
+handler.FILE.fileName=${test.dir}/embedded/test.log
 handler.FILE.formatter=PATTERN
 
 # Formatter pattern configuration

Added: projects/jboss-jca/trunk/embedded/src/test/resources/simple-deployment.xml
===================================================================
--- projects/jboss-jca/trunk/embedded/src/test/resources/simple-deployment.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/embedded/src/test/resources/simple-deployment.xml	2010-12-02 15:13:53 UTC (rev 109646)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment>
+
+  <bean name="Test" class="java.lang.Object"/>
+
+</deployment>



More information about the jboss-cvs-commits mailing list