Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
xml
xml
<build>
    <plugins>
    <!-- Generate web-xml and geronimo deployment descriptor -->
        <plugin>
            <groupId>org.apache.tuscany.sca</groupId>
            <artifactId>tuscany-maven-web-junit</artifactId>
            <version>1.2-incubating-SNAPSHOT</version>
            <executions>
                <execution>
                    <id>generate-web-xml</id>
                    <configuration>
                        <geronimo>true</geronimo>
                    </configuration>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

5. Test automation with maven

Code Block
2xml
titleSample pom.xml
borderStylesolid
<!--
        This profile handles generation of jar/war artifacts to be used in executing tests in a web-container
        -->
        <profile>
            <id>webapp</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>

            <dependencies>
                <dependency>
	    	    <groupId>org.apache.tuscany.sca</groupId>
	    	    <artifactId>tuscany-host-webapp</artifactId>
	    	    <version>1.2-incubating-SNAPSHOT</version>
                           <scope>runtime</scope>
	    </dependency>
                <dependency>
	    	    <groupId>org.apache.tuscany.sca</groupId>
	    	    <artifactId>tuscany-host-webapp-junit</artifactId>
	    	    <version>1.2-incubating-SNAPSHOT</version>
                    <scope>runtime</scope>
	    	</dependency>
                <dependency>
	    	    <groupId>javax.servlet</groupId>
	    	    <artifactId>servlet-api</artifactId>
	    	    <version>2.3</version>
                    <scope>provided</scope>
	    	</dependency>
	    </dependencies>

            <build>
                <pluginManagement>
                    <plugins>
                        <!-- Skip local junit test cases -->
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>2.3.1</version>
                            <configuration>
                                <skip>true</skip>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>

                <plugins>

                    <!-- Generate web-xml -->
                    <plugin>
                        <groupId>org.apache.tuscany.sca</groupId>
                        <artifactId>tuscany-maven-web-junit</artifactId>
                        <version>1.2-incubating-SNAPSHOT</version>
                        <executions>
                            <execution>
                                <id>generate-web-xml</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Create war and include jUnit test classes -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.0.2</version>
                        <configuration>
                            <primaryArtifact>false</primaryArtifact>
                            <!-- Exclude a few jars to avoid conflicts -->
                            <warSourceExcludes>WEB-INF/lib/tuscany-host-tomcat-*.jar,WEB-INF/lib/tuscany-host-jetty-*.jar,servlet-api-*.jar, WEB-INF/classes/META-INF/sca-contribution*.xml</warSourceExcludes>
                            <webResources>
                                <resource>
                                    <directory>${project.build.directory}/test-classes</directory>
                                    <targetPath>WEB-INF/classes</targetPath>
                                </resource>

                                <resource>
                                    <directory>${project.build.directory}/classes/META-INF</directory>
                                    <includes>
                                        <include>sca-contribution*.xml</include>
                                    </includes>
                                    <targetPath>META-INF</targetPath>
                                </resource>

                                <!-- Add the junit -->
                                <resource>
                                    <directory>${settings.localRepository}/junit/junit/4.2</directory>
                                    <includes>
                                        <include>junit-4.2.jar</include>
                                    </includes>
                                    <targetPath>WEB-INF/lib</targetPath>
                                </resource>

                            </webResources>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>war</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>geronimo</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <http.port>8080</http.port>
                <http.base>http://127.0.0.1:${http.port}</http.base>
                <geronimo.home>${env.GERONIMO_HOME}</geronimo.home>
            </properties>

            <build>
                <plugins>
                    <!-- Generate web-xml and geronimo deployment descriptor -->
                    <plugin>
                        <groupId>org.apache.tuscany.sca</groupId>
                        <artifactId>tuscany-maven-web-junit</artifactId>
                        <version>1.2-incubating-SNAPSHOT</version>
                        <executions>
                            <execution>
                                <id>generate-web-xml</id>
                                <configuration>
                                    <geronimo>true</geronimo>
                                </configuration>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>web-junit-test</id>
                                <configuration>
                                    <url>${http.base}/${project.build.finalName}/junit?op=runAll</url>
                                </configuration>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.geronimo.plugins</groupId>
                        <artifactId>geronimo-maven-plugin</artifactId>
                        <version>2.0.2</version>
                        <configuration>
                            <geronimoHome>${geronimo.home}</geronimoHome>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-container</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                                <configuration>
                                    <background>true</background>
                                </configuration>
                            </execution>
                            <execution>
                                <id>deploy-war</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>deploy</goal>
                                </goals>
                                <configuration>
                                    <moduleArchive>${project.build.directory}/${project.build.finalName}.war</moduleArchive>
                                </configuration>
                            </execution>
                            <execution>
                                <id>undeploy-war</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>undeploy</goal>
                                </goals>
                                <configuration>
                                    <moduleId>${groupId}/${artifactId}/${version}/war</moduleId>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop-container</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                                <configuration>
                                    <username>system</username>
                                    <password>manager</password>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

...