Class LocalhostSmileHarness
- All Implemented Interfaces:
SmileHarness,AutoCloseable
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 Summary
ConstructorsConstructorDescriptionLocalhostSmileHarness(HarnessContext theContext) LocalhostSmileHarness(HarnessContext theContext, Map<Integer, Integer> theExposedPortMappings) -
Method Summary
Modifier and TypeMethodDescriptionca.uhn.fhir.test.utilities.HttpTestRequestadminJsonRequest(String thePath) Starts building a request against the Admin JSON API, pre-authenticated with this harness'sHarnessContextcredentials via HTTP Basic Auth.ca.uhn.fhir.test.utilities.HttpTestRequestanonymousRequest(int thePort, String thePath) Starts building an unauthenticated request against any port this harness can reach.ca.uhn.fhir.test.utilities.HttpTestRequestanonymousRequest(String theModuleId, String thePath) Starts building an unauthenticated request against a specific module, resolving that module's port the waySmileHarness.request(String, String)does.voidDiscards every cookie held by this harness's HTTP client, ending any session established by prior requests.voidclose()Releases this harness's HTTP client and its connection pool.ca.uhn.fhir.test.utilities.HttpTestRequestfhirAnonymousRequest(String thePath) Starts building an unauthenticated request against the first discovered FHIR endpoint module.ca.uhn.fhir.test.utilities.HttpTestRequestfhirAnonymousRequest(String theModuleId, String thePath) Starts building an unauthenticated request against a specific FHIR endpoint module.ca.uhn.fhir.test.utilities.HttpTestRequestfhirBearerRequest(String theModuleId, String thePath, String theBearerToken) Starts building a request against a specific FHIR endpoint module that authenticates with an OAuth 2.0 access token.ca.uhn.fhir.test.utilities.HttpTestRequestfhirRequest(String thePath) Starts building a request against the first discovered FHIR endpoint module, pre-authenticated with this harness'sHarnessContextcredentials via HTTP Basic Auth.ca.uhn.fhir.test.utilities.HttpTestRequestfhirRequest(String theModuleId, String thePath) Starts building a request against a specific FHIR endpoint module, pre-authenticated with this harness'sHarnessContextcredentials via HTTP Basic Auth.Gets an administrative JSON client for interacting with the CDR's admin API.getAdminJsonClient(int theAdminPort) Gets anAdminJsonRestClientfor interacting with the CDR's admin API on a specific port.Gets a CDS Hooks client for the default CDS Hooks endpoint module, authenticating with this harness'sHarnessContextcredentials.getCdsHooksClient(int thePort) Gets a CDS Hooks client for the module configured with a specific port.getCdsHooksClient(String theModuleId) Gets a CDS Hooks client for a specific module.Gets a standard FHIR client.getFhirClient(int thePort) Gets a standard FHIR client on a specific port.getFhirClient(String theModuleId) Gets a standard FHIR client for a specific module.getFhirClient(String theModuleId, String theBearerToken) Gets a FHIR client for a specific module that authenticates with an OAuth 2.0 access token, such as one fromOutboundSmartClient.clientCredentials(String, String, String...), rather than with this harness's credentials.Gets the only persistence module's FhirContext.getFhirContext(String moduleId) Get the FHIR context for a specific persistence/fhir endpoint module.Gets an HL7V2 REST client for interacting with the CDR's HL7V2 endpoint.getHL7V2RestClient(int thePort) Gets an HL7V2 REST client for interacting with the CDR's HL7V2 endpoint on a specific port.getHL7V2RestClient(String theModuleId) Gets an HL7V2 REST client for a specific module.Returns this harness's HTTP client as a handle that can issue requests but cannot close it.Gets an NPM Package client for interacting with the CDR's package registry endpoint.getNpmPackageClient(int thePort) Gets an NPM Package client for interacting with the CDR's package registry endpoint on a specific port.getNpmPackageClient(String theModuleId) Gets an NPM Package client for interacting with the CDR's package registry endpoint for a specific module.Gets an outbound SMART client for OAuth 2.0 authorization flows.getOutboundSmartClient(int thePort) Gets an outbound SMART client for OAuth 2.0 authorization flows on a specific port.getOutboundSmartClient(String theModuleId) Gets an outbound SMART client for OAuth 2.0 authorization flows for a specific module.getSmartHealthLinkClient(String theModuleId) getSmilePortalClient(String theModuleId) Gets a FHIR client with superuser privileges.getSuperuserFhirClient(int thePort) Gets a FHIR client with superuser privileges on a specific port.getSuperuserFhirClient(String theModuleId) Gets a FHIR client with superuser privileges for a specific module.booleanisClosed()Whetherclose()has been called.ca.uhn.fhir.test.utilities.HttpTestRequestStarts building a request against any port this harness can reach, pre-authenticated with this harness'sHarnessContextcredentials via HTTP Basic Auth.ca.uhn.fhir.test.utilities.HttpTestRequestStarts building a request against a specific module, resolving that module's port from the running node's configuration.ca.uhn.fhir.test.utilities.HttpTestRequestserverUrlRequest(String theServerUrl)
-
Constructor Details
-
LocalhostSmileHarness
-
LocalhostSmileHarness
public LocalhostSmileHarness(HarnessContext theContext, Map<Integer, Integer> theExposedPortMappings)
-
-
Method Details
-
getSuperuserFhirClient
Description copied from interface:SmileHarnessGets a FHIR client with superuser privileges. This will create anIGenericClientwith the first available FHIR_ENDPOINT module- Specified by:
getSuperuserFhirClientin interfaceSmileHarness- Returns:
- The FHIR client with superuser authentication
-
getSuperuserFhirClient
Description copied from interface:SmileHarnessGets a FHIR client with superuser privileges on a specific port.- Specified by:
getSuperuserFhirClientin interfaceSmileHarness- Parameters:
thePort- The port to connect to- Returns:
- The FHIR client with superuser authentication on the specified port
-
getAdminJsonClient
Description copied from interface:SmileHarnessGets an administrative JSON client for interacting with the CDR's admin API. This will create anAdminJsonRestClientwith the first available ADMIN_JSON module u- Specified by:
getAdminJsonClientin interfaceSmileHarness- Returns:
- An autodiscovered AdminJsonRestClient.
-
getAdminJsonClient
Description copied from interface:SmileHarnessGets anAdminJsonRestClientfor interacting with the CDR's admin API on a specific port.- Specified by:
getAdminJsonClientin interfaceSmileHarness- Parameters:
theAdminPort- The port to connect to- Returns:
- The admin JSON client configured with the specified port
-
getSuperuserFhirClient
Description copied from interface:SmileHarnessGets a FHIR client with superuser privileges for a specific module.- Specified by:
getSuperuserFhirClientin interfaceSmileHarness- 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:SmileHarnessGets a standard FHIR client.- Specified by:
getFhirClientin interfaceSmileHarness- Returns:
- The FHIR client with default authentication
-
getFhirClient
Description copied from interface:SmileHarnessGets a standard FHIR client on a specific port.- Specified by:
getFhirClientin interfaceSmileHarness- Parameters:
thePort- The port to connect to- Returns:
- The FHIR client with default authentication on the specified port
-
getFhirClient
Description copied from interface:SmileHarnessGets a standard FHIR client for a specific module.- Specified by:
getFhirClientin interfaceSmileHarness- Parameters:
theModuleId- The ID of the module to connect to- Returns:
- The FHIR client with default authentication for the specified module
-
getFhirClient
Description copied from interface:SmileHarnessGets a FHIR client for a specific module that authenticates with an OAuth 2.0 access token, such as one fromOutboundSmartClient.clientCredentials(String, String, String...), rather than with this harness's credentials.- Specified by:
getFhirClientin interfaceSmileHarness- Parameters:
theModuleId- The ID of the module to connect totheBearerToken- the access token to send asAuthorization: Bearer- Returns:
- The FHIR client for the specified module, authenticating with the token
-
fhirRequest
Description copied from interface:SmileHarnessStarts building a request against the first discovered FHIR endpoint module, pre-authenticated with this harness'sHarnessContextcredentials 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 useSmileHarness.fhirRequest(String, String).- Specified by:
fhirRequestin interfaceSmileHarness- Parameters:
thePath- the path below the FHIR endpoint's base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder 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:SmileHarnessStarts building a request against a specific FHIR endpoint module, pre-authenticated with this harness'sHarnessContextcredentials via HTTP Basic Auth.- Specified by:
fhirRequestin interfaceSmileHarness- Parameters:
theModuleId- The ID of the FHIR endpoint module to targetthePath- the path below the FHIR endpoint's base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder targeting the specified FHIR endpoint module
-
fhirAnonymousRequest
@Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest fhirAnonymousRequest(@Nonnull String thePath) Description copied from interface:SmileHarnessStarts 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 withHttpTestRequest.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:
fhirAnonymousRequestin interfaceSmileHarness- Parameters:
thePath- the path below the FHIR endpoint's base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder 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:SmileHarnessStarts 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 toSmileHarness.fhirRequest(String, String)instead would leave the shared session cookie on the request alongside them.- Specified by:
fhirAnonymousRequestin interfaceSmileHarness- Parameters:
theModuleId- The ID of the FHIR endpoint module to targetthePath- the path below the FHIR endpoint's base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder targeting the specified module, with no authentication
-
serverUrlRequest
@Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest serverUrlRequest(@Nonnull String theServerUrl) - Specified by:
serverUrlRequestin interfaceSmileHarness
-
fhirBearerRequest
@Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest fhirBearerRequest(@Nonnull String theModuleId, @Nonnull String thePath, @Nonnull String theBearerToken) Description copied from interface:SmileHarnessStarts building a request against a specific FHIR endpoint module that authenticates with an OAuth 2.0 access token. LikeSmileHarness.fhirAnonymousRequest(String, String), it carries neither this harness's credentials nor its cookies; it addsAuthorization: Bearerinstead.- Specified by:
fhirBearerRequestin interfaceSmileHarness- Parameters:
theModuleId- The ID of the FHIR endpoint module to targetthePath- the path below the FHIR endpoint's base URL, beginning with a slashtheBearerToken- the access token to send- Returns:
- A
HttpTestRequestbuilder targeting the specified module
-
request
@Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest request(int thePort, @Nonnull String thePath) Description copied from interface:SmileHarnessStarts building a request against any port this harness can reach, pre-authenticated with this harness'sHarnessContextcredentials 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
FhirContextand so cannot encode a FHIR resource body ? useSmileHarness.fhirRequest(String)for that.- Specified by:
requestin interfaceSmileHarness- Parameters:
thePort- the port the target module is configured with; a port no module is configured with is addressed at its rootthePath- the path below that module's base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder targeting the given port
-
request
@Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest request(@Nonnull String theModuleId, @Nonnull String thePath) Description copied from interface:SmileHarnessStarts building a request against a specific module, resolving that module's port from the running node's configuration.- Specified by:
requestin interfaceSmileHarness- Parameters:
theModuleId- The ID of the module to targetthePath- the path below that module's base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder targeting the specified module - See Also:
-
adminJsonRequest
@Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest adminJsonRequest(@Nonnull String thePath) Description copied from interface:SmileHarnessStarts building a request against the Admin JSON API, pre-authenticated with this harness'sHarnessContextcredentials via HTTP Basic Auth.A
HarnessContextnaming 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 toHarnessContext.jsonAdminContextPath().- Specified by:
adminJsonRequestin interfaceSmileHarness- Parameters:
thePath- the path below the Admin JSON base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder targeting the Admin JSON API
-
anonymousRequest
@Nonnull public ca.uhn.fhir.test.utilities.HttpTestRequest anonymousRequest(int thePort, @Nonnull String thePath) Description copied from interface:SmileHarnessStarts 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 withHttpTestRequest.withBasicAuth(String, String)if you need them.- Specified by:
anonymousRequestin interfaceSmileHarness- Parameters:
thePort- the port the target module is configured withthePath- the path below that module's base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder 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:SmileHarnessStarts building an unauthenticated request against a specific module, resolving that module's port the waySmileHarness.request(String, String)does. It carries neither credentials nor cookies, so it cannot be answered as whoever logged in last. Add credentials withHttpTestRequest.withBasicAuth(String, String)to assert how a particular user is treated without the shared session riding along.- Specified by:
anonymousRequestin interfaceSmileHarness- Parameters:
theModuleId- The ID of the module to targetthePath- the path below that module's base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder targeting the specified module, with no authentication
-
getHttpClient
Description copied from interface:SmileHarnessReturns 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. PreferSmileHarness.fhirRequest(String)andSmileHarness.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:
getHttpClientin interfaceSmileHarness- Returns:
- a handle whose lifetime is this harness's ?
SmileHarness.close()ends it
-
clearCookies
Description copied from interface:SmileHarnessDiscards 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:
clearCookiesin interfaceSmileHarness
-
close
Description copied from interface:SmileHarnessReleases this harness's HTTP client and its connection pool. Declares no checked exception, so callers need not handle one.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSmileHarness
-
isClosed
Whetherclose()has been called.SmileCdrContainercaches 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, throwsIllegalStateException.}See
getFhirContext(String)if you have multiple persistence modules.- Specified by:
getFhirContextin interfaceSmileHarness- Returns:
- the
FhirContextof the only persistence module.}
-
getFhirContext
Get the FHIR context for a specific persistence/fhir endpoint module.- Specified by:
getFhirContextin interfaceSmileHarness- 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:SmileHarnessGets an HL7V2 REST client for interacting with the CDR's HL7V2 endpoint.- Specified by:
getHL7V2RestClientin interfaceSmileHarness- Returns:
- The HL7V2 REST client configured with default port
-
getHL7V2RestClient
Description copied from interface:SmileHarnessGets an HL7V2 REST client for interacting with the CDR's HL7V2 endpoint on a specific port.- Specified by:
getHL7V2RestClientin interfaceSmileHarness- Parameters:
thePort- The port to connect to- Returns:
- The HL7V2 REST client configured with the specified port
-
getHL7V2RestClient
Description copied from interface:SmileHarnessGets an HL7V2 REST client for a specific module.- Specified by:
getHL7V2RestClientin interfaceSmileHarness- Parameters:
theModuleId- The ID of the module to connect to- Returns:
- The HL7V2 REST client for the specified module
-
getOutboundSmartClient
Description copied from interface:SmileHarnessGets an outbound SMART client for OAuth 2.0 authorization flows. This will create an OutboundSmartClient targeting the first available SMART endpoint module.- Specified by:
getOutboundSmartClientin interfaceSmileHarness- Returns:
- The outbound SMART client configured with default endpoint
-
getOutboundSmartClient
Description copied from interface:SmileHarnessGets an outbound SMART client for OAuth 2.0 authorization flows on a specific port.- Specified by:
getOutboundSmartClientin interfaceSmileHarness- Parameters:
thePort- The port to connect to- Returns:
- The outbound SMART client configured with the specified port
-
getOutboundSmartClient
Description copied from interface:SmileHarnessGets an outbound SMART client for OAuth 2.0 authorization flows for a specific module.- Specified by:
getOutboundSmartClientin interfaceSmileHarness- Parameters:
theModuleId- The ID of the module to connect to- Returns:
- The outbound SMART client for the specified module
-
getNpmPackageClient
Description copied from interface:SmileHarnessGets 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:
getNpmPackageClientin interfaceSmileHarness- Returns:
- The NPM Package client configured with default endpoint
-
getNpmPackageClient
Description copied from interface:SmileHarnessGets an NPM Package client for interacting with the CDR's package registry endpoint on a specific port.- Specified by:
getNpmPackageClientin interfaceSmileHarness- Parameters:
thePort- The port to connect to- Returns:
- The NPM Package client configured with the specified port
-
getNpmPackageClient
Description copied from interface:SmileHarnessGets an NPM Package client for interacting with the CDR's package registry endpoint for a specific module.- Specified by:
getNpmPackageClientin interfaceSmileHarness- Parameters:
theModuleId- The ID of the module to connect to- Returns:
- The NPM Package client for the specified module
-
getSmartHealthLinkClient
- Specified by:
getSmartHealthLinkClientin interfaceSmileHarness
-
getSmilePortalClient
- Specified by:
getSmilePortalClientin interfaceSmileHarness
-
getCdsHooksClient
Description copied from interface:SmileHarnessGets a CDS Hooks client for the default CDS Hooks endpoint module, authenticating with this harness'sHarnessContextcredentials. For an unauthenticated client, useCdsHooksClient.openAnonymous(String).- Specified by:
getCdsHooksClientin interfaceSmileHarness- Returns:
- The CDS Hooks client for the first discovered
ENDPOINT_CDS_HOOKSmodule
-
getCdsHooksClient
Description copied from interface:SmileHarnessGets a CDS Hooks client for the module configured with a specific port.- Specified by:
getCdsHooksClientin interfaceSmileHarness- Parameters:
thePort- The port the module is configured with- Returns:
- The CDS Hooks client for that module
-
getCdsHooksClient
Description copied from interface:SmileHarnessGets a CDS Hooks client for a specific module.- Specified by:
getCdsHooksClientin interfaceSmileHarness- Parameters:
theModuleId- The ID of the module to connect to- Returns:
- The CDS Hooks client for the specified module
-