Getting started

Mark Adamcin edited this page Nov 4, 2013 · 20 revisions

Activating the Enhanced Integration Test Lifecycle

Step 1: Create an Adobe standard AEM maven project.

You should now have a project consisting of three modules:

  • /pom.xml
  • /bundle/pom.xml
  • /content/pom.xml

Step 2: Edit /content/pom.xml and change the packaging type from content-package to content-package-it

<!-- ====================================================================== -->
<!-- P R O J E C T D E S C R I P T I O N -->
<!-- ====================================================================== -->

<artifactId>my-content</artifactId>
<packaging>content-package-it</packaging>
<name>My Package</name>

Step 3: Add a graniteit-maven-plugin descriptor to your content-package-it module (/content/pom.xml).

<!-- this plugin should already be defined -->
<plugin>
  <groupId>com.day.jcr.vault</groupId>
  <artifactId>content-package-maven-plugin</artifactId>
  <extensions>true</extensions>
  ...
</plugin>
<!-- you will need to add this plugin -->
<plugin>
  <groupId>net.adamcin</groupId>
  <artifactId>graniteit-maven-plugin</artifactId>
  <version>0.8.0</version>
  <extensions>true</extensions>
</plugin>

By default, the graniteit-maven-plugin will attempt to upload your content-package module artifact to http://localhost:4502 using admin:admin credentials during the pre-integration-test phase. This is the default configuration of an AEM Quickstart installation. Just start it up and run the build without any autoInstallPackage profiles to verify that your package is still uploaded by the build:

$ mvn clean verify

... later that day ...

[INFO] --- graniteit-maven-plugin:0.8.0:upload-content-package (default-upload-content-package) @ my-content ---
[INFO] uploading main package...
[INFO] Waiting for writing...
[INFO] Waiting for writing...
[INFO] Waiting for writing...
[INFO] Waiting for writing...
[INFO] Waiting for writing...
[INFO] Waiting for writing...
[INFO] Waiting for writing...
[INFO] Waiting for writing...
[INFO] uploading /projects/my/content/target/my-content-1.0-SNAPSHOT.zip to /etc/packages/com.my/my-content-1.0-SNAPSHOT.zip: Package uploaded
[INFO] installing /etc/packages/com.my/my-content-1.0-SNAPSHOT.zip: Package installed

Step 4: Add JUnit Dependency to the test scope

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.10</version>
    <scope>test</scope>
  </dependency>

  ... [other dependencies in /content/pom.xml] ...
</dependencies>

Step 5: Create your first IT Class to successfully fail the build

Create a new class under content/src/test/java called FailIT.java:

import org.junit.Assert;
import org.junit.Test;

public class FailIT {

    /**
     * Always fails. Useful for making sure your pom configuration works. Not very useful otherwise.
     */
    @Test
    public void fail() {
        Assert.fail("Failing the build to prove a point.");
    }
}

Now run mvn clean verify and see that your project has failed:

... later that day ...
[INFO] --- maven-failsafe-plugin:2.16:verify (default-verify) @ my-content ---
[INFO] Failsafe report directory: /projects/my/content/target/failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.878s
[INFO] Finished at: Thu Oct 31 11:03:42 PDT 2013
[INFO] Final Memory: 21M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.16:verify (default-verify) on project my-content: There are test failures.

By default, the maven-failsafe-plugin will execute all test classes matching the following patterns:

<includes>
  <include>**/IT*.java</include>
  <include>**/*IT.java</include>
  <include>**/*ITCase.java</include>
</includes>

Armed with this knowledge, you may now proceed to create non-trivial integration tests! (Be sure to delete the FailIT test first!)

Next Steps:

  1. Getting Started: The SlingClient
  2. Deploy and execute a Sling Server-Side Test