views:

352

answers:

2

I have a Maven project which executes integration tests for another web-application. This application is deployed and started within a tomcat container.

The configuration for this is done in the “cargo-maven2-plugin”:

 <plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
   <wait>false</wait>
   <configuration>
    <type>standalone</type>
    <properties>
     <cargo.hostname>${itest.hostname}</cargo.hostname>
     <cargo.protocol>${itest.protocol}</cargo.protocol>
     <cargo.servlet.port>${itest.port}</cargo.servlet.port>
     <cargo.servlet.uriencoding>UTF-8</cargo.servlet.uriencoding>
     <cargo.jvmargs>-Xmx1024m</cargo.jvmargs>
    </properties>
   </configuration>
   <container>
    <containerId>tomcat6x</containerId>
    <home>${TEST_TOMCAT_HOME}</home>
   </container>
   <deployer>
    <deployables>
     <deployable>
      <groupId>de.apllicationundertest</groupId>
      <artifactId>apllicationundertest</artifactId>
      <type>war</type>
      <!--
       This will test if the app is ready an throw an exception if
       the integration tests start before deployment is finished
      -->
      <pingURL>${itest.protocol}://${itest.hostname}:${itest.port}/${itest.web.context}/main.html 
      </pingURL>
      <pingTimeout>120000</pingTimeout>
      <!--  Setting our context for the integration tests -->
      <properties>
       <context>${itest.web.context}</context>
      </properties>
     </deployable>
    </deployables>
   </deployer>
  </configuration>
  <executions>
   <execution>
    <id>start-container</id>
    <phase>pre-integration-test</phase>
    <goals>
     <goal>start</goal>
     <goal>deploy</goal>
    </goals>
   </execution>
   <execution>
    <id>stop-container</id>
    <phase>post-integration-test</phase>
    <goals>
     <goal>stop</goal>
    </goals>
   </execution>
  </executions>
 </plugin>

The (web-)apllication under tests is integrated as a dependency in the pom.xml of my integration test project, so I have no absolute or relative path to the war.

My problem is that I can't control the tomcat container during the runtime of my program. Though my test scenario requires the stopping and restarting of the container (and the redeployment of the apllication under test) between some tests, f.e. for checking if there are still some active Threads after the stopping of the container or if there are still some elements of my apllication in the cache,...

  1. I want to configure the starting and stopping of the container outside java, preferably in the pom.xml. Is that possible?
  2. Can I specify that certain unit tests require a restarting and execute that? How?
A: 

I don't think it is possible since starting container is done in pre-integration-test phase. Why specyfic tests need to be run in restarted server? If it is possible try rewrite your test (do cleanup).

I want to configure the starting and stopping of the container outside java, preferably in the pom.xml. Is that possible?

If you need this hardly you can try put configuration for separate tests in dedicated profiles. Each profile will contain configuration of cargo and surefire/failsafe plugins.

Can I specify that certain unit tests require a restarting and execute that? How?

You can specify what test should be run. Look at surefire/failsafe plugin configuration

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.5</version>
    <configuration>
      <includes>
        <include>Sample.java</include>
      </includes>
    </configuration>
    <executions>
      <execution>
        <id>integration-test</id>
        <phase>integration-test</phase>
        <goals>
          <goal>integration-test</goal>
        </goals>
      </execution>
      <execution>
        <id>verify</id>
        <phase>verify</phase>
        <goals>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
cetnar
Thanks cetnar, I think I will go with that solution. But how can I configure that each profile is used after another? I tried this: "mvn clean integration-test -P profileA -P profileB" and this "mvn clean integration-test -P profileA,profileB", but with each only one profile was executed. With "mvn clean integration-test -P profileA profileB", there is another error: "you must specify a valid lifecycle phase".
Sebastian Rapp
A: 

I want to configure the starting and stopping of the container outside java, preferably in the pom.xml. Is that possible?

What you can do from Maven is what you are currently doing: starting and stoping cargo during the pre-integration-test and post-integration-test phases respectively.

Can I specify that certain unit tests require a restarting and execute that? How?

No, this is not possible. Maven doesn't have this granularity and doesn't give you any hooks for that. If this is really what you need, you have two options:

  • Control the container from Java like I described in this previous answer.
  • Put the tests in separate maven modules (so that maven will start and stop your container for each).
Pascal Thivent