Kohei Nozaki's blog 

ArquillianをWildFly8.0.0.CR1で動かしてみる


Posted on Saturday Jan 25, 2014 at 05:20PM in Technology


ArquillianチュートリアルのJPAを使ったテストを走らせるところをやってみるの続きです。WildFly8.0.0.CR1に対してremoteモードでArquillianのテストを走らせてみます。

環境

  • WildFly 8.0.0.CR1
  • Eclipse Kepler SR1
  • Apache Maven 2.2.1 (r801777; 2009-08-07 04:16:01+0900)
  • Oracle JDK7u51
  • OS X 10.9.1

準備

pom.xmlの編集

[1]に書かれたdependency要素を使ってpom.xmlに新しいprofile要素を定義します。こうなる

<?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 -->
        <!-- wildfly start -->
        <profile>
            <id>arquillian-wildfly-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.wildfly</groupId>
                    <artifactId>wildfly-arquillian-container-remote</artifactId>
                    <version>8.0.0.CR1</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>
        <!-- wildfly end -->
    </profiles>
    <!-- clip -->
</project>

Profileの選択を変更

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

JVMの設定を変更

このままテストを走らせようとするとUnsupportedClassVersionErrorが出てしまいます。Arquillianを走らせるJREが1.6でWildFlyは1.7なのが原因っぽいのでプロジェクト側のJREを変更します。

  1. プロジェクトの設定→Java Build Path→Librariesを開く

  2. JRE System Library [JavaSE-1.6] を選択してEditを選択

  3. ラジオボタンをAlternate JREに合わせてドロップダウンリストからJava SE 7を選択してOK

  4. JRE System Library [Java SE 7] に変わっているのを確認してOK

テストを走らせる

WildFly8を起動して前回と同じやり方で走らせてみます

GreeterTest (JPA使ってない方)

WARNレベルのメッセージが若干出てますが普通に走ります

JUnit窓

ログ

17:41:30,906 INFO  [org.jboss.as.repository] (management-handler-thread - 5) JBAS014900: Content added at location /Users/kyle/apps/wildfly-8.0.0.CR1/standalone/data/content/be/e45d12928bf1ee6b6f2f2206e4995f7b80ca61/content
17:41:30,909 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-11) JBAS015876: Starting deployment of "arquillian-service" (runtime-name: "arquillian-service")
17:41:31,005 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-2) 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.
17:41:31,005 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-2) 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.
17:41:31,006 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-2) 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.
17:41:31,006 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-2) JBAS018567: Deployment "deployment.arquillian-service" is using a private module ("org.wildfly.security.manager:main") which may be changed or removed in future versions without notice.
17:41:31,011 WARN  [org.jboss.weld.deployer] (MSC service thread 1-4) JBAS016012: Deployment deployment "arquillian-service" contains CDI annotations but no bean archive was not found. (No beans.xml nor class with bean defining annotations)
17:41:31,040 INFO  [org.jboss.as.server] (management-handler-thread - 5) JBAS018559: Deployed "arquillian-service" (runtime-name : "arquillian-service")
17:41:32,924 INFO  [org.jboss.as.repository] (management-handler-thread - 5) JBAS014900: Content added at location /Users/kyle/apps/wildfly-8.0.0.CR1/standalone/data/content/ea/a3ef36deeeb6b7c9f983ca3a59bf1b078e3a7c/content
17:41:32,927 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-16) JBAS015876: Starting deployment of "f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar" (runtime-name: "f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar")
17:41:32,940 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-14) JBAS018567: Deployment "deployment.f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar" is using a private module ("org.wildfly.security.manager:main") which may be changed or removed in future versions without notice.
17:41:32,941 INFO  [org.jboss.weld.deployer] (MSC service thread 1-14) JBAS016002: Processing weld deployment f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar
17:41:32,946 INFO  [org.jboss.weld.deployer] (MSC service thread 1-12) JBAS016005: Starting Services for CDI deployment: f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar
17:41:32,950 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016008: Starting weld service for deployment f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar
17:41:32,950 INFO  [org.jboss.as.arquillian] (MSC service thread 1-12) Arquillian deployment detected: ArquillianConfig[service=jboss.arquillian.config."f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar",unit=f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar,tests=[org.arquillian.example.GreeterTest]]
17:41:33,062 INFO  [org.jboss.as.server] (management-handler-thread - 5) JBAS018559: Deployed "f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar" (runtime-name : "f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar")
17:41:33,238 INFO  [stdout] (pool-2-thread-2) Hello, Earthling!
17:41:33,298 INFO  [org.jboss.weld.deployer] (MSC service thread 1-14) JBAS016009: Stopping weld service for deployment f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar
17:41:33,310 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) JBAS015877: Stopped deployment f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar (runtime-name: f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar) in 19ms
17:41:33,322 INFO  [org.jboss.as.repository] (management-handler-thread - 7) JBAS014901: Content removed from location /Users/kyle/apps/wildfly-8.0.0.CR1/standalone/data/content/ea/a3ef36deeeb6b7c9f983ca3a59bf1b078e3a7c/content
17:41:33,322 INFO  [org.jboss.as.server] (management-handler-thread - 7) JBAS018558: Undeployed "f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar" (runtime-name: "f4da79a4-4a77-4468-9fce-679cc1f8aa95.jar")
17:41:33,340 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015877: Stopped deployment arquillian-service (runtime-name: arquillian-service) in 5ms
17:41:33,350 INFO  [org.jboss.as.repository] (management-handler-thread - 8) JBAS014901: Content removed from location /Users/kyle/apps/wildfly-8.0.0.CR1/standalone/data/content/be/e45d12928bf1ee6b6f2f2206e4995f7b80ca61/content
17:41:33,350 INFO  [org.jboss.as.server] (management-handler-thread - 8) JBAS018558: Undeployed "arquillian-service" (runtime-name: "arquillian-service")

GamePersistenceTest (JPA使っている方)

こちらもWARNレベルのメッセージが若干出てますが普通に走ります

JUnit窓

ログ

17:54:11,145 INFO  [org.jboss.as.repository] (management-handler-thread - 17) JBAS014900: Content added at location /Users/kyle/apps/wildfly-8.0.0.CR1/standalone/data/content/7d/5f3376f9a12e783c3e26d6d58e51ffcf03c103/content
17:54:11,147 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-12) JBAS015876: Starting deployment of "arquillian-service" (runtime-name: "arquillian-service")
17:54:11,206 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-7) 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.
17:54:11,206 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-7) 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.
17:54:11,207 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-7) 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.
17:54:11,207 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-7) JBAS018567: Deployment "deployment.arquillian-service" is using a private module ("org.wildfly.security.manager:main") which may be changed or removed in future versions without notice.
17:54:11,211 WARN  [org.jboss.weld.deployer] (MSC service thread 1-12) JBAS016012: Deployment deployment "arquillian-service" contains CDI annotations but no bean archive was not found. (No beans.xml nor class with bean defining annotations)
17:54:11,222 INFO  [org.jboss.as.server] (management-handler-thread - 17) JBAS018559: Deployed "arquillian-service" (runtime-name : "arquillian-service")
17:54:11,873 INFO  [org.jboss.as.repository] (management-handler-thread - 17) JBAS014900: Content added at location /Users/kyle/apps/wildfly-8.0.0.CR1/standalone/data/content/ec/f5873a270286159d851f049b3d6d3d50d72491/content
17:54:11,875 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "test.war" (runtime-name: "test.war")
17:54:11,890 INFO  [org.jboss.as.jpa] (MSC service thread 1-10) JBAS011401: Read persistence.xml for test
17:54:11,898 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-11) JBAS018567: Deployment "deployment.test.war" is using a private module ("org.wildfly.security.manager:main") which may be changed or removed in future versions without notice.
17:54:11,900 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) JBAS010400: Bound data source [java:/jdbc/arquillian]
17:54:11,900 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 79) JBAS011409: Starting Persistence Unit (phase 1 of 2) Service 'test.war#test'
17:54:11,901 INFO  [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 79) HHH000204: Processing PersistenceUnitInfo [
    name: test
    ...]
17:54:11,909 INFO  [org.jboss.weld.deployer] (MSC service thread 1-11) JBAS016002: Processing weld deployment test.war
17:54:11,917 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) JBAS016005: Starting Services for CDI deployment: test.war
17:54:11,920 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) JBAS016008: Starting weld service for deployment test.war
17:54:11,921 INFO  [org.jboss.as.arquillian] (MSC service thread 1-3) Arquillian deployment detected: ArquillianConfig[service=jboss.arquillian.config."test.war",unit=test.war,tests=[org.arquillian.example.GreeterTest, org.arquillian.example.GamePersistenceTest]]
17:54:11,924 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 79) JBAS011409: Starting Persistence Unit (phase 2 of 2) Service 'test.war#test'
17:54:11,932 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 79) HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
17:54:11,933 WARN  [org.hibernate.dialect.H2Dialect] (ServerService Thread Pool -- 79) HHH000431: Unable to determine H2 database version, certain features may not work
17:54:11,935 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 79) HHH000397: Using ASTQueryTranslatorFactory
17:54:11,945 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 79) HHH000227: Running hbm2ddl schema export
17:54:11,946 INFO  [stdout] (ServerService Thread Pool -- 79) Hibernate: drop table Game if exists
17:54:11,946 INFO  [stdout] (ServerService Thread Pool -- 79) Hibernate: drop sequence hibernate_sequence
17:54:11,947 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 79) HHH000389: Unsuccessful: drop sequence hibernate_sequence
17:54:11,947 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 79) シーケンス "HIBERNATE_SEQUENCE" が見つかりません
Sequence "HIBERNATE_SEQUENCE" not found; SQL statement:
drop sequence hibernate_sequence [90036-173]
17:54:11,947 INFO  [stdout] (ServerService Thread Pool -- 79) Hibernate: create table Game (id bigint not null, title varchar(50) not null, primary key (id))
17:54:11,948 INFO  [stdout] (ServerService Thread Pool -- 79) Hibernate: create sequence hibernate_sequence start with 1 increment by 1
17:54:11,948 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 79) HHH000230: Schema export complete
17:54:12,078 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-14) JBAS017534: Register web context: /test
17:54:12,086 INFO  [org.jboss.as.server] (management-handler-thread - 17) JBAS018559: Deployed "test.war" (runtime-name : "test.war")
17:54:12,197 INFO  [stdout] (pool-2-thread-5) Dumping old records...
17:54:12,200 INFO  [stdout] (pool-2-thread-5) Hibernate: delete from Game
17:54:12,202 INFO  [stdout] (pool-2-thread-5) Inserting records...
17:54:12,202 INFO  [stdout] (pool-2-thread-5) Hibernate: call next value for hibernate_sequence
17:54:12,203 INFO  [stdout] (pool-2-thread-5) Hibernate: call next value for hibernate_sequence
17:54:12,204 INFO  [stdout] (pool-2-thread-5) Hibernate: call next value for hibernate_sequence
17:54:12,209 INFO  [stdout] (pool-2-thread-5) Hibernate: insert into Game (title, id) values (?, ?)
17:54:12,210 INFO  [stdout] (pool-2-thread-5) Hibernate: insert into Game (title, id) values (?, ?)
17:54:12,211 INFO  [stdout] (pool-2-thread-5) Hibernate: insert into Game (title, id) values (?, ?)
17:54:12,214 INFO  [stdout] (pool-2-thread-5) Selecting (using JPQL)...
17:54:12,216 INFO  [stdout] (pool-2-thread-5) Hibernate: select game0_.id as id1_0_, game0_.title as title2_0_ from Game game0_ order by game0_.id
17:54:12,218 INFO  [stdout] (pool-2-thread-5) Found 3 games (using JPQL):
17:54:12,218 INFO  [stdout] (pool-2-thread-5) * Game@649254855[id = 1; title = Super Mario Brothers]
17:54:12,218 INFO  [stdout] (pool-2-thread-5) * Game@661937578[id = 2; title = Mario Kart]
17:54:12,218 INFO  [stdout] (pool-2-thread-5) * Game@1219581986[id = 3; title = F-Zero]
17:54:12,247 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-14) JBAS017535: Unregister web context: /test
17:54:12,248 SEVERE [javax.faces] (MSC service thread 1-14) Unable to obtain InjectionProvider from init time FacesContext. Does this container implement the Mojarra Injection SPI?
17:54:12,248 SEVERE [javax.faces] (MSC service thread 1-14) Unable to call @PreDestroy annotated methods because no InjectionProvider can be found. Does this container implement the Mojarra Injection SPI?
17:54:12,248 SEVERE [javax.faces] (MSC service thread 1-14) Unable to obtain InjectionProvider from init time FacesContext. Does this container implement the Mojarra Injection SPI?
17:54:12,248 SEVERE [javax.faces] (MSC service thread 1-14) Unable to call @PreDestroy annotated methods because no InjectionProvider can be found. Does this container implement the Mojarra Injection SPI?
17:54:12,249 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 83) JBAS011410: Stopping Persistence Unit (phase 2 of 2) Service 'test.war#test'
17:54:12,250 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 83) HHH000227: Running hbm2ddl schema export
17:54:12,250 INFO  [stdout] (ServerService Thread Pool -- 83) Hibernate: drop table Game if exists
17:54:12,251 INFO  [stdout] (ServerService Thread Pool -- 83) Hibernate: drop sequence hibernate_sequence
17:54:12,252 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 83) HHH000230: Schema export complete
17:54:12,252 INFO  [org.jboss.weld.deployer] (MSC service thread 1-14) JBAS016009: Stopping weld service for deployment test.war
17:54:12,256 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 83) JBAS011410: Stopping Persistence Unit (phase 1 of 2) Service 'test.war#test'
17:54:12,256 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010409: Unbound data source [java:/jdbc/arquillian]
17:54:12,260 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015877: Stopped deployment test.war (runtime-name: test.war) in 14ms
17:54:12,270 INFO  [org.jboss.as.repository] (management-handler-thread - 19) JBAS014901: Content removed from location /Users/kyle/apps/wildfly-8.0.0.CR1/standalone/data/content/ec/f5873a270286159d851f049b3d6d3d50d72491/content
17:54:12,271 INFO  [org.jboss.as.server] (management-handler-thread - 19) JBAS018558: Undeployed "test.war" (runtime-name: "test.war")
17:54:12,286 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015877: Stopped deployment arquillian-service (runtime-name: arquillian-service) in 3ms
17:54:12,294 INFO  [org.jboss.as.repository] (management-handler-thread - 20) JBAS014901: Content removed from location /Users/kyle/apps/wildfly-8.0.0.CR1/standalone/data/content/7d/5f3376f9a12e783c3e26d6d58e51ffcf03c103/content
17:54:12,295 INFO  [org.jboss.as.server] (management-handler-thread - 20) JBAS018558: Undeployed "arquillian-service" (runtime-name: "arquillian-service")

ロガーを設定してみるで書いたHibernateのロガーの設定をしている場合は、Hibernateのログが2重に出力されてしまうので、一時的に以下のようにコンソールのログレベルを変えておくと良いかもしれません。以下jboss-cli用コマンド

/subsystem=logging/console-handler=CONSOLE:change-log-level(level=INFO)

参考文献

  1. Arquillian WildFly 8 Remote Container Adapter · Arquillian
  2. How to change JRE / JDK in Eclipse project.

添付資料

JREを変更しないと発生する例外

java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:160)
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:111)
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:97)
    at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
    at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:93)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:156)
    ... 10 more
Caused by: java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.core.impl.ManagerImpl
    at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:160)
    at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:111)
    at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:97)
    at org.jboss.arquillian.core.spi.ManagerBuilder.create(ManagerBuilder.java:77)
    at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:55)
    ... 15 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:156)
    ... 19 more
Caused by: java.lang.UnsupportedClassVersionError: org/jboss/as/arquillian/container/remote/RemoteContainerExtension : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at org.jboss.arquillian.core.impl.loadable.JavaSPIExtensionLoader.load(JavaSPIExtensionLoader.java:108)
    at org.jboss.arquillian.core.impl.loadable.JavaSPIExtensionLoader.all(JavaSPIExtensionLoader.java:65)
    at org.jboss.arquillian.core.impl.loadable.JavaSPIExtensionLoader.load(JavaSPIExtensionLoader.java:53)
    at org.jboss.arquillian.core.impl.loadable.LoadableExtensionLoader.load(LoadableExtensionLoader.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
    at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
    at org.jboss.arquillian.core.impl.ManagerImpl.fireProcessing(ManagerImpl.java:316)
    at org.jboss.arquillian.core.impl.ManagerImpl.<init>(ManagerImpl.java:98)
    ... 24 more


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


Posted on Saturday Jan 25, 2014 at 02:29PM in Technology


Arquillianチュートリアルのリモートコンテナでテストを走らせるところをやってみるの続きです。JPAを使ったテストを走らせるところをやってみます。今回も基本的にはチュートリアル[1]なぞるだけです。

環境

  • 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

準備

チュートリアルにはGlassFishでテストを走らせる方法についても書いてありますが、ここではJBossで必要なものだけ用意します

何を作るか

この画像で選択されている4つのリソースを作ります

Game.java (エンティティクラス)

package org.arquillian.example;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
public class Game implements Serializable {
    private Long id;
    private String title;

    public Game() {}

    public Game(String title) {
        this.title = title;
    }

    @Id @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @NotNull
    @Size(min = 3, max = 50)
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        return "Game@" + hashCode() + "[id = " + id + "; title = " + title + "]";
    }
}

GamePersistenceTest.java (テストクラス)

このチュートリアルではEntityManagerを叩いているのはこのテストクラスだけです。本当はJPAを使ったEJBのテストをしたいところですが、とりあえずこれでやってみます

package org.arquillian.example;

import java.util.List;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.UserTransaction;
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.junit.Assert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class GamePersistenceTest {
    @Deployment
    public static Archive<?> createDeployment() {
        return ShrinkWrap.create(WebArchive.class, "test.war")
            .addPackage(Game.class.getPackage())
            .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsWebInfResource("jbossas-ds.xml");
    }

    private static final String[] GAME_TITLES = {
        "Super Mario Brothers",
        "Mario Kart",
        "F-Zero"
    };

    @PersistenceContext
    EntityManager em;

    @Inject
    UserTransaction utx;

    @Before
    public void preparePersistenceTest() throws Exception {
        clearData();
        insertData();
        startTransaction();
    }

    private void clearData() throws Exception {
        utx.begin();
        em.joinTransaction();
        System.out.println("Dumping old records...");
        em.createQuery("delete from Game").executeUpdate();
        utx.commit();
    }

    private void insertData() throws Exception {
        utx.begin();
        em.joinTransaction();
        System.out.println("Inserting records...");
        for (String title : GAME_TITLES) {
            Game game = new Game(title);
            em.persist(game);
        }
        utx.commit();
        // clear the persistence context (first-level cache)
        em.clear();
    }

    private void startTransaction() throws Exception {
        utx.begin();
        em.joinTransaction();
    }

    @After
    public void commitTransaction() throws Exception {
        utx.commit();
    }

    @Test
    public void shouldFindAllGamesUsingJpqlQuery() throws Exception {
        // given
        String fetchingAllGamesInJpql = "select g from Game g order by g.id";

        // when
        System.out.println("Selecting (using JPQL)...");
        List<Game> games = em.createQuery(fetchingAllGamesInJpql, Game.class).getResultList();

        // then
        System.out.println("Found " + games.size() + " games (using JPQL):");
        assertContainsAllGames(games);
    }

    private static void assertContainsAllGames(Collection<Game> retrievedGames) {
        Assert.assertEquals(GAME_TITLES.length, retrievedGames.size());
        final Set<String> retrievedGameTitles = new HashSet<String>();
        for (Game game : retrievedGames) {
            System.out.println("* " + game);
            retrievedGameTitles.add(game.getTitle());
        }
        Assert.assertTrue(retrievedGameTitles.containsAll(Arrays.asList(GAME_TITLES)));
    }
}

jbossas-ds.xml (データソース定義)

データソース定義をこのファイルに書いておけば、テスト実行する度に一時的にデータソース定義を行ってくれます。APサーバ側のコンソールをいじってデータソース定義をやる必要はありません。これは便利。

本当はPostgreSQLあたりを使ってリアルにレコードを確認したいところですが、簡単のためとりあえずチュートリアル通りに標準搭載のH2を使ってインメモリデータベースを使います

<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.jboss.org/ironjacamar/schema
        http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
    <datasource enabled="true"
        jndi-name="jdbc/arquillian"
        pool-name="ArquillianEmbeddedH2Pool">
        <connection-url>jdbc:h2:mem:arquillian;DB_CLOSE_DELAY=-1</connection-url>
        <driver>h2</driver>
    </datasource>
</datasources>

test-persistence.xml (永続化コンテキスト定義)

JTAトランザクションのJavaEEなJPAの定義ですね。JavaSEのと違ってエンティティクラス名の列挙は必要ありません。良い。

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="test">
        <jta-data-source>jdbc/arquillian</jta-data-source>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
            <property name="hibernate.show_sql" value="true"/>
        </properties>
    </persistence-unit>
</persistence>

テスト実行

  • 前回同様、右クリック→Run As→JUnit Test
  • Profileも前回同様JBossのremoteで

JUnit窓

ログ

16:22:40,034 INFO  [org.jboss.as.repository] (management-handler-thread - 17) JBAS014900: Content added at location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/48/93a135faeb37e43d3d9346ea59cc2bfc3c784c/content
16:22:40,040 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015876: Starting deployment of "arquillian-service"
16:22:40,100 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-5) 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.
16:22:40,101 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-5) 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.
16:22:40,101 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-5) 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.
16:22:40,102 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-5) 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.
16:22:40,102 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-5) 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.
16:22:40,123 INFO  [org.jboss.as.server] (management-handler-thread - 17) JBAS018559: Deployed "arquillian-service"
16:22:40,251 INFO  [org.jboss.as.repository] (management-handler-thread - 18) JBAS014900: Content added at location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/ed/a8915f6ceb2f30ae6c44b37a827c3c0064d992/content
16:22:40,253 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "test.war"
16:22:40,307 INFO  [org.jboss.as.jpa] (MSC service thread 1-2) JBAS011401: Read persistence.xml for test
16:22:40,350 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016002: Processing weld deployment test.war
16:22:40,387 INFO  [org.jboss.weld.deployer] (MSC service thread 1-15) JBAS016005: Starting Services for CDI deployment: test.war
16:22:40,401 INFO  [org.jboss.as.arquillian] (MSC service thread 1-9) Arquillian deployment detected: ArquillianConfig[service=jboss.arquillian.config."test.war",unit=test.war,tests=[org.arquillian.example.GreeterTest, org.arquillian.example.GamePersistenceTest]]
16:22:40,402 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source [jdbc/arquillian]
16:22:40,403 INFO  [org.jboss.as.jpa] (MSC service thread 1-2) JBAS011402: Starting Persistence Unit Service 'test.war#test'
16:22:40,498 INFO  [org.hibernate.annotations.common.Version] (MSC service thread 1-2) HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
16:22:40,503 INFO  [org.hibernate.Version] (MSC service thread 1-2) HHH000412: Hibernate Core {4.0.1.Final}
16:22:40,505 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-2) HHH000206: hibernate.properties not found
16:22:40,506 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-2) HHH000021: Bytecode provider name : javassist
16:22:40,525 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-2) HHH000204: Processing PersistenceUnitInfo [
    name: test
    ...]
16:22:40,648 INFO  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-2) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
16:22:40,830 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-2) HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
16:22:40,835 WARN  [org.hibernate.dialect.H2Dialect] (MSC service thread 1-2) HHH000431: Unable to determine H2 database version, certain features may not work
16:22:40,838 INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-2) HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
16:22:40,845 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-2) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
16:22:40,848 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-2) HHH000397: Using ASTQueryTranslatorFactory
16:22:40,875 INFO  [org.hibernate.validator.util.Version] (MSC service thread 1-2) Hibernate Validator 4.2.0.Final
16:22:41,079 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-2) HHH000227: Running hbm2ddl schema export
16:22:41,083 INFO  [stdout] (MSC service thread 1-2) Hibernate: drop table Game if exists
16:22:41,083 INFO  [stdout] (MSC service thread 1-2) Hibernate: drop sequence hibernate_sequence
16:22:41,090 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-2) HHH000389: Unsuccessful: drop sequence hibernate_sequence
16:22:41,090 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-2) シーケンス "HIBERNATE_SEQUENCE" が見つかりません
Sequence "HIBERNATE_SEQUENCE" not found; SQL statement:
drop sequence hibernate_sequence [90036-161]
16:22:41,090 INFO  [stdout] (MSC service thread 1-2) Hibernate: create table Game (id bigint not null, title varchar(50) not null, primary key (id))
16:22:41,091 INFO  [stdout] (MSC service thread 1-2) Hibernate: create sequence hibernate_sequence start with 1 increment by 1
16:22:41,093 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-2) HHH000230: Schema export complete
16:22:41,113 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016008: Starting weld service for deployment test.war
16:22:41,239 INFO  [org.jboss.web] (MSC service thread 1-6) JBAS018210: Registering web context: /test
16:22:41,248 INFO  [org.jboss.as.server] (management-handler-thread - 18) JBAS018559: Deployed "test.war"
16:22:41,407 INFO  [stdout] (pool-4-thread-4) Dumping old records...
16:22:41,501 INFO  [stdout] (pool-4-thread-4) Hibernate: delete from Game
16:22:41,515 INFO  [stdout] (pool-4-thread-4) Inserting records...
16:22:41,517 INFO  [stdout] (pool-4-thread-4) Hibernate: call next value for hibernate_sequence
16:22:41,549 INFO  [stdout] (pool-4-thread-4) Hibernate: call next value for hibernate_sequence
16:22:41,550 INFO  [stdout] (pool-4-thread-4) Hibernate: call next value for hibernate_sequence
16:22:41,566 INFO  [stdout] (pool-4-thread-4) Hibernate: insert into Game (title, id) values (?, ?)
16:22:41,568 INFO  [stdout] (pool-4-thread-4) Hibernate: insert into Game (title, id) values (?, ?)
16:22:41,569 INFO  [stdout] (pool-4-thread-4) Hibernate: insert into Game (title, id) values (?, ?)
16:22:41,573 INFO  [stdout] (pool-4-thread-4) Selecting (using JPQL)...
16:22:41,584 INFO  [stdout] (pool-4-thread-4) Hibernate: select game0_.id as id0_, game0_.title as title0_ from Game game0_ order by game0_.id
16:22:41,588 INFO  [stdout] (pool-4-thread-4) Found 3 games (using JPQL):
16:22:41,588 INFO  [stdout] (pool-4-thread-4) * Game@1954523691[id = 1; title = Super Mario Brothers]
16:22:41,589 INFO  [stdout] (pool-4-thread-4) * Game@402776278[id = 2; title = Mario Kart]
16:22:41,589 INFO  [stdout] (pool-4-thread-4) * Game@592449002[id = 3; title = F-Zero]
16:22:41,641 INFO  [org.jboss.weld.deployer] (MSC service thread 1-14) JBAS016009: Stopping weld service for deployment test.war
16:22:41,643 INFO  [org.jboss.as.jpa] (MSC service thread 1-14) JBAS011403: Stopping Persistence Unit Service 'test.war#test'
16:22:41,643 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-14) HHH000227: Running hbm2ddl schema export
16:22:41,644 INFO  [stdout] (MSC service thread 1-14) Hibernate: drop table Game if exists
16:22:41,647 INFO  [stdout] (MSC service thread 1-14) Hibernate: drop sequence hibernate_sequence
16:22:41,647 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-14) HHH000230: Schema export complete
16:22:41,648 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) JBAS010409: Unbound data source [jdbc/arquillian]
16:22:41,656 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) JBAS015877: Stopped deployment test.war in 40ms
16:22:41,664 INFO  [org.jboss.as.repository] (management-handler-thread - 20) JBAS014901: Content removed from location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/ed/a8915f6ceb2f30ae6c44b37a827c3c0064d992/content
16:22:41,665 INFO  [org.jboss.as.server] (management-handler-thread - 20) JBAS018558: Undeployed "test.war"
16:22:41,685 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-11) JBAS015877: Stopped deployment arquillian-service in 5ms
16:22:41,693 INFO  [org.jboss.as.repository] (management-handler-thread - 17) JBAS014901: Content removed from location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/48/93a135faeb37e43d3d9346ea59cc2bfc3c784c/content
16:22:41,693 INFO  [org.jboss.as.server] (management-handler-thread - 17) JBAS018558: Undeployed "arquillian-service"

備考

特に問題なさげですね。しかも速い。クラスの数も少なくアプリケーションアーカイブのサイズも小さいので当然かもしれませんが3〜4秒です。これならJPAのマニアックな機能を使った複雑な機能の実装とテストも怖くないですね。

というか本家のチュートリアル[1]がよくできてて日本語訳も読みやすいので読みましょう。

ちなみにチュートリアルにも書かれていますが埋め込みモードではJPAを使ったテストは動かないそうです。ただし埋め込みGlassFishは可。

続き

ArquillianをWildFly8.0.0.CR1で動かしてみる

参考文献

  1. Testing Java Persistence · Arquillian Guides


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 (日本語訳)


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


Posted on Saturday Jan 25, 2014 at 09:58AM in Technology


Arquillianチュートリアルの埋め込みGlassFish3でテストを走らせるところをやってみるの続きです。今回も本家のチュートリアル[1]なぞるだけです。JBoss AS7でテストを走らせます。

環境

  • 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.1.1をダウンロードして展開

[2]からJBoss AS7.1.1を取ってきます。私はjboss-as-7.1.1.Final.tar.gzというやつを取ってきました。チュートリアルにはMavenに取ってこさせる方法も紹介されていますがサイズもでかい(132MB)ので手で取ってきます。取ってきたら適当な場所に展開します。

arquillian.xmlを作る

ArquillianにJBoss AS7の場所を教えてやる必要が有り、チュートリアルにはJBOSS_HOME環境変数にセットするように書かれていますが、環境変数に定義したくないのでこうします。

あと私の環境だとコンソールの出力が文字化けしてしまうので文字化けを防ぐ設定も入れます

作る場所

内容

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://jboss.org/schema/arquillian
        http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
    <container qualifier="jbossas-managed" default="true">
        <configuration>
            <property name="jbossHome">/Users/kyle/apps/jboss-as-7.1.1.Final</property>
            <property name="javaVmArguments">-Dfile.encoding=UTF-8</property>
        </configuration>
    </container>
</arquillian>

Profileをarquillian-jbossas-managedに変更

プロジェクトを右クリック→Maven→Select Maven Profilesを選択、arquillian-jbossas-managedだけチェックされた状態にしてOK

OKを押すと右下の進捗バーが動き出すので終わるまで待ちます。GlassFishの時より時間かかる。

テスト実行

テストクラスを右クリック→Run As→JUnit Test

コンソール

JUnit窓

備考

以下が走るようです

  1. JBossの起動
  2. テスト資源のデプロイ
  3. テストコード実行
  4. テスト資源のアンデプロイ
  5. JBossの停止

全部で9秒強。それでも楽ですね。今回は起動停止までArquillianが面倒を見るmanagedというモードを試したのですが、すでに動いているJBossを使うremoteというモードもあるそうなので、それでやった方が実行時間は短く済むような気がします。またそのうちやってみる

ログ

2014/01/25 11:08:53 org.jboss.as.arquillian.container.managed.ManagedDeployableContainer startInternal
情報: Starting container with: [/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java, -Dfile.encoding=UTF-8, -ea, -Djboss.home.dir=/Users/kyle/apps/jboss-as-7.1.1.Final, -Dorg.jboss.boot.log.file=/Users/kyle/apps/jboss-as-7.1.1.Final/standalone/log/boot.log, -Dlogging.configuration=file:/Users/kyle/apps/jboss-as-7.1.1.Final/standalone/configuration/logging.properties, -Djboss.modules.dir=/Users/kyle/apps/jboss-as-7.1.1.Final/modules, -Djboss.bundles.dir=/Users/kyle/apps/jboss-as-7.1.1.Final/bundles, -jar, /Users/kyle/apps/jboss-as-7.1.1.Final/jboss-modules.jar, -mp, /Users/kyle/apps/jboss-as-7.1.1.Final/modules, -jaxpmodule, javax.xml.jaxp-provider, org.jboss.as.standalone, -server-config, standalone.xml]
2014/01/25 11:08:53 org.xnio.Xnio <clinit>
INFO: XNIO Version 3.0.0.GA
2014/01/25 11:08:53 org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.0.GA
2014/01/25 11:08:53 org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.3.GA
11:08:53,852 情報    [org.jboss.modules] JBoss Modules version 1.1.1.GA
11:08:54,196 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA
11:08:54,233 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
11:08:54,850 INFO  [org.xnio] XNIO Version 3.0.3.GA
11:08:54,851 INFO  [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
11:08:54,856 INFO  [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
11:08:54,862 INFO  [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
11:08:54,878 INFO  [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
11:08:54,880 INFO  [org.jboss.as.configadmin] (ServerService Thread Pool -- 26) JBAS016200: Activating ConfigAdmin Subsystem
11:08:54,884 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
11:08:54,890 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem
11:08:54,897 INFO  [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
11:08:54,902 INFO  [org.jboss.as.connector] (MSC service thread 1-13) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
11:08:54,910 INFO  [org.jboss.as.naming] (MSC service thread 1-10) JBAS011802: Starting Naming Service
11:08:54,914 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-9) JBAS015400: Bound mail session [java:jboss/mail/Default]
11:08:54,936 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem
11:08:54,939 INFO  [org.jboss.as.security] (MSC service thread 1-13) JBAS013100: Current PicketBox version=4.0.7.Final
11:08:54,954 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
11:08:54,955 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
11:08:55,029 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-8) Coyote HTTP/1.1を http--127.0.0.1-8080 で起動します
11:08:55,137 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-3) JBoss Web Services - Stack CXF Server 4.0.2.GA
11:08:55,212 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
11:08:55,326 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-7) JBAS015012: Started FileSystemDeploymentService for directory /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/deployments
11:08:55,345 INFO  [org.jboss.as.remoting] (MSC service thread 1-5) JBAS017100: Listening on /127.0.0.1:4447
11:08:55,345 INFO  [org.jboss.as.remoting] (MSC service thread 1-1) JBAS017100: Listening on /127.0.0.1:9999
11:08:55,398 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
11:08:55,399 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 1813ms - Started 133 of 208 services (74 services are passive or on-demand)
2014/01/25 11:09:00 org.jboss.as.arquillian.protocol.jmx.ArquillianServiceDeployer doServiceDeploy
INFO: Deploy arquillian service: arquillian-service: 1001 assets
11:09:00,655 INFO  [org.jboss.as.repository] (management-handler-thread - 2) JBAS014900: Content added at location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/fd/d2bc84b645ec6211439baf0f0ac0f5b5e6edaa/content
11:09:00,667 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-11) JBAS015876: Starting deployment of "arquillian-service"
11:09:00,876 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-8) 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.
11:09:00,876 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-8) 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.
11:09:00,877 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-8) 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.
11:09:00,878 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-8) 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.
11:09:00,878 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-8) 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.
11:09:00,950 INFO  [org.jboss.as.server] (management-handler-thread - 2) JBAS018559: Deployed "arquillian-service"
11:09:01,234 INFO  [org.jboss.as.repository] (management-handler-thread - 3) JBAS014900: Content added at location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/df/66c1c9dd842d5f94bc469ed4deb8309334ed1a/content
11:09:01,238 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) JBAS015876: Starting deployment of "a65375aa-bafb-4037-82ff-1ac105d8bace.jar"
11:09:01,257 INFO  [org.jboss.weld.deployer] (MSC service thread 1-9) JBAS016002: Processing weld deployment a65375aa-bafb-4037-82ff-1ac105d8bace.jar
11:09:01,267 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016005: Starting Services for CDI deployment: a65375aa-bafb-4037-82ff-1ac105d8bace.jar
11:09:01,313 INFO  [org.jboss.weld.Version] (MSC service thread 1-1) WELD-000900 1.1.5 (AS71)
11:09:01,324 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) JBAS016008: Starting weld service for deployment a65375aa-bafb-4037-82ff-1ac105d8bace.jar
11:09:01,325 INFO  [org.jboss.as.arquillian] (MSC service thread 1-11) Arquillian deployment detected: ArquillianConfig[service=jboss.arquillian.config."a65375aa-bafb-4037-82ff-1ac105d8bace.jar",unit=a65375aa-bafb-4037-82ff-1ac105d8bace.jar,tests=[org.arquillian.example.GreeterTest]]
11:09:01,544 INFO  [org.jboss.as.server] (management-handler-thread - 3) JBAS018559: Deployed "a65375aa-bafb-4037-82ff-1ac105d8bace.jar"
11:09:01,728 INFO  [stdout] (pool-4-thread-1) Hello, Earthling!
11:09:01,769 INFO  [org.jboss.weld.deployer] (MSC service thread 1-10) JBAS016009: Stopping weld service for deployment a65375aa-bafb-4037-82ff-1ac105d8bace.jar
11:09:01,779 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015877: Stopped deployment a65375aa-bafb-4037-82ff-1ac105d8bace.jar in 13ms
11:09:01,790 INFO  [org.jboss.as.repository] (management-handler-thread - 1) JBAS014901: Content removed from location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/df/66c1c9dd842d5f94bc469ed4deb8309334ed1a/content
11:09:01,791 INFO  [org.jboss.as.server] (management-handler-thread - 1) JBAS018558: Undeployed "a65375aa-bafb-4037-82ff-1ac105d8bace.jar"
2014/01/25 11:09:01 org.jboss.as.arquillian.protocol.jmx.ArquillianServiceDeployer undeploy
INFO: Undeploy arquillian service: arquillian-service: 1002 assets
11:09:01,805 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) JBAS015877: Stopped deployment arquillian-service in 4ms
11:09:01,814 INFO  [org.jboss.as.repository] (management-handler-thread - 2) JBAS014901: Content removed from location /Users/kyle/apps/jboss-as-7.1.1.Final/standalone/data/content/fd/d2bc84b645ec6211439baf0f0ac0f5b5e6edaa/content
11:09:01,815 INFO  [org.jboss.as.server] (management-handler-thread - 2) JBAS018558: Undeployed "arquillian-service"

続き

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

参考文献

  1. Getting Started · Arquillian Guides (日本語訳)
  2. JBoss Application Server Downloads - JBoss Community
  3. External properties in arquillian.xml | Community


Arquillianチュートリアルの埋め込みGlassFish3でテストを走らせるところをやってみる


Posted on Saturday Jan 25, 2014 at 07:42AM in Technology


Test - Arquillianチュートリアルを埋め込みWeldでテスト走らせるところまでやってみるの続きです。今回はチュートリアル[1]の残りのProfileを定義して埋め込みGlassFish3でテストを走らせるところをやってみます。今回もチュートリアルなぞるだけです。ProfileはJBoss AS7のも定義しますが、長くなるので走らせるのは別の項で。

チュートリアルはわかりやすく詳細な解説付きで、pom.xmlの編集等も手を動かしながら学べるので読んだ方がいいです。日本語訳[1]も機械的でなく分かりやすいので普通にこの記事よりもそっちを読んだ方がいいかも。JBoss Forgeを使ったやり方なども紹介されています。

環境

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

準備

pom.xmlの編集

  • 前回使った埋め込みWeld用の定義を新しいProfileに移動
  • 埋め込みGlassFish3のProfileを定義
  • JBoss AS7のProfileを定義

Profileに定義すると簡単にテストの実行環境を切り替えることができるようになるようです。結果こうなる

<?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 -->
    </profiles>
    <!-- clip -->
</project>

保存するとき自動ビルドを有効にしているとビルドエラーになりますがこれでOKです。

埋め込みWeldでテスト

Profileを選択

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

  2. arquillian-weld-ee-embeddedにチェックを入れてOK

  3. 右下の進捗バーが動き出します。暫し眺めているとビルドエラーが消えます

テスト実行

JUnit窓も緑色なので大丈夫そうですね

埋め込みGlassFish3でテスト

Profileを選択

  1. arquillian-weld-ee-embeddedのチェックを外してarquillian-glassfish-embeddedにチェックを入れOK

  2. 進捗バーを眺める。1分ぐらいかかります

  3. 埋め込みGlassFishのjarがMaven Dependenciesに追加されます。7MBある。

テスト実行

前回同様テストクラスの窓で右クリック→Run As→JUnit Test

  • コンソール

  • JUnit窓

コンソールを眺めているとちゃんとGlassFishが走っていることがわかります。実行時間は5秒ぐらい。埋め込みWeldがPOJOの単体テスト並だったのを考えると若干遅いです。

一応ログも貼っておく。Webコンテナもリスナもきちんと立ち上がっているのは興味深い。

2014/01/25 9:49:51 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
情報: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
2014/01/25 9:49:51 org.hibernate.validator.util.Version <clinit>
情報: Hibernate Validator 4.2.0.Final
2014/01/25 9:49:52 com.sun.enterprise.security.ssl.impl.SecuritySupportImpl checkCertificateDates
致命的: SEC5054: Certificate has expired: [
[
  Version: V3
  Subject: CN=GTE CyberTrust Root 5, OU="GTE CyberTrust Solutions, Inc.", O=GTE Corporation, C=US
  Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5

  Key:  Sun RSA public key, 2048 bits
  modulus: 23741889829347261660812437366387754385443431973861114865490414153884050331745811968523116847625570146592736935209718565296053386842135985534863157983128812774162998053673746470782252407673402238146869994438729551246768368782318393878374421033907597162218758024581735139682087126982809511479059100617027892880227587855877479432885604404402435662802390484099065871430585284534529627347717530352189612077130606642676951640071336717026459037542552927905851171460589361570392199748753414855675665635003335769915908187224347232807336022456537328962095005323382940080676931822787496212635993279098588863972868266229522169377
  public exponent: 65537
  Validity: [From: Fri Aug 14 23:50:00 JST 1998,
               To: Thu Aug 15 08:59:00 JST 2013]
  Issuer: CN=GTE CyberTrust Root 5, OU="GTE CyberTrust Solutions, Inc.", O=GTE Corporation, C=US
  SerialNumber: [    01b6]

Certificate Extensions: 4
[1]: ObjectId: 2.5.29.19 Criticality=true
BasicConstraints:[
  CA:true
  PathLen:5
]

[2]: ObjectId: 2.5.29.32 Criticality=false
CertificatePolicies [
  [CertificatePolicyId: [1.2.840.113763.1.2.1.3]
[]  ]
]

[3]: ObjectId: 2.5.29.15 Criticality=true
KeyUsage [
  Key_CertSign
  Crl_Sign
]

[4]: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 76 0A 49 21 38 4C 9F DE   F8 C4 49 C7 71 71 91 9D  v.I!8L....I.qq..
]
]

]
  Algorithm: [SHA1withRSA]
  Signature:
0000: 41 3A D4 18 5B DA B8 DE   21 1C E1 8E 09 E5 F1 68  A:..[...!......h
0010: 34 FF DE 96 F4 07 F5 A7   3C F3 AC 4A B1 9B FA 92  4.......<..J....
0020: FA 9B ED E6 32 21 AA 4A   76 C5 DC 4F 38 E5 DF D5  ....2!.Jv..O8...
0030: 86 E4 D5 C8 76 7D 98 D7   B1 CD 8F 4D B5 91 23 6C  ....v......M..#l
0040: 8B 8A EB EA 7C EF 14 94   C4 C6 F0 1F 4A 2D 32 71  ............J-2q
0050: 63 2B 63 91 26 02 09 B6   80 1D ED E2 CC B8 7F DB  c+c.&...........
0060: 87 63 C8 E1 D0 6C 26 B1   35 1D 40 66 10 1B CD 95  .c...l&.5.@f....
0070: 54 18 33 61 EC 13 4F DA   13 F7 99 AF 3E D0 CF 8E  T.3a..O.....>...
0080: A6 72 A2 B3 C3 05 9A C9   27 7D 92 CC 7E 52 8D B3  .r......'....R..
0090: AB 70 6D 9E 89 9F 4D EB   1A 75 C2 98 AA D5 02 16  .pm...M..u......
00A0: D7 0C 8A BF 25 E4 EB 2D   BC 98 E9 58 38 19 7C B9  ....%..-...X8...
00B0: 37 FE DB E2 99 08 73 06   C7 97 83 6A 7D 10 01 2F  7.....s....j.../
00C0: 32 B9 17 05 4A 65 E6 2F   CE BE 5E 53 A6 82 E9 9A  2...Je./..^S....
00D0: 53 0A 84 74 2D 83 CA C8   94 16 76 5F 94 61 28 F0  S..t-.....v_.a(.
00E0: 85 A7 39 BB D7 8B D9 A8   B2 13 1D 54 09 34 24 7D  ..9........T.4$.
00F0: 20 81 7D 66 7E A2 90 74   5C 10 C6 BD EC AB 1B C2   ..f...t\.......

]
2014/01/25 9:49:52 com.sun.enterprise.v3.services.impl.GrizzlyService createNetworkProxy
情報: Network listener https-listener on port 0 disabled per domain.xml
2014/01/25 9:49:52 com.sun.enterprise.v3.services.impl.GrizzlyProxy$2$1 onReady
情報: Grizzly Framework 1.9.46 started in: 41ms - bound to [0.0.0.0:8181]
2014/01/25 9:49:52 com.sun.enterprise.v3.server.AppServerStartup run
情報: GlassFish Server Open Source Edition 3.1.2 (java_re-private) startup time : Embedded (609ms), startup services(630ms), total(1,239ms)
2014/01/25 9:49:52 org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run
情報: JMX006: JMXStartupService had disabled JMXConnector system
2014/01/25 9:49:53 com.sun.enterprise.security.SecurityLifecycle <init>
情報: SEC1002: Security Manager is OFF.
2014/01/25 9:49:53 com.sun.enterprise.security.SecurityLifecycle onInitialization
情報: SEC1010: Entering Security Startup Service
2014/01/25 9:49:53 com.sun.enterprise.security.PolicyLoader loadPolicy
情報: SEC1143: Loading policy provider com.sun.enterprise.security.jacc.provider.SimplePolicyProvider.
2014/01/25 9:49:53 com.sun.enterprise.security.auth.realm.Realm doInstantiate
情報: SEC1115: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
2014/01/25 9:49:53 com.sun.enterprise.security.auth.realm.Realm doInstantiate
情報: SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
2014/01/25 9:49:53 com.sun.enterprise.security.auth.realm.Realm doInstantiate
情報: SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.
2014/01/25 9:49:53 com.sun.enterprise.security.SecurityLifecycle onInitialization
情報: SEC1011: Security Service(s) Started Successfully
2014/01/25 9:49:53 com.sun.enterprise.web.WebContainer createHttpListener
情報: WEB0169: Created HTTP listener [http-listener] on host/port [0.0.0.0:8181]
2014/01/25 9:49:53 com.sun.enterprise.web.WebContainer createHosts
情報: WEB0171: Created virtual server [server]
2014/01/25 9:49:53 com.sun.enterprise.web.WebContainer loadSystemDefaultWebModules
情報: WEB0172: Virtual server [server] loaded default web module []
classLoader = WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)
SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@711dc088
2014/01/25 9:49:54 org.jboss.weld.bootstrap.WeldBootstrap <clinit>
情報: WELD-000900 SNAPSHOT
2014/01/25 9:49:54 com.sun.enterprise.web.WebApplication start
情報: WEB0671: Loading application [test] at [/test]
2014/01/25 9:49:55 org.glassfish.deployment.admin.DeployCommand execute
情報: test was successfully deployed in 1,930 milliseconds.
Hello, Earthling!
classLoader = WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)
SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@711dc088
PlainTextActionReporterSUCCESSNo monitoring data to report.
2014/01/25 9:49:56 org.glassfish.admin.mbeanserver.JMXStartupService shutdown
情報: JMX001: JMXStartupService and JMXConnectors have been shut down.
2014/01/25 9:49:56 com.sun.enterprise.v3.server.AppServerStartup stop
情報: Shutdown procedure finished
2014/01/25 9:49:56 AppServerStartup run
情報: [Thread[GlassFish Kernel Main Thread,5,main]] exiting

続き

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

参考文献

  1. Getting Started · Arquillian Guides (日本語訳)