[jboss-cvs] JBossAS SVN: r93581 - in projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss: embedded/testsuite/fulldep and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Sep 16 02:17:27 EDT 2009


Author: ALRubinger
Date: 2009-09-16 02:17:27 -0400 (Wed, 16 Sep 2009)
New Revision: 93581

Added:
   projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/SecurityActions.java
   projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/ServerTestCase.java
Removed:
   projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/SecurityActions.java
   projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
Log:
[EMB-44] Move the ServerTestCase now that it no longer has to reside in org.jboss

Deleted: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/SecurityActions.java
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/SecurityActions.java	2009-09-16 06:11:17 UTC (rev 93580)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/SecurityActions.java	2009-09-16 06:17:27 UTC (rev 93581)
@@ -1,153 +0,0 @@
-package org.jboss;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- * SecurityActions
- * 
- * A set of privileged actions that are not to leak out
- * of this package 
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-class SecurityActions
-{
-
-   //-------------------------------------------------------------------------------||
-   // Constructor ------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------||
-
-   /**
-    * No external instanciation
-    */
-   private SecurityActions()
-   {
-
-   }
-
-   //-------------------------------------------------------------------------------||
-   // Utility Methods --------------------------------------------------------------||
-   //-------------------------------------------------------------------------------||
-
-   /**
-    * Sets the specified property with key and value
-    */
-   static void setSystemProperty(final String key, final String value)
-   {
-      AccessController.doPrivileged(new PrivilegedAction<Void>()
-      {
-         public Void run()
-         {
-            System.setProperty(key, value);
-            return null;
-         }
-      });
-   }
-
-   /**
-    * Obtains the system property with the specified key
-    * 
-    * @param key
-    * @return
-    * @throws IllegalArgumentException If the key is null
-    */
-   static String getSystemProperty(final String key) throws IllegalArgumentException
-   {
-      // Precondition check
-      if (key == null)
-      {
-         throw new IllegalArgumentException("key was null");
-      }
-
-      // Get sysprop
-      return AccessController.doPrivileged(new PrivilegedAction<String>()
-      {
-         public String run()
-         {
-            return System.getProperty(key);
-         }
-      });
-   }
-
-   /**
-    * Obtains the Thread Context ClassLoader
-    */
-   static ClassLoader getThreadContextClassLoader()
-   {
-      return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
-      {
-         public ClassLoader run()
-         {
-            return Thread.currentThread().getContextClassLoader();
-         }
-      });
-   }
-
-   /**
-    * Sets the specified CL upon the current Thread's Context 
-    * 
-    * @param cl
-    * @throws IllegalArgumentException If the CL was null
-    */
-   static void setThreadContextClassLoader(final ClassLoader cl) throws IllegalArgumentException
-   {
-      if (cl == null)
-      {
-         throw new IllegalArgumentException("ClassLoader was null");
-      }
-
-      AccessController.doPrivileged(new PrivilegedAction<Void>()
-      {
-         public Void run()
-         {
-            Thread.currentThread().setContextClassLoader(cl);
-            return null;
-         };
-      });
-   }
-
-   /**
-    * Adds the specified shutdown hook
-    * 
-    * @param shutdownHook
-    */
-   static void addShutdownHook(final Thread shutdownHook)
-   {
-      AccessController.doPrivileged(new PrivilegedAction<Void>()
-      {
-         public Void run()
-         {
-            Runtime.getRuntime().addShutdownHook(shutdownHook);
-            return null;
-         }
-      });
-
-   }
-
-   /**
-    * Obtains the environment variable with the specified key 
-    * 
-    * @param key
-    * @return
-    * @throws IllegalArgumentException If the key is null
-    */
-   static String getEnvironmentVariable(final String key) throws IllegalArgumentException
-   {
-      // Precondition check
-      if (key == null)
-      {
-         throw new IllegalArgumentException("key was null");
-      }
-
-      // Get envvar
-      return AccessController.doPrivileged(new PrivilegedAction<String>()
-      {
-         public String run()
-         {
-            return System.getenv(key);
-         }
-      });
-   }
-}

Deleted: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java	2009-09-16 06:11:17 UTC (rev 93580)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java	2009-09-16 06:17:27 UTC (rev 93581)
@@ -1,490 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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.
- */
-//FIXME We have to be in org.jboss due to JMX getPackage in AS 
-package org.jboss;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueSender;
-import javax.jms.QueueSession;
-import javax.jms.TextMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.utils.URIUtils;
-import org.apache.http.client.utils.URLEncodedUtils;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.message.BasicNameValuePair;
-import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
-import org.jboss.embedded.core.server.JBossASEmbeddedServer;
-import org.jboss.embedded.core.server.JBossASEmbeddedServerImpl;
-import org.jboss.embedded.testsuite.fulldep.ejb3.entity.Jbossian;
-import org.jboss.embedded.testsuite.fulldep.ejb3.entity.JbossianRegistrarBean;
-import org.jboss.embedded.testsuite.fulldep.ejb3.entity.JbossianRegistrarLocalBusiness;
-import org.jboss.embedded.testsuite.fulldep.ejb3.mdb.MessageStoringMdb;
-import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputBean;
-import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputLocalBusiness;
-import org.jboss.embedded.testsuite.fulldep.servlet.JspForwardingServlet;
-import org.jboss.logging.Logger;
-import org.jboss.shrinkwrap.api.JavaArchiveFactory;
-import org.jboss.shrinkwrap.api.Path;
-import org.jboss.shrinkwrap.api.WebArchiveFactory;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.impl.base.path.BasicPath;
-import org.jboss.tmpdpl.api.deployable.Deployable;
-import org.jboss.tmpdpl.api.deployable.VfsVdfDeployableFactory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * ServerTestCase
- * 
- * The beginnings of the prototype for an end-user view 
- * of the Embedded Server.  Tests here should include lifecycle
- * to start/stop the server, and checks to ensure that
- * subsystems are working as expected.
- * 
- * This is the initial prototype for Embedded AS to run 
- * with a full AS Dependency Set upon the Application
- * ClassLoader.  The deps are defined by pom.xml and its parents.
- * 
- * Some hacks worthy of note:
- * 1) Requires JDK6 to run, something to do with JAXP not getting endorsed 
- *      from java.endorsed.dirs in pom.xml Surefire Config
- * 2) This class must be in package org.jboss due to JMX 
- *   package checking in AS org.jboss.management.j2ee.deployers.LocalJBossServerDomain at 335
- *   or else:
- *   Caused by: java.lang.NullPointerException
- *   at org.jboss.management.j2ee.deployers.ServiceModuleJSR77Deployer.deployJsr77(ServiceModuleJSR77Deployer.java:62)
- *   at org.jboss.management.j2ee.deployers.ServiceModuleJSR77Deployer.deployJsr77(ServiceModuleJSR77Deployer.java:40)
- *   at org.jboss.management.j2ee.deployers.AbstractVFSJSR77Deployer.deployJsr77(AbstractVFSJSR77Deployer.java:46)
- *   at org.jboss.management.j2ee.deployers.AbstractJSR77Deployer.deploy(AbstractJSR77Deployer.java:173)
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ServerTestCase
-{
-
-   //-------------------------------------------------------------------------------||
-   // Class Members ----------------------------------------------------------------||
-   //-------------------------------------------------------------------------------||
-
-   /**
-    * Logger
-    */
-   private static final Logger log = Logger.getLogger(ServerTestCase.class);
-
-   /**
-    * The server instance
-    */
-   private static JBossASEmbeddedServer server;
-
-   /**
-    * Path, relative to the resources base, of a test web.xml
-    */
-   private static final String PATH_ACTUAL_WEB_XML = "webxml/servletForwardingToJsp.xml";
-
-   /**
-    * Filename of a test queue *-service.xml
-    */
-   private static final String FILENAME_QUEUE_SERVICE_XML = "mdb-queue-service.xml";
-
-   /**
-    * Path, relative to the resources base, of a test queue *-service.xml
-    */
-   private static final String PATH_QUEUE_SERVICE_XML = "queues/" + FILENAME_QUEUE_SERVICE_XML;
-
-   /**
-    * Path, relative to the resources base, of a test JSP
-    */
-   private static final String PATH_JSP = "jsp/requestParamEcho.jsp";
-
-   /**
-    * Path, relative to the resources base, of a persistence.xml file for Embedded DataSource
-    */
-   private static final String PATH_RESOURCE_PERSISTENCE_XML_EMBEDDED = "persistence/persistenceEmbedded.xml";
-
-   /**
-    * Path, relative to the deployment root, of a persistence.xml file
-    */
-   private static final String PATH_DESTINATION_PERSISTENCE_XML = "persistence.xml";
-
-   /**
-    * Path, relative to the resources base, of the directory containing DataSource resources
-    */
-   private static final String PATH_RESOURCE_DS_XMLs = "datasources/";
-
-   /**
-    * Filename of the Embedded DataSource deployment XML
-    */
-   private static final String FILENAME_EMBEDDED_DS = "embedded-ds.xml";
-
-   /**
-    * Path, relative to the resources base, of the directory containing DataSource resources
-    */
-   private static final String PATH_RESOURCE_DS_XML_EMBEDDED = PATH_RESOURCE_DS_XMLs + FILENAME_EMBEDDED_DS;
-
-   /**
-    * Separator character within archives
-    */
-   private static final char SEPARATOR = '/';
-
-   /**
-    * The JNDI Context
-    */
-   private static Context NAMING_CONTEXT;
-
-   /**
-    * Name of the Queue Connection Factory in JNDI
-    */
-   private static final String JNDI_NAME_CONNECTION_FACTORY = "ConnectionFactory";
-
-   /**
-    * JNDI name suffix appended to local business EJB3 views
-    */
-   private static final String JNDI_SUFFIX_LOCAL_BUSINESS = "/local";
-
-   //-------------------------------------------------------------------------------||
-   // Lifecycle --------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------||
-
-   /**
-    * Starts up the Application Server.  Relies upon either Environment
-    * Variable "JBOSS_HOME" or System Property "jboss.home" being set, with 
-    * precedence to the system property
-    */
-   @BeforeClass
-   public static void startEmbedddedASAndSetNamingContext() throws Exception
-   {
-      // Make Server (will pull JBOSS_HOME from env var or sys prop)
-      server = new JBossASEmbeddedServerImpl();
-      log.info("Created: " + server);
-
-      // Start
-      log.info("Starting Server: " + server);
-      server.start();
-      log.info("...started.");
-
-      // Set Naming Context
-      NAMING_CONTEXT = new InitialContext();
-   }
-
-   /**
-    * Shuts down the Application Server after the suite ends
-    */
-   @AfterClass
-   public static void stopEmbeddedAS() throws Exception
-   {
-      // If exists and started
-      if (server != null && server.getState().equals(LifecycleState.STARTED))
-      {
-         // Shutdown
-         log.info("Shutting down server: " + server);
-         server.shutdown();
-      }
-
-   }
-
-   //-------------------------------------------------------------------------------||
-   // Tests ------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------||
-
-   /**
-    * Tests EJB3 Stateless Session Beans via a virtual archive
-    * deployment
-    */
-   @Test
-   public void testSlsb() throws Exception
-   {
-      // Log
-      log.info("testSlsb");
-
-      // Make a deployment
-      final String name = "slsb.jar";
-      final JavaArchive archive = JavaArchiveFactory.create(name).addClasses(OutputBean.class,
-            OutputLocalBusiness.class);
-      log.info(archive.toString(true));
-      final Deployable deployable = VfsVdfDeployableFactory.createDeployable(archive);
-
-      // Deploy
-      server.deploy(deployable);
-
-      // Test
-      final OutputLocalBusiness bean = (OutputLocalBusiness) NAMING_CONTEXT.lookup(OutputBean.class.getSimpleName()
-            + JNDI_SUFFIX_LOCAL_BUSINESS);;
-      final String output = bean.getOutput();
-      log.info("Got output: " + output);
-      Assert.assertEquals(OutputLocalBusiness.OUTPUT, output);
-
-      // Undeploy
-      server.undeploy(deployable);
-
-   }
-
-   /**
-    * Tests deployment of a virtual WAR containing a servlet 
-    * and JSP.
-    * 
-    * The Servlet will forward to the JSP path denoted by request param
-    * "jsp".  The JSP will echo the value of request param "echo".
-    * 
-    * @throws Exception
-    */
-   @Test
-   public void testWarServletJsp() throws Exception
-   {
-      // Log
-      log.info("testWarServletJsp");
-
-      // Get the path to the test web.xml file and JSP 
-      final Path targetPathWebXml = new BasicPath("web.xml");
-
-      // Make a deployment
-      final String appName = "testServletJsp";
-      final String name = appName + ".war";
-      final Class<?> servletClass = JspForwardingServlet.class;
-      final WebArchive archive = WebArchiveFactory.create(name);
-      archive.addWebResource(targetPathWebXml, PATH_ACTUAL_WEB_XML).addResource(PATH_JSP).addClass(servletClass);
-      log.info(archive.toString(true));
-
-      // Deploy
-      server.deploy(archive);
-
-      // Get an HTTP Client
-      final HttpClient client = new DefaultHttpClient();
-
-      // Make an HTTP Request
-      final String echoValue = "EmbeddedBiatch";
-      final List<NameValuePair> params = new ArrayList<NameValuePair>();
-      params.add(new BasicNameValuePair("jsp", PATH_JSP));
-      params.add(new BasicNameValuePair("echo", echoValue));
-      final URI uri = URIUtils.createURI("http", "localhost", 8080, appName + SEPARATOR + servletClass.getSimpleName(),
-            URLEncodedUtils.format(params, "UTF-8"), null);
-      final HttpGet request = new HttpGet(uri);
-
-      // Execute the request
-      log.info("Executing request to: " + request.getURI());
-      final HttpResponse response = client.execute(request);
-      final HttpEntity entity = response.getEntity();
-      if (entity == null)
-      {
-         TestCase.fail("Request returned no entity");
-      }
-
-      // Read the result, ensure it's what we're expecting (should be the value of request param "echo")
-      final BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
-      final String line = reader.readLine();
-      log.info("Got response: " + line);
-      Assert.assertEquals(echoValue, line);
-
-      // Undeploy
-      server.undeploy(archive);
-   }
-
-   /**
-    * Tests deployment of a JMS Queue with EJB3 MDB Listener
-    * 
-    * The MDB will simply store the text of the message in a publicly-accessible
-    * static field
-    * 
-    * @throws Exception
-    */
-   @Test
-   public void testJmsAndMdb() throws Exception
-   {
-      // Log
-      log.info("testJmsAndMdb");
-
-      // Create a virtual archive for the MDB deployment
-      final String name = "jms-mdb-test.jar";
-      final JavaArchive archive = JavaArchiveFactory.create(name);
-      final Path queuesTargetPath = new BasicPath(FILENAME_QUEUE_SERVICE_XML);
-      archive.addClass(MessageStoringMdb.class).addResource(queuesTargetPath, PATH_QUEUE_SERVICE_XML);
-
-      // Deploy
-      log.info(archive.toString(true));
-      final Deployable deployable = VfsVdfDeployableFactory.createDeployable(archive);
-      server.deploy(archive);
-
-      // Define a String message to send
-      final String message = "From in-JVM Test Message";
-
-      // Send the message
-      this.sendTextMessageToQueue(message, MessageStoringMdb.NAME_QUEUE);
-
-      // Wait on the MDB to process
-      try
-      {
-         MessageStoringMdb.BARRIER.await(10, TimeUnit.SECONDS);
-      }
-      catch (final InterruptedException e)
-      {
-         // Clear the flag
-         Thread.interrupted();
-         // Throw up
-         throw e;
-      }
-      catch (final TimeoutException e)
-      {
-         TestCase.fail("The MDB did not process the message in the allotted time");
-      }
-
-      // Get the contents of the String from the MDB
-      final String received = MessageStoringMdb.LAST_MESSAGE_CONTENTS;
-
-      // Ensure equal
-      Assert.assertEquals("The test message received was not as expected", message, received);
-
-      // Undeploy
-      server.undeploy(deployable);
-
-   }
-
-   /**
-    * Tests deployment of a JCA DataSource and EJB3 Entity Bean (JPA)
-    * 
-    * A test SLSB will also be used to create a few rows in the DB, 
-    * then obtain all.
-    * 
-    * @throws Exception
-    */
-   @Test
-   public void testDataSourceAndEntity() throws Exception
-   {
-      // Log
-      log.info("testDataSourceAndEntity");
-
-      // Create a virtual archive for DS, persistence.xml, Entity, and SLSB
-      final String name = "datasource-entity-test.jar";
-      final Path targetDsPath = new BasicPath(FILENAME_EMBEDDED_DS); //TODO Use factory when available
-      final Path targetPersistencePath = new BasicPath(PATH_DESTINATION_PERSISTENCE_XML); //TODO Use factory when available
-      final JavaArchive archive = JavaArchiveFactory.create(name);
-      archive.addClasses(Jbossian.class, JbossianRegistrarLocalBusiness.class, JbossianRegistrarBean.class)
-            .addResource(targetDsPath, PATH_RESOURCE_DS_XML_EMBEDDED).addManifestResource(targetPersistencePath,
-                  PATH_RESOURCE_PERSISTENCE_XML_EMBEDDED);
-
-      // Deploy
-      log.info(archive.toString(true));
-      server.deploy(archive);
-
-      // Make some JBossians
-      final Jbossian jgreene = new Jbossian("Jason T. Greene", "AS Hole", 12);
-      final Jbossian jpederse = new Jbossian("Jesper Pedersen", "Professional Tattletale", 21);
-      final Jbossian dmlloyd = new Jbossian("David M. Lloyd", "???????", 15);
-      final Jbossian wolfc = new Jbossian("Carlo de Wolf", "Superlead", 13);
-      final Jbossian alr = new Jbossian("Andew Lee Rubinger", "The New Fluery", 58);
-      final Jbossian asaldhan = new Jbossian("Anil Saldhana", "Karma Police", 23);
-
-      // Get an SLSB to interact w/ the DB
-      final JbossianRegistrarLocalBusiness slsb = (JbossianRegistrarLocalBusiness) NAMING_CONTEXT
-            .lookup(JbossianRegistrarBean.class.getSimpleName() + JNDI_SUFFIX_LOCAL_BUSINESS);
-
-      // Add the JBossians
-      slsb.add(jgreene);
-      slsb.add(jpederse);
-      slsb.add(dmlloyd);
-      slsb.add(wolfc);
-      slsb.add(alr);
-      slsb.add(asaldhan);
-
-      // Get all
-      final Collection<Jbossian> jbossians = slsb.getAllJbossians();
-      log.info("Got all JBossians: " + jbossians);
-
-      // Test
-      Assert.assertEquals(6, jbossians.size());
-
-      // Undeploy
-      server.undeploy(archive);
-   }
-
-   //-------------------------------------------------------------------------------------||
-   // Internal Helper Methods ------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Sends a JMS {@link TextMessage} containing the specified contents to the 
-    * queue of the specified name  
-    * 
-    * @param contents
-    * @param queueName
-    * @throws Exception
-    * @throws IllegalArgumentException If either argument is not provided
-    */
-   private void sendTextMessageToQueue(final String contents, final String queueName) throws Exception,
-         IllegalArgumentException
-   {
-      // Precondition check
-      if (contents == null || contents.length() == 0)
-      {
-         throw new IllegalArgumentException("contents must be provided");
-      }
-      if (queueName == null || queueName.length() == 0)
-      {
-         throw new IllegalArgumentException("queueName must be provided");
-      }
-
-      // Get the queue from JNDI
-      final Queue queue = (Queue) NAMING_CONTEXT.lookup(queueName);
-
-      // Get the ConnectionFactory from JNDI
-      final QueueConnectionFactory factory = (QueueConnectionFactory) NAMING_CONTEXT
-            .lookup(JNDI_NAME_CONNECTION_FACTORY);
-
-      // Make a Connection
-      final QueueConnection connection = factory.createQueueConnection();
-      final QueueSession sendSession = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
-
-      // Make the message
-      final TextMessage message = sendSession.createTextMessage(contents);
-
-      // Send the message
-      final QueueSender sender = sendSession.createSender(queue);
-      sender.send(message);
-      log.info("Sent message " + message + " with contents: " + contents);
-
-      // Clean up
-      sendSession.close();
-      connection.close();
-   }
-}

Copied: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/SecurityActions.java (from rev 93554, projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/SecurityActions.java)
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/SecurityActions.java	                        (rev 0)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/SecurityActions.java	2009-09-16 06:17:27 UTC (rev 93581)
@@ -0,0 +1,153 @@
+package org.jboss.embedded.testsuite.fulldep;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions
+ * 
+ * A set of privileged actions that are not to leak out
+ * of this package 
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+   //-------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------||
+
+   /**
+    * No external instanciation
+    */
+   private SecurityActions()
+   {
+
+   }
+
+   //-------------------------------------------------------------------------------||
+   // Utility Methods --------------------------------------------------------------||
+   //-------------------------------------------------------------------------------||
+
+   /**
+    * Sets the specified property with key and value
+    */
+   static void setSystemProperty(final String key, final String value)
+   {
+      AccessController.doPrivileged(new PrivilegedAction<Void>()
+      {
+         public Void run()
+         {
+            System.setProperty(key, value);
+            return null;
+         }
+      });
+   }
+
+   /**
+    * Obtains the system property with the specified key
+    * 
+    * @param key
+    * @return
+    * @throws IllegalArgumentException If the key is null
+    */
+   static String getSystemProperty(final String key) throws IllegalArgumentException
+   {
+      // Precondition check
+      if (key == null)
+      {
+         throw new IllegalArgumentException("key was null");
+      }
+
+      // Get sysprop
+      return AccessController.doPrivileged(new PrivilegedAction<String>()
+      {
+         public String run()
+         {
+            return System.getProperty(key);
+         }
+      });
+   }
+
+   /**
+    * Obtains the Thread Context ClassLoader
+    */
+   static ClassLoader getThreadContextClassLoader()
+   {
+      return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+      {
+         public ClassLoader run()
+         {
+            return Thread.currentThread().getContextClassLoader();
+         }
+      });
+   }
+
+   /**
+    * Sets the specified CL upon the current Thread's Context 
+    * 
+    * @param cl
+    * @throws IllegalArgumentException If the CL was null
+    */
+   static void setThreadContextClassLoader(final ClassLoader cl) throws IllegalArgumentException
+   {
+      if (cl == null)
+      {
+         throw new IllegalArgumentException("ClassLoader was null");
+      }
+
+      AccessController.doPrivileged(new PrivilegedAction<Void>()
+      {
+         public Void run()
+         {
+            Thread.currentThread().setContextClassLoader(cl);
+            return null;
+         };
+      });
+   }
+
+   /**
+    * Adds the specified shutdown hook
+    * 
+    * @param shutdownHook
+    */
+   static void addShutdownHook(final Thread shutdownHook)
+   {
+      AccessController.doPrivileged(new PrivilegedAction<Void>()
+      {
+         public Void run()
+         {
+            Runtime.getRuntime().addShutdownHook(shutdownHook);
+            return null;
+         }
+      });
+
+   }
+
+   /**
+    * Obtains the environment variable with the specified key 
+    * 
+    * @param key
+    * @return
+    * @throws IllegalArgumentException If the key is null
+    */
+   static String getEnvironmentVariable(final String key) throws IllegalArgumentException
+   {
+      // Precondition check
+      if (key == null)
+      {
+         throw new IllegalArgumentException("key was null");
+      }
+
+      // Get envvar
+      return AccessController.doPrivileged(new PrivilegedAction<String>()
+      {
+         public String run()
+         {
+            return System.getenv(key);
+         }
+      });
+   }
+}

Copied: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/ServerTestCase.java (from rev 93570, projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java)
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/ServerTestCase.java	                        (rev 0)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/ServerTestCase.java	2009-09-16 06:17:27 UTC (rev 93581)
@@ -0,0 +1,478 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.
+ */
+//FIXME We have to be in org.jboss due to JMX getPackage in AS 
+package org.jboss.embedded.testsuite.fulldep;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.utils.URIUtils;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
+import org.jboss.embedded.core.server.JBossASEmbeddedServer;
+import org.jboss.embedded.core.server.JBossASEmbeddedServerImpl;
+import org.jboss.embedded.testsuite.fulldep.ejb3.entity.Jbossian;
+import org.jboss.embedded.testsuite.fulldep.ejb3.entity.JbossianRegistrarBean;
+import org.jboss.embedded.testsuite.fulldep.ejb3.entity.JbossianRegistrarLocalBusiness;
+import org.jboss.embedded.testsuite.fulldep.ejb3.mdb.MessageStoringMdb;
+import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputBean;
+import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputLocalBusiness;
+import org.jboss.embedded.testsuite.fulldep.servlet.JspForwardingServlet;
+import org.jboss.logging.Logger;
+import org.jboss.shrinkwrap.api.JavaArchiveFactory;
+import org.jboss.shrinkwrap.api.Path;
+import org.jboss.shrinkwrap.api.WebArchiveFactory;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.impl.base.path.BasicPath;
+import org.jboss.tmpdpl.api.deployable.Deployable;
+import org.jboss.tmpdpl.api.deployable.VfsVdfDeployableFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * ServerTestCase
+ * 
+ * The beginnings of the prototype for an end-user view 
+ * of the Embedded Server.  Tests here should include lifecycle
+ * to start/stop the server, and checks to ensure that
+ * subsystems are working as expected.
+ * 
+ * This is the initial prototype for Embedded AS to run 
+ * with a full AS Dependency Set upon the Application
+ * ClassLoader.  The deps are defined by pom.xml and its parents.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ServerTestCase
+{
+
+   //-------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------||
+   //-------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(ServerTestCase.class);
+
+   /**
+    * The server instance
+    */
+   private static JBossASEmbeddedServer server;
+
+   /**
+    * Path, relative to the resources base, of a test web.xml
+    */
+   private static final String PATH_ACTUAL_WEB_XML = "webxml/servletForwardingToJsp.xml";
+
+   /**
+    * Filename of a test queue *-service.xml
+    */
+   private static final String FILENAME_QUEUE_SERVICE_XML = "mdb-queue-service.xml";
+
+   /**
+    * Path, relative to the resources base, of a test queue *-service.xml
+    */
+   private static final String PATH_QUEUE_SERVICE_XML = "queues/" + FILENAME_QUEUE_SERVICE_XML;
+
+   /**
+    * Path, relative to the resources base, of a test JSP
+    */
+   private static final String PATH_JSP = "jsp/requestParamEcho.jsp";
+
+   /**
+    * Path, relative to the resources base, of a persistence.xml file for Embedded DataSource
+    */
+   private static final String PATH_RESOURCE_PERSISTENCE_XML_EMBEDDED = "persistence/persistenceEmbedded.xml";
+
+   /**
+    * Path, relative to the deployment root, of a persistence.xml file
+    */
+   private static final String PATH_DESTINATION_PERSISTENCE_XML = "persistence.xml";
+
+   /**
+    * Path, relative to the resources base, of the directory containing DataSource resources
+    */
+   private static final String PATH_RESOURCE_DS_XMLs = "datasources/";
+
+   /**
+    * Filename of the Embedded DataSource deployment XML
+    */
+   private static final String FILENAME_EMBEDDED_DS = "embedded-ds.xml";
+
+   /**
+    * Path, relative to the resources base, of the directory containing DataSource resources
+    */
+   private static final String PATH_RESOURCE_DS_XML_EMBEDDED = PATH_RESOURCE_DS_XMLs + FILENAME_EMBEDDED_DS;
+
+   /**
+    * Separator character within archives
+    */
+   private static final char SEPARATOR = '/';
+
+   /**
+    * The JNDI Context
+    */
+   private static Context NAMING_CONTEXT;
+
+   /**
+    * Name of the Queue Connection Factory in JNDI
+    */
+   private static final String JNDI_NAME_CONNECTION_FACTORY = "ConnectionFactory";
+
+   /**
+    * JNDI name suffix appended to local business EJB3 views
+    */
+   private static final String JNDI_SUFFIX_LOCAL_BUSINESS = "/local";
+
+   //-------------------------------------------------------------------------------||
+   // Lifecycle --------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------||
+
+   /**
+    * Starts up the Application Server.  Relies upon either Environment
+    * Variable "JBOSS_HOME" or System Property "jboss.home" being set, with 
+    * precedence to the system property
+    */
+   @BeforeClass
+   public static void startEmbedddedASAndSetNamingContext() throws Exception
+   {
+      // Make Server (will pull JBOSS_HOME from env var or sys prop)
+      server = new JBossASEmbeddedServerImpl();
+      log.info("Created: " + server);
+
+      // Start
+      log.info("Starting Server: " + server);
+      server.start();
+      log.info("...started.");
+
+      // Set Naming Context
+      NAMING_CONTEXT = new InitialContext();
+   }
+
+   /**
+    * Shuts down the Application Server after the suite ends
+    */
+   @AfterClass
+   public static void stopEmbeddedAS() throws Exception
+   {
+      // If exists and started
+      if (server != null && server.getState().equals(LifecycleState.STARTED))
+      {
+         // Shutdown
+         log.info("Shutting down server: " + server);
+         server.shutdown();
+      }
+
+   }
+
+   //-------------------------------------------------------------------------------||
+   // Tests ------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------||
+
+   /**
+    * Tests EJB3 Stateless Session Beans via a virtual archive
+    * deployment
+    */
+   @Test
+   public void testSlsb() throws Exception
+   {
+      // Log
+      log.info("testSlsb");
+
+      // Make a deployment
+      final String name = "slsb.jar";
+      final JavaArchive archive = JavaArchiveFactory.create(name).addClasses(OutputBean.class,
+            OutputLocalBusiness.class);
+      log.info(archive.toString(true));
+      final Deployable deployable = VfsVdfDeployableFactory.createDeployable(archive);
+
+      // Deploy
+      server.deploy(deployable);
+
+      // Test
+      final OutputLocalBusiness bean = (OutputLocalBusiness) NAMING_CONTEXT.lookup(OutputBean.class.getSimpleName()
+            + JNDI_SUFFIX_LOCAL_BUSINESS);;
+      final String output = bean.getOutput();
+      log.info("Got output: " + output);
+      Assert.assertEquals(OutputLocalBusiness.OUTPUT, output);
+
+      // Undeploy
+      server.undeploy(deployable);
+
+   }
+
+   /**
+    * Tests deployment of a virtual WAR containing a servlet 
+    * and JSP.
+    * 
+    * The Servlet will forward to the JSP path denoted by request param
+    * "jsp".  The JSP will echo the value of request param "echo".
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testWarServletJsp() throws Exception
+   {
+      // Log
+      log.info("testWarServletJsp");
+
+      // Get the path to the test web.xml file and JSP 
+      final Path targetPathWebXml = new BasicPath("web.xml");
+
+      // Make a deployment
+      final String appName = "testServletJsp";
+      final String name = appName + ".war";
+      final Class<?> servletClass = JspForwardingServlet.class;
+      final WebArchive archive = WebArchiveFactory.create(name);
+      archive.addWebResource(targetPathWebXml, PATH_ACTUAL_WEB_XML).addResource(PATH_JSP).addClass(servletClass);
+      log.info(archive.toString(true));
+
+      // Deploy
+      server.deploy(archive);
+
+      // Get an HTTP Client
+      final HttpClient client = new DefaultHttpClient();
+
+      // Make an HTTP Request
+      final String echoValue = "EmbeddedBiatch";
+      final List<NameValuePair> params = new ArrayList<NameValuePair>();
+      params.add(new BasicNameValuePair("jsp", PATH_JSP));
+      params.add(new BasicNameValuePair("echo", echoValue));
+      final URI uri = URIUtils.createURI("http", "localhost", 8080, appName + SEPARATOR + servletClass.getSimpleName(),
+            URLEncodedUtils.format(params, "UTF-8"), null);
+      final HttpGet request = new HttpGet(uri);
+
+      // Execute the request
+      log.info("Executing request to: " + request.getURI());
+      final HttpResponse response = client.execute(request);
+      final HttpEntity entity = response.getEntity();
+      if (entity == null)
+      {
+         TestCase.fail("Request returned no entity");
+      }
+
+      // Read the result, ensure it's what we're expecting (should be the value of request param "echo")
+      final BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
+      final String line = reader.readLine();
+      log.info("Got response: " + line);
+      Assert.assertEquals(echoValue, line);
+
+      // Undeploy
+      server.undeploy(archive);
+   }
+
+   /**
+    * Tests deployment of a JMS Queue with EJB3 MDB Listener
+    * 
+    * The MDB will simply store the text of the message in a publicly-accessible
+    * static field
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testJmsAndMdb() throws Exception
+   {
+      // Log
+      log.info("testJmsAndMdb");
+
+      // Create a virtual archive for the MDB deployment
+      final String name = "jms-mdb-test.jar";
+      final JavaArchive archive = JavaArchiveFactory.create(name);
+      final Path queuesTargetPath = new BasicPath(FILENAME_QUEUE_SERVICE_XML);
+      archive.addClass(MessageStoringMdb.class).addResource(queuesTargetPath, PATH_QUEUE_SERVICE_XML);
+
+      // Deploy
+      log.info(archive.toString(true));
+      final Deployable deployable = VfsVdfDeployableFactory.createDeployable(archive);
+      server.deploy(archive);
+
+      // Define a String message to send
+      final String message = "From in-JVM Test Message";
+
+      // Send the message
+      this.sendTextMessageToQueue(message, MessageStoringMdb.NAME_QUEUE);
+
+      // Wait on the MDB to process
+      try
+      {
+         MessageStoringMdb.BARRIER.await(10, TimeUnit.SECONDS);
+      }
+      catch (final InterruptedException e)
+      {
+         // Clear the flag
+         Thread.interrupted();
+         // Throw up
+         throw e;
+      }
+      catch (final TimeoutException e)
+      {
+         TestCase.fail("The MDB did not process the message in the allotted time");
+      }
+
+      // Get the contents of the String from the MDB
+      final String received = MessageStoringMdb.LAST_MESSAGE_CONTENTS;
+
+      // Ensure equal
+      Assert.assertEquals("The test message received was not as expected", message, received);
+
+      // Undeploy
+      server.undeploy(deployable);
+
+   }
+
+   /**
+    * Tests deployment of a JCA DataSource and EJB3 Entity Bean (JPA)
+    * 
+    * A test SLSB will also be used to create a few rows in the DB, 
+    * then obtain all.
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testDataSourceAndEntity() throws Exception
+   {
+      // Log
+      log.info("testDataSourceAndEntity");
+
+      // Create a virtual archive for DS, persistence.xml, Entity, and SLSB
+      final String name = "datasource-entity-test.jar";
+      final Path targetDsPath = new BasicPath(FILENAME_EMBEDDED_DS); //TODO Use factory when available
+      final Path targetPersistencePath = new BasicPath(PATH_DESTINATION_PERSISTENCE_XML); //TODO Use factory when available
+      final JavaArchive archive = JavaArchiveFactory.create(name);
+      archive.addClasses(Jbossian.class, JbossianRegistrarLocalBusiness.class, JbossianRegistrarBean.class)
+            .addResource(targetDsPath, PATH_RESOURCE_DS_XML_EMBEDDED).addManifestResource(targetPersistencePath,
+                  PATH_RESOURCE_PERSISTENCE_XML_EMBEDDED);
+
+      // Deploy
+      log.info(archive.toString(true));
+      server.deploy(archive);
+
+      // Make some JBossians
+      final Jbossian jgreene = new Jbossian("Jason T. Greene", "AS Hole", 12);
+      final Jbossian jpederse = new Jbossian("Jesper Pedersen", "Professional Tattletale", 21);
+      final Jbossian dmlloyd = new Jbossian("David M. Lloyd", "???????", 15);
+      final Jbossian wolfc = new Jbossian("Carlo de Wolf", "Superlead", 13);
+      final Jbossian alr = new Jbossian("Andew Lee Rubinger", "The New Fluery", 58);
+      final Jbossian asaldhan = new Jbossian("Anil Saldhana", "Karma Police", 23);
+
+      // Get an SLSB to interact w/ the DB
+      final JbossianRegistrarLocalBusiness slsb = (JbossianRegistrarLocalBusiness) NAMING_CONTEXT
+            .lookup(JbossianRegistrarBean.class.getSimpleName() + JNDI_SUFFIX_LOCAL_BUSINESS);
+
+      // Add the JBossians
+      slsb.add(jgreene);
+      slsb.add(jpederse);
+      slsb.add(dmlloyd);
+      slsb.add(wolfc);
+      slsb.add(alr);
+      slsb.add(asaldhan);
+
+      // Get all
+      final Collection<Jbossian> jbossians = slsb.getAllJbossians();
+      log.info("Got all JBossians: " + jbossians);
+
+      // Test
+      Assert.assertEquals(6, jbossians.size());
+
+      // Undeploy
+      server.undeploy(archive);
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Internal Helper Methods ------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Sends a JMS {@link TextMessage} containing the specified contents to the 
+    * queue of the specified name  
+    * 
+    * @param contents
+    * @param queueName
+    * @throws Exception
+    * @throws IllegalArgumentException If either argument is not provided
+    */
+   private void sendTextMessageToQueue(final String contents, final String queueName) throws Exception,
+         IllegalArgumentException
+   {
+      // Precondition check
+      if (contents == null || contents.length() == 0)
+      {
+         throw new IllegalArgumentException("contents must be provided");
+      }
+      if (queueName == null || queueName.length() == 0)
+      {
+         throw new IllegalArgumentException("queueName must be provided");
+      }
+
+      // Get the queue from JNDI
+      final Queue queue = (Queue) NAMING_CONTEXT.lookup(queueName);
+
+      // Get the ConnectionFactory from JNDI
+      final QueueConnectionFactory factory = (QueueConnectionFactory) NAMING_CONTEXT
+            .lookup(JNDI_NAME_CONNECTION_FACTORY);
+
+      // Make a Connection
+      final QueueConnection connection = factory.createQueueConnection();
+      final QueueSession sendSession = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+      // Make the message
+      final TextMessage message = sendSession.createTextMessage(contents);
+
+      // Send the message
+      final QueueSender sender = sendSession.createSender(queue);
+      sender.send(message);
+      log.info("Sent message " + message + " with contents: " + contents);
+
+      // Clean up
+      sendSession.close();
+      connection.close();
+   }
+}




More information about the jboss-cvs-commits mailing list