I cast you out unclean spirit.

This commit is contained in:
markiantorno 2020-04-29 16:55:40 -04:00
parent 1086a46a6c
commit 89f98bb960
56 changed files with 1480 additions and 1342 deletions

View File

@ -66,6 +66,19 @@
<optional>true</optional>
</dependency>
<!-- JUnit Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -1,6 +1,22 @@
package org.hl7.fhir.convertors;
import org.hl7.fhir.dstu2.model.*;
import org.hl7.fhir.dstu2.model.Base64BinaryType;
import org.hl7.fhir.dstu2.model.BooleanType;
import org.hl7.fhir.dstu2.model.CodeType;
import org.hl7.fhir.dstu2.model.DateTimeType;
import org.hl7.fhir.dstu2.model.DateType;
import org.hl7.fhir.dstu2.model.DecimalType;
import org.hl7.fhir.dstu2.model.InstantType;
import org.hl7.fhir.dstu2.model.IntegerType;
import org.hl7.fhir.dstu2.model.MarkdownType;
import org.hl7.fhir.dstu2.model.OidType;
import org.hl7.fhir.dstu2.model.PositiveIntType;
import org.hl7.fhir.dstu2.model.PrimitiveType;
import org.hl7.fhir.dstu2.model.StringType;
import org.hl7.fhir.dstu2.model.TimeType;
import org.hl7.fhir.dstu2.model.UnsignedIntType;
import org.hl7.fhir.dstu2.model.UriType;
import org.hl7.fhir.dstu2.model.UuidType;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -8,10 +24,7 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import junit.framework.Assert;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Stream;
public class VersionConvertorPrimitiveType10_50Test {
@ -22,10 +35,10 @@ public class VersionConvertorPrimitiveType10_50Test {
public void testAuditEvent() throws FHIRFormatError, IOException {
org.hl7.fhir.dstu2.model.AuditEvent ae2 = (org.hl7.fhir.dstu2.model.AuditEvent) new org.hl7.fhir.dstu2.formats.JsonParser().parse(AUDIT_EVENT_SOURCE);
org.hl7.fhir.r5.model.AuditEvent ae5 = (org.hl7.fhir.r5.model.AuditEvent) VersionConvertor_10_50.convertResource(ae2);
Assert.assertEquals(ae5.getId(), ae2.getId());
Assertions.assertEquals(ae5.getId(), ae2.getId());
}
@ParameterizedTest(name = "Testing dstu2 -> r5 conversion of null value {0}.")
@MethodSource("dstu2PrimitiveTypes")
public <T extends PrimitiveType> void testNullValueDstu2Primitive(String classname, T obj) {

View File

@ -1,6 +1,22 @@
package org.hl7.fhir.convertors;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.Base64BinaryType;
import org.hl7.fhir.dstu3.model.BooleanType;
import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.DateTimeType;
import org.hl7.fhir.dstu3.model.DateType;
import org.hl7.fhir.dstu3.model.DecimalType;
import org.hl7.fhir.dstu3.model.InstantType;
import org.hl7.fhir.dstu3.model.IntegerType;
import org.hl7.fhir.dstu3.model.MarkdownType;
import org.hl7.fhir.dstu3.model.OidType;
import org.hl7.fhir.dstu3.model.PositiveIntType;
import org.hl7.fhir.dstu3.model.PrimitiveType;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.TimeType;
import org.hl7.fhir.dstu3.model.UnsignedIntType;
import org.hl7.fhir.dstu3.model.UriType;
import org.hl7.fhir.dstu3.model.UuidType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;

View File

@ -1,6 +1,22 @@
package org.hl7.fhir.convertors;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.Base64BinaryType;
import org.hl7.fhir.dstu3.model.BooleanType;
import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.DateTimeType;
import org.hl7.fhir.dstu3.model.DateType;
import org.hl7.fhir.dstu3.model.DecimalType;
import org.hl7.fhir.dstu3.model.InstantType;
import org.hl7.fhir.dstu3.model.IntegerType;
import org.hl7.fhir.dstu3.model.MarkdownType;
import org.hl7.fhir.dstu3.model.OidType;
import org.hl7.fhir.dstu3.model.PositiveIntType;
import org.hl7.fhir.dstu3.model.PrimitiveType;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.TimeType;
import org.hl7.fhir.dstu3.model.UnsignedIntType;
import org.hl7.fhir.dstu3.model.UriType;
import org.hl7.fhir.dstu3.model.UuidType;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -8,10 +24,7 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import junit.framework.Assert;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Stream;
public class VersionConvertorPrimitiveType30_50Test {
@ -22,9 +35,9 @@ public class VersionConvertorPrimitiveType30_50Test {
public void testAuditEvent() throws FHIRFormatError, IOException {
org.hl7.fhir.dstu3.model.AuditEvent ae3 = (org.hl7.fhir.dstu3.model.AuditEvent) new org.hl7.fhir.dstu3.formats.JsonParser().parse(AUDIT_EVENT_SOURCE);
org.hl7.fhir.r5.model.AuditEvent ae5 = (org.hl7.fhir.r5.model.AuditEvent) VersionConvertor_30_50.convertResource(ae3, false);
Assert.assertEquals(ae5.getId(), ae3.getId());
Assertions.assertEquals(ae5.getId(), ae3.getId());
}
@ParameterizedTest(name = "Testing dstu3 -> r5 conversion of null value {0}.")
@MethodSource("dstu3PrimitiveTypes")
public <T extends PrimitiveType> void testNullValueDstu2Primitive(String classname, T obj) {

View File

@ -1,17 +1,30 @@
package org.hl7.fhir.convertors;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r4.model.Base64BinaryType;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.CodeType;
import org.hl7.fhir.r4.model.DateTimeType;
import org.hl7.fhir.r4.model.DateType;
import org.hl7.fhir.r4.model.DecimalType;
import org.hl7.fhir.r4.model.InstantType;
import org.hl7.fhir.r4.model.IntegerType;
import org.hl7.fhir.r4.model.MarkdownType;
import org.hl7.fhir.r4.model.OidType;
import org.hl7.fhir.r4.model.PositiveIntType;
import org.hl7.fhir.r4.model.PrimitiveType;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.TimeType;
import org.hl7.fhir.r4.model.UnsignedIntType;
import org.hl7.fhir.r4.model.UriType;
import org.hl7.fhir.r4.model.UuidType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import junit.framework.Assert;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Stream;
public class VersionConvertorPrimitiveType40_50Test {
@ -22,10 +35,10 @@ public class VersionConvertorPrimitiveType40_50Test {
public void testAuditEvent() throws FHIRFormatError, IOException {
org.hl7.fhir.r4.model.AuditEvent ae4 = (org.hl7.fhir.r4.model.AuditEvent) new org.hl7.fhir.r4.formats.JsonParser().parse(AUDIT_EVENT_SOURCE);
org.hl7.fhir.r5.model.AuditEvent ae5 = (org.hl7.fhir.r5.model.AuditEvent) VersionConvertor_40_50.convertResource(ae4);
Assert.assertEquals(ae5.getId(), ae4.getId());
Assertions.assertEquals(ae5.getId(), ae4.getId());
}
@ParameterizedTest(name = "Testing r4 -> r5 conversion of null value {0}.")
@MethodSource("r4PrimitiveTypes")
public <T extends PrimitiveType> void testNullValueDstu2Primitive(String classname, T obj) {

View File

@ -95,6 +95,20 @@
<artifactId>Saxon-HE</artifactId>
<scope>test</scope>
</dependency>
<!-- JUnit Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -2,9 +2,8 @@ package org.hl7.fhir.dstu2.test;
import org.hl7.fhir.dstu2.model.Coding;
import org.hl7.fhir.dstu2.model.Meta;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class MetaTest {
public static String TEST_SYSTEM = "TEST_SYSTEM";
@ -14,11 +13,11 @@ public class MetaTest {
public void testMetaSecurity() {
Meta meta = new Meta();
Coding coding = meta.addSecurity().setSystem(TEST_SYSTEM).setCode(TEST_CODE);
assertTrue(meta.hasSecurity());
assertNotNull(meta.getSecurity());
assertNotNull(meta.getSecurity(TEST_SYSTEM, TEST_CODE));
assertEquals(1, meta.getSecurity().size());
assertEquals(meta.getSecurity().get(0), meta.getSecurity(TEST_SYSTEM, TEST_CODE));
assertEquals(coding, meta.getSecurity(TEST_SYSTEM, TEST_CODE));
Assertions.assertTrue(meta.hasSecurity());
Assertions.assertNotNull(meta.getSecurity());
Assertions.assertNotNull(meta.getSecurity(TEST_SYSTEM, TEST_CODE));
Assertions.assertEquals(1, meta.getSecurity().size());
Assertions.assertEquals(meta.getSecurity().get(0), meta.getSecurity(TEST_SYSTEM, TEST_CODE));
Assertions.assertEquals(coding, meta.getSecurity(TEST_SYSTEM, TEST_CODE));
}
}

View File

@ -109,6 +109,20 @@
<artifactId>Saxon-HE</artifactId>
<scope>test</scope>
</dependency>
<!-- JUnit Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -3,8 +3,8 @@ package org.hl7.fhir.dstu2016may.test;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import org.hl7.fhir.dstu2016may.model.DateType;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@ -16,7 +16,7 @@ import static org.junit.Assert.assertEquals;
public class BaseDateTimeTypeTest {
private SimpleDateFormat myDateInstantParser;
@Before
@BeforeEach
public void before() {
myDateInstantParser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
}
@ -52,6 +52,4 @@ public class BaseDateTimeTypeTest {
date.setValue(time);
assertEquals("2012-01-02", date.getValueAsString());
}
}

View File

@ -1,10 +1,5 @@
package org.hl7.fhir.dstu2016may.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import org.hl7.fhir.dstu2016may.formats.JsonParser;
import org.hl7.fhir.dstu2016may.model.Appointment;
import org.hl7.fhir.dstu2016may.model.Base;
@ -30,11 +25,15 @@ import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.exceptions.PathEngineException;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import junit.framework.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
@Disabled
public class FluentPathTests {
@ -77,7 +76,7 @@ public class FluentPathTests {
@SuppressWarnings("deprecation")
private void test(Resource resource, String expression, int count, String... types) throws FileNotFoundException, IOException, FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
FHIRPathEngine fp = new FHIRPathEngine(TestingUtilities.context);
ExpressionNode node = fp.parse(expression);
@ -86,7 +85,7 @@ public class FluentPathTests {
if (fp.hasLog())
System.out.println(fp.takeLog());
Assert.assertTrue(String.format("Expected %d objects but found %d", count, outcome.size()), outcome.size() == count);
Assertions.assertTrue(outcome.size() == count, String.format("Expected %d objects but found %d", count, outcome.size()));
CommaSeparatedStringBuilder msg = new CommaSeparatedStringBuilder();
for (String t : types)
msg.append(t);
@ -94,16 +93,16 @@ public class FluentPathTests {
boolean found = false;
String type = b.fhirType();
for (String t : types)
if (type.equals(t))
if (type.equals(t))
found = true;
Assert.assertTrue(String.format("Object type %s not ok from %s", type, msg), found);
Assertions.assertTrue(found, String.format("Object type %s not ok from %s", type, msg));
}
}
@SuppressWarnings("deprecation")
private void testBoolean(Resource resource, String expression, boolean value) throws FileNotFoundException, IOException, FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
FHIRPathEngine fp = new FHIRPathEngine(TestingUtilities.context);
ExpressionNode node = fp.parse(expression);
@ -112,13 +111,13 @@ public class FluentPathTests {
if (fp.hasLog())
System.out.println(fp.takeLog());
Assert.assertTrue("Wrong answer", fp.convertToBoolean(outcome) == value);
Assertions.assertEquals(fp.convertToBoolean(outcome), value, "Wrong answer");
}
@SuppressWarnings("deprecation")
private void testBoolean(Resource resource, Base focus, String focusType, String expression, boolean value) throws FileNotFoundException, IOException, FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
FHIRPathEngine fp = new FHIRPathEngine(TestingUtilities.context);
ExpressionNode node = fp.parse(expression);
@ -127,12 +126,12 @@ public class FluentPathTests {
if (fp.hasLog())
System.out.println(fp.takeLog());
Assert.assertTrue("Wrong answer", fp.convertToBoolean(outcome) == value);
Assertions.assertEquals(fp.convertToBoolean(outcome), value, "Wrong answer");
}
private void testWrong(Resource resource, String expression) throws FileNotFoundException, IOException, FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
FHIRPathEngine fp = new FHIRPathEngine(TestingUtilities.context);
try {
@ -141,7 +140,7 @@ public class FluentPathTests {
fp.evaluate(null, null, resource, node);
if (fp.hasLog())
System.out.println(fp.takeLog());
Assert.assertTrue("Fail expected", false);
Assertions.fail("Fail expected");
} catch (PathEngineException e) {
// ok
}
@ -713,7 +712,7 @@ public class FluentPathTests {
testBoolean(patient(), "(1 | 2 | 3).count() = 3", true);
testBoolean(patient(), "(1 | 2 | 2).count() = 2", true); // merge duplicates
}
@Test
public void testIn() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), "1 in (1 | 2 | 3)", true);
@ -735,7 +734,7 @@ public class FluentPathTests {
testBoolean(patient(), "(true and true) = true", true);
testBoolean(patient(), "(true and false) = false", true);
testBoolean(patient(), "(true and {}) = {}", true);
testBoolean(patient(), "(false and true) = false", true);
testBoolean(patient(), "(false and false) = false", true);
testBoolean(patient(), "(false and {}) = false", true);
@ -750,7 +749,7 @@ public class FluentPathTests {
testBoolean(patient(), "(true or true) = true", true);
testBoolean(patient(), "(true or false) = true", true);
testBoolean(patient(), "(true or {}) = true", true);
testBoolean(patient(), "(false or true) = true", true);
testBoolean(patient(), "(false or false) = false", true);
testBoolean(patient(), "(false or {}) = {}", true);
@ -765,7 +764,7 @@ public class FluentPathTests {
testBoolean(patient(), "(true xor true) = false", true);
testBoolean(patient(), "(true xor false) = true", true);
testBoolean(patient(), "(true xor {}) = {}", true);
testBoolean(patient(), "(false xor true) = true", true);
testBoolean(patient(), "(false xor false) = false", true);
testBoolean(patient(), "(false xor {}) = {}", true);
@ -774,13 +773,13 @@ public class FluentPathTests {
testBoolean(patient(), "({} xor false) = {}", true);
testBoolean(patient(), "({} xor {}) = {}", true);
}
@Test
public void testBooleanImplies() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), "(true implies true) = true", true);
testBoolean(patient(), "(true implies false) = false", true);
testBoolean(patient(), "(true implies {}) = {}", true);
testBoolean(patient(), "(false implies true) = true", true);
testBoolean(patient(), "(false implies false) = true", true);
testBoolean(patient(), "(false implies {}) = true", true);
@ -789,12 +788,12 @@ public class FluentPathTests {
testBoolean(patient(), "({} implies false) = true", true);
testBoolean(patient(), "({} implies {}) = true", true);
}
@Test
public void testPlus() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), "1 + 1 = 2", true);
testBoolean(patient(), "1 + 0 = 1", true);
testBoolean(patient(), "1.2 + 1.8 = 3.0", true);
testBoolean(patient(), "1.2 + 1.8 = 3.0", true);
testBoolean(patient(), "'a'+'b' = 'ab'", true);
}
@ -802,56 +801,56 @@ public class FluentPathTests {
public void testConcatenate() throws FileNotFoundException, IOException, FHIRException {
testBoolean(patient(), "1 & 1 = '11'", true);
testBoolean(patient(), "1 & 'a' = '1a'", true);
testBoolean(patient(), "{} & 'b' = 'b'", true);
testBoolean(patient(), "(1 | 2 | 3) & 'b' = '1,2,3b'", true);
testBoolean(patient(), "{} & 'b' = 'b'", true);
testBoolean(patient(), "(1 | 2 | 3) & 'b' = '1,2,3b'", true);
testBoolean(patient(), "'a'&'b' = 'ab'", true);
}
@Test
public void testMinus() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), "1 - 1 = 0", true);
testBoolean(patient(), "1 - 0 = 1", true);
testBoolean(patient(), "1.8 - 1.2 = 0.6", true);
testBoolean(patient(), "1.8 - 1.2 = 0.6", true);
testWrong(patient(), "'a'-'b' = 'ab'");
}
@Test
public void testMultiply() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), "1 * 1 = 1", true);
testBoolean(patient(), "1 * 0 = 0", true);
testBoolean(patient(), "1.2 * 1.8 = 2.16", true);
testBoolean(patient(), "1.2 * 1.8 = 2.16", true);
}
@Test
public void testDivide() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), "1 / 1 = 1", true);
testBoolean(patient(), "4 / 2 = 2", true);
testBoolean(patient(), "1 / 2 = 0.5", true);
testBoolean(patient(), "1.2 / 1.8 = 0.67", true);
testBoolean(patient(), "1.2 / 1.8 = 0.67", true);
}
@Test
public void testDiv() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), "1 div 1 = 1", true);
testBoolean(patient(), "4 div 2 = 2", true);
testBoolean(patient(), "5 div 2 = 2", true);
testBoolean(patient(), "2.2 div 1.8 = 1", true);
testBoolean(patient(), "2.2 div 1.8 = 1", true);
}
@Test
public void testMod() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), "1 mod 1 = 0", true);
testBoolean(patient(), "4 mod 2 = 0", true);
testBoolean(patient(), "5 mod 2 = 1", true);
testBoolean(patient(), "2.2 mod 1.8 = 0.4", true);
testBoolean(patient(), "2.2 mod 1.8 = 0.4", true);
}
@Test
public void testPrecedence() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), "1+2*3+4 = 11", true);
}
@Test
public void testVariables() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), "%sct = 'http://snomed.info/sct'", true);
@ -859,28 +858,28 @@ public class FluentPathTests {
testBoolean(patient(), "%ucum = 'http://unitsofmeasure.org'", true);
testBoolean(patient(), "%\"vs-administrative-gender\" = 'http://hl7.org/fhir/ValueSet/administrative-gender'", true);
}
@Test
public void testExtension() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), "Patient.birthDate.extension('http://hl7.org/fhir/StructureDefinition/patient-birthTime').exists()", true);
testBoolean(patient(), "Patient.birthDate.extension(%\"ext-patient-birthTime\").exists()", true);
testBoolean(patient(), "Patient.birthDate.extension('http://hl7.org/fhir/StructureDefinition/patient-birthTime1').empty()", true);
}
@Test
public void testDollarResource() throws FileNotFoundException, FHIRFormatError, IOException, FHIRException {
testBoolean(patient(), patient().getManagingOrganization(), "Reference", "reference.startsWith('#').not() or (reference.substring(1).trace('url') in %resource.contained.id.trace('ids'))", true);
testBoolean(patient(), patient(), "Patient", "contained.select(('#'+id in %resource.descendents().reference).not()).empty()", true);
testWrong(patient(), "contained.select(('#'+id in %resource.descendents().reference).not()).empty()");
}
@Test
public void testTyping() throws FileNotFoundException, IOException, FHIRException {
ElementDefinition ed = new ElementDefinition();
ed.getBinding().setValueSet(new UriType("http://test.org"));
testBoolean(null, ed.getBinding().getValueSet(), "ElementDefinition.binding.valueSetUri", "startsWith('http:') or startsWith('https') or startsWith('urn:')", true);
}
@Test
public void testDecimalRA() throws FileNotFoundException, IOException, FHIRException {
RiskAssessment r = new RiskAssessment();
@ -895,20 +894,20 @@ public class FluentPathTests {
sq1.setCode("%");
sq1.setSystem("http://unitsofmeasure.org");
r.addPrediction().setProbability(new Range().setLow(sq).setHigh(sq1));
testBoolean(r, r.getPrediction().get(0).getProbability(), "RiskAssessment.prediction.probabilityRange",
"(low.empty() or ((low.code = '%') and (low.system = %ucum))) and (high.empty() or ((high.code = '%') and (high.system = %ucum)))", true);
testBoolean(r, r.getPrediction().get(0).getProbability(), "RiskAssessment.prediction.probabilityRange",
"(low.empty() or ((low.code = '%') and (low.system = %ucum))) and (high.empty() or ((high.code = '%') and (high.system = %ucum)))", true);
testBoolean(r, r.getPrediction().get(0), "RiskAssessment.prediction", "probability is decimal implies probability.as(decimal) <= 100", true);
r.getPrediction().get(0).setProbability(new DecimalType(80));
testBoolean(r, r.getPrediction().get(0), "RiskAssessment.prediction", "probability.as(decimal) <= 100", true);
}
@Test
public void testAppointment() throws FileNotFoundException, IOException, FHIRException {
testBoolean(appointment(), "(start and end) or status = 'proposed' or status = 'cancelled'", true);
testBoolean(appointment(), "start.empty() xor end.exists()", true);
}
@Test
public void testQuestionnaire() throws FileNotFoundException, IOException, FHIRException {
Questionnaire q = (Questionnaire) new JsonParser().parse(new FileInputStream("C:/work/org.hl7.fhir.2016May/build/publish/questionnaire-example-gcs.json"));
@ -920,7 +919,7 @@ public class FluentPathTests {
private void testQItem(QuestionnaireItemComponent qi) throws FileNotFoundException, IOException, FHIRException {
testBoolean(null, qi, "Questionnaire.item", "(type = 'choice' or type = 'open-choice') or (options.empty() and option.empty())", true);
}
@Test
public void testExtensionDefinitions() throws FileNotFoundException, IOException, FHIRException {
Bundle b = (Bundle) new JsonParser().parse(new FileInputStream("C:/work/org.hl7.fhir.2016May/build/publish/extension-definitions.json"));
@ -930,7 +929,7 @@ public class FluentPathTests {
}
private void testStructureDefinition(StructureDefinition sd) throws FileNotFoundException, IOException, FHIRException {
testBoolean(sd, sd, "StructureDefinition", "snapshot.element.tail().all(path.startsWith(%resource.snapshot.element.first().path&'.')) and differential.element.tail().all(path.startsWith(%resource.differential.element.first().path&'.'))", true);
testBoolean(sd, sd, "StructureDefinition", "snapshot.element.tail().all(path.startsWith(%resource.snapshot.element.first().path&'.')) and differential.element.tail().all(path.startsWith(%resource.differential.element.first().path&'.'))", true);
}
@Test

View File

@ -10,7 +10,7 @@ import org.hl7.fhir.dstu2016may.formats.JsonParser;
import org.hl7.fhir.dstu2016may.model.Bundle;
import org.hl7.fhir.dstu2016may.model.Resource;
import org.hl7.fhir.exceptions.FHIRException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class MessageTest {

View File

@ -12,7 +12,7 @@ import org.hl7.fhir.dstu2016may.model.Resource;
import org.hl7.fhir.dstu2016may.utils.SimpleWorkerContext;
import org.hl7.fhir.utilities.Utilities;
import junit.framework.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -38,14 +38,13 @@ public class ParserTests {
}
}
@SuppressWarnings("deprecation")
private void testRoundTrip(String filename, String name) throws Exception {
System.out.println(name);
Resource r = new org.hl7.fhir.dstu2016may.formats.XmlParser().parse(new FileInputStream(filename));
String fn = makeTempFilename();
new org.hl7.fhir.dstu2016may.formats.XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), r);
String msg = TestingUtilities.checkXMLIsSame(filename, fn);
Assert.assertTrue(name+": "+msg, msg == null);
Assertions.assertNull(msg, name + ": " + msg);
String j1 = makeTempFilename();
new org.hl7.fhir.dstu2016may.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(j1), r);
@ -57,12 +56,12 @@ public class ParserTests {
fn = makeTempFilename();
Manager.compose(TestingUtilities.context, re, new FileOutputStream(fn), FhirFormat.XML, OutputStyle.PRETTY, null);
msg = TestingUtilities.checkXMLIsSame(filename, fn);
Assert.assertTrue(name+": "+msg, msg == null);
Assertions.assertNull(msg, name + ": " + msg);
String j2 = makeTempFilename();
Manager.compose(TestingUtilities.context, re, new FileOutputStream(j2), FhirFormat.JSON, OutputStyle.PRETTY, null);
msg = TestingUtilities.checkJsonIsSame(j1, j2);
Assert.assertTrue(name+": "+msg, msg == null);
Assertions.assertNull(msg, name + ": " + msg);
// ok, we've produced equivalent JSON by both methods.
// now, we're going to reverse the process
@ -70,7 +69,7 @@ public class ParserTests {
fn = makeTempFilename();
new org.hl7.fhir.dstu2016may.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), r);
msg = TestingUtilities.checkJsonIsSame(j2, fn);
Assert.assertTrue(name+": "+msg, msg == null);
Assertions.assertNull(msg, name + ": " + msg);
String x1 = makeTempFilename();
new org.hl7.fhir.dstu2016may.formats.XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(x1), r);
@ -78,14 +77,14 @@ public class ParserTests {
fn = makeTempFilename();
Manager.compose(TestingUtilities.context, re, new FileOutputStream(fn), FhirFormat.JSON, OutputStyle.PRETTY, null);
msg = TestingUtilities.checkJsonIsSame(j1, fn);
Assert.assertTrue(name+": "+msg, msg == null);
Assertions.assertNull(msg, name + ": " + msg);
String x2 = makeTempFilename();
Manager.compose(TestingUtilities.context, re, new FileOutputStream(x2), FhirFormat.XML, OutputStyle.PRETTY, null);
msg = TestingUtilities.checkXMLIsSame(x1, x2);
Assert.assertTrue(name+": "+msg, msg == null);
Assertions.assertNull(msg, name + ": " + msg);
msg = TestingUtilities.checkXMLIsSame(filename, x1);
Assert.assertTrue(name+": "+msg, msg == null);
Assertions.assertNull(msg, name + ": " + msg);
}

View File

@ -95,6 +95,20 @@
<artifactId>Saxon-HE</artifactId>
<scope>test</scope>
</dependency>
<!-- JUnit Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,9 +1,12 @@
package org.hl7.fhir.dstu3.test;
import junit.framework.Assert;
import org.hl7.fhir.dstu3.context.SimpleWorkerContext;
import org.hl7.fhir.dstu3.formats.XmlParser;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.Base;
import org.hl7.fhir.dstu3.model.BooleanType;
import org.hl7.fhir.dstu3.model.ExpressionNode;
import org.hl7.fhir.dstu3.model.PrimitiveType;
import org.hl7.fhir.dstu3.model.Resource;
import org.hl7.fhir.dstu3.test.support.TestingUtilities;
import org.hl7.fhir.dstu3.utils.FHIRPathEngine;
import org.hl7.fhir.exceptions.FHIRException;
@ -36,8 +39,8 @@ public class FluentPathTests {
@BeforeAll
public void setup() throws IOException {
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\definitions.xml.zip");
this.fp = new FHIRPathEngine(TestingUtilities.context);
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\definitions.xml.zip");
this.fp = new FHIRPathEngine(TestingUtilities.context);
}
@ParameterizedTest(name = "{index}: file {0}")

View File

@ -1,18 +1,22 @@
package org.hl7.fhir.dstu3.test;
import junit.framework.Assert;
import org.apache.commons.codec.Charsets;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.dstu3.conformance.ProfileUtilities;
import org.hl7.fhir.dstu3.context.SimpleWorkerContext;
import org.hl7.fhir.dstu3.formats.IParser.OutputStyle;
import org.hl7.fhir.dstu3.formats.XmlParser;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.Base;
import org.hl7.fhir.dstu3.model.ExpressionNode.CollectionStatus;
import org.hl7.fhir.dstu3.model.MetadataResource;
import org.hl7.fhir.dstu3.model.Resource;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.dstu3.model.TestScript;
import org.hl7.fhir.dstu3.model.TestScript.SetupActionAssertComponent;
import org.hl7.fhir.dstu3.model.TestScript.SetupActionOperationComponent;
import org.hl7.fhir.dstu3.model.TestScript.TestScriptFixtureComponent;
import org.hl7.fhir.dstu3.model.TestScript.TestScriptTestComponent;
import org.hl7.fhir.dstu3.model.TypeDetails;
import org.hl7.fhir.dstu3.test.support.TestingUtilities;
import org.hl7.fhir.dstu3.utils.CodingUtilities;
import org.hl7.fhir.dstu3.utils.FHIRPathEngine;
@ -22,6 +26,7 @@ import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.exceptions.PathEngineException;
import org.hl7.fhir.utilities.Utilities;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@ -29,7 +34,12 @@ import org.junit.jupiter.params.provider.MethodSource;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
@Disabled
@ -82,7 +92,7 @@ public class SnapShotGenerationTests {
//ok, now the asserts:
for (int i = 1; i < test.getAction().size(); i++) {
SetupActionAssertComponent a = test.getAction().get(i).getAssert();
Assert.assertTrue(a.getLabel() + ": " + a.getDescription(), fp.evaluateToBoolean(source, source, a.getExpression()));
Assertions.assertTrue(fp.evaluateToBoolean(source, source, a.getExpression()), a.getLabel() + ": " + a.getDescription());
}
}

View File

@ -1,8 +1,8 @@
package org.hl7.fhir.dstu3.test;
import junit.framework.Assert;
import org.hl7.fhir.dstu3.utils.formats.Turtle;
import org.hl7.fhir.utilities.TextFile;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -17,9 +17,9 @@ public class TurtleTests {
String s = TextFile.fileToString(filename);
Turtle ttl = new Turtle();
ttl.parse(s);
Assert.assertTrue(ok);
Assertions.assertTrue(ok);
} catch (Exception e) {
Assert.assertTrue(e.getMessage(), !ok);
Assertions.assertFalse(ok, e.getMessage());
}
}

View File

@ -101,6 +101,20 @@
<artifactId>Saxon-HE</artifactId>
<scope>test</scope>
</dependency>
<!-- JUnit Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -1,11 +1,8 @@
package org.hl7.fhir.r4.model;
import org.junit.Ignore;
import org.junit.Test;
import java.util.TimeZone;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
public class BaseDateTimeTypeTest {
@ -19,52 +16,52 @@ public class BaseDateTimeTypeTest {
* </ul>
*/
@Test
@Ignore
@Disabled
public void equalsUsingFhirPathRules() {
// Exact same - Same timezone
assertTrue(compareDateTimes("2001-01-02T11:22:33.444Z", "2001-01-02T11:22:33.444Z"));
Assertions.assertTrue(compareDateTimes("2001-01-02T11:22:33.444Z", "2001-01-02T11:22:33.444Z"));
// Exact same - Different timezone
assertTrue(compareDateTimes("2001-01-02T11:22:33.444-03:00", "2001-01-02T10:22:33.444-04:00"));
Assertions.assertTrue(compareDateTimes("2001-01-02T11:22:33.444-03:00", "2001-01-02T10:22:33.444-04:00"));
// Exact same - Dates
assertTrue(compareDateTimes("2001", "2001"));
assertTrue(compareDateTimes("2001-01", "2001-01"));
assertTrue(compareDateTimes("2001-01-02", "2001-01-02"));
Assertions.assertTrue(compareDateTimes("2001", "2001"));
Assertions.assertTrue(compareDateTimes("2001-01", "2001-01"));
Assertions.assertTrue(compareDateTimes("2001-01-02", "2001-01-02"));
// Same precision but different values - Dates
assertFalse(compareDateTimes("2001", "2002"));
assertFalse(compareDateTimes("2001-01", "2001-02"));
assertFalse(compareDateTimes("2001-01-02", "2001-01-03"));
Assertions.assertFalse(compareDateTimes("2001", "2002"));
Assertions.assertFalse(compareDateTimes("2001-01", "2001-02"));
Assertions.assertFalse(compareDateTimes("2001-01-02", "2001-01-03"));
// Different instant - Same timezone
assertFalse(compareDateTimes("2001-01-02T11:22:33.444Z", "2001-01-02T11:22:33.445Z"));
assertFalse(compareDateTimes("2001-01-02T11:22:33.445Z", "2001-01-02T11:22:33.444Z"));
Assertions.assertFalse(compareDateTimes("2001-01-02T11:22:33.444Z", "2001-01-02T11:22:33.445Z"));
Assertions.assertFalse(compareDateTimes("2001-01-02T11:22:33.445Z", "2001-01-02T11:22:33.444Z"));
// FHIRPath tests:
assertFalse(compareDateTimes("1974-12-25", "1974-12-25T12:34:00+10:00"));
assertFalse(compareDateTimes("1974-12-25T12:34:00+10:00", "1974-12-25"));
assertFalse(compareDateTimes("1974-12-25", "1974-12-25T12:34:00-10:00"));
assertFalse(compareDateTimes("1974-12-25T12:34:00-10:00", "1974-12-25"));
assertFalse(compareDateTimes("1974-12-25", "1974-12-25T12:34:00Z"));
assertFalse(compareDateTimes("1974-12-25T12:34:00Z", "1974-12-25"));
assertFalse(compareDateTimes("2012-04-15", "2012-04-16"));
assertFalse(compareDateTimes("2012-04-16", "2012-04-15"));
assertFalse(compareDateTimes("2012-04-15T15:00:00", "2012-04-15T10:00:00"));
assertFalse(compareDateTimes("2012-04-15T10:00:00", "2012-04-15T15:00:00"));
assertFalse(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T01:15:00.0-05:00"));
assertFalse(compareDateTimes("2017-11-05T01:15:00.0-05:00", "2017-11-05T01:30:00.0-04:00"));
assertNull(compareDateTimes("1974-12-25", "1974-12-25T12:34:00"));
assertNull(compareDateTimes("1974-12-25T12:34:00", "1974-12-25"));
assertNull(compareDateTimes("2012-04-15T10:00:00", "2012-04-15"));
assertNull(compareDateTimes("2012-04-15T15:00:00Z", "2012-04-15T10:00:00"));
assertNull(compareDateTimes("2012-04-15T10:00:00", "2012-04-15T15:00:00Z"));
assertTrue(compareDateTimes("1974-12-25", "1974-12-25"));
assertTrue(compareDateTimes("2012-04-15", "2012-04-15"));
assertTrue(compareDateTimes("2012-04-15T15:00:00+02:00", "2012-04-15T16:00:00+03:00"));
assertTrue(compareDateTimes("2012-04-15T16:00:00+03:00", "2012-04-15T15:00:00+02:00"));
assertTrue(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T00:30:00.0-05:00"));
assertTrue(compareDateTimes("2017-11-05T00:30:00.0-05:00", "2017-11-05T01:30:00.0-04:00"));
Assertions.assertFalse(compareDateTimes("1974-12-25", "1974-12-25T12:34:00+10:00"));
Assertions.assertFalse(compareDateTimes("1974-12-25T12:34:00+10:00", "1974-12-25"));
Assertions.assertFalse(compareDateTimes("1974-12-25", "1974-12-25T12:34:00-10:00"));
Assertions.assertFalse(compareDateTimes("1974-12-25T12:34:00-10:00", "1974-12-25"));
Assertions.assertFalse(compareDateTimes("1974-12-25", "1974-12-25T12:34:00Z"));
Assertions.assertFalse(compareDateTimes("1974-12-25T12:34:00Z", "1974-12-25"));
Assertions.assertFalse(compareDateTimes("2012-04-15", "2012-04-16"));
Assertions.assertFalse(compareDateTimes("2012-04-16", "2012-04-15"));
Assertions.assertFalse(compareDateTimes("2012-04-15T15:00:00", "2012-04-15T10:00:00"));
Assertions.assertFalse(compareDateTimes("2012-04-15T10:00:00", "2012-04-15T15:00:00"));
Assertions.assertFalse(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T01:15:00.0-05:00"));
Assertions.assertFalse(compareDateTimes("2017-11-05T01:15:00.0-05:00", "2017-11-05T01:30:00.0-04:00"));
Assertions.assertNull(compareDateTimes("1974-12-25", "1974-12-25T12:34:00"));
Assertions.assertNull(compareDateTimes("1974-12-25T12:34:00", "1974-12-25"));
Assertions.assertNull(compareDateTimes("2012-04-15T10:00:00", "2012-04-15"));
Assertions.assertNull(compareDateTimes("2012-04-15T15:00:00Z", "2012-04-15T10:00:00"));
Assertions.assertNull(compareDateTimes("2012-04-15T10:00:00", "2012-04-15T15:00:00Z"));
Assertions.assertTrue(compareDateTimes("1974-12-25", "1974-12-25"));
Assertions.assertTrue(compareDateTimes("2012-04-15", "2012-04-15"));
Assertions.assertTrue(compareDateTimes("2012-04-15T15:00:00+02:00", "2012-04-15T16:00:00+03:00"));
Assertions.assertTrue(compareDateTimes("2012-04-15T16:00:00+03:00", "2012-04-15T15:00:00+02:00"));
Assertions.assertTrue(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T00:30:00.0-05:00"));
Assertions.assertTrue(compareDateTimes("2017-11-05T00:30:00.0-05:00", "2017-11-05T01:30:00.0-04:00"));
assertFalse(compareDateTimes("2016-12-02T13:00:00Z", "2016-11-02T10:00:00")); // no timezone, but cannot be the same time
assertNull(compareDateTimes("2016-12-02T13:00:00Z", "2016-12-02T10:00:00")); // no timezone, might be the same time
Assertions.assertFalse(compareDateTimes("2016-12-02T13:00:00Z", "2016-11-02T10:00:00")); // no timezone, but cannot be the same time
Assertions.assertNull(compareDateTimes("2016-12-02T13:00:00Z", "2016-12-02T10:00:00")); // no timezone, might be the same time
}
private Boolean compareDateTimes(String theLeft, String theRight) {

View File

@ -1,6 +1,5 @@
package org.hl7.fhir.r4.test;
import junit.framework.Assert;
import org.apache.commons.lang3.NotImplementedException;
import org.fhir.ucum.UcumException;
import org.hl7.fhir.exceptions.FHIRException;
@ -12,6 +11,7 @@ import org.hl7.fhir.r4.utils.FHIRPathEngine;
import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.TestInstance;
@ -34,7 +34,6 @@ import java.util.Map;
import java.util.stream.Stream;
@Disabled
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class FHIRPathTests {
public class FHIRPathTestEvaluationServices implements IEvaluationContext {
@ -93,7 +92,7 @@ public class FHIRPathTests {
private static FHIRPathEngine fp;
@BeforeAll
public void setup() {
public static void setup() {
fp = new FHIRPathEngine(TestingUtilities.context());
}
@ -161,9 +160,9 @@ public class FHIRPathTests {
fp.check(res, res.getResourceType().toString(), res.getResourceType().toString(), node);
}
outcome = fp.evaluate(res, node);
Assert.assertTrue(String.format("Expected exception parsing %s", expression), !fail);
Assertions.assertFalse(fail, String.format("Expected exception parsing %s", expression));
} catch (Exception e) {
Assert.assertTrue(String.format("Unexpected exception parsing %s: " + e.getMessage(), expression), fail);
Assertions.assertTrue(fail, String.format("Unexpected exception parsing %s: " + e.getMessage(), expression));
}
if ("true".equals(test.getAttribute("predicate"))) {
@ -176,7 +175,7 @@ public class FHIRPathTests {
List<Element> expected = new ArrayList<Element>();
XMLUtil.getNamedChildren(test, "output", expected);
Assert.assertTrue(String.format("Expected %d objects but found %d for expression %s", expected.size(), outcome.size(), expression), outcome.size() == expected.size());
Assertions.assertEquals(outcome.size(), expected.size(), String.format("Expected %d objects but found %d for expression %s", expected.size(), outcome.size(), expression));
if ("false".equals(test.getAttribute("ordered"))) {
for (int i = 0; i < Math.min(outcome.size(), expected.size()); i++) {
String tn = outcome.get(i).fhirType();
@ -191,22 +190,22 @@ public class FHIRPathTests {
(Utilities.noString(e.getTextContent()) || e.getTextContent().equals(s)))
found = true;
}
Assert.assertTrue(String.format("Outcome %d: Value %s of type %s not expected for %s", i, s, tn, expression), found);
Assertions.assertTrue(found, String.format("Outcome %d: Value %s of type %s not expected for %s", i, s, tn, expression));
}
} else {
for (int i = 0; i < Math.min(outcome.size(), expected.size()); i++) {
String tn = expected.get(i).getAttribute("type");
if (!Utilities.noString(tn)) {
Assert.assertTrue(String.format("Outcome %d: Type should be %s but was %s", i, tn, outcome.get(i).fhirType()), tn.equals(outcome.get(i).fhirType()));
Assertions.assertEquals(tn, outcome.get(i).fhirType(), String.format("Outcome %d: Type should be %s but was %s", i, tn, outcome.get(i).fhirType()));
}
String v = expected.get(i).getTextContent();
if (!Utilities.noString(v)) {
if (outcome.get(i) instanceof Quantity) {
Quantity q = fp.parseQuantityString(v);
Assert.assertTrue(String.format("Outcome %d: Value should be %s but was %s", i, v, outcome.get(i).toString()), outcome.get(i).equalsDeep(q));
Assertions.assertTrue(outcome.get(i).equalsDeep(q), String.format("Outcome %d: Value should be %s but was %s", i, v, outcome.get(i).toString()));
} else {
Assert.assertTrue(String.format("Outcome %d: Value should be a primitive type but was %s", i, outcome.get(i).fhirType()), outcome.get(i) instanceof PrimitiveType);
Assert.assertTrue(String.format("Outcome %d: Value should be %s but was %s for expression %s", i, v, outcome.get(i).toString(), expression), v.equals(((PrimitiveType) outcome.get(i)).asStringValue()));
Assertions.assertTrue(outcome.get(i) instanceof PrimitiveType, String.format("Outcome %d: Value should be a primitive type but was %s", i, outcome.get(i).fhirType()));
Assertions.assertEquals(v, ((PrimitiveType) outcome.get(i)).asStringValue(), String.format("Outcome %d: Value should be %s but was %s for expression %s", i, v, outcome.get(i).toString(), expression));
}
}
}

View File

@ -3,7 +3,6 @@ package org.hl7.fhir.r4.test;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import junit.framework.Assert;
import org.apache.commons.collections4.map.HashedMap;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r4.formats.XmlParser;
@ -13,12 +12,14 @@ import org.hl7.fhir.r4.utils.LiquidEngine;
import org.hl7.fhir.r4.utils.LiquidEngine.ILiquidEngineIcludeResolver;
import org.hl7.fhir.r4.utils.LiquidEngine.LiquidDocument;
import org.hl7.fhir.utilities.TextFile;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
@ -27,8 +28,9 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@RunWith(Parameterized.class)
@Disabled
public class LiquidEngineTests implements ILiquidEngineIcludeResolver {
private static Map<String, Resource> resources = new HashedMap<>();
@ -37,29 +39,31 @@ public class LiquidEngineTests implements ILiquidEngineIcludeResolver {
private JsonObject test;
private LiquidEngine engine;
@Parameters(name = "{index}: file{0}")
public static Iterable<Object[]> data() throws ParserConfigurationException, SAXException, IOException {
testdoc = (JsonObject) new com.google.gson.JsonParser().parse(TextFile.fileToString(TestingUtilities.resourceNameToFile("liquid", "liquid-tests.json")));
JsonArray tests = testdoc.getAsJsonArray("tests");
List<Object[]> objects = new ArrayList<Object[]>(tests.size());
for (JsonElement n : tests) {
objects.add(new Object[]{n});
}
return objects;
}
public LiquidEngineTests(JsonObject test) {
super();
this.test = test;
}
@Before
public void setUp() throws Exception {
@BeforeEach
public void setUp() {
engine = new LiquidEngine(TestingUtilities.context(), null);
engine.setIncludeResolver(this);
}
public static Stream<Arguments> data() throws ParserConfigurationException, SAXException, IOException {
testdoc = (JsonObject) new com.google.gson.JsonParser().parse(TextFile.fileToString(TestingUtilities.resourceNameToFile("liquid", "liquid-tests.json")));
JsonArray tests = testdoc.getAsJsonArray("tests");
List<Arguments> objects = new ArrayList<>();
for (JsonElement n : tests) {
objects.add(Arguments.of(n));
}
return objects.stream();
}
@ParameterizedTest(name = "{index}: file{0}")
@MethodSource("data")
public void test(JsonObject test) throws Exception {
this.test = test;
LiquidDocument doc = engine.parse(test.get("template").getAsString(), "test-script");
String output = engine.evaluate(doc, loadResource(), null);
Assertions.assertTrue(test.get("output").getAsString().equals(output));
}
@Override
public String fetchInclude(LiquidEngine engine, String name) {
if (test.has("includes") && test.getAsJsonObject("includes").has(name))
@ -76,14 +80,4 @@ public class LiquidEngineTests implements ILiquidEngineIcludeResolver {
}
return resources.get(test.get("focus").getAsString());
}
@Test
@Ignore
public void test() throws Exception {
LiquidDocument doc = engine.parse(test.get("template").getAsString(), "test-script");
String output = engine.evaluate(doc, loadResource(), null);
Assert.assertTrue(test.get("output").getAsString().equals(output));
}
}

View File

@ -1,6 +1,5 @@
package org.hl7.fhir.r4.test;
import junit.framework.Assert;
import org.apache.commons.lang3.NotImplementedException;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
@ -11,11 +10,15 @@ import org.hl7.fhir.r4.conformance.ProfileUtilities.ProfileKnowledgeProvider;
import org.hl7.fhir.r4.formats.IParser.OutputStyle;
import org.hl7.fhir.r4.formats.JsonParser;
import org.hl7.fhir.r4.formats.XmlParser;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r4.model.Base;
import org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionBindingComponent;
import org.hl7.fhir.r4.model.ExpressionNode.CollectionStatus;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r4.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.r4.model.TypeDetails;
import org.hl7.fhir.r4.model.ValueSet;
import org.hl7.fhir.r4.test.utils.TestingUtilities;
import org.hl7.fhir.r4.utils.FHIRPathEngine;
import org.hl7.fhir.r4.utils.FHIRPathEngine.IEvaluationContext;
@ -36,7 +39,11 @@ import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
@ -399,9 +406,9 @@ public class SnapShotGenerationTests {
testGen(test, context);
else
testSort(test, context);
Assert.assertTrue("Should have failed", false);
Assertions.assertTrue(false, "Should have failed");
} catch (Throwable e) {
Assert.assertTrue("all ok", true);
Assertions.assertTrue(true, "all ok");
}
} else if (test.isGen())
@ -411,7 +418,7 @@ public class SnapShotGenerationTests {
for (Rule r : test.getRules()) {
StructureDefinition sdn = new StructureDefinition();
boolean ok = fp.evaluateToBoolean(sdn, sdn, sdn, r.expression);
Assert.assertTrue(r.description, ok);
Assertions.assertTrue(ok, r.description);
}
}

View File

@ -2,24 +2,20 @@ package org.hl7.fhir.r4.test.misc;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import javax.xml.parsers.ParserConfigurationException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
@RunWith(Parameterized.class)
public class StructureMapTests {
@Parameters(name = "{index}: file {0}")
public static Iterable<Object[]> data() throws ParserConfigurationException, IOException, FHIRFormatError {
public static Stream<Arguments> data() throws ParserConfigurationException, IOException, FHIRFormatError {
List<String> files = new ArrayList<>();
// File dir = new File(Utilities.path(TestingUtilities.home(), "implementations", "r3maps", "R3toR4"));
// for (File f : dir.listFiles())
@ -29,24 +25,18 @@ public class StructureMapTests {
// for (File f : dir.listFiles())
// if (f.getName().endsWith(".map"))
// files.add(f.getAbsolutePath());
List<Object[]> objects = new ArrayList<Object[]>(files.size());
List<Arguments> objects = new ArrayList<>();
//
// for (String fn : files) {
// objects.add(new Object[] { new File(fn).getName(), fn });
// }
return objects;
}
private String filename;
public StructureMapTests(String name, String filename) {
this.filename = filename;
return objects.stream();
}
@SuppressWarnings("deprecation")
@Test
@Ignore
public void test() throws FHIRException, FileNotFoundException, IOException {
@ParameterizedTest(name = "{index}: file {0}")
@MethodSource("data")
public void test(String name, String filename) throws FHIRException, FileNotFoundException, IOException {
// if (TestingUtilities.context == null) {
// TestingUtilities.context = SimpleWorkerContext.fromPack(Utilities.path(TestingUtilities.content(), "definitions.xml.zip"));
// }

View File

@ -108,11 +108,17 @@
<scope>test</scope>
</dependency>
<!-- JUNIT JUPITER (JUNIT5) -->
<!-- JUnit Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -9,9 +9,9 @@ package org.hl7.fhir.r5.test.utils;
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -20,19 +20,12 @@ package org.hl7.fhir.r5.test.utils;
* #L%
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.fhir.ucum.UcumEssenceService;
@ -45,79 +38,85 @@ import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.cache.PackageCacheManager;
import org.hl7.fhir.utilities.cache.ToolsVersion;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TestingUtilities {
private static final boolean SHOW_DIFF = true;
static public Map<String, IWorkerContext> fcontexts;
static public Map<String, IWorkerContext> fcontexts;
public static IWorkerContext context() {
return context("4.0.1");
}
public static IWorkerContext context(String version) {
String v = VersionUtilities.getMajMin(version);
public static IWorkerContext context(String version) {
String v = VersionUtilities.getMajMin(version);
if (fcontexts == null) {
fcontexts = new HashMap<>();
}
if (!fcontexts.containsKey(v)) {
PackageCacheManager pcm;
try {
pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
fcontext.setExpansionProfile(new Parameters());
fcontexts.put(v, fcontext);
} catch (Exception e) {
throw new Error(e);
}
}
return fcontexts.get(v);
}
static public boolean silent;
if (!fcontexts.containsKey(v)) {
PackageCacheManager pcm;
try {
pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
fcontext.setExpansionProfile(new Parameters());
fcontexts.put(v, fcontext);
} catch (Exception e) {
throw new Error(e);
}
}
return fcontexts.get(v);
}
static public boolean silent;
static public String fixedpath;
static public String contentpath;
public static String home() {
if (fixedpath != null)
return fixedpath;
return fixedpath;
String s = System.getenv("FHIR_HOME");
if (!Utilities.noString(s))
return s;
s = "C:\\work\\org.hl7.fhir\\build";
// FIXME: change this back
s = "/Users/jamesagnew/git/fhir";
s = "/Users/jamesagnew/git/fhir";
if (new File(s).exists())
return s;
throw new Error("FHIR Home directory not configured");
}
public static String content() throws IOException {
if (contentpath != null)
return contentpath;
return contentpath;
String s = "R:\\fhir\\publish";
if (new File(s).exists())
return s;
return Utilities.path(home(), "publish");
}
// diretory that contains all the US implementation guides
public static String us() {
if (fixedpath != null)
return fixedpath;
return fixedpath;
String s = System.getenv("FHIR_HOME");
if (!Utilities.noString(s))
return s;
@ -126,26 +125,26 @@ public class TestingUtilities {
return s;
throw new Error("FHIR US directory not configured");
}
public static String checkXMLIsSame(InputStream f1, InputStream f2) throws Exception {
String result = compareXml(f1, f2);
return result;
}
public static String checkXMLIsSame(String f1, String f2) throws Exception {
String result = compareXml(f1, f2);
if (result != null && SHOW_DIFF) {
String diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
List<String> command = new ArrayList<String>();
command.add("\"" + diff + "\" \"" + f1 + "\" \"" + f2 + "\"");
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new CSFile("c:\\temp"));
builder.start();
}
return result;
}
public static String checkXMLIsSame(String f1, String f2) throws Exception {
String result = compareXml(f1, f2);
if (result != null && SHOW_DIFF) {
String diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
List<String> command = new ArrayList<String>();
command.add("\"" + diff + "\" \"" + f1 + "\" \"" + f2 + "\"");
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new CSFile("c:\\temp"));
builder.start();
}
return result;
}
private static String compareXml(InputStream f1, InputStream f2) throws Exception {
return compareElements("", loadXml(f1).getDocumentElement(), loadXml(f2).getDocumentElement());
@ -155,93 +154,92 @@ public class TestingUtilities {
return compareElements("", loadXml(f1).getDocumentElement(), loadXml(f2).getDocumentElement());
}
private static String compareElements(String path, Element e1, Element e2) {
if (!e1.getNamespaceURI().equals(e2.getNamespaceURI()))
return "Namespaces differ at "+path+": "+e1.getNamespaceURI()+"/"+e2.getNamespaceURI();
if (!e1.getLocalName().equals(e2.getLocalName()))
return "Names differ at "+path+": "+e1.getLocalName()+"/"+e2.getLocalName();
path = path + "/"+e1.getLocalName();
String s = compareAttributes(path, e1.getAttributes(), e2.getAttributes());
if (!Utilities.noString(s))
return s;
s = compareAttributes(path, e2.getAttributes(), e1.getAttributes());
if (!Utilities.noString(s))
return s;
private static String compareElements(String path, Element e1, Element e2) {
if (!e1.getNamespaceURI().equals(e2.getNamespaceURI()))
return "Namespaces differ at " + path + ": " + e1.getNamespaceURI() + "/" + e2.getNamespaceURI();
if (!e1.getLocalName().equals(e2.getLocalName()))
return "Names differ at " + path + ": " + e1.getLocalName() + "/" + e2.getLocalName();
path = path + "/" + e1.getLocalName();
String s = compareAttributes(path, e1.getAttributes(), e2.getAttributes());
if (!Utilities.noString(s))
return s;
s = compareAttributes(path, e2.getAttributes(), e1.getAttributes());
if (!Utilities.noString(s))
return s;
Node c1 = e1.getFirstChild();
Node c2 = e2.getFirstChild();
c1 = skipBlankText(c1);
c2 = skipBlankText(c2);
while (c1 != null && c2 != null) {
if (c1.getNodeType() != c2.getNodeType())
return "node type mismatch in children of "+path+": "+Integer.toString(e1.getNodeType())+"/"+Integer.toString(e2.getNodeType());
if (c1.getNodeType() == Node.TEXT_NODE) {
if (!normalise(c1.getTextContent()).equals(normalise(c2.getTextContent())))
return "Text differs at "+path+": "+normalise(c1.getTextContent()) +"/"+ normalise(c2.getTextContent());
}
else if (c1.getNodeType() == Node.ELEMENT_NODE) {
s = compareElements(path, (Element) c1, (Element) c2);
if (!Utilities.noString(s))
return s;
}
Node c1 = e1.getFirstChild();
Node c2 = e2.getFirstChild();
c1 = skipBlankText(c1);
c2 = skipBlankText(c2);
while (c1 != null && c2 != null) {
if (c1.getNodeType() != c2.getNodeType())
return "node type mismatch in children of " + path + ": " + Integer.toString(e1.getNodeType()) + "/" + Integer.toString(e2.getNodeType());
if (c1.getNodeType() == Node.TEXT_NODE) {
if (!normalise(c1.getTextContent()).equals(normalise(c2.getTextContent())))
return "Text differs at " + path + ": " + normalise(c1.getTextContent()) + "/" + normalise(c2.getTextContent());
} else if (c1.getNodeType() == Node.ELEMENT_NODE) {
s = compareElements(path, (Element) c1, (Element) c2);
if (!Utilities.noString(s))
return s;
}
c1 = skipBlankText(c1.getNextSibling());
c2 = skipBlankText(c2.getNextSibling());
}
if (c1 != null)
return "node mismatch - more nodes in source in children of "+path;
if (c2 != null)
return "node mismatch - more nodes in target in children of "+path;
return null;
}
c1 = skipBlankText(c1.getNextSibling());
c2 = skipBlankText(c2.getNextSibling());
}
if (c1 != null)
return "node mismatch - more nodes in source in children of " + path;
if (c2 != null)
return "node mismatch - more nodes in target in children of " + path;
return null;
}
private static Object normalise(String text) {
String result = text.trim().replace('\r', ' ').replace('\n', ' ').replace('\t', ' ');
while (result.contains(" "))
result = result.replace(" ", " ");
return result;
}
private static Object normalise(String text) {
String result = text.trim().replace('\r', ' ').replace('\n', ' ').replace('\t', ' ');
while (result.contains(" "))
result = result.replace(" ", " ");
return result;
}
private static String compareAttributes(String path, NamedNodeMap src, NamedNodeMap tgt) {
for (int i = 0; i < src.getLength(); i++) {
Node sa = src.item(i);
String sn = sa.getNodeName();
if (! (sn.equals("xmlns") || sn.startsWith("xmlns:"))) {
Node ta = tgt.getNamedItem(sn);
if (ta == null)
return "Attributes differ at "+path+": missing attribute "+sn;
if (!normalise(sa.getTextContent()).equals(normalise(ta.getTextContent()))) {
byte[] b1 = unBase64(sa.getTextContent());
byte[] b2 = unBase64(ta.getTextContent());
if (!sameBytes(b1, b2))
return "Attributes differ at "+path+": value "+normalise(sa.getTextContent()) +"/"+ normalise(ta.getTextContent());
}
}
}
return null;
}
private static String compareAttributes(String path, NamedNodeMap src, NamedNodeMap tgt) {
for (int i = 0; i < src.getLength(); i++) {
private static boolean sameBytes(byte[] b1, byte[] b2) {
if (b1.length == 0 || b2.length == 0)
return false;
if (b1.length != b2.length)
return false;
for (int i = 0; i < b1.length; i++)
if (b1[i] != b2[i])
return false;
return true;
}
Node sa = src.item(i);
String sn = sa.getNodeName();
if (!(sn.equals("xmlns") || sn.startsWith("xmlns:"))) {
Node ta = tgt.getNamedItem(sn);
if (ta == null)
return "Attributes differ at " + path + ": missing attribute " + sn;
if (!normalise(sa.getTextContent()).equals(normalise(ta.getTextContent()))) {
byte[] b1 = unBase64(sa.getTextContent());
byte[] b2 = unBase64(ta.getTextContent());
if (!sameBytes(b1, b2))
return "Attributes differ at " + path + ": value " + normalise(sa.getTextContent()) + "/" + normalise(ta.getTextContent());
}
}
}
return null;
}
private static byte[] unBase64(String text) {
return Base64.decodeBase64(text);
}
private static boolean sameBytes(byte[] b1, byte[] b2) {
if (b1.length == 0 || b2.length == 0)
return false;
if (b1.length != b2.length)
return false;
for (int i = 0; i < b1.length; i++)
if (b1[i] != b2[i])
return false;
return true;
}
private static Node skipBlankText(Node node) {
while (node != null && (((node.getNodeType() == Node.TEXT_NODE) && Utilities.isWhitespace(node.getTextContent())) || (node.getNodeType() == Node.COMMENT_NODE)))
node = node.getNextSibling();
return node;
}
private static byte[] unBase64(String text) {
return Base64.decodeBase64(text);
}
private static Node skipBlankText(Node node) {
while (node != null && (((node.getNodeType() == Node.TEXT_NODE) && Utilities.isWhitespace(node.getTextContent())) || (node.getNodeType() == Node.COMMENT_NODE)))
node = node.getNextSibling();
return node;
}
private static Document loadXml(String fn) throws Exception {
return loadXml(new FileInputStream(fn));
@ -249,175 +247,37 @@ public class TestingUtilities {
private static Document loadXml(InputStream fn) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
factory.setXIncludeAware(false);
factory.setExpandEntityReferences(false);
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
factory.setXIncludeAware(false);
factory.setExpandEntityReferences(false);
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(fn);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(fn);
}
public static String checkJsonSrcIsSame(String s1, String s2) throws JsonSyntaxException, FileNotFoundException, IOException {
return checkJsonSrcIsSame(s1,s2,true);
return checkJsonSrcIsSame(s1, s2, true);
}
public static String checkJsonSrcIsSame(String s1, String s2, boolean showDiff) throws JsonSyntaxException, FileNotFoundException, IOException {
String result = compareJsonSrc(s1, s2);
if (result != null && SHOW_DIFF && showDiff) {
String diff = null;
String diff = null;
if (System.getProperty("os.name").contains("Linux"))
diff = Utilities.path("/", "usr", "bin", "meld");
else {
if (Utilities.checkFile("WinMerge", Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge"), "\\WinMergeU.exe", null))
diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
else if (Utilities.checkFile("WinMerge", Utilities.path(System.getenv("ProgramFiles(X86)"), "Meld"), "\\Meld.exe", null))
diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "Meld", "Meld.exe");
}
if (diff == null || diff.isEmpty())
return result;
List<String> command = new ArrayList<String>();
String f1 = Utilities.path("[tmp]", "input" + s1.hashCode() + ".json");
String f2 = Utilities.path("[tmp]", "output" + s2.hashCode() + ".json");
TextFile.stringToFile(s1, f1);
TextFile.stringToFile(s2, f2);
command.add(diff);
if (diff.toLowerCase().contains("meld"))
command.add("--newtab");
command.add(f1);
command.add(f2);
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new CSFile(Utilities.path("[tmp]")));
builder.start();
}
return result;
}
public static String checkJsonIsSame(String f1, String f2) throws JsonSyntaxException, FileNotFoundException, IOException {
String result = compareJson(f1, f2);
if (result != null && SHOW_DIFF) {
String diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
List<String> command = new ArrayList<String>();
command.add("\"" + diff + "\" \"" + f1 + "\" \"" + f2 + "\"");
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new CSFile("c:\\temp"));
builder.start();
}
return result;
}
private static String compareJsonSrc(String f1, String f2) throws JsonSyntaxException, FileNotFoundException, IOException {
JsonObject o1 = (JsonObject) new com.google.gson.JsonParser().parse(f1);
JsonObject o2 = (JsonObject) new com.google.gson.JsonParser().parse(f2);
return compareObjects("", o1, o2);
}
private static String compareJson(String f1, String f2) throws JsonSyntaxException, FileNotFoundException, IOException {
JsonObject o1 = (JsonObject) new com.google.gson.JsonParser().parse(TextFile.fileToString(f1));
JsonObject o2 = (JsonObject) new com.google.gson.JsonParser().parse(TextFile.fileToString(f2));
return compareObjects("", o1, o2);
}
private static String compareObjects(String path, JsonObject o1, JsonObject o2) {
for (Map.Entry<String, JsonElement> en : o1.entrySet()) {
String n = en.getKey();
if (!n.equals("fhir_comments")) {
if (o2.has(n)) {
String s = compareNodes(path+'.'+n, en.getValue(), o2.get(n));
if (!Utilities.noString(s))
return s;
}
else
return "properties differ at "+path+": missing property "+n;
}
}
for (Map.Entry<String, JsonElement> en : o2.entrySet()) {
String n = en.getKey();
if (!n.equals("fhir_comments")) {
if (!o1.has(n))
return "properties differ at "+path+": missing property "+n;
}
}
return null;
}
private static String compareNodes(String path, JsonElement n1, JsonElement n2) {
if (n1.getClass() != n2.getClass())
return "properties differ at "+path+": type "+n1.getClass().getName()+"/"+n2.getClass().getName();
else if (n1 instanceof JsonPrimitive) {
JsonPrimitive p1 = (JsonPrimitive) n1;
JsonPrimitive p2 = (JsonPrimitive) n2;
if (p1.isBoolean() && p2.isBoolean()) {
if (p1.getAsBoolean() != p2.getAsBoolean())
return "boolean property values differ at "+path+": type "+p1.getAsString()+"/"+p2.getAsString();
} else if (p1.isString() && p2.isString()) {
String s1 = p1.getAsString();
String s2 = p2.getAsString();
if (!(s1.contains("<div") && s2.contains("<div")))
if (!s1.equals(s2))
if (!sameBytes(unBase64(s1), unBase64(s2)))
return "string property values differ at "+path+": type "+s1+"/"+s2;
} else if (p1.isNumber() && p2.isNumber()) {
if (!p1.getAsString().equals(p2.getAsString()))
return "number property values differ at "+path+": type "+p1.getAsString()+"/"+p2.getAsString();
} else
return "property types differ at "+path+": type "+p1.getAsString()+"/"+p2.getAsString();
}
else if (n1 instanceof JsonObject) {
String s = compareObjects(path, (JsonObject) n1, (JsonObject) n2);
if (!Utilities.noString(s))
return s;
} else if (n1 instanceof JsonArray) {
JsonArray a1 = (JsonArray) n1;
JsonArray a2 = (JsonArray) n2;
if (a1.size() != a2.size())
return "array properties differ at "+path+": count "+Integer.toString(a1.size())+"/"+Integer.toString(a2.size());
for (int i = 0; i < a1.size(); i++) {
String s = compareNodes(path+"["+Integer.toString(i)+"]", a1.get(i), a2.get(i));
if (!Utilities.noString(s))
return s;
}
}
else if (n1 instanceof JsonNull) {
} else
return "unhandled property "+n1.getClass().getName();
return null;
}
public static String temp() {
if (new File("c:\\temp").exists())
return "c:\\temp";
return System.getProperty("java.io.tmpdir");
}
public static String checkTextIsSame(String s1, String s2) throws JsonSyntaxException, FileNotFoundException, IOException {
return checkTextIsSame(s1,s2,true);
}
public static String checkTextIsSame(String s1, String s2, boolean showDiff) throws JsonSyntaxException, FileNotFoundException, IOException {
String result = compareText(s1, s2);
if (result != null && SHOW_DIFF && showDiff) {
String diff = null;
if (System.getProperty("os.name").contains("Linux"))
diff = Utilities.path("/", "usr", "bin", "meld");
else {
if (Utilities.checkFile("WinMerge", Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge"), "\\WinMergeU.exe", null))
diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
else if (Utilities.checkFile("WinMerge", Utilities.path(System.getenv("ProgramFiles(X86)"), "Meld"), "\\Meld.exe", null))
diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "Meld", "Meld.exe");
if (Utilities.checkFile("WinMerge", Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge"), "\\WinMergeU.exe", null))
diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
else if (Utilities.checkFile("WinMerge", Utilities.path(System.getenv("ProgramFiles(X86)"), "Meld"), "\\Meld.exe", null))
diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "Meld", "Meld.exe");
}
if (diff == null || diff.isEmpty())
return result;
List<String> command = new ArrayList<String>();
String f1 = Utilities.path("[tmp]", "input" + s1.hashCode() + ".json");
String f2 = Utilities.path("[tmp]", "output" + s2.hashCode() + ".json");
@ -432,7 +292,143 @@ public class TestingUtilities {
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new CSFile(Utilities.path("[tmp]")));
builder.start();
}
return result;
}
public static String checkJsonIsSame(String f1, String f2) throws JsonSyntaxException, FileNotFoundException, IOException {
String result = compareJson(f1, f2);
if (result != null && SHOW_DIFF) {
String diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
List<String> command = new ArrayList<String>();
command.add("\"" + diff + "\" \"" + f1 + "\" \"" + f2 + "\"");
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new CSFile("c:\\temp"));
builder.start();
}
return result;
}
private static String compareJsonSrc(String f1, String f2) throws JsonSyntaxException, FileNotFoundException, IOException {
JsonObject o1 = (JsonObject) new com.google.gson.JsonParser().parse(f1);
JsonObject o2 = (JsonObject) new com.google.gson.JsonParser().parse(f2);
return compareObjects("", o1, o2);
}
private static String compareJson(String f1, String f2) throws JsonSyntaxException, FileNotFoundException, IOException {
JsonObject o1 = (JsonObject) new com.google.gson.JsonParser().parse(TextFile.fileToString(f1));
JsonObject o2 = (JsonObject) new com.google.gson.JsonParser().parse(TextFile.fileToString(f2));
return compareObjects("", o1, o2);
}
private static String compareObjects(String path, JsonObject o1, JsonObject o2) {
for (Map.Entry<String, JsonElement> en : o1.entrySet()) {
String n = en.getKey();
if (!n.equals("fhir_comments")) {
if (o2.has(n)) {
String s = compareNodes(path + '.' + n, en.getValue(), o2.get(n));
if (!Utilities.noString(s))
return s;
} else
return "properties differ at " + path + ": missing property " + n;
}
}
for (Map.Entry<String, JsonElement> en : o2.entrySet()) {
String n = en.getKey();
if (!n.equals("fhir_comments")) {
if (!o1.has(n))
return "properties differ at " + path + ": missing property " + n;
}
}
return null;
}
private static String compareNodes(String path, JsonElement n1, JsonElement n2) {
if (n1.getClass() != n2.getClass())
return "properties differ at " + path + ": type " + n1.getClass().getName() + "/" + n2.getClass().getName();
else if (n1 instanceof JsonPrimitive) {
JsonPrimitive p1 = (JsonPrimitive) n1;
JsonPrimitive p2 = (JsonPrimitive) n2;
if (p1.isBoolean() && p2.isBoolean()) {
if (p1.getAsBoolean() != p2.getAsBoolean())
return "boolean property values differ at " + path + ": type " + p1.getAsString() + "/" + p2.getAsString();
} else if (p1.isString() && p2.isString()) {
String s1 = p1.getAsString();
String s2 = p2.getAsString();
if (!(s1.contains("<div") && s2.contains("<div")))
if (!s1.equals(s2))
if (!sameBytes(unBase64(s1), unBase64(s2)))
return "string property values differ at " + path + ": type " + s1 + "/" + s2;
} else if (p1.isNumber() && p2.isNumber()) {
if (!p1.getAsString().equals(p2.getAsString()))
return "number property values differ at " + path + ": type " + p1.getAsString() + "/" + p2.getAsString();
} else
return "property types differ at " + path + ": type " + p1.getAsString() + "/" + p2.getAsString();
} else if (n1 instanceof JsonObject) {
String s = compareObjects(path, (JsonObject) n1, (JsonObject) n2);
if (!Utilities.noString(s))
return s;
} else if (n1 instanceof JsonArray) {
JsonArray a1 = (JsonArray) n1;
JsonArray a2 = (JsonArray) n2;
if (a1.size() != a2.size())
return "array properties differ at " + path + ": count " + Integer.toString(a1.size()) + "/" + Integer.toString(a2.size());
for (int i = 0; i < a1.size(); i++) {
String s = compareNodes(path + "[" + Integer.toString(i) + "]", a1.get(i), a2.get(i));
if (!Utilities.noString(s))
return s;
}
} else if (n1 instanceof JsonNull) {
} else
return "unhandled property " + n1.getClass().getName();
return null;
}
public static String temp() {
if (new File("c:\\temp").exists())
return "c:\\temp";
return System.getProperty("java.io.tmpdir");
}
public static String checkTextIsSame(String s1, String s2) throws JsonSyntaxException, FileNotFoundException, IOException {
return checkTextIsSame(s1, s2, true);
}
public static String checkTextIsSame(String s1, String s2, boolean showDiff) throws JsonSyntaxException, FileNotFoundException, IOException {
String result = compareText(s1, s2);
if (result != null && SHOW_DIFF && showDiff) {
String diff = null;
if (System.getProperty("os.name").contains("Linux"))
diff = Utilities.path("/", "usr", "bin", "meld");
else {
if (Utilities.checkFile("WinMerge", Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge"), "\\WinMergeU.exe", null))
diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
else if (Utilities.checkFile("WinMerge", Utilities.path(System.getenv("ProgramFiles(X86)"), "Meld"), "\\Meld.exe", null))
diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "Meld", "Meld.exe");
}
if (diff == null || diff.isEmpty())
return result;
List<String> command = new ArrayList<String>();
String f1 = Utilities.path("[tmp]", "input" + s1.hashCode() + ".json");
String f2 = Utilities.path("[tmp]", "output" + s2.hashCode() + ".json");
TextFile.stringToFile(s1, f1);
TextFile.stringToFile(s2, f2);
command.add(diff);
if (diff.toLowerCase().contains("meld"))
command.add("--newtab");
command.add(f1);
command.add(f2);
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new CSFile(Utilities.path("[tmp]")));
builder.start();
}
return result;
}
@ -441,19 +437,19 @@ public class TestingUtilities {
private static String compareText(String s1, String s2) {
for (int i = 0; i < Integer.min(s1.length(), s2.length()); i++) {
if (s1.charAt(i) != s2.charAt(i))
return "Strings differ at character "+Integer.toString(i)+": '"+s1.charAt(i) +"' vs '"+s2.charAt(i)+"'";
return "Strings differ at character " + Integer.toString(i) + ": '" + s1.charAt(i) + "' vs '" + s2.charAt(i) + "'";
}
if (s1.length() != s2.length())
return "Strings differ in length: "+Integer.toString(s1.length())+" vs "+Integer.toString(s2.length())+" but match to the end of the shortest";
return "Strings differ in length: " + Integer.toString(s1.length()) + " vs " + Integer.toString(s2.length()) + " but match to the end of the shortest";
return null;
}
public static boolean findTestResource(String... paths) throws IOException {
public static boolean findTestResource(String... paths) throws IOException {
if (new File("../../fhir-test-cases").exists() && isTryToLoadFromFileSystem()) {
String n = Utilities.path(System.getProperty("user.dir"), "..", "..", "fhir-test-cases", Utilities.path(paths));
return new File(n).exists();
} else {
String classpath = ("/org/hl7/fhir/testcases/"+ Utilities.pathURL(paths));
String classpath = ("/org/hl7/fhir/testcases/" + Utilities.pathURL(paths));
try {
InputStream inputStream = TestingUtilities.class.getResourceAsStream(classpath);
return inputStream != null;
@ -476,7 +472,7 @@ public class TestingUtilities {
} else {
// resolve from the package
String contents;
String classpath = ("/org/hl7/fhir/testcases/"+ Utilities.pathURL(paths));
String classpath = ("/org/hl7/fhir/testcases/" + Utilities.pathURL(paths));
try (InputStream inputStream = TestingUtilities.class.getResourceAsStream(classpath)) {
if (inputStream == null) {
throw new IOException("Can't find file on classpath: " + classpath);
@ -492,10 +488,10 @@ public class TestingUtilities {
String n = Utilities.path(System.getProperty("user.dir"), "..", "..", "fhir-test-cases", Utilities.path(paths));
return new FileInputStream(n);
} else {
String classpath = ("/org/hl7/fhir/testcases/"+ Utilities.pathURL(paths));
String classpath = ("/org/hl7/fhir/testcases/" + Utilities.pathURL(paths));
InputStream s = TestingUtilities.class.getResourceAsStream(classpath);
if (s == null) {
throw new Error("unable to find resource "+classpath);
throw new Error("unable to find resource " + classpath);
}
return s;
}
@ -506,10 +502,10 @@ public class TestingUtilities {
String n = Utilities.path(System.getProperty("user.dir"), "..", "..", "fhir-test-cases", Utilities.path(paths));
return TextFile.fileToBytes(n);
} else {
String classpath = ("/org/hl7/fhir/testcases/"+ Utilities.pathURL(paths));
String classpath = ("/org/hl7/fhir/testcases/" + Utilities.pathURL(paths));
InputStream s = TestingUtilities.class.getResourceAsStream(classpath);
if (s == null) {
throw new Error("unable to find resource "+classpath);
throw new Error("unable to find resource " + classpath);
}
return TextFile.streamToBytes(s);
}
@ -520,7 +516,7 @@ public class TestingUtilities {
String tmp = tempFolder(folder);
return Utilities.path(tmp, name);
}
public static String tempFolder(String name) throws IOException {
File tmp = new File("C:\\temp");
if (tmp.exists() && tmp.isDirectory()) {

View File

@ -1,110 +1,108 @@
package org.hl7.fhir.r5.model;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Date;
import java.util.TimeZone;
import static org.junit.Assert.*;
public class BaseDateTimeTypeTest {
/**
* <ul>
* <li>true if the given datetimes represent the exact same instant with the same precision (irrespective of the timezone)</li>
* <li>true if the given datetimes represent the exact same instant but one includes milliseconds of <code>.[0]+</code> while the other includes only SECONDS precision (irrespecitve of the timezone)</li>
* <li>true if the given datetimes represent the exact same year/year-month/year-month-date (if both operands have the same precision)</li>
* <li>false if the given datetimes have the same precision but do not represent the same instant (irrespective of timezone)</li>
* <li>null otherwise (since these datetimes are not comparable)</li>
* </ul>
*/
@Test
public void equalsUsingFhirPathRulesInSpec() {
// from the spec
assertTrue( compareDateTimes("2012", "2012"));
assertFalse(compareDateTimes("2012", "2013"));
assertNull( compareDateTimes("2012-01", "2012"));
assertNull( compareDateTimes("2012-01-01", "2012-01-01T00:00:00"));
assertTrue( compareDateTimes("2012-01-01T10:30:00", "2012-01-01T10:30:00"));
assertFalse(compareDateTimes("2012-01-01T10:30:00", "2012-01-01T10:31:00"));
assertTrue( compareDateTimes("2012-01-01T10:30:31.0", "2012-01-01T10:30:31"));
assertFalse(compareDateTimes("2012-01-01T10:30:31.1", "2012-01-01T10:30:31"));
assertFalse(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T01:15:00.0-05:00"));
assertTrue(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T00:30:00.0-05:00"));
}
@Test
public void equalsUsingFhirPathRulesOther() {
// Setting timezone for this test. Grahame is in UTC+11, Travis is in GMT, and I'm here in Toronto, Canada with
// all my time based tests failing locally...
TimeZone.setDefault(TimeZone.getTimeZone("UTC+1100"));
/**
* <ul>
* <li>true if the given datetimes represent the exact same instant with the same precision (irrespective of the timezone)</li>
* <li>true if the given datetimes represent the exact same instant but one includes milliseconds of <code>.[0]+</code> while the other includes only SECONDS precision (irrespecitve of the timezone)</li>
* <li>true if the given datetimes represent the exact same year/year-month/year-month-date (if both operands have the same precision)</li>
* <li>false if the given datetimes have the same precision but do not represent the same instant (irrespective of timezone)</li>
* <li>null otherwise (since these datetimes are not comparable)</li>
* </ul>
*/
@Test
public void equalsUsingFhirPathRulesInSpec() {
// Exact same - Same timezone
assertTrue( compareDateTimes("2001-01-02T11:22:33.444Z", "2001-01-02T11:22:33.444Z"));
// Exact same - Different timezone
assertTrue( compareDateTimes("2001-01-02T11:22:33.444-03:00", "2001-01-02T10:22:33.444-04:00"));
// Exact same - Dates
assertTrue( compareDateTimes("2001", "2001"));
assertTrue( compareDateTimes("2001-01", "2001-01"));
assertTrue( compareDateTimes("2001-01-02", "2001-01-02"));
// Same precision but different values - Dates
assertFalse(compareDateTimes("2001", "2002"));
assertFalse(compareDateTimes("2001-01", "2001-02"));
assertFalse(compareDateTimes("2001-01-02", "2001-01-03"));
// Different instant - Same timezone
assertFalse(compareDateTimes("2001-01-02T11:22:33.444Z", "2001-01-02T11:22:33.445Z"));
assertFalse(compareDateTimes("2001-01-02T11:22:33.445Z", "2001-01-02T11:22:33.444Z"));
// from the spec
Assertions.assertTrue(compareDateTimes("2012", "2012"));
Assertions.assertFalse(compareDateTimes("2012", "2013"));
Assertions.assertNull(compareDateTimes("2012-01", "2012"));
Assertions.assertNull(compareDateTimes("2012-01-01", "2012-01-01T00:00:00"));
Assertions.assertTrue(compareDateTimes("2012-01-01T10:30:00", "2012-01-01T10:30:00"));
Assertions.assertFalse(compareDateTimes("2012-01-01T10:30:00", "2012-01-01T10:31:00"));
Assertions.assertTrue(compareDateTimes("2012-01-01T10:30:31.0", "2012-01-01T10:30:31"));
Assertions.assertFalse(compareDateTimes("2012-01-01T10:30:31.1", "2012-01-01T10:30:31"));
Assertions.assertFalse(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T01:15:00.0-05:00"));
Assertions.assertTrue(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T00:30:00.0-05:00"));
}
// FHIRPath tests:
assertNull( compareDateTimes("1974-12-25", "1974-12-25T12:34:00+10:00"));
assertNull( compareDateTimes("1974-12-25T12:34:00+10:00", "1974-12-25"));
assertFalse(compareDateTimes("1974-12-25", "1974-12-23T12:34:00+10:00")); // false because they can't be the same date irrespective of precision
assertFalse(compareDateTimes("1974-12-23T12:34:00+10:00", "1974-12-25"));
assertNull( compareDateTimes("1974-12-25", "1974-12-25T12:34:00Z"));
assertNull( compareDateTimes("1974-12-25T12:34:00Z", "1974-12-25"));
assertFalse(compareDateTimes("2012-04-15", "2012-04-16"));
assertFalse(compareDateTimes("2012-04-16", "2012-04-15"));
assertFalse(compareDateTimes("2012-04-15T15:00:00", "2012-04-15T10:00:00"));
assertFalse(compareDateTimes("2012-04-15T10:00:00", "2012-04-15T15:00:00"));
assertFalse(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T01:15:00.0-05:00"));
assertFalse(compareDateTimes("2017-11-05T01:15:00.0-05:00", "2017-11-05T01:30:00.0-04:00"));
assertNull(compareDateTimes("1974-12-25", "1974-12-25T12:34:00"));
assertNull(compareDateTimes("1974-12-25T12:34:00", "1974-12-25"));
assertNull(compareDateTimes("2012-04-15T10:00:00", "2012-04-15"));
assertFalse(compareDateTimes("2012-04-15T15:00:00Z", "2012-04-15T10:00:00"));
assertFalse(compareDateTimes("2012-04-15T10:00:00", "2012-04-15T15:00:00Z"));
assertTrue(compareDateTimes("1974-12-25", "1974-12-25"));
assertTrue(compareDateTimes("2012-04-15", "2012-04-15"));
assertTrue(compareDateTimes("2012-04-15T15:00:00+02:00", "2012-04-15T16:00:00+03:00"));
assertTrue(compareDateTimes("2012-04-15T16:00:00+03:00", "2012-04-15T15:00:00+02:00"));
assertTrue(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T00:30:00.0-05:00"));
assertTrue(compareDateTimes("2017-11-05T00:30:00.0-05:00", "2017-11-05T01:30:00.0-04:00"));
@Test
public void equalsUsingFhirPathRulesOther() {
// Setting timezone for this test. Grahame is in UTC+11, Travis is in GMT, and I'm here in Toronto, Canada with
// all my time based tests failing locally...
TimeZone.setDefault(TimeZone.getTimeZone("UTC+1100"));
assertFalse(compareDateTimes("2016-12-02T13:00:00Z", "2016-11-02T10:00:00")); // no timezone, but cannot be the same time
assertFalse(compareDateTimes("2016-12-02T13:00:00Z", "2016-12-02T10:00:00")); // no timezone, might be the same time
}
// Exact same - Same timezone
Assertions.assertTrue(compareDateTimes("2001-01-02T11:22:33.444Z", "2001-01-02T11:22:33.444Z"));
// Exact same - Different timezone
Assertions.assertTrue(compareDateTimes("2001-01-02T11:22:33.444-03:00", "2001-01-02T10:22:33.444-04:00"));
// Exact same - Dates
Assertions.assertTrue(compareDateTimes("2001", "2001"));
Assertions.assertTrue(compareDateTimes("2001-01", "2001-01"));
Assertions.assertTrue(compareDateTimes("2001-01-02", "2001-01-02"));
// Same precision but different values - Dates
Assertions.assertFalse(compareDateTimes("2001", "2002"));
Assertions.assertFalse(compareDateTimes("2001-01", "2001-02"));
Assertions.assertFalse(compareDateTimes("2001-01-02", "2001-01-03"));
// Different instant - Same timezone
Assertions.assertFalse(compareDateTimes("2001-01-02T11:22:33.444Z", "2001-01-02T11:22:33.445Z"));
Assertions.assertFalse(compareDateTimes("2001-01-02T11:22:33.445Z", "2001-01-02T11:22:33.444Z"));
@Test
public void testToHumanDisplayForDateOnlyPrecisions() {
assertEquals("2019-01-02", new DateTimeType("2019-01-02").toHumanDisplay());
assertEquals("2019-01", new DateTimeType("2019-01").toHumanDisplay());
assertEquals("2019", new DateTimeType("2019").toHumanDisplay());
}
// FHIRPath tests:
Assertions.assertNull(compareDateTimes("1974-12-25", "1974-12-25T12:34:00+10:00"));
Assertions.assertNull(compareDateTimes("1974-12-25T12:34:00+10:00", "1974-12-25"));
Assertions.assertFalse(compareDateTimes("1974-12-25", "1974-12-23T12:34:00+10:00")); // false because they can't be the same date irrespective of precision
Assertions.assertFalse(compareDateTimes("1974-12-23T12:34:00+10:00", "1974-12-25"));
Assertions.assertNull(compareDateTimes("1974-12-25", "1974-12-25T12:34:00Z"));
Assertions.assertNull(compareDateTimes("1974-12-25T12:34:00Z", "1974-12-25"));
Assertions.assertFalse(compareDateTimes("2012-04-15", "2012-04-16"));
Assertions.assertFalse(compareDateTimes("2012-04-16", "2012-04-15"));
Assertions.assertFalse(compareDateTimes("2012-04-15T15:00:00", "2012-04-15T10:00:00"));
Assertions.assertFalse(compareDateTimes("2012-04-15T10:00:00", "2012-04-15T15:00:00"));
Assertions.assertFalse(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T01:15:00.0-05:00"));
Assertions.assertFalse(compareDateTimes("2017-11-05T01:15:00.0-05:00", "2017-11-05T01:30:00.0-04:00"));
Assertions.assertNull(compareDateTimes("1974-12-25", "1974-12-25T12:34:00"));
Assertions.assertNull(compareDateTimes("1974-12-25T12:34:00", "1974-12-25"));
Assertions.assertNull(compareDateTimes("2012-04-15T10:00:00", "2012-04-15"));
Assertions.assertFalse(compareDateTimes("2012-04-15T15:00:00Z", "2012-04-15T10:00:00"));
Assertions.assertFalse(compareDateTimes("2012-04-15T10:00:00", "2012-04-15T15:00:00Z"));
Assertions.assertTrue(compareDateTimes("1974-12-25", "1974-12-25"));
Assertions.assertTrue(compareDateTimes("2012-04-15", "2012-04-15"));
Assertions.assertTrue(compareDateTimes("2012-04-15T15:00:00+02:00", "2012-04-15T16:00:00+03:00"));
Assertions.assertTrue(compareDateTimes("2012-04-15T16:00:00+03:00", "2012-04-15T15:00:00+02:00"));
Assertions.assertTrue(compareDateTimes("2017-11-05T01:30:00.0-04:00", "2017-11-05T00:30:00.0-05:00"));
Assertions.assertTrue(compareDateTimes("2017-11-05T00:30:00.0-05:00", "2017-11-05T01:30:00.0-04:00"));
Assertions.assertFalse(compareDateTimes("2016-12-02T13:00:00Z", "2016-11-02T10:00:00")); // no timezone, but cannot be the same time
Assertions.assertFalse(compareDateTimes("2016-12-02T13:00:00Z", "2016-12-02T10:00:00")); // no timezone, might be the same time
}
@Test
public void testToHumanDisplayForDateOnlyPrecisions() {
Assertions.assertEquals("2019-01-02", new DateTimeType("2019-01-02").toHumanDisplay());
Assertions.assertEquals("2019-01", new DateTimeType("2019-01").toHumanDisplay());
Assertions.assertEquals("2019", new DateTimeType("2019").toHumanDisplay());
}
@Test
public void testToHumanDisplayLocalTimezoneForDateOnlyPrecisions() {
assertEquals("2019-01-02", new DateTimeType("2019-01-02").toHumanDisplayLocalTimezone());
assertEquals("2019-01", new DateTimeType("2019-01").toHumanDisplayLocalTimezone());
assertEquals("2019", new DateTimeType("2019").toHumanDisplayLocalTimezone());
Assertions.assertEquals("2019-01-02", new DateTimeType("2019-01-02").toHumanDisplayLocalTimezone());
Assertions.assertEquals("2019-01", new DateTimeType("2019-01").toHumanDisplayLocalTimezone());
Assertions.assertEquals("2019", new DateTimeType("2019").toHumanDisplayLocalTimezone());
}
private Boolean compareDateTimes(String theLeft, String theRight) {
System.out.println("Compare "+theLeft+" to "+theRight);
DateTimeType leftDt = new DateTimeType(theLeft);
DateTimeType rightDt = new DateTimeType(theRight);
return leftDt.equalsUsingFhirPathRules(rightDt);
}
private Boolean compareDateTimes(String theLeft, String theRight) {
System.out.println("Compare " + theLeft + " to " + theRight);
DateTimeType leftDt = new DateTimeType(theLeft);
DateTimeType rightDt = new DateTimeType(theRight);
return leftDt.equalsUsingFhirPathRules(rightDt);
}
}

View File

@ -1,6 +1,5 @@
package org.hl7.fhir.r5.test;
import junit.framework.Assert;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.elementmodel.Manager;
@ -10,7 +9,8 @@ import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.utilities.cache.PackageCacheManager;
import org.hl7.fhir.utilities.cache.ToolsVersion;
import org.junit.Before;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -21,7 +21,7 @@ public class CDARoundTripTests {
// private SimpleWorkerContext context;
// old-test private FHIRPathEngine fp;
@Before
@BeforeAll
public void setUp() throws Exception {
// old-test context = new SimpleWorkerContext();
// old-test PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
@ -191,8 +191,7 @@ public class CDARoundTripTests {
}
Element cda = Manager.parse(context, TestingUtilities.loadTestResourceStream("r5", "cda", "example.xml"), FhirFormat.XML);
FHIRPathEngine fp = new FHIRPathEngine(context);
Assert.assertEquals("2.16.840.1.113883.3.27.1776", fp.evaluateToString(null, cda, cda, cda, fp.parse("ClinicalDocument.templateId.root")));
Assertions.assertEquals("2.16.840.1.113883.3.27.1776", fp.evaluateToString(null, cda, cda, cda, fp.parse("ClinicalDocument.templateId.root")));
}
}

View File

@ -3,7 +3,8 @@ package org.hl7.fhir.r5.test;
import org.hl7.fhir.r5.context.CanonicalResourceManager;
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
import org.hl7.fhir.r5.model.ValueSet;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class CanonicalResourceManagerTester {
@ -19,27 +20,27 @@ public class CanonicalResourceManagerTester {
mrm.clear();
mrm.see(vs, null);
Assert.assertEquals(mrm.size(), 1);
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertNotNull(mrm.get("2345"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.size(), 1);
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
mrm.see(vs, null);
Assert.assertEquals(mrm.size(), 1);
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertNotNull(mrm.get("2345"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.size(), 1);
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
mrm.drop("2344");
Assert.assertEquals(mrm.size(), 1);
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertNotNull(mrm.get("2345"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.size(), 1);
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
mrm.drop("2345");
Assert.assertEquals(mrm.size(), 0);
Assert.assertNull(mrm.get("http://url/ValueSet/234"));
Assert.assertNull(mrm.get("2345"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.size(), 0);
Assertions.assertNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertNull(mrm.get("2345"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
}
@Test
@ -53,13 +54,13 @@ public class CanonicalResourceManagerTester {
mrm.clear();
mrm.see(vs, null);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
}
@Test
@ -73,11 +74,11 @@ public class CanonicalResourceManagerTester {
mrm.clear();
mrm.see(vs, null);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "20140403"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "20140402"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "2014"));
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "20140403"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "20140402"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "2014"));
}
@Test
@ -98,66 +99,66 @@ public class CanonicalResourceManagerTester {
mrm.clear();
mrm.see(vs1, null);
Assert.assertEquals(mrm.size(), 1);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertEquals(mrm.get("2345").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertEquals(mrm.size(), 1);
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertEquals(mrm.get("2345").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
mrm.see(vs2, null);
Assert.assertEquals(mrm.size(), 2);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertEquals(mrm.get("2345").getName(), "2");
Assertions.assertEquals(mrm.size(), 2);
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertEquals(mrm.get("2345").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
mrm.drop("2346"); // doesn't exist;
Assert.assertEquals(mrm.size(), 2);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertNull(mrm.get("2346"));
Assert.assertEquals(mrm.get("2345").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertEquals(mrm.size(), 2);
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertNull(mrm.get("2346"));
Assertions.assertEquals(mrm.get("2345").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
mrm.drop("2345"); // vs2;
Assert.assertEquals(mrm.size(), 0);
Assert.assertNull(mrm.get("2345"));
Assert.assertNull(mrm.get("2346"));
Assert.assertNull(mrm.get("http://url/ValueSet/234"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertEquals(mrm.size(), 0);
Assertions.assertNull(mrm.get("2345"));
Assertions.assertNull(mrm.get("2346"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
}
@ -179,49 +180,49 @@ public class CanonicalResourceManagerTester {
mrm.clear();
mrm.see(vs1, null);
Assert.assertEquals(mrm.size(), 1);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertEquals(mrm.get("2345").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertEquals(mrm.size(), 1);
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertEquals(mrm.get("2345").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
mrm.see(vs2, null);
Assert.assertEquals(mrm.size(), 1);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertEquals(mrm.get("2345").getName(), "2");
Assertions.assertEquals(mrm.size(), 1);
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertEquals(mrm.get("2345").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
mrm.drop("2345"); // vs2;
Assert.assertEquals(mrm.size(), 0);
Assert.assertNull(mrm.get("2345"));
Assert.assertNull(mrm.get("2346"));
Assert.assertNull(mrm.get("http://url/ValueSet/234"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertEquals(mrm.size(), 0);
Assertions.assertNull(mrm.get("2345"));
Assertions.assertNull(mrm.get("2346"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
}
@Test
@ -242,57 +243,57 @@ public class CanonicalResourceManagerTester {
mrm.clear();
mrm.see(vs1, null);
Assert.assertEquals(mrm.size(), 1);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertEquals(mrm.get("2345").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertEquals(mrm.size(), 1);
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertEquals(mrm.get("2345").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
mrm.see(vs2, null);
Assert.assertEquals(mrm.size(), 2);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertEquals(mrm.get("2345").getName(), "1");
Assert.assertNotNull(mrm.get("2346"));
Assert.assertEquals(mrm.get("2346").getName(), "2");
Assertions.assertEquals(mrm.size(), 2);
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertEquals(mrm.get("2345").getName(), "1");
Assertions.assertNotNull(mrm.get("2346"));
Assertions.assertEquals(mrm.get("2346").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
mrm.drop("2346"); // vs2;
Assert.assertEquals(mrm.size(), 1);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertNull(mrm.get("2346"));
Assert.assertEquals(mrm.get("2345").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertEquals(mrm.size(), 1);
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertNull(mrm.get("2346"));
Assertions.assertEquals(mrm.get("2345").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
}
@ -314,58 +315,58 @@ public class CanonicalResourceManagerTester {
mrm.clear();
mrm.see(vs1, null);
Assert.assertEquals(mrm.size(), 1);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertEquals(mrm.get("2345").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertEquals(mrm.size(), 1);
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertEquals(mrm.get("2345").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
mrm.see(vs2, null);
Assert.assertEquals(mrm.size(), 2);
Assert.assertNotNull(mrm.get("2345"));
Assert.assertEquals(mrm.get("2345").getName(), "1");
Assert.assertNotNull(mrm.get("2346"));
Assert.assertEquals(mrm.get("2346").getName(), "2");
Assertions.assertEquals(mrm.size(), 2);
Assertions.assertNotNull(mrm.get("2345"));
Assertions.assertEquals(mrm.get("2345").getName(), "1");
Assertions.assertNotNull(mrm.get("2346"));
Assertions.assertEquals(mrm.get("2346").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
mrm.drop("2345"); // vs1;
Assert.assertEquals(mrm.size(), 1);
Assert.assertNull(mrm.get("2345"));
Assert.assertNotNull(mrm.get("2346"));
Assert.assertEquals(mrm.get("2346").getName(), "2");
Assertions.assertEquals(mrm.size(), 1);
Assertions.assertNull(mrm.get("2345"));
Assertions.assertNotNull(mrm.get("2346"));
Assertions.assertEquals(mrm.get("2346").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assert.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assert.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assert.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
}
@Test
@ -385,15 +386,15 @@ public class CanonicalResourceManagerTester {
mrm.see(vs1, null);
Assert.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
Assert.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0"));
Assert.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("1"));
Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0"));
Assertions.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("1"));
mrm.see(vs2, null);
Assert.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
Assert.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("2"));
Assert.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0"));
Assert.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2000.0.0"));
Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
Assertions.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("2"));
Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0"));
Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2000.0.0"));
}
@Test
@ -413,13 +414,13 @@ public class CanonicalResourceManagerTester {
mrm.see(vs1, new PackageVersion("hl7.fhir.r4.core", "4.0.1"));
Assert.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
Assert.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0"));
Assert.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("1"));
Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0"));
Assertions.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("1"));
mrm.see(vs2, new PackageVersion("hl7.terminology.r4", "4.0.1"));
Assert.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
Assert.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("2"));
Assert.assertNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0")); // this will get dropped completely because of UTG rules
Assertions.assertNotNull(mrm.get("http://terminology.hl7.org/ValueSet/234"));
Assertions.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("2"));
Assertions.assertNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0")); // this will get dropped completely because of UTG rules
}
}

View File

@ -37,7 +37,6 @@ import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class FHIRMappingLanguageTests implements ITransformerServices {
private List<Resource> outputs = new ArrayList<Resource>();
@ -45,7 +44,6 @@ public class FHIRMappingLanguageTests implements ITransformerServices {
static private SimpleWorkerContext context;
static private JsonParser jsonParser;
@Parameters
public static Stream<Arguments> data()
throws FileNotFoundException, IOException, ParserConfigurationException, SAXException {
Document tests = XMLUtil.parseToDom(TestingUtilities.loadTestResource("r5", "fml", "manifest.xml"));
@ -60,7 +58,7 @@ public class FHIRMappingLanguageTests implements ITransformerServices {
}
@BeforeAll
public void setUp() throws Exception {
public static void setUp() throws Exception {
PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.1"));
jsonParser = new JsonParser();

View File

@ -1,6 +1,5 @@
package org.hl7.fhir.r5.test;
import junit.framework.Assert;
import org.apache.commons.lang3.NotImplementedException;
import org.fhir.ucum.UcumException;
import org.hl7.fhir.exceptions.FHIRException;
@ -12,6 +11,7 @@ import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@ -156,9 +156,9 @@ public class FHIRPathTests {
fp.check(res, res.getResourceType().toString(), res.getResourceType().toString(), node);
}
outcome = fp.evaluate(res, node);
Assert.assertTrue(String.format("Expected exception parsing %s", expression), !fail);
Assertions.assertFalse(fail, String.format("Expected exception parsing %s", expression));
} catch (Exception e) {
Assert.assertTrue(String.format("Unexpected exception parsing %s: " + e.getMessage(), expression), fail);
Assertions.assertTrue(fail, String.format("Unexpected exception parsing %s: " + e.getMessage(), expression));
}
if ("true".equals(test.getAttribute("predicate"))) {
@ -171,7 +171,7 @@ public class FHIRPathTests {
List<Element> expected = new ArrayList<Element>();
XMLUtil.getNamedChildren(test, "output", expected);
Assert.assertTrue(String.format("Expected %d objects but found %d for expression %s", expected.size(), outcome.size(), expression), outcome.size() == expected.size());
Assertions.assertEquals(outcome.size(), expected.size(), String.format("Expected %d objects but found %d for expression %s", expected.size(), outcome.size(), expression));
if ("false".equals(test.getAttribute("ordered"))) {
for (int i = 0; i < Math.min(outcome.size(), expected.size()); i++) {
String tn = outcome.get(i).fhirType();
@ -186,22 +186,22 @@ public class FHIRPathTests {
(Utilities.noString(e.getTextContent()) || e.getTextContent().equals(s)))
found = true;
}
Assert.assertTrue(String.format("Outcome %d: Value %s of type %s not expected for %s", i, s, tn, expression), found);
Assertions.assertTrue(found, String.format("Outcome %d: Value %s of type %s not expected for %s", i, s, tn, expression));
}
} else {
for (int i = 0; i < Math.min(outcome.size(), expected.size()); i++) {
String tn = expected.get(i).getAttribute("type");
if (!Utilities.noString(tn)) {
Assert.assertTrue(String.format("Outcome %d: Type should be %s but was %s", i, tn, outcome.get(i).fhirType()), tn.equals(outcome.get(i).fhirType()));
Assertions.assertEquals(tn, outcome.get(i).fhirType(), String.format("Outcome %d: Type should be %s but was %s", i, tn, outcome.get(i).fhirType()));
}
String v = expected.get(i).getTextContent();
if (!Utilities.noString(v)) {
if (outcome.get(i) instanceof Quantity) {
Quantity q = fp.parseQuantityString(v);
Assert.assertTrue(String.format("Outcome %d: Value should be %s but was %s", i, v, outcome.get(i).toString()), outcome.get(i).equalsDeep(q));
Assertions.assertTrue(outcome.get(i).equalsDeep(q), String.format("Outcome %d: Value should be %s but was %s", i, v, outcome.get(i).toString()));
} else {
Assert.assertTrue(String.format("Outcome %d: Value should be a primitive type but was %s", i, outcome.get(i).fhirType()), outcome.get(i) instanceof PrimitiveType);
Assert.assertTrue(String.format("Outcome %d: Value should be %s but was %s for expression %s", i, v, outcome.get(i).toString(), expression), v.equals(((PrimitiveType) outcome.get(i)).asStringValue()));
Assertions.assertTrue(outcome.get(i) instanceof PrimitiveType, String.format("Outcome %d: Value should be a primitive type but was %s", i, outcome.get(i).fhirType()));
Assertions.assertEquals(v, ((PrimitiveType) outcome.get(i)).asStringValue(), String.format("Outcome %d: Value should be %s but was %s for expression %s", i, v, outcome.get(i).toString(), expression));
}
}
}

View File

@ -6,18 +6,16 @@ import org.hl7.fhir.utilities.graphql.EGraphEngine;
import org.hl7.fhir.utilities.graphql.EGraphQLException;
import org.hl7.fhir.utilities.graphql.Package;
import org.hl7.fhir.utilities.graphql.Parser;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import static org.junit.Assert.assertTrue;
public class GraphQLParserTests {
public static Stream<Arguments> data() throws IOException {
@ -37,7 +35,7 @@ public class GraphQLParserTests {
@MethodSource("data")
public void test(String name, String test) throws IOException, EGraphQLException, EGraphEngine {
Package doc = Parser.parse(test);
assertTrue(doc != null);
Assertions.assertNotNull(doc);
}

View File

@ -3,7 +3,6 @@ package org.hl7.fhir.r5.test;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import junit.framework.Assert;
import org.apache.commons.collections4.map.HashedMap;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.formats.XmlParser;
@ -12,11 +11,11 @@ import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.LiquidEngine;
import org.hl7.fhir.r5.utils.LiquidEngine.ILiquidEngineIcludeResolver;
import org.hl7.fhir.r5.utils.LiquidEngine.LiquidDocument;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
@ -24,40 +23,41 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@RunWith(Parameterized.class)
public class LiquidEngineTests implements ILiquidEngineIcludeResolver {
//TODO Migrate this test to JUnit Jupiter. Need to refactor the base class ILiquidEngineIcludeResolver to do this properly.
private static Map<String, Resource> resources = new HashedMap<>();
private static JsonObject testdoc = null;
private JsonObject test;
private LiquidEngine engine;
@Parameters(name = "{index}: file{0}")
public static Iterable<Object[]> data() throws ParserConfigurationException, SAXException, IOException {
testdoc = (JsonObject) new com.google.gson.JsonParser().parse(TestingUtilities.loadTestResource("r5", "liquid", "liquid-tests.json"));
JsonArray tests = testdoc.getAsJsonArray("tests");
List<Object[]> objects = new ArrayList<Object[]>(tests.size());
for (JsonElement n : tests) {
objects.add(new Object[]{n});
}
return objects;
}
public LiquidEngineTests(JsonObject test) {
super();
this.test = test;
}
@Before
@BeforeEach
public void setUp() throws Exception {
engine = new LiquidEngine(TestingUtilities.context(), null);
engine.setIncludeResolver(this);
}
public static Stream<Arguments> data() throws ParserConfigurationException, SAXException, IOException {
testdoc = (JsonObject) new com.google.gson.JsonParser().parse(TestingUtilities.loadTestResource("r5", "liquid", "liquid-tests.json"));
JsonArray tests = testdoc.getAsJsonArray("tests");
List<Arguments> objects = new ArrayList<>();
for (JsonElement n : tests) {
objects.add(Arguments.of(n));
}
return objects.stream();
}
@ParameterizedTest(name = "{index}: file{0}")
@MethodSource("data")
public void test(JsonObject test) throws Exception {
this.test = test;
LiquidDocument doc = engine.parse(test.get("template").getAsString(), "test-script");
String output = engine.evaluate(doc, loadResource(), null);
Assertions.assertTrue(test.get("output").getAsString().equals(output));
}
@Override
public String fetchInclude(LiquidEngine engine, String name) {
if (test.has("includes") && test.getAsJsonObject("includes").has(name))
@ -74,11 +74,4 @@ public class LiquidEngineTests implements ILiquidEngineIcludeResolver {
return resources.get(test.get("focus").getAsString());
}
@Test
public void test() throws Exception {
LiquidDocument doc = engine.parse(test.get("template").getAsString(), "test-script");
String output = engine.evaluate(doc, loadResource(), null);
Assert.assertTrue(test.get("output").getAsString().equals(output));
}
}

View File

@ -9,12 +9,9 @@ import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.NarrativeGenerator;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@ -30,11 +27,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Disabled //Test case 1 doesn't pass
public class NarrativeGenerationTests {
private IWorkerContext context;
private static IWorkerContext context;
public static class TestDetails {
private String id;
@ -62,8 +58,8 @@ public class NarrativeGenerationTests {
}
@BeforeAll
public void setUp() {
this.context = TestingUtilities.context();
public static void setUp() {
context = TestingUtilities.context();
}
@ParameterizedTest(name = "{index}: file {0}")

View File

@ -8,7 +8,6 @@ import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.NarrativeGenerator;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.xmlpull.v1.XmlPullParserException;
import java.io.FileNotFoundException;
@ -16,13 +15,12 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class NarrativeGeneratorTests {
private NarrativeGenerator gen;
private static NarrativeGenerator gen;
@BeforeAll
public void setUp() throws FHIRException {
public static void setUp() throws FHIRException {
gen = new NarrativeGenerator("", null, TestingUtilities.context());
}

View File

@ -6,7 +6,12 @@ import org.hl7.fhir.utilities.cache.NpmPackage;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

View File

@ -1,8 +1,5 @@
package org.hl7.fhir.r5.test;
import java.io.File;
import java.io.IOException;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.cache.NpmPackage;
import org.hl7.fhir.utilities.cache.PackageCacheManager;
@ -11,6 +8,9 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
public class PackageCacheTests {
@Test
@ -29,7 +29,7 @@ public class PackageCacheTests {
Utilities.createDirectory(dir.getAbsolutePath());
}
npm.save(dir);
NpmPackage npm2 = cache.loadPackage("hl7.fhir.pubpack", "file:"+dir.getAbsolutePath());
NpmPackage npm2 = cache.loadPackage("hl7.fhir.pubpack", "file:" + dir.getAbsolutePath());
Assertions.assertNotNull(npm2);
}
}

View File

@ -52,7 +52,6 @@ public class PackageClientTests {
Assertions.assertTrue(matches.size() == 0);
}
@Test
public void testExists2() throws IOException {
PackageClient client = new PackageClient("http://test.fhir.org/packages");

View File

@ -1,11 +1,5 @@
package org.hl7.fhir.r5.test;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.fhir.ucum.UcumException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.conformance.ProfileUtilities;
@ -22,9 +16,15 @@ import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.junit.jupiter.api.Test;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ProfileUtilitiesTests {
// /**
// /**
// * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base
// *
// * @param context2
@ -48,9 +48,9 @@ public class ProfileUtilitiesTests {
ElementDefinition b = base.getSnapshot().getElement().get(i);
ElementDefinition f = focus.getSnapshot().getElement().get(i);
if (ok) {
if (!f.hasBase())
if (!f.hasBase())
ok = false;
else if (!b.getPath().equals(f.getPath()))
else if (!b.getPath().equals(f.getPath()))
ok = false;
else {
b.setBase(null);
@ -65,12 +65,12 @@ public class ProfileUtilitiesTests {
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation simple test failed");
} else
} else
System.out.println("Snap shot generation simple test passed");
}
//
//
// /**
// * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base. for a different resource with recursion
// *
@ -86,14 +86,14 @@ public class ProfileUtilitiesTests {
focus.setSnapshot(null);
focus.setDifferential(null);
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test" );
new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test");
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
if (ok) {
ElementDefinition b = base.getSnapshot().getElement().get(i);
ElementDefinition f = focus.getSnapshot().getElement().get(i);
if (!f.hasBase() || !b.getPath().equals(f.getPath()))
if (!f.hasBase() || !b.getPath().equals(f.getPath()))
ok = false;
else {
f.setBase(null);
@ -108,12 +108,12 @@ public class ProfileUtilitiesTests {
}
}
}
if (!ok) {
compareXml(base, focus);
System.out.println("Snap shot generation simple test failed");
throw new FHIRException("Snap shot generation simple test failed");
} else
} else
System.out.println("Snap shot generation simple test passed");
}
@ -799,8 +799,10 @@ public class ProfileUtilitiesTests {
// focus.setDifferential(null);
String f1 = Utilities.path("c:", "temp", "base.xml");
String f2 = Utilities.path("c:", "temp", "derived.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f1), base);;
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f2), focus);;
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f1), base);
;
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f2), focus);
;
String diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
List<String> command = new ArrayList<String>();
command.add("\"" + diff + "\" \"" + f1 + "\" \"" + f2 + "\"");

View File

@ -14,7 +14,11 @@ import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.NarrativeGenerator;
import org.junit.jupiter.api.Test;
import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class ResourceRoundTripTests {

View File

@ -1,10 +1,5 @@
package org.hl7.fhir.r5.test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import org.fhir.ucum.UcumException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.conformance.ProfileUtilities;
@ -15,14 +10,19 @@ import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.utilities.TextFile;
import org.junit.jupiter.api.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
public class ShexGeneratorTests {
private void doTest(String name) throws FileNotFoundException, IOException, FHIRException, UcumException {
StructureDefinition sd = TestingUtilities.context().fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(name, null));
if(sd == null) {
if (sd == null) {
throw new FHIRException("StructuredDefinition for " + name + "was null");
}
Path outPath = FileSystems.getDefault().getPath(System.getProperty("java.io.tmpdir"), name.toLowerCase()+".shex");
Path outPath = FileSystems.getDefault().getPath(System.getProperty("java.io.tmpdir"), name.toLowerCase() + ".shex");
TextFile.stringToFile(new ShExGenerator(TestingUtilities.context()).generate(HTMLLinkPolicy.NONE, sd), outPath.toString());
}
@ -36,7 +36,6 @@ public class ShexGeneratorTests {
doTest("uri");
}
@Test
public void testObservation() throws FHIRException, IOException, UcumException {
doTest("Observation");

View File

@ -12,11 +12,16 @@ import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.*;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent;
import org.hl7.fhir.r5.model.ExpressionNode.CollectionStatus;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.r5.model.TypeDetails;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
@ -40,7 +45,11 @@ import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

View File

@ -47,7 +47,5 @@ public class SnomedExpressionsTests {
private void p(String expression) throws FHIRException {
Assertions.assertNotNull(SnomedExpressions.parse(expression), "must be present");
}
}

View File

@ -2,14 +2,10 @@ package org.hl7.fhir.r5.test.misc;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import javax.xml.parsers.ParserConfigurationException;
import java.io.FileNotFoundException;

View File

@ -60,6 +60,19 @@
<optional>true</optional>
</dependency>
<!-- JUnit Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -1,15 +0,0 @@
package org.hl7.fhir.utilities.tests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite.SuiteClasses;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@SuiteClasses({
JsonParserTests.class,
XhtmlNodeTest.class,
XLSXmlNormaliserTests.class})
public class AllUtilitiesTests {
}

View File

@ -1,11 +1,9 @@
package org.hl7.fhir.utilities.tests;
import static org.junit.Assert.*;
import java.io.IOException;
import org.hl7.fhir.utilities.json.JsonTrackingParser;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class JsonParserTests {

View File

@ -7,11 +7,10 @@ import javax.xml.transform.TransformerException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.xls.XLSXmlNormaliser;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;
public class XLSXmlNormaliserTests {
@Test
@ -20,7 +19,6 @@ public class XLSXmlNormaliserTests {
n.go();
// n = new XLSXmlNormaliser("C:\\work\\org.hl7.fhir\\build\\source\\observation\\observation-spreadsheet.before.xml", "C:\\\\work\\\\org.hl7.fhir\\\\build\\\\source\\\\observation\\\\observation-spreadsheet.before.out.xml", true);
// n.go();
Assert.assertTrue(true);
Assertions.assertTrue(true);
}
}

View File

@ -1,12 +1,13 @@
package org.hl7.fhir.utilities.tests;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertEquals;
@ -29,7 +30,6 @@ public class XhtmlNodeTest {
node = new XhtmlNode();
node.setValueAsString("<div>&lt;</div>");
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">&lt;</div>", node.getValueAsString());
}
/**

View File

@ -164,10 +164,17 @@
<artifactId>thymeleaf</artifactId>
<version>3.0.9.RELEASE</version>
</dependency>
<!-- JUnit Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>

View File

@ -405,5 +405,42 @@ public class CliContext {
this.noExtensibleBindingMessages = noExtensibleBindingMessages;
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CliContext that = (CliContext) o;
return doNative == that.doNative &&
anyExtensionsAllowed == that.anyExtensionsAllowed &&
hintAboutNonMustSupport == that.hintAboutNonMustSupport &&
recursive == that.recursive &&
doDebug == that.doDebug &&
assumeValidRestReferences == that.assumeValidRestReferences &&
canDoNative == that.canDoNative &&
noInternalCaching == that.noInternalCaching &&
noExtensibleBindingMessages == that.noExtensibleBindingMessages &&
Objects.equals(map, that.map) &&
Objects.equals(output, that.output) &&
Objects.equals(txServer, that.txServer) &&
Objects.equals(sv, that.sv) &&
Objects.equals(txLog, that.txLog) &&
Objects.equals(mapLog, that.mapLog) &&
Objects.equals(lang, that.lang) &&
Objects.equals(fhirpath, that.fhirpath) &&
Objects.equals(snomedCT, that.snomedCT) &&
Objects.equals(targetVer, that.targetVer) &&
Objects.equals(igs, that.igs) &&
Objects.equals(questionnaires, that.questionnaires) &&
Objects.equals(profiles, that.profiles) &&
Objects.equals(sources, that.sources) &&
mode == that.mode &&
Objects.equals(locale, that.locale) &&
Objects.equals(locations, that.locations);
}
@Override
public int hashCode() {
return Objects.hash(doNative, anyExtensionsAllowed, hintAboutNonMustSupport, recursive, doDebug, assumeValidRestReferences, canDoNative, noInternalCaching, noExtensibleBindingMessages, map, output, txServer, sv, txLog, mapLog, lang, fhirpath, snomedCT, targetVer, igs, questionnaires, profiles, sources, mode, locale, locations);
}
}

View File

@ -1,14 +1,5 @@
package org.hl7.fhir.conversion.tests;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.NotImplementedException;
import org.hl7.fhir.exceptions.DefinitionException;
@ -37,41 +28,49 @@ import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import junit.framework.Assert;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@RunWith(Parameterized.class)
public class SnapShotGenerationTestsX {
public enum TestFetchMode {
INPUT,
OUTPUT,
OUTPUT,
INCLUDE
}
public static class Rule {
private String description;
private String expression;
public Rule(String description, String expression) {
super();
this.description = description;
this.expression = expression;
}
public Rule(Element rule) {
super();
this.description = rule.getAttribute("text");
this.expression = rule.getAttribute("fhirpath");
}
public String getDescription() {
return description;
}
public String getExpression() {
return expression;
}
@ -89,7 +88,7 @@ public class SnapShotGenerationTestsX {
private boolean newSliceProcessing;
private boolean debug;
private String version;
private List<Rule> rules = new ArrayList<>();
private StructureDefinition source;
private StructureDefinition included;
@ -103,7 +102,7 @@ public class SnapShotGenerationTestsX {
fail = "true".equals(test.getAttribute("fail"));
newSliceProcessing = !"false".equals(test.getAttribute("new-slice-processing"));
debug = "true".equals(test.getAttribute("debug"));
id = test.getAttribute("id");
include = test.getAttribute("include");
register = test.getAttribute("register");
@ -115,65 +114,81 @@ public class SnapShotGenerationTestsX {
rule = XMLUtil.getNextSibling(rule);
}
}
public String getId() {
return id;
}
public boolean isSort() {
return sort;
}
public boolean isGen() {
return gen;
}
public String getInclude() {
return include;
}
public boolean isFail() {
return fail;
}
public StructureDefinition getIncluded() {
return included;
}
public List<Rule> getRules() {
return rules;
}
public StructureDefinition getSource() {
return source;
}
public void setSource(StructureDefinition source) {
this.source = source;
}
public StructureDefinition getExpected() {
return expected;
}
public void setExpected(StructureDefinition expected) {
this.expected = expected;
}
public StructureDefinition getOutput() {
return output;
}
public void setOutput(StructureDefinition output) {
this.output = output;
}
public void load() throws FHIRFormatError, FileNotFoundException, IOException {
if (TestingUtilitiesX.findTestResource("rX", "snapshot-generation", id+"-input.json"))
source = (StructureDefinition) new JsonParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", id+"-input.json"));
if (TestingUtilitiesX.findTestResource("rX", "snapshot-generation", id + "-input.json"))
source = (StructureDefinition) new JsonParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", id + "-input.json"));
else
source = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", id+"-input.xml"));
source = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", id + "-input.xml"));
if (!fail)
expected = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", id+"-expected.xml"));
expected = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", id + "-expected.xml"));
if (!Utilities.noString(include))
included = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", include+".xml"));
included = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", include + ".xml"));
if (!Utilities.noString(register)) {
if (TestingUtilitiesX.findTestResource("rX", "snapshot-generation", register+".xml")) {
included = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", register+".xml"));
if (TestingUtilitiesX.findTestResource("rX", "snapshot-generation", register + ".xml")) {
included = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", register + ".xml"));
} else {
included = (StructureDefinition) new JsonParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", register+".json"));
included = (StructureDefinition) new JsonParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", register + ".json"));
}
}
}
public boolean isNewSliceProcessing() {
return newSliceProcessing;
}
public boolean isDebug() {
return debug;
}
@ -184,13 +199,13 @@ public class SnapShotGenerationTestsX {
@Override
public boolean isDatatype(String name) {
StructureDefinition sd = TestingUtilitiesX.context(version).fetchTypeDefinition(name);
return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE || sd.getKind() == StructureDefinitionKind.COMPLEXTYPE);
return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE || sd.getKind() == StructureDefinitionKind.COMPLEXTYPE);
}
@Override
public boolean isResource(String typeSimple) {
StructureDefinition sd = TestingUtilitiesX.context(version).fetchTypeDefinition(typeSimple);
return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.RESOURCE);
return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.RESOURCE);
}
@Override
@ -200,13 +215,13 @@ public class SnapShotGenerationTestsX {
@Override
public String getLinkFor(String corePath, String typeSimple) {
return Utilities.pathURL(corePath, "datatypes.html#"+typeSimple);
return Utilities.pathURL(corePath, "datatypes.html#" + typeSimple);
}
@Override
public BindingResolution resolveBinding(StructureDefinition def, ElementDefinitionBindingComponent binding, String path) throws FHIRException {
BindingResolution br = new BindingResolution();
br.url = path+"/something.html";
br.url = path + "/something.html";
br.display = "something";
return br;
}
@ -214,7 +229,7 @@ public class SnapShotGenerationTestsX {
@Override
public BindingResolution resolveBinding(StructureDefinition def, String url, String path) throws FHIRException {
BindingResolution br = new BindingResolution();
br.url = path+"/something.html";
br.url = path + "/something.html";
br.display = "something";
return br;
}
@ -223,9 +238,9 @@ public class SnapShotGenerationTestsX {
public String getLinkForProfile(StructureDefinition profile, String url) {
StructureDefinition sd = TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, url);
if (sd == null)
return url+"|"+url;
return url + "|" + url;
else
return sd.getId()+".html|"+sd.present();
return sd.getId() + ".html|" + sd.present();
}
@Override
@ -256,7 +271,7 @@ public class SnapShotGenerationTestsX {
return TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/OperationOutcome");
if (id.equals("parameters"))
return TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Parameters");
if (id.contains("-")) {
String[] p = id.split("\\-");
id = p[0];
@ -268,15 +283,17 @@ public class SnapShotGenerationTestsX {
for (TestDetails td : tests) {
if (td.getId().equals(id))
switch (mode) {
case INPUT: return td.getSource();
case OUTPUT: if (td.getOutput() == null)
throw new FHIRException("Not generated yet");
else
return td.getOutput();
case INCLUDE:
return td.getIncluded();
default:
throw new FHIRException("Not done yet");
case INPUT:
return td.getSource();
case OUTPUT:
if (td.getOutput() == null)
throw new FHIRException("Not generated yet");
else
return td.getOutput();
case INCLUDE:
return td.getIncluded();
default:
throw new FHIRException("Not done yet");
}
}
return null;
@ -295,7 +312,7 @@ public class SnapShotGenerationTestsX {
@Override
public boolean log(String argument, List<Base> focus) {
System.out.println(argument+": "+fp.convertToString(focus));
System.out.println(argument + ": " + fp.convertToString(focus));
return true;
}
@ -323,7 +340,7 @@ public class SnapShotGenerationTestsX {
list.add(res);
return list;
}
throw new Error("Could not resolve "+id);
throw new Error("Could not resolve " + id);
}
throw new Error("Not implemented yet");
}
@ -369,7 +386,6 @@ public class SnapShotGenerationTestsX {
private static FHIRPathEngine fp;
@Parameters(name = "{index}: file {0}")
public static Iterable<Object[]> data() throws ParserConfigurationException, IOException, FHIRFormatError, SAXException {
SnapShotGenerationTestsContext context = new SnapShotGenerationTestsContext();
@ -380,80 +396,74 @@ public class SnapShotGenerationTestsX {
TestDetails t = new TestDetails(test);
context.tests.add(t);
t.load();
objects.add(new Object[] {t.getId(), t, context });
objects.add(new Object[]{t.getId(), t, context});
test = XMLUtil.getNextSibling(test);
}
return objects;
}
private final TestDetails test;
private SnapShotGenerationTestsContext context;
private List<ValidationMessage> messages;
private static String version;
public SnapShotGenerationTestsX(String id, TestDetails test, SnapShotGenerationTestsContext context) {
this.test = test;
this.context = context;
}
@SuppressWarnings("deprecation")
@Test
public void test() throws Exception {
@ParameterizedTest(name = "{index}: file {0}")
@MethodSource("data")
public void test(String id, TestDetails test, SnapShotGenerationTestsContext context) throws Exception {
version = test.version;
this.context = context;
if (fp == null)
fp = new FHIRPathEngine(TestingUtilitiesX.context(version));
fp.setHostServices(context);
messages = new ArrayList<ValidationMessage>();
if (test.isFail()) {
try {
if (test.isGen())
testGen(true);
testGen(true, test);
else
testSort();
Assert.assertTrue("Should have failed", false);
testSort(test);
Assertions.assertTrue(false, "Should have failed");
} catch (Throwable e) {
System.out.println("Error running test: "+e.getMessage());
System.out.println("Error running test: " + e.getMessage());
if (!Utilities.noString(test.regex)) {
Assert.assertTrue("correct error message", e.getMessage().matches(test.regex));
Assertions.assertTrue(e.getMessage().matches(test.regex), "correct error message");
} else if ("Should have failed".equals(e.getMessage())) {
throw e;
} else {
Assert.assertTrue("all ok", true);
Assertions.assertTrue(true, "all ok");
}
}
} else if (test.isGen())
testGen(false);
testGen(false, test);
else
testSort();
testSort(test);
for (Rule r : test.getRules()) {
StructureDefinition sdn = new StructureDefinition();
boolean ok = fp.evaluateToBoolean(sdn, sdn, sdn, r.expression);
Assert.assertTrue(r.description, ok);
Assertions.assertTrue(ok, r.description);
}
}
private void testSort() throws DefinitionException, FHIRException, IOException {
StructureDefinition base = getSD(test.getSource().getBaseDefinition());
private void testSort(TestDetails test) throws DefinitionException, FHIRException, IOException {
StructureDefinition base = getSD(test.getSource().getBaseDefinition());
test.setOutput(test.getSource().copy());
ProfileUtilities pu = new ProfileUtilities(TestingUtilitiesX.context(version), null, null);
pu.setIds(test.getSource(), false);
List<String> errors = new ArrayList<String>();
List<String> errors = new ArrayList<String>();
pu.sortDifferential(base, test.getOutput(), test.getOutput().getUrl(), errors, false);
if (!errors.isEmpty())
throw new FHIRException(errors.get(0));
IOUtils.copy(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", test.getId()+"-expected.xml"), new FileOutputStream(TestingUtilitiesX.tempFile("snapshot", test.getId()+"-expected.xml")));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilitiesX.tempFile("snapshot", test.getId()+"-actual.xml")), test.getOutput());
Assert.assertTrue("Output does not match expected", test.expected.equalsDeep(test.output));
IOUtils.copy(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(TestingUtilitiesX.tempFile("snapshot", test.getId() + "-expected.xml")));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilitiesX.tempFile("snapshot", test.getId() + "-actual.xml")), test.getOutput());
Assertions.assertTrue(test.expected.equalsDeep(test.output), "Output does not match expected");
}
private void testGen(boolean fail) throws Exception {
private void testGen(boolean fail, TestDetails test) throws Exception {
if (!Utilities.noString(test.register)) {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
ProfileUtilities pu = new ProfileUtilities(TestingUtilitiesX.context(version), messages, null);
pu.setNewSlicingProcessing(true);
pu.setIds(test.included, false);
@ -471,14 +481,14 @@ public class SnapShotGenerationTestsX {
}
}
if (ec > 0)
throw new FHIRException("register gen failed: "+messages.toString());
throw new FHIRException("register gen failed: " + messages.toString());
}
StructureDefinition base = getSD(test.getSource().getBaseDefinition());
StructureDefinition base = getSD(test.getSource().getBaseDefinition());
if (!base.getUrl().equals(test.getSource().getBaseDefinition()))
throw new Exception("URL mismatch on base: "+base.getUrl()+" wanting "+test.getSource().getBaseDefinition());
throw new Exception("URL mismatch on base: " + base.getUrl() + " wanting " + test.getSource().getBaseDefinition());
StructureDefinition output = test.getSource().copy();
ProfileUtilities pu = new ProfileUtilities(TestingUtilitiesX.context(version), messages , new TestPKP());
ProfileUtilities pu = new ProfileUtilities(TestingUtilitiesX.context(version), messages, new TestPKP());
pu.setNewSlicingProcessing(test.isNewSliceProcessing());
pu.setThrowException(false);
pu.setDebug(test.isDebug());
@ -488,7 +498,7 @@ public class SnapShotGenerationTestsX {
int lastCount = output.getDifferential().getElement().size();
pu.sortDifferential(base, output, test.getSource().getName(), errors, false);
if (errors.size() > 0)
throw new FHIRException("Sort failed: "+errors.toString());
throw new FHIRException("Sort failed: " + errors.toString());
}
try {
messages.clear();
@ -500,10 +510,10 @@ public class SnapShotGenerationTestsX {
}
}
if (ml.size() > 0) {
throw new FHIRException("Snapshot Generation failed: "+ml.toString());
throw new FHIRException("Snapshot Generation failed: " + ml.toString());
}
} catch (Throwable e) {
System.out.println("\r\nException: "+e.getMessage());
System.out.println("\r\nException: " + e.getMessage());
throw e;
}
if (output.getDifferential().hasElement())
@ -511,16 +521,16 @@ public class SnapShotGenerationTestsX {
if (!fail) {
test.output = output;
TestingUtilitiesX.context(version).cacheResource(output);
File dst = new File(TestingUtilitiesX.tempFile("snapshot", test.getId()+"-expected.xml"));
File dst = new File(TestingUtilitiesX.tempFile("snapshot", test.getId() + "-expected.xml"));
if (dst.exists())
dst.delete();
IOUtils.copy(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", test.getId()+"-expected.xml"), new FileOutputStream(dst));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilitiesX.tempFile("snapshot", test.getId()+"-actual.xml")), output);
IOUtils.copy(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(dst));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilitiesX.tempFile("snapshot", test.getId() + "-actual.xml")), output);
StructureDefinition t1 = test.expected.copy();
t1.setText(null);
StructureDefinition t2 = test.output.copy();
t2.setText(null);
Assert.assertTrue("Output does not match expected", t1.equalsDeep(t2));
Assertions.assertTrue(t1.equalsDeep(t2), "Output does not match expected");
}
}
@ -530,9 +540,9 @@ public class SnapShotGenerationTestsX {
sd = TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, url);
if (!sd.hasSnapshot()) {
StructureDefinition base = getSD(sd.getBaseDefinition());
ProfileUtilities pu = new ProfileUtilities(TestingUtilitiesX.context(version), messages , new TestPKP());
ProfileUtilities pu = new ProfileUtilities(TestingUtilitiesX.context(version), messages, new TestPKP());
pu.setNewSlicingProcessing(true);
List<String> errors = new ArrayList<String>();
List<String> errors = new ArrayList<String>();
pu.sortDifferential(base, sd, url, errors, false);
if (!errors.isEmpty())
throw new FHIRException(errors.get(0));

View File

@ -1,133 +1,131 @@
package org.hl7.fhir.validation.tests;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.everit.json.schema.Schema;
import org.everit.json.schema.ValidationException;
import org.everit.json.schema.loader.SchemaLoader;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.validation.tests.utilities.TestUtilities;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
public class JsonSchemaTests {
static private org.everit.json.schema.Schema sFhir;
static private org.everit.json.schema.Schema sTest;
public static final String TEST_SCHEMA = "{\r\n"+
" \"$schema\": \"http://json-schema.org/draft-06/schema#\",\r\n"+
// " \"id\": \"http://hl7.org/fhir/test-json-schema/4.0\",\r\n"+
" \"description\": \"for unit tests\",\r\n"+
" \"discriminator\": {\r\n"+
" \"propertyName\": \"resourceType\",\r\n"+
" \"mapping\": {\r\n"+
" \"A\": \"#/definitions/A\",\r\n"+
" \"B\": \"#/definitions/B\"\r\n"+
" }\r\n"+
" },\r\n"+
" \"oneOf\": [\r\n"+
" {\r\n"+
" \"$ref\": \"#/definitions/A\"\r\n"+
" },\r\n"+
" {\r\n"+
" \"$ref\": \"#/definitions/B\"\r\n"+
" }\r\n"+
" ],\r\n"+
" \"definitions\": {\r\n"+
" \"boolean\": {\r\n"+
" \"pattern\": \"^true|false$\",\r\n"+
" \"type\": \"boolean\"\r\n"+
" },\r\n"+
" \"id\": {\r\n"+
" \"pattern\": \"^[A-Za-z0-9\\\\-\\\\.]{1,64}$\",\r\n"+
" \"type\": \"string\"\r\n"+
" },\r\n"+
" \"integer\": {\r\n"+
" \"pattern\": \"^-?([0]|([1-9][0-9]*))$\",\r\n"+
" \"type\": \"number\"\r\n"+
" },\r\n"+
" \"string\": {\r\n"+
" \"pattern\": \"^[ \\\\r\\\\n\\\\t\\\\S]+$\",\r\n"+
" \"type\": \"string\"\r\n"+
" },\r\n"+
" \"Element\": {\r\n"+
" \"properties\": {\r\n"+
" \"id\": {\r\n"+
" \"$ref\": \"#/definitions/string\"\r\n"+
" }\r\n"+
" },\r\n"+
" \"additionalProperties\": false\r\n"+
" },\r\n"+
" \"Coding\": {\r\n"+
" \"properties\": {\r\n"+
" \"id\": {\r\n"+
" \"$ref\": \"#/definitions/string\"\r\n"+
" },\r\n"+
" \"system\": {\r\n"+
" \"$ref\": \"#/definitions/string\"\r\n"+
" },\r\n"+
" \"version\": {\r\n"+
" \"$ref\": \"#/definitions/string\"\r\n"+
" },\r\n"+
" \"code\": {\r\n"+
" \"$ref\": \"#/definitions/string\"\r\n"+
" },\r\n"+
" \"display\": {\r\n"+
" \"$ref\": \"#/definitions/string\"\r\n"+
" },\r\n"+
" \"userSelected\": {\r\n"+
" \"$ref\": \"#/definitions/boolean\"\r\n"+
" }\r\n"+
" },\r\n"+
" \"additionalProperties\": false\r\n"+
" },\r\n"+
" \"A\": {\r\n"+
" \"properties\": {\r\n"+
" \"resourceType\": {\r\n"+
" \"const\": \"A\"\r\n"+
" },\r\n"+
" \"id\": {\r\n"+
" \"$ref\": \"#/definitions/id\"\r\n"+
" }\r\n"+
" },\r\n"+
" \"required\": [\r\n"+
" \"resourceType\"\r\n"+
" ]\r\n"+
" },\r\n"+
" \"B\": {\r\n"+
" \"properties\": {\r\n"+
" \"resourceType\": {\r\n"+
" \"const\": \"B\"\r\n"+
" },\r\n"+
" \"code\": {\r\n"+
" \"$ref\": \"#/definitions/id\"\r\n"+
" },\r\n"+
" \"string\": {\r\n"+
" \"$ref\": \"#/definitions/string\"\r\n"+
" },\r\n"+
" \"integer\": {\r\n"+
" \"$ref\": \"#/definitions/integer\"\r\n"+
" },\r\n"+
" \"boolean\": {\r\n"+
" \"$ref\": \"#/definitions/boolean\"\r\n"+
" }\r\n"+
" \r\n"+
" },\r\n"+
" \"additionalProperties\": false,\r\n"+
" \"required\": [\r\n"+
" \"resourceType\", \"code\"\r\n"+
" ]\r\n"+
" }\r\n"+
" }\r\n"+
"}\r\n";
@Before
public static final String TEST_SCHEMA = "{\r\n" +
" \"$schema\": \"http://json-schema.org/draft-06/schema#\",\r\n" +
// " \"id\": \"http://hl7.org/fhir/test-json-schema/4.0\",\r\n"+
" \"description\": \"for unit tests\",\r\n" +
" \"discriminator\": {\r\n" +
" \"propertyName\": \"resourceType\",\r\n" +
" \"mapping\": {\r\n" +
" \"A\": \"#/definitions/A\",\r\n" +
" \"B\": \"#/definitions/B\"\r\n" +
" }\r\n" +
" },\r\n" +
" \"oneOf\": [\r\n" +
" {\r\n" +
" \"$ref\": \"#/definitions/A\"\r\n" +
" },\r\n" +
" {\r\n" +
" \"$ref\": \"#/definitions/B\"\r\n" +
" }\r\n" +
" ],\r\n" +
" \"definitions\": {\r\n" +
" \"boolean\": {\r\n" +
" \"pattern\": \"^true|false$\",\r\n" +
" \"type\": \"boolean\"\r\n" +
" },\r\n" +
" \"id\": {\r\n" +
" \"pattern\": \"^[A-Za-z0-9\\\\-\\\\.]{1,64}$\",\r\n" +
" \"type\": \"string\"\r\n" +
" },\r\n" +
" \"integer\": {\r\n" +
" \"pattern\": \"^-?([0]|([1-9][0-9]*))$\",\r\n" +
" \"type\": \"number\"\r\n" +
" },\r\n" +
" \"string\": {\r\n" +
" \"pattern\": \"^[ \\\\r\\\\n\\\\t\\\\S]+$\",\r\n" +
" \"type\": \"string\"\r\n" +
" },\r\n" +
" \"Element\": {\r\n" +
" \"properties\": {\r\n" +
" \"id\": {\r\n" +
" \"$ref\": \"#/definitions/string\"\r\n" +
" }\r\n" +
" },\r\n" +
" \"additionalProperties\": false\r\n" +
" },\r\n" +
" \"Coding\": {\r\n" +
" \"properties\": {\r\n" +
" \"id\": {\r\n" +
" \"$ref\": \"#/definitions/string\"\r\n" +
" },\r\n" +
" \"system\": {\r\n" +
" \"$ref\": \"#/definitions/string\"\r\n" +
" },\r\n" +
" \"version\": {\r\n" +
" \"$ref\": \"#/definitions/string\"\r\n" +
" },\r\n" +
" \"code\": {\r\n" +
" \"$ref\": \"#/definitions/string\"\r\n" +
" },\r\n" +
" \"display\": {\r\n" +
" \"$ref\": \"#/definitions/string\"\r\n" +
" },\r\n" +
" \"userSelected\": {\r\n" +
" \"$ref\": \"#/definitions/boolean\"\r\n" +
" }\r\n" +
" },\r\n" +
" \"additionalProperties\": false\r\n" +
" },\r\n" +
" \"A\": {\r\n" +
" \"properties\": {\r\n" +
" \"resourceType\": {\r\n" +
" \"const\": \"A\"\r\n" +
" },\r\n" +
" \"id\": {\r\n" +
" \"$ref\": \"#/definitions/id\"\r\n" +
" }\r\n" +
" },\r\n" +
" \"required\": [\r\n" +
" \"resourceType\"\r\n" +
" ]\r\n" +
" },\r\n" +
" \"B\": {\r\n" +
" \"properties\": {\r\n" +
" \"resourceType\": {\r\n" +
" \"const\": \"B\"\r\n" +
" },\r\n" +
" \"code\": {\r\n" +
" \"$ref\": \"#/definitions/id\"\r\n" +
" },\r\n" +
" \"string\": {\r\n" +
" \"$ref\": \"#/definitions/string\"\r\n" +
" },\r\n" +
" \"integer\": {\r\n" +
" \"$ref\": \"#/definitions/integer\"\r\n" +
" },\r\n" +
" \"boolean\": {\r\n" +
" \"$ref\": \"#/definitions/boolean\"\r\n" +
" }\r\n" +
" \r\n" +
" },\r\n" +
" \"additionalProperties\": false,\r\n" +
" \"required\": [\r\n" +
" \"resourceType\", \"code\"\r\n" +
" ]\r\n" +
" }\r\n" +
" }\r\n" +
"}\r\n";
@BeforeEach
public void setUp() throws Exception {
if (sFhir == null) {
// String path = TestUtilities.resourceNameToFile("fhir.schema.json"); // todo... what should this be?
@ -155,11 +153,11 @@ public class JsonSchemaTests {
private void pass(String source, Schema schema) throws FileNotFoundException, IOException {
Assert.assertTrue(validateJson(source, schema));
Assertions.assertTrue(validateJson(source, schema));
}
private void fail(String source, Schema schema) throws FileNotFoundException, IOException {
Assert.assertFalse(validateJson(source, schema));
Assertions.assertFalse(validateJson(source, schema));
}
@Test

View File

@ -3,7 +3,7 @@ package org.hl7.fhir.validation.tests;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.validation.NativeHostServices;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class NativeHostServiceTester {

View File

@ -13,7 +13,7 @@ import org.hl7.fhir.utilities.cache.ToolsVersion;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.validation.ValidationEngine;
import org.hl7.fhir.validation.tests.utilities.TestUtilities;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class ProfileComparisonTests {

View File

@ -1,8 +1,5 @@
package org.hl7.fhir.validation.tests;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.model.FhirPublication;
import org.hl7.fhir.r5.model.OperationOutcome;
@ -11,19 +8,22 @@ import org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.validation.ValidationEngine;
import org.hl7.fhir.validation.tests.utilities.TestUtilities;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
public class ValidationEngineTests {
private static final String DEF_TX = "http://tx.fhir.org";
private static final String DBG_TX = "http://local.fhir.org:960";
public static boolean inbuild;
@Test
public void testCurrentXml() throws Exception {
if (!TestUtilities.silent)
if (!TestUtilities.silent)
System.out.println("Validate patient-example.xml in Current version");
ValidationEngine ve = new ValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, null, FhirPublication.R4, "4.0.1");
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient-example.xml"), null);
@ -31,36 +31,36 @@ public class ValidationEngineTests {
int w = warnings(op);
int h = hints(op);
if (!TestUtilities.silent) {
System.out.println(" .. done: "+Integer.toString(e)+" errors, "+Integer.toString(w)+" warnings, "+Integer.toString(h)+" information messages");
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
for (OperationOutcomeIssueComponent iss : op.getIssue()) {
System.out.println(" "+iss.getDetails().getText());
System.out.println(" " + iss.getDetails().getText());
}
}
Assert.assertTrue(e == 0);
Assert.assertTrue(w == 0);
Assert.assertTrue(h == 0);
Assertions.assertEquals(0, e);
Assertions.assertEquals(0, w);
Assertions.assertEquals(0, h);
}
@Test
public void testCurrentJson() throws Exception {
if (!TestUtilities.silent)
System.out.println("Validate patient-example.json in Current version");
System.out.println("Validate patient-example.json in Current version");
ValidationEngine ve = new ValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, null, FhirPublication.R4, "4.0.1");
OperationOutcome op = ve.validate(FhirFormat.JSON, TestingUtilities.loadTestResourceStream("validator", "patient-example.json"), null);
int e = errors(op);
int w = warnings(op);
int h = hints(op);
Assert.assertTrue(e == 0);
Assert.assertTrue(w == 0);
Assert.assertTrue(h == 0);
Assertions.assertEquals(0, e);
Assertions.assertEquals(0, w);
Assertions.assertEquals(0, h);
if (!TestUtilities.silent)
System.out.println(" .. done: "+Integer.toString(e)+" errors, "+Integer.toString(w)+" warnings, "+Integer.toString(h)+" information messages");
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
}
@Test
public void test140() throws Exception {
if (inbuild) {
Assert.assertTrue(true);
Assertions.assertTrue(true);
return;
}
if (!TestUtilities.silent)
@ -70,22 +70,22 @@ public class ValidationEngineTests {
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient140.xml"), null);
if (!TestUtilities.silent)
for (OperationOutcomeIssueComponent iss : op.getIssue()) {
System.out.println(" "+iss.getDetails().getText());
System.out.println(" " + iss.getDetails().getText());
}
int e = errors(op);
int w = warnings(op);
int h = hints(op);
Assert.assertTrue(e == 1);
Assert.assertTrue(w == 0);
Assert.assertTrue(h == 0);
Assertions.assertEquals(1, e);
Assertions.assertEquals(0, w);
Assertions.assertEquals(0, h);
if (!TestUtilities.silent)
System.out.println(" .. done: "+Integer.toString(e)+" errors, "+Integer.toString(w)+" warnings, "+Integer.toString(h)+" information messages");
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
}
@Test
public void test102() throws Exception {
if (inbuild) {
Assert.assertTrue(true);
Assertions.assertTrue(true);
return;
}
if (!org.hl7.fhir.validation.tests.utilities.TestUtilities.silent)
@ -95,22 +95,22 @@ public class ValidationEngineTests {
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient102.xml"), null);
if (!TestUtilities.silent)
for (OperationOutcomeIssueComponent iss : op.getIssue()) {
System.out.println(" "+iss.getSeverity().toCode()+": "+iss.getDetails().getText());
System.out.println(" " + iss.getSeverity().toCode() + ": " + iss.getDetails().getText());
}
int e = errors(op);
int w = warnings(op);
int h = hints(op);
Assert.assertTrue(e == 1);
Assert.assertTrue(w == 0);
Assert.assertTrue(h == 0);
Assertions.assertEquals(1, e);
Assertions.assertEquals(0, w);
Assertions.assertEquals(0, h);
if (!TestUtilities.silent)
System.out.println(" .. done: "+Integer.toString(e)+" errors, "+Integer.toString(w)+" warnings, "+Integer.toString(h)+" information messages");
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
}
@Test
public void testObs102() throws Exception {
if (inbuild) {
Assert.assertTrue(true);
Assertions.assertTrue(true);
return;
}
if (!TestUtilities.silent)
@ -120,16 +120,16 @@ public class ValidationEngineTests {
OperationOutcome op = ve.validate(FhirFormat.JSON, TestingUtilities.loadTestResourceStream("validator", "observation102.json"), null);
if (!TestUtilities.silent)
for (OperationOutcomeIssueComponent iss : op.getIssue()) {
System.out.println(" "+iss.getDetails().getText());
System.out.println(" " + iss.getDetails().getText());
}
int e = errors(op);
int w = warnings(op);
int h = hints(op);
Assert.assertTrue(e == 1);
Assert.assertTrue(w == 0);
Assert.assertTrue(h == 1);
Assertions.assertEquals(1, e);
Assertions.assertEquals(0, w);
Assertions.assertEquals(1, h);
if (!TestUtilities.silent)
System.out.println(" .. done: "+Integer.toString(e)+" errors, "+Integer.toString(w)+" warnings, "+Integer.toString(h)+" information messages");
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
}
@ -143,13 +143,13 @@ public class ValidationEngineTests {
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "observation301.xml"), null);
if (!TestUtilities.silent)
for (OperationOutcomeIssueComponent issue : op.getIssue())
System.out.println(" - "+issue.getDetails().getText());
System.out.println(" - " + issue.getDetails().getText());
int e = errors(op);
int w = warnings(op);
int h = hints(op);
Assert.assertTrue(e == 0);
Assertions.assertEquals(0, e);
if (!TestUtilities.silent)
System.out.println(" .. done: "+Integer.toString(e)+" errors, "+Integer.toString(w)+" warnings, "+Integer.toString(h)+" information messages");
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
}
@Test
@ -165,15 +165,15 @@ public class ValidationEngineTests {
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient301.xml"), profiles);
if (!TestUtilities.silent)
for (OperationOutcomeIssueComponent issue : op.getIssue())
System.out.println(" - "+issue.getDetails().getText());
System.out.println(" - " + issue.getDetails().getText());
int e = errors(op);
int w = warnings(op);
int h = hints(op);
Assert.assertTrue(e == 1);
Assert.assertTrue(w == 0);
Assert.assertTrue(h == 0);
Assertions.assertEquals(1, e);
Assertions.assertEquals(0, w);
Assertions.assertEquals(0, h);
if (!TestUtilities.silent)
System.out.println(" .. done: "+Integer.toString(e)+" errors, "+Integer.toString(w)+" warnings, "+Integer.toString(h)+" information messages");
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
}
private int errors(OperationOutcome op) {

View File

@ -7,7 +7,10 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.NotImplementedException;
import org.hl7.fhir.convertors.*;
import org.hl7.fhir.convertors.VersionConvertor_10_50;
import org.hl7.fhir.convertors.VersionConvertor_14_50;
import org.hl7.fhir.convertors.VersionConvertor_30_50;
import org.hl7.fhir.convertors.VersionConvertor_40_50;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
@ -19,40 +22,51 @@ import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.elementmodel.ObjectConverter;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.*;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.Constants;
import org.hl7.fhir.r5.model.FhirPublication;
import org.hl7.fhir.r5.model.Patient;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.TypeDetails;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.IResourceValidator;
import org.hl7.fhir.r5.utils.IResourceValidator.IValidatorResourceFetcher;
import org.hl7.fhir.r5.utils.IResourceValidator.ReferenceValidationPolicy;
import org.hl7.fhir.validation.instance.InstanceValidator;
import org.hl7.fhir.validation.ValidationEngine;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.hl7.fhir.validation.ValidationEngine;
import org.hl7.fhir.validation.instance.InstanceValidator;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Stream;
@RunWith(Parameterized.class)
public class ValidationTests implements IEvaluationContext, IValidatorResourceFetcher {
public final static boolean PRINT_OUTPUT_TO_CONSOLE = false;
@Parameters(name = "{index}: id {0}")
public static Iterable<Object[]> data() throws IOException {
public static Stream<Arguments> data() throws IOException {
String contents = TestingUtilities.loadTestResource("validator", "manifest.json");
Map<String, JsonObject> examples = new HashMap<String, JsonObject>();
@ -65,44 +79,37 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
names.addAll(examples.keySet());
Collections.sort(names);
List<Object[]> objects = new ArrayList<Object[]>(examples.size());
List<Arguments> objects = new ArrayList<>();
for (String id : names) {
objects.add(new Object[] { id, examples.get(id)});
objects.add(Arguments.of(id, examples.get(id)));
}
return objects;
return objects.stream();
}
private static JsonObject manifest;
private String name;
private JsonObject content;
private String version;
public ValidationTests(String name, JsonObject content) {
this.name = name;
this.content = content;
}
private static final String DEF_TX = "http://tx.fhir.org";
// private static final String DEF_TX = "http://local.fhir.org:960";
private static Map<String, ValidationEngine> ve = new HashMap<>();
private static ValidationEngine vCurr;
@SuppressWarnings("deprecation")
@Test
public void test() throws Exception {
System.out.println("---- "+name+" ----------------------------------------------------------------");
@ParameterizedTest(name = "{index}: id {0}")
@MethodSource("data")
public void test(String name, JsonObject content) throws Exception {
this.content = content;
System.out.println("---- " + name + " ----------------------------------------------------------------");
System.out.println("** Core: ");
String txLog = null;
if (content.has("txLog")) {
txLog = content.get("txLog").getAsString();
txLog = content.get("txLog").getAsString();
}
version = "5.0";
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
if (content.has("version")) {
version = content.get("version").getAsString();
}
version = VersionUtilities.getMajMin(version);
if (!ve.containsKey(version)) {
if (version.startsWith("5.0"))
@ -116,7 +123,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
else if (version.startsWith("1.4"))
ve.put(version, new ValidationEngine("hl7.fhir.r2b.core#1.4.0", DEF_TX, txLog, FhirPublication.DSTU2016May, true, "1.4.0"));
else
throw new Exception("unknown version "+version);
throw new Exception("unknown version " + version);
}
vCurr = ve.get(version);
vCurr.setFetcher(this);
@ -132,7 +139,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
InstanceValidator val = vCurr.getValidator();
val.setDebug(false);
if (content.has("allowed-extension-domain"))
if (content.has("allowed-extension-domain"))
val.getExtensionDomains().add(content.get("allowed-extension-domain").getAsString());
if (content.has("allowed-extension-domains"))
for (JsonElement a : content.getAsJsonArray("allowed-extension-domains"))
@ -149,7 +156,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
}
if (content.has("supporting")) {
for (JsonElement e : content.getAsJsonArray("supporting")) {
String filename = e.getAsString();
String filename = e.getAsString();
String contents = TestingUtilities.loadTestResource("validator", filename);
CanonicalResource mr = (CanonicalResource) loadResource(filename, contents);
val.getContext().cacheResource(mr);
@ -172,7 +179,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
if (content.has("examples")) {
val.setAllowExamples(content.get("examples").getAsBoolean());
} else {
val.setAllowExamples(true);
val.setAllowExamples(true);
}
val.setAssumeValidRestReferences(content.has("assumeValidRestReferences") ? content.get("assumeValidRestReferences").getAsBoolean() : false);
if (name.endsWith(".json"))
@ -189,24 +196,24 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
}
if (profile.has("supporting")) {
for (JsonElement e : profile.getAsJsonArray("supporting")) {
String filename = e.getAsString();
String filename = e.getAsString();
String contents = TestingUtilities.loadTestResource("validator", filename);
CanonicalResource mr = (CanonicalResource) loadResource(filename, contents);
val.getContext().cacheResource(mr);
}
}
String filename = profile.get("source").getAsString();
String filename = profile.get("source").getAsString();
String contents = TestingUtilities.loadTestResource("validator", filename);
System.out.println("Name: " + name+" - profile : "+profile.get("source").getAsString());
System.out.println("Name: " + name + " - profile : " + profile.get("source").getAsString());
version = content.has("version") ? content.get("version").getAsString() : Constants.VERSION;
StructureDefinition sd = loadProfile(filename, contents, messages);
val.getContext().cacheResource(sd);
val.getContext().cacheResource(sd);
val.setAssumeValidRestReferences(profile.has("assumeValidRestReferences") ? profile.get("assumeValidRestReferences").getAsBoolean() : false);
List<ValidationMessage> errorsProfile = new ArrayList<ValidationMessage>();
if (name.endsWith(".json"))
val.validate(null, errorsProfile, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.JSON, asSdList(sd));
else
val.validate(null, errorsProfile, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.XML, asSdList(sd));
val.validate(null, errorsProfile, IOUtils.toInputStream(testCaseContent, Charsets.UTF_8), FhirFormat.XML, asSdList(sd));
System.out.println(val.reportTimes());
checkOutcomes(errorsProfile, profile);
}
@ -214,7 +221,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
JsonObject logical = content.getAsJsonObject("logical");
if (logical.has("supporting")) {
for (JsonElement e : logical.getAsJsonArray("supporting")) {
String filename = e.getAsString();
String filename = e.getAsString();
String contents = TestingUtilities.loadTestResource("validator", filename);
CanonicalResource mr = (CanonicalResource) loadResource(filename, contents);
if (mr instanceof StructureDefinition) {
@ -229,7 +236,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
FHIRPathEngine fp = new FHIRPathEngine(val.getContext());
for (JsonElement e : logical.getAsJsonArray("expressions")) {
String exp = e.getAsString();
Assert.assertTrue(fp.evaluateToBoolean(null, le, le, le, fp.parse(exp)));
Assertions.assertTrue(fp.evaluateToBoolean(null, le, le, le, fp.parse(exp)));
}
}
checkOutcomes(errorsLogical, logical);
@ -242,7 +249,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
return res;
}
public StructureDefinition loadProfile(String filename, String contents, List<ValidationMessage> messages) throws IOException, FHIRFormatError, FileNotFoundException, FHIRException, DefinitionException {
public StructureDefinition loadProfile(String filename, String contents, List<ValidationMessage> messages) throws IOException, FHIRFormatError, FileNotFoundException, FHIRException, DefinitionException {
StructureDefinition sd = (StructureDefinition) loadResource(filename, contents);
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(version), messages, null);
if (!sd.hasSnapshot()) {
@ -250,19 +257,19 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
pu.generateSnapshot(base, sd, sd.getUrl(), null, sd.getTitle());
// (debugging) new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", sd.getId()+".xml")), sd);
}
for (Resource r: sd.getContained()) {
for (Resource r : sd.getContained()) {
if (r instanceof StructureDefinition) {
StructureDefinition childSd = (StructureDefinition)r;
StructureDefinition childSd = (StructureDefinition) r;
if (!childSd.hasSnapshot()) {
StructureDefinition base = TestingUtilities.context(version).fetchResource(StructureDefinition.class, childSd.getBaseDefinition());
pu.generateSnapshot(base, childSd, childSd.getUrl(), null, childSd.getTitle());
pu.generateSnapshot(base, childSd, childSd.getUrl(), null, childSd.getTitle());
}
}
}
return sd;
}
public Resource loadResource(String filename, String contents) throws IOException, FHIRFormatError, FileNotFoundException, FHIRException, DefinitionException {
public Resource loadResource(String filename, String contents) throws IOException, FHIRFormatError, FileNotFoundException, FHIRException, DefinitionException {
try (InputStream inputStream = IOUtils.toInputStream(contents, Charsets.UTF_8)) {
if (filename.contains(".json")) {
if (Constants.VERSION.equals(version) || "5.0".equals(version))
@ -276,7 +283,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
else if (org.hl7.fhir.r4.model.Constants.VERSION.equals(version) || "4.0".equals(version))
return VersionConvertor_40_50.convertResource(new org.hl7.fhir.r4.formats.JsonParser().parse(inputStream));
else
throw new FHIRException("unknown version "+version);
throw new FHIRException("unknown version " + version);
} else {
if (Constants.VERSION.equals(version) || "5.0".equals(version))
return new XmlParser().parse(inputStream);
@ -303,41 +310,41 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
for (ValidationMessage vm : errors) {
if (vm.getLevel() == IssueSeverity.FATAL || vm.getLevel() == IssueSeverity.ERROR) {
ec++;
if (PRINT_OUTPUT_TO_CONSOLE ) {
if (PRINT_OUTPUT_TO_CONSOLE) {
System.out.println(vm.getDisplay());
}
errLocs.add(vm.getLocation());
}
if (vm.getLevel() == IssueSeverity.WARNING) {
if (vm.getLevel() == IssueSeverity.WARNING) {
wc++;
if (PRINT_OUTPUT_TO_CONSOLE ) {
if (PRINT_OUTPUT_TO_CONSOLE) {
System.out.println(vm.getDisplay());
}
}
if (vm.getLevel() == IssueSeverity.INFORMATION) {
if (vm.getLevel() == IssueSeverity.INFORMATION) {
hc++;
if (PRINT_OUTPUT_TO_CONSOLE ) {
if (PRINT_OUTPUT_TO_CONSOLE) {
System.out.println(vm.getDisplay());
}
}
}
if (!TestingUtilities.context(version).isNoTerminologyServer() || !focus.has("tx-dependent")) {
Assert.assertEquals("Expected "+Integer.toString(java.get("errorCount").getAsInt())+" errors, but found "+Integer.toString(ec)+".", java.get("errorCount").getAsInt(), ec);
Assertions.assertEquals(java.get("errorCount").getAsInt(), ec, "Expected " + Integer.toString(java.get("errorCount").getAsInt()) + " errors, but found " + Integer.toString(ec) + ".");
if (java.has("warningCount"))
Assert.assertEquals("Expected "+Integer.toString(java.get("warningCount").getAsInt())+" warnings, but found "+Integer.toString(wc)+".", java.get("warningCount").getAsInt(), wc);
Assertions.assertEquals(java.get("warningCount").getAsInt(), wc, "Expected " + Integer.toString(java.get("warningCount").getAsInt()) + " warnings, but found " + Integer.toString(wc) + ".");
if (java.has("infoCount"))
Assert.assertEquals("Expected "+Integer.toString(java.get("infoCount").getAsInt())+" hints, but found "+Integer.toString(hc)+".", java.get("infoCount").getAsInt(), hc);
Assertions.assertEquals(java.get("infoCount").getAsInt(), hc, "Expected " + Integer.toString(java.get("infoCount").getAsInt()) + " hints, but found " + Integer.toString(hc) + ".");
}
if (java.has("error-locations")) {
JsonArray el = java.getAsJsonArray("error-locations");
Assert.assertEquals("locations count is not correct", errLocs.size(), el.size());
Assertions.assertEquals(errLocs.size(), el.size(), "locations count is not correct");
for (int i = 0; i < errLocs.size(); i++) {
Assert.assertEquals("Location should be "+el.get(i).getAsString()+", but was "+errLocs.get(i), errLocs.get(i), el.get(i).getAsString());
Assertions.assertEquals(errLocs.get(i), el.get(i).getAsString(), "Location should be " + el.get(i).getAsString() + ", but was " + errLocs.get(i));
}
}
if (focus.has("output")) {
focus.remove("output");
}
}
JsonArray vr = new JsonArray();
java.add("output", vr);
for (ValidationMessage vm : errors) {
@ -346,7 +353,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
}
private org.hl7.fhir.r4.model.Parameters makeExpProfile() {
org.hl7.fhir.r4.model.Parameters ep = new org.hl7.fhir.r4.model.Parameters();
org.hl7.fhir.r4.model.Parameters ep = new org.hl7.fhir.r4.model.Parameters();
ep.addParameter("profile-url", "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"); // change this to blow the cache
// all defaults....
return ep;
@ -394,17 +401,17 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
Element res = null;
if (url.equals("Patient/test")) {
res = new ObjectConverter(TestingUtilities.context(version)).convert(new Patient());
} else if (TestingUtilities.findTestResource("validator", url.replace("/", "-").toLowerCase()+".json")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.JSON).parse(TestingUtilities.loadTestResourceStream("validator", url.replace("/", "-").toLowerCase()+".json"));
} else if (TestingUtilities.findTestResource("validator", url.replace("/", "-").toLowerCase()+".xml")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.XML).parse(TestingUtilities.loadTestResourceStream("validator", url.replace("/", "-").toLowerCase()+".xml"));
} else if (TestingUtilities.findTestResource("validator", url.replace("/", "-").toLowerCase() + ".json")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.JSON).parse(TestingUtilities.loadTestResourceStream("validator", url.replace("/", "-").toLowerCase() + ".json"));
} else if (TestingUtilities.findTestResource("validator", url.replace("/", "-").toLowerCase() + ".xml")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.XML).parse(TestingUtilities.loadTestResourceStream("validator", url.replace("/", "-").toLowerCase() + ".xml"));
}
if (res == null && url.contains("/")) {
String tail = url.substring(url.indexOf("/")+1);
if (TestingUtilities.findTestResource("validator", tail.replace("/", "-").toLowerCase()+".json")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.JSON).parse(TestingUtilities.loadTestResourceStream("validator", tail.replace("/", "-").toLowerCase()+".json"));
} else if (TestingUtilities.findTestResource("validator", tail.replace("/", "-").toLowerCase()+".xml")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.XML).parse(TestingUtilities.loadTestResourceStream("validator", tail.replace("/", "-").toLowerCase()+".xml"));
String tail = url.substring(url.indexOf("/") + 1);
if (TestingUtilities.findTestResource("validator", tail.replace("/", "-").toLowerCase() + ".json")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.JSON).parse(TestingUtilities.loadTestResourceStream("validator", tail.replace("/", "-").toLowerCase() + ".json"));
} else if (TestingUtilities.findTestResource("validator", tail.replace("/", "-").toLowerCase() + ".xml")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.XML).parse(TestingUtilities.loadTestResourceStream("validator", tail.replace("/", "-").toLowerCase() + ".xml"));
}
}
return res;
@ -425,7 +432,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
@Override
public void setLocale(Locale locale) {
//do nothing
//do nothing
}
@Override
@ -447,10 +454,10 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
return vCurr.getContext().fetchResource(ValueSet.class, url);
}
@AfterClass
@AfterAll
public static void saveWhenDone() throws IOException {
String content = new GsonBuilder().setPrettyPrinting().create().toJson(manifest);
TextFile.stringToFile(content, Utilities.path("[tmp]", "validator-produced-manifest.json"));
}
}

33
pom.xml
View File

@ -19,6 +19,7 @@
<hapi_fhir_version>4.2.0</hapi_fhir_version>
<validator_test_case_version>1.1.10-SNAPSHOT</validator_test_case_version>
<junit_jupiter_version>5.6.2</junit_jupiter_version>
<maven_surefire_version>3.0.0-M4</maven_surefire_version>
</properties>
<artifactId>org.hl7.fhir.core</artifactId>
@ -71,25 +72,6 @@
<scope>test</scope>
</dependency>
<!-- JUnit Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
@ -174,24 +156,13 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven_surefire_version}</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
<testFailureIgnore>false</testFailureIgnore>
<argLine>-Xmx4096m</argLine>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit_jupiter_version}</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit_jupiter_version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.basepom.maven</groupId>