NativeQueryでSELECTしてみる
TweetPosted on Saturday Jan 25, 2014 at 11:37PM in Technology
ここではNativeQueryを使うまでもない簡単な単独のエンティティをSELECTしてみます。複雑なのは後々。
環境
- Hibernate 4.3.0.Final
- WildFly8.0.0.CR1
- Oracle JDK7u51
- postgresql-9.3-1100.jdbc41.jar
- PostgreSQL 9.2.4
前提条件
- Arquillian Persistence ExtensionとJavaEE7を使います
- プロジェクトを作ったりする作業はJavaEE7プロジェクトでArquillianを使ってみるあたりを参照
- WildFlyへのJDBCドライバ配備方法等はWildFly - CLIでデータソースを定義するあたりを参照
関連を持たない単独のエンティティをSELECTしてみる
エンティティクラス等を配置
配置図
図で選択されている資源を作る必要が有ります
Employee.java
package org.arquillian.example; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity public class Employee implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column private String firstName; @Column private String lastName; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } @Override public String toString() { return "Employee [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + "]"; } }
orm.xml
<?xml version="1.0" encoding="UTF-8"?> <entity-mappings version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd"> <named-native-query name="findEmployee" result-set-mapping="employeeResult"> <query><![CDATA[ SELECT emp.id, emp.firstName, emp.lastName FROM Employee AS emp ]]></query> </named-native-query> <sql-result-set-mapping name="employeeResult"> <entity-result entity-class="org.arquillian.example.Employee"/> </sql-result-set-mapping> </entity-mappings>
IndependentSelectTest.java
package org.arquillian.example; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.transaction.Transactional; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.persistence.UsingDataSet; 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.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class IndependentSelectTest { @Deployment public static Archive<?> createDeployment() { Archive<?> a = ShrinkWrap.create(WebArchive.class, "test.war") .addPackage(Employee.class.getPackage()) .addAsResource("test-persistence.xml", "META-INF/persistence.xml") .addAsResource("META-INF/orm.xml", "META-INF/orm.xml") .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") .addAsWebInfResource("jbossas-ds.xml"); return a; } @PersistenceContext EntityManager em; @Test @Transactional @UsingDataSet("datasets/independentSelect/employees.yml") public void select() throws Exception { dumpEntityList(em.createNamedQuery("findEmployee", Employee.class).getResultList()); } protected void dumpEntityList(List<?> list){ for(Object o : list){ System.out.println(o + ", contains=" + em.contains(o)); } } }
employees.yml
employee: - id: -1 firstname: Taro lastname: Yamada - id: -2 firstname: Jiro lastname: Suzuki - id: -3 firstname: Saburo lastname: Tanaka
jbossas-ds.xml
ローカルで動いているPostgreSQLにjpapracというDBを作っておきます
<?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="ArquillianPostgresPool"> <connection-url>jdbc:postgresql://localhost:5432/jpaprac</connection-url> <driver>postgresql-9.3-1100.jdbc41.jar</driver> <security> <user-name>postgres</user-name> <password>***</password> </security> </datasource> </datasources>
test-persistence.xml
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="test"> <jta-data-source>jdbc/arquillian</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="update" /> <property name="hibernate.show_sql" value="true" /> </properties> </persistence-unit> </persistence>
実行結果
コンソールの出力を関係ありそうなところだけ抜粋
10:23:35,245 INFO [stdout] (pool-2-thread-12) Hibernate: SELECT emp.id, emp.firstName, emp.lastName FROM Employee AS emp 10:23:35,248 INFO [stdout] (pool-2-thread-12) Employee [id=-1, firstName=Taro, lastName=Yamada], contains=true 10:23:35,248 INFO [stdout] (pool-2-thread-12) Employee [id=-2, firstName=Jiro, lastName=Suzuki], contains=true 10:23:35,248 INFO [stdout] (pool-2-thread-12) Employee [id=-3, firstName=Saburo, lastName=Tanaka], contains=true
普通に出てますね。NamedNativeQueryにしてResultSetMappingまで定義するとManagedになる。
備考
@UsingDataSetアノテーションをテストメソッドに付けると、Arquillian Persistence Extensionがデータ投入してくれますが、投入したデータはテスト後にTRUNCATEされてしまうので、テスト後にテーブルで確認しようとしても見えないようです[3]。これを抑制する設定は現状存在しないらしい。まあデバッガか何かで止めれば見られるだろうけど。
arquillian.xmlにこういう内容を書けばTRUNCATEがテスト実行前に走るようになるので、テスト実行後のデータを簡単に確認できます
<?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"> <extension qualifier="persistence"> <property name="defaultCleanupPhase">BEFORE</property> </extension> </arquillian>
HibernateのSQLログは、persistence.xmlのproperties要素内に以下のようなのを追記すると複数行使って見やすくインデントとかしてくれる
<property name="hibernate.format_sql" value="true"/>
続き
NativeQueryで関連持ちエンティティをSELECTしてみる
参考文献
Tags: jpa
ArquillianのテストをリモートのWildFly内でデバッグしてみる
TweetPosted on Saturday Jan 25, 2014 at 10:37PM in Technology
ArquillianをWildFly8.0.0.CR1で動かしてみるの続きです。テストクラスのデバッグをしてみます
ArquillianのRemoteでも普通のクラス同様にデバッグできます[1]。今回のようなケースではEdit Source Lookup Pathをやらないといけないのでその手順を残しておきます
環境
- wildfly-arquillian-container-remote 8.0.0.CR1
- Arquillian 1.1.2.Final
- WildFly 8.0.0.CR1
- Eclipse Kepler SR1
- Oracle JDK7u51
前提条件
- NativeQueryでSELECTしてみるで使った資源と環境を流用します
やってみる
資源は前述の前提条件の記事で書いたのと全く同じ状態で、テストクラスの39行目にブレークポイントを設定します
WildFlyをDebugで起動します
右クリック→Run As→JUnit Test。基本的にはこの手順で普通にブレークポイントで止まってデバッグ出来るはず。この手順より後はソースがデバッガに認識されない場合の設定手順です
OK。コンパイラオプションどうのこうの言ってるけど、これONになってても出るし
Yes
Debugパースペクティブに切り替わる。Source not foundと出たら、画面中ほどのEdit Source Lookup Pathをクリック
Addをクリック
Workspace Folderを選択してOK
作業中のプロジェクトのsrc/test/javaを選択してOK
追加されたのを確認してOK
ソースと止まってるところが表示されるのを確認
いったんResume(F8)でデバッガを終わらせる
この作業をしている間にデバッガが勝手に終了していたら、投入されたまま放ったらかされているテストデータの掃除などをしておく
3の手順で再度テストを実行
参考文献
Tags: test
JavaEE7プロジェクトでArquillianを使ってみる
TweetPosted on Saturday Jan 25, 2014 at 09:23PM in Technology
チュートリアルはJavaEE6ベースで書かれていたが、実際にはJavaEE7で作業したいのでJavaEE7で環境を作る方法
本当はArchetypeを作りたいのだが、まだMavenもEclipseも良くわかっていないのでまた後日
環境
- WildFly8.0.0.CR1
- Oracle JDK7u51
手順
- WildFly8.0.0CR1でサーブレットを動かしてみるの要領でjavaee7-essentials-archetypeでプロジェクトを作る
- java build pathを開き、test用のフォルダが欠けていたりする(test/resourcesとtest/java)のでそれらを作ってRefresh。test用のフォルダはOutput folderをtarget/test-classesに変更する。resourcesフォルダを作ったらExcludedを「**」にする
- プロジェクトの設定のdeployment assemblyを開いてテスト用の資源がデプロイされないようにする。test/resourcesがあれば削除
- java build pathのorder and exportで並び順を変更
- pom.xmlを編集する
pom.xml
こういう感じに改変してやれば良さげ。Arquillian Persistenceも入れておく
<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>com.example</groupId> <artifactId>arquillian-javaee7</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <failOnMissingWebXml>false</failOnMissingWebXml> </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.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.12</version> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.9.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> <dependency> <groupId>org.wildfly</groupId> <artifactId>wildfly-arquillian-container-remote</artifactId> <version>8.0.0.CR1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-persistence-impl</artifactId> <version>1.0.0.Alpha6</version> <scope>test</scope> </dependency> </dependencies> </project>
こういう感じのテストが走るようになる
[1]にあったサンプルを少し改変したもの。test-persistence.xmlやjbossas-ds.xmlはArquillianチュートリアルのJPAを使ったテストを走らせるところをやってみるのと同じ。
package org.arquillian.example; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.persistence.ShouldMatchDataSet; import org.jboss.arquillian.persistence.UsingDataSet; 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.Assert; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class UserPersistenceTest { @Deployment public static Archive<?> createDeploymentPackage() { return ShrinkWrap.create(WebArchive.class, "test.war") .addPackage(UserAccount.class.getPackage()) .addAsResource("test-persistence.xml", "META-INF/persistence.xml") .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") .addAsWebInfResource("jbossas-ds.xml"); } @PersistenceContext EntityManager em; @Test @UsingDataSet("datasets/users.yml") @ShouldMatchDataSet("datasets/expected-users.yml") public void should_change_user_password() throws Exception { // given String expectedPassword = "LexLuthor"; UserAccount user = em.find(UserAccount.class, 2L); // when user.setPassword("LexLuthor"); user = em.merge(user); // then Assert.assertEquals(expectedPassword, user.getPassword()); } }
テストを走らせると、log4jの設定が無い、slf4jの実装が無い、と怒られるのでそれは適宜対応。
参考文献
Tags: test
jboss-cliからいろいろ設定したりしてみる
TweetPosted on Saturday Jan 25, 2014 at 08:01PM in Technology
jboss-cliを使っていろいろ設定する方法のメモです
環境
- WildFly 8.0.0.CR1
ロガー
ここに書きました: ロガーを設定してみる
データソース
ここに書きました: CLIでデータソースを定義する
データソースの一覧を見る
ls /subsystem=datasources/data-source
JNDI
ここにも書きました: ProjectStageをJNDIで設定する
一覧表示
ls /subsystem=naming/binding
java:/env/jsf/ProjectStage=Developmentを設定する
/subsystem=naming/binding=java\:\/env\/jsf\/ProjectStage/:add(binding-type=simple,value=Development,class=java.lang.String)
java:/env/jsf/ProjectStageの設定内容を確認する
ls /subsystem=naming/binding=java\:\/env\/jsf\/ProjectStage
java:/env/jsf/ProjectStageの値をUnitTestに変更する
/subsystem=naming/binding=java\:\/env\/jsf\/ProjectStage/:write-attribute(name=value,value=UnitTest)
システムプロパティ
一覧表示
ls /system-property
file.encoding=UTF-8を設定する
/system-property=file.encoding:add(value=UTF-8)
file.encodingの設定内容を確認する
/system-property=file.encoding:read-resource
file.encodingを削除する
/system-property=file.encoding:remove
参考文献
Tags: wildfly
ArquillianをWildFly8.0.0.CR1で動かしてみる
TweetPosted 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を変更します。
プロジェクトの設定→Java Build Path→Librariesを開く
JRE System Library [JavaSE-1.6] を選択してEditを選択
ラジオボタンをAlternate JREに合わせてドロップダウンリストからJava SE 7を選択してOK
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)
参考文献
- Arquillian WildFly 8 Remote Container Adapter · Arquillian
- 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
Tags: test