Overview
IM integration tests use Spock framework with IntegrationTestSpecification as the base class. Tests start a real Camel context with WireMock for HTTP mocking.
Test File: src/test/groovy/com/example/ImportProductsSpec.groovy
Groovy
import com.pricefx.integrationmanager.testing.IntegrationTestSpecification
class ImportProductsSpec extends IntegrationTestSpecification {
def "should import products from CSV file into Pricefx"() {
given: "a CSV file in the import directory"
def csvContent = """sku,label,currency,attribute1
PROD-001,Widget A,USD,9.99
PROD-002,Widget B,USD,14.99"""
writeToImportDirectory("products.csv", csvContent)
and: "Pricefx loaddata endpoint is mocked"
mockPricefxLoadData(objectType: "P") {
respondWith(status: 200, body: '{"response":{"data":[]}}')
}
when: "the import route runs"
triggerRoute("importProducts")
waitForRouteCompletion("importProducts")
then: "loaddata was called with the correct payload"
verifyPricefxLoadDataCalled(objectType: "P", times: 1)
def sentData = getCapturedLoadDataPayload(objectType: "P")
sentData.size() == 2
sentData[0].sku == "PROD-001"
sentData[0].label == "Widget A"
sentData[1].sku == "PROD-002"
}
def "should skip rows with missing SKU"() {
given: "a CSV file with one row missing SKU"
def csvContent = """sku,label,currency
,Empty SKU Row,USD
PROD-003,Valid Row,USD"""
writeToImportDirectory("products.csv", csvContent)
and: "Pricefx loaddata endpoint is mocked"
mockPricefxLoadData(objectType: "P") {
respondWith(status: 200, body: '{"response":{"data":[]}}')
}
when: "the import route runs"
triggerRoute("importProducts")
waitForRouteCompletion("importProducts")
then: "only the valid row was loaded"
def sentData = getCapturedLoadDataPayload(objectType: "P")
sentData.size() == 1
sentData[0].sku == "PROD-003"
}
}
Running Tests
Bash
JAVA_HOME=/opt/homebrew/Cellar/openjdk@17/17.0.14/libexec/openjdk.jdk/Contents/Home \
mvn test -pl <your-module>
Key Rules
-
Always use
IntegrationTestSpecificationas the base class — never mock the IM framework -
Tests must use real Camel routes — WireMock handles HTTP, not route logic
-
Each test should verify the exact payload sent to Pricefx, not just that it was called
-
Use
given/when/thenblocks for readability