Kohei Nozaki's blog 

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


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


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

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

環境

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

準備

pom.xmlの編集

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

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

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

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

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

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

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

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

    </dependencies>

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

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

埋め込みWeldでテスト

Profileを選択

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

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

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

テスト実行

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

埋め込みGlassFish3でテスト

Profileを選択

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

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

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

テスト実行

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

  • コンソール

  • JUnit窓

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

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

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

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

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

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

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

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

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

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

続き

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

参考文献

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



No one has commented yet.

Leave a Comment

HTML Syntax: NOT allowed