Kohei Nozaki's blog 

Arquillianチュートリアルのリモートコンテナでテストを走らせるところをやってみる


Posted on Saturday Jan 25, 2014 at 11:21AM in Technology


ArquillianチュートリアルのJBoss AS7でテストを走らせるところをやってみるの続きです。チュートリアル[1]のremoteモード(すでに動いているアプリケーションサーバでテストをする)でテストを走らせるところをやってみます。

環境

  • JBoss AS 7.1.1.Final
  • Eclipse Kepler SR1
  • Apache Maven 2.2.1 (r801777; 2009-08-07 04:16:01+0900)
  • Apple JDK6u65
  • OS X 10.9.1

準備

チュートリアルでは新しいコンポーネントを作るところから入っていますが、面倒なので飛ばして最初に作った単純なコンポーネントだけでいきます。

JBoss AS7をEclipseに登録して起動

remoteモードでは手動でJBossの立ち上げをやらないといけないので、とりあえずEclipseに登録して起動しておきます

  1. Server窓で右クリック→New→Server

  2. JBoss Communityの中のJBoss AS 7.1を選んでNext

  3. JBossを展開したディレクトリを入力しJavaSE1.6のJREを選んでFinish

  4. 登録された事を確認

  5. JBoss 7.1 Runtime Serverを右クリックしてStartを選択

  6. コンソールを見て起動する事を確認

pom.xmlの編集

新たなProfile「arquillian-jbossas-remote」を追加します。チュートリアルにはGlassFish3用の設定法も書かれていますが飛ばします。結果こうなる

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.arquillian.example</groupId>
    <artifactId>arquillian-tutorial</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>arquillian-tutorial</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>1.1.2.Final</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12</version>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.8.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-integration</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>net.avh4.util</groupId>
            <artifactId>imagecomparison</artifactId>
            <version>0.0.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <!-- clip -->
    <profiles>
        <profile>
            <id>arquillian-weld-ee-embedded</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.spec</groupId>
                    <artifactId>jboss-javaee-6.0</artifactId>
                    <version>1.0.0.Final</version>
                    <type>pom</type>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.arquillian.container</groupId>
                    <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
                    <version>1.0.0.CR3</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.weld</groupId>
                    <artifactId>weld-core</artifactId>
                    <version>1.1.5.Final</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                    <version>1.6.4</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>
        <!-- clip -->
        <profile>
            <id>arquillian-glassfish-embedded</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.arquillian.container</groupId>
                    <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
                    <version>1.0.0.CR2</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.glassfish.main.extras</groupId>
                    <artifactId>glassfish-embedded-all</artifactId>
                    <version>3.1.2</version>
                    <scope>provided</scope>
                </dependency>
            </dependencies>
        </profile>
        <!-- clip -->
        <!-- clip -->
        <profile>
            <id>arquillian-jbossas-managed</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.spec</groupId>
                    <artifactId>jboss-javaee-6.0</artifactId>
                    <version>1.0.0.Final</version>
                    <type>pom</type>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.as</groupId>
                    <artifactId>jboss-as-arquillian-container-managed</artifactId>
                    <version>7.1.1.Final</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.arquillian.protocol</groupId>
                    <artifactId>arquillian-protocol-servlet</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>
        <!-- clip -->
        <!-- clip -->
        <profile>
            <id>arquillian-jbossas-remote</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.spec</groupId>
                    <artifactId>jboss-javaee-6.0</artifactId>
                    <version>1.0.0.Final</version>
                    <type>pom</type>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.as</groupId>
                    <artifactId>jboss-as-arquillian-container-remote</artifactId>
                    <version>7.1.1.Final</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>
        <!-- clip -->
    </profiles>
    <!-- clip -->
</project>

Profileを変更

  1. プロジェクトを右クリック→Maven→Select Maven Profilesを選択

  2. arquillian-jbossas-remoteだけチェックされた状態にしてOK

Eclipseからテスト実行

前回同様テストクラスを右クリック→Run As→JUnit Testで実行します。

コンソール

JUnit窓

ログ

14:22:09,297 INFO  [org.jboss.as.repository] (management-handler-thread - 5) JBAS014900: Content added at location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/01/428305db821001575772a3e91a1fc2db39bf0e/content
14:22:09,307 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "arquillian-service"
14:22:09,497 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-9) JBAS018567: Deployment "deployment.arquillian-service" is using a private module ("org.jboss.as.jmx:main") which may be changed or removed in future versions without notice.
14:22:09,498 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-9) JBAS018567: Deployment "deployment.arquillian-service" is using a private module ("org.jboss.as.server:main") which may be changed or removed in future versions without notice.
14:22:09,498 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-9) JBAS018567: Deployment "deployment.arquillian-service" is using a private module ("org.jboss.as.osgi:main") which may be changed or removed in future versions without notice.
14:22:09,499 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-9) JBAS018567: Deployment "deployment.arquillian-service" is using a private module ("org.jboss.jandex:main") which may be changed or removed in future versions without notice.
14:22:09,499 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-9) JBAS018567: Deployment "deployment.arquillian-service" is using a private module ("org.jboss.osgi.framework:main") which may be changed or removed in future versions without notice.
14:22:09,574 INFO  [org.jboss.as.server] (management-handler-thread - 5) JBAS018559: Deployed "arquillian-service"
14:22:09,826 INFO  [org.jboss.as.repository] (management-handler-thread - 6) JBAS014900: Content added at location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/ca/98d99cb1a5a4e11c31041af98a99d4adb7c05c/content
14:22:09,829 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-14) JBAS015876: Starting deployment of "2cfbb74d-9ab5-4b63-9bad-9b2257442d92.jar"
14:22:09,848 INFO  [org.jboss.weld.deployer] (MSC service thread 1-13) JBAS016002: Processing weld deployment 2cfbb74d-9ab5-4b63-9bad-9b2257442d92.jar
14:22:09,856 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016005: Starting Services for CDI deployment: 2cfbb74d-9ab5-4b63-9bad-9b2257442d92.jar
14:22:09,901 INFO  [org.jboss.weld.Version] (MSC service thread 1-7) WELD-000900 1.1.5 (AS71)
14:22:09,914 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) JBAS016008: Starting weld service for deployment 2cfbb74d-9ab5-4b63-9bad-9b2257442d92.jar
14:22:09,914 INFO  [org.jboss.as.arquillian] (MSC service thread 1-2) Arquillian deployment detected: ArquillianConfig[service=jboss.arquillian.config."2cfbb74d-9ab5-4b63-9bad-9b2257442d92.jar",unit=2cfbb74d-9ab5-4b63-9bad-9b2257442d92.jar,tests=[org.arquillian.example.GreeterTest]]
14:22:10,143 INFO  [org.jboss.as.server] (management-handler-thread - 6) JBAS018559: Deployed "2cfbb74d-9ab5-4b63-9bad-9b2257442d92.jar"
14:22:10,307 INFO  [stdout] (pool-4-thread-1) Hello, Earthling!
14:22:10,346 INFO  [org.jboss.weld.deployer] (MSC service thread 1-5) JBAS016009: Stopping weld service for deployment 2cfbb74d-9ab5-4b63-9bad-9b2257442d92.jar
14:22:10,358 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) JBAS015877: Stopped deployment 2cfbb74d-9ab5-4b63-9bad-9b2257442d92.jar in 16ms
14:22:10,367 INFO  [org.jboss.as.repository] (management-handler-thread - 8) JBAS014901: Content removed from location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/ca/98d99cb1a5a4e11c31041af98a99d4adb7c05c/content
14:22:10,368 INFO  [org.jboss.as.server] (management-handler-thread - 8) JBAS018558: Undeployed "2cfbb74d-9ab5-4b63-9bad-9b2257442d92.jar"
14:22:10,386 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-13) JBAS015877: Stopped deployment arquillian-service in 9ms
14:22:10,395 INFO  [org.jboss.as.repository] (management-handler-thread - 5) JBAS014901: Content removed from location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/01/428305db821001575772a3e91a1fc2db39bf0e/content
14:22:10,396 INFO  [org.jboss.as.server] (management-handler-thread - 5) JBAS018558: Undeployed "arquillian-service"

mvnからテスト実行

kyle-no-MacBook:arquillian-tutorial kyle$ JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home mvn test -Parquillian-jbossas-remote -Dtest=GreeterTest
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building arquillian-tutorial
[INFO]    task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: /Users/kyle/Documents/workspace/arquillian-tutorial/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
Running org.arquillian.example.GreeterTest
2014/01/25 14:31:06 org.jboss.arquillian.container.impl.MapObject populate
警告: Configuration contain properties not supported by the backing object org.jboss.as.arquillian.container.remote.RemoteContainerConfiguration
Unused property entries: {javaVmArguments=-Dfile.encoding=UTF-8, jbossHome=/Users/kyle/apps/jboss-as-7.1.1.Final}
Supported property names: [managementPort, username, managementAddress, password]
2014/01/25 14:31:06 org.jboss.as.arquillian.protocol.jmx.ArquillianServiceDeployer doServiceDeploy
INFO: Deploy arquillian service: arquillian-service: 1001 assets
2014/01/25 14:31:06 org.xnio.Xnio <clinit>
INFO: XNIO Version 3.0.3.GA
2014/01/25 14:31:06 org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.3.GA
2014/01/25 14:31:06 org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.2.GA
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.906 sec
2014/01/25 14:31:08 org.jboss.as.arquillian.protocol.jmx.ArquillianServiceDeployer undeploy
INFO: Undeploy arquillian service: arquillian-service: 1002 assets

Results :

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Sat Jan 25 14:31:08 JST 2014
[INFO] Final Memory: 43M/90M
[INFO] ------------------------------------------------------------------------
kyle-no-MacBook:arquillian-tutorial kyle$ 

前回使ったmanaged用の設定項目が残ったままな点だけ警告が出てますが普通に動いてます。

その他

managedで9秒強かかっていたのが2〜3秒で終わるようになっています。速い。良いですね。

あとはJPAを使ったコンポーネントのテストと、JRE7とWildFly8でJavaEE7アプリのテストをしてみたいと思います

続き

ArquillianチュートリアルのJPAを使ったテストを走らせるところをやってみる

参考文献

  1. Getting Started: Rinse and Repeat · Arquillian Guides (日本語訳)



No one has commented yet.

Leave a Comment

HTML Syntax: NOT allowed