-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#122 - adding expires_in as string support for cds hooks requests ...…
… added simple test
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/request/CdsHooksRequestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.opencds.cqf.ruler.plugin.cdshooks.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Test; | ||
import org.opencds.cqf.ruler.cdshooks.request.CdsHooksRequest; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
class CdsHooksRequestIT { | ||
@Test | ||
void testFhirAuthExpiresIn() throws JsonProcessingException { | ||
ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
// expires_in as String | ||
String requestJson = "{\n" + | ||
" \"hookInstance\": \"6bc883b2-b795-4dcb-b661-34884a31d472\",\n" + | ||
" \"fhirServer\": \"https://cloud.alphora.com/sandbox/r4/cds/fhir\",\n" + | ||
" \"hook\": \"patient-view\",\n" + | ||
" \"fhirAuthorization\": {\n" + | ||
" \"access_token\": \"12345\",\n" + | ||
" \"token_type\": \"Bearer\",\n" + | ||
" \"expires_in\": \"3600\",\n" + | ||
" \"scope\": \"\",\n" + | ||
" \"subject\": \"\"\n" + | ||
" },\n" + | ||
" \"context\": {\n" + | ||
" \"userId\": \"Practitioner/example\",\n" + | ||
" \"patientId\": \"Patient/example\"\n" + | ||
" }\n" + | ||
"}"; | ||
CdsHooksRequest cdsHooksRequest = mapper.readValue(requestJson, CdsHooksRequest.class); | ||
assertNotNull(cdsHooksRequest.fhirAuthorization); | ||
assertEquals(3600, cdsHooksRequest.fhirAuthorization.expiresIn); | ||
|
||
// expires_in as int | ||
requestJson = "{\n" + | ||
" \"hookInstance\": \"6bc883b2-b795-4dcb-b661-34884a31d472\",\n" + | ||
" \"fhirServer\": \"https://cloud.alphora.com/sandbox/r4/cds/fhir\",\n" + | ||
" \"hook\": \"patient-view\",\n" + | ||
" \"fhirAuthorization\": {\n" + | ||
" \"access_token\": \"12345\",\n" + | ||
" \"token_type\": \"Bearer\",\n" + | ||
" \"expires_in\": 3600,\n" + | ||
" \"scope\": \"\",\n" + | ||
" \"subject\": \"\"\n" + | ||
" },\n" + | ||
" \"context\": {\n" + | ||
" \"userId\": \"Practitioner/example\",\n" + | ||
" \"patientId\": \"Patient/example\"\n" + | ||
" }\n" + | ||
"}"; | ||
|
||
cdsHooksRequest = mapper.readValue(requestJson, CdsHooksRequest.class); | ||
assertNotNull(cdsHooksRequest.fhirAuthorization); | ||
assertEquals(3600, cdsHooksRequest.fhirAuthorization.expiresIn); | ||
|
||
// expires_in as invalid type (double) | ||
requestJson = "{\n" + | ||
" \"hookInstance\": \"6bc883b2-b795-4dcb-b661-34884a31d472\",\n" + | ||
" \"fhirServer\": \"https://cloud.alphora.com/sandbox/r4/cds/fhir\",\n" + | ||
" \"hook\": \"patient-view\",\n" + | ||
" \"fhirAuthorization\": {\n" + | ||
" \"access_token\": \"12345\",\n" + | ||
" \"token_type\": \"Bearer\",\n" + | ||
" \"expires_in\": 3600.45,\n" + | ||
" \"scope\": \"\",\n" + | ||
" \"subject\": \"\"\n" + | ||
" },\n" + | ||
" \"context\": {\n" + | ||
" \"userId\": \"Practitioner/example\",\n" + | ||
" \"patientId\": \"Patient/example\"\n" + | ||
" }\n" + | ||
"}"; | ||
|
||
try { | ||
cdsHooksRequest = mapper.readValue(requestJson, CdsHooksRequest.class); | ||
fail(); | ||
} catch (JsonProcessingException JPE) { | ||
// pass | ||
} | ||
} | ||
} |