SmileCdrContainer and SmileHarness Overview

 
Looking for a tutorial or walkthrough on how to write automated tests? See the tutorial!

Introduction

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.

What 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.
  • User Preseeding: Supports preloading users with specific permissions into the Smile CDR instance for testing.
  • Access to SmileHarness: Provides a convenient way to obtain a SmileHarness instance for interacting with the running Smile CDR container.

What 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 implementation, LocalhostSmileHarness, works with any Smile CDR instance it can reach over HTTP: one running in a Docker container managed by SmileCdrContainer, or one already running on a known host.

Key features of SmileHarness include:

  • Client Access: Provides methods to obtain various clients for interacting with Smile CDR, including:
    • FHIR clients, authenticating with the harness credentials or with an OAuth 2.0 access token
    • Administrative JSON clients
    • HL7v2 REST clients
    • NPM package registry clients
    • SMART on FHIR (OAuth 2.0) clients
    • CDS Hooks clients
  • Endpoint Discovery: Automatically discovers available endpoints in the Smile CDR instance.
  • Context Paths: Reaches each module beneath its configured context_path, such as /fhir-request.
  • 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.

How 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.

Next 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.