7 Replies Latest reply: Apr 26, 2012 6:52 PM by Tomohisa igarashi RSS

    injecting InitialContext and ServiceContainer into Arquillian junit testcase

    Tomohisa igarashi Master

      Hi,

       

      I'm looking for the way to inject InitialContext and AS7 ServiceContainer into Arquillian junit testcase. With following testcase, ServiceContainer was null and InitlaContext failed to lookup from AS7 instance. Could you let me know if you find my mistake?

       

      • testcase
      package org.switchyard.test.arquillian.hello;
      import javax.inject.Inject;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      
      
      import junit.framework.Assert;
      
      
      import org.jboss.arquillian.junit.Arquillian;
      import org.jboss.arquillian.test.api.ArquillianResource;
      import org.jboss.as.connector.ConnectorServices;
      import org.jboss.jca.core.spi.rar.ResourceAdapterRepository;
      import org.jboss.msc.service.ServiceContainer;
      import org.junit.Before;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      
      
      @RunWith(Arquillian.class)
      public class HelloArquillianTest {
      
      
          @Inject
          ServiceContainer _serviceContainer;
      
          @ArquillianResource
          InitialContext _initialContext;
      
          @Before
          public void before() {
              System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
          }
      
          @Test
          public void testInjection() throws Exception {
              Assert.assertNotNull(_serviceContainer);
              Assert.assertTrue(_serviceContainer.getService(ConnectorServices.RA_REPOSITORY_SERVICE) instanceof ResourceAdapterRepository);
          }
      
          @Test
          public void testArquillianResourceInjection() throws Exception {
              Assert.assertNotNull(_initialContext);
              Assert.assertTrue(_initialContext.lookup("java:/ConnectionFactory") instanceof javax.jms.ConnectionFactory);
          }
      }
      
      

       

      Other files including pom.xml and arquillian.xml are in the attached .jar file.

       

      Thanks,

      Tomo