• 0.10.1

Integration Testing of DynamoDB

First, configure maven-dependency-plugin to unpack DynamoDB Local ZIP archive (it is in Maven Central):

<project>
  <plugins>
    <plugin>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.8</version>
      <executions>
        <execution>
          <id>unpack-dynamodb-local</id>
          <goals>
            <goal>unpack</goal>
          </goals>
          <configuration>
            <artifactItems>
              <artifactItem>
                <groupId>com.jcabi</groupId>
                <artifactId>DynamoDBLocal</artifactId>
                <version>2013-09-12</version>
                <type>zip</type>
                <outputDirectory>${project.build.directory}/dynamodb-dist</outputDirectory>
                <overWrite>false</overWrite>
              </artifactItem>
            </artifactItems>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
  [...]
</project>

This example uses version 2013-09-12, which is the first one (and the oldest one). Full list of currently packaged and supported versions is here.

Then, add build-helper-maven-plugin to reserve a random TCP port for DynamoDB Local running instance:

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <id>reserver-dynamodb-port</id>
            <goals>
              <goal>reserve-network-port</goal>
            </goals>
            <configuration>
              <portNames>
                <portName>dynamodblocal.port</portName>
              </portNames>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

And now, configure jcabi-dynamodb-maven-plugin:

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>com.jcabi</groupId>
        <artifactId>jcabi-dynamodb-maven-plugin</artifactId>
        <version>0.10.1</version>
        <executions>
          <execution>
            <id>dynamodb-integration-test</id>
            <goals>
              <goal>start</goal>
              <goal>stop</goal>
            </goals>
            <configuration>
              <port>${dynamodblocal.port}</port>
              <dist>${project.build.directory}/dynamodb-dist</dist>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Now you need to know this temporary port number in your integration tests:

<project>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-failsafe-plugin</artifactId>
          <configuration>
            <systemPropertyVariables>
              <dynamodb.port>${dynamodblocal.port}</dynamodb.port>
            </systemPropertyVariables>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
  [...]
</project>

In your integration tests make sure that you set a correct entry point for AWS Dynamo:

public class FooITCase {
  private static final String PORT = System.getProperty("dynamodb.port");
  @Test
  public void worksWithAwsDynamoDb() {
    AmazonDynamoDB aws = new AmazonDynamoDBClient(
      new BasicAWSCredentials("", "")
    );
    aws.setEndpoint(String.format("http://localhost:%s", FooTest.PORT));
    // and now your code
  }
}

Cutting Edge Version

If you want to use current version of the product, you can do it with this configuration in your pom.xml:

<pluginRepositories>
  <pluginRepository>
    <id>oss.sonatype.org</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
  </pluginRepository>
</pluginRepositories>
<build>
  <plugins>
    <plugin>
      <groupId>com.jcabi</groupId>
      <artifactId>jcabi-dynamodb-maven-plugin</artifactId>
      <version>1.0-SNAPSHOT</version>
      [...]
    </plugin>
  </plugins>
</build>