【问题标题】:Integration tests with maven2 fail-safe & embedded-glassfish使用 maven2 故障安全和嵌入式 glassfish 进行集成测试
【发布时间】:2012-08-13 09:36:32
【问题描述】:

我创建了一个新项目,它将只运行集成测试

  • maven-ear-plugin
  • maven-failsafe-plugin
  • maven-embedded-glassfish-plugin

当我将包装设置为 ear 时,ear 文件被创建,glassfish 运行但测试被忽略,我收到以下消息

[failsafe:integration-test] 没有要运行的测试。

glassfish 取消部署失败

[嵌入式玻璃鱼:取消部署]
17/08/2012 10:08:17 AM PluginUtil doUndeploy
信息:部署者 = com.sun.enterprise.admin.cli.embeddable.DeployerImpl@105f0f87
17/08/2012 10:08:17 AM com.sun.enterprise.loader.ASURLClassLoader$SentinelInputStream
报告
警告:输入流已被最终确定或强制关闭,而未明确
关闭;在以下堆栈跟踪中报告了流实例化
java.lang.Throwable
在 com.sun.enterprise.loader.ASURLClassLoader$SentinelInputStream.
(ASURLClassLoader.java:1230)

当我将包装设置为 jar 我明白了

运行 packageName.MyServiceTest
2012 年 8 月 17 日上午 10:09:34 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl
findDerbyClient
信息:找不到 javadb 客户端 jar 文件,默认情况下,derby jdbc 驱动程序将不可用。
org.omg.CORBA.COMM_FAILURE:FINE:IOP00410001:连接失败:socketType:
IIOP_CLEAR_TEXT;主机名:本地主机;端口:3700 vmcid:OMG 次要代码:1
已完成:否
在 sun.reflect.GeneratedConstructorAccessor27.newInstance(Unknown Source)

glassfish 没有启动

我知道它与 Maven 生命周期有关,它不允许我创建 ear 文件、启动 glassfish 嵌入式服务器并在同一个项目中运行集成测试。

有人可以建议我一个解决方案吗?我正在尝试仅使用 EJB 和业务实体项目创建 ear 文件,并将其部署到嵌入式 glassfish 服务器以使用 maven-failsafe-plugin 运行集成测试,而不是部署由父 pom.xml 创建的ear 文件添加UI等项目放入ear文件。

这是我的 pom.xml 文件

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<parent>
    <groupId>company.MyProject</groupId>
    <artifactId>MyProject</artifactId>
    <version>3.8.1-SNAPSHOT</version>
</parent>

<artifactId>MyProject-integration-test</artifactId>
<packaging>jar</packaging>

<name>MyProject Integration Tests</name>

<properties>
    <ear-final-name>MyProject-integration-test-${project.version}</ear-final-name>
</properties>

<dependencies>
    <dependency>
        <groupId>org.glassfish.extras</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>3.1.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.concordion</groupId>
        <artifactId>concordion</artifactId>
        <version>1.4.2</version>
        <scope>test</scope>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.concordion</groupId>
        <artifactId>concordion-extensions</artifactId>
        <version>1.0.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>MyProject-ejb</artifactId>
        <version>${project.version}</version>
        <type>ejb</type>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-words-jdk15</artifactId>
        <version>${aspose.libraryVersion}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>hibernate-entitymanager</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.2.GA</version>
    </dependency>
    <dependency>
        <groupId>hibernate-annotations</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
    <dependency>
        <groupId>hibernate-commons-annotations</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>10.1.0.5.0</version>
    </dependency>
    <dependency>
        <groupId>ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <version>1.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.6</version>
    </dependency>
    <dependency>
        <groupId>org-apache-commons-logging</groupId>
        <artifactId>org-apache-commons-logging</artifactId>
        <version>1.1.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <version>5</version>
                <displayName>MyProject</displayName>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <finalName>${ear-final-name}</finalName>
                <name>MyProject-integration-test</name>
                <modules>
                    <ejbModule>
                        <groupId>company.MyProject</groupId>
                        <artifactId>MyProject-ejb</artifactId>
                        <bundleFileName>MyProject-ejb.jar</bundleFileName>
                    </ejbModule>
                    <jarModule>
                        <groupId>company.MyProject</groupId>
                        <artifactId>MyProject-business-entities</artifactId>
                        <bundleFileName>MyProject-business-entities-3.8.1-SNAPSHOT.jar</bundleFileName>
                    </jarModule>
                    <jarModule>
                        <groupId>company.MyProject</groupId>
                        <artifactId>MyProject-util</artifactId>
                        <bundleFileName>MyProject-util-3.8.1-SNAPSHOT.jar</bundleFileName>
                    </jarModule>
                </modules>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.12</version>
            <executions>
                <execution>
                    <id>failsafe-integration-tests</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>integration-test</goal>
                    </goals>
                </execution>
                <execution>
                    <id>failsafe-verify</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>4.8.2</version>
                </dependency>
            </dependencies>
        </plugin>

        <plugin>
            <groupId>org.glassfish</groupId>
            <artifactId>maven-embedded-glassfish-plugin</artifactId>
            <version>3.1.1</version>
            <configuration>
                <goalPrefix>embedded-glassfish</goalPrefix>
                <autoDelete>true</autoDelete>
                <app>${basedir}/target/MyProject-integration-test-${project.version}.ear</app> 
                <port>8080</port>
                <configFile>src/test/resources/glassfish/config/domain.xml</configFile>
            </configuration>
            <executions> 
                <execution>
                    <id>start-glassfish</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>glassfish-deploy</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>deploy</goal>
                    </goals>
                </execution>
                <execution>
                    <id>glassfish-undeploy</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>undeploy</goal>
                    </goals>
                </execution>

                <execution>
                    <id>stop-glassfish</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions> 
        </plugin> 
    </plugins>

</build>

【问题讨论】:

  • 您是否测试过在命令行上构建 ear 并首先将其部署到 glassfish?

标签: maven-2 glassfish-embedded maven-failsafe-plugin


【解决方案1】:

是的,它现在可以工作了。原来问题出在我的 domain.xml 文件上。默认 domain.xml 带有前缀为 2 的端口号,应将其删除,并且在嵌入式 glassfish 3.1 8080 如果设置了 则不起作用(参考此文档) http://embedded-glassfish.java.net/nonav/plugindocs/3.1/stop-mojo.html

我只需将 domain.xml 中的 IIOP 端口设置为 3700 并在我的测试中

 Properties props = new Properties();  
 props.put("org.omg.CORBA.ORBInitialPort", "3700");
 Context ctx = new InitialContext(props);   

谢谢大家

【讨论】:

    【解决方案2】:

    您可以在一次调用中完成打包和启动 glassfish。

    你试过了吗:

    mvn verify 
    

    这样做?

    【讨论】:

    • 是的,我试过了。运行 mvn verify 产生了上述结果。我们现在要试试 Arquillian。希望使用 arquillian 将 ear 文件部署到 glassfish 并运行集成测试会更容易。
    • 你能告诉我如何在我的测试用例中获得一个由 maven 启动的 Glassfish 实例吗?
    • 是的,它现在可以工作了。原来问题出在我的 domain.xml 文件上。默认 domain.xml 带有前缀为 2 的端口号,如果设置了 (参考此文档)embedded-glassfish.java.net/nonav/plugindocs/3.1/stop-mojo.html,则应将其删除,并且在嵌入式 glassfish 3.1 8080 中不起作用。我只需将 domain.xml 中的 IIOP 端口设置为 3700 并在我的测试 Properties props = new Properties(); props.put("org.omg.CORBA.ORBInitialPort", "3700");上下文 ctx = new InitialContext(props);谢谢大家
    【解决方案3】:

    可能是另一种指定 Glassfish 的 IIOP 端口的解决方案(首先需要确认服务器 IP 和 IIOP 侦听器端口):

    System.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
    System.setProperty("org.omg.CORBA.ORBInitialPort", "8037");
    Context ctx = new InitialContext();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-21
      • 1970-01-01
      • 2020-03-16
      • 2018-06-02
      • 2013-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多