diff --git a/org.hl7.fhir.r4/src/main/resources/snapshot-generation-tests.xml b/org.hl7.fhir.r4/src/main/resources/snapshot-generation-tests.xml
index bc8e7c497..9b16b0b71 100644
--- a/org.hl7.fhir.r4/src/main/resources/snapshot-generation-tests.xml
+++ b/org.hl7.fhir.r4/src/main/resources/snapshot-generation-tests.xml
@@ -3666,10 +3666,10 @@
-
-
+
+
-
+
diff --git a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/SnapShotGenerationTests.java b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/SnapShotGenerationTests.java
index 86952aa2c..7d3bb53a5 100644
--- a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/SnapShotGenerationTests.java
+++ b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/SnapShotGenerationTests.java
@@ -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 errors = new ArrayList();
- 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 errors = new ArrayList();
- 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 errors = new ArrayList();
+ 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 errors = new ArrayList();
+ 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) {