Tests for Base64Binary 40_50 conversions and streaming
This commit is contained in:
parent
76411218ac
commit
8a48e657f3
|
@ -0,0 +1,91 @@
|
|||
package org.hl7.fhir.convertors.conv40_50;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class AuditEvent40_50Test {
|
||||
|
||||
public static final String THE_BASE_64_BINARY_STRING = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
|
||||
public static final byte[] THE_BASE_64_BINARY_BYTE_ARRAY = Base64.decodeBase64(THE_BASE_64_BINARY_STRING.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
||||
|
||||
public static final String INVALID_BASE_64_BINARY_STRING = "Picard was the best starship captain";
|
||||
public static final byte[] INVALID_BASE_64_BINARY_BYTE_ARRAY = Base64.decodeBase64(THE_BASE_64_BINARY_STRING.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("Test r5 -> r4 AuditEvent conversion.")
|
||||
public void testR5_R4() throws IOException {
|
||||
InputStream r5_input = this.getClass().getResourceAsStream("/auditevent_50_with_base64binary.json");
|
||||
|
||||
org.hl7.fhir.r5.model.AuditEvent r5_actual = (org.hl7.fhir.r5.model.AuditEvent) new org.hl7.fhir.r5.formats.JsonParser().parse(r5_input);
|
||||
org.hl7.fhir.r4.model.Resource r4_conv = VersionConvertorFactory_40_50.convertResource(r5_actual);
|
||||
|
||||
org.hl7.fhir.r4.formats.JsonParser r4_parser = new org.hl7.fhir.r4.formats.JsonParser();
|
||||
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
r4_parser.compose(stream, r4_conv);
|
||||
|
||||
org.hl7.fhir.r4.model.Resource r4_streamed = (org.hl7.fhir.r4.model.AuditEvent) new org.hl7.fhir.r4.formats.JsonParser().parse(new ByteArrayInputStream(stream.toByteArray()));
|
||||
|
||||
assertArrayEquals(((org.hl7.fhir.r4.model.AuditEvent)r4_conv).getEntity().get(0).getQuery(), THE_BASE_64_BINARY_BYTE_ARRAY);
|
||||
assertArrayEquals(((org.hl7.fhir.r4.model.AuditEvent)r4_streamed).getEntity().get(0).getQuery(), THE_BASE_64_BINARY_BYTE_ARRAY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test r5 -> r4 AuditEvent conversion.")
|
||||
public void testR4_R5() throws IOException {
|
||||
InputStream r4_input = this.getClass().getResourceAsStream("/auditevent_40_with_base64binary.json");
|
||||
|
||||
org.hl7.fhir.r4.model.AuditEvent r4_actual = (org.hl7.fhir.r4.model.AuditEvent) new org.hl7.fhir.r4.formats.JsonParser().parse(r4_input);
|
||||
org.hl7.fhir.r5.model.Resource r5_conv = VersionConvertorFactory_40_50.convertResource(r4_actual);
|
||||
|
||||
org.hl7.fhir.r5.formats.JsonParser r5_parser = new org.hl7.fhir.r5.formats.JsonParser();
|
||||
|
||||
ByteArrayOutputStream stream
|
||||
= new ByteArrayOutputStream();
|
||||
|
||||
r5_parser.compose(stream, r5_conv);
|
||||
|
||||
org.hl7.fhir.r5.model.Resource r5_streamed = (org.hl7.fhir.r5.model.AuditEvent) new org.hl7.fhir.r5.formats.JsonParser().parse(new ByteArrayInputStream(stream.toByteArray()));
|
||||
|
||||
assertArrayEquals(((org.hl7.fhir.r5.model.AuditEvent)r5_conv).getEntity().get(0).getQuery(), THE_BASE_64_BINARY_BYTE_ARRAY);
|
||||
assertArrayEquals(((org.hl7.fhir.r5.model.AuditEvent)r5_streamed).getEntity().get(0).getQuery(), THE_BASE_64_BINARY_BYTE_ARRAY);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test r5 -> r4 AuditEvent conversion with invalid Base64Binary.")
|
||||
public void testR4_R5BadBase64Binary() throws IOException {
|
||||
InputStream r4_input = this.getClass().getResourceAsStream("/auditevent_40_with_invalid_base64binary.json");
|
||||
|
||||
org.hl7.fhir.r4.model.AuditEvent r4_actual = (org.hl7.fhir.r4.model.AuditEvent) new org.hl7.fhir.r4.formats.JsonParser().parse(r4_input);
|
||||
|
||||
org.hl7.fhir.r5.model.Resource r5_conv = VersionConvertorFactory_40_50.convertResource(r4_actual);
|
||||
|
||||
org.hl7.fhir.r5.formats.JsonParser r5_parser = new org.hl7.fhir.r5.formats.JsonParser();
|
||||
|
||||
ByteArrayOutputStream stream
|
||||
= new ByteArrayOutputStream();
|
||||
|
||||
r5_parser.compose(stream, r5_conv);
|
||||
|
||||
org.hl7.fhir.r5.model.Resource r5_streamed = (org.hl7.fhir.r5.model.AuditEvent) new org.hl7.fhir.r5.formats.JsonParser().parse(new ByteArrayInputStream(stream.toByteArray()));
|
||||
|
||||
System.out.println(((org.hl7.fhir.r5.model.AuditEvent)r5_conv).getEntity().get(0).getQueryElement().getValueAsString());
|
||||
|
||||
//FIXME we should not be even getting this far.
|
||||
assertArrayEquals(((org.hl7.fhir.r5.model.AuditEvent)r5_conv).getEntity().get(0).getQuery(), INVALID_BASE_64_BINARY_BYTE_ARRAY);
|
||||
assertArrayEquals(((org.hl7.fhir.r5.model.AuditEvent)r5_streamed).getEntity().get(0).getQuery(), INVALID_BASE_64_BINARY_BYTE_ARRAY);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
{
|
||||
"resourceType": "AuditEvent",
|
||||
"id": "example",
|
||||
"text": {
|
||||
"status": "generated",
|
||||
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)</div>"
|
||||
},
|
||||
"type": {
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": "110100",
|
||||
"display": "Application Activity"
|
||||
},
|
||||
"subtype": [
|
||||
{
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": "110120",
|
||||
"display": "Application Start"
|
||||
}
|
||||
],
|
||||
"action": "E",
|
||||
"recorded": "2012-10-25T22:04:27+11:00",
|
||||
"outcome": "0",
|
||||
"agent": [
|
||||
{
|
||||
"type": {
|
||||
"coding": [
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/extra-security-role-type",
|
||||
"code": "humanuser",
|
||||
"display": "human user"
|
||||
}
|
||||
]
|
||||
},
|
||||
"role": [
|
||||
{
|
||||
"text": "Service User (Logon)"
|
||||
}
|
||||
],
|
||||
"who": {
|
||||
"identifier": {
|
||||
"value": "Grahame"
|
||||
}
|
||||
},
|
||||
"requestor": false,
|
||||
"network": {
|
||||
"address": "127.0.0.1",
|
||||
"type": "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": {
|
||||
"coding": [
|
||||
{
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": "110153",
|
||||
"display": "Source Role ID"
|
||||
}
|
||||
]
|
||||
},
|
||||
"who": {
|
||||
"identifier": {
|
||||
"system": "urn:oid:2.16.840.1.113883.4.2",
|
||||
"value": "2.16.840.1.113883.4.2"
|
||||
}
|
||||
},
|
||||
"altId": "6580",
|
||||
"requestor": false,
|
||||
"network": {
|
||||
"address": "Workstation1.ehr.familyclinic.com",
|
||||
"type": "1"
|
||||
}
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
"site": "Development",
|
||||
"observer": {
|
||||
"display": "Grahame's Laptop"
|
||||
},
|
||||
"type": [
|
||||
{
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": "110122",
|
||||
"display": "Login"
|
||||
}
|
||||
]
|
||||
},
|
||||
"entity": [
|
||||
{
|
||||
"what": {
|
||||
"identifier": {
|
||||
"type": {
|
||||
"coding": [
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
|
||||
"code": "SNO"
|
||||
}
|
||||
],
|
||||
"text": "Dell Serial Number"
|
||||
},
|
||||
"value": "ABCDEF"
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"system": "http://terminology.hl7.org/CodeSystem/audit-entity-type",
|
||||
"code": "4",
|
||||
"display": "Other"
|
||||
},
|
||||
"role": {
|
||||
"system": "http://terminology.hl7.org/CodeSystem/object-role",
|
||||
"code": "4",
|
||||
"display": "Domain Resource"
|
||||
},
|
||||
"lifecycle": {
|
||||
"system": "http://terminology.hl7.org/CodeSystem/dicom-audit-lifecycle",
|
||||
"code": "6",
|
||||
"display": "Access / Use"
|
||||
},
|
||||
"name": "Grahame's Laptop",
|
||||
"query" : "dGhpcyBpcyB2YWxpZCBiYXNlNjQ="
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
{
|
||||
"resourceType": "AuditEvent",
|
||||
"id": "example",
|
||||
"text": {
|
||||
"status": "generated",
|
||||
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)</div>"
|
||||
},
|
||||
"type": {
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": "110100",
|
||||
"display": "Application Activity"
|
||||
},
|
||||
"subtype": [
|
||||
{
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": "110120",
|
||||
"display": "Application Start"
|
||||
}
|
||||
],
|
||||
"action": "E",
|
||||
"recorded": "2012-10-25T22:04:27+11:00",
|
||||
"outcome": "0",
|
||||
"agent": [
|
||||
{
|
||||
"type": {
|
||||
"coding": [
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/extra-security-role-type",
|
||||
"code": "humanuser",
|
||||
"display": "human user"
|
||||
}
|
||||
]
|
||||
},
|
||||
"role": [
|
||||
{
|
||||
"text": "Service User (Logon)"
|
||||
}
|
||||
],
|
||||
"who": {
|
||||
"identifier": {
|
||||
"value": "Grahame"
|
||||
}
|
||||
},
|
||||
"requestor": false,
|
||||
"network": {
|
||||
"address": "127.0.0.1",
|
||||
"type": "2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": {
|
||||
"coding": [
|
||||
{
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": "110153",
|
||||
"display": "Source Role ID"
|
||||
}
|
||||
]
|
||||
},
|
||||
"who": {
|
||||
"identifier": {
|
||||
"system": "urn:oid:2.16.840.1.113883.4.2",
|
||||
"value": "2.16.840.1.113883.4.2"
|
||||
}
|
||||
},
|
||||
"altId": "6580",
|
||||
"requestor": false,
|
||||
"network": {
|
||||
"address": "Workstation1.ehr.familyclinic.com",
|
||||
"type": "1"
|
||||
}
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
"site": "Development",
|
||||
"observer": {
|
||||
"display": "Grahame's Laptop"
|
||||
},
|
||||
"type": [
|
||||
{
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": "110122",
|
||||
"display": "Login"
|
||||
}
|
||||
]
|
||||
},
|
||||
"entity": [
|
||||
{
|
||||
"what": {
|
||||
"identifier": {
|
||||
"type": {
|
||||
"coding": [
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
|
||||
"code": "SNO"
|
||||
}
|
||||
],
|
||||
"text": "Dell Serial Number"
|
||||
},
|
||||
"value": "ABCDEF"
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"system": "http://terminology.hl7.org/CodeSystem/audit-entity-type",
|
||||
"code": "4",
|
||||
"display": "Other"
|
||||
},
|
||||
"role": {
|
||||
"system": "http://terminology.hl7.org/CodeSystem/object-role",
|
||||
"code": "4",
|
||||
"display": "Domain Resource"
|
||||
},
|
||||
"lifecycle": {
|
||||
"system": "http://terminology.hl7.org/CodeSystem/dicom-audit-lifecycle",
|
||||
"code": "6",
|
||||
"display": "Access / Use"
|
||||
},
|
||||
"name": "Grahame's Laptop",
|
||||
"query" : "Picard was the best starship captain"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
{
|
||||
"resourceType": "AuditEvent",
|
||||
"id": "example",
|
||||
"text": {
|
||||
"status": "generated",
|
||||
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)</div>"
|
||||
},
|
||||
"category": [
|
||||
{
|
||||
"coding": [
|
||||
{
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": "110100",
|
||||
"display": "Application Activity"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"code": {
|
||||
"coding": [
|
||||
{
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": "110120",
|
||||
"display": "Application Start"
|
||||
}
|
||||
]
|
||||
},
|
||||
"action": "E",
|
||||
"recorded": "2012-10-25T22:04:27+11:00",
|
||||
"outcome": {
|
||||
"code": {
|
||||
"system": "http://terminology.hl7.org/CodeSystem/audit-event-outcome",
|
||||
"code": "0",
|
||||
"display": "Success"
|
||||
}
|
||||
},
|
||||
"agent": [
|
||||
{
|
||||
"role": [
|
||||
{
|
||||
"text": "Service User (Logon)"
|
||||
}
|
||||
],
|
||||
"who": {
|
||||
"identifier": {
|
||||
"value": "Grahame"
|
||||
}
|
||||
},
|
||||
"requestor": false
|
||||
},
|
||||
{
|
||||
"extension": [
|
||||
{
|
||||
"url": "http://hl7.org/fhir/StructureDefinition/auditevent-AlternativeUserID",
|
||||
"valueIdentifier": {
|
||||
"type": {
|
||||
"text": "process ID"
|
||||
},
|
||||
"value": "6580"
|
||||
}
|
||||
}
|
||||
],
|
||||
"who": {
|
||||
"identifier": {
|
||||
"system": "urn:oid:2.16.840.1.113883.4.2",
|
||||
"value": "2.16.840.1.113883.4.2"
|
||||
}
|
||||
},
|
||||
"requestor": false,
|
||||
"networkString": "Workstation1.ehr.familyclinic.com"
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
"observer": {
|
||||
"display": "Grahame's Laptop"
|
||||
},
|
||||
"type": [
|
||||
{
|
||||
"coding": [
|
||||
{
|
||||
"system": "http://dicom.nema.org/resources/ontology/DCM",
|
||||
"code": "110122",
|
||||
"display": "Login"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"entity": [
|
||||
{
|
||||
"what": {
|
||||
"identifier": {
|
||||
"type": {
|
||||
"coding": [
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
|
||||
"code": "SNO"
|
||||
}
|
||||
],
|
||||
"text": "Dell Serial Number"
|
||||
},
|
||||
"value": "ABCDEF"
|
||||
}
|
||||
},
|
||||
"role": {
|
||||
"coding": [
|
||||
{
|
||||
"system": "http://terminology.hl7.org/CodeSystem/object-role",
|
||||
"code": "4",
|
||||
"display": "Domain Resource"
|
||||
}
|
||||
]
|
||||
},
|
||||
"query" : "dGhpcyBpcyB2YWxpZCBiYXNlNjQ="
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue