Skip to content

Migrate R4AvroConverterCustomProfileTest to JUnit 5 with cross-platform support #1362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion bunsen/bunsen-avro/pom.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>bunsen-avro</artifactId>
<packaging>jar</packaging>

<parent>
<artifactId>bunsen-parent</artifactId>
<groupId>com.cerner.bunsen</groupId>
<version>0.5.14-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<name>Bunsen Avro</name>
<description>Avro support for Bunsen.</description>

Expand Down Expand Up @@ -86,12 +91,39 @@
<scope>compile</scope>
</dependency>

<!-- JUnit 4 tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<!-- Added JUnit 5 for newer test classes -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>

</dependencies>

<!-- Configured Surefire plugin to run JUnit 5 tests -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package com.cerner.bunsen.avro;

import static org.junit.jupiter.api.Assertions.*;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import com.cerner.bunsen.ProfileMapperFhirContexts;
import com.cerner.bunsen.exception.ProfileException;
import com.cerner.bunsen.r4.TestData;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import org.apache.avro.generic.GenericData.Record;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Patient;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
* This class tests the used defined structure definitions which should also follow the HL7 FHIR
* specifications and these are just some additional test cases, apart from the regular US Core
* Profiles tests.
* This class tests the user-defined structure definitions which should also follow the HL7 FHIR
* specifications. These are additional test cases beyond the regular US Core Profiles tests.
*/
public class R4AvroConverterCustomProfileTest {

Expand All @@ -30,12 +33,20 @@ public class R4AvroConverterCustomProfileTest {

private static Patient testBunsenTestProfilePatientDecoded;

@BeforeClass
@BeforeAll
public static void setUp() throws URISyntaxException, ProfileException {
ProfileMapperFhirContexts.getInstance().deRegisterFhirContexts(FhirVersionEnum.R4);
URI profileDirUri =
R4AvroConverterCustomProfileTest.class
.getResource("/r4-custom-profile-definitions")
.toURI();

Path profileDirPath = Paths.get(profileDirUri);

FhirContext fhirContext =
ProfileMapperFhirContexts.getInstance()
.contextFor(FhirVersionEnum.R4, "classpath:/r4-custom-profile-definitions");
.contextFor(FhirVersionEnum.R4, profileDirPath.toString());

List<String> patientProfiles =
Arrays.asList(
"http://hl7.org/fhir/StructureDefinition/Patient",
Expand All @@ -52,7 +63,6 @@ public static void setUp() throws URISyntaxException, ProfileException {

@Test
public void testSimpleExtensionWithBooleanField() {

Boolean expected =
(Boolean)
testBunsenTestProfilePatient
Expand All @@ -62,7 +72,7 @@ public void testSimpleExtensionWithBooleanField() {
.getValue();

Boolean actual = (Boolean) avroBunsenTestProfilePatient.get("booleanfield");
Assert.assertEquals(expected, actual);
assertEquals(expected, actual);

Boolean decodedBooleanField =
(Boolean)
Expand All @@ -72,12 +82,11 @@ public void testSimpleExtensionWithBooleanField() {
.getValueAsPrimitive()
.getValue();

Assert.assertEquals(expected, decodedBooleanField);
assertEquals(expected, decodedBooleanField);
}

@Test
public void testSimpleExtensionWithIntegerField() {

Integer expected =
(Integer)
testBunsenTestProfilePatient
Expand All @@ -87,7 +96,7 @@ public void testSimpleExtensionWithIntegerField() {
.getValue();

Integer actual = (Integer) avroBunsenTestProfilePatient.get("integerfield");
Assert.assertEquals(expected, actual);
assertEquals(expected, actual);

Integer decodedIntegerField =
(Integer)
Expand All @@ -97,12 +106,11 @@ public void testSimpleExtensionWithIntegerField() {
.getValueAsPrimitive()
.getValue();

Assert.assertEquals(expected, decodedIntegerField);
assertEquals(expected, decodedIntegerField);
}

@Test
public void testMultiExtensionWithIntegerArrayField() {

Integer expected1 =
(Integer)
testBunsenTestProfilePatient
Expand All @@ -124,8 +132,8 @@ public void testMultiExtensionWithIntegerArrayField() {
Integer actual2 =
((List<Integer>) avroBunsenTestProfilePatient.get("integerArrayField")).get(1);

Assert.assertEquals(expected1, actual1);
Assert.assertEquals(expected2, actual2);
assertEquals(expected1, actual1);
assertEquals(expected2, actual2);

Integer decodedIntegerField1 =
(Integer)
Expand All @@ -143,10 +151,8 @@ public void testMultiExtensionWithIntegerArrayField() {
.getValueAsPrimitive()
.getValue();

Assert.assertEquals(expected1, decodedIntegerField1);
Assert.assertEquals(expected2, decodedIntegerField2);

final List<Record> nestedExtList = (List<Record>) avroBunsenTestProfilePatient.get("nestedExt");
assertEquals(expected1, decodedIntegerField1);
assertEquals(expected2, decodedIntegerField2);
}

@Test
Expand Down Expand Up @@ -244,14 +250,13 @@ public void testMultiNestedExtension() {
.get(0)
.getValue();

Assert.assertEquals(text1, decodedText1);
Assert.assertEquals(text2, decodedText2);
Assert.assertEquals(text3, decodedText3);

Assert.assertTrue(codeableConcept1.equalsDeep(decodedCodeableConcept1));
Assert.assertTrue(codeableConcept2.equalsDeep(decodedCodeableConcept2));
Assert.assertTrue(codeableConcept3.equalsDeep(decodedCodeableConcept3));
assertEquals(text1, decodedText1);
assertEquals(text2, decodedText2);
assertEquals(text3, decodedText3);

assertTrue(codeableConcept1.equalsDeep(decodedCodeableConcept1));
assertTrue(codeableConcept2.equalsDeep(decodedCodeableConcept2));
assertTrue(codeableConcept3.equalsDeep(decodedCodeableConcept3));
final List<Record> nestedExtList = (List<Record>) avroBunsenTestProfilePatient.get("nestedExt");

final Record nestedExt1 = nestedExtList.get(0);
Expand All @@ -263,19 +268,19 @@ public void testMultiNestedExtension() {
final List<Record> codeableConceptsList1 = (List<Record>) nestedExt1.get("codeableConceptExt");
final List<Record> codeableConceptsList2 = (List<Record>) nestedExt2.get("codeableConceptExt");

Assert.assertEquals(text1, textList1.get(0));
Assert.assertEquals(text2, textList1.get(1));
Assert.assertEquals(text3, textList2.get(0));
assertEquals(text1, textList1.get(0));
assertEquals(text2, textList1.get(1));
assertEquals(text3, textList2.get(0));

Assert.assertEquals(
assertEquals(
codeableConcept1.getCoding().get(0).getCode(),
((List<Record>) codeableConceptsList1.get(0).get("coding")).get(0).get("code"));

Assert.assertEquals(
assertEquals(
codeableConcept2.getCoding().get(0).getCode(),
((List<Record>) codeableConceptsList1.get(1).get("coding")).get(0).get("code"));

Assert.assertEquals(
assertEquals(
codeableConcept3.getCoding().get(0).getCode(),
((List<Record>) codeableConceptsList2.get(0).get("coding")).get(0).get("code"));
}
Expand All @@ -293,7 +298,7 @@ public void testSimpleModifierExtensionWithStringField() {

String actual = (String) avroBunsenTestProfilePatient.get("stringModifierExt");

Assert.assertEquals(expected, actual);
assertEquals(expected, actual);

String decodedStringField =
(String)
Expand All @@ -303,7 +308,7 @@ public void testSimpleModifierExtensionWithStringField() {
.getValueAsPrimitive()
.getValue();

Assert.assertEquals(expected, decodedStringField);
assertEquals(expected, decodedStringField);
}

@Test
Expand Down Expand Up @@ -341,32 +346,31 @@ public void testMultiModifierExtensionsWithCodeableConceptField() {
.get(1)
.getValue();

Assert.assertTrue(expected1.equalsDeep(decodedCodeableConceptField1));
Assert.assertTrue(expected2.equalsDeep(decodedCodeableConceptField2));

assertTrue(expected1.equalsDeep(decodedCodeableConceptField1));
assertTrue(expected2.equalsDeep(decodedCodeableConceptField2));
final List<Record> codeableConceptList =
(List<Record>) avroBunsenTestProfilePatient.get("codeableConceptModifierExt");

final Record codeableConcept1 = codeableConceptList.get(0);
final Record codeableConcept2 = codeableConceptList.get(1);

Assert.assertEquals(
assertEquals(
decodedCodeableConceptField1.getCoding().get(0).getSystem(),
((List<Record>) codeableConcept1.get("coding")).get(0).get("system"));
Assert.assertEquals(
assertEquals(
decodedCodeableConceptField1.getCoding().get(0).getCode(),
((List<Record>) codeableConcept1.get("coding")).get(0).get("code"));
Assert.assertEquals(
assertEquals(
decodedCodeableConceptField1.getCoding().get(0).getDisplay(),
((List<Record>) codeableConcept1.get("coding")).get(0).get("display"));

Assert.assertEquals(
assertEquals(
decodedCodeableConceptField2.getCoding().get(0).getSystem(),
((List<Record>) codeableConcept2.get("coding")).get(0).get("system"));
Assert.assertEquals(
assertEquals(
decodedCodeableConceptField2.getCoding().get(0).getCode(),
((List<Record>) codeableConcept2.get("coding")).get(0).get("code"));
Assert.assertEquals(
assertEquals(
decodedCodeableConceptField2.getCoding().get(0).getDisplay(),
((List<Record>) codeableConcept2.get("coding")).get(0).get("display"));
}
Expand Down
Loading