Showing posts with label testing. Show all posts
Showing posts with label testing. Show all posts

Wednesday, October 21, 2009

Test your build with Maven 3

Maven 3 is coming

This post is to show you how to get Maven 3.
Maven 3 is supposed to be drop in replacement of Maven 2.
So you should be able to build your Maven based build with Maven 3 with no problem.
So lets take Maven 3 for a spin.

Getting Maven 3

You can get Maven 3 binaries or build it by hand.

Getting binaries

You can grab binaries from Sonatypes Hudson grid.
Depending on your platform:
Linux
lastSuccessfulBuild from ubuntu
Windows
lastSuccessfulBuild from windows
And extract it to your new M2_HOME.

Building from source

Check it out, and build:
$ svn co http://svn.apache.org/repos/asf/maven/maven-3/trunk maven-3
$ cd maven-3
$ export M2_HOME=/your/new/m3/home/
$ ant
So you have your own build of Maven 3 at /your/new/m3/home/. Congratulations!

Add to path

Independently how you got your new Maven 3, you need to add M2_HOME/bin to your PATH environment variable.

Start using it

And that is it, you have Maven 3.
As verification step execute, end expect something similar:
$ mvn -version
Apache Maven 3.0-SNAPSHOT (r828135; 2009-10-21 20:46:19+0200)
...
You probably will see quite some warnings while building your projects that previously where unnoticed.
Following those instructions will improve your build.
Enjoy your new build tool!

Monday, January 12, 2009

Maven Archetype Automation 1

In my need for automation I found another place for improvements in Maven2.

Here is a situation: you have sample project showing how to use something.

And you want to be nice to your users so you would like to offer them this sample project as archetype via archetype-catalog.xml.

Here is a bit longer version of above:


ArchetypeNG seems like possible solution, have to research this one.

Monday, July 7, 2008

Super Helpful Integration Testing ThingY

Maven plug-in integration testing.



After walking around integration tests for Overview I finally set down and made it happen.

Most helpful integration testing solution I found is called SHITTY http://mojo.codehaus.org/shitty-maven-plugin/.

It is very easy to use.

As sane developer would expect, you'll have to put your integration tests somewhere in src (src/it).

Integration test is:
  • yes you are right, pom.xml,
  • than goals.txt - defining goals to execute,
  • optional setup and validation Groovy scripts.
  • some additional stuff that wasn't needed for me.
You can find sample usage here.

Big thanks to Jason Dillon for creating Super Helpful Integration Testing ThingY.

Wednesday, November 7, 2007

Maven2 cargo plugin and integration test

So I was facing a problem of creating Maven2 project that would:
  1. Create domain based on JBoss default server configuration,
  2. Copy to this newly created domain configuration file and datasource configuration,
  3. Start container with domain that was result of #2.
I thought that cargo-maven2-plugin will do the job.
Unfortunately it didn't.

My initial approach was:
  1. Attach cargo:configure (undocumented goal :-/) to generate-test-sources phase, using standalone type, so configuration gets generated from scratch based on default,
  2. Attach antrun:run to generate-test-resources phase to copy .properties to conf, and -ds.xml to deploy,
  3. Attach cargo:start to pre-integration-test phase, using existing type, so configuration from #2 is read-only used, and *should* not be overwritten.
In theory it seems all great and already working.
But I couldn't convince cargo to work like that.
Started executing maven with -X to discover that maven configures mojos properly, not a big surprise, especially if you take a look at CI of cargo, you would suspect cargo of errors.
At the end of a day I created this ugly but working configuration:



<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>your.group.id</groupId>
 <artifactId>itest</artifactId>
 <version>0.1-SNAPSHOT</version>
 <name>Integration Tests</name>
 <description>This module provides a collection of integration tests.</description>
 <packaging>jar</packaging>
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>your.group.id</groupId>
   <artifactId>your-ear</artifactId>
   <type>ear</type>
   <version>${project.version}</version>
  </dependency>
  <dependency>
   <groupId>org.codehaus.cargo</groupId>
   <artifactId>cargo-ant</artifactId>
   <version>0.9</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.codehaus.cargo</groupId>
   <artifactId>cargo-core-uberjar</artifactId>
   <version>0.9</version>
   <scope>test</scope>
  </dependency>
 </dependencies>
 <build>
  <plugins>
   <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>
   </plugin>
   <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.1</version>
    <executions>
     <execution>
      <id>tune-deployment</id>
      <phase>generate-test-resources</phase>
      <goals>
       <goal>run</goal>
      </goals>
      <configuration>
       <tasks>
        <copy todir="${basedir}/target/jboss4x" overwrite="true">
         <fileset dir="${basedir}/src/jboss4x"/>
        </copy>
       </tasks>
      </configuration>
     </execution>
     <!-- This execution is needed to start container with existing configuration -->
     <execution>
      <id>start-container</id>
      <phase>pre-integration-test</phase>
      <goals>
       <goal>run</goal>
      </goals>
      <configuration>
       <tasks>
        <taskdef resource="cargo.tasks">
         <classpath refid="maven.test.classpath"/>
        </taskdef>
        <echo message="Starting Cargo..."/>
        <cargo containerId="jboss4x"
            home="${jboss4x.home}"
            output="${project.build.directory}/container.log"
            append="true"
            log="${project.build.directory}/cargo.log"
            action="start"
            wait="false">
         <configuration type="existing" home="${project.build.directory}/jboss4x">
          <property name="cargo.servlet.port" value="8982"/>
         </configuration>
        </cargo>
       </tasks>
      </configuration>
     </execution>
    </executions>
   </plugin>
   <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <configuration>
     <wait>false</wait>
     <container>
      <containerId>jboss4x</containerId>
      <home>${jboss4x.home}</home>
      <output>${project.build.directory}/container.log</output>
      <append>true</append>
      <log>${project.build.directory}/cargo.log</log>
     </container>
     <configuration>
      <type>existing</type>
      <home>${project.build.directory}/jboss4x</home>
      <properties>
       <cargo.logging>high</cargo.logging>
      </properties>
     </configuration>
    </configuration>
    <executions>
     <execution>
      <id>stop-container</id>
      <phase>post-integration-test</phase>
      <goals>
       <goal>stop</goal>
      </goals>
     </execution>
     <execution>
      <id>create-deployment</id>
      <phase>generate-test-sources</phase>
      <goals>
       <goal>configure</goal>
      </goals>
      <configuration>
       <container>
        <containerId>jboss4x</containerId>
        <home>${jboss4x.home}</home>
        <output>${project.build.directory}/container.log</output>
        <append>true</append>
        <log>${project.build.directory}/cargo.log</log>
       </container>
       <configuration>
        <type>standalone</type>
        <home>${project.build.directory}/jboss4x</home>
        <properties>
         <cargo.jvmargs>
          -Xdebug -Xnoagent
          -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
         </cargo.jvmargs>
         <cargo.logging>high</cargo.logging>
         <cargo.servlet.port>8982</cargo.servlet.port>
        </properties>
        <deployables>
         <deployable>
          <groupId>your.group.id</groupId>
          <artifactId>your-ear</artifactId>
          <type>ear</type>
         </deployable>
        </deployables>
       </configuration>
      </configuration>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>
</project>

Monday, February 26, 2007

DBUnit and RDMS with special types

If you are using DBUnit for testing your data access layer, and your scheme uses some unusual data types, you need to use data type factories but it won't work if you are about to use at the same time FlatXmlDataSet.
You are going to get errors like:
WARNING - table_name.column_name data type (1111, ëbití) not recognized and will be ignored. See FAQ for more information.
Here is solution that I haven't found on google:
Override default implementation of protected IDatabaseTester newDatabaseTester() throws Exception from DBTestCase to something like this:

protected IDatabaseTester newDatabaseTester() throws Exception {
return new PropertiesBasedJdbcDatabaseTester() {
public IDatabaseConnection getConnection() throws Exception {
IDatabaseConnection databaseConnection = super.getConnection();
DatabaseConfig databaseConfig = databaseConnection.getConfig();
databaseConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
return databaseConnection;
}
};
}



Where you should use suitable for your database DataTypeFactory.