Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

With this, we can run the plain JUNIT test cases in the web application by connecting to a URL like http://localhost:8080/Image Removed<app-name>/junit.

...

3) Run the maven build as ususal, produce a WAR, deploy to Tomcat, browse to http://localhost:8080/sample-calculator-webapp/junitImage Removed, and see the test results in the browser. To run a selected list of test cases, http://localhost:8080/sample-calculator-webapp/junit?test1,test2Image Removed.

This seems to be non-invasive as we already configure the servlet filter for web applications. The regular URLs to JSPs or web services stay the same. We don't have to change the test case code too much.

Image Added

I also went a bit further:

1) Developed a maven plugin to trigger the web-based junit tests and analyze the results
2) Configure the pom.xml with cargo plugin to start an embedded Jetty server, deploy the WAR, trigger the web-based junit tests, and stop the server.

Now I have a complete automation. To avoid repeating the pom configuration for each itest, we can add a profile in the parent pom to support this scheme.

Appendix

Sample results

Code Block
<?xml version="1.0" encoding="UTF-8" ?>
<!--
  <report>
     * Licensed<testsuites>
 to the Apache Software Foundation (ASF)    <testsuite name="null" tests="1" failures="0" errors="0" time="0.094">
              <testcase name="testTry(calculator.CalculatorTestCase)" time="0" />
          </testsuite>
      </testsuites>
  </report>

Updated pom.xml

Code Block

<?xml version="1.0" encoding="UTF-8"?>
<!--
    * Licensed to the Apache Software Foundation (ASF) under one
    * or more contributor license agreements.  See the NOTICE file
    * distributed with this work for additional information
    * regarding copyright ownership.  The ASF licenses this file
    * to you under the Apache License, Version 2.0 (the
    * "License"); you may not use this file except in compliance
    * with the License.  You may obtain a copy of the License at
    * 
    *   http://www.apache.org/licenses/LICENSE-2.0
    * 
    * Unless required by applicable law or agreed to in writing,
    * software distributed under the License is distributed on an
    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    * KIND, either express or implied.  See the License for the
    * specific language governing permissions and limitations
    * under the License.    
-->
<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.apache.tuscany.sca</groupId>
        <artifactId>tuscany-sca</artifactId>
        <version>1.2-incubating-SNAPSHOT</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <artifactId>sample-calculator-webapp</artifactId>
    <packaging>war</packaging>
    <name>Apache Tuscany SCA Calculator Sample in a WebApp</name>

    <repositories>
        <repository>
            <id>apache.incubator</id>
            <url>http://people.apache.org/repo/m2-incubating-repository</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.apache.tuscany.sca</groupId>
            <artifactId>tuscany-host-webapp</artifactId>
            <version>1.2-incubating-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tuscany.sca</groupId>
            <artifactId>tuscany-implementation-java-runtime</artifactId>
            <version>1.2-incubating-SNAPSHOT</version>
            <scope>runtime</scope>
        </dependency>

        <!-- marking dependency as provided to exclude from war file -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.3</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.2</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

    <build>
        <finalName>${artifactId}</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <configuration>
                            <finalName>web</finalName>
                        </configuration>
                        <phase>test</phase>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <webResources>
                        <resource>
                            <!-- this is relative to the pom.xml directory -->
                            <directory>target</directory>
                            <includes>
                                <include>*-tests.jar</include>
                            </includes>
                            <targetPath>WEB-INF/test-lib</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.tuscany.sca</groupId>
                <artifactId>tuscany-maven-web-unittest</artifactId>
                <version>1.2-incubating-SNAPSHOT</version>
                <executions>
                    <execution>
                        <configuration></configuration>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.tuscany.sca</groupId>
                <artifactId>tuscany-maven-ant-generator</artifactId>
                <version>1.2-incubating-SNAPSHOT</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>jetty</id>
            <activation>
                <activeByDefault />
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>cargo-maven2-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>start-container</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop-container</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>under one
    * or more contributor license agreements.  See the NOTICE file
    * distributed with this work for additional information
    * regarding copyright ownership.  The ASF licenses this file
    * to you under the Apache License, Version 2.0 (the
    * "License"); you may not use this file except in compliance
    * with the License.  You may obtain a copy of the License at
    * 
    *   http://www.apache.org/licenses/LICENSE-2.0
    * 
    * Unless required by applicable law or agreed to in writing,
    * software distributed under the License is distributed on an
    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    * KIND, either express or implied.  See the License for the
    * specific language governing permissions and limitations
    * under the License.    
-->
<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.apache.tuscany.sca</groupId>
        <artifactId>tuscany-sca</artifactId>
        <version>1.2-incubating-SNAPSHOT</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <artifactId>sample-calculator-webapp</artifactId>
    <packaging>war</packaging>
    <name>Apache Tuscany SCA Calculator Sample in a WebApp</name>

    <repositories>
        <repository>
            <id>apache.incubator</id>
                <url>http://people.apache.org/repo/m2-incubating-repository</url>
<container>
             </repository>
               </repositories>

    <dependencies><containerId>jetty6x</containerId>
        <dependency>
            <groupId>org.apache.tuscany.sca</groupId>
            <artifactId>tuscany-host-webapp</artifactId><type>embedded</type>
            <version>1.2-incubating-SNAPSHOT</version>
         </dependency>

        <dependency>
   <systemProperties>
         <groupId>org.apache.tuscany.sca</groupId>
               <artifactId>tuscany-implementation-java-runtime</artifactId>
            <version>1.2-incubating-SNAPSHOT</version>
<org.apache.commons.logging.Log>
                  <scope>runtime</scope>
        </dependency>

        <!-- marking dependency as provided to exclude from war file -->
 org.apache.commons.logging.impl.SimpleLog
            <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId></org.apache.commons.logging.Log>
            <version>2.3</version>
            <scope>provided</scope>
        </dependency>
systemProperties>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit<</artifactId>container>
            <version>4.2</version>
            <scope>compile</scope>
    <wait>false</wait>
    </dependency>

    </dependencies>

    <build>
        <finalName>${artifactId}</finalName>

        <plugins><configuration>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
    <properties>
            <artifactId>maven-jar-plugin</artifactId>
                <version>2.2</version>
        <cargo.servlet.port>8080</cargo.servlet.port>
        <executions>
                    <execution>
    </properties>
                    <configuration>
            <deployables>
                <finalName>web</finalName>
                    <deployable>
    </configuration>
                        <phase>test</phase>
            <location>
            <goals>
                            <goal>test-jar</goal>
    ${project.build.directory}/${project.build.finalName}.${project.packaging}
                    </goals>
                    </execution>location>
                  </executions>
                </plugin>

      <pingURL>http://localhost:8080/${project.build.finalName}/junit</pingURL>
      <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId></deployable>
                <version>2.0.2</version>
                <configuration></deployables>
                    <webResources>
        </configuration>
                <resource>
        </configuration>
                    <!-- this is relative to the pom.xml directory -->
/plugin>
                </plugins>
            </build>
         <directory>target<</directory>profile>
        <profile>
            <id>geronimo</id>
        <includes>
    <properties>
                <geronimo.home>C:\Apache\geronimo-tomcat6-jee5-2.0.2</geronimo.home>
            <include>*-tests.jar</include></properties>

            <build>
                </includes><plugins>
                     <plugin>
       <targetPath>WEB-INF/test-lib</targetPath>
                    <groupId>org.apache.geronimo.plugins</groupId>
    </resource>
                    </webResources>
   <artifactId>geronimo-maven-plugin</artifactId>
             </configuration>
            </plugin><version>2.0.2</version>
            <plugin>
                <groupId>org.codehaus.cargo</groupId><configuration>
                <artifactId>cargo-maven2-plugin</artifactId>
            <geronimoHome>${geronimo.home}</geronimoHome>
    <executions>
                    <execution></configuration>
                        <id>start-container</id><executions>
                         <phase>pre-integration-test</phase>   <execution>
                        <goals>
        <id>start-container</id>
                    <goal>start</goal>
            <phase>pre-integration-test</phase>
            </goals>
                    </execution><goals>
                    <execution>
                <goal>start</goal>
        <id>stop-container</id>
                        <phase>post-integration-test</phase>
</goals>
                          <goals>
      <configuration>
                      <goal>stop</goal>
              <background>true</background>
             </goals>
                    </execution>configuration>

                </executions>
            </execution>
    <configuration>
                    <container>
    <execution>
                    <containerId>jetty6x</containerId>
            <id>deploy-war</id>
            <type>embedded</type>
                    <phase>pre-integration-test</phase>
    <systemProperties>
                            <org.apache.commons.logging.Log><goals>
                                org.apache.commons.logging.impl.SimpleLog
       <goal>deploy</goal>
                     </org.apache.commons.logging.Log>
            </goals>
            </systemProperties>
                    </container><configuration>
                    <wait>false</wait>
                    <configuration><moduleArchive>
                        <properties>
                ${project.build.directory}/${project.build.finalName}.${project.packaging}
            <cargo.servlet.port>8080</cargo.servlet.port>
                        </properties>moduleArchive>
                        <deployables>
        </configuration>
                    <deployable>
        </execution>
                        <location>
    <execution>
                                ${project.build.directory}/${project.build.finalName}.${project.packaging}<id>undeploy-war</id>
                                </location>
      <phase>post-integration-test</phase>
                          <pingURL>http://localhost:8080/${project.build.finalName}/junit</pingURL>
      <goals>
                      </deployable>
              <goal>undeploy</goal>
          </deployables>
                      </configuration>goals>
                    </configuration>
            </plugin>
<configuration>
                   <plugin>
                 <groupId>org<moduleId>org.apache.tuscany.sca</groupId>
sca/sample-calculator-webapp/1.2-incubating-SNAPSHOT/war</moduleId> 
                            <artifactId>tuscany-maven-web-unittest</artifactId>
    </configuration>
            <version>1.2-incubating-SNAPSHOT</version>                </execution>
                <executions>
            <execution>
        <execution>
                        <configuration><<id>stop-container</configuration>id>
                        <phase>integration-test</phase>
        <phase>post-integration-test</phase>
                <goals>
                <goals>
            <goal>test</goal>
                        <<goal>stop</goals>goal>
                    </execution>
            </goals>
     </executions>
            </plugin>
            <plugin>
   <configuration>
             <groupId>org.apache.tuscany.sca</groupId>
                <artifactId>tuscany-maven-ant-generator</artifactId>
        <username>system</username>
        <version>1.2-incubating-SNAPSHOT</version>
                <executions>
            <password>manager</password>
        <execution>
                        <goals></configuration>
                            <goal>generate<</goal>execution>
                        </goals>executions>
                    </execution>plugin>
                </executions>plugins>
            </plugin>build>
        </plugins>profile>
    </build>profiles>
</project>