17.0.1SmileCdrContainer and SmileHarness Overview

 
Looking for a tutorial or walkthrough on how to write automated tests? See the [tutorial](/docs/guide_tutorials/tutorial_integration_test.md)!

17.0.1.1Introduction

The cdr-public-test-utils library provides powerful tools for writing tests that interact with Smile CDR. Two of the most important components in this library are SmileCdrContainer and SmileHarness, which together enable developers to easily set up and interact with Smile CDR instances in their tests.

17.0.1.2What is SmileCdrContainer?

SmileCdrContainer is a specialized Testcontainers implementation that simplifies the process of running Smile CDR in Docker containers for testing purposes. It extends the GenericContainer class from the Testcontainers library and provides Smile CDR-specific functionality.

Key features of SmileCdrContainer include:

  • Easy Docker Container Setup: Automatically configures and starts a Smile CDR Docker container with sensible defaults.
  • Port Management: Handles the mapping of container ports to host ports, making it easy to connect to the various endpoints exposed by Smile CDR.
  • Configuration Management: Allows customization of the dockerized Smile CDR instance through properties files.
  • Access to SmileHarness: Provides a convenient way to obtain a SmileHarness instance for interacting with the running Smile CDR container.

17.0.1.3What is SmileHarness?

SmileHarness is an interface that provides a unified common API for interacting with a Smile CDR instance during testing. It abstracts away the details of connecting to different endpoints and services within Smile CDR, making it easier to write tests that interact with these services.

The primary implementation, DockerSmileHarness, is designed to work with Smile CDR instances running in Docker containers, particularly those managed by SmileCdrContainer.

Key features of SmileHarness include:

  • Client Access: Provides methods to obtain various clients for interacting with Smile CDR, including:
    • FHIR clients
    • Administrative JSON clients
    • HL7v2 REST clients
  • Endpoint Discovery: Automatically discovers available endpoints in the Smile CDR instance.
  • FHIR Context Management: Provides access to the appropriate FhirContext for the Smile CDR instance.
  • Port Mapping: Handles the mapping between container ports and host ports.

17.0.1.4How They Work Together

In a typical test scenario:

  1. A SmileCdrContainer is created and started, which launches a Smile CDR Docker container.
  2. The SmileCdrContainer provides a SmileHarness instance through its getHarness() method.
  3. The test uses the SmileHarness to obtain clients for interacting with the Smile CDR instance.
  4. These clients are used to perform operations against the Smile CDR instance as part of the test.

This approach allows for comprehensive integration testing of applications that interact with Smile CDR, without the need to manually set up and configure a Smile CDR instance for each test run.

17.0.1.5Next Steps

For more information on how to use these components in your tests, see the other documentation in this section. For a tutorial, please check out the tutorial page.