From 8a48e657f3a2499a760db46fe2837344193cd7db Mon Sep 17 00:00:00 2001 From: dotasek Date: Fri, 8 Apr 2022 14:37:42 -0400 Subject: [PATCH 1/4] Tests for Base64Binary 40_50 conversions and streaming --- .../conv40_50/AuditEvent40_50Test.java | 91 +++++++++++++ .../auditevent_40_with_base64binary.json | 122 ++++++++++++++++++ ...ditevent_40_with_invalid_base64binary.json | 122 ++++++++++++++++++ .../auditevent_50_with_base64binary.json | 117 +++++++++++++++++ 4 files changed, 452 insertions(+) create mode 100644 org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java create mode 100644 org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.json create mode 100644 org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.json create mode 100644 org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.json diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java new file mode 100644 index 000000000..244768be4 --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java @@ -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); + + } +} diff --git a/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.json b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.json new file mode 100644 index 000000000..ed6c0ff6d --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.json @@ -0,0 +1,122 @@ +{ + "resourceType": "AuditEvent", + "id": "example", + "text": { + "status": "generated", + "div": "
Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)
" + }, + "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=" + } + ] +} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.json b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.json new file mode 100644 index 000000000..146cb7520 --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.json @@ -0,0 +1,122 @@ +{ + "resourceType": "AuditEvent", + "id": "example", + "text": { + "status": "generated", + "div": "
Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)
" + }, + "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" + } + ] +} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.json b/org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.json new file mode 100644 index 000000000..5bd96899f --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.json @@ -0,0 +1,117 @@ +{ + "resourceType": "AuditEvent", + "id": "example", + "text": { + "status": "generated", + "div": "
Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)
" + }, + "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=" + } + ] +} \ No newline at end of file From 2181cb14d534821904d5d20e2d8d174ecf746848 Mon Sep 17 00:00:00 2001 From: dotasek Date: Mon, 11 Apr 2022 14:10:53 -0400 Subject: [PATCH 2/4] Change tests to xml + fix breaking test --- .../conv40_50/AuditEvent40_50Test.java | 24 ++-- .../auditevent_40_with_base64binary.json | 122 ------------------ .../auditevent_40_with_base64binary.xml | 95 ++++++++++++++ ...ditevent_40_with_invalid_base64binary.json | 122 ------------------ ...uditevent_40_with_invalid_base64binary.xml | 95 ++++++++++++++ .../auditevent_50_with_base64binary.json | 117 ----------------- .../auditevent_50_with_base64binary.xml | 100 ++++++++++++++ .../fhir/dstu3/model/Base64BinaryType.java | 2 +- .../hl7/fhir/r4/model/Base64BinaryType.java | 2 +- "org.hl7.fhir.r4b/c:\\temp\\test.xml" | 1 + .../hl7/fhir/r4b/model/Base64BinaryType.java | 2 +- .../hl7/fhir/r5/model/Base64BinaryType.java | 2 +- 12 files changed, 307 insertions(+), 377 deletions(-) delete mode 100644 org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.json create mode 100644 org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.xml delete mode 100644 org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.json create mode 100644 org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.xml delete mode 100644 org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.json create mode 100644 org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.xml create mode 100644 "org.hl7.fhir.r4b/c:\\temp\\test.xml" diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java index 244768be4..52b3013ee 100644 --- a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java @@ -25,17 +25,17 @@ public class AuditEvent40_50Test { @Test @DisplayName("Test r5 -> r4 AuditEvent conversion.") public void testR5_R4() throws IOException { - InputStream r5_input = this.getClass().getResourceAsStream("/auditevent_50_with_base64binary.json"); + InputStream r5_input = this.getClass().getResourceAsStream("/auditevent_50_with_base64binary.xml"); - 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.r5.model.AuditEvent r5_actual = (org.hl7.fhir.r5.model.AuditEvent) new org.hl7.fhir.r5.formats.XmlParser().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(); + org.hl7.fhir.r4.formats.XmlParser r4_parser = new org.hl7.fhir.r4.formats.XmlParser(); 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())); + org.hl7.fhir.r4.model.Resource r4_streamed = (org.hl7.fhir.r4.model.AuditEvent) new org.hl7.fhir.r4.formats.XmlParser().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); @@ -44,19 +44,19 @@ public class AuditEvent40_50Test { @Test @DisplayName("Test r5 -> r4 AuditEvent conversion.") public void testR4_R5() throws IOException { - InputStream r4_input = this.getClass().getResourceAsStream("/auditevent_40_with_base64binary.json"); + InputStream r4_input = this.getClass().getResourceAsStream("/auditevent_40_with_base64binary.xml"); - 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.r4.model.AuditEvent r4_actual = (org.hl7.fhir.r4.model.AuditEvent) new org.hl7.fhir.r4.formats.XmlParser().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(); + org.hl7.fhir.r5.formats.XmlParser r5_parser = new org.hl7.fhir.r5.formats.XmlParser(); 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())); + org.hl7.fhir.r5.model.Resource r5_streamed = (org.hl7.fhir.r5.model.AuditEvent) new org.hl7.fhir.r5.formats.XmlParser().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); @@ -66,20 +66,20 @@ public class AuditEvent40_50Test { @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"); + InputStream r4_input = this.getClass().getResourceAsStream("/auditevent_40_with_invalid_base64binary.xml"); - 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.r4.model.AuditEvent r4_actual = (org.hl7.fhir.r4.model.AuditEvent) new org.hl7.fhir.r4.formats.XmlParser().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(); + org.hl7.fhir.r5.formats.XmlParser r5_parser = new org.hl7.fhir.r5.formats.XmlParser(); 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())); + org.hl7.fhir.r5.model.Resource r5_streamed = (org.hl7.fhir.r5.model.AuditEvent) new org.hl7.fhir.r5.formats.XmlParser().parse(new ByteArrayInputStream(stream.toByteArray())); System.out.println(((org.hl7.fhir.r5.model.AuditEvent)r5_conv).getEntity().get(0).getQueryElement().getValueAsString()); diff --git a/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.json b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.json deleted file mode 100644 index ed6c0ff6d..000000000 --- a/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.json +++ /dev/null @@ -1,122 +0,0 @@ -{ - "resourceType": "AuditEvent", - "id": "example", - "text": { - "status": "generated", - "div": "
Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)
" - }, - "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=" - } - ] -} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.xml b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.xml new file mode 100644 index 000000000..812edeb05 --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_base64binary.xml @@ -0,0 +1,95 @@ + + + + + + +
Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.json b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.json deleted file mode 100644 index 146cb7520..000000000 --- a/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.json +++ /dev/null @@ -1,122 +0,0 @@ -{ - "resourceType": "AuditEvent", - "id": "example", - "text": { - "status": "generated", - "div": "
Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)
" - }, - "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" - } - ] -} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.xml b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.xml new file mode 100644 index 000000000..812edeb05 --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.xml @@ -0,0 +1,95 @@ + + + + + + +
Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.json b/org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.json deleted file mode 100644 index 5bd96899f..000000000 --- a/org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.json +++ /dev/null @@ -1,117 +0,0 @@ -{ - "resourceType": "AuditEvent", - "id": "example", - "text": { - "status": "generated", - "div": "
Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)
" - }, - "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=" - } - ] -} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.xml b/org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.xml new file mode 100644 index 000000000..3730ef7cd --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/auditevent_50_with_base64binary.xml @@ -0,0 +1,100 @@ + + + + + + +
Application Start for under service login "Grahame" (id: Grahame's Test HL7Connect)
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Base64BinaryType.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Base64BinaryType.java index b4c3d5293..99b7f325d 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Base64BinaryType.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Base64BinaryType.java @@ -130,7 +130,7 @@ public class Base64BinaryType extends PrimitiveType implements IPrimitiv @Override public Base64BinaryType setValue(byte[] theValue) throws IllegalArgumentException { myValue = theValue; - return this; + return (Base64BinaryType) super.setValue(theValue); } @Override diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/Base64BinaryType.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/Base64BinaryType.java index f51356a52..7cdceedf7 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/Base64BinaryType.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/Base64BinaryType.java @@ -130,7 +130,7 @@ public class Base64BinaryType extends PrimitiveType implements IPrimitiv @Override public Base64BinaryType setValue(byte[] theValue) throws IllegalArgumentException { myValue = theValue; - return this; + return (Base64BinaryType) super.setValue(theValue); } @Override diff --git "a/org.hl7.fhir.r4b/c:\\temp\\test.xml" "b/org.hl7.fhir.r4b/c:\\temp\\test.xml" new file mode 100644 index 000000000..990c09b35 --- /dev/null +++ "b/org.hl7.fhir.r4b/c:\\temp\\test.xml" @@ -0,0 +1 @@ +
Sample Contract Lens prescription
\ No newline at end of file diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/Base64BinaryType.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/Base64BinaryType.java index 4f413fbd5..a1c73f821 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/Base64BinaryType.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/Base64BinaryType.java @@ -129,7 +129,7 @@ public class Base64BinaryType extends PrimitiveType implements IPrimitiv @Override public Base64BinaryType setValue(byte[] theValue) throws IllegalArgumentException { myValue = theValue; - return this; + return (Base64BinaryType) super.setValue(theValue); } @Override diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Base64BinaryType.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Base64BinaryType.java index 66473144b..4e83d1a8b 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Base64BinaryType.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Base64BinaryType.java @@ -129,7 +129,7 @@ public class Base64BinaryType extends PrimitiveType implements IPrimitiv @Override public Base64BinaryType setValue(byte[] theValue) throws IllegalArgumentException { myValue = theValue; - return this; + return (Base64BinaryType) super.setValue(theValue); } @Override From a8da416ee3f135ac98612351ca72f9fcef6a29c4 Mon Sep 17 00:00:00 2001 From: dotasek Date: Mon, 11 Apr 2022 14:57:10 -0400 Subject: [PATCH 3/4] Fix xml test + add unit tests --- .../convertors/conv40_50/AuditEvent40_50Test.java | 2 +- .../auditevent_40_with_invalid_base64binary.xml | 2 +- .../hl7/fhir/dstu2/model/Base64BinaryTypeTest.java | 12 ++++++++++++ .../dstu2016may/model/Base64BinaryTypeTest.java | 12 ++++++++++++ .../hl7/fhir/dstu3/model/Base64BinaryTypeTest.java | 12 ++++++++++++ .../org/hl7/fhir/r4/model/Base64BinaryTypeTest.java | 12 ++++++++++++ .../hl7/fhir/r4b/model/Base64BinaryTypeTest.java | 12 ++++++++++++ .../org/hl7/fhir/r5/model/Base64BinaryTypeTest.java | 13 +++++++++++++ 8 files changed, 75 insertions(+), 2 deletions(-) diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java index 52b3013ee..ab8955db4 100644 --- a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/AuditEvent40_50Test.java @@ -19,7 +19,7 @@ public class AuditEvent40_50Test { 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)); + public static final byte[] INVALID_BASE_64_BINARY_BYTE_ARRAY = Base64.decodeBase64(INVALID_BASE_64_BINARY_STRING.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8)); @Test diff --git a/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.xml b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.xml index 812edeb05..c60c9750c 100644 --- a/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.xml +++ b/org.hl7.fhir.convertors/src/test/resources/auditevent_40_with_invalid_base64binary.xml @@ -90,6 +90,6 @@ - + \ No newline at end of file diff --git a/org.hl7.fhir.dstu2/src/test/java/org/hl7/fhir/dstu2/model/Base64BinaryTypeTest.java b/org.hl7.fhir.dstu2/src/test/java/org/hl7/fhir/dstu2/model/Base64BinaryTypeTest.java index fef6661ff..1d9ed516f 100644 --- a/org.hl7.fhir.dstu2/src/test/java/org/hl7/fhir/dstu2/model/Base64BinaryTypeTest.java +++ b/org.hl7.fhir.dstu2/src/test/java/org/hl7/fhir/dstu2/model/Base64BinaryTypeTest.java @@ -1,6 +1,7 @@ package org.hl7.fhir.dstu2.model; import ca.uhn.fhir.parser.DataFormatException; +import org.apache.commons.codec.binary.Base64; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,6 +12,8 @@ class Base64BinaryTypeTest { static final String NON_BASE_64 = "Picard was the best starship captain."; static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ="; + static final byte[] VALID_BASE_64_BYTES = Base64.decodeBase64(VALID_BASE_64.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8)); + @Test @DisplayName("Passing a non Base64 encoded String to constructor causes exception.") public void testNonBase64String() { @@ -45,6 +48,15 @@ class Base64BinaryTypeTest { Assertions.assertNull(b64.getValueAsString()); } + @Test + @DisplayName("Valid Base64 String creates non-null instance with non-null bytes.") + public void testValidBytes() { + Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64_BYTES); + Assertions.assertNotNull(b64); + Assertions.assertNotNull(b64.getValue()); + Assertions.assertEquals(VALID_BASE_64, b64.asStringValue()); + } + @Test @DisplayName("Valid Base64 String creates non-null instance with non-null values.") public void testValid() { diff --git a/org.hl7.fhir.dstu2016may/src/test/java/org/hl7/fhir/dstu2016may/model/Base64BinaryTypeTest.java b/org.hl7.fhir.dstu2016may/src/test/java/org/hl7/fhir/dstu2016may/model/Base64BinaryTypeTest.java index 529cb0425..f8d6021e7 100644 --- a/org.hl7.fhir.dstu2016may/src/test/java/org/hl7/fhir/dstu2016may/model/Base64BinaryTypeTest.java +++ b/org.hl7.fhir.dstu2016may/src/test/java/org/hl7/fhir/dstu2016may/model/Base64BinaryTypeTest.java @@ -1,6 +1,7 @@ package org.hl7.fhir.dstu2016may.model; import ca.uhn.fhir.parser.DataFormatException; +import org.apache.commons.codec.binary.Base64; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,6 +12,8 @@ class Base64BinaryTypeTest { static final String NON_BASE_64 = "Picard was the best starship captain."; static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ="; + static final byte[] VALID_BASE_64_BYTES = Base64.decodeBase64(VALID_BASE_64.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8)); + @Test @DisplayName("Passing a non Base64 encoded String to constructor causes exception.") public void testNonBase64String() { @@ -45,6 +48,15 @@ class Base64BinaryTypeTest { Assertions.assertNull(b64.getValueAsString()); } + @Test + @DisplayName("Valid Base64 String creates non-null instance with non-null bytes.") + public void testValidBytes() { + Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64_BYTES); + Assertions.assertNotNull(b64); + Assertions.assertNotNull(b64.getValue()); + Assertions.assertEquals(VALID_BASE_64, b64.asStringValue()); + } + @Test @DisplayName("Valid Base64 String creates non-null instance with non-null values.") public void testValid() { diff --git a/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/model/Base64BinaryTypeTest.java b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/model/Base64BinaryTypeTest.java index a0d879bde..37b5249e8 100644 --- a/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/model/Base64BinaryTypeTest.java +++ b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/model/Base64BinaryTypeTest.java @@ -1,6 +1,7 @@ package org.hl7.fhir.dstu3.model; import ca.uhn.fhir.parser.DataFormatException; +import org.apache.commons.codec.binary.Base64; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,6 +12,8 @@ class Base64BinaryTypeTest { static final String NON_BASE_64 = "Picard was the best starship captain."; static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ="; + static final byte[] VALID_BASE_64_BYTES = Base64.decodeBase64(VALID_BASE_64.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8)); + @Test @DisplayName("Passing a non Base64 encoded String to constructor causes exception.") public void testNonBase64String() { @@ -54,6 +57,15 @@ class Base64BinaryTypeTest { Assertions.assertEquals(VALID_BASE_64, b64.asStringValue()); } + @Test + @DisplayName("Valid Base64 String creates non-null instance with non-null bytes.") + public void testValidBytes() { + Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64_BYTES); + Assertions.assertNotNull(b64); + Assertions.assertNotNull(b64.getValue()); + Assertions.assertEquals(VALID_BASE_64, b64.asStringValue()); + } + @Test @DisplayName("Valid Base64 String creates non-null instance with non-null values.") public void testValidSetValueAsString() { diff --git a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/model/Base64BinaryTypeTest.java b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/model/Base64BinaryTypeTest.java index 3e33c79d2..72a469d5a 100644 --- a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/model/Base64BinaryTypeTest.java +++ b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/model/Base64BinaryTypeTest.java @@ -1,6 +1,7 @@ package org.hl7.fhir.r4.model; import ca.uhn.fhir.parser.DataFormatException; +import org.apache.commons.codec.binary.Base64; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,6 +12,8 @@ class Base64BinaryTypeTest { static final String NON_BASE_64 = "Picard was the best starship captain."; static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ="; + static final byte[] VALID_BASE_64_BYTES = Base64.decodeBase64(VALID_BASE_64.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8)); + @Test @DisplayName("Passing a non Base64 encoded String to constructor causes exception.") public void testNonBase64String() { @@ -54,6 +57,15 @@ class Base64BinaryTypeTest { Assertions.assertEquals(VALID_BASE_64, b64.asStringValue()); } + @Test + @DisplayName("Valid Base64 String creates non-null instance with non-null bytes.") + public void testValidBytes() { + Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64_BYTES); + Assertions.assertNotNull(b64); + Assertions.assertNotNull(b64.getValue()); + Assertions.assertEquals(VALID_BASE_64, b64.asStringValue()); + } + @Test @DisplayName("Valid Base64 String creates non-null instance with non-null values.") public void testValidSetValueAsString() { diff --git a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/model/Base64BinaryTypeTest.java b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/model/Base64BinaryTypeTest.java index 5bc9deae9..5bb7e854f 100644 --- a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/model/Base64BinaryTypeTest.java +++ b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/model/Base64BinaryTypeTest.java @@ -2,6 +2,7 @@ package org.hl7.fhir.r4b.model; import static org.junit.jupiter.api.Assertions.assertThrows; +import org.apache.commons.codec.binary.Base64; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -12,6 +13,8 @@ class Base64BinaryTypeTest { static final String NON_BASE_64 = "Picard was the best starship captain."; static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ="; + static final byte[] VALID_BASE_64_BYTES = Base64.decodeBase64(VALID_BASE_64.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8)); + @Test @DisplayName("Passing a non Base64 encoded String to constructor causes exception.") public void testNonBase64String() { @@ -55,6 +58,15 @@ class Base64BinaryTypeTest { Assertions.assertEquals(VALID_BASE_64, b64.asStringValue()); } + @Test + @DisplayName("Valid Base64 String creates non-null instance with non-null bytes.") + public void testValidBytes() { + Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64_BYTES); + Assertions.assertNotNull(b64); + Assertions.assertNotNull(b64.getValue()); + Assertions.assertEquals(VALID_BASE_64, b64.asStringValue()); + } + @Test @DisplayName("Valid Base64 String creates non-null instance with non-null values.") public void testValidSetValueAsString() { diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/model/Base64BinaryTypeTest.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/model/Base64BinaryTypeTest.java index 36a7aa96a..3f5a164b3 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/model/Base64BinaryTypeTest.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/model/Base64BinaryTypeTest.java @@ -2,16 +2,20 @@ package org.hl7.fhir.r5.model; import static org.junit.jupiter.api.Assertions.assertThrows; +import org.apache.commons.codec.binary.Base64; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import ca.uhn.fhir.parser.DataFormatException; +import java.nio.charset.StandardCharsets; + class Base64BinaryTypeTest { static final String NON_BASE_64 = "Picard was the best starship captain."; static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ="; + static final byte[] VALID_BASE_64_BYTES = Base64.decodeBase64(VALID_BASE_64.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8)); @Test @DisplayName("Passing a non Base64 encoded String to constructor causes exception.") public void testNonBase64String() { @@ -55,6 +59,15 @@ class Base64BinaryTypeTest { Assertions.assertEquals(VALID_BASE_64, b64.asStringValue()); } + @Test + @DisplayName("Valid Base64 String creates non-null instance with non-null bytes.") + public void testValidBytes() { + Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64_BYTES); + Assertions.assertNotNull(b64); + Assertions.assertNotNull(b64.getValue()); + Assertions.assertEquals(VALID_BASE_64, b64.asStringValue()); + } + @Test @DisplayName("Valid Base64 String creates non-null instance with non-null values.") public void testValidSetValueAsString() { From 2eae5ade6ba86fbd311d16764c649cd0da41c285 Mon Sep 17 00:00:00 2001 From: dotasek Date: Mon, 11 Apr 2022 16:18:42 -0400 Subject: [PATCH 4/4] Remove c:\temp\test.xml --- "org.hl7.fhir.r4b/c:\\temp\\test.xml" | 1 - 1 file changed, 1 deletion(-) delete mode 100644 "org.hl7.fhir.r4b/c:\\temp\\test.xml" diff --git "a/org.hl7.fhir.r4b/c:\\temp\\test.xml" "b/org.hl7.fhir.r4b/c:\\temp\\test.xml" deleted file mode 100644 index 990c09b35..000000000 --- "a/org.hl7.fhir.r4b/c:\\temp\\test.xml" +++ /dev/null @@ -1 +0,0 @@ -
Sample Contract Lens prescription
\ No newline at end of file