Skip to content

Creating an Integration Test

abmagil edited this page Aug 1, 2013 · 5 revisions

An Integration test consists of running an inference trace combined with a bundle in an automated fashion. The inference trace format supports expected results, which the integration tests framework then verifies if present. This allows verification of the inference process.

Follow the simple steps below to add an integration test.

Add trace file

Add a trace of the activity to this directory:

onebusaway-nyc/onebusaway-nyc-integration-tests/src/integration-test/resources/traces

Go to create a trace to better understand the trace format.

Add GTFS

If the bundle was build with the onebusaway-nyc-admin-webapp, the inputs directory of the bundle associated with this trace will contain the original GTFS. Place the GTFS in a directory named after the bundle ({BUNDLE_NAME}) in this directory:

onebusaway-nyc/onebusaway-nyc-integration-tests/src/integration-test/resources/bundle/gtfs

You may pare down the GTFS to what is appropriate to increase the speed of the integration test.

Add external source data

Occasionally other source data is combined with the GTFS to aid in inference. If any external data is required, add it in a subdirectory of

onebusaway-nyc/onebusaway-nyc-integration-tests/src/integration-test/resources/bundle/

Again, name the directory based on the name of the bundle.

Configure Bundle Build

If this trace uses a bundle not already configured by the build, add the configuration to

onebusaway-nyc/onebusaway-nyc-integration-tests/pom.xml

In Executions, add an execution as in this example:

                    <execution>
                        <id>graph-builder-execution-{BUNDLE_NAME}</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <arguments>
                                <argument>-Xmx1500m</argument><!-- larger than this may fail on 32-bit machines -->
                                <argument>-classpath</argument>
                                <classpath />
                                <argument>-Dlog4j.configuration=log4j-stdout.xml</argument>
                                <argument>-Donebusaway_prefix=${basedir}</argument>
                                <argument>org.onebusaway.transit_data_federation.bundle.FederatedTransitDataBundleCreatorMain</argument>
                                <argument>-onlyIfDoesNotExist</argument>
                                <argument>-additionalResourcesDirectory</argument>
                                <argument>${basedir}/src/integration-test/resources/bundle</argument>
                                <argument>${basedir}/src/integration-test/resources/bundle-{BUNDLE_NAME}.xml</argument>
                                <argument>${project.build.directory}/transit-data-bundle/{BUNDLE_NAME}</argument>
                            </arguments>
                        </configuration>
                    </execution>

Note that the above references a bundle description file that needs to be created:bundle-{BUNDLE_NAME}.xml

Its syntax is below:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!-- Provides support for specifying "${some.java.system.property}" for bean values -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />

    <bean id="bundle" class="org.onebusaway.transit_data_federation.services.FederatedTransitDataBundle">
      <property name="path" value="${bundlePath}" />
    </bean>

    <bean id="nycBundle" class="org.onebusaway.nyc.transit_data_federation.bundle.model.NycFederatedTransitDataBundle">
      <property name="path" value="${bundlePath}" />
    </bean>

    <bean id="gtfs-bundles" class="org.onebusaway.transit_data_federation.bundle.model.GtfsBundles">
        <property name="bundles">
            <list>
                <ref bean="gtfs_1" />
                <ref bean="gtfs_2" />
            </list>
        </property>
    </bean>

    <bean id="gtfs_1" class="org.onebusaway.transit_data_federation.bundle.model.GtfsBundle">
		<property name="defaultAgencyId" value="MTA" /> 
        <property name="path" 
        	value="${onebusaway_prefix}/src/integration-test/resources/bundle/gtfs/{BUNDLE_NAME}/gtfs_1.zip" />
    </bean>
    <bean id="gtfs_2" class="org.onebusaway.transit_data_federation.bundle.model.GtfsBundle">
		<property name="defaultAgencyId" value="MTA" /> 
        <property name="path" 
        	value="${onebusaway_prefix}/src/integration-test/resources/bundle/gtfs/{BUNDLE_NAME}/gtfs_2.zip" />
    </bean>

    <bean id="multiCSVLogger" class="org.onebusaway.nyc.transit_data_federation.bundle.tasks.MultiCSVLogger"/>

    <bean id="clearCSVsTask" class="org.onebusaway.nyc.transit_data_federation.bundle.tasks.ClearCSVTask">
        <property name="logger" ref="multiCSVLogger"/>
    </bean>
    <bean class="org.onebusaway.transit_data_federation.bundle.model.TaskDefinition">
        <property name="taskName" value="clearCSVsTask" />
        <property name="afterTaskName" value="gtfs" />
 	    <property name="beforeTaskName" value="transit_graph" />
        <property name="task" ref="clearCSVsTask" />
    </bean>

    <bean id="checkShapesTask" class="org.onebusaway.nyc.transit_data_federation.bundle.tasks.CheckShapeIdTask">
        <property name="logger" ref="multiCSVLogger"/>
    </bean>
    <bean class="org.onebusaway.transit_data_federation.bundle.model.TaskDefinition">
        <property name="taskName" value="checkShapesTask" />
        <property name="afterTaskName" value="clearCSVsTask" />
 	    <property name="beforeTaskName" value="transit_graph" />
        <property name="task" ref="checkShapesTask" />
    </bean>

<!-- add any external data source integration tasks here -->

<!-- now create a CSV logger to track statistics -->
    <bean id="summarizeCSVTask" class="org.onebusaway.nyc.transit_data_federation.bundle.tasks.SummarizeCSVTask">
        <property name="logger" ref="multiCSVLogger"/>
    </bean>
    <bean class="org.onebusaway.transit_data_federation.bundle.model.TaskDefinition">
        <property name="taskName" value="summarizeCSVTask" />
        <property name="afterTaskName" value="stifLoaderTask" />
 	    <property name="beforeTaskName" value="transit_graph" />
        <property name="task" ref="summarizeCSVTask" />
    </bean>

</beans>

Create test file in location

Create a Java file that extends AbstractTraceRunner in the following location:

onebusaway-nyc/onebusaway-nyc-integration-tests/src/test/java/org/onebusaway/nyc/integration_tests/vehicle_tracking_webapp/cases

of format:

package org.onebusaway.nyc.integration_tests.vehicle_tracking_webapp.cases;

import org.onebusaway.nyc.integration_tests.vehicle_tracking_webapp.AbstractTraceRunner;

/**
 * Describe the situation this trace is testing for.
 *
 */
public class Trace_{TRACE_NAME}_IntegrationTest extends AbstractTraceRunner {

  public Trace_{TRACE_NAME}_IntegrationTest() throws Exception {
    super("{TRACE_NAME}.csv");
    // Date format is 2013-07-15T19:40:00EDT
    setBundle("{BUNDLE_NAME}", "{TIME_OF_START_OF_TRACE}");
  }
}

Add to TestSuite

For performance reasons, the integration tests are run in a set order. This minimizes the number of bundle swaps necessary. Due to this however, new integration tests need to be manually added to the TestSuite. they are not discovered automatically.

To add a new integration tests to the TestSuite, edit

onebusaway-nyc/onebusaway-nyc-integration-tests/src/test/java/org/onebusaway/nyc/integration_tests/TestSuite.java

and add the class to the list of SuiteClasses in the appropriate location.

Run integration tests

Test that the work you did above passes:

user@localhost:~src/onebusaway-nyc$ mvn clean install

Commit and push

user@localhost:~src/onebusaway-nyc$ git commit -a -m "adding integration tests {TRACE_NAME}" && git push
Clone this wiki locally