Interface SmileHarness

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
LocalhostSmileHarness

public interface SmileHarness extends AutoCloseable
Interface for interacting with a Smile CDR instance during testing. It hands out the clients a test needs, in four kinds: A harness owns a single HTTP client, so the request builders and the protocol clients all share one cookie store and one connection pool. That shared store is what lets a multi-request login flow work across them: a SMART login is visible to a later fhirRequest(String). Cookies are scoped to the host rather than the port, so the session reaches every module. clearCookies() ends it; close() releases the pool. The FHIR clients are the exception ? they are HAPI IGenericClients with their own transport, and none of this applies to them.

Every URL a harness builds includes the target module's context_path, so a module mounted at /fhir-request is reached there by the request builders and the clients alike; paths passed to the request builders are relative to it.

Where a no-argument accessor has several modules of its type to choose from, it takes the one with the conventional ID (fhir_endpoint for FHIR, smart_auth for SMART) if there is one, and otherwise the first in the node's configuration.

fhirAnonymousRequest(String) and anonymousRequest(int, String) opt out of the session too: they send no cookies and store none, so a test asserting that an unauthenticated caller is rejected cannot be answered as whoever logged in last.

  • Method Details

    • getAdminJsonClient

      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
      Returns:
      An autodiscovered AdminJsonRestClient.
    • getAdminJsonClient

      Gets an AdminJsonRestClient for interacting with the CDR's admin API on a specific port.
      Parameters:
      thePort - The port to connect to
      Returns:
      The admin JSON client configured with the specified port
    • getSuperuserFhirClient

      Gets a FHIR client with superuser privileges. This will create an IGenericClient with the first available FHIR_ENDPOINT module
      Returns:
      The FHIR client with superuser authentication
    • getSuperuserFhirClient

      Gets a FHIR client with superuser privileges on a specific port.
      Parameters:
      thePort - The port to connect to
      Returns:
      The FHIR client with superuser authentication on the specified port
    • getSuperuserFhirClient

      Gets a FHIR client with superuser privileges for a specific module.
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The FHIR client with superuser authentication for the specified module
    • getFhirClient

      Gets a standard FHIR client.
      Returns:
      The FHIR client with default authentication
    • getFhirClient

      Gets a standard FHIR client on a specific port.
      Parameters:
      thePort - The port to connect to
      Returns:
      The FHIR client with default authentication on the specified port
    • getFhirClient

      Gets a standard FHIR client for a specific module.
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The FHIR client with default authentication for the specified module
    • getFhirClient

      CdrFhirClient getFhirClient(@Nonnull String theModuleId, @Nonnull String theBearerToken)
      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.
      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
    • getFhirContext

      Gets the FHIR context used by this harness.
      Returns:
      The FHIR context
    • getFhirContext

      Gets the FHIR context for a specific module.
      Parameters:
      moduleId - The ID of the module
      Returns:
      The FHIR context for the specified module
    • getHL7V2RestClient

      Gets an HL7V2 REST client for interacting with the CDR's HL7V2 endpoint.
      Returns:
      The HL7V2 REST client configured with default port
    • getHL7V2RestClient

      Gets an HL7V2 REST client for interacting with the CDR's HL7V2 endpoint on a specific port.
      Parameters:
      thePort - The port to connect to
      Returns:
      The HL7V2 REST client configured with the specified port
    • getHL7V2RestClient

      Gets an HL7V2 REST client for a specific module.
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The HL7V2 REST client for the specified module
    • getOutboundSmartClient

      Gets an outbound SMART client for OAuth 2.0 authorization flows. This will create an OutboundSmartClient targeting the first available SMART endpoint module.
      Returns:
      The outbound SMART client configured with default endpoint
    • getOutboundSmartClient

      Gets an outbound SMART client for OAuth 2.0 authorization flows on a specific port.
      Parameters:
      thePort - The port to connect to
      Returns:
      The outbound SMART client configured with the specified port
    • getOutboundSmartClient

      Gets an outbound SMART client for OAuth 2.0 authorization flows for a specific module.
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The outbound SMART client for the specified module
    • getNpmPackageClient

      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.
      Returns:
      The NPM Package client configured with default endpoint
    • getNpmPackageClient

      Gets an NPM Package client for interacting with the CDR's package registry endpoint on a specific port.
      Parameters:
      thePort - The port to connect to
      Returns:
      The NPM Package client configured with the specified port
    • getNpmPackageClient

      Gets an NPM Package client for interacting with the CDR's package registry endpoint for a specific module.
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The NPM Package client for the specified module
    • getSmartHealthLinkClient

      @Nonnull SmartHealthLinkClient getSmartHealthLinkClient(@Nonnull String theModuleId)
    • getSmilePortalClient

      @Nonnull SmilePortalClient getSmilePortalClient(@Nonnull String theModuleId)
    • getCdsHooksClient

      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).
      Returns:
      The CDS Hooks client for the first discovered ENDPOINT_CDS_HOOKS module
      Throws:
      IllegalStateException - if the node has no CDS Hooks endpoint
    • getCdsHooksClient

      @Nonnull CdsHooksClient getCdsHooksClient(int thePort)
      Gets a CDS Hooks client for the module configured with a specific port.
      Parameters:
      thePort - The port the module is configured with
      Returns:
      The CDS Hooks client for that module
    • getCdsHooksClient

      @Nonnull CdsHooksClient getCdsHooksClient(@Nonnull String theModuleId)
      Gets a CDS Hooks client for a specific module.
      Parameters:
      theModuleId - The ID of the module to connect to
      Returns:
      The CDS Hooks client for the specified module
    • fhirRequest

      @Nonnull ca.uhn.fhir.test.utilities.HttpTestRequest fhirRequest(@Nonnull String thePath)
      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 getFhirClient(String) and its siblings, which is a module ID. To target a named module use fhirRequest(String, String).

      Parameters:
      thePath - the path below the FHIR endpoint's base URL, beginning with a slash
      Returns:
      A HttpTestRequest builder targeting the discovered FHIR endpoint
      Throws:
      IllegalArgumentException - if the path is neither empty nor beginning with a slash ? the shape a module ID passed here by mistake would have
    • fhirRequest

      @Nonnull ca.uhn.fhir.test.utilities.HttpTestRequest fhirRequest(@Nonnull String theModuleId, @Nonnull String thePath)
      Starts building a request against a specific FHIR endpoint module, pre-authenticated with this harness's HarnessContext credentials via HTTP Basic Auth.
      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 ca.uhn.fhir.test.utilities.HttpTestRequest fhirAnonymousRequest(@Nonnull String thePath)
      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 fhirAnonymousRequest(String, String).

      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
      Throws:
      IllegalArgumentException - if the path is neither empty nor beginning with a slash ? the shape a module ID passed here by mistake would have
    • fhirAnonymousRequest

      @Nonnull ca.uhn.fhir.test.utilities.HttpTestRequest fhirAnonymousRequest(@Nonnull String theModuleId, @Nonnull String thePath)
      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 fhirRequest(String, String) instead would leave the shared session cookie on the request alongside them.

      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 ca.uhn.fhir.test.utilities.HttpTestRequest serverUrlRequest(@Nonnull String theServerUrl)
    • fhirBearerRequest

      @Nonnull ca.uhn.fhir.test.utilities.HttpTestRequest fhirBearerRequest(@Nonnull String theModuleId, @Nonnull String thePath, @Nonnull String theBearerToken)
      Starts building a request against a specific FHIR endpoint module that authenticates with an OAuth 2.0 access token. Like fhirAnonymousRequest(String, String), it carries neither this harness's credentials nor its cookies; it adds Authorization: Bearer instead.
      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 ca.uhn.fhir.test.utilities.HttpTestRequest request(int thePort, @Nonnull String thePath)
      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 fhirRequest(String) for that.

      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 ca.uhn.fhir.test.utilities.HttpTestRequest request(@Nonnull String theModuleId, @Nonnull String thePath)
      Starts building a request against a specific module, resolving that module's port from the running node's configuration.
      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 ca.uhn.fhir.test.utilities.HttpTestRequest adminJsonRequest(@Nonnull String thePath)
      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().

      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 ca.uhn.fhir.test.utilities.HttpTestRequest anonymousRequest(int thePort, @Nonnull String thePath)
      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.
      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 ca.uhn.fhir.test.utilities.HttpTestRequest anonymousRequest(@Nonnull String theModuleId, @Nonnull String thePath)
      Starts building an unauthenticated request against a specific module, resolving that module's port the way 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.
      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

      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 fhirRequest(String) and 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.

      Returns:
      a handle whose lifetime is this harness's ? close() ends it
    • clearCookies

      void clearCookies()
      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.
    • close

      void close()
      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