Updated code to support tests that blow up
This commit is contained in:
parent
8eedf12955
commit
13d22dfcd1
|
@ -3666,10 +3666,10 @@
|
|||
</action>
|
||||
<action>
|
||||
<assert>
|
||||
<label value="test37"/>
|
||||
<description value="Snapshot missing polymorphic constrained element from differential"/>
|
||||
<label value="test37-0"/>
|
||||
<description value="Snapshot must not generate ok"/>
|
||||
<direction value="response"/>
|
||||
<expression value="fixture('t37o').snapshot.element.where(path = 'MedicationRequest.dosageInstruction.timing.repeat').mustSupport"/>
|
||||
<response value="bad"/>
|
||||
<warningOnly value="false"/>
|
||||
</assert>
|
||||
</action>
|
||||
|
|
|
@ -167,8 +167,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() && a.getResponse().equals(TestScript.AssertionResponseTypes.BAD)))
|
||||
throw new Error("Unsupported: actions must have an expression or a response type of 'bad'");
|
||||
} else {
|
||||
throw new Error("Unsupported: Unrecognized action type");
|
||||
}
|
||||
|
@ -325,53 +325,72 @@ public class SnapShotGenerationTests {
|
|||
|
||||
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);
|
||||
|
||||
} 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());
|
||||
StructureDefinition output = source.copy();
|
||||
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), null, null);
|
||||
pu.setIds(source, false);
|
||||
List<String> errors = new ArrayList<String>();
|
||||
pu.sortDifferential(base, output, output.getUrl(), errors);
|
||||
if (!errors.isEmpty())
|
||||
throw new FHIRException(errors.get(0));
|
||||
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);
|
||||
try {
|
||||
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);
|
||||
|
||||
} else {
|
||||
throw new Error("Unsupported operation: " + opType.getSystem() + " : " + opType.getCode());
|
||||
} 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());
|
||||
StructureDefinition output = source.copy();
|
||||
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), null, null);
|
||||
pu.setIds(source, false);
|
||||
List<String> errors = new ArrayList<String>();
|
||||
pu.sortDifferential(base, output, output.getUrl(), errors);
|
||||
if (!errors.isEmpty())
|
||||
throw new FHIRException(errors.get(0));
|
||||
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);
|
||||
|
||||
} else {
|
||||
throw new Error("Unsupported operation: " + opType.getSystem() + " : " + opType.getCode());
|
||||
}
|
||||
} else if (action.hasAssert()) {
|
||||
SetupActionAssertComponent a = action.getAssert();
|
||||
if (a.hasResponse() && a.getResponse().equals(TestScript.AssertionResponseTypes.BAD))
|
||||
Assert.fail(action.getAssert().getLabel()+": "+action.getAssert().getDescription());
|
||||
else {
|
||||
boolean ok = fp.evaluateToBoolean(new StructureDefinition(), new StructureDefinition(), a.getExpression());
|
||||
Assert.assertTrue(a.getLabel()+": "+a.getDescription(), ok);
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
} catch (Exception e) {
|
||||
boolean ok = false;
|
||||
for (int j = i+1;i < test.getAction().size(); i++) {
|
||||
TestActionComponent followAction = test.getAction().get(j);
|
||||
if (followAction.hasAssert() && followAction.getAssert().hasResponse() && followAction.getAssert().getResponse().equals(TestScript.AssertionResponseTypes.BAD)) {
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ok)
|
||||
throw e;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
Loading…
Reference in New Issue