From 06a8f53cafc975e24728ca9342485ce6a05e6e87 Mon Sep 17 00:00:00 2001 From: Lee Surprenant Date: Tue, 18 Feb 2020 17:44:13 -0500 Subject: [PATCH] issue #679 - fix the fhirpathspectests Somehow I left these in a broken state. I had renamed the test file and added some stuff, but because the test file never loaded properly it never generated any tests (which would have failed). This change fixes that all. Signed-off-by: Lee Surprenant --- .../ibm/fhir/path/patch/FHIRPathPatch.java | 29 +- .../fhir/path/patch/FHIRPathPatchInsert.java | 10 +- .../fhir/path/patch/FHIRPathPatchMove.java | 2 +- .../fhir/path/patch/FHIRPathPatchReplace.java | 2 +- .../patch/test/FHIRPathPatchSpecTest.java | 6 +- .../resources/fhir-path-patch-tests.CHANGELOG | 3 +- .../test/resources/fhir-path-patch-tests.xml | 1026 ++++++++--------- 7 files changed, 546 insertions(+), 532 deletions(-) diff --git a/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatch.java b/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatch.java index 960357f2025..fc8934306f7 100644 --- a/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatch.java +++ b/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatch.java @@ -10,6 +10,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.UUID; import com.ibm.fhir.model.patch.FHIRPatch; import com.ibm.fhir.model.patch.exception.FHIRPatchException; @@ -38,7 +39,7 @@ public T apply(T resource) throws FHIRPatchException { * Convert the FHIRPathPatch to a FHIR Parameters resource */ public Parameters toParameters() { - Parameters.Builder builder = Parameters.builder(); + Parameters.Builder builder = Parameters.builder().id(UUID.randomUUID().toString()); for (FHIRPathPatchOperation operation : operations) { builder.parameter(operation.toParameter()); } @@ -127,14 +128,14 @@ public FHIRPathPatch build() { public static FHIRPathPatch from(Parameters params) { Objects.requireNonNull(params); Builder builder = FHIRPathPatch.builder(); - + for (Parameter param : params.getParameter()) { if (!FHIRPathPatchOperation.OPERATION.equals(param.getName().getValue())) { throw new IllegalArgumentException("Each FHIRPath patch operation must have a name of 'operation'"); } addOperation(builder, param); } - + return builder.build(); } @@ -143,7 +144,7 @@ public static FHIRPathPatch from(Parameters params) { * * @throws IllegalArgumentException if the Parameter object does not represent a valid FHIRPath Patch operation */ - private static FHIRPathPatchOperation addOperation(Builder builder, Parameter operation) { + private static void addOperation(Builder builder, Parameter operation) { boolean foundType = false, foundPath = false, foundName = false, foundValue = false, foundIndex = false, foundSource = false, foundDestination = false; FHIRPathPatchType type = null; String fhirPath = null; @@ -197,11 +198,21 @@ private static FHIRPathPatchOperation addOperation(Builder builder, Parameter op } try { switch (type) { - case ADD: builder.add(fhirPath, name, value); - case DELETE: builder.delete(fhirPath); - case INSERT: builder.insert(fhirPath, value, index); - case MOVE: builder.move(fhirPath, source, destination); - case REPLACE: builder.replace(fhirPath, value); + case ADD: + builder.add(fhirPath, name, value); + break; + case DELETE: + builder.delete(fhirPath); + break; + case INSERT: + builder.insert(fhirPath, value, index); + break; + case MOVE: + builder.move(fhirPath, source, destination); + break; + case REPLACE: + builder.replace(fhirPath, value); + break; default: throw new IllegalArgumentException("Invalid FHIRPath patch operation type: " + type.name()); } diff --git a/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchInsert.java b/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchInsert.java index ada6c20360f..76c75dd2c08 100644 --- a/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchInsert.java +++ b/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchInsert.java @@ -44,20 +44,20 @@ public Parameter toParameter() { .name(string(OPERATION)) .part(Parameter.builder() .name(string(TYPE)) - .value(Code.of(FHIRPathPatchType.ADD.value())) + .value(Code.of(FHIRPathPatchType.INSERT.value())) .build()) .part(Parameter.builder() .name(string(PATH)) .value(string(fhirPath)) .build()) - .part(Parameter.builder() - .name(string(VALUE)) - .value(value) - .build()) .part(Parameter.builder() .name(string(INDEX)) .value(com.ibm.fhir.model.type.Integer.of(index)) .build()) + .part(Parameter.builder() + .name(string(VALUE)) + .value(value) + .build()) .build(); } } \ No newline at end of file diff --git a/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchMove.java b/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchMove.java index b551e3d15a0..e117461d9f6 100644 --- a/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchMove.java +++ b/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchMove.java @@ -43,7 +43,7 @@ public Parameter toParameter() { .name(string(OPERATION)) .part(Parameter.builder() .name(string(TYPE)) - .value(Code.of(FHIRPathPatchType.ADD.value())) + .value(Code.of(FHIRPathPatchType.MOVE.value())) .build()) .part(Parameter.builder() .name(string(PATH)) diff --git a/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchReplace.java b/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchReplace.java index 352ee570f34..e77fc145515 100644 --- a/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchReplace.java +++ b/fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatchReplace.java @@ -42,7 +42,7 @@ public Parameter toParameter() { .name(string(OPERATION)) .part(Parameter.builder() .name(string(TYPE)) - .value(Code.of(FHIRPathPatchType.ADD.value())) + .value(Code.of(FHIRPathPatchType.REPLACE.value())) .build()) .part(Parameter.builder() .name(string(PATH)) diff --git a/fhir-path/src/test/java/com/ibm/fhir/path/patch/test/FHIRPathPatchSpecTest.java b/fhir-path/src/test/java/com/ibm/fhir/path/patch/test/FHIRPathPatchSpecTest.java index e7814d12bc0..8d7b7cea1eb 100644 --- a/fhir-path/src/test/java/com/ibm/fhir/path/patch/test/FHIRPathPatchSpecTest.java +++ b/fhir-path/src/test/java/com/ibm/fhir/path/patch/test/FHIRPathPatchSpecTest.java @@ -79,7 +79,9 @@ private void executeTest() throws Exception { } try { FHIRPathPatch patch = FHIRPathPatch.from(params); - assertEquals(patch.toParameters(), params); + // Set the id to match the expected parameters object so we can do a normal compare + Parameters serializedPatch = patch.toParameters().toBuilder().id(params.getId()).build(); + assertEquals(serializedPatch, params); Resource actualOutput = patch.apply(input); assertEquals(actualOutput, expectedOutput); @@ -117,7 +119,7 @@ public static Object[][] provideAllTestData() throws Exception { domFactory.setIgnoringElementContentWhitespace(true); domFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = domFactory.newDocumentBuilder(); - try (InputStream in = FHIRPathPatchSpecTest.class.getClassLoader().getResourceAsStream("patch\\fhir-path-tests.xml")) { + try (InputStream in = FHIRPathPatchSpecTest.class.getClassLoader().getResourceAsStream("fhir-path-patch-tests.xml")) { Document testDoc = documentBuilder.parse(in); NodeList cases = testDoc.getDocumentElement().getElementsByTagName("case"); diff --git a/fhir-path/src/test/resources/fhir-path-patch-tests.CHANGELOG b/fhir-path/src/test/resources/fhir-path-patch-tests.CHANGELOG index f16dbdca9dd..0f7df85259d 100644 --- a/fhir-path/src/test/resources/fhir-path-patch-tests.CHANGELOG +++ b/fhir-path/src/test/resources/fhir-path-patch-tests.CHANGELOG @@ -1,3 +1,4 @@ Renamed file from "patch\fhir-path-tests.xml" to "fhir-path-patch-tests.xml" to avoid git error: invalid path 'fhir-path/src/test/resources/patch\fhir-path-tests.CHANGELOG' To workaround global-1 I added a Resource.id to all FHIR Resources in the file (except the "Full Resource" test case which already had one) -I commented out the Patient.text.div replace operation in the test case Full Resource \ No newline at end of file +I commented out the Patient.text.div replace operation in the test case Full Resource +Replace tabs with spaces and remove trailing whitespace \ No newline at end of file diff --git a/fhir-path/src/test/resources/fhir-path-patch-tests.xml b/fhir-path/src/test/resources/fhir-path-patch-tests.xml index 94bb95f9d3d..e3a49dc2ac3 100644 --- a/fhir-path/src/test/resources/fhir-path-patch-tests.xml +++ b/fhir-path/src/test/resources/fhir-path-patch-tests.xml @@ -1,531 +1,531 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -539,7 +539,7 @@ - + @@ -556,7 +556,7 @@ - + @@ -600,7 +600,7 @@ - + @@ -617,7 +617,7 @@ - + @@ -653,7 +653,7 @@ - + @@ -674,7 +674,7 @@ - + @@ -710,7 +710,7 @@ - + @@ -731,7 +731,7 @@ - + @@ -767,7 +767,7 @@ - + @@ -788,7 +788,7 @@ - + @@ -817,7 +817,7 @@ - + @@ -834,7 +834,7 @@ - + @@ -863,7 +863,7 @@ - + @@ -880,7 +880,7 @@ - + @@ -909,7 +909,7 @@ - + @@ -926,7 +926,7 @@ - + @@ -967,7 +967,7 @@ - + @@ -992,7 +992,7 @@ - + @@ -1033,7 +1033,7 @@ - + @@ -1058,7 +1058,7 @@ - + @@ -1099,7 +1099,7 @@ - + @@ -1124,7 +1124,7 @@ - + @@ -1165,7 +1165,7 @@ - + @@ -1190,7 +1190,7 @@ - + @@ -1250,7 +1250,7 @@ - + @@ -1275,7 +1275,7 @@ - + @@ -1354,7 +1354,7 @@ - + @@ -1379,7 +1379,7 @@ - + @@ -1395,7 +1395,7 @@ Name Peter James - Chalmers ("Jim") + Chalmers("Jim") @@ -1426,7 +1426,7 @@ - + @@ -1546,9 +1546,9 @@ - + - --> + --> @@ -1564,7 +1564,7 @@ - + @@ -1582,7 +1582,7 @@ Name Peter James - Chalmers ("Jim") + Chalmers("Jim") @@ -1613,7 +1613,7 @@ - + @@ -1719,5 +1719,5 @@ - + \ No newline at end of file