2016-11-02 1 views
3

統合テスト用に組み込みのWildfly 10サーバーをオンザフライでセットアップする方法について質問があります。Mavenでのテストのために組み込みのWildFlyサーバーをオンザフライでセットアップする方法

<!-- Loading Wildfly 10 on the fly and copy it into the target folder. --> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>unpack</id> 
      <phase>process-test-classes</phase> 
      <goals> 
       <goal>unpack</goal> 
      </goals> 
      <configuration> 
       <artifactItems> 
        <artifactItem> 
         <groupId>org.wildfly</groupId> 
         <artifactId>wildfly-dist</artifactId> 
         <version>10.0.0.Final</version> 
         <type>zip</type> 
         <overWrite>false</overWrite> 
         <outputDirectory>target</outputDirectory> 
        </artifactItem> 
       </artifactItems> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

<plugin> 
    <groupId>org.wildfly.plugins</groupId> 
    <artifactId>wildfly-maven-plugin</artifactId> 
    <version>1.1.0.Alpha1</version> 
    <configuration> 
     <jbossHome>target/wildfly-10.0.0.Final</jbossHome> 
     <hostname>127.0.0.1</hostname> 
     <!-- <port>9990</port> --> 
     <filename>${project.build.finalName}.war</filename> 
     <java-opts> 
      <java-opt>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005</java-opt> 
     </java-opts> 
     <commands> 
      <command>/subsystem=logging/file-handler=debug:add(level=DEBUG,autoflush=true,file={"relative-to"=>"jboss.server.log.dir", 
       "path"=>"debug.log"})</command> 
      <command>/subsystem=logging/logger=org.jboss.as:add(level=DEBUG,handlers=[debug])</command> 
     </commands> 
    </configuration> 
    <dependencies> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
      <version>1.6.4</version> 
     </dependency> 
    </dependencies> 
    <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>deploy</goal> 
      </goals> 
     </execution> 
     <execution> 
      <id>start-wildfly</id> 
      <phase>test-compile</phase> 
      <goals> 
       <goal>run</goal> 
      </goals> 
     </execution> 
     <execution> 
      <id>shutdown-wildfly</id> 
      <phase>test</phase> 
      <goals> 
       <goal>shutdown</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

最初にMavenがサーバーをダウンロードしてターゲットフォルダに保存します。後で新しいstandalone.xmlをコピーし、サーバーを起動し、統合テストを実行してサーバーを停止します。

今まで私がサーバーを起動したことがわかりません。

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running com.example.FunctionalTest 
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.071 sec <<< FAILURE! - in com.example.FunctionalTest 
basicPingTest(com.example.FunctionalTest) Time elapsed: 0.07 sec <<< ERROR! 
java.net.ConnectException: Connection refused 
at com.example.FunctionalTest.basicPingTest(FunctionalTest.java:39) 

Results : 

Tests in error: 
FunctionalTest.basicPingTest:39 » Connect Connection refused 

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0 

は、誰もがスタートをMavenを設定し、組み込みWildflyサーバを停止し、テストケースを起動し、うまくいけば、いくつかのログを確認する方法を知っていますか?

答えて

3

Arquillianをご覧になることをお勧めします。これは、コンテナのライフサイクル管理を担当し、コンテナに展開してテストを実行します。テスト(ランナー)自体がコンテナのライフサイクルを管理するため、IDE内からテストを実行することも可能です。

WildFly Mavenプラグインを使用してコンテナを制御する場合は、Maven Failsafeプラグインをこの種の統合テストに使用して、テストが実行された後もコンテナが安全にシャットダウンされるようにする必要があります失敗の場合は

また、Arquillianを使用して統合テストを実行するHibernate Searchからthese integration testsを取得することもできます。 src/test/resources/arquillian.xmlここでは、standalone.xmlの代わりに、使用する特定のサーバー設定ファイルを指しています。

このPOMは、Maven依存関係プラグインを使用してWildFlyをダウンロードし、テストを実行する前にそれを抽出する方法も示しています。

関連する問題