Test Support Library
| GitHub Repository | https://github.com/AirCommerce/library-test-support |
| Maven Coordinates | one.aircommerce.library:test-support-library (Inherited at <scope>test</scope> via boot-base-super-pom) |
The Test Support Library (library-test-support) provides standardized test infrastructure across all AirCommerce microservices. As established in ADR 0005, boot-base-super-pom binds this library strictly to <scope>test</scope>, ensuring that MockMvc, WireMock, and Testcontainers utilities are available to every service’s test suite without leaking into production container images.
Architecture
Section titled “Architecture”Exported Test Harness & Utilities
Section titled “Exported Test Harness & Utilities”1. BaseControllerTest (one.aircommerce.library.test.support.BaseControllerTest)
Section titled “1. BaseControllerTest (one.aircommerce.library.test.support.BaseControllerTest)”Abstract base class for Spring Boot controller and integration tests:
- Pre-configures
MockMvcwith Spring Security filters active. - Mocks
OAuth2AuthorizedClientManagerandJwtDecoderout-of-the-box so downstream Feign client calls inside controller flows automatically receive a mock OAuth2 Bearer access token without requiring a live Keycloak instance. - Imports
SpringTestConfigurationfor consistent Jackson and web test wiring.
2. @WithMockUser Security Context (one.aircommerce.library.test.support.aspect)
Section titled “2. @WithMockUser Security Context (one.aircommerce.library.test.support.aspect)”@WithMockUser&WithMockUserSecurityContextFactory: Custom test security annotation that populates aJwtAuthenticationTokenprincipal with configurable roles, subject, and claims matchingKeycloakJwtAuthenticationConverterexpectations.
3. TestUtil & Bundled Test Frameworks
Section titled “3. TestUtil & Bundled Test Frameworks”TestUtil(one.aircommerce.library.test.support.util.TestUtil): Helper methods for loading JSON/XML test fixtures fromsrc/test/resources/and performing assertions.- Bundled Dependencies (Inherited automatically at
testscope):spring-boot-starter-webmvc-test&spring-boot-starter-security-testwiremock-spring-boot(@EnableWireMock/@ConfigureWireMockfor stubbing downstream REST and SOAP services such asiFlyRes)spring-boot-testcontainers&testcontainers-junit-jupiter
Usage in Microservice Test Suites
Section titled “Usage in Microservice Test Suites”@SpringBootTest@AutoConfigureMockMvc@EnableWireMock(@ConfigureWireMock(name = "iflyres-service", port = 0))class AvailabilityControllerTest extends BaseControllerTest {
@Test @WithMockUser(roles = {"NDC_USER"}) void shouldReturnAvailabilityWhenValidRequest() throws Exception { // MockMvc and OAuth2 token exchange are pre-configured by BaseControllerTest }}Architecture Decisions
Section titled “Architecture Decisions”None
High-Level Designs
Section titled “High-Level Designs”None