www.ironjacamar.orgCommunity Documentation

Chapter 11. Embedded

Table of Contents

11.1. Overview
11.2. Configuration
11.3. Usage
11.3.1. Simple usage
11.3.2. Advanced usage

The IronJacamar embedded configuration provides a way of running a JCA container in-VM.

The configuration is useful when you want a

Especially the ability to unit test your resource adapter archives before deploying them into a testing or a production environment will benefit developers.

In order to enhance the experience with working with the embedded configuration the container integrates with the ShrinkWrap and Arquillian frameworks.

You will need all the JAR files located in the

$IRON_JACAMAR_HOME/bin
$IRON_JACAMAR_HOME/lib
$IRON_JACAMAR_HOME/lib/embedded
      

directories on your application class loader - f.ex.

java -classpath allthejarfiles.jar yourapp
      

in order to use the embedded configuration.

If you want integration with the Arquillian framework you need to add the JAR files located in the

$IRON_JACAMAR_HOME/lib/embedded/arquillian
      

directory as well.

The Arquillian/Byteman integration is located in the

$IRON_JACAMAR_HOME/lib/embedded/arquillian/byteman
      

directory.

Furthermore you will need to configure Java Naming and Directory Interface (JNDI) and logging using for example property files.

Sample jndi.properties file:

java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      

Sample logging.properties file:

# Additional logger names to configure (root logger is always configured)
loggers=org.jboss.jca,org.jboss,org.jnp,com.arjuna

# Root logger level
logger.level=${iron.jacamar.log.level:INFO}
logger.handlers=CONSOLE, FILE

# org.jboss.jca
logger.org.jboss.jca.level=DEBUG

# org.jboss
logger.org.jboss.level=INFO

# org.jnp
logger.org.jnp.level=INFO

# com.arjuna
logger.com.arjuna.level=INFO

# Console handler configuration
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.properties=autoFlush
handler.CONSOLE.level=${iron.jacamar.log.console.level:INFO}
handler.CONSOLE.autoFlush=true
handler.CONSOLE.formatter=PATTERN

# File handler configuration
handler.FILE=org.jboss.logmanager.handlers.FileHandler
handler.FILE.level=${iron.jacamar.log.file.level:DEBUG}
handler.FILE.properties=autoFlush,fileName
handler.FILE.autoFlush=true
handler.FILE.fileName=${test.dir}/embedded/test.log
handler.FILE.formatter=PATTERN

# Formatter pattern configuration
formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.pattern=%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n
      

These files needs to be available to the application classloader.

IronJacamar Embedded supports both a simple and an advanced usage model, using pre-assembled resource adapter archives (.rar) or dynamic resource adapter archives based on ShrinkWrap.

The embedded environment supports registering resource adapters and datasources in the platform MBeanServer by setting the system property ironjacamar.embedded.management to true before starting the environment.

The IronJacamar Embedded container environment supports the following open source testing projects:

These extensions allow the developer to use the embedded platform with greater ease as there doesn't have to be a physical representation of the resource adapter archive located to the disk.

The Arquillian integration furthermore allows the developer to leave all the embedded container setup to the integration layer instead.

See the Arquillian and ShrinkWrap web sites for a detailed description of the projects and additional documentation.

The code sample below shows an usage of deploying a ShrinkWrap resource adapter archive into the IronJacamar Embedded environment using Arquillian.



/*
 * IronJacamar, a Java EE Connector Architecture implementation
 * Copyright 2012, Red Hat Inc, 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.arquillian.unit;
import org.jboss.jca.arquillian.embedded.Configuration;
import org.jboss.jca.arquillian.rars.simple.TestConnection;
import org.jboss.jca.arquillian.rars.simple.TestConnectionFactory;
import java.util.UUID;
import javax.annotation.Resource;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertNotNull;
/**
 * Unit test for Arquillian integration
 * 
 * @author <a href="mailto:jesper.pedersen@ironjacamar.org">Jesper Pedersen</a>
 */
@RunWith(Arquillian.class)
@Configuration(autoActivate = true)
public class ArquillianTestCase
{
   // --------------------------------------------------------------------------------||
   // Class Members ------------------------------------------------------------------||
   // --------------------------------------------------------------------------------||
   private static Logger log = Logger.getLogger(ArquillianTestCase.class);
   private static String deploymentName = "ArquillianTest";
   /**
    * Define the deployment
    * @return The deployment archive
    */
   @Deployment
   public static ResourceAdapterArchive createDeployment()
   {
      ResourceAdapterArchive raa =
         ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName + ".rar");
      JavaArchive ja = ShrinkWrap.create(JavaArchive.class, UUID.randomUUID().toString() + ".jar");
      ja.addPackage(TestConnection.class.getPackage());
      raa.addAsLibrary(ja);
      raa.addAsManifestResource("simple.rar/META-INF/ra.xml", "ra.xml");
      return raa;
   }
   //-------------------------------------------------------------------------------------||
   // Tests ------------------------------------------------------------------------------||
   //-------------------------------------------------------------------------------------||
   @Resource(mappedName = "java:/eis/ArquillianTest")
   private TestConnectionFactory connectionFactory;
   
   /**
    * Basic
    * @exception Throwable Thrown if case of an error
    */
   @Test
   public void testBasic() throws Throwable
   {
      assertNotNull(connectionFactory);
      TestConnection c = connectionFactory.getConnection();
      assertNotNull(c);
      c.callMe();
      c.close();
   }
}
          

The class makes use of the org.jboss.jca.embedded.arquillian.Configuration annotation in order to specify that the deployed archive should be auto activated through the RAActivator bean.

The code sample below shows how to use Arquillian to deploy a ShrinkWrap resource adapter archive and activate the resource adapter using the ShrinkWrap/Descriptors API.

This example uses the org.jboss.jca.embedded.arquillian.Configuration annotation to explicit say not to auto activate the resource adapter archive.



/*
 * IronJacamar, a Java EE Connector Architecture implementation
 * Copyright 2012, Red Hat Inc, 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.unit;
import org.jboss.jca.arquillian.embedded.Configuration;
import org.jboss.jca.embedded.dsl.resourceadapters11.api.ConnectionDefinitionsType;
import org.jboss.jca.embedded.dsl.resourceadapters11.api.ResourceAdapterType;
import org.jboss.jca.embedded.dsl.resourceadapters11.api.ResourceAdaptersDescriptor;
import org.jboss.jca.embedded.rars.simple.TestConnection;
import org.jboss.jca.embedded.rars.simple.TestConnectionFactory;
import org.jboss.jca.embedded.rars.simple.TestConnectionFactoryImpl;
import org.jboss.jca.embedded.rars.simple.TestConnectionImpl;
import org.jboss.jca.embedded.rars.simple.TestManagedConnectionFactory;
import org.jboss.jca.embedded.rars.simple.TestResourceAdapter;
import java.util.UUID;
import javax.annotation.Resource;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptors;
import org.jboss.shrinkwrap.descriptor.api.connector15.ConnectorDescriptor;
import org.jboss.shrinkwrap.descriptor.api.connector15.OutboundResourceadapterType;
import org.jboss.shrinkwrap.descriptor.api.connector15.ResourceadapterType;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertNotNull;
/**
 * Unit test for ShrinkWrap/Descriptors integration
 * 
 * @author <a href="mailto:jesper.pedersen@ironjacamar.org">Jesper Pedersen</a>
 */
@RunWith(Arquillian.class)
@Configuration(autoActivate = false)
public class ShrinkWrapDescriptorsTestCase
{
   // --------------------------------------------------------------------------------||
   // Class Members ------------------------------------------------------------------||
   // --------------------------------------------------------------------------------||
   private static Logger log = Logger.getLogger(ShrinkWrapDescriptorsTestCase.class);
   private static String deploymentName = "sd.rar";
   /**
    * Define the resource adapter archive
    * @return The archive
    */
   @Deployment(order = 1)
   public static ResourceAdapterArchive createArchive()
   {
      ConnectorDescriptor raXml = Descriptors.create(ConnectorDescriptor.class, "ra.xml")
         .version("1.5");
      ResourceadapterType rt = raXml.getOrCreateResourceadapter()
         .resourceadapterClass(TestResourceAdapter.class.getName());
      OutboundResourceadapterType ort = rt.getOrCreateOutboundResourceadapter()
         .transactionSupport("NoTransaction").reauthenticationSupport(false);
      org.jboss.shrinkwrap.descriptor.api.connector15.ConnectionDefinitionType cdt =
         ort.createConnectionDefinition()
            .managedconnectionfactoryClass(TestManagedConnectionFactory.class.getName())
            .connectionfactoryInterface(TestConnectionFactory.class.getName())
            .connectionfactoryImplClass(TestConnectionFactoryImpl.class.getName())
            .connectionInterface(TestConnection.class.getName())
            .connectionImplClass(TestConnectionImpl.class.getName());
      ResourceAdapterArchive raa =
         ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName);
      JavaArchive ja = ShrinkWrap.create(JavaArchive.class, UUID.randomUUID().toString() + ".jar");
      ja.addPackage(TestConnection.class.getPackage());
      raa.addAsLibrary(ja);
      raa.addAsManifestResource(new StringAsset(raXml.exportAsString()), "ra.xml");
      return raa;
   }
   /**
    * Define the deployment descriptor
    * @return The descriptor
    */
   @Deployment(order = 2)
   public static ResourceAdaptersDescriptor createDeployment()
   {
      ResourceAdaptersDescriptor dashRaXml = Descriptors.create(ResourceAdaptersDescriptor.class, "sd-ra.xml");
      ResourceAdapterType rt = dashRaXml.createResourceAdapter().archive(deploymentName);
      ConnectionDefinitionsType cdst = rt.getOrCreateConnectionDefinitions();
      org.jboss.jca.embedded.dsl.resourceadapters11.api.ConnectionDefinitionType cdt =
         cdst.createConnectionDefinition()
            .className(TestManagedConnectionFactory.class.getName())
            .jndiName("java:/eis/TestConnectionFactory").poolName("TestConnectionFactory");
      return dashRaXml;
   }
   //-------------------------------------------------------------------------------------||
   // Tests ------------------------------------------------------------------------------||
   //-------------------------------------------------------------------------------------||
   @Resource(mappedName = "java:/eis/TestConnectionFactory")
   private TestConnectionFactory connectionFactory;
   
   /**
    * Basic
    * @exception Throwable Thrown if case of an error
    */
   @Test
   public void testBasic() throws Throwable
   {
      assertNotNull(connectionFactory);
      TestConnection c = connectionFactory.getConnection();
      assertNotNull(c);
      c.callMe();
      c.close();
   }
}
          

The code sample below shows how to use Arquillian to deploy a ShrinkWrap resource adapter archive and change the allocateConnection of org.jboss.jca.core.connectionmanager.AbstractConnectionManager to throw a ResourceException when the method is called.

The framework used to provide this functionality is called Byteman, which allows developers to change behavior of a method to for example throw an exception. This is called fault injection and can be used to increase code coverage of your project.



/*
 * IronJacamar, a Java EE Connector Architecture implementation
 * Copyright 2012, Red Hat Inc, 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.arquillian.unit;
import org.jboss.jca.arquillian.embedded.Configuration;
import org.jboss.jca.arquillian.rars.simple.TestConnection;
import org.jboss.jca.arquillian.rars.simple.TestConnectionFactory;
import org.jboss.jca.embedded.dsl.InputStreamDescriptor;
import java.util.UUID;
import javax.annotation.Resource;
import javax.resource.ResourceException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.extension.byteman.api.BMRule;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
/**
 * Unit test for Byteman integration
 * 
 * @author <a href="mailto:jesper.pedersen@ironjacamar.org">Jesper Pedersen</a>
 */
@RunWith(Arquillian.class)
@Configuration(autoActivate = false)
public class BytemanBMTestCase
{
   // --------------------------------------------------------------------------------||
   // Class Members ------------------------------------------------------------------||
   // --------------------------------------------------------------------------------||
   private static Logger log = Logger.getLogger(BytemanBMTestCase.class);
   /**
    * Define the deployment
    * @return The deployment archive
    */
   @Deployment(order = 1)
   public static ResourceAdapterArchive createDeployment()
   {
      ResourceAdapterArchive raa =
         ShrinkWrap.create(ResourceAdapterArchive.class, "byteman.rar");
      JavaArchive ja = ShrinkWrap.create(JavaArchive.class, UUID.randomUUID().toString() + ".jar");
      ja.addPackage(TestConnection.class.getPackage());
      raa.addAsLibrary(ja);
      raa.addAsManifestResource("simple.rar/META-INF/ra.xml", "ra.xml");
      return raa;
   }
   /**
    * Define the activation
    * @return The deployment archive
    */
   @Deployment(order = 2)
   public static Descriptor createDescriptor()
   {
      ClassLoader cl = BytemanBMTestCase.class.getClassLoader();
      InputStreamDescriptor isd = new InputStreamDescriptor("byteman-ra.xml", 
                                                            cl.getResourceAsStream("byteman-ra.xml"));
      return isd;
   }
   //-------------------------------------------------------------------------------------||
   // Tests ------------------------------------------------------------------------------||
   //-------------------------------------------------------------------------------------||
   @Resource(mappedName = "java:/eis/BytemanTest")
   private TestConnectionFactory connectionFactory;
   /**
    * Byteman
    * @exception Throwable Thrown if case of an error
    */
   @Test
   @BMRule(name = "Throw exception on allocateConnection",
           targetClass = "org.jboss.jca.core.connectionmanager.AbstractConnectionManager",
           targetMethod = "allocateConnection",
           action = "throw new javax.resource.ResourceException()")
   public void testByteman() throws Throwable
   {
      assertNotNull(connectionFactory);
      TestConnection c = null;
      try
      {
         c = connectionFactory.getConnection();
         fail("Got a connection");
      }
      catch (ResourceException re)
      {
         // Ok
      }
      catch (Throwable t)
      {
         fail(t.getMessage());
         throw t;
      }
      finally
      {
         if (!= null)
            c.close();
      }
   }
}
          

See the Byteman web site for a detailed description of the project and additional documentation.

The code sample below shows how to use Arquillian to deploy a ShrinkWrap resource adapter archive and inject the IronJacamar metadata repository into the test case such that assertions can be made.

The IronJacamar container features various components that makes up the entire Java EE Connector Architecture container. The available list of components can be viewed in the configuration of the container or through the management console under the Kernel category.



/*/*
 * IronJacamar, a Java EE Connector Architecture implementation
 * Copyright 2011, Red Hat Inc, 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.arquillian.unit;
import org.jboss.jca.arquillian.embedded.Configuration;
import org.jboss.jca.arquillian.embedded.Inject;
import org.jboss.jca.arquillian.rars.simple.TestConnection;
import org.jboss.jca.arquillian.rars.simple.TestConnectionFactory;
import org.jboss.jca.core.spi.mdr.MetadataRepository;
import java.util.UUID;
import javax.annotation.Resource;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
 * Unit test for Arquillian integration and injecting
 * 
 * @author <a href="mailto:jesper.pedersen@ironjacamar.org">Jesper Pedersen</a>
 */
@RunWith(Arquillian.class)
@Configuration(autoActivate = true)
public class InjectTestCase
{
   // --------------------------------------------------------------------------------||
   // Class Members ------------------------------------------------------------------||
   // --------------------------------------------------------------------------------||
   private static Logger log = Logger.getLogger(InjectTestCase.class);
   /**
    * Define the deployment
    * @return The deployment archive
    */
   @Deployment
   public static ResourceAdapterArchive createDeployment()
   {
      ResourceAdapterArchive raa =
         ShrinkWrap.create(ResourceAdapterArchive.class, "ArquillianTest.rar");
      JavaArchive ja = ShrinkWrap.create(JavaArchive.class, UUID.randomUUID().toString() + ".jar");
      ja.addPackage(TestConnection.class.getPackage());
      raa.addAsLibrary(ja);
      raa.addAsManifestResource("simple.rar/META-INF/ra.xml", "ra.xml");
      return raa;
   }
   //-------------------------------------------------------------------------------------||
   // Tests ------------------------------------------------------------------------------||
   //-------------------------------------------------------------------------------------||
   @Resource(mappedName = "java:/eis/ArquillianTest")
   private TestConnectionFactory connectionFactory;
 
   @Inject(name = "MDR")
   private MetadataRepository mdr;
  
   /**
    * Basic
    * @exception Throwable Thrown if case of an error
    */
   @Test
   public void testBasic() throws Throwable
   {
      assertNotNull(connectionFactory);
      assertNotNull(mdr);
      assertNotNull(mdr.getResourceAdapters());
      assertTrue(mdr.getResourceAdapters().size() == 1);
   }
}
          

The code sample below shows an advanced usage of deploying a ShrinkWrap resource adapter archive into the IronJacamar Embedded environment.



/*
 * IronJacamar, a Java EE Connector Architecture implementation
 * Copyright 2012, Red Hat Inc, 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.unit;
import org.jboss.jca.embedded.Embedded;
import org.jboss.jca.embedded.EmbeddedFactory;
import org.jboss.jca.embedded.rars.simple.TestConnection;
import org.jboss.jca.embedded.rars.simple.TestConnectionFactory;
import java.util.UUID;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
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 deploying resource adapter archives (.RAR)
 * using ShrinkWrap
 * 
 * @author <a href="mailto:jesper.pedersen@ironjacamar.org">Jesper Pedersen</a>
 */
public class ShrinkWrapTestCase
{
   // --------------------------------------------------------------------------------||
   // Class Members ------------------------------------------------------------------||
   // --------------------------------------------------------------------------------||
   private static Logger log = Logger.getLogger(ShrinkWrapTestCase.class);
   private static final String JNDI_PREFIX = "java:/eis/";
   /*
    * Embedded
    */
   private static Embedded embedded;
   // --------------------------------------------------------------------------------||
   // Tests --------------------------------------------------------------------------||
   // --------------------------------------------------------------------------------||
   /**
    * Basic ShrinkWrap ResourceAdapterArchive test case
    * @exception Throwable Thrown if case of an error
    */
   @Test
   public void testBasic() throws Throwable
   {
      Context context = null;
      String name = UUID.randomUUID().toString();
      ResourceAdapterArchive raa =
         ShrinkWrap.create(ResourceAdapterArchive.class, name + ".rar");
      JavaArchive ja = ShrinkWrap.create(JavaArchive.class, UUID.randomUUID().toString() + ".jar");
      ja.addPackage(TestConnection.class.getPackage());
      raa.addAsLibrary(ja);
      raa.addAsManifestResource("simple.rar/META-INF/ra.xml", "ra.xml");
      try
      {
         embedded.deploy(raa);
         context = new InitialContext();
         TestConnectionFactory tcf = (TestConnectionFactory)context.lookup(JNDI_PREFIX + name);
         assertNotNull(tcf);
         TestConnection tc = tcf.getConnection();
         tc.callMe();
         tc.close();
      }
      catch (Exception t)
      {
         log.error(t.getMessage(), t);
         fail(t.getMessage());
      }
      finally
      {
         if (context != null)
         {
            try
            {
               context.close();
            }
            catch (NamingException ne)
            {
               // Ignore
            }
         }
         embedded.undeploy(raa);
      }
   }
   // --------------------------------------------------------------------------------||
   // Lifecycle Methods --------------------------------------------------------------||
   // --------------------------------------------------------------------------------||
   /**
    * Lifecycle start, before the suite is executed
    * @throws Throwable throwable exception 
    */
   @BeforeClass
   public static void beforeClass() throws Throwable
   {
      // Create and set an embedded JCA instance
      embedded = EmbeddedFactory.create();
      // Startup
      embedded.startup();
   }
   /**
    * Lifecycle stop, after the suite is executed
    * @throws Throwable throwable exception 
    */
   @AfterClass
   public static void afterClass() throws Throwable
   {
      // Shutdown embedded
      embedded.shutdown();
      // Set embedded to null
      embedded = null;
   }
}
          

The code sample below shows a simple usage of deploying a pre-assembled resource adapter archive into the IronJacamar Embedded environment.



import org.jboss.jca.embedded.Embedded;
import org.jboss.jca.embedded.EmbeddedFactory;
import java.net.URL;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
public class MyTestCase
{
   /** Embedded */
   private static Embedded embedded;
   /** JNDI prefix */
   private static final String JNDI_PREFIX = "java:/eis/";
   /**
    * Simple test to verify deployment of myresourceadapter.rar
    * @throws Throwable throwable exception 
    */
   @Test
   public void testDeployment() throws Throwable
   {
      URL archive = MyTestCase.class.getResource("myresourceadapter.rar");
      Context context = null;
 
      try
      {
         embedded.deploy(archive);
         context = new InitialContext();
         Object o = context.lookup(JNDI_PREFIX + "myresourceadapter");
         assertNotNull(o);
      }
      catch (Throwable t)
      {
         fail(t.getMessage());
      }
      finally
      {
         embedded.undeploy(archive);
         if (context != null)
         {
            try
            {
               context.close();
            }
            catch (NamingException ne)
            {
               // Ignore
            }
         }
      }
   }
   @BeforeClass
   public static void beforeClass() throws Throwable
   {
      // Create an embedded JCA instance
      embedded = EmbeddedFactory.create();
      // Startup
      embedded.startup();
   }
   @AfterClass
   public static void afterClass() throws Throwable
   {
      // Shutdown
      embedded.shutdown();
   }
}
            

See the IronJacamar Embedded API documentation for additional functionality.