From b9fe85996bd9a990082dc00b176254a391e855c4 Mon Sep 17 00:00:00 2001 From: dotasek Date: Fri, 14 Jan 2022 16:16:26 -0500 Subject: [PATCH 1/4] Fix literal inclusion of Java contants in static text file in cli hjelp --- .../hl7/fhir/utilities/VersionUtilities.java | 2 +- .../fhir/validation/cli/utils/Display.java | 29 ++++++++++++++++++- .../src/main/resources/help.txt | 10 +++---- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java index bb777f0a9..0f73b40a5 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java @@ -134,7 +134,7 @@ public class VersionUtilities { } public static String listSupportedVersions() { - return "1.0.2, 1.4.0, 3.0.2, 4.0.1, 4.1.0, 4.3.0, 5.0, "+CURRENT_FULL_VERSION; + return "1.0.2, 1.4.0, 3.0.2, 4.0.1, 4.1.0, 4.3.0, 5.0, " + CURRENT_FULL_VERSION; } public static boolean isR5Ver(String ver) { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java index ebf74f78a..4ce9ec86f 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java @@ -2,12 +2,16 @@ package org.hl7.fhir.validation.cli.utils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.hl7.fhir.r5.model.Constants; +import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.ToolsVersion; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; +import java.util.Map; /** * Class for displaying output to the cli user. @@ -16,6 +20,7 @@ import java.io.InputStream; */ public class Display { + private static String toMB(long maxMemory) { return Long.toString(maxMemory / (1024 * 1024)); } @@ -29,6 +34,25 @@ public class Display { System.out.println(); } + final static String CURLY_START = "\\{\\{"; + final static String CURLY_END = "\\}\\}"; + + final static String[][] PLACEHOLDERS = { + { CURLY_START + "XML_AND_JSON_FHIR_VERSIONS" + CURLY_END, "1.0, 1.4, 3.0, 4.0," + Constants.VERSION_MM }, + { CURLY_START + "TURTLE_FHIR_VERSIONS" + CURLY_END, "3.0, 4.0, " + Constants.VERSION_MM }, + { CURLY_START + "FHIR_MAJOR_VERSIONS" + CURLY_END, "1.0|1.4|3.0|" + VersionUtilities.CURRENT_VERSION}, + { CURLY_START + "FHIR_MINOR_VERSIONS" + CURLY_END, "1.0.2|1.4.0|3.0.2|4.0.1|" + VersionUtilities.CURRENT_FULL_VERSION }, + { CURLY_START + "FHIR_CURRENT_VERSION" + CURLY_END, VersionUtilities.CURRENT_VERSION}, + }; + + final static String replacePlaceholders(String input, String[][] placeholders) { + String output = input; + for (String[] placeholder : placeholders) { + output = output.replaceAll(placeholder[0], placeholder[1]); + } + return output; + } + /** * Loads the help details from resources/help.txt, and displays them on the command line to the user. */ @@ -37,12 +61,15 @@ public class Display { InputStream help = classLoader.getResourceAsStream("help.txt"); try { String data = IOUtils.toString(help, "UTF-8"); - System.out.println(data); + + System.out.println(replacePlaceholders(data, PLACEHOLDERS)); } catch (IOException e) { e.printStackTrace(); } } + + /** * Prints out system info to the command line. */ diff --git a/org.hl7.fhir.validation/src/main/resources/help.txt b/org.hl7.fhir.validation/src/main/resources/help.txt index 357a56b8c..8a0445342 100644 --- a/org.hl7.fhir.validation/src/main/resources/help.txt +++ b/org.hl7.fhir.validation/src/main/resources/help.txt @@ -6,8 +6,8 @@ command line The FHIR validation tool validates a FHIR resource or bundle. Schema and schematron checking is performed, then some additional checks are performed. -* XML & Json (FHIR versions 1.0, 1.4, 3.0, 4.0, " + Constants.VERSION_MM + ") -* Turtle (FHIR versions 3.0, 4.0, " + Constants.VERSION_MM + ") +* XML & Json (FHIR versions {{XML_AND_JSON_FHIR_VERSIONS}}) +* Turtle (FHIR versions {{TURTLE_FHIR_VERSIONS}}) If requested, instances will also be verified against the appropriate schema W3C XML Schema, JSON schema or ShEx, as appropriate @@ -22,8 +22,8 @@ The following parameters are supported: Patterns are limited to a directory followed by a filename with an embedded asterisk. E.g. foo*-examples.xml or someresource.*, etc. -version [ver]: The FHIR version to use. This can only appear once. - valid values 1.0 | 1.4 | 3.0 | " + VersionUtilities.CURRENT_VERSION + " or 1.0.2 | 1.4.0 | 3.0.2 | 4.0.1 | " + VersionUtilities.CURRENT_FULL_VERSION); - Default value is " + VersionUtilities.CURRENT_VERSION); + valid values {{FHIR_MAJOR_VERSIONS}} or {{FHIR_MINOR_VERSIONS}} + Default value is {{FHIR_CURRENT_VERSION}} -ig [package|file|folder|url]: an IG or profile definition to load. Can be the URL of an implementation guide or a package ([id]-[ver]) for a built implementation guide or a local folder that contains a @@ -48,7 +48,7 @@ The following parameters are supported: -showReferenceMessages Includes validation messages resulting from validating target resources against profiles defined on a reference. This increases the volume of - validationmessages, but may allow easier debugging. If not specified, + validation messages, but may allow easier debugging. If not specified, then only a high-level message indicating that the referenced item wasn't valid against the listed profile(s) will be provided. -questionnaire mode: what to do with when validating QuestionnaireResponse resources From a3ff15484b1879f0abf54759dc1bb38ead7eb0ff Mon Sep 17 00:00:00 2001 From: dotasek Date: Fri, 14 Jan 2022 16:49:44 -0500 Subject: [PATCH 2/4] Tests for help display --- .../fhir/validation/cli/utils/Display.java | 16 +++--- .../validation/cli/utils/DisplayTests.java | 54 +++++++++++++++++++ 2 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/utils/DisplayTests.java diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java index 4ce9ec86f..8e94d4d61 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java @@ -37,15 +37,19 @@ public class Display { final static String CURLY_START = "\\{\\{"; final static String CURLY_END = "\\}\\}"; + final static String getMoustacheString(final String string) { + return CURLY_START + string + CURLY_END; + } + final static String[][] PLACEHOLDERS = { - { CURLY_START + "XML_AND_JSON_FHIR_VERSIONS" + CURLY_END, "1.0, 1.4, 3.0, 4.0," + Constants.VERSION_MM }, - { CURLY_START + "TURTLE_FHIR_VERSIONS" + CURLY_END, "3.0, 4.0, " + Constants.VERSION_MM }, - { CURLY_START + "FHIR_MAJOR_VERSIONS" + CURLY_END, "1.0|1.4|3.0|" + VersionUtilities.CURRENT_VERSION}, - { CURLY_START + "FHIR_MINOR_VERSIONS" + CURLY_END, "1.0.2|1.4.0|3.0.2|4.0.1|" + VersionUtilities.CURRENT_FULL_VERSION }, - { CURLY_START + "FHIR_CURRENT_VERSION" + CURLY_END, VersionUtilities.CURRENT_VERSION}, + { getMoustacheString("XML_AND_JSON_FHIR_VERSIONS"), "1.0, 1.4, 3.0, 4.0," + Constants.VERSION_MM }, + { getMoustacheString("TURTLE_FHIR_VERSIONS"), "3.0, 4.0, " + Constants.VERSION_MM }, + { getMoustacheString("FHIR_MAJOR_VERSIONS"), "1.0|1.4|3.0|" + VersionUtilities.CURRENT_VERSION}, + { getMoustacheString("FHIR_MINOR_VERSIONS"), "1.0.2|1.4.0|3.0.2|4.0.1|" + VersionUtilities.CURRENT_FULL_VERSION }, + { getMoustacheString("FHIR_CURRENT_VERSION"), VersionUtilities.CURRENT_VERSION}, }; - final static String replacePlaceholders(String input, String[][] placeholders) { + final static String replacePlaceholders(final String input, final String[][] placeholders) { String output = input; for (String[] placeholder : placeholders) { output = output.replaceAll(placeholder[0], placeholder[1]); diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/utils/DisplayTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/utils/DisplayTests.java new file mode 100644 index 000000000..d70b7aae0 --- /dev/null +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/utils/DisplayTests.java @@ -0,0 +1,54 @@ +package org.hl7.fhir.validation.cli.utils; + +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import static org.junit.jupiter.api.Assertions.*; + +public class DisplayTests { + + @Test + public void displayHelpDetails() { + final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + + final PrintStream originalOut = System.out; + final PrintStream originalErr = System.err; + + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + + try { + Display.displayHelpDetails(); + + String output = outContent.toString(); + + for (String[] placeHolder: Display.PLACEHOLDERS) { + assertTrue(output.contains(placeHolder[1]), placeHolder[1] + " is not contained in output:\n" + output); + assertFalse(output.contains(placeHolder[0]), placeHolder[0] + " found in output:\n" + output); + } + } + finally { + System.setOut(originalOut); + System.setErr(originalErr); + } + } + + @Test + public void testReplacePlaceholdersBaseCase() { + + final String myTestString = "The {{DUMMY_A}} jumps over the {{DUMMY_B}}."; + final String[][] placeHolders = { + { "\\{\\{DUMMY_A\\}\\}", "quick brown fox"}, + { "\\{\\{DUMMY_B\\}\\}", "lazy dog"}, + }; + + final String expectedOutput = "The quick brown fox jumps over the lazy dog."; + final String output = Display.replacePlaceholders(myTestString, placeHolders); + + assertEquals(expectedOutput, output); + } + +} From a99d39b89e2d6b21636759646e67e114378c1e49 Mon Sep 17 00:00:00 2001 From: dotasek Date: Fri, 14 Jan 2022 20:49:26 -0500 Subject: [PATCH 3/4] Fix surefire config so jacoco doesn't skip jacoco coverage --- org.hl7.fhir.validation/pom.xml | 18 ++++++++++++++++++ .../validation/cli/utils/DisplayTests.java | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/org.hl7.fhir.validation/pom.xml b/org.hl7.fhir.validation/pom.xml index 12e710e29..13d7bc685 100644 --- a/org.hl7.fhir.validation/pom.xml +++ b/org.hl7.fhir.validation/pom.xml @@ -235,6 +235,24 @@ + + maven-surefire-plugin + ${maven_surefire_version} + + + default-test + test + + test + + + + org/hl7/fhir/validation/cli/services/ValidationServiceTest.java + + + + + org.basepom.maven duplicate-finder-maven-plugin diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/utils/DisplayTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/utils/DisplayTests.java index d70b7aae0..1ec8d8263 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/utils/DisplayTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/cli/utils/DisplayTests.java @@ -1,5 +1,7 @@ package org.hl7.fhir.validation.cli.utils; +import org.hl7.fhir.validation.cli.utils.Display; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; @@ -10,6 +12,7 @@ import static org.junit.jupiter.api.Assertions.*; public class DisplayTests { @Test + @DisplayName("Check for placeholder replacement in help output") public void displayHelpDetails() { final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); @@ -37,6 +40,7 @@ public class DisplayTests { } @Test + @DisplayName("Test replacePlaceholder base case") public void testReplacePlaceholdersBaseCase() { final String myTestString = "The {{DUMMY_A}} jumps over the {{DUMMY_B}}."; From e7ef32508476203810c79f62174684759fd14d2b Mon Sep 17 00:00:00 2001 From: dotasek Date: Mon, 17 Jan 2022 10:36:34 -0500 Subject: [PATCH 4/4] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e69de29bb..722131711 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -0,0 +1,7 @@ +## Validator Changes + +* fix inclusion of Java constants in CLI help text. + +## Other code changes + +n/a