Product Acceptance Test

This Product Acceptance Test (PAT) demonstrates one way to validate learned cluster data that is written to the output catalog. For the code, see com.here.platform.examples.p2.PATTest.java.

Running the Test Locally

The following prerequisites apply to running the PAT locally.

  • Prepare your data catalogs before running your PATs.
  • Start the pipeline you are testing at the beginning of a test and stop the pipeline at the end of the test.
  • Since the test publishes the following partition to your input catalog, update the input partition name to ensure it contains a timestamp within the configured window of the pipeline processing logic.

    This partition contains the data that is processed by the pipeline and validated as part of the testing step.

     1475716_20180522155459_20180522153926_20180522155455_10._48.159957275016836_48.080087029569135_12.040017134498243_11.896950104895032
    
  • After the pipeline has finished processing the input data, download the partition "23611423" from the output catalog. The Integration test executable JAR uses this partition as input.

To run the tests from command line, enter the following command.

java -jar  -Dpartition=<output partition path>/23611423 <executable jar path>/p2-learning-processor-standalone-<VERSION>-it-tests.jar

Expected test execution output.

JUnit version 4.12
.
Time: 0.278

OK (1 test)

Running the Test from Jenkins

The "Prepare test catalogs" stage sets up the environment for testing with the following steps:

  • creates input and output catalogs for the test following the recipe from the file deployment.properties
  • reads a cluster data archive partition tile from the file system
  • changes the date to the current date in the file name, which triggers processing
  • loads the partition into the input catalog
    pipeline_config = helper.preparePipelineConfig(pipeline_config_path, path_prefix, deployment)

    def input_partition_id = "1475716_20180522155459_20180522153926_20180522155455_10." +
            "_48.159957275016836_48.080087029569135_12.040017134498243_11.896950104895032"
    def input_partition_file_path = "${WORKSPACE}/test_data/target/dependency/${input_partition_id}"

    // Changing the date to the current date in the file name (which will trigger processing).
    def now = new Date()
    def fileParts = input_partition_id.split("_")
    fileParts[1] = now.format("yyyyMMddHHmmss", TimeZone.getTimeZone('UTC'))
    def partitionID = fileParts.join("_")

    putPartitions(helper, pipeline_config["archive-catalog"], "sdii-data-archive", [partitionID: input_partition_file_path])

The "Run Product Acceptance Tests" stage executes the following steps:

  • retrieves the defined partition for verification by PATTest.
  • executes PATTest to verify the data.
    def output_partitions = ["23611423"]
    getPartitions(helper, pipeline_config["output"], "data-learnings", output_partitions, WORKSPACE)

    // Run tests
    output_partitions.each { partition ->
        sh("java -jar -Dpartition=${WORKSPACE}/${partition} ${WORKSPACE}/${env.PROJECT_ARTIFACT_ID}-${env.PROJECT_VERSION}-it-tests.jar")
    }

Integration Tests Runner

Integration tests are written to execute JUnit tests. PATTestRunner is the entry-point for executing JUnit tests from the executable jar.

import org.junit.runner.JUnitCore;

public class PATTestRunner {
    public static void main(String[] args) {
        JUnitCore.main("com.here.platform.examples.p2.PATTest");
    }
}

Annotate Your Test Classes

import org.junit.experimental.categories.Category;
@Category(IntegrationTest.class)
public class PatTest{

    @Test
    public void outputDataValidationTest() throws Exception {
    }
}

Configure Your Maven Profile to Build the Executable Jar

The Maven assembly plugin must be configured to build an executable JAR that includes all required dependencies.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>${maven-assembly-plugin.version}</version>
    <configuration>
        <descriptors>
            <descriptor>src/test/assembly/it-tests-jar.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.here.platform.examples.p2.PATTestRunner</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </execution>
    </executions>
</plugin>

Configure Assembly Plugin Descriptor File

The assembly descriptor file includes/excludes dependencies and files needed for building the executable JAR.

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>it-tests</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory></outputDirectory>
            <useProjectArtifact>false</useProjectArtifact>
            <!-- we're creating the test-jar as an attachment -->
            <useProjectAttachments>true</useProjectAttachments>
            <useTransitiveFiltering>true</useTransitiveFiltering>
            <includes>
                <include>com.here.platform.examples:automotive-sensor-model</include>
                <include>org.slf4j:slf4j-log4j12</include>
                <include>junit:junit</include>
                <include>com.fasterxml.jackson.datatype:jackson-datatype-jsr310</include>
                <include>commons-io:commons-io</include>
            </includes>
            <unpack>true</unpack>
            <scope>test</scope>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/test-classes</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>**/PATTest*.class</include>
                <include>**/PATTestRunner.class</include>
                <include>**/IntegrationTest.class</include>
            </includes>
            <excludes>
                <exclude>**/clustering/**</exclude>
                <exclude>**/utils/**</exclude>
                <exclude>**/p2/Compiler*</exclude>
            </excludes>
            <useDefaultExcludes>true</useDefaultExcludes>
        </fileSet>
        <fileSet>
            <directory>${project.basedir}/src/main/resources</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>log4j.properties</include>
            </includes>
            <useDefaultExcludes>true</useDefaultExcludes>
        </fileSet>
        <fileSet>
            <directory>${project.basedir}/src/test/resources/inputCatalogFiles</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>1475716_20180522155459_20180522153926_20180522155455_10._48.159957275016836_48.080087029569135_12.040017134498243_11.896950104895032 </include>
            </includes>
            <useDefaultExcludes>true</useDefaultExcludes>
        </fileSet>
    </fileSets>
</assembly>

results matching ""

    No results matching ""