### Verifying Docker Installation (Shell) Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-1-getting-started.md This command verifies that Docker is correctly installed and running on your machine by displaying its client and server versions. It helps confirm the Docker environment is ready for Testcontainers. ```shell $ docker version ``` -------------------------------- ### Compiling Project Dependencies with Maven (Shell) Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-1-getting-started.md This command uses the Maven Wrapper to compile the project and download all necessary dependencies. It ensures that the project is set up correctly before running the application. ```shell ./mvnw compile ``` -------------------------------- ### Cloning the Workshop Project (Shell) Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-1-getting-started.md This command clones the 'java-local-development-workshop' repository from GitHub, downloading all project files to the local machine. This is the first step to get the workshop's source code. ```shell git clone https://github.com/testcontainers/java-local-development-workshop.git ``` -------------------------------- ### Pre-pulling Required Docker Images (Shell) Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-1-getting-started.md These commands pre-pull several Docker images (PostgreSQL, LocalStack, Microcks, Kafka, Schema Registry, Control Center) to the local Docker environment. This is an optional step to save time and bandwidth during the workshop, especially with slow internet connections. ```shell docker pull postgres:16-alpine docker pull localstack/localstack:2.3 docker pull quay.io/microcks/microcks-uber:1.8.1 docker pull confluentinc/cp-kafka:7.5.0 docker pull confluentinc/cp-schema-registry:7.5.0 docker pull confluentinc/cp-enterprise-control-center:7.5.0 ``` -------------------------------- ### Example Product API Response Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This JSON object represents a typical successful response from the product API when querying for a product by its code. It includes details such as product ID, code, name, description, image URL, price, and availability status. ```json { "id":1, "code":"P101", "name":"Product P101", "description":"Product P101 description", "imageUrl":"http://127.0.0.1:60739/product-images/P101.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&...", "price":34.0, "available":true } ``` -------------------------------- ### Starting Spring Boot Application with Testcontainers Configuration - Java Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This class provides a `main` method to start the Spring Boot application. It uses `SpringApplication.from(Application::main).with(ContainersConfig.class).run(args)` to ensure that the `ContainersConfig` class, which defines the Testcontainers beans, is included in the application context during startup, enabling the use of configured containers. ```Java package com.testcontainers.catalog; import org.springframework.boot.SpringApplication; public class TestApplication { public static void main(String[] args) { SpringApplication //note that we are starting our actual Application from within our TestApplication .from(Application::main) .with(ContainersConfig.class) .run(args); } } ``` -------------------------------- ### Retrieving Product by Code using cURL Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This `curl` command demonstrates how to make a GET request to the product API endpoint to retrieve details for a specific product using its code. It targets `http://localhost:8080/api/products/P101`, expecting product information as a response. ```shell curl -X "GET" 'http://localhost:8080/api/products/P101' ``` -------------------------------- ### Creating a New Product via API - Java Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-5-write-tests.md This Java test method (`createProductSuccessfully`) demonstrates how to create a new product by sending a POST request to the `/api/products` endpoint. It uses RestAssured to construct a JSON payload with a unique product code, asserts a 201 (Created) status code, and verifies the 'Location' header in the response, indicating successful resource creation. It relies on `BaseIntegrationTest` for setup and `test-data.sql` for initial data. ```Java package com.testcontainers.catalog.api; import com.testcontainers.catalog.BaseIntegrationTest; import io.restassured.http.ContentType; import org.junit.jupiter.api.Test; import org.springframework.test.context.jdbc.Sql; import java.util.UUID; import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.endsWith; @Sql("/test-data.sql") class ProductControllerTest extends BaseIntegrationTest { @Test void createProductSuccessfully() { String code = UUID.randomUUID().toString(); given().contentType(ContentType.JSON) .body( """ { "code": "%s", "name": "Product %s", "description": "Product %s description", "price": 10.0 } """ .formatted(code, code, code)) .when() .post("/api/products") .then() .statusCode(201) .header("Location", endsWith("/api/products/%s".formatted(code))); } } ``` -------------------------------- ### Invoking Product API for P101 with cURL Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This cURL command sends a GET request to the local application's `/api/products/P101` endpoint. This is used to test the integration with the mocked inventory service, expecting a successful response for product P101, which has a quantity of 25 as defined in the OpenAPI mock. ```shell curl -X "GET" 'http://localhost:8080/api/products/P101' ``` -------------------------------- ### Invoking Product API for P103 with cURL Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This cURL command sends a GET request to the local application's `/api/products/P103` endpoint. This tests the mocked inventory service's behavior for product P103, which is configured in the OpenAPI definition to have a quantity of 0, thus expecting `available: false` in the response. ```shell curl -X "GET" 'http://localhost:8080/api/products/P103' ``` -------------------------------- ### Defining Inventory Service OpenAPI Specification for Microcks Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This YAML snippet defines an OpenAPI 3.0.2 specification for an 'Inventory Service'. It includes paths for `/api/inventory/{code}` with GET operations, defining parameters, responses (200 and 500), and examples for different product codes (P101, P102, P103). This specification is used by Microcks to generate mock responses for the inventory service. ```yaml openapi: 3.0.2 info: title: Inventory Service version: 1.0 description: API definition of Inventory Service license: name: MIT License url: https://opensource.org/licenses/MIT paths: /api/inventory/{code}: get: parameters: - name: code description: product code schema: type: string in: path required: true examples: P101: value: P101 P102: value: P102 P103: value: P103 responses: "200": content: application/json: schema: $ref: '#/components/schemas/Product' examples: P101: value: code: P101 quantity: 25 P103: value: code: P103 quantity: 0 "500": content: application/json: schema: type: string examples: P102: value: "" components: schemas: Product: title: Root Type for Product type: object properties: code: description: Code of this product type: string quantity: description: Remaining quantity for this product type: number required: - code - quantity additionalProperties: false ``` -------------------------------- ### Displaying Application Startup Failure (Shell) Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This shell output shows a common error when a Spring Boot application fails to start due to missing database configuration, specifically a 'DataSource' URL. It indicates that no embedded database was found and no suitable driver class could be determined, prompting the user to add an embedded database or activate a profile with database settings. ```Shell *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active). Process finished with exit code 0 ``` -------------------------------- ### Setting Up Common Integration Test Base Class - Java Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-5-write-tests.md This abstract class provides a common setup for integration tests, leveraging Spring Boot's test capabilities and Testcontainers. It configures a random port for the web environment, sets the Kafka consumer offset to 'earliest', and exposes the application's dynamic port to Testcontainers for host access, ensuring all required containers are initialized via `ContainersConfig`. ```Java package com.testcontainers.catalog; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import com.testcontainers.catalog.ContainersConfig; import io.restassured.RestAssured; import org.junit.jupiter.api.BeforeEach; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.context.annotation.Import; import org.testcontainers.Testcontainers; @SpringBootTest( webEnvironment = RANDOM_PORT, properties = { "spring.kafka.consumer.auto-offset-reset=earliest" }) @Import(ContainersConfig.class) public abstract class BaseIntegrationTest { @LocalServerPort private int port; @BeforeEach void setUpBase() { RestAssured.port = port; Testcontainers.exposeHostPorts(port); } } ``` -------------------------------- ### Verifying Application Context Load - Java Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-5-write-tests.md This test class extends `BaseIntegrationTest` to inherit the common container setup and Spring Boot context configuration. Its primary purpose is to verify that the application context successfully loads and all required services (PostgreSQL, Kafka, LocalStack, Microcks) are properly initialized and available, indicated by the `contextLoads()` method passing without errors. ```Java package com.testcontainers.catalog; import org.junit.jupiter.api.Test; class ApplicationTests extends BaseIntegrationTest { @Test void contextLoads() {} } ``` -------------------------------- ### Retrieving Product by Code via API - Java Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-5-write-tests.md This Java test method (`getProductByCodeSuccessfully`) verifies the functionality of retrieving product information by its unique code. It sends a GET request to `/api/products/{code}` using RestAssured, asserts a 200 (OK) status code, and then extracts the response body into a `Product` object. Finally, it asserts that the retrieved product's code, name, and description match the expected values, ensuring data integrity. It depends on `BaseIntegrationTest` and `test-data.sql` for initial data. ```Java package com.testcontainers.catalog.api; import com.testcontainers.catalog.BaseIntegrationTest; import com.testcontainers.catalog.domain.ProductService; import com.testcontainers.catalog.domain.models.Product; import io.restassured.http.ContentType; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.test.context.jdbc.Sql; import java.io.File; import java.io.IOException; import java.time.Duration; import java.util.Optional; import java.util.UUID; import static io.restassured.RestAssured.given; import static java.util.concurrent.TimeUnit.SECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.endsWith; @Sql("/test-data.sql") class ProductControllerTest extends BaseIntegrationTest { @Autowired ProductService productService; @Test void getProductByCodeSuccessfully() { String code = "P101"; Product product = given().contentType(ContentType.JSON) .when() .get("/api/products/{code}", code) .then() .statusCode(200) .extract() .as(Product.class); assertThat(product.code()).isEqualTo(code); assertThat(product.name()).isEqualTo("Product %s".formatted(code)); assertThat(product.description()).isEqualTo("Product %s description".formatted(code)); } } ``` -------------------------------- ### Creating a Product via REST API - Shell Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This `curl` command sends a POST request to the `/api/products` endpoint to create a new product. It includes a JSON payload with product details such as `code`, `name`, `description`, and `price`. The expected output is an HTTP 201 Created status with a Location header indicating the newly created resource. ```Shell curl -v -X "POST" 'http://localhost:8080/api/products' \ --header 'Content-Type: application/json' \ --data '{ "code": "P201", "name": "Product P201", "description": "Product P201 description", "price": 24.0 }' ``` -------------------------------- ### Connecting to PostgreSQL via psql (Shell) Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-4-connect-to-services.md This shell command demonstrates how to connect to the PostgreSQL database using the `psql` client. It specifies the host as `localhost`, port as `5432`, user as `test`, and database as `test`, assuming the fixed port mapping is active and default credentials are used. ```shell psql -h localhost -p 5432 -U test -d test ``` -------------------------------- ### Expected JSON Response for Product P103 Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This JSON snippet represents the expected response for product P103, demonstrating the mocked behavior where the product is `available: false` due to its quantity being set to 0 in the OpenAPI definition used by Microcks. This confirms the successful mocking of inventory service logic. ```json { "id":3, "code":"P103", "name":"Product P103", "description":"Product P103 description", "imageUrl":null, "price":15.0, "available":false } ``` -------------------------------- ### Querying Products Table in PostgreSQL (SQL) Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-4-connect-to-services.md This SQL query retrieves all columns from the `products` table within the `public` schema of the `test` database. It's used to verify data after successfully connecting to the PostgreSQL instance, typically to check if products exist or have been inserted. ```sql select * from test.public.products; ``` -------------------------------- ### Inserting Test Data for Product API Tests - SQL Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-5-write-tests.md This SQL snippet is used to prepare the database for integration tests. It first clears existing product data and then inserts three sample product records (P101, P102, P103) into the `products` table, ensuring a consistent and known state for subsequent tests. ```SQL DELETE FROM products; insert into products(code, name, description, image, price) values ('P101','Product P101','Product P101 description', null, 34.0), ('P102','Product P102','Product P102 description', null, 25.0), ('P103','Product P103','Product P103 description', null, 15.0) ; ``` -------------------------------- ### Expected JSON Response for Product P101 Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This JSON snippet represents the expected successful response when querying the `/api/products/P101` endpoint after Microcks has mocked the inventory service. It shows details for product P101, including `available: true`, reflecting the mocked quantity of 25. ```json { "id":1, "code":"P101", "name":"Product P101", "description":"Product P101 description", "imageUrl":null, "price":34.0, "available":true } ``` -------------------------------- ### Configuring MicrocksContainer in Java with Testcontainers Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This Java code snippet demonstrates how to configure a `MicrocksContainer` within a Spring `@TestConfiguration` class. It initializes the container with a specific Microcks image, loads the `inventory-openapi.yaml` as main artifacts, and enables host access. It then registers the Microcks mock endpoint for the 'Inventory Service' (version 1.0) as a dynamic property `application.inventory-service-url`, allowing the application to route inventory service calls to the mocked endpoint. ```java package com.testcontainers.catalog; import io.github.microcks.testcontainers.MicrocksContainer; @TestConfiguration(proxyBeanMethods = false) public class ContainersConfig { // [...] @Bean MicrocksContainer microcksContainer(DynamicPropertyRegistry registry) { MicrocksContainer microcks = new MicrocksContainer("quay.io/microcks/microcks-uber:1.8.1") .withMainArtifacts("inventory-openapi.yaml") .withAccessToHost(true); registry.add( "application.inventory-service-url", () -> microcks.getRestMockEndpoint("Inventory Service", "1.0")); return microcks; } } ``` -------------------------------- ### Uploading Product Image via REST API - Shell Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This `curl` command sends a POST request to the `/api/products/{productCode}/image` endpoint to upload an image file. It uses the `--form` option to send `src/test/resources/P101.jpg` as a multipart file. The expected output is a JSON response indicating the filename and success status of the upload. ```Shell curl -X "POST" 'http://localhost:8080/api/products/P101/image' \ --form 'file=@"src/test/resources/P101.jpg"' ``` -------------------------------- ### Uploading Product Image via API - Java Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-5-write-tests.md This Java test method (`shouldUploadProductImageSuccessfully`) validates the product image upload functionality. It sends a multipart POST request to `/api/products/{code}/image` with a sample image file (`P101.jpg`). The test asserts a 200 status code, confirms the response body indicates success, and uses Awaitility to asynchronously verify that the product's `imageUrl` is updated in the database after the upload process completes. ```Java package com.testcontainers.catalog.api; import com.testcontainers.catalog.BaseIntegrationTest; import com.testcontainers.catalog.domain.ProductService; import com.testcontainers.catalog.domain.models.Product; import io.restassured.http.ContentType; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.test.context.jdbc.Sql; import java.io.File; import java.io.IOException; import java.time.Duration; import java.util.Optional; import java.util.UUID; import static io.restassured.RestAssured.given; import static java.util.concurrent.TimeUnit.SECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.endsWith; @Sql("/test-data.sql") class ProductControllerTest extends BaseIntegrationTest { @Autowired ProductService productService; @Test void shouldUploadProductImageSuccessfully() throws IOException { String code = "P101"; File file = new ClassPathResource("P101.jpg").getFile(); Optional product = productService.getProductByCode(code); assertThat(product).isPresent(); assertThat(product.get().imageUrl()).isNull(); given().multiPart("file", file, "multipart/form-data") .contentType(ContentType.MULTIPART) .when() .post("/api/products/{code}/image", code) .then() .statusCode(200) .body("status", endsWith("success")) .body("filename", endsWith("P101.jpg")); await().pollInterval(Duration.ofSeconds(3)).atMost(10, SECONDS).untilAsserted(() -> { Optional optionalProduct = productService.getProductByCode(code); assertThat(optionalProduct).isPresent(); assertThat(optionalProduct.get().imageUrl()).isNotEmpty(); }); } } ``` -------------------------------- ### Adding Testcontainers Dependencies (Maven XML) Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This XML snippet for pom.xml demonstrates how to include essential Testcontainers dependencies for Spring Boot development. It adds 'spring-boot-testcontainers' for Spring Boot integration, and specific modules for 'postgresql', 'kafka', and 'localstack', all with a 'test' scope, enabling automatic service provisioning during local development. ```XML org.springframework.boot spring-boot-testcontainers test org.testcontainers postgresql test org.testcontainers kafka test org.testcontainers localstack test ``` -------------------------------- ### Configuring Fixed Port for PostgreSQL with Testcontainers Desktop (TOML) Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-4-connect-to-services.md This TOML configuration maps the PostgreSQL container's internal port 5432 to the host machine's port 5432, allowing consistent access to the database. It targets containers with the image name 'postgres', ensuring the mapping applies specifically to PostgreSQL instances managed by Testcontainers Desktop. ```toml ports = [ {local-port = 5432, container-port = 5432}, ] selector.image-names = ["postgres"] ``` -------------------------------- ### Adding API Testing and Asynchronous Process Dependencies (Maven XML) Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This XML snippet for pom.xml adds 'rest-assured' for robust API testing and 'awaitility' for simplifying the testing of asynchronous operations. Both dependencies are scoped as 'test', indicating their primary use in the testing phase of the application. ```XML io.rest-assured rest-assured test org.awaitility awaitility test ``` -------------------------------- ### Spring ResourceAccessException in Product Service Logs Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This log snippet shows a `ResourceAccessException` occurring in the `DefaultProductService` when it attempts to call the inventory service. The error indicates an I/O problem, specifically that the inventory service at `http://localhost:8081/api/inventory/P101` is unreachable, leading to a failure in retrieving product availability. ```java com.testcontainers.catalog.domain.internal.DefaultProductService - Error while calling inventory service org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8081/api/inventory/P101": null at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.createResourceAccessException(DefaultRestClient.java:489) at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchangeInternal(DefaultRestClient.java:414) at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.retrieve(DefaultRestClient.java:380) ... ... at jdk.proxy4/jdk.proxy4.$Proxy179.getInventory(Unknown Source) at com.testcontainers.catalog.domain.internal.DefaultProductService.isProductAvailable(DefaultProductService.java:68) at com.testcontainers.catalog.domain.internal.DefaultProductService.toProduct(DefaultProductService.java:84) at java.base/java.util.Optional.map(Optional.java:260) ``` -------------------------------- ### Asserting Product Properties in Java Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-5-write-tests.md This snippet demonstrates basic assertions using AssertJ to verify the price and availability of a Product object. It represents a common pattern for manual property validation in unit or integration tests, often used when automated schema validation is not in place. ```java assertThat(product.price().compareTo(new BigDecimal("34.0"))).isEqualTo(0); assertThat(product.available()).isTrue(); ``` -------------------------------- ### Configuring Testcontainers for Spring Boot Tests - Java Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This class defines Spring `@Bean` methods for `PostgreSQLContainer`, `KafkaContainer`, and `LocalStackContainer` to be used in Spring Boot tests. It leverages `@ServiceConnection` for automatic connection details for PostgreSQL and Kafka, and `DynamicPropertyRegistry` for LocalStack to configure AWS properties. It also includes an `ApplicationRunner` to initialize AWS resources like S3 buckets upon application startup. ```Java package com.testcontainers.catalog; import static org.testcontainers.utility.DockerImageName.parse; import com.testcontainers.catalog.domain.FileStorageService; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.DependsOn; import org.springframework.test.context.DynamicPropertyRegistry; import org.testcontainers.containers.KafkaContainer; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.localstack.LocalStackContainer; @TestConfiguration(proxyBeanMethods = false) public class ContainersConfig { @Bean @ServiceConnection PostgreSQLContainer postgresContainer() { return new PostgreSQLContainer<>(parse("postgres:16-alpine")); } @Bean @ServiceConnection KafkaContainer kafkaContainer() { return new KafkaContainer(parse("confluentinc/cp-kafka:7.5.0")); } @Bean("localstackContainer") LocalStackContainer localstackContainer(DynamicPropertyRegistry registry) { LocalStackContainer localStack = new LocalStackContainer(parse("localstack/localstack:2.3")); registry.add("spring.cloud.aws.credentials.access-key", localStack::getAccessKey); registry.add("spring.cloud.aws.credentials.secret-key", localStack::getSecretKey); registry.add("spring.cloud.aws.region.static", localStack::getRegion); registry.add("spring.cloud.aws.endpoint", localStack::getEndpoint); return localStack; } @Bean @DependsOn("localstackContainer") ApplicationRunner awsInitializer(ApplicationProperties properties, FileStorageService fileStorageService) { return args -> fileStorageService.createBucket(properties.productImagesBucketName()); } } ``` -------------------------------- ### Adding Microcks Testcontainers Dependency to Maven Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-3-local-development-environment.md This XML snippet adds the `microcks-testcontainers` dependency to the `pom.xml` file, scoped for testing. This dependency is required to use Microcks with Testcontainers for mocking services in a local development environment. ```xml io.github.microcks microcks-testcontainers 0.2.4 test ``` -------------------------------- ### Checking OpenAPI Conformance with Microcks Testcontainers in Java Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-5-write-tests.md This test class illustrates how to use MicrocksContainer to automatically validate a Spring Boot application's API responses against an OpenAPI definition. It shows importing the OpenAPI artifact, configuring a TestRequest for schema validation, and asserting the success of the conformance test, providing a robust way to ensure API contract adherence. ```java import io.github.microcks.testcontainers.MicrocksContainer; import io.github.microcks.testcontainers.model.TestRequest; import io.github.microcks.testcontainers.model.TestResult; import io.github.microcks.testcontainers.model.TestRunnerType; import io.restassured.RestAssured; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.test.context.jdbc.Sql; @Sql("/test-data.sql") class ProductControllerTest extends BaseIntegrationTest { @Autowired MicrocksContainer microcks; @Test void checkOpenAPIConformance() throws Exception { microcks.importAsMainArtifact(new ClassPathResource("catalog-openapi.yaml").getFile()); TestRequest testRequest = new TestRequest.Builder() .serviceId("Catalog Service:1.0") .runnerType(TestRunnerType.OPEN_API_SCHEMA.name()) .testEndpoint("http://host.testcontainers.internal:" + RestAssured.port) .build(); TestResult testResult = microcks.testEndpoint(testRequest); assertThat(testResult.isSuccess()).isTrue(); } } ``` -------------------------------- ### Inspecting Microcks TestResult Object in Java Source: https://github.com/testcontainers/java-local-development-workshop/blob/main/step-5-write-tests.md This snippet demonstrates how to serialize and print the TestResult object obtained from Microcks using Jackson's ObjectMapper. It's useful for detailed inspection and debugging of the test outcomes, allowing developers to see the full structure and content of the test results. ```java // You may inspect complete response object with following: ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(testResult)); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.