update test cases for various issues encountered and fixed

This commit is contained in:
Grahame Grieve 2023-05-22 17:17:17 +10:00
parent 073e89d98d
commit 7da282b5d7
9 changed files with 47 additions and 20 deletions

View File

@ -100,7 +100,7 @@ public interface IResourceValidator {
void setNoUnicodeBiDiControlChars(boolean noUnicodeBiDiControlChars);
boolean isForPublication();
void setForPublication(boolean forPublication);
IResourceValidator setForPublication(boolean forPublication);
/**
* Whether being unable to resolve a profile in found in Resource.meta.profile or ElementDefinition.type.profile or targetProfile is an error or just a warning

View File

@ -585,8 +585,8 @@ public class SnapShotGenerationTests {
boolean structureDefinitionEquality = t1.equalsDeep(t2);
if (!structureDefinitionEquality) {
System.out.println("Encountered unexpected diff in structure definition");
DiffUtils.testDiff(dst.getAbsolutePath(), actualFilePath);
System.out.println("Encountered unexpected change in diff in structure definition");
// DiffUtils.testDiff(dst.getAbsolutePath(), actualFilePath);
}
Assertions.assertTrue(structureDefinitionEquality, "Output does not match expected");
}

View File

@ -590,7 +590,7 @@ public class Utilities {
public static boolean isPlural(String word) {
word = word.toLowerCase();
if ("restricts".equals(word) || "contains".equals(word) || "data".equals(word) || "specimen".equals(word) || "replaces".equals(word) || "addresses".equals(word)
|| "supplementalData".equals(word) || "instantiates".equals(word) || "imports".equals(word))
|| "supplementalData".equals(word) || "instantiates".equals(word) || "imports".equals(word) || "covers".equals(word))
return false;
Inflector inf = new Inflector();
return !inf.singularize(word).equals(word);
@ -1966,4 +1966,8 @@ public class Utilities {
return Utilities.startsWithInList(s.replace("https://", "http://"), FhirSettings.getTxFhirProduction(), FhirSettings.getTxFhirDevelopment(), FhirSettings.getTxFhirLocal());
}
public static String[] splitLines(String txt) {
return txt.split("\\r?\\n|\\r");
}
}

View File

@ -866,6 +866,9 @@ public class I18nConstants {
public static final String SD_NO_CONTEXT_INV_WHEN_NOT_EXTENSION = "SD_NO_CONTEXT_INV_WHEN_NOT_EXTENSION";
public static final String SM_TARGET_TRANSFORM_OP_UNKNOWN_SOURCE = "SM_TARGET_TRANSFORM_OP_UNKNOWN_SOURCE";
public static final String SM_TARGET_TRANSFORM_OP_INVALID_TYPE = "SM_TARGET_TRANSFORM_OP_INVALID_TYPE";
public static final String ED_PATH_WRONG_TYPE_MATCH = "ED_PATH_WRONG_TYPE_MATCH";
public static final String ATTEMPT_TO_CHANGE_SLICING = "ATTEMPT_TO_CHANGE_SLICING";
public static final String REPEAT_SLICING_IGNORED = "REPEAT_SLICING_IGNORED";
}

View File

@ -672,7 +672,7 @@ RENDER_BUNDLE_DOCUMENT_CONTENT = Additional Document Content
RENDER_BUNDLE_HEADER_DOC_ENTRY_URD = {0}. {1} ({2}/{3})
RENDER_BUNDLE_HEADER_DOC_ENTRY_U = {0}. {1}
RENDER_BUNDLE_HEADER_DOC_ENTRY_RD = {0}. {2}/{3}
UNABLE_TO_CHECK_IF_THE_PROVIDED_CODES_ARE_IN_THE_VALUE_SET_ = Unable to determine whether the provided codes {1} are in the value set {0} because the value set or a code system it depends on is not known to the validator
UNABLE_TO_CHECK_IF_THE_PROVIDED_CODES_ARE_IN_THE_VALUE_SET_ = Unable to check whether the code is in the value set {0}
TERMINOLOGY_TX_SYSTEM_WRONG_HTML = The code system reference {0} is wrong - the code system reference cannot be to an HTML page. This may be the correct reference: {1}
TERMINOLOGY_TX_SYSTEM_WRONG_BUILD = The code system reference {0} is wrong - the code system reference cannot be a reference to build.fhir.org. This may be the correct reference: {1}
FHIRPATH_BAD_DATE = Unable to parse Date {0}
@ -920,6 +920,7 @@ NO_VALID_DISPLAY_FOUND_other = No valid Display Names found for {1}#{2} in the l
SD_NO_CONTEXT_WHEN_NOT_EXTENSION = The type is {0} so an extension context should not be specified
SD_NO_CONTEXT_INV_WHEN_NOT_EXTENSION = The type is {0} so an extension context invariants should not be specified
SD_CONTEXT_SHOULD_NOT_BE_ELEMENT = Review the extension type: extensions should not have a context of {0} unless it''s really intended that they can be used anywhere
ED_PATH_WRONG_TYPE_MATCH = The path must be ''{0}'' not ''{1}'' when the type list is not constrained
ATTEMPT_TO_CHANGE_SLICING = The element at {0} defines the slicing {1} but then an element in the slicing {2} tries to redefine the slicing to {3}
REPEAT_SLICING_IGNORED = The element at {0} defines the slicing but then an element in the slicing {2} repeats it, which is ignored

View File

@ -156,6 +156,7 @@ public class BaseValidator implements IValidationContextResourceLoader {
private ValidationLevel level = ValidationLevel.HINTS;
protected Coding jurisdiction;
protected boolean allowExamples;
protected boolean forPublication;
public BaseValidator(IWorkerContext context, XVerExtensionManager xverManager) {
super();
@ -1242,7 +1243,16 @@ public class BaseValidator implements IValidationContextResourceLoader {
}
protected boolean isExampleUrl(String url) {
return Utilities.containsInList(url, "example.org", "acme.com", "acme.org");
return Utilities.containsInList(url, "example.org", "acme.com", "acme.org");
}
public boolean isForPublication() {
return forPublication;
}
public BaseValidator setForPublication(boolean forPublication) {
this.forPublication = forPublication;
return this;
}
}

View File

@ -175,19 +175,19 @@ public class SnapShotGenerationXTests {
}
public void load(String version) throws FHIRFormatError, FileNotFoundException, IOException {
if (UtilitiesXTests.findTestResource("rX", "snapshot-generation", id + "-input.json"))
source = (StructureDefinition) XVersionLoader.loadJson(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-input.json"));
if (TestingUtilities.findTestResource("rX", "snapshot-generation", id + "-input.json"))
source = (StructureDefinition) XVersionLoader.loadJson(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", id + "-input.json"));
else
source = (StructureDefinition) XVersionLoader.loadXml(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-input.xml"));
source = (StructureDefinition) XVersionLoader.loadXml(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", id + "-input.xml"));
if (!fail)
expected = (StructureDefinition) XVersionLoader.loadXml(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-expected.xml"));
expected = (StructureDefinition) XVersionLoader.loadXml(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", id + "-expected.xml"));
if (!Utilities.noString(include))
included = (StructureDefinition) XVersionLoader.loadXml(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", include + ".xml"));
included = (StructureDefinition) XVersionLoader.loadXml(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", include + ".xml"));
if (!Utilities.noString(register)) {
if (UtilitiesXTests.findTestResource("rX", "snapshot-generation", register + ".xml")) {
included = (StructureDefinition) XVersionLoader.loadXml(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", register + ".xml"));
if (TestingUtilities.findTestResource("rX", "snapshot-generation", register + ".xml")) {
included = (StructureDefinition) XVersionLoader.loadXml(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", register + ".xml"));
} else {
included = (StructureDefinition) XVersionLoader.loadJson(version, UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", register + ".json"));
included = (StructureDefinition) XVersionLoader.loadJson(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", register + ".json"));
}
}
}
@ -404,7 +404,7 @@ public class SnapShotGenerationXTests {
public static Iterable<Object[]> data() throws ParserConfigurationException, IOException, FHIRFormatError, SAXException {
SnapShotGenerationTestsContext context = new SnapShotGenerationTestsContext();
Document tests = XMLUtil.parseToDom(UtilitiesXTests.loadTestResource("rX", "snapshot-generation", "manifest.xml"));
Document tests = XMLUtil.parseToDom(TestingUtilities.loadTestResource("rX", "snapshot-generation", "manifest.xml"));
Element test = XMLUtil.getFirstChild(tests.getDocumentElement());
List<Object[]> objects = new ArrayList<Object[]>();
while (test != null && test.getNodeName().equals("test")) {
@ -471,7 +471,7 @@ public class SnapShotGenerationXTests {
pu.sortDifferential(base, test.getOutput(), test.getOutput().getUrl(), errors, false);
if (!errors.isEmpty())
throw new FHIRException(errors.get(0));
IOUtils.copy(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-expected.xml")));
IOUtils.copy(TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-expected.xml")));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-actual.xml")), test.getOutput());
Assertions.assertTrue(test.expected.equalsDeep(test.output), "Output does not match expected");
}
@ -545,7 +545,7 @@ public class SnapShotGenerationXTests {
File dst = new File(UtilitiesXTests.tempFile("snapshot", test.getId() + "-expected.xml"));
if (dst.exists())
dst.delete();
IOUtils.copy(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(dst));
IOUtils.copy(TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(dst));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-actual.xml")), output);
StructureDefinition t1 = test.expected.copy();
t1.setText(null);

View File

@ -280,6 +280,11 @@ public class TerminologyServiceTests {
if (vm.getCodeableConcept() != null) {
res.addParameter("codeableConcept", vm.getCodeableConcept());
}
if (vm.getUnknownSystems() != null) {
for (String s : vm.getUnknownSystems()) {
res.addParameter("x-caused-by-unknown-system", new UriType(s));
}
}
if (vm.getIssues().size() > 0) {
OperationOutcome oo = new OperationOutcome();
oo.getIssue().addAll(vm.getIssues());

View File

@ -202,6 +202,9 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
byte[] testCaseContent = TestingUtilities.loadTestResource("validator", JsonUtilities.str(content, "file")).getBytes(StandardCharsets.UTF_8);
// load and process content
FhirFormat fmt = determineFormat(content, testCaseContent);
if (fmt == null) {
throw new FHIRException("Unknown format in source "+JsonUtilities.str(content, "file"));
}
InstanceValidator val = vCurr.getValidator(fmt);
val.setWantCheckSnapshotUnchanged(true);
@ -238,6 +241,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
val.setValidationLanguage(content.get("language").getAsString());
else
val.setValidationLanguage(null);
val.setForPublication(content.has("for-publication") && "true".equals(content.get("for-publication").getAsString()));
if (content.has("default-version")) {
val.setBaseOptions(val.getBaseOptions().withVersionFlexible(content.get("default-version").getAsBoolean()));
} else {