test snapshot generation bad path

This commit is contained in:
Grahame Grieve 2019-02-07 15:16:27 +11:00
parent e8121dec74
commit 483e0a3e80
2 changed files with 316 additions and 55 deletions

View File

@ -39,7 +39,7 @@
34. Referencing a custom extension 34. Referencing a custom extension
35. Referencing a profiled custom extension 35. Referencing a profiled custom extension
36. Deep recursion 36. Deep recursion
37. Constrained polymorphic elements 37. Test Bad Path
38. Deep nesting 38. Deep nesting
--> -->
<contained> <contained>
@ -1832,10 +1832,10 @@
<contained> <contained>
<StructureDefinition> <StructureDefinition>
<id value="t37"/> <id value="t37"/>
<url value="urn:uuid:2918bbbf-2145-4c13-822e-7dfd758694ec"/> <url value="urn:uuid:44a92f3e-3681-4dbc-baa2-48a07e2765ca"/>
<name value="t38"/> <name value="t37"/>
<status value="draft"/> <status value="draft"/>
<description value="fixture for #38: Constrained polymporphic elements"/> <description value="fixture for #37: Test bad Path"/>
<kind value="resource"/> <kind value="resource"/>
<abstract value="false"/> <abstract value="false"/>
<type value="MedicationDispense"/> <type value="MedicationDispense"/>
@ -1846,10 +1846,9 @@
<path value="MedicationDispense"/> <path value="MedicationDispense"/>
</element> </element>
<element> <element>
<path value="MedicationDispense.dosageInstruction"/> <path value="MedicationDispense.invalid"/>
</element> </element>
<element> <element>
<!-- Including this element isn't strictly necessary to reproduce the problem. However, its inclusion seemed to prevent certain errors from showing up when I trimmed the instance, so I'm leaving it in -->
<path value="MedicationDispense.dosageInstruction.extension"/> <path value="MedicationDispense.dosageInstruction.extension"/>
<slicing> <slicing>
<discriminator> <discriminator>
@ -1860,20 +1859,6 @@
</slicing> </slicing>
<mustSupport value="true"/> <mustSupport value="true"/>
</element> </element>
<element>
<path value="MedicationOrder.dosageInstruction.additionalInstruction"/>
<type>
<code value="Quantity"/>
</type>
<mustSupport value="true"/>
</element>
<element>
<path value="MedicationOrder.dosageInstruction.doseQuantity"/>
<type>
<code value="Quantity"/>
</type>
<mustSupport value="true"/>
</element>
</differential> </differential>
</StructureDefinition> </StructureDefinition>
</contained> </contained>
@ -2007,6 +1992,13 @@
<sourceId value="t1"/> <sourceId value="t1"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test1-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test1-1"/> <label value="test1-1"/>
@ -2068,6 +2060,13 @@
<sourceId value="t2"/> <sourceId value="t2"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test2-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test2-1"/> <label value="test2-1"/>
@ -2102,6 +2101,13 @@
<sourceId value="t3"/> <sourceId value="t3"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test3-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test3-1"/> <label value="test3-1"/>
@ -2145,6 +2151,13 @@
<sourceId value="t4"/> <sourceId value="t4"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test4-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test4-1"/> <label value="test4-1"/>
@ -2170,6 +2183,13 @@
<sourceId value="t5"/> <sourceId value="t5"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test5-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test5-1"/> <label value="test5-1"/>
@ -2204,6 +2224,13 @@
<sourceId value="t6"/> <sourceId value="t6"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test6-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test6-1"/> <label value="test6-1"/>
@ -2238,6 +2265,13 @@
<sourceId value="t7"/> <sourceId value="t7"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test7-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test7-1"/> <label value="test7-1"/>
@ -2263,6 +2297,13 @@
<sourceId value="t8"/> <sourceId value="t8"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test8-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test8-1"/> <label value="test8-1"/>
@ -2297,6 +2338,13 @@
<sourceId value="t9"/> <sourceId value="t9"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test9-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test9-1"/> <label value="test9-1"/>
@ -2331,6 +2379,13 @@
<sourceId value="t10"/> <sourceId value="t10"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test10-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test10-1"/> <label value="test10-1"/>
@ -2401,6 +2456,13 @@
<sourceId value="t11"/> <sourceId value="t11"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test11-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test11-1"/> <label value="test11-1"/>
@ -2480,6 +2542,13 @@
<sourceId value="t12"/> <sourceId value="t12"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test12-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test12-1"/> <label value="test12-1"/>
@ -2550,6 +2619,13 @@
<sourceId value="t12a"/> <sourceId value="t12a"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test12a-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test12a-1"/> <label value="test12a-1"/>
@ -2611,6 +2687,13 @@
<sourceId value="t13"/> <sourceId value="t13"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test13-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test13-1"/> <label value="test13-1"/>
@ -2819,6 +2902,13 @@
<sourceId value="t14"/> <sourceId value="t14"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test14-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test14-1"/> <label value="test14-1"/>
@ -2843,6 +2933,13 @@
<sourceId value="t15"/> <sourceId value="t15"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test15-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test15-1"/> <label value="test15-1"/>
@ -2867,6 +2964,13 @@
<sourceId value="t16"/> <sourceId value="t16"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test16-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test16-1"/> <label value="test16-1"/>
@ -2891,6 +2995,13 @@
<sourceId value="t17"/> <sourceId value="t17"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test17-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test17-1"/> <label value="test17-1"/>
@ -2970,6 +3081,13 @@
<sourceId value="t18"/> <sourceId value="t18"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test18-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test18-1"/> <label value="test18-1"/>
@ -3049,6 +3167,13 @@
<sourceId value="t19"/> <sourceId value="t19"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test19-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test19-1"/> <label value="test19-1"/>
@ -3110,6 +3235,13 @@
<sourceId value="t20"/> <sourceId value="t20"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test20-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test20-1"/> <label value="test20-1"/>
@ -3180,6 +3312,13 @@
<sourceId value="t21"/> <sourceId value="t21"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test21-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test21-1"/> <label value="test21-1"/>
@ -3241,6 +3380,13 @@
<sourceId value="t22"/> <sourceId value="t22"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test22-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test22-1"/> <label value="test22-1"/>
@ -3266,6 +3412,13 @@
<sourceId value="t23"/> <sourceId value="t23"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test23-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test23-1"/> <label value="test23-1"/>
@ -3302,6 +3455,13 @@
<sourceId value="t24b"/> <sourceId value="t24b"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test24-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test24-1"/> <label value="test24-1"/>
@ -3334,6 +3494,13 @@
<sourceId value="t25b"/> <sourceId value="t25b"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test25-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test25-1"/> <label value="test25-1"/>
@ -3359,6 +3526,13 @@
<sourceId value="t26"/> <sourceId value="t26"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test26-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test26-1"/> <label value="test26-1"/>
@ -3383,6 +3557,13 @@
<sourceId value="t27"/> <sourceId value="t27"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test27-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test27-1"/> <label value="test27-1"/>
@ -3418,6 +3599,13 @@
<sourceId value="t28"/> <sourceId value="t28"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test28-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test28-1"/> <label value="test28-1"/>
@ -3444,6 +3632,13 @@
<sourceId value="t29"/> <sourceId value="t29"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test29-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test29-1"/> <label value="test29-1"/>
@ -3481,7 +3676,14 @@
</action> </action>
<action> <action>
<assert> <assert>
<label value="test30"/> <label value="test30-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test30-1"/>
<description value="Snapshot doesn't result in an error'"/> <description value="Snapshot doesn't result in an error'"/>
<direction value="response"/> <direction value="response"/>
<expression value="fixture('t30bo').snapshot.element.count().trace('t30bo')>1"/> <expression value="fixture('t30bo').snapshot.element.count().trace('t30bo')>1"/>
@ -3505,6 +3707,13 @@
<sourceId value="t31"/> <sourceId value="t31"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test31-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test31"/> <label value="test31"/>
@ -3531,6 +3740,13 @@
<sourceId value="t32"/> <sourceId value="t32"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test32-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test32"/> <label value="test32"/>
@ -3557,6 +3773,13 @@
<sourceId value="t33"/> <sourceId value="t33"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test33-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test33"/> <label value="test33"/>
@ -3583,6 +3806,13 @@
<sourceId value="t34"/> <sourceId value="t34"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test34-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test34"/> <label value="test34"/>
@ -3618,6 +3848,13 @@
<sourceId value="t35"/> <sourceId value="t35"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test35-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test35"/> <label value="test35"/>
@ -3653,6 +3890,13 @@
<sourceId value="t36"/> <sourceId value="t36"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test36-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test36"/> <label value="test36"/>
@ -3665,7 +3909,7 @@
</test> </test>
<test> <test>
<name value="Test37"/> <name value="Test37"/>
<description value="Test deep nesting"/> <description value="Test bad path"/>
<action> <action>
<operation> <operation>
<type> <type>
@ -3681,11 +3925,9 @@
</action> </action>
<action> <action>
<assert> <assert>
<label value="test37"/> <label value="test37-0"/>
<description value="Snapshot includes polymorphic constrained element"/> <description value="Snapshot must not generate ok"/>
<direction value="response"/> <response value="bad"/>
<expression value="fixture('t37o').snapshot.element.where(path = 'MedicationDispense.dosageInstruction.doseQuantity').count() = 1"/>
<warningOnly value="false"/>
</assert> </assert>
</action> </action>
</test> </test>
@ -3705,6 +3947,13 @@
<sourceId value="t38"/> <sourceId value="t38"/>
</operation> </operation>
</action> </action>
<action>
<assert>
<label value="test38-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action> <action>
<assert> <assert>
<label value="test38"/> <label value="test38"/>

View File

@ -33,6 +33,7 @@ import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind; import org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r4.model.StructureDefinition.TypeDerivationRule; import org.hl7.fhir.r4.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.r4.model.TestScript; import org.hl7.fhir.r4.model.TestScript;
import org.hl7.fhir.r4.model.TestScript.AssertionResponseTypes;
import org.hl7.fhir.r4.model.TestScript.SetupActionAssertComponent; import org.hl7.fhir.r4.model.TestScript.SetupActionAssertComponent;
import org.hl7.fhir.r4.model.TestScript.SetupActionOperationComponent; import org.hl7.fhir.r4.model.TestScript.SetupActionOperationComponent;
import org.hl7.fhir.r4.model.TestScript.TestActionComponent; import org.hl7.fhir.r4.model.TestScript.TestActionComponent;
@ -167,8 +168,8 @@ public class SnapShotGenerationTests {
throw new Error("Unsupported: actions must have a label"); throw new Error("Unsupported: actions must have a label");
if (!a.hasDescription()) if (!a.hasDescription())
throw new Error("Unsupported: actions must have a description"); throw new Error("Unsupported: actions must have a description");
if (!a.hasExpression()) if (!a.hasExpression() && !a.hasResponse())
throw new Error("Unsupported: actions must have an expression"); throw new Error("Unsupported: actions must have an expression or a response");
} else { } else {
throw new Error("Unsupported: Unrecognized action type"); throw new Error("Unsupported: Unrecognized action type");
} }
@ -323,9 +324,12 @@ public class SnapShotGenerationTests {
resolveFixtures(); resolveFixtures();
TestScript.AssertionResponseTypes lastOpOutcome = null;
for (int i = 0; i < test.getAction().size(); i++) { for (int i = 0; i < test.getAction().size(); i++) {
TestActionComponent action = test.getAction().get(i); TestActionComponent action = test.getAction().get(i);
if (action.hasOperation()) { if (action.hasOperation()) {
lastOpOutcome = AssertionResponseTypes.OKAY;
try {
SetupActionOperationComponent op = action.getOperation(); SetupActionOperationComponent op = action.getOperation();
Coding opType = op.getType(); Coding opType = op.getType();
if (opType.getSystem().equals("http://hl7.org/fhir/testscript-operation-codes") && opType.getCode().equals("snapshot")) { if (opType.getSystem().equals("http://hl7.org/fhir/testscript-operation-codes") && opType.getCode().equals("snapshot")) {
@ -349,7 +353,6 @@ public class SnapShotGenerationTests {
if (output.getDifferential().hasElement()) if (output.getDifferential().hasElement())
new NarrativeGenerator("", "http://hl7.org/fhir", TestingUtilities.context()).setPkp(new TestPKP()).generate(output, null); new NarrativeGenerator("", "http://hl7.org/fhir", TestingUtilities.context()).setPkp(new TestPKP()).generate(output, null);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(System.getProperty("java.io.tmpdir"), op.getResponseId()+"-d.xml")), output); new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(System.getProperty("java.io.tmpdir"), op.getResponseId()+"-d.xml")), output);
} else if (opType.getSystem().equals("http://hl7.org/fhir/testscript-operation-codes") && opType.getCode().equals("sortDifferential")) { } else if (opType.getSystem().equals("http://hl7.org/fhir/testscript-operation-codes") && opType.getCode().equals("sortDifferential")) {
StructureDefinition source = (StructureDefinition) context.fetchFixture(op.getSourceId()); StructureDefinition source = (StructureDefinition) context.fetchFixture(op.getSourceId());
StructureDefinition base = getSD(source.getBaseDefinition()); StructureDefinition base = getSD(source.getBaseDefinition());
@ -368,12 +371,21 @@ public class SnapShotGenerationTests {
} else { } else {
throw new Error("Unsupported operation: " + opType.getSystem() + " : " + opType.getCode()); throw new Error("Unsupported operation: " + opType.getSystem() + " : " + opType.getCode());
} }
} catch (Exception e) {
lastOpOutcome = AssertionResponseTypes.BAD;
}
} else if (action.hasAssert()) { } else if (action.hasAssert()) {
SetupActionAssertComponent a = action.getAssert(); SetupActionAssertComponent a = action.getAssert();
if (a.getResponse() != null) {
Assert.assertTrue(a.getLabel()+" (response): "+a.getDescription(), a.getResponse() == lastOpOutcome);
}
if (a.hasExpression()) {
boolean ok = fp.evaluateToBoolean(new StructureDefinition(), new StructureDefinition(), a.getExpression()); boolean ok = fp.evaluateToBoolean(new StructureDefinition(), new StructureDefinition(), a.getExpression());
Assert.assertTrue(a.getLabel()+": "+a.getDescription(), ok); Assert.assertTrue(a.getLabel()+": "+a.getDescription(), ok);
} }
} }
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new FHIRException(e); throw new FHIRException(e);