Skip to content

Commit

Permalink
issue #679 - fix the fhirpathspectests
Browse files Browse the repository at this point in the history
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 <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Feb 18, 2020
1 parent 5b93f7e commit 0ace3a1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
29 changes: 20 additions & 9 deletions fhir-path/src/main/java/com/ibm/fhir/path/patch/FHIRPathPatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,7 +39,7 @@ public <T extends Resource> 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());
}
Expand Down Expand Up @@ -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();
}

Expand All @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 0ace3a1

Please sign in to comment.