使用maven2进行集成测试,故障安全&嵌入式的GlassFish

时间:2012-08-17 00:25:12

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

我创建了一个新项目,它只会用

运行集成测试
  • maven-ear-plugin
  • maven-failsafe-plugin
  • maven-embedded-glassfish-plugin

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

  

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

和glassfish取消部署失败

  

[嵌入的glassfish:取消部署]   
17/08/2012 10:08:17 AM PluginUtil doUndeploy   
INFO:Deployer = 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)

当我将包装设置为罐子时 我得到了

  

运行packageName.MyServiceTest   
17/08/2012 10:09:34 AM com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl
findDerbyClient   
INFO:找不到javadb客户端jar文件,默认情况下derby jdbc驱动程序不可用。   
org.omg.CORBA.COMM_FAILURE:FINE:IOP00410001:连接失败:socketType:
IIOP_CLEAR_TEXT; hostname:localhost;端口:3700 vmcid:OMG次要代码:1
完成:否   
在sun.reflect.GeneratedConstructorAccessor27.newInstance(未知来源)

并且glassfish无法启动

我知道它必须对Maven生命周期做一些事情,它不允许我创建ear文件,启动glassfish嵌入式服务器并在同一个项目中运行集成测试。

有人可以建议我一个解决方案吗?我正在尝试使用EJB和Business实体项目创建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>

3 个答案:

答案 0 :(得分:1)

是的,它现在正在运作。结果问题出在我的domain.xml文件中。默认的domain.xml附带前缀为2的端口号,应该删除它,并且嵌入的glassfish 3.1&lt;端口&GT; 8080&lt; /端口&GT;如果&lt;不起作用CONFIGFILE&GT;设置(参考这个doco) 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);   

谢谢你们

答案 1 :(得分:0)

您可以通过一次通话进行打包和启动玻璃鱼。

你试过了吗?

mvn verify 

要这样做吗?

答案 2 :(得分:0)

可能是指定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();
相关问题