我正在开发一款需要运行在Glassfish 3.1上的MDB的应用程序。我已经管理过使用嵌入式容器运行简单EJB的单元/集成测试,没有任何问题。现在我正在尝试为我的MDB创建集成测试。JMS与Maven和Glassfish的集成测试
1)我尝试以编程方式启动Glassfish嵌入式服务器,但它不支持创建JMS队列。
2)我从Maven插件运行Glassfish服务器。 现在我可以创建队列,并部署我的MDB,完全没有问题。现在,我无法弄清楚运行JUnit的方式。
- 当我创建InitialContext时,访问本地服务器时超时。我没有办法访问我的豆子。
我找到了一个解决办法,但它不是完美的服务我的需求:
在我的测试源,我创建了一个简单的辛格尔顿@Startup豆。在@PostConstruct方法中,我称之为要实现的单元测试类。为了部署这个bean,我有一个特殊的Maven构建规则,它将我的一些测试文件打包到EJB jar中。部署这个特殊的jar导致我的测试正在启动。要清楚,这是我的Maven文件的摘录:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/test-ejb</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/classes</directory>
</resource>
<resource>
<directory>${project.build.directory}/test-classes</directory>
<includes>
<include>**/*TestTrigger.class</include>
<include>**/*IntegrationTest.class</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>ejb</goal>
</goals>
<configuration>
<classifier>TEST</classifier>
<outputDirectory>${project.build.directory}/test-ejb</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.glassfish</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>${glassfish.version}</version>
<configuration>
<goalPrefix>glassfish</goalPrefix>
<app>target/${project.build.finalName}-TEST.jar</app>
<port>8080</port>
<name>MyApp</name>
<serverID>embedded</serverID>
</configuration>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>admin</id>
<phase>pre-integration-test</phase>
<goals>
<goal>admin</goal>
</goals>
<configuration>
<commands>
<param>create-jms-resource --restype javax.jms.QueueConnectionFactory jms/TestQueueConnectionFactory</param>
<param>create-jms-resource --restype javax.jms.Queue --property imqDestinationName=ceQueue jms/ceQueue</param>
</commands>
</configuration>
</execution>
<execution>
<id>deploy</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>undeploy</goal>
<goal>stop</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
现在,有没有什么办法我IntegrationTest可以使用surfire推出,以产生一个适当的报告,并不能建立,如果测试别通过?更不用说Cobertura了。
谢谢你的帮助。