我一直在尝试在我的“远程”本地主机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。
我放弃了Arquillian,最终能够通过远程调用来测试我的EJB,请阅读以下文章:http://blog.jonasbandi.net/2013/08/jboss-remote-ejb-invocation-unexpected.html –