Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy to integration server and run smoke test with Maven

We are using Maven to build a web application.

Now we'd like our CI (continouous integration) server to automatically deploy the WAR to a remote Tomcat instance which serves as an alpha test server.

We use the cargo-maven-plugin to do this, and it works fine.

However, now we would also like to run a smoke test on the remote Tomcat after deployment, to make sure the (re)deployment went off cleanly.

We have tests to do that (using HtmlUnit), but we're having trouble integrating them into Maven. So far, we started cargo directly (using mvn cargo:redeploy). This worked - however, we could not find a way to run the smoke tests afterwards.

So how can we set up maven to

  • first deploy using cargo
  • then run smoke tests

There does not seem to be a place in the maven build lifecycle for this. Do we need to define a custom build lifecycle? Can we somehow bind to a default lifecycle phase? Which one?

like image 985
sleske Avatar asked Aug 03 '11 10:08

sleske


1 Answers

The most important thing you have to do is to put your integration into a separate maven module call it whatever-it (for integration test). Put the cargo plugin into the integration phase:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <configuration>
      <wait>false</wait>
      <container>
        <containerId>tomcat${tomcat.major}x</containerId>
        <zipUrlInstaller>
          <url>http://archive.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url>
          <downloadDir>${project.build.directory}/cargo/download/</downloadDir>
          <extractDir>${installDir}</extractDir>
        </zipUrlInstaller>
        <output>${project.build.directory}/tomcat${tomcat.major}x.log</output>
        <log>${project.build.directory}/cargo.log</log>
      </container>
      <configuration>
        <home>${project.build.directory}/tomcat-${tomcat.version}/container</home>
        <properties>
          <cargo.logging>high</cargo.logging>
          <cargo.servlet.port>9080</cargo.servlet.port>
        </properties>
      </configuration>
    </configuration>

add execution blocks:

  <executions>
      <execution>
        <id>start-container</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>start</goal>
          <goal>deploy</goal>
        </goals>
        <configuration>
          <deployer>
            <deployables>
              <deployable>
                <groupId>${project.groupId}</groupId>
                <artifactId>mod-war</artifactId>
                <type>war</type>
                <pingURL>http://localhost:9080/mod-war</pingURL>
                <pingTimeout>30000</pingTimeout>
                <properties>
                  <context>mod-war</context>
                </properties>
              </deployable>
            </deployables>
          </deployer>
        </configuration>
      </execution>

and the shutdown part:

      <execution>
        <id>stop-container</id>
        <phase>post-integration-test</phase>
        <goals>
          <goal>stop</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

The above configuration describes a full integration test cycle with downloading a tomcat unpacking the distribution of tomcat deploying a war file(the dependend project into tomcat), start the web-application and finally stop Tomcat. What you need to change for your purposes is that you don't have a start phase, cause you have already a running container. How to do this is described in the cargo documentation. Finally you have to put your integration tests into the src/test/java folder of the integration test module and don't forget to configure the maven-surefire-plugin like the following:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <executions>
      <execution>
        <phase>integration-test</phase>
        <goals>
          <goal>test</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <printSummary>true</printSummary>
      <testFailureIgnore>true</testFailureIgnore>
    </configuration>
  </plugin>

You can take a look of a full example here. The description of this is given here.

like image 161
khmarbaise Avatar answered Sep 17 '22 13:09

khmarbaise