Merge pull request #1303 from hapifhir/gg-202206-tx-extensions
Fix up terminology tests to ignore irrelevant extensions
This commit is contained in:
commit
d8309796ca
|
@ -0,0 +1,45 @@
|
|||
package org.hl7.fhir.r5.utils;
|
||||
|
||||
import org.hl7.fhir.r5.model.Base;
|
||||
import org.hl7.fhir.r5.model.Element;
|
||||
import org.hl7.fhir.r5.model.Property;
|
||||
import org.hl7.fhir.r5.model.Resource;
|
||||
|
||||
public class ElementVisitor {
|
||||
|
||||
public interface IElementVisitor {
|
||||
public void visit(Resource resource);
|
||||
public void visit(Element element);
|
||||
}
|
||||
|
||||
private IElementVisitor visitor;
|
||||
|
||||
public ElementVisitor(IElementVisitor visitor) {
|
||||
this.visitor = visitor;
|
||||
}
|
||||
|
||||
private void visitBase(Base base) {
|
||||
for (Property p : base.children()) {
|
||||
if (p.hasValues()) {
|
||||
for (Base b : p.getValues()) {
|
||||
if (b instanceof Resource) {
|
||||
visit((Resource) b);
|
||||
} else {
|
||||
visit((Element) b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void visit(Resource res) {
|
||||
visitor.visit(res);
|
||||
visitBase(res);
|
||||
}
|
||||
|
||||
public void visit(Element e) {
|
||||
visitor.visit(e);
|
||||
visitBase(e);
|
||||
}
|
||||
|
||||
}
|
|
@ -224,7 +224,7 @@ public class ValidatorCli {
|
|||
final String version = Params.getParam(args, Params.VERSION);
|
||||
final String tx = Params.getParam(args, Params.TERMINOLOGY);
|
||||
final String filter = Params.getParam(args, Params.FILTER);
|
||||
boolean ok = new TxTester(new InternalTxLoader(source, output), tx).setOutput(output).execute(version, filter);
|
||||
boolean ok = new TxTester(new InternalTxLoader(source, output), tx, false).setOutput(output).execute(version, filter);
|
||||
System.exit(ok ? 1 : 0);
|
||||
} else {
|
||||
final String testModuleParam = Params.getParam(args, Params.TEST_MODULES);
|
||||
|
|
|
@ -58,16 +58,18 @@ public class TxTester {
|
|||
private String error;
|
||||
private String output;
|
||||
private ITerminologyClient tx;
|
||||
private boolean tight;
|
||||
|
||||
|
||||
public TxTester(ITxTesterLoader loader, String server) {
|
||||
public TxTester(ITxTesterLoader loader, String server, boolean tight) {
|
||||
super();
|
||||
this.server = server;
|
||||
this.loader = loader;
|
||||
this.tight = tight;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new TxTester(new InternalTxLoader(args[0]), args[1]).execute(args[2], args[3]);
|
||||
new TxTester(new InternalTxLoader(args[0]), args[1], "true".equals(args[2])).execute(args[2], args[3]);
|
||||
}
|
||||
|
||||
public boolean execute(String version, String filter) throws IOException, URISyntaxException {
|
||||
|
@ -239,12 +241,12 @@ public class TxTester {
|
|||
String vsj;
|
||||
try {
|
||||
ValueSet vs = tx.expandValueset(null, p, null);
|
||||
TxTesterScrubbers.scrub(vs);
|
||||
TxTesterScrubbers.scrubVS(vs, tight);
|
||||
TxTesterSorters.sortValueSet(vs);
|
||||
vsj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(vs);
|
||||
} catch (EFhirClientException e) {
|
||||
OperationOutcome oo = e.getServerErrors().get(0);
|
||||
TxTesterScrubbers.scrub(oo);
|
||||
TxTesterScrubbers.scrubOO(oo, tight);
|
||||
vsj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(oo);
|
||||
}
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(resp, vsj);
|
||||
|
@ -263,7 +265,7 @@ public class TxTester {
|
|||
String pj;
|
||||
try {
|
||||
Parameters po = tx.validateVS(p);
|
||||
TxTesterScrubbers.scrub(po);
|
||||
TxTesterScrubbers.scrubParams(po);
|
||||
TxTesterSorters.sortParameters(po);
|
||||
pj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(po);
|
||||
} catch (EFhirClientException e) {
|
||||
|
|
|
@ -1,20 +1,85 @@
|
|||
package org.hl7.fhir.validation.special;
|
||||
|
||||
import org.hl7.fhir.r5.model.DomainResource;
|
||||
import org.hl7.fhir.r5.model.Element;
|
||||
import org.hl7.fhir.r5.model.Extension;
|
||||
import org.hl7.fhir.r5.model.OperationOutcome;
|
||||
import org.hl7.fhir.r5.model.Parameters;
|
||||
import org.hl7.fhir.r5.model.Resource;
|
||||
import org.hl7.fhir.r5.model.ValueSet;
|
||||
import org.hl7.fhir.r5.utils.ElementVisitor;
|
||||
import org.hl7.fhir.r5.utils.ElementVisitor.IElementVisitor;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
|
||||
public class TxTesterScrubbers {
|
||||
|
||||
public static void scrub(DomainResource dr) {
|
||||
dr.setText(null);
|
||||
dr.setMeta(null);
|
||||
|
||||
public static class TxTesterScrubberVisitor implements IElementVisitor {
|
||||
|
||||
private boolean tight;
|
||||
|
||||
protected TxTesterScrubberVisitor(boolean tight) {
|
||||
super();
|
||||
this.tight = tight;
|
||||
}
|
||||
|
||||
private boolean isManagedExtension(Extension extension) {
|
||||
return !tight || !Utilities.isAbsoluteUrl(extension.getUrl()) || Utilities.existsInList(extension.getUrl(),
|
||||
"http://hl7.org/fhir/StructureDefinition/codesystem-alternate",
|
||||
"http://hl7.org/fhir/StructureDefinition/codesystem-conceptOrder",
|
||||
"http://hl7.org/fhir/StructureDefinition/codesystem-label",
|
||||
"http://hl7.org/fhir/StructureDefinition/coding-sctdescid",
|
||||
"http://hl7.org/fhir/StructureDefinition/itemWeight",
|
||||
"http://hl7.org/fhir/StructureDefinition/rendering-style",
|
||||
"http://hl7.org/fhir/StructureDefinition/rendering-xhtml",
|
||||
"http://hl7.org/fhir/StructureDefinition/translation",
|
||||
"http://hl7.org/fhir/StructureDefinition/valueset-concept-definition",
|
||||
"http://hl7.org/fhir/StructureDefinition/valueset-conceptOrder",
|
||||
"http://hl7.org/fhir/StructureDefinition/valueset-deprecated",
|
||||
"http://hl7.org/fhir/StructureDefinition/valueset-label",
|
||||
"http://hl7.org/fhir/StructureDefinition/valueset-supplement",
|
||||
"http://hl7.org/fhir/test/CodeSystem/de-multi",
|
||||
"http://hl7.org/fhir/test/CodeSystem/en-multi",
|
||||
"http://hl7.org/fhir/test/StructureDefinition/unknown-extension-1",
|
||||
"http://hl7.org/fhir/test/StructureDefinition/unknown-extension-3",
|
||||
"http://hl7.org/fhir/test/StructureDefinition/unknown-extension-4",
|
||||
"http://hl7.org/fhir/test/StructureDefinition/unknown-extension-5",
|
||||
"http://hl7.org/fhir/test/ValueSet/extensions-bad-supplement",
|
||||
"http://hl7.org/fhir/test/ValueSet/simple-all",
|
||||
"http://hl7.org/fhir/test/ValueSet/simple-enumerated",
|
||||
"http://hl7.org/fhir/test/ValueSet/simple-filter-isa");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Resource resource) {
|
||||
if (resource instanceof DomainResource) {
|
||||
DomainResource dr = (DomainResource) resource;
|
||||
dr.getExtension().removeIf(ext -> !isManagedExtension(ext));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Element element) {
|
||||
element.getExtension().removeIf(ext -> !isManagedExtension(ext));
|
||||
}
|
||||
}
|
||||
|
||||
public static void scrub(Parameters po) {
|
||||
po.setMeta(null);
|
||||
public static void scrubDR(DomainResource dr, boolean tight) {
|
||||
dr.setText(null);
|
||||
dr.setMeta(null);
|
||||
new ElementVisitor(new TxTesterScrubberVisitor(tight)).visit(dr);
|
||||
}
|
||||
|
||||
public static void scrubVS(ValueSet vs, boolean tight) {
|
||||
scrubDR(vs, tight);
|
||||
}
|
||||
|
||||
public static void scrubParams(Parameters po) {
|
||||
po.setMeta(null);
|
||||
}
|
||||
|
||||
public static void scrubOO(OperationOutcome po, boolean tight) {
|
||||
scrubDR(po, tight);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ public class ExternalTerminologyServiceTests implements ITxTesterLoader {
|
|||
public void test() throws Exception {
|
||||
if (SERVER != null) {
|
||||
if (tester == null) {
|
||||
tester = new TxTester(this, SERVER);
|
||||
tester = new TxTester(this, SERVER, true);
|
||||
}
|
||||
String err = tester.executeTest(setup.suite, setup.test);
|
||||
Assertions.assertTrue(err == null, err);
|
||||
|
|
|
@ -161,7 +161,7 @@ public class TerminologyServiceTests {
|
|||
removeParameter(vse.getValueset(), "excludeNested");
|
||||
}
|
||||
TxTesterSorters.sortValueSet(vse.getValueset());
|
||||
TxTesterScrubbers.scrub(vse.getValueset());
|
||||
TxTesterScrubbers.scrubVS(vse.getValueset(), false);
|
||||
String vsj = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(vse.getValueset());
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(resp, vsj);
|
||||
if (diff != null) {
|
||||
|
@ -205,7 +205,7 @@ public class TerminologyServiceTests {
|
|||
}
|
||||
e.getDetails().setText(vse.getError());
|
||||
oo.addIssue(e);
|
||||
TxTesterScrubbers.scrub(oo);
|
||||
TxTesterScrubbers.scrubOO(oo, false);
|
||||
|
||||
String ooj = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(oo);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(resp, ooj);
|
||||
|
@ -291,7 +291,7 @@ public class TerminologyServiceTests {
|
|||
res.addParameter().setName("issues").setResource(oo);
|
||||
}
|
||||
TxTesterSorters.sortParameters(res);
|
||||
TxTesterScrubbers.scrub(res);
|
||||
TxTesterScrubbers.scrubParams(res);
|
||||
|
||||
String pj = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(res);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(resp, pj);
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -19,7 +19,7 @@
|
|||
|
||||
<properties>
|
||||
<hapi_fhir_version>6.4.1</hapi_fhir_version>
|
||||
<validator_test_case_version>1.3.9</validator_test_case_version>
|
||||
<validator_test_case_version>1.3.10-SNAPSHOT</validator_test_case_version>
|
||||
<jackson_version>2.14.0</jackson_version>
|
||||
<junit_jupiter_version>5.9.2</junit_jupiter_version>
|
||||
<junit_platform_launcher_version>1.8.2</junit_platform_launcher_version>
|
||||
|
|
Loading…
Reference in New Issue