1

スイングアプリケーションの統合テストを実行するには、同じWebアプリケーションで構成が異なる(スプリング+システムプロパティを介して注入された)3つのtomcatを起動する必要があります。

サーバー側アプリのWARとswingアプリのJARの両方をフェッチし、3つの異なるポートセットで3つのTomcatインスタンスを起動し、それらのTomcatにWARをデプロイしてテストを実行する、このテスト専用のMavenプロジェクトがあります。

これが私たちのMaven構成です:

<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>xxx</groupId>
    <artifactId>XXX-SwingTests</artifactId>
    <version>3.1.2-SNAPSHOT</version>
    <name>XXX Swing Tests</name>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <source.encoding>UTF-8</source.encoding>
        <java.compiler.version>1.6</java.compiler.version>
        <XXX.version>${project.version}</XXX.version>
        <swing-test.include>**/ *SwingTest*</swing-test.include>
    </properties>

    <dependencies>
        <dependency>
            <groupId>xxx</groupId>
            <artifactId>XXX-Client-Base</artifactId>
            <version>${XXX.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>xxx</groupId>
            <artifactId>XXX-Client-Base</artifactId>
            <version>${XXX.version}</version>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>abbot</groupId>
            <artifactId>abbot</artifactId>
            <version>1.2.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>

                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.0</version>

                    <!-- External Libraries included in Tomcat -->
                    <dependencies>

                        <!-- Active MQ dependencies -->
                        <dependency>
                            <groupId>org.apache.activemq</groupId>
                            <artifactId>activemq-all</artifactId>
                            <version>5.6.0</version>
                        </dependency>
                        <dependency>
                            <groupId>commons-logging</groupId>
                            <artifactId>commons-logging</artifactId>
                            <version>1.1.1</version>
                        </dependency>
                        <dependency>
                            <groupId>commons-collections</groupId>
                            <artifactId>commons-collections</artifactId>
                            <version>3.2.1</version>
                        </dependency>
                        <dependency>
                            <groupId>log4j</groupId>
                            <artifactId>log4j</artifactId>
                            <version>1.2.16</version>
                        </dependency>
                        <dependency>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-context</artifactId>
                            <version>3.0.6.RELEASE</version>
                        </dependency>
                        <dependency>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-asm</artifactId>
                            <version>3.0.6.RELEASE</version>
                        </dependency>
                        <dependency>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-beans</artifactId>
                            <version>3.0.6.RELEASE</version>
                        </dependency>
                        <dependency>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-core</artifactId>
                            <version>3.0.6.RELEASE</version>
                        </dependency>
                        <dependency>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-expression</artifactId>
                            <version>3.0.6.RELEASE</version>
                        </dependency>
                        <dependency>
                            <groupId>org.apache.xbean</groupId>
                            <artifactId>xbean-spring</artifactId>
                            <version>3.9</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <ignorePackaging>true</ignorePackaging>
                        <webapps>
                            <webapp>
                                <groupId>xxx</groupId>
                                <artifactId>XXX-Web</artifactId>
                                <version>${XXX.version}</version>
                                <type>war</type>
                                <asWebapp>true</asWebapp>
                                <contextPath>XXX</contextPath>
                            </webapp>
                        </webapps>
                        <systemProperties>
                            <!-- Allow Slashes and backslashes encoding -->
                            <org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH>true</org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH>
                            <org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH>true</org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH>
                        </systemProperties>
                    </configuration>

                </plugin>
            </plugins>
        </pluginManagement>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>*</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>*</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/conf</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <testResources>
            <testResource>
                <filtering>false</filtering>
                <directory>src/test/resources</directory>
                <includes>
                    <include>**/*</include>
                </includes>
                <excludes>
                    <exclude>**/*.xml</exclude>
                </excludes>
            </testResource>
            <testResource>
                <filtering>true</filtering>
                <directory>src/test/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </testResource>
        </testResources>
    </build>

    <profiles>

        <!-- Profile that starts the tomcat servers -->
        <profile>
            <id>start-servers</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <!-- Run CL server -->
                    <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>tomcat-run-CL</id>
                                <goals>
                                    <goal>run-war-only</goal>
                                </goals>
                                <phase>pre-integration-test</phase>
                                <configuration>
                                    <port>8180</port>
                                    <ajpPort>8109</ajpPort>
                                    <fork>true</fork>
                                    <systemProperties>
                                        <config_XXX_application>${project.build.directory}/test-classes/central/application.properties</config_XXX_application>
                                        <config_XXX_cron_application>${project.build.directory}/test-classes/central/cron.properties</config_XXX_cron_application>
                                        <config_XXX_external>${project.build.directory}/test-classes/central/external-providers.properties</config_XXX_external>
                                    </systemProperties>
                                    <contextFile>${project.build.directory}/classes/CL/context.xml</contextFile>
                                    <configurationDir>${project.build.directory}/tomcat-cl</configurationDir>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Run LL server -->
                    <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>tomcat-run-LL</id>
                                <goals>
                                    <goal>run-war-only</goal>
                                </goals>
                                <phase>pre-integration-test</phase>
                                <configuration>
                                    <port>8280</port>
                                    <ajpPort>8209</ajpPort>
                                    <fork>true</fork>
                                    <systemProperties>
                                        <config_XXX_application>${project.build.directory}/test-classes/local/application.properties</config_XXX_application>
                                        <config_XXX_cron_application>${project.build.directory}/test-classes/local/cron.properties</config_XXX_cron_application>
                                        <config_XXX_external>${project.build.directory}/test-classes/local/external-providers.properties</config_XXX_external>
                                    </systemProperties>
                                    <contextFile>${project.build.directory}/classes/LL/context.xml</contextFile>
                                    <configurationDir>${project.build.directory}/tomcat-ll</configurationDir>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Run OL server -->
                    <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>tomcat-run-OL</id>
                                <goals>
                                    <goal>run-war-only</goal>
                                </goals>
                                <phase>pre-integration-test</phase>
                                <configuration>
                                    <port>8380</port>
                                    <ajpPort>8309</ajpPort>
                                    <fork>true</fork>
                                    <systemProperties>
                                        <config_XXX_application>${project.build.directory}/test-classes/operational/application.properties</config_XXX_application>
                                        <config_XXX_cron_application>${project.build.directory}/test-classes/operational/cron.properties</config_XXX_cron_application>
                                        <config_XXX_external>${project.build.directory}/test-classes/operational/external-providers.properties</config_XXX_external>
                                    </systemProperties>
                                    <contextFile>${project.build.directory}/classes/OL/context.xml</contextFile>
                                    <configurationDir>${project.build.directory}/tomcat-ol</configurationDir>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Stop all servers -->
                    <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>tomcat-shutdown</id>
                                <goals>
                                    <goal>shutdown</goal>
                                </goals>
                                <phase>post-integration-test</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Profile that runs the swing tests in the integration-test phase -->
        <profile>
            <id>swing-tests</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <!-- Execute swing tests in the 'integration-test' phase -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>2.13</version>
                        <executions>
                            <execution>
                                <id>integration-test</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=512m</argLine>
                                    <includes>
                                        <include>${swing-test.include}</include>
                                    </includes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

ログには特に何も表示されていませんが、最初に開始されたサーバーを対象とするテストのみが成功し、他のテストは失敗し、理由がわかりません(Springコンテキストが正しく開始されなかったと思われますが、できませんでした)必ず)。最初のプラグインの実行をコメントアウトすると、このサーバーを対象とするすべてのテストは(明らかに)失敗しますが、リスト内の次のサーバーを対象とするテストは合格します。

この構成の何が問題になっているのか分かりますか?私たちがここで試みていることを達成するための適切な方法は何ですか?

編集:実際には、ログにエラーがありますが、それを理解する方法がわかりません:

[INFO] [tomcat7:run-war-only {execution: tomcat-run-CL}]
[INFO] Running war on http://localhost:8180/xxx-SwingTests
[INFO] Creating Tomcat server configuration at C:\projects\xxx\workspace\xxx-SwingTests\target\tomcat-cl
[INFO] setting SystemProperties:
[INFO]  config_xxx_application=C:\projects\xxx\workspace\xxx-SwingTests\target/test-classes/central/application.properties
[INFO]  config_xxx_cron_application=C:\projects\xxx\workspace\xxx-SwingTests\target/test-classes/central/cron.properties
[INFO]  config_xxx_external=C:\projects\xxx\workspace\xxx-SwingTests\target/test-classes/central/external-providers.properties
[INFO]  org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true
[INFO]  org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
[INFO] create webapp with contextPath: /xxx-SwingTests
[INFO] Deploying dependency wars
[INFO] Deploy warfile: C:\Users\Administrator\.m2\repository\xxx\xxx-Web\3.1.2-SNAPSHOT\xxx-Web-3.1.2-SNAPSHOT.war to contextPath: /xxx
Jan 9, 2013 7:44:27 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8180"]
Jan 9, 2013 7:44:27 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8109"]
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.30
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base C:\projects\xxx\workspace\xxx-SwingTests\target\xxx-SwingTests-3.1.2-SNAPSHOT does not exist or is not a readable directory
        at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:140)
        at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4906)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5086)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error in resourceStart()
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error getConfigured
Jan 9, 2013 7:44:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/xxx-SwingTests] startup failed due to previous errors
Jan 9, 2013 7:44:27 PM org.apache.catalina.deploy.NamingResources cleanUp
WARNING: Failed to retrieve JNDI naming context for container [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/xxx-SwingTests]] so no cleanup was performed for that container
javax.naming.NameNotFoundException: Name [comp/env] is not bound in this Context. Unable to find [comp].
        at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
        at org.apache.catalina.deploy.NamingResources.cleanUp(NamingResources.java:988)
        at org.apache.catalina.deploy.NamingResources.stopInternal(NamingResources.java:970)
        at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
        at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5495)
        at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
4

2 に答える 2

1

問題は、同じクラスローダーで jndi コンテキストを 2 回開始することです。これは現在、tomcat では不可能です。

于 2013-02-04T17:52:06.500 に答える
0

Jetty + Tomcat だけを使用するのはどうですか?

プラグインでは、必要なだけ多くのインスタンスに Tomcat を使用できません。ただし、maven-jetty-plugin を使用して、少なくとも 2 つのアプリケーションを同時に開始できます。

于 2014-12-16T12:43:50.860 に答える