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
35. Referencing a profiled custom extension
36. Deep recursion
37. Constrained polymorphic elements
37. Test Bad Path
38. Deep nesting
-->
<contained>
@ -1832,10 +1832,10 @@
<contained>
<StructureDefinition>
<id value="t37"/>
<url value="urn:uuid:2918bbbf-2145-4c13-822e-7dfd758694ec"/>
<name value="t38"/>
<url value="urn:uuid:44a92f3e-3681-4dbc-baa2-48a07e2765ca"/>
<name value="t37"/>
<status value="draft"/>
<description value="fixture for #38: Constrained polymporphic elements"/>
<description value="fixture for #37: Test bad Path"/>
<kind value="resource"/>
<abstract value="false"/>
<type value="MedicationDispense"/>
@ -1846,10 +1846,9 @@
<path value="MedicationDispense"/>
</element>
<element>
<path value="MedicationDispense.dosageInstruction"/>
<path value="MedicationDispense.invalid"/>
</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"/>
<slicing>
<discriminator>
@ -1860,20 +1859,6 @@
</slicing>
<mustSupport value="true"/>
</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>
</StructureDefinition>
</contained>
@ -2007,6 +1992,13 @@
<sourceId value="t1"/>
</operation>
</action>
<action>
<assert>
<label value="test1-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test1-1"/>
@ -2068,6 +2060,13 @@
<sourceId value="t2"/>
</operation>
</action>
<action>
<assert>
<label value="test2-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test2-1"/>
@ -2102,6 +2101,13 @@
<sourceId value="t3"/>
</operation>
</action>
<action>
<assert>
<label value="test3-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test3-1"/>
@ -2145,6 +2151,13 @@
<sourceId value="t4"/>
</operation>
</action>
<action>
<assert>
<label value="test4-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test4-1"/>
@ -2170,6 +2183,13 @@
<sourceId value="t5"/>
</operation>
</action>
<action>
<assert>
<label value="test5-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test5-1"/>
@ -2204,6 +2224,13 @@
<sourceId value="t6"/>
</operation>
</action>
<action>
<assert>
<label value="test6-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test6-1"/>
@ -2238,6 +2265,13 @@
<sourceId value="t7"/>
</operation>
</action>
<action>
<assert>
<label value="test7-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test7-1"/>
@ -2263,6 +2297,13 @@
<sourceId value="t8"/>
</operation>
</action>
<action>
<assert>
<label value="test8-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test8-1"/>
@ -2297,6 +2338,13 @@
<sourceId value="t9"/>
</operation>
</action>
<action>
<assert>
<label value="test9-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test9-1"/>
@ -2331,6 +2379,13 @@
<sourceId value="t10"/>
</operation>
</action>
<action>
<assert>
<label value="test10-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test10-1"/>
@ -2401,6 +2456,13 @@
<sourceId value="t11"/>
</operation>
</action>
<action>
<assert>
<label value="test11-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test11-1"/>
@ -2480,6 +2542,13 @@
<sourceId value="t12"/>
</operation>
</action>
<action>
<assert>
<label value="test12-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test12-1"/>
@ -2550,6 +2619,13 @@
<sourceId value="t12a"/>
</operation>
</action>
<action>
<assert>
<label value="test12a-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test12a-1"/>
@ -2611,6 +2687,13 @@
<sourceId value="t13"/>
</operation>
</action>
<action>
<assert>
<label value="test13-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test13-1"/>
@ -2819,6 +2902,13 @@
<sourceId value="t14"/>
</operation>
</action>
<action>
<assert>
<label value="test14-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test14-1"/>
@ -2843,6 +2933,13 @@
<sourceId value="t15"/>
</operation>
</action>
<action>
<assert>
<label value="test15-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test15-1"/>
@ -2867,6 +2964,13 @@
<sourceId value="t16"/>
</operation>
</action>
<action>
<assert>
<label value="test16-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test16-1"/>
@ -2891,6 +2995,13 @@
<sourceId value="t17"/>
</operation>
</action>
<action>
<assert>
<label value="test17-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test17-1"/>
@ -2970,6 +3081,13 @@
<sourceId value="t18"/>
</operation>
</action>
<action>
<assert>
<label value="test18-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test18-1"/>
@ -3049,6 +3167,13 @@
<sourceId value="t19"/>
</operation>
</action>
<action>
<assert>
<label value="test19-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test19-1"/>
@ -3110,6 +3235,13 @@
<sourceId value="t20"/>
</operation>
</action>
<action>
<assert>
<label value="test20-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test20-1"/>
@ -3180,6 +3312,13 @@
<sourceId value="t21"/>
</operation>
</action>
<action>
<assert>
<label value="test21-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test21-1"/>
@ -3241,6 +3380,13 @@
<sourceId value="t22"/>
</operation>
</action>
<action>
<assert>
<label value="test22-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test22-1"/>
@ -3266,6 +3412,13 @@
<sourceId value="t23"/>
</operation>
</action>
<action>
<assert>
<label value="test23-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test23-1"/>
@ -3302,6 +3455,13 @@
<sourceId value="t24b"/>
</operation>
</action>
<action>
<assert>
<label value="test24-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test24-1"/>
@ -3334,6 +3494,13 @@
<sourceId value="t25b"/>
</operation>
</action>
<action>
<assert>
<label value="test25-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test25-1"/>
@ -3359,6 +3526,13 @@
<sourceId value="t26"/>
</operation>
</action>
<action>
<assert>
<label value="test26-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test26-1"/>
@ -3383,6 +3557,13 @@
<sourceId value="t27"/>
</operation>
</action>
<action>
<assert>
<label value="test27-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test27-1"/>
@ -3418,6 +3599,13 @@
<sourceId value="t28"/>
</operation>
</action>
<action>
<assert>
<label value="test28-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test28-1"/>
@ -3444,6 +3632,13 @@
<sourceId value="t29"/>
</operation>
</action>
<action>
<assert>
<label value="test29-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test29-1"/>
@ -3481,7 +3676,14 @@
</action>
<action>
<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'"/>
<direction value="response"/>
<expression value="fixture('t30bo').snapshot.element.count().trace('t30bo')>1"/>
@ -3505,6 +3707,13 @@
<sourceId value="t31"/>
</operation>
</action>
<action>
<assert>
<label value="test31-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test31"/>
@ -3531,6 +3740,13 @@
<sourceId value="t32"/>
</operation>
</action>
<action>
<assert>
<label value="test32-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test32"/>
@ -3557,6 +3773,13 @@
<sourceId value="t33"/>
</operation>
</action>
<action>
<assert>
<label value="test33-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test33"/>
@ -3583,6 +3806,13 @@
<sourceId value="t34"/>
</operation>
</action>
<action>
<assert>
<label value="test34-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test34"/>
@ -3618,6 +3848,13 @@
<sourceId value="t35"/>
</operation>
</action>
<action>
<assert>
<label value="test35-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test35"/>
@ -3653,6 +3890,13 @@
<sourceId value="t36"/>
</operation>
</action>
<action>
<assert>
<label value="test36-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<label value="test36"/>
@ -3665,7 +3909,7 @@
</test>
<test>
<name value="Test37"/>
<description value="Test deep nesting"/>
<description value="Test bad path"/>
<action>
<operation>
<type>
@ -3681,11 +3925,9 @@
</action>
<action>
<assert>
<label value="test37"/>
<description value="Snapshot includes polymorphic constrained element"/>
<direction value="response"/>
<expression value="fixture('t37o').snapshot.element.where(path = 'MedicationDispense.dosageInstruction.doseQuantity').count() = 1"/>
<warningOnly value="false"/>
<label value="test37-0"/>
<description value="Snapshot must not generate ok"/>
<response value="bad"/>
</assert>
</action>
</test>
@ -3705,6 +3947,13 @@
<sourceId value="t38"/>
</operation>
</action>
<action>
<assert>
<label value="test38-0"/>
<description value="Snapshot must generate ok"/>
<response value="okay"/>
</assert>
</action>
<action>
<assert>
<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.TypeDerivationRule;
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.SetupActionOperationComponent;
import org.hl7.fhir.r4.model.TestScript.TestActionComponent;
@ -167,8 +168,8 @@ public class SnapShotGenerationTests {
throw new Error("Unsupported: actions must have a label");
if (!a.hasDescription())
throw new Error("Unsupported: actions must have a description");
if (!a.hasExpression())
throw new Error("Unsupported: actions must have an expression");
if (!a.hasExpression() && !a.hasResponse())
throw new Error("Unsupported: actions must have an expression or a response");
} else {
throw new Error("Unsupported: Unrecognized action type");
}
@ -323,33 +324,35 @@ public class SnapShotGenerationTests {
resolveFixtures();
TestScript.AssertionResponseTypes lastOpOutcome = null;
for (int i = 0; i < test.getAction().size(); i++) {
TestActionComponent action = test.getAction().get(i);
if (action.hasOperation()) {
SetupActionOperationComponent op = action.getOperation();
Coding opType = op.getType();
if (opType.getSystem().equals("http://hl7.org/fhir/testscript-operation-codes") && opType.getCode().equals("snapshot")) {
StructureDefinition source = (StructureDefinition) context.fetchFixture(op.getSourceId());
StructureDefinition base = getSD(source.getBaseDefinition());
StructureDefinition output = source.copy();
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), null, new TestPKP());
pu.setIds(source, false);
if ("sort=true".equals(op.getParams())) {
List<String> errors = new ArrayList<String>();
pu.sortDifferential(base, output, source.getName(), errors);
if (errors.size() > 0)
throw new FHIRException("Sort failed: "+errors.toString());
}
pu.generateSnapshot(base, output, source.getUrl(), source.getName());
debugSaveResource(output);
context.fixtures.put(op.getResponseId(), output);
context.snapshots.put(output.getUrl(), output);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(System.getProperty("java.io.tmpdir"), op.getResponseId()+".xml")), output);
if (output.getDifferential().hasElement())
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);
lastOpOutcome = AssertionResponseTypes.OKAY;
try {
SetupActionOperationComponent op = action.getOperation();
Coding opType = op.getType();
if (opType.getSystem().equals("http://hl7.org/fhir/testscript-operation-codes") && opType.getCode().equals("snapshot")) {
StructureDefinition source = (StructureDefinition) context.fetchFixture(op.getSourceId());
StructureDefinition base = getSD(source.getBaseDefinition());
StructureDefinition output = source.copy();
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), null, new TestPKP());
pu.setIds(source, false);
if ("sort=true".equals(op.getParams())) {
List<String> errors = new ArrayList<String>();
pu.sortDifferential(base, output, source.getName(), errors);
if (errors.size() > 0)
throw new FHIRException("Sort failed: "+errors.toString());
}
pu.generateSnapshot(base, output, source.getUrl(), source.getName());
debugSaveResource(output);
context.fixtures.put(op.getResponseId(), output);
context.snapshots.put(output.getUrl(), output);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(System.getProperty("java.io.tmpdir"), op.getResponseId()+".xml")), output);
if (output.getDifferential().hasElement())
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);
} else if (opType.getSystem().equals("http://hl7.org/fhir/testscript-operation-codes") && opType.getCode().equals("sortDifferential")) {
StructureDefinition source = (StructureDefinition) context.fetchFixture(op.getSourceId());
StructureDefinition base = getSD(source.getBaseDefinition());
@ -368,10 +371,19 @@ public class SnapShotGenerationTests {
} else {
throw new Error("Unsupported operation: " + opType.getSystem() + " : " + opType.getCode());
}
} catch (Exception e) {
lastOpOutcome = AssertionResponseTypes.BAD;
}
} else if (action.hasAssert()) {
SetupActionAssertComponent a = action.getAssert();
boolean ok = fp.evaluateToBoolean(new StructureDefinition(), new StructureDefinition(), a.getExpression());
Assert.assertTrue(a.getLabel()+": "+a.getDescription(), ok);
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());
Assert.assertTrue(a.getLabel()+": "+a.getDescription(), ok);
}
}
}
} catch (Exception e) {