Itegration Test Framework - Getting started

This page will describe what is the integration test framework and how it can be used to write test cases.

The Integration Test Framework gives the ability for users to write Function Verification Test Cases, which can then be run on a fully integrated tuscany runtime. Some of the features of the Itest plugin are auto start and stop of the tuscany runtime, and running the test cases within the runtime.

Writing Test Cases to run on Tuscany StandAlone

You could have a simple test case as is the example with the propertyTest. Here the application is simply a jar file that would run on standalone tuscany runtime. In the pom.xml file, you can specify the following:

<plugin>
                <groupId>org.apache.tuscany.sca.plugins</groupId>
                <artifactId>tuscany-itest-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/*ITest.java</include>
                            </includes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
   </plugin>


In the above, the code marked in red starts up the tuscany runtime.

And similarly, the code marked in blue stops the tuscany runtime after the tests are run

The code marked in green runs the actual test cases. Notice that it does have an <include> filter, to indicate which of the tests you want to include. Similarly you can have an <exclude> filter.

Also, you should have the following code in order to not run these testcases as part of the regular unit tests in case you have other unit testcases.

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/*ITest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>

To see the code for the test case, please check the propertyTest module.

Writing Test Cases to test on Apache Tomcat


You may have your testSuite containing webApps that need to be deployed on tomcat (For example if you have testcases to test single or multiple composites). In such a case, you would need to use the "Maven Cargo Plugin". More information on the plugin itself can be found here: Maven Cargo Plugin.

This plugin can be used to automatically deploy your webApp on a tomcat server, start the server, run the testcases and stop the server. The following code illustrates this process.

The Maven Cargo plugin is defined as such in the pom.xml file:

<plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
</plugin>

The following code illustrated starting and stopping the container from within the cargo plugin. The container is started in a "pre-integration-test" phase. This ensures that the container is started well before the actual tests are run which is desired. Also, the container is stopped in a "post-integration-test" phase, which ensures that the container is stopped well after the test cases are run.

               <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>

The following code specifies the configuration for the container. Firstly the configuration of the container itself is specified, by specifying the container ID and home, which in this case is wherever tomcat is installed. Next, the configuration to be used within the container is specified. This would include the home for the container, which is where all the container (tomcat) core files are copied and used for the testcases. Also specified, are the webApps which need to be deployed on the container during this run.

              <configuration>
                    <wait>false</wait>

                    <!-- Container configuration -->
                    <container>
                        <containerId>tomcat5x</containerId>
                        <home>${tomcat.dir}</home>
                    </container>

                    <!-- Configuration to use with the container -->
                    <configuration>
                        <home>${project.build.directory}/tomcat5x</home>
                            <deployables>
                              <deployable>
                                <groupId>org.apache.tuscany.testing.bindingstest</groupId>
                                <artifactId>bindingscomposite</artifactId>
                                <type>war</type>
                                <properties>
                                    <context>/testtool</context>
                                </properties>
                                <pingURL>http://localhost:8080/testtool/services</pingURL>
                              </deployable>
                              <deployable>
                                <groupId>org.apache.tuscany.testing.bindingstest</groupId>
                                <artifactId>bindingsutility</artifactId>
                                <type>war</type>
                                <properties>
                                    <context>/testutil</context>
                                </properties>
                                <pingURL>http://localhost:8080/testutil/services</pingURL>
                              </deployable>
                            </deployables>
                    </configuration>

                </configuration>

In the above code, for each webApp that is deployed, there is a <context> property specified, which is the context under which the webApp is deployed.

Now the final part of the code below which illustrates the running of the testcases using the itest plugin:

             <plugin>
                <groupId>org.apache.tuscany.sca.plugins</groupId>
                <artifactId>tuscany-itest-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <applicationScdl>
                                file:///C:/SDO2/Tuscany/java/testing/sca/itest/bindingsTest/bindingsclient/src/main/resources/META-INF/sca/default.scdl
                            </applicationScdl>
                            <extensions>
                                <dependency>
                                    <groupId>org.apache.tuscany.sca.services.databinding</groupId>
                                    <artifactId>databinding-sdo</artifactId>
                                    <version>1.0-incubator-SNAPSHOT</version>
                                </dependency>
                                <dependency>
                                    <groupId>org.apache.tuscany.sca.services.bindings</groupId>
                                    <artifactId>axis2</artifactId>
                                    <version>1.0-incubator-SNAPSHOT</version>
                                </dependency>
                            </extensions>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/*ITest.java</include>
                            </includes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Notice in the above code, how the execution <start> and <stop> phase for the testcases is defined as "pre-integration-test". This is the same phase under which the container was started. Hence this ensures that the testcases are run after the container is started, and before it is stopped. In the above example, we have two composites as webApps being deployed on tomcat. Since we have multiple scdl files, with the same name, we need to specify the application scdl file which can done using <applicationScdl> property. Also, if the testcases require some extensions, then they can also be specified as indicated above using the <extensions> property.

The final pom file for such a test case should be similar to the one given below:

  <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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>org.apache.tuscany.testing.bindingstest</groupId>
      <artifactId>bindingsclient</artifactId>
      <packaging>jar</packaging>
      <version>SNAPSHOT</version>
      <name>SCA FVT Bindings Test Tool JSP Client</name>

        <properties>
        <tomcat.dir>C:/Apache/Tomcat 5.5</tomcat.dir>
        </properties>

      <dependencies>
            <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>3.8.1</version>
                  <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.osoa</groupId>
                <artifactId>sca-api-r0.95</artifactId>
                <version>1.0-incubator-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
   
           <dependency>
               <groupId>org.apache.tuscany.sca.services.bindings</groupId>
               <artifactId>axis2</artifactId>
               <version>1.0-incubator-SNAPSHOT</version>
           </dependency>
           <dependency>
              <groupId>org.apache.tuscany.testing.bindingstest</groupId>
              <artifactId>bindingscomposite</artifactId>
              <version>SNAPSHOT</version>
              <type>war</type>
              <scope>provided</scope>
           </dependency>
           <dependency>
              <groupId>org.apache.tuscany.testing.bindingstest</groupId>
              <artifactId>bindingsutility</artifactId>
              <version>SNAPSHOT</version>
              <type>war</type>
              <scope>provided</scope>
           </dependency>
           <dependency>
                <groupId>org.apache.tuscany.sca</groupId>
                <artifactId>test</artifactId>
                <version>1.0-incubator-SNAPSHOT</version>
            </dependency>
    
    
      </dependencies>



 
  <build>
     <defaultGoal>install</defaultGoal>
     <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.5</source>
              <target>1.5</target>
              <showDeprecation>true</showDeprecation>
              <compilerArgument>-Xlint:unchecked,deprecation,fallthrough,finally</compilerArgument>
            </configuration>
          </plugin>
          <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>
                    <wait>false</wait>

                    <!-- Container configuration -->
                    <container>
                        <containerId>tomcat5x</containerId>
                        <home>${tomcat.dir}</home>
                        <!--
                            <zipUrlInstaller>
                            <url>http://www.orionserver.com/distributions/orion2.0.5.zip</url>
                            <installDir>${java.io.tmpdir}/cargoinstalls</installDir>
                            </zipUrlInstaller>
                        -->

                    </container>

                    <!-- Configuration to use with the container -->
                    <configuration>
                        <home>${project.build.directory}/tomcat5x</home>
                            <deployables>
                              <deployable>
                                <groupId>org.apache.tuscany.testing.bindingstest</groupId>
                                <artifactId>bindingscomposite</artifactId>
                                <type>war</type>
                                <properties>
                                    <context>/testtool</context>
                                </properties>
                                <pingURL>http://localhost:8080/testtool/services</pingURL>
                              </deployable>
                              <deployable>
                                <groupId>org.apache.tuscany.testing.bindingstest</groupId>
                                <artifactId>bindingsutility</artifactId>
                                <type>war</type>
                                <properties>
                                    <context>/testutil</context>
                                </properties>
                                <pingURL>http://localhost:8080/testutil/services</pingURL>
                              </deployable>
                            </deployables>
                    </configuration>

                </configuration>
            </plugin>         
            <plugin>
                <groupId>org.apache.tuscany.sca.plugins</groupId>
                <artifactId>tuscany-itest-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <applicationScdl>
                                file:///C:/SDO2/Tuscany/java/testing/sca/itest/bindingsTest/bindingsclient/src/main/resources/META-INF/sca/default.scdl
                            </applicationScdl>
                            <extensions>
                                <dependency>
                                    <groupId>org.apache.tuscany.sca.services.databinding</groupId>
                                    <artifactId>databinding-sdo</artifactId>
                                    <version>1.0-incubator-SNAPSHOT</version>
                                </dependency>
                                <dependency>
                                    <groupId>org.apache.tuscany.sca.services.bindings</groupId>
                                    <artifactId>axis2</artifactId>
                                    <version>1.0-incubator-SNAPSHOT</version>
                                </dependency>
                            </extensions>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/*ITest.java</include>
                            </includes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/*ITest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>
    </plugins>
  </build>
 
</project>

Getting Help

First place to look is at the Tuscany FAQ at http://incubator.apache.org/tuscany/faq.html

Any problem with this release can be reported to the Tuscany mailing lists or create a JIRA issue at http://issues.apache.org/jira/browse/Tuscany.

Thank you for your interest in Tuscany.

-The Tuscany Development Team