Glassfish 3.1 で動作する MDB を必要とするアプリを開発しています。埋め込みコンテナーを使用して、単純な EJB の単体/統合テストを問題なく実行することができました。現在、MDB の統合テストを作成しようとしています。
1) Glassfish 組み込みサーバーをプログラムで起動しようとしましたが、JMS キューの作成をサポートしていません。
2) Maven プラグインから Glassfish サーバーを実行します。これで、キューを作成し、MDB をデプロイできます。まったく問題ありません。今、私はJUnitを実行する方法を理解できません。
- InitialContext を作成すると、ローカル サーバーへのアクセス時にタイムアウトします。Bean にアクセスする方法がありません。
回避策を見つけましたが、私のニーズを完全には満たしていません
。私のテスト ソースでは、シンプルなシングルトン @Startup Bean を作成しました。@PostConstruct メソッドで、実現したい単体テスト クラスを呼び出します。この Bean をデプロイするために、いくつかのテスト ファイルを EJB jar にパッケージ化する特別な特別な Maven ビルド ルールがあります。この特別な 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>
さて、テストに合格しない場合に適切なレポートを作成してビルドを失敗させるために、surfire を使用して IntegrationTest を起動する方法はありますか? コベルチュラは言うまでもありません。
ご協力ありがとうございました。