【发布时间】:2014-08-09 13:41:04
【问题描述】:
我一直在尝试在我的“远程”本地 JBoss 服务器(非嵌入式/托管)上执行 Arquillian 集成测试,但我的本地 EJB 没有被注入。
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 注入,并将 beans.xml 放在测试资源类路径以及主类路径中。没有运气。
Arquillian 是否能够在 EnterpriseArchive 上运行集成测试? 根据我的经验,情况似乎并非如此。
我遇到的所有示例都涉及创建一个带有一两个类的小型 JavaArchive。这对我不起作用。由于需要所有依赖项,我必须部署 EAR。
【问题讨论】:
-
我放弃了 Arquillian,最终能够通过远程调用测试我的 EJB,遵循这篇文章:blog.jonasbandi.net/2013/08/…
标签: maven jakarta-ee integration-testing jboss-arquillian