ArquillianチュートリアルのJPAを使ったテストを走らせるところをやってみる
TweetPosted 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で動かしてみる
参考文献
Tags: test
Arquillianチュートリアルのリモートコンテナでテストを走らせるところをやってみる
TweetPosted 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に登録して起動しておきます
Server窓で右クリック→New→Server
JBoss Communityの中のJBoss AS 7.1を選んでNext
JBossを展開したディレクトリを入力しJavaSE1.6のJREを選んでFinish
登録された事を確認
JBoss 7.1 Runtime Serverを右クリックしてStartを選択
コンソールを見て起動する事を確認
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を変更
プロジェクトを右クリック→Maven→Select Maven Profilesを選択
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を使ったテストを走らせるところをやってみる
参考文献
Tags: test
ArquillianチュートリアルのJBoss AS7でテストを走らせるところをやってみる
TweetPosted 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窓
備考
以下が走るようです
- JBossの起動
- テスト資源のデプロイ
- テストコード実行
- テスト資源のアンデプロイ
- 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チュートリアルのリモートコンテナでテストを走らせるところをやってみる
参考文献
Tags: test
Arquillianチュートリアルの埋め込みGlassFish3でテストを走らせるところをやってみる
TweetPosted 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を選択
プロジェクトを右クリック→Maven→Select Maven Profilesを選択
arquillian-weld-ee-embeddedにチェックを入れてOK
右下の進捗バーが動き出します。暫し眺めているとビルドエラーが消えます
テスト実行
JUnit窓も緑色なので大丈夫そうですね
埋め込みGlassFish3でテスト
Profileを選択
arquillian-weld-ee-embeddedのチェックを外してarquillian-glassfish-embeddedにチェックを入れOK
進捗バーを眺める。1分ぐらいかかります
埋め込み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でテストを走らせるところをやってみる
参考文献
Tags: test
PNotifyで遊ぶ
TweetPosted on Friday Jan 24, 2014 at 05:28PM in Technology
Macの通知ウインドウ的な表示が出来るPNotifyを使ってみます
環境
- pnotify-1.2.2.zip
- Firefox 26.0
- OS X 10.9.1
準備
とりあえず[1]からzipファイルを落としてきます。他の依存ライブラリはCDNのを使います
ファイルの置き方
ローカルに置くのはこんなものです。css2つと、jsファイルはzipファイルに入ってます
pnotify.html
<!DOCTYPE HTML> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/jquery-ui.min.js"></script> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/redmond/jquery-ui.css"> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/i18n/jquery-ui-i18n.min.js"></script> <script type="text/javascript" src="jquery.pnotify.js"></script> <link href="jquery.pnotify.default.css" media="all" rel="stylesheet" type="text/css" /> <link href="jquery.pnotify.default.icons.css" media="all" rel="stylesheet" type="text/css" /> <meta charset="utf-8"> <title></title> </head> <body> <script type="text/javascript"> $.pnotify.defaults.styling = "jqueryui"; $(function(){ $.pnotify({ title: 'Regular Notice', text: 'Check me out! I\'m a notice.' }); }); </script> </body> </html>
動かしてみる
全くカスタマイズもしてませんが一応出ました。結構長い間出っぱです。
ポインタを窓の上に持っていくとボタンが出ます
右上に出ている水色の物体にポインタを持っていくと過去表示した通知を再表示できたりするようです。字がはみ出てるのがちょっと嫌な感じ。
イベントに連動させてみる
ベタですがボタン押したら出るようにしてみましょう
pnotify.html
<!DOCTYPE HTML> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/jquery-ui.min.js"></script> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/redmond/jquery-ui.css"> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/i18n/jquery-ui-i18n.min.js"></script> <script type="text/javascript" src="jquery.pnotify.js"></script> <link href="jquery.pnotify.default.css" media="all" rel="stylesheet" type="text/css" /> <link href="jquery.pnotify.default.icons.css" media="all" rel="stylesheet" type="text/css" /> <meta charset="utf-8"> <title></title> </head> <body> <script type="text/javascript"> $.pnotify.defaults.styling = "jqueryui"; function pnotifyShow(){ $(function(){ $.pnotify({ title: 'Regular Notice', text: 'Check me out! I\'m a notice.' }); }); } </script> </body> <button id="btn" onclick="pnotifyShow()">pnotify</button> </html>
動かしてみる
ボタン押します
表示されます
まあ普通ですね。
カスタマイズしてみる
表示される時間を変えてみる
これで1秒になります
$.pnotify.defaults.delay = 1000;
全体はこうなる
<!DOCTYPE HTML> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/jquery-ui.min.js"></script> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/redmond/jquery-ui.css"> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/i18n/jquery-ui-i18n.min.js"></script> <script type="text/javascript" src="jquery.pnotify.js"></script> <link href="jquery.pnotify.default.css" media="all" rel="stylesheet" type="text/css" /> <link href="jquery.pnotify.default.icons.css" media="all" rel="stylesheet" type="text/css" /> <meta charset="utf-8"> <title></title> </head> <body> <script type="text/javascript"> $.pnotify.defaults.styling = "jqueryui"; $.pnotify.defaults.delay = 1000; function pnotifyShow(){ $(function(){ $.pnotify({ title: 'Regular Notice', text: 'Check me out! I\'m a notice.' }); }); } </script> </body> <button id="btn" onclick="pnotifyShow()">pnotify</button> </html>
その他
背景色の変え方がよくわからない…。CSSのセレクタが不明なんだがうまく調べる方法ないかなあ。jQuery UI側の設定を変えないといけないんだろうか。[1]のページ下部にはものすごい量のサンプルがあるのでそのうちまた調べてみる
参考文献
Tags: web