Class LocalhostSmileHarness

java.lang.Object
ca.cdr.test.app.harness.impl.LocalhostSmileHarness
All Implemented Interfaces:
SmileHarness, AutoCloseable

public class LocalhostSmileHarness extends Object implements SmileHarness
The LocalhostSmileHarness class is responsible for managing interaction with a Smile CDR environment running on the localhost. It provides utility methods to identify and interact with Smile modules, such as FHIR endpoints and HL7v2 endpoints, through exposed ports and administrative interfaces.

This class implements the SmileHarness interface to provide concrete implementations of the methods required to handle FHIR and administrative operations.

Every URL it builds is protocol://host:port followed by the target module's context_path, so modules mounted beneath a context path are reached there. The Admin JSON module's own context path comes from HarnessContext.jsonAdminContextPath(), since it is needed before any module configuration can be read; every other module's comes from that configuration. A port no module is configured with is addressed at the root.

This class was generated partly with the help of Claude Sonnet 3.7

  • Constructor Details

  • Method Details

    • getSuperuserFhirClient

      Description copied from interface: SmileHarness
      Gets a FHIR client with superuser privileges. This will create an IGenericClient with the first available FHIR_ENDPOINT module
      Specified by:
      getSuperuserFhirClient in interface SmileHarness
      Returns:
      The FHIR client with superuser authentication
    • getSuperuserFhirClient

      public CdrFhirClient getSuperuserFhirClient(int thePort)
      Description copied from interface: SmileHarness
      Gets a FHIR client with superuser privileges on a specific port.
      Specified by:
      getSuperuserFhirClient in interface SmileHarness
      Parameters:
      thePort - The port to connect to
      Returns:
      The FHIR client with superuser authentication on the specified port
    • getAdminJsonClient

      Description copied from interface: SmileHarness
      Gets an administrative JSON client for interacting with the CDR's admin API. This will create an AdminJsonRestClient with the first available ADMIN_JSON module u
      Specified by:
      getAdminJsonClient in interface SmileHarness
      Returns:
      An autodiscovered AdminJsonRestClient.
    • getAdminJsonClient

      public AdminJsonRestClient getAdminJsonClient(int theAdminPort)
      Description copied from interface: SmileHarness
      Gets an AdminJsonRestClient for interacting with the CDR's admin API on a specific port.
      Specified by:
      getAdminJsonClient in interface SmileHarness
      Parameters:
      theAdminPort - The port to connect to
      Returns:
      The admin JSON client configured with the specified port
    • getSuperuserFhirClient

      Description copied from interface: SmileHarness
      Gets a FHIR client with superuser privileges for a specific module.
      Specified by:
      getSuperuserFhirClient in interface SmileHarness
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The FHIR client with superuser authentication for the specified module
    • getFhirClient

      Description copied from interface: SmileHarness
      Gets a standard FHIR client.
      Specified by:
      getFhirClient in interface SmileHarness
      Returns:
      The FHIR client with default authentication
    • getFhirClient

      public CdrFhirClient getFhirClient(int thePort)
      Description copied from interface: SmileHarness
      Gets a standard FHIR client on a specific port.
      Specified by:
      getFhirClient in interface SmileHarness
      Parameters:
      thePort - The port to connect to
      Returns:
      The FHIR client with default authentication on the specified port
    • getFhirClient

      public CdrFhirClient getFhirClient(String theModuleId)
      Description copied from interface: SmileHarness
      Gets a standard FHIR client for a specific module.
      Specified by:
      getFhirClient in interface SmileHarness
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The FHIR client with default authentication for the specified module
    • getFhirClient

      public CdrFhirClient getFhirClient(@Nonnull String theModuleId, @Nonnull String theBearerToken)
      Description copied from interface: SmileHarness
      Gets a FHIR client for a specific module that authenticates with an OAuth 2.0 access token, such as one from OutboundSmartClient.clientCredentials(String, String, String...), rather than with this harness's credentials.
      Specified by:
      getFhirClient in interface SmileHarness
      Parameters:
      theModuleId - The ID of the module to connect to
      theBearerToken - the access token to send as Authorization: Bearer
      Returns:
      The FHIR client for the specified module, authenticating with the token
    • fhirRequest

      @Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest fhirRequest(@Nonnull String thePath)
      Description copied from interface: SmileHarness
      Starts building a request against the first discovered FHIR endpoint module, pre-authenticated with this harness's HarnessContext credentials via HTTP Basic Auth.

      The single argument here is a path, unlike the single argument to SmileHarness.getFhirClient(String) and its siblings, which is a module ID. To target a named module use SmileHarness.fhirRequest(String, String).

      Specified by:
      fhirRequest in interface SmileHarness
      Parameters:
      thePath - the path below the FHIR endpoint's base URL, beginning with a slash
      Returns:
      A HttpTestRequest builder targeting the discovered FHIR endpoint
    • fhirRequest

      @Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest fhirRequest(@Nonnull String theModuleId, @Nonnull String thePath)
      Description copied from interface: SmileHarness
      Starts building a request against a specific FHIR endpoint module, pre-authenticated with this harness's HarnessContext credentials via HTTP Basic Auth.
      Specified by:
      fhirRequest in interface SmileHarness
      Parameters:
      theModuleId - The ID of the FHIR endpoint module to target
      thePath - the path below the FHIR endpoint's base URL, beginning with a slash
      Returns:
      A HttpTestRequest builder targeting the specified FHIR endpoint module
    • fhirAnonymousRequest

      @Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest fhirAnonymousRequest(@Nonnull String thePath)
      Description copied from interface: SmileHarness
      Starts building an unauthenticated request against the first discovered FHIR endpoint module. It carries neither credentials nor cookies, so it cannot be answered as whoever logged in last. Add credentials with HttpTestRequest.withBasicAuth(String, String) if you need them.

      The single argument here is a path; to target a named module use SmileHarness.fhirAnonymousRequest(String, String).

      Specified by:
      fhirAnonymousRequest in interface SmileHarness
      Parameters:
      thePath - the path below the FHIR endpoint's base URL, beginning with a slash
      Returns:
      A HttpTestRequest builder targeting the discovered FHIR endpoint, with no authentication
    • fhirAnonymousRequest

      @Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest fhirAnonymousRequest(@Nonnull String theModuleId, @Nonnull String thePath)
      Description copied from interface: SmileHarness
      Starts building an unauthenticated request against a specific FHIR endpoint module. It carries neither credentials nor cookies, so it cannot be answered as whoever logged in last.

      This is the builder to use when asserting how a different user is treated: fhirAnonymousRequest(moduleId, path).withBasicAuth(user, password) sends that user's credentials and nothing else. Adding credentials to SmileHarness.fhirRequest(String, String) instead would leave the shared session cookie on the request alongside them.

      Specified by:
      fhirAnonymousRequest in interface SmileHarness
      Parameters:
      theModuleId - The ID of the FHIR endpoint module to target
      thePath - the path below the FHIR endpoint's base URL, beginning with a slash
      Returns:
      A HttpTestRequest builder targeting the specified module, with no authentication
    • serverUrlRequest

      @Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest serverUrlRequest(@Nonnull String theServerUrl)
      Specified by:
      serverUrlRequest in interface SmileHarness
    • fhirBearerRequest

      @Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest fhirBearerRequest(@Nonnull String theModuleId, @Nonnull String thePath, @Nonnull String theBearerToken)
      Description copied from interface: SmileHarness
      Starts building a request against a specific FHIR endpoint module that authenticates with an OAuth 2.0 access token. Like SmileHarness.fhirAnonymousRequest(String, String), it carries neither this harness's credentials nor its cookies; it adds Authorization: Bearer instead.
      Specified by:
      fhirBearerRequest in interface SmileHarness
      Parameters:
      theModuleId - The ID of the FHIR endpoint module to target
      thePath - the path below the FHIR endpoint's base URL, beginning with a slash
      theBearerToken - the access token to send
      Returns:
      A HttpTestRequest builder targeting the specified module
    • request

      @Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest request(int thePort, @Nonnull String thePath)
      Description copied from interface: SmileHarness
      Starts building a request against any port this harness can reach, pre-authenticated with this harness's HarnessContext credentials via HTTP Basic Auth. Pass the port the module is configured with; the harness maps it to the port the module is published on.

      This carries no FhirContext and so cannot encode a FHIR resource body ? use SmileHarness.fhirRequest(String) for that.

      Specified by:
      request in interface SmileHarness
      Parameters:
      thePort - the port the target module is configured with; a port no module is configured with is addressed at its root
      thePath - the path below that module's base URL, beginning with a slash
      Returns:
      A HttpTestRequest builder targeting the given port
    • request

      @Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest request(@Nonnull String theModuleId, @Nonnull String thePath)
      Description copied from interface: SmileHarness
      Starts building a request against a specific module, resolving that module's port from the running node's configuration.
      Specified by:
      request in interface SmileHarness
      Parameters:
      theModuleId - The ID of the module to target
      thePath - the path below that module's base URL, beginning with a slash
      Returns:
      A HttpTestRequest builder targeting the specified module
      See Also:
    • adminJsonRequest

      @Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest adminJsonRequest(@Nonnull String thePath)
      Description copied from interface: SmileHarness
      Starts building a request against the Admin JSON API, pre-authenticated with this harness's HarnessContext credentials via HTTP Basic Auth.

      A HarnessContext naming no Admin JSON port falls back to the default one, which is the port this harness already read the node's configuration from. The path is relative to HarnessContext.jsonAdminContextPath().

      Specified by:
      adminJsonRequest in interface SmileHarness
      Parameters:
      thePath - the path below the Admin JSON base URL, beginning with a slash
      Returns:
      A HttpTestRequest builder targeting the Admin JSON API
    • anonymousRequest

      @Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest anonymousRequest(int thePort, @Nonnull String thePath)
      Description copied from interface: SmileHarness
      Starts building an unauthenticated request against any port this harness can reach. It carries neither credentials nor cookies, so it cannot be answered as whoever logged in last. Add credentials with HttpTestRequest.withBasicAuth(String, String) if you need them.
      Specified by:
      anonymousRequest in interface SmileHarness
      Parameters:
      thePort - the port the target module is configured with
      thePath - the path below that module's base URL, beginning with a slash
      Returns:
      A HttpTestRequest builder targeting the given port, with no authentication
    • anonymousRequest

      @Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest anonymousRequest(@Nonnull String theModuleId, @Nonnull String thePath)
      Description copied from interface: SmileHarness
      Starts building an unauthenticated request against a specific module, resolving that module's port the way SmileHarness.request(String, String) does. It carries neither credentials nor cookies, so it cannot be answered as whoever logged in last. Add credentials with HttpTestRequest.withBasicAuth(String, String) to assert how a particular user is treated without the shared session riding along.
      Specified by:
      anonymousRequest in interface SmileHarness
      Parameters:
      theModuleId - The ID of the module to target
      thePath - the path below that module's base URL, beginning with a slash
      Returns:
      A HttpTestRequest builder targeting the specified module, with no authentication
    • getHttpClient

      Description copied from interface: SmileHarness
      Returns this harness's HTTP client as a handle that can issue requests but cannot close it. Use it only for a URL this harness cannot build ? a service outside the CDR node, or a port it did not discover. Prefer SmileHarness.fhirRequest(String) and SmileHarness.request(String, String), which resolve the module's port and build the URL for you.

      ISmileTestHttpClient.request(String) shares this harness's session and pool; ISmileTestHttpClient.cookielessRequest(String) shares only the pool.

      Specified by:
      getHttpClient in interface SmileHarness
      Returns:
      a handle whose lifetime is this harness's ? SmileHarness.close() ends it
    • clearCookies

      public void clearCookies()
      Description copied from interface: SmileHarness
      Discards every cookie held by this harness's HTTP client, ending any session established by prior requests. Tests exercising several login flows in sequence need this between flows.
      Specified by:
      clearCookies in interface SmileHarness
    • close

      public void close()
      Description copied from interface: SmileHarness
      Releases this harness's HTTP client and its connection pool. Declares no checked exception, so callers need not handle one.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SmileHarness
    • isClosed

      public boolean isClosed()
      Whether close() has been called. SmileCdrContainer caches a harness and uses this to replace one a caller closed, since every request through a closed harness fails on the shut-down pool.
    • getFhirContext

      Gets the only persistence module's FhirContext. If More or less than 1 persistence modules are present, throws IllegalStateException.}

      See getFhirContext(String) if you have multiple persistence modules.

      Specified by:
      getFhirContext in interface SmileHarness
      Returns:
      the FhirContext of the only persistence module.}
    • getFhirContext

      public FhirContext getFhirContext(String moduleId)
      Get the FHIR context for a specific persistence/fhir endpoint module.
      Specified by:
      getFhirContext in interface SmileHarness
      Parameters:
      moduleId - The ID of the persistence or FHIR endpoint module to get the FHIR context for
      Returns:
      The FHIR context for the specified module
      Throws:
      IllegalStateException - if the module is not found or has an unsupported type
    • getHL7V2RestClient

      Description copied from interface: SmileHarness
      Gets an HL7V2 REST client for interacting with the CDR's HL7V2 endpoint.
      Specified by:
      getHL7V2RestClient in interface SmileHarness
      Returns:
      The HL7V2 REST client configured with default port
    • getHL7V2RestClient

      public HL7V2RestClient getHL7V2RestClient(int thePort)
      Description copied from interface: SmileHarness
      Gets an HL7V2 REST client for interacting with the CDR's HL7V2 endpoint on a specific port.
      Specified by:
      getHL7V2RestClient in interface SmileHarness
      Parameters:
      thePort - The port to connect to
      Returns:
      The HL7V2 REST client configured with the specified port
    • getHL7V2RestClient

      Description copied from interface: SmileHarness
      Gets an HL7V2 REST client for a specific module.
      Specified by:
      getHL7V2RestClient in interface SmileHarness
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The HL7V2 REST client for the specified module
    • getOutboundSmartClient

      Description copied from interface: SmileHarness
      Gets an outbound SMART client for OAuth 2.0 authorization flows. This will create an OutboundSmartClient targeting the first available SMART endpoint module.
      Specified by:
      getOutboundSmartClient in interface SmileHarness
      Returns:
      The outbound SMART client configured with default endpoint
    • getOutboundSmartClient

      Description copied from interface: SmileHarness
      Gets an outbound SMART client for OAuth 2.0 authorization flows on a specific port.
      Specified by:
      getOutboundSmartClient in interface SmileHarness
      Parameters:
      thePort - The port to connect to
      Returns:
      The outbound SMART client configured with the specified port
    • getOutboundSmartClient

      Description copied from interface: SmileHarness
      Gets an outbound SMART client for OAuth 2.0 authorization flows for a specific module.
      Specified by:
      getOutboundSmartClient in interface SmileHarness
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The outbound SMART client for the specified module
    • getNpmPackageClient

      Description copied from interface: SmileHarness
      Gets an NPM Package client for interacting with the CDR's package registry endpoint. This will create an NpmPackageClient targeting the first available PACKAGE_REGISTRY endpoint module.
      Specified by:
      getNpmPackageClient in interface SmileHarness
      Returns:
      The NPM Package client configured with default endpoint
    • getNpmPackageClient

      public NpmPackageClient getNpmPackageClient(int thePort)
      Description copied from interface: SmileHarness
      Gets an NPM Package client for interacting with the CDR's package registry endpoint on a specific port.
      Specified by:
      getNpmPackageClient in interface SmileHarness
      Parameters:
      thePort - The port to connect to
      Returns:
      The NPM Package client configured with the specified port
    • getNpmPackageClient

      Description copied from interface: SmileHarness
      Gets an NPM Package client for interacting with the CDR's package registry endpoint for a specific module.
      Specified by:
      getNpmPackageClient in interface SmileHarness
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The NPM Package client for the specified module
    • getSmartHealthLinkClient

      @Nonnull public SmartHealthLinkClient getSmartHealthLinkClient(@Nonnull String theModuleId)
      Specified by:
      getSmartHealthLinkClient in interface SmileHarness
    • getSmilePortalClient

      @Nonnull public SmilePortalClient getSmilePortalClient(@Nonnull String theModuleId)
      Specified by:
      getSmilePortalClient in interface SmileHarness
    • getCdsHooksClient

      @Nonnull public CdsHooksClient getCdsHooksClient()
      Description copied from interface: SmileHarness
      Gets a CDS Hooks client for the default CDS Hooks endpoint module, authenticating with this harness's HarnessContext credentials. For an unauthenticated client, use CdsHooksClient.openAnonymous(String).
      Specified by:
      getCdsHooksClient in interface SmileHarness
      Returns:
      The CDS Hooks client for the first discovered ENDPOINT_CDS_HOOKS module
    • getCdsHooksClient

      @Nonnull public CdsHooksClient getCdsHooksClient(int thePort)
      Description copied from interface: SmileHarness
      Gets a CDS Hooks client for the module configured with a specific port.
      Specified by:
      getCdsHooksClient in interface SmileHarness
      Parameters:
      thePort - The port the module is configured with
      Returns:
      The CDS Hooks client for that module
    • getCdsHooksClient

      @Nonnull public CdsHooksClient getCdsHooksClient(@Nonnull String theModuleId)
      Description copied from interface: SmileHarness
      Gets a CDS Hooks client for a specific module.
      Specified by:
      getCdsHooksClient in interface SmileHarness
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The CDS Hooks client for the specified module