2014-06-19 62 views
0

我一直在嘗試在我的「遠程」本地主機JBoss服務器(不嵌入/管理)上執行Arquillian Integration測試,但是我的本地EJB沒有被注入。Arquillian @EJB在EAR部署中注入null

的pom.xml

<profile> 
    <!-- An optional Arquillian testing profile that executes tests in a remote JBoss AS instance --> 
    <!-- Run with: mvn clean test -Parq-jbossas-remote --> 
    <id>arq-jbossas-remote</id> 
    <dependencies> 
     <dependency> 
      <groupId>org.jboss.as</groupId> 
      <artifactId>jboss-as-arquillian-container-remote</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</profile> 

ProductService.java:

@Stateless 
@Local(IProductService.class) 
public class ProductService implements IProductService { 

ProductServiceIntegrationTest.java

@RunWith(Arquillian.class) 
public class ProductServiceIntegrationTest { 

    protected static final Logger logger = LoggerFactory.getLogger(ProductServiceIntegrationTest.class); 

    @Rule 
    public TestName testMethod = new TestName(); 

    @EJB 
    public IProductService productService; 

    // @Deployment(order = 1, name = "keystone-ear", testable = false) 
    // public static Archive<?> createKeystoneServicesArchive() { 
    //  return ShrinkWrap 
    //    .create(ZipImporter.class, "keystone-ear.ear") 
    //    .importFrom(new File("target/dependency/keystone-ear.ear")) 
    //    .as(EnterpriseArchive.class); 
    // } 
    //  
    // @Deployment(order = 2, name = "stock-wiz-ear", testable = false) 
    // public static Archive<?> createStockWizEjbArchive() { 
    //  return ShrinkWrap 
    //    .create(ZipImporter.class, "stock-wiz-ear.ear") 
    //    .importFrom(new File("target/dependency/stock-wiz-ear.ear")) 
    //    .as(EnterpriseArchive.class); 
    // } 

    @Deployment 
    public static Archive<?> createConductorEjbArchive() { 

     JavaArchive ejbModule = ShrinkWrap 
       .create(ZipImporter.class, "conductor-ejb.jar") 
       .importFrom(new File("target/dependency/conductor-ejb.jar")) 
       .as(JavaArchive.class); 

     ejbModule.deletePackage("za.co.fnb.cbs.conductor.component.camel"); 

     EnterpriseArchive ear = ShrinkWrap 
       .create(ZipImporter.class, "conductor-ear.ear") 
       .importFrom(new File("target/dependency/conductor-ear.ear")) 
       .as(EnterpriseArchive.class); 
     ear.delete("/conductor-ejb.jar"); 
     ear.delete("/controller-web.war"); 
     ear.addAsModule(ejbModule); 
     System.out.println(ear.toString(true)); 
     return ear; 
    } 

    @Test 
    public void shouldBeInjected() throws Exception { 
     Assert.assertNotNull(productService); 
    } 

} 

我註釋掉的兩個額外的部署,這是依賴於我的積分測試。在執行測試之前,我手動將依賴關係部署到服務器。無論如何,我似乎無法得到它的工作。

我也試着指定JNDI映射名稱如下:

@EJB(mappedName = "java:global/conductor/conductor-ejb/ProductService!za.co.fnb.cbs.conductor.api.smartdevices.services.IProductService") 
public IProductService productService; 

我也試着仰視通過上下文中的EJB ...

@Before 
public void before() throws Exception { 
    Properties jndiProps = new Properties(); 
    jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
//   env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory"); 
    jndiProps.put(Context.PROVIDER_URL, "remote://localhost:4447"); 
    initialContext = new InitialContext(jndiProps); 
    productService = (IProductService)initialContext.lookup("java:module/ProductService!za.co.fnb.cbs.conductor.api.smartdevices.services.IProductService"); 
} 

我也試過CDI注入,並將bean.xml放置在測試資源類路徑中,以及主類路徑中。沒有運氣。

Arquillian能夠對EnterpriseArchive的集成測試運行嗎? 從我的經驗來看,似乎並非如此。

我遇到的所有示例都涉及創建一個具有一個或兩個類的小JavaArchive。這對我不起作用。由於需要所有的依賴關係,我必須部署EAR。

+0

我放棄了Arquillian,最終能夠通過遠程調用來測試我的EJB,請閱讀以下文章:http://blog.jonasbandi.net/2013/08/jboss-remote-ejb-invocation-unexpected.html –

回答

0

EJB是一個託管bean。如果它的null表示它沒有被注入,那麼可能的原因可能是JMX超時,這意味着MBean服務器沒有及時響應請求,我只是說增加JMX超時並給它一個bash xxxxxxx。