Integration Testing
Integration tests are used to test more complex scenarios, examining the interaction between different components of the system. In our case, they are employed to test Provisioned IM integration entities defined in the repo directory. The core class of an integration test is IntegrationTestSpecification
.
During the test startup, the IM context is created, and entities are loaded from the repo directory. You can define which entities are part of the test, including all entities or some subset. This is achieved by using the seedEntities
method. If no entities are specified, all entities are loaded.
How to Use an Integration Test
Let's examine an example of an integration test. In this scenario, the test focuses on a route that reads products from a CSV file, utilizes a product mapper to map the CSV data to a list of products, and subsequently invokes a partition endpoint with the appropriate payload.
class FileRouteGitTest extends IntegrationTestSpecification {
def "should load data from csv to pricefx partition"() {
given: 'mock pricefx endpoint and seed entities'
mockPost('/pricefx/test-partition/loaddata/P')
seedProperty("data.directory", temporaryFolder.toString())
seedEntities([routePrn("load-products-route.xml"), mapperPrn("product-mapper.xml")])
when: 'csv file is created in data directory'
seedFile("data/products/products.csv")
then: 'verify that route converts csv to json and sends it to pricefx'
def conditions = new PollingConditions(timeout: 10)
conditions.eventually {
verifyPost("/pricefx/test-partition/loaddata/P", 1,
expectedResponse("requests/load-products-request.json"))
}
}
}
How to Test a Bean
class BeansGitTest extends IntegrationTestSpecification {
@Autowired
private CamelContext context
def "should deploy specific route and beans and process it"() {
given:
seedEntities([beanPrn("example-beans.xml"),routePrn("test-route5.xml")])
when:
Exchange exchange = sendBody("direct:test-route5", "Michal")
then:
context.getEndpoint("mock:end").receivedExchanges.size() == 1
exchange.getIn().getBody() == "[foo, bar]"
}
}
How to Test a Class
class ClassesGitTest extends IntegrationTestSpecification {
@Autowired
private CamelContext context
def "should deploy all classes and routes except two and process it"() {
given:
seedEntities([], [routePrn("import-csv-from-ftp-to-pricefx.xml"), routePrn("load-products-route.xml")])
when:
Exchange exchange = sendBody("direct:test-route3", "John")
Exchange exchange2 = sendBody("direct:test-route4", "Hello")
then:
context.getEndpoint("mock:end").receivedExchanges.size() == 2
exchange.getIn().getBody() == "Hello John"
exchange2.getIn().getBody() == "Hello"
}
def "should deploy specific route and classes and process it"() {
given:
seedEntities([classPrn("ExampleProcessor.groovy"),routePrn("test-route3.xml")])
when:
Exchange exchange = sendBody("direct:test-route3", "Michal")
then:
context.getEndpoint("mock:end").receivedExchanges.size() == 1
exchange.getIn().getBody() == "Hello Michal"
}
}
How to Test a Mapper
How to Test a Route Consuming Data from SFTP
We have implemented the SftpTestSpecification
class for handling SFTP processing. This class, during the test startup, initiates an SFTP server and establishes a connection named default-sftp-connection
. The primary purpose of introducing the SftpTestSpecification
is to simplify and standardize the testing process for SFTP routes.
How to Use Properties
All properties from application.properties are loaded during a test startup. If you want to override a property or define a new one, you can do it by the seedProperty
method.
How to Use seedEntities
The seedEntities
method has two parameters – includeOnly
and exclude
. The includeOnly
parameter is used to specify which entities should be included in the test, exclude
is used to specify which entities should be excluded from the test.
IntegrationManager version 5.8.0