arquillian-remote 进行EJB测试

一、使用默认的jpa实现进行remote测试

此配置请参照官网的配置http://arquillian.org/guides/getting_started_rinse_and_repeat/,此处不做重复。

二、使用自己的jpa实现进行remote测试

1、配置pom.xml
由于此测试框架有自己的一套JavaEE的实现jar包,所以会造成与工程内部的jsf和javaee6 api等冲突,使用测试框架时不能启用此jar包(通过配置profile,可参考arquillian官网示例介绍)。
<profile>
	<id>dev</id>
	<activation>
		<activeByDefault>true</activeByDefault>
	</activation>
	<dependencies>
		<dependency>
			<groupId>javax</groupId>
			<artifactId>javaee-web-api</artifactId>
			<version>6.0</version>
			<type>jar</type>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.faces</groupId>
			<artifactId>jsf-api</artifactId>
			<version>2.1</version>
			<type>jar</type>
			<scope>provided</scope>
		</dependency>
	</dependencies>
</profile>
配置测试框架需要的基础jar包(请参照上一篇博客"arquillian-embedded 进行EJB测试"或者官网介绍)

除了配置基础jar包以外,如果要使用自己的jpa实现还需要配置一个单独的jar包(重要)
	<dependency>
		<groupId>org.jboss.shrinkwrap.resolver</groupId>
		<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
		<scope>test</scope>
		<exclusions>
			<exclusion>
				<groupId>com.google.collections</groupId>
				<artifactId>google-collections</artifactId>
			</exclusion>
		</exclusions>
	</dependency>
2、配置arquillian.xml(注意:测试服务器用的为glassfish3.1.1。我使用的测试版本无法在glassfish3.1.2上运行)
<?xml version="1.0"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://jboss.org/schema/arquillian"
	xsi:schemaLocation="http://jboss.org/schema/arquillian
    http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
	<container qualifier="glassfish" default="true">
		<configuration>
			<property name="remoteServerAddress">10.228.XX.XX</property>
			<property name="remoteServerHttpPort">8080</property>
			<property name="remoteServerAdminPort">4848</property>
			<property name="adminUser">admin</property>
			<property name="adminPassword"></property>
		</configuration>
	</container>
</arquillian>

测试代码中需要通过配置的maven resolver的api加入openjpa的依赖
@RunWith(Arquillian.class)
public class TestServiceTest {
	@Deployment
	public static Archive<?> createDeployment() {
		MavenDependencyResolver resolver = DependencyResolvers
				.use(MavenDependencyResolver.class)
				.loadMetadataFromPom("pom.xml");
		WebArchive webInfResource = ShrinkWrap
				.create(WebArchive.class, "arqTest.war")
				.addClass(MyTestService.class)
				.addAsLibraries(resolver.artifact("org.apache.openjpa:openjpa-all:2.1.1").resolveAsFiles()) 
				.addPackages(true, "com.test.model")
				.addAsResource("META-INF/persistence.xml")
				.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
		System.out.println("webInfResource:" + webInfResource);
		return webInfResource;
	}
	@EJB
	private MyTestService rs;
	@Test
	public void testCal() {
		rs.test();
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值