Interface SmileHarness
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
LocalhostSmileHarness
- Request builders ?
fhirRequest(String),request(int, String)andadminJsonRequest(String). Reach for these first. They resolve the module's port, add the harness credentials, and hand back the whole exchange, so a test can assert on a status code, a response header or a redirect.fhirAnonymousRequest(String)andanonymousRequest(int, String)are their unauthenticated counterparts. - FHIR clients ?
getFhirClient()andgetSuperuserFhirClient(). Use these to do FHIR work (read, search, transact) rather than to assert on HTTP. - Protocol clients ?
getAdminJsonClient(),getHL7V2RestClient(),getNpmPackageClient(),getOutboundSmartClient()andgetCdsHooksClient(). Each wraps one API, so a test does not have to hand-build its requests. - The raw HTTP client ?
getHttpClient(), for a URL this harness cannot build, such as a service outside the CDR node.
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 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 wayrequest(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 thePort) 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 FHIR context used by this harness.getFhirContext(String moduleId) Gets the FHIR context for a specific 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.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)
-
Method Details
-
getAdminJsonClient
Gets an administrative JSON client for interacting with the CDR's admin API. This will create anAdminJsonRestClientwith the first available ADMIN_JSON module u- Returns:
- An autodiscovered AdminJsonRestClient.
-
getAdminJsonClient
Gets anAdminJsonRestClientfor 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 anIGenericClientwith 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
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.- 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
-
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
-
getSmilePortalClient
-
getCdsHooksClient
Gets a CDS Hooks client for the default CDS Hooks endpoint module, authenticating with this harness'sHarnessContextcredentials. For an unauthenticated client, useCdsHooksClient.openAnonymous(String).- Returns:
- The CDS Hooks client for the first discovered
ENDPOINT_CDS_HOOKSmodule - Throws:
IllegalStateException- if the node has no CDS Hooks endpoint
-
getCdsHooksClient
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
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
Starts 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
getFhirClient(String)and its siblings, which is a module ID. To target a named module usefhirRequest(String, String).- Parameters:
thePath- the path below the FHIR endpoint's base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder 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'sHarnessContextcredentials via HTTP Basic Auth.- 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
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 withHttpTestRequest.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
HttpTestRequestbuilder 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 tofhirRequest(String, String)instead would leave the shared session cookie on the request alongside them.- 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
-
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. LikefhirAnonymousRequest(String, String), it carries neither this harness's credentials nor its cookies; it addsAuthorization: Bearerinstead.- 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
Starts 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 ? usefhirRequest(String)for that.- 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 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 targetthePath- the path below that module's base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder targeting the specified module - See Also:
-
adminJsonRequest
Starts 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().- Parameters:
thePath- the path below the Admin JSON base URL, beginning with a slash- Returns:
- A
HttpTestRequestbuilder 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 withHttpTestRequest.withBasicAuth(String, String)if you need them.- 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 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 wayrequest(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.- 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
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. PreferfhirRequest(String)andrequest(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:
closein interfaceAutoCloseable
-