From a8da416ee3f135ac98612351ca72f9fcef6a29c4 Mon Sep 17 00:00:00 2001 From: dotasek Date: Mon, 11 Apr 2022 14:57:10 -0400 Subject: [PATCH] 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() {