Skip to main content

Test and Validate

This guide explains how to test and validate a new or existing connector to ensure it functions correctly before deployment.

Testing Overview

Unit Tests

Test individual components and routes in isolation

Integration Tests

Test connector interactions with external services

Contract Tests

Validate API contracts and OpenAPI specifications

End-to-End Tests

Test complete flows from request to response

Run Unit Tests

Unit tests are supported within connectors through the camel-test-junit5 library. This test library is available for every connector from the grandcentral-bom.

Running Tests with Maven

Execute unit tests using Maven:
mvn test

Running Specific Tests

Run a specific test class:
mvn test -Dtest=GenericApiConnectorTest
Run specific test methods:
mvn test -Dtest=GenericApiConnectorTest#testSuccessfulRequest

Unit Test Examples

For comprehensive unit test examples, see the Grand Central connector template repository.

Example: Basic Route Test

@QuarkusTest
public class GenericApiConnectorTest {

    @Test
    public void testSuccessfulRequest() {
        given()
            .contentType(ContentType.JSON)
            .body("{\"name\": \"test\"}")
        .when()
            .post("/api/connector/process")
        .then()
            .statusCode(200)
            .body("status", equalTo("success"));
    }
}

Example: Mock External Service

@QuarkusTest
public class ExternalServiceTest {

    @InjectMock
    ExternalServiceClient externalService;

    @Test
    public void testWithMockedService() {
        // Mock external service response
        when(externalService.getData())
            .thenReturn(new ResponseData("mocked"));

        given()
            .get("/api/data")
        .when()
        .then()
            .statusCode(200)
            .body("data", equalTo("mocked"));
    }
}

Test Configuration

Test Properties

Configure test-specific properties in src/test/resources/application.properties:
# Test profile
quarkus.test.profile=test

# Mock external endpoints
connector.baseUrl=http://localhost:8081
connector.mock.enabled=true

# Logging for tests
quarkus.log.level=DEBUG
quarkus.log.category."com.backbase.gc".level=DEBUG

Test Profiles

Create custom test profiles for different scenarios:
@TestProfile(CustomTestProfile.class)
public class CustomConnectorTest {
    // Test implementation
}

public class CustomTestProfile implements QuarkusTestProfile {
    @Override
    public Map<String, String> getConfigOverrides() {
        return Map.of(
            "connector.baseUrl", "http://test-server:8080",
            "connector.timeout", "5000"
        );
    }
}

Integration Testing

WireMock for External Services

Use WireMock to mock external HTTP services:
@QuarkusTest
@QuarkusTestResource(WireMockExtensions.class)
public class IntegrationTest {

    @InjectWireMock
    WireMockServer wireMock;

    @Test
    public void testExternalApiCall() {
        // Stub external API
        wireMock.stubFor(
            get(urlEqualTo("/external/api"))
                .willReturn(aResponse()
                    .withStatus(200)
                    .withBody("{\"result\": \"success\"}")
                )
        );

        // Test connector call
        given()
            .get("/api/process")
        .then()
            .statusCode(200);
    }
}

API Contract Validation

OpenAPI Specification Validation

Validate that your connector implementation matches the OpenAPI specification:
@Test
public void validateOpenAPIContract() {
    given()
        .get("/q/openapi")
    .then()
        .statusCode(200)
        .body(matchesJsonSchemaInClasspath("openapi-schema.json"));
}

Test Coverage

Generate Coverage Reports

Generate test coverage reports with JaCoCo:
mvn clean verify
View the coverage report at target/site/jacoco/index.html.

Coverage Goals

Aim for the following coverage targets:
  • Line Coverage: Minimum 80%
  • Branch Coverage: Minimum 75%
  • Method Coverage: Minimum 85%

Performance Testing

Load Testing with Gatling

Run performance tests to validate connector behavior under load:
class ConnectorLoadTest extends Simulation {
  val httpProtocol = http
    .baseUrl("http://localhost:8080")

  val scn = scenario("Basic Load Test")
    .exec(http("process_request")
      .post("/api/connector/process")
      .body(StringBody("""{"data": "test"}"""))
      .check(status.is(200)))

  setUp(
    scn.inject(
      rampUsers(100) during (60 seconds)
    )
  ).protocols(httpProtocol)
}

Continuous Testing

Running Tests in CI/CD

Include tests in your CI/CD pipeline:
# Example GitHub Actions workflow
name: Test
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v3
        with:
          java-version: '17'
      - name: Run tests
        run: mvn clean verify
      - name: Upload coverage
        uses: codecov/codecov-action@v3

Validation Checklist

Before deploying your connector, ensure:
  • All unit tests pass
  • Coverage meets minimum thresholds
  • Edge cases are covered
  • External service interactions are tested
  • Error scenarios are validated
  • Timeouts and retries work correctly
  • OpenAPI specification is valid
  • Request/response schemas match
  • All endpoints are documented
  • Load tests pass successfully
  • Response times are acceptable
  • Resource usage is within limits

Troubleshooting Tests

Common Issues

Check for environment-specific configurations or dependencies
  • Add proper wait conditions
  • Avoid time-based assertions
  • Use deterministic test data
  • Parallelize test execution
  • Use test profiles to skip heavy tests during development
  • Optimize test setup and teardown

Next Steps

After successfully testing your connector: