Skip to content

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.

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 MockMvc with Spring Security filters active.
  • Mocks OAuth2AuthorizedClientManager and JwtDecoder out-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 SpringTestConfiguration for 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 a JwtAuthenticationToken principal with configurable roles, subject, and claims matching KeycloakJwtAuthenticationConverter expectations.
  • TestUtil (one.aircommerce.library.test.support.util.TestUtil): Helper methods for loading JSON/XML test fixtures from src/test/resources/ and performing assertions.
  • Bundled Dependencies (Inherited automatically at test scope):
    • spring-boot-starter-webmvc-test & spring-boot-starter-security-test
    • wiremock-spring-boot (@EnableWireMock / @ConfigureWireMock for stubbing downstream REST and SOAP services such as iFlyRes)
    • spring-boot-testcontainers & testcontainers-junit-jupiter
@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
}
}

None

None