diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/api/IBasicClient.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/api/IBasicClient.java index e965726175f..264aa44c3f5 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/api/IBasicClient.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/api/IBasicClient.java @@ -1,26 +1,7 @@ package ca.uhn.fhir.rest.client.api; -/* - * #%L - * HAPI FHIR - Core Library - * %% - * Copyright (C) 2014 - 2017 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ +import org.hl7.fhir.instance.model.api.IBaseConformance; -import ca.uhn.fhir.model.base.resource.BaseConformance; import ca.uhn.fhir.rest.annotation.Metadata; /** @@ -36,6 +17,6 @@ public interface IBasicClient extends IRestfulClient { * for more information. */ @Metadata - BaseConformance getServerConformanceStatement(); + IBaseConformance getServerConformanceStatement(); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java index d8c0d8bec74..4ca33aa1156 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java @@ -187,7 +187,7 @@ public class ParameterUtil { for (Annotation[] annotations : theMethod.getParameterAnnotations()) { for (int annotationIndex = 0; annotationIndex < annotations.length; annotationIndex++) { Annotation nextAnnotation = annotations[annotationIndex]; - Class class1 = nextAnnotation.getClass(); + Class class1 = nextAnnotation.annotationType(); if (toFind.isAssignableFrom(class1)) { return paramIndex; } diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseResourceReturningMethodBinding.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseResourceReturningMethodBinding.java index 4066fa84e07..a1befaa4981 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseResourceReturningMethodBinding.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseResourceReturningMethodBinding.java @@ -104,6 +104,11 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi @Override public Object invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map> theHeaders) { + + if (Constants.STATUS_HTTP_204_NO_CONTENT == theResponseStatusCode) { + return toReturnType(null); + } + IParser parser = createAppropriateParserForParsingResponse(theResponseMimeType, theResponseReader, theResponseStatusCode, myPreferTypesList); switch (getReturnType()) { @@ -153,31 +158,44 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi MethodUtil.parseClientRequestResourceHeaders(null, theHeaders, resource); - switch (getMethodReturnType()) { - case LIST_OF_RESOURCES: - return Collections.singletonList(resource); - case RESOURCE: - return resource; - case BUNDLE_RESOURCE: - return resource; - case METHOD_OUTCOME: - MethodOutcome retVal = new MethodOutcome(); - retVal.setOperationOutcome((IBaseOperationOutcome) resource); - return retVal; - } - break; + return toReturnType(resource); } } throw new IllegalStateException("Should not get here!"); } + private Object toReturnType(IBaseResource resource) { + Object retVal = null; + + switch (getMethodReturnType()) { + case LIST_OF_RESOURCES: + retVal = Collections.emptyList(); + if (resource != null) { + retVal = Collections.singletonList(resource); + } + break; + case RESOURCE: + retVal = resource; + break; + case BUNDLE_RESOURCE: + retVal = resource; + break; + case METHOD_OUTCOME: + MethodOutcome outcome = new MethodOutcome(); + outcome.setOperationOutcome((IBaseOperationOutcome) resource); + retVal = outcome; + break; + } + return retVal; + } + @SuppressWarnings("unchecked") private List> createPreferTypesList() { List> preferTypes = null; if (myResourceType != null && !BaseMethodBinding.isResourceInterface(myResourceType)) { preferTypes = new ArrayList>(1); - preferTypes.add((Class) myResourceType); + preferTypes.add(myResourceType); } else if (myResourceListCollectionType != null && IBaseResource.class.isAssignableFrom(myResourceListCollectionType) && !BaseMethodBinding.isResourceInterface(myResourceListCollectionType)) { preferTypes = new ArrayList>(1); preferTypes.add((Class) myResourceListCollectionType); diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/SearchMethodBinding.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/SearchMethodBinding.java index fc80ad04f8a..78b71cce9e4 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/SearchMethodBinding.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/SearchMethodBinding.java @@ -23,24 +23,19 @@ import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.lang.reflect.Method; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.annotation.Description; -import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.Search; -import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.api.RestOperationTypeEnum; -import ca.uhn.fhir.rest.api.SearchStyleEnum; +import ca.uhn.fhir.rest.api.*; import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; @@ -135,7 +130,7 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding { queryStringArgs.put(Constants.PARAM_QUERY, Collections.singletonList(myQueryName)); } - IdDt id = (IdDt) (myIdParamIndex != null ? theArgs[myIdParamIndex] : null); + IIdType id = (IIdType) (myIdParamIndex != null ? theArgs[myIdParamIndex] : null); String resourceName = getResourceName(); if (theArgs != null) { @@ -167,7 +162,7 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding { } - public static BaseHttpClientInvocation createSearchInvocation(FhirContext theContext, String theResourceName, Map> theParameters, IdDt theId, String theCompartmentName, + public static BaseHttpClientInvocation createSearchInvocation(FhirContext theContext, String theResourceName, Map> theParameters, IIdType theId, String theCompartmentName, SearchStyleEnum theSearchStyle) { SearchStyleEnum searchStyle = theSearchStyle; if (searchStyle == null) { diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/TransactionParameter.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/TransactionParameter.java index 921d10cbfeb..df2caa69973 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/TransactionParameter.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/TransactionParameter.java @@ -45,7 +45,7 @@ public class TransactionParameter implements IParameter { if (theInnerCollectionType.equals(List.class) == false) { throw new ConfigurationException(createParameterTypeError(theMethod)); } - if (theParameterType.equals(IResource.class) == false) { + if (theParameterType.equals(IResource.class) == false && theParameterType.equals(IBaseResource.class) == false) { throw new ConfigurationException(createParameterTypeError(theMethod)); } myParamStyle = ParamStyle.RESOURCE_LIST; diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ValidateMethodBindingDstu2Plus.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ValidateMethodBindingDstu2Plus.java index eaa6b4ac920..5aa8844e2dd 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ValidateMethodBindingDstu2Plus.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ValidateMethodBindingDstu2Plus.java @@ -40,7 +40,7 @@ public class ValidateMethodBindingDstu2Plus extends OperationMethodBinding { public ValidateMethodBindingDstu2Plus(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, Validate theAnnotation) { - super(theReturnResourceType, theReturnTypeFromRp, theMethod, theContext, theProvider, true, Constants.EXTOP_VALIDATE, theAnnotation.type(), new OperationParam[0], BundleTypeEnum.COLLECTION); + super(null, theReturnTypeFromRp, theMethod, theContext, theProvider, true, Constants.EXTOP_VALIDATE, theAnnotation.type(), new OperationParam[0], BundleTypeEnum.COLLECTION); List newParams = new ArrayList(); int idx = 0; diff --git a/hapi-fhir-jacoco/pom.xml b/hapi-fhir-jacoco/pom.xml index a6754817541..9c628cf0f68 100644 --- a/hapi-fhir-jacoco/pom.xml +++ b/hapi-fhir-jacoco/pom.xml @@ -196,8 +196,8 @@ guava - xmlunit - xmlunit + org.xmlunit + xmlunit-core test diff --git a/hapi-fhir-structures-dstu2.1/pom.xml b/hapi-fhir-structures-dstu2.1/pom.xml index a693f17b765..4228515e7ff 100644 --- a/hapi-fhir-structures-dstu2.1/pom.xml +++ b/hapi-fhir-structures-dstu2.1/pom.xml @@ -80,8 +80,8 @@ - xmlunit - xmlunit + org.xmlunit + xmlunit-core test diff --git a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/RoundTripDstu2_1Test.java b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/RoundTripDstu2_1Test.java deleted file mode 100644 index ce8841f5728..00000000000 --- a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/RoundTripDstu2_1Test.java +++ /dev/null @@ -1,120 +0,0 @@ -package ca.uhn.fhir.parser; - -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLEventWriter; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.events.XMLEvent; - -import org.custommonkey.xmlunit.DetailedDiff; -import org.custommonkey.xmlunit.Diff; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.AfterClass; -import org.junit.Test; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.util.TestUtil; -import ca.uhn.fhir.util.XmlUtil; - -public class RoundTripDstu2_1Test { - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RoundTripDstu2_1Test.class); - private static FhirContext ourCtx = FhirContext.forDstu2_1(); - - @Test - public void testIt() { - // Just so this doesn't complain until we enable roundtrip test - } - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - -// @Test - public void testRoundTrip() throws Exception { - ZipInputStream is = new ZipInputStream(new FileInputStream("src/test/resources/examples.zip")); - try { - while (true) { - ZipEntry nextEntry = is.getNextEntry(); - if (nextEntry == null) { - break; - } - - ByteArrayOutputStream oos = new ByteArrayOutputStream(); - byte[] buffer = new byte[2048]; - int len = 0; - while ((len = is.read(buffer)) > 0) { - oos.write(buffer, 0, len); - } - - String exampleText = oos.toString("UTF-8"); - ourLog.info("Next file: {} - Size: {} bytes", nextEntry.getName(), exampleText.length()); - if (!nextEntry.getName().contains("diagnosticreport-examples-lab")) { - continue; - } - - IBaseResource parsed = ourCtx.newXmlParser().parseResource(exampleText); - String encodedXml = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed); - - exampleText = cleanXml(exampleText); - encodedXml = cleanXml(encodedXml); - - DetailedDiff d = new DetailedDiff(new Diff(new StringReader(exampleText), new StringReader(encodedXml))); -// d.overrideDifferenceListener(new DifferenceListener() { -// -// @Override -// public void skippedComparison(Node theControl, Node theTest) { -// ourLog.info("" + theControl); -// } -// -// @Override -// public int differenceFound(Difference theDifference) { -// ourLog.info("" + theDifference); -// return 0; -// } -// }); - - boolean similar = d.similar(); - if (!similar) { - exampleText = exampleText.replace(" xmlns=\"http://hl7.org/fhir\"", ""); - encodedXml = encodedXml.replace(" xmlns=\"http://hl7.org/fhir\"", ""); - if (exampleText.length() != encodedXml.length()) { -// ourLog.info("Expected: " + exampleText); -// ourLog.info("Actual : " + encodedXml); - assertTrue(d.toString(), similar); - } - } - - } - - } finally { - is.close(); - } - } - - private String cleanXml(String exampleText) throws Error, Exception { - XMLEventReader read = XmlUtil.createXmlReader(new StringReader(exampleText)); - StringWriter sw = new StringWriter(); - XMLEventWriter write = XmlUtil.createXmlWriter(sw); - while (read.hasNext()) { - XMLEvent nextEvent = read.nextEvent(); - if (nextEvent.getEventType() == XMLStreamConstants.COMMENT) { - continue; - } - write.add(nextEvent); - } - write.add(read); - sw.close(); - return sw.toString().replaceAll("", "").replace("\n", " ").replace("\r", " ").replaceAll(">\\s+<", "><").replaceAll("<\\?.*\\?>", "").replaceAll("\\s+", " "); - } - -} diff --git a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2_1Test.java b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2_1Test.java index 6e5f3fa5aa8..34ec391b6fe 100644 --- a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2_1Test.java +++ b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2_1Test.java @@ -1,32 +1,16 @@ package ca.uhn.fhir.parser; +import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; import java.io.IOException; -import java.io.StringReader; import java.nio.charset.StandardCharsets; import java.util.*; import org.apache.commons.io.IOUtils; -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.XMLUnit; import org.hamcrest.collection.IsEmptyCollection; import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; @@ -46,6 +30,9 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.*; import org.mockito.ArgumentCaptor; +import org.xmlunit.builder.DiffBuilder; +import org.xmlunit.builder.Input; +import org.xmlunit.diff.*; import com.google.common.collect.Sets; @@ -1814,8 +1801,7 @@ public class XmlParserDstu2_1Test { String reencoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed); ourLog.info(reencoded); - Diff d = new Diff(new StringReader(content), new StringReader(reencoded)); - assertTrue(d.toString(), d.identical()); + compareXml(content, reencoded); } @@ -1852,9 +1838,7 @@ public class XmlParserDstu2_1Test { String reencoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed); ourLog.info(reencoded); - Diff d = new Diff(new StringReader(content), new StringReader(reencoded)); - assertTrue(d.toString(), d.identical()); - + compareXml(content, reencoded); } @Test @@ -2510,8 +2494,7 @@ public class XmlParserDstu2_1Test { String reEncoded = p.encodeResourceToString(b); ourLog.info(reEncoded); - Diff d = new Diff(new StringReader(bundle), new StringReader(reEncoded)); - assertTrue(d.toString(), d.identical()); + compareXml(bundle, reEncoded); } @@ -2684,11 +2667,17 @@ public class XmlParserDstu2_1Test { TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass - public static void beforeClass() { - XMLUnit.setIgnoreAttributeOrder(true); - XMLUnit.setIgnoreComments(true); - XMLUnit.setIgnoreWhitespace(true); + public static void compareXml(String content, String reEncoded) { + Diff d = DiffBuilder.compare(Input.fromString(content)) + .withTest(Input.fromString(reEncoded)) + .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)) + .checkForSimilar() + .ignoreWhitespace() + .ignoreComments() + .withComparisonController(ComparisonControllers.Default) + .build(); + + assertTrue(d.toString(), !d.hasDifferences()); } public static void main(String[] args) { diff --git a/hapi-fhir-structures-dstu2/pom.xml b/hapi-fhir-structures-dstu2/pom.xml index 4a92d3b1b2d..77f9969e47c 100644 --- a/hapi-fhir-structures-dstu2/pom.xml +++ b/hapi-fhir-structures-dstu2/pom.xml @@ -52,8 +52,8 @@ - xmlunit - xmlunit + org.xmlunit + xmlunit-core test diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/RoundTripDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/RoundTripDstu2Test.java deleted file mode 100644 index 7502afd0c9e..00000000000 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/RoundTripDstu2Test.java +++ /dev/null @@ -1,120 +0,0 @@ -package ca.uhn.fhir.parser; - -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLEventWriter; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.events.XMLEvent; - -import org.custommonkey.xmlunit.DetailedDiff; -import org.custommonkey.xmlunit.Diff; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.AfterClass; -import org.junit.Test; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.util.TestUtil; -import ca.uhn.fhir.util.XmlUtil; - -public class RoundTripDstu2Test { - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RoundTripDstu2Test.class); - private static FhirContext ourCtx = FhirContext.forDstu2(); - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - - @Test - public void testIt() { - // Just so this doesn't complain until we enable roundtrip test - } - -// @Test - public void testRoundTrip() throws Exception { - ZipInputStream is = new ZipInputStream(new FileInputStream("src/test/resources/examples.zip")); - try { - while (true) { - ZipEntry nextEntry = is.getNextEntry(); - if (nextEntry == null) { - break; - } - - ByteArrayOutputStream oos = new ByteArrayOutputStream(); - byte[] buffer = new byte[2048]; - int len = 0; - while ((len = is.read(buffer)) > 0) { - oos.write(buffer, 0, len); - } - - String exampleText = oos.toString("UTF-8"); - ourLog.info("Next file: {} - Size: {} bytes", nextEntry.getName(), exampleText.length()); - if (!nextEntry.getName().contains("diagnosticreport-examples-lab")) { - continue; - } - - IBaseResource parsed = ourCtx.newXmlParser().parseResource(exampleText); - String encodedXml = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed); - - exampleText = cleanXml(exampleText); - encodedXml = cleanXml(encodedXml); - - DetailedDiff d = new DetailedDiff(new Diff(new StringReader(exampleText), new StringReader(encodedXml))); -// d.overrideDifferenceListener(new DifferenceListener() { -// -// @Override -// public void skippedComparison(Node theControl, Node theTest) { -// ourLog.info("" + theControl); -// } -// -// @Override -// public int differenceFound(Difference theDifference) { -// ourLog.info("" + theDifference); -// return 0; -// } -// }); - - boolean similar = d.similar(); - if (!similar) { - exampleText = exampleText.replace(" xmlns=\"http://hl7.org/fhir\"", ""); - encodedXml = encodedXml.replace(" xmlns=\"http://hl7.org/fhir\"", ""); - if (exampleText.length() != encodedXml.length()) { -// ourLog.info("Expected: " + exampleText); -// ourLog.info("Actual : " + encodedXml); - assertTrue(d.toString(), similar); - } - } - - } - - } finally { - is.close(); - } - } - - private String cleanXml(String exampleText) throws Error, Exception { - XMLEventReader read = XmlUtil.createXmlReader(new StringReader(exampleText)); - StringWriter sw = new StringWriter(); - XMLEventWriter write = XmlUtil.createXmlWriter(sw); - while (read.hasNext()) { - XMLEvent nextEvent = read.nextEvent(); - if (nextEvent.getEventType() == XMLStreamConstants.COMMENT) { - continue; - } - write.add(nextEvent); - } - write.add(read); - sw.close(); - return sw.toString().replaceAll("", "").replace("\n", " ").replace("\r", " ").replaceAll(">\\s+<", "><").replaceAll("<\\?.*\\?>", "").replaceAll("\\s+", " "); - } - -} diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java index 7cf1a816eea..239222a059a 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java @@ -1,23 +1,9 @@ package ca.uhn.fhir.parser; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.emptyOrNullString; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; import java.io.IOException; import java.io.StringReader; @@ -25,17 +11,19 @@ import java.nio.charset.StandardCharsets; import java.util.*; import org.apache.commons.io.IOUtils; -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.XMLUnit; import org.hamcrest.collection.IsEmptyCollection; import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; +import org.junit.AfterClass; +import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.internal.stubbing.answers.ThrowsException; +import org.xmlunit.builder.DiffBuilder; +import org.xmlunit.builder.Input; +import org.xmlunit.diff.*; import com.google.common.collect.Sets; @@ -1933,8 +1921,7 @@ public class XmlParserDstu2Test { String reencoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed); ourLog.info(reencoded); - Diff d = new Diff(new StringReader(content), new StringReader(reencoded)); - assertTrue(d.toString(), d.identical()); + compareXml(content, reencoded); } @@ -1970,8 +1957,7 @@ public class XmlParserDstu2Test { String reencoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed); ourLog.info(reencoded); - Diff d = new Diff(new StringReader(content), new StringReader(reencoded)); - assertTrue(d.toString(), d.identical()); + compareXml(content, reencoded); } @@ -2624,9 +2610,7 @@ public class XmlParserDstu2Test { ourLog.info(reEncoded); - Diff d = new Diff(new StringReader(bundle), new StringReader(reEncoded)); - assertTrue(d.toString(), d.identical()); - + compareXml(bundle, reEncoded); } @Test @@ -2811,12 +2795,6 @@ public class XmlParserDstu2Test { TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass - public static void beforeClass() { - XMLUnit.setIgnoreAttributeOrder(true); - XMLUnit.setIgnoreComments(true); - XMLUnit.setIgnoreWhitespace(true); - } public static void main(String[] args) { IGenericClient c = ourCtx.newRestfulGenericClient("http://fhir-dev.healthintersections.com.au/open"); @@ -2858,4 +2836,17 @@ public class XmlParserDstu2Test { } } + public static void compareXml(String content, String reEncoded) { + Diff d = DiffBuilder.compare(Input.fromString(content)) + .withTest(Input.fromString(reEncoded)) + .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)) + .checkForSimilar() + .ignoreWhitespace() + .ignoreComments() + .withComparisonController(ComparisonControllers.Default) + .build(); + + assertTrue(d.toString(), !d.hasDifferences()); + } + } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientDstu2Test.java index 105f91d153e..892d7c6821f 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientDstu2Test.java @@ -109,12 +109,6 @@ public class ETagClientDstu2Test { lm.setTimeZoneZulu(true); assertEquals("1995-11-15T04:58:08.000Z", lm.getValueAsString()); - TagList tags = ResourceMetadataKeyEnum.TAG_LIST.get(response); - assertNotNull(tags); - assertEquals(1, tags.size()); - assertEquals("http://foo/tagdefinition.html", tags.get(0).getTerm()); - assertEquals("http://hl7.org/fhir/tag", tags.get(0).getScheme()); - assertEquals("Some tag", tags.get(0).getLabel()); } @Test diff --git a/hapi-fhir-structures-dstu3/pom.xml b/hapi-fhir-structures-dstu3/pom.xml index fbfe84197e8..b2302ab102d 100644 --- a/hapi-fhir-structures-dstu3/pom.xml +++ b/hapi-fhir-structures-dstu3/pom.xml @@ -93,8 +93,8 @@ - xmlunit - xmlunit + org.xmlunit + xmlunit-core test diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/RoundTripDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/RoundTripDstu3Test.java index 2619d9bbd92..36431f3dc3a 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/RoundTripDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/RoundTripDstu3Test.java @@ -1,21 +1,12 @@ package ca.uhn.fhir.parser; -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.StringReader; -import java.io.StringWriter; +import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLEventWriter; -import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.*; import javax.xml.stream.events.XMLEvent; -import org.custommonkey.xmlunit.DetailedDiff; -import org.custommonkey.xmlunit.Diff; import org.hl7.fhir.instance.model.api.IBaseResource; import org.junit.AfterClass; import org.junit.Test; @@ -68,31 +59,17 @@ public class RoundTripDstu3Test { exampleText = cleanXml(exampleText); encodedXml = cleanXml(encodedXml); - DetailedDiff d = new DetailedDiff(new Diff(new StringReader(exampleText), new StringReader(encodedXml))); -// d.overrideDifferenceListener(new DifferenceListener() { -// -// @Override -// public void skippedComparison(Node theControl, Node theTest) { -// ourLog.info("" + theControl); + XmlParserDstu3Test.compareXml(exampleText, encodedXml); +// DetailedDiff d = new DetailedDiff(new Diff(new StringReader(exampleText), new StringReader(encodedXml))); +// +// boolean similar = d.similar(); +// if (!similar) { +// exampleText = exampleText.replace(" xmlns=\"http://hl7.org/fhir\"", ""); +// encodedXml = encodedXml.replace(" xmlns=\"http://hl7.org/fhir\"", ""); +// if (exampleText.length() != encodedXml.length()) { +// assertTrue(d.toString(), similar); // } -// -// @Override -// public int differenceFound(Difference theDifference) { -// ourLog.info("" + theDifference); -// return 0; -// } -// }); - - boolean similar = d.similar(); - if (!similar) { - exampleText = exampleText.replace(" xmlns=\"http://hl7.org/fhir\"", ""); - encodedXml = encodedXml.replace(" xmlns=\"http://hl7.org/fhir\"", ""); - if (exampleText.length() != encodedXml.length()) { -// ourLog.info("Expected: " + exampleText); -// ourLog.info("Actual : " + encodedXml); - assertTrue(d.toString(), similar); - } - } +// } } diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java index 0da4e8804bc..4a75a14faf2 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java @@ -29,8 +29,6 @@ import java.util.*; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.XMLUnit; import org.hamcrest.collection.IsEmptyCollection; import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; @@ -54,6 +52,9 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.*; import org.mockito.ArgumentCaptor; +import org.xmlunit.builder.DiffBuilder; +import org.xmlunit.builder.Input; +import org.xmlunit.diff.*; import com.google.common.collect.Sets; @@ -82,7 +83,7 @@ public class XmlParserDstu3Test { } ourCtx.setNarrativeGenerator(null); } - + /** * See #544 */ @@ -110,7 +111,7 @@ public class XmlParserDstu3Test { assertNotNull(subject); assertEquals("FAMILY", subject.getNameFirstRep().getFamily()); } - + @Test public void testBundleWithBinary() { @@ -1571,7 +1572,8 @@ public class XmlParserDstu3Test { ourLog.info(encoded); assertThat(encoded, containsString("", "", "", "")); + assertThat(encoded, stringContainsInOrder("", "", + "", "")); assertThat(encoded, not(containsString("text"))); assertThat(encoded, not(containsString("THE DIV"))); assertThat(encoded, containsString("family")); @@ -1717,7 +1719,8 @@ public class XmlParserDstu3Test { ourLog.info(encoded); assertThat(encoded, containsString("", "", "", "")); + assertThat(encoded, stringContainsInOrder("", "", + "", "")); assertThat(encoded, not(containsString("THE DIV"))); assertThat(encoded, containsString("family")); assertThat(encoded, not(containsString("maritalStatus"))); @@ -1738,7 +1741,8 @@ public class XmlParserDstu3Test { assertThat(encoded, containsString("", "", "", "")); - assertThat(encoded, stringContainsInOrder("", "", "", "")); + assertThat(encoded, stringContainsInOrder("", "", + "", "")); assertThat(encoded, not(containsString("THE DIV"))); assertThat(encoded, containsString("family")); assertThat(encoded, not(containsString("maritalStatus"))); @@ -2130,8 +2134,7 @@ public class XmlParserDstu3Test { String reencoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed); ourLog.info(reencoded); - Diff d = new Diff(new StringReader(content), new StringReader(reencoded)); - assertTrue(d.toString(), d.identical()); + compareXml(content, reencoded); } @@ -2168,8 +2171,7 @@ public class XmlParserDstu3Test { String reencoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed); ourLog.info(reencoded); - Diff d = new Diff(new StringReader(content), new StringReader(reencoded)); - assertTrue(d.toString(), d.identical()); + compareXml(content, reencoded); } @@ -2994,7 +2996,7 @@ public class XmlParserDstu3Test { @Test public void testParseMetadata() throws Exception { - String bundle = "\n" + + String content = "\n" + " \n" + " \n" + " \n" + @@ -3023,7 +3025,7 @@ public class XmlParserDstu3Test { " \n" + ""; - Bundle b = ourCtx.newXmlParser().parseResource(Bundle.class, bundle); + Bundle b = ourCtx.newXmlParser().parseResource(Bundle.class, content); assertEquals(1, b.getEntry().size()); BundleEntryComponent entry = b.getEntry().get(0); @@ -3040,11 +3042,23 @@ public class XmlParserDstu3Test { String reEncoded = p.encodeResourceToString(b); ourLog.info(reEncoded); - Diff d = new Diff(new StringReader(bundle), new StringReader(reEncoded)); - assertTrue(d.toString(), d.identical()); + compareXml(content, reEncoded); } + public static void compareXml(String content, String reEncoded) { + Diff d = DiffBuilder.compare(Input.fromString(content)) + .withTest(Input.fromString(reEncoded)) + .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)) + .checkForSimilar() + .ignoreWhitespace() // this is working with newest Saxon 9.8.0-2 (not worked with 9.7.0-15 + .ignoreComments() // this is not working even with newest Saxon 9.8.0-2 + .withComparisonController(ComparisonControllers.Default) + .build(); + + assertTrue(d.toString(), !d.hasDifferences()); + } + @Test public void testParseMetaUpdatedDate() { @@ -3325,13 +3339,6 @@ public class XmlParserDstu3Test { TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass - public static void beforeClass() { - XMLUnit.setIgnoreAttributeOrder(true); - XMLUnit.setIgnoreComments(true); - XMLUnit.setIgnoreWhitespace(true); - } - public static void main(String[] args) { IGenericClient c = ourCtx.newRestfulGenericClient("http://fhir-dev.healthintersections.com.au/open"); // c.registerInterceptor(new LoggingInterceptor(true)); diff --git a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/model/BaseDateTimeTypeDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/model/BaseDateTimeTypeDstu3Test.java index 4f7ec16502b..48e150c389c 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/model/BaseDateTimeTypeDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/model/BaseDateTimeTypeDstu3Test.java @@ -343,7 +343,7 @@ public class BaseDateTimeTypeDstu3Test { public void testLargePrecision() { DateTimeType dt = new DateTimeType("2014-03-06T22:09:58.9121174+04:30"); - myDateInstantParser.setTimeZone(TimeZone.getTimeZone("Z")); + myDateInstantParser.setTimeZone(TimeZone.getTimeZone("GMT")); assertEquals("2014-03-06 17:39:58.912", myDateInstantParser.format(dt.getValue())); } diff --git a/hapi-fhir-structures-hl7org-dstu2/pom.xml b/hapi-fhir-structures-hl7org-dstu2/pom.xml index f819e7b24dd..6d11955bb56 100644 --- a/hapi-fhir-structures-hl7org-dstu2/pom.xml +++ b/hapi-fhir-structures-hl7org-dstu2/pom.xml @@ -71,8 +71,8 @@ - xmlunit - xmlunit + org.xmlunit + xmlunit-core test diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgDstu2Test.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgDstu2Test.java index c3b02b7433c..3f5cd57e7f4 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgDstu2Test.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgDstu2Test.java @@ -1,16 +1,7 @@ package ca.uhn.fhir.parser; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; import java.io.*; import java.nio.charset.Charset; @@ -18,7 +9,6 @@ import java.util.Arrays; import java.util.List; import org.apache.commons.io.IOUtils; -import org.custommonkey.xmlunit.Diff; import org.hamcrest.core.IsNot; import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; @@ -38,7 +28,6 @@ import org.junit.*; import org.xml.sax.SAXException; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.narrative.INarrativeGenerator; @@ -1281,9 +1270,7 @@ public class JsonParserHl7OrgDstu2Test { String expected = (xmlString); String actual = (encoded.trim()); - Diff d = new Diff(new StringReader(expected), new StringReader(actual)); - assertTrue(d.toString(), d.identical()); - + XmlParserHl7OrgDstu2Test.compareXml(expected, actual); } diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java index 1dc28937346..6a088bf247e 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java @@ -1,23 +1,13 @@ package ca.uhn.fhir.parser; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; import java.io.*; import java.nio.charset.Charset; import java.util.*; import org.apache.commons.io.IOUtils; -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.XMLUnit; import org.hamcrest.core.IsNot; import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; @@ -32,6 +22,9 @@ import org.hl7.fhir.instance.model.Narrative.NarrativeStatus; import org.hl7.fhir.instance.model.api.*; import org.junit.*; import org.xml.sax.SAXException; +import org.xmlunit.builder.DiffBuilder; +import org.xmlunit.builder.Input; +import org.xmlunit.diff.*; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; @@ -1352,12 +1345,10 @@ public class XmlParserHl7OrgDstu2Test { ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient)); - Diff d = new Diff(new StringReader(msg), new StringReader(encoded)); - ourLog.info("Expected: {}", msg); ourLog.info("Actual: {}", encoded); - assertTrue(d.toString(), d.identical()); + compareXml(msg, encoded); } @@ -1396,8 +1387,7 @@ public class XmlParserHl7OrgDstu2Test { String encoded = p.setPrettyPrint(true).encodeResourceToString(resource); ourLog.info(encoded); - Diff d = new Diff(new StringReader(msg), new StringReader(encoded)); - assertTrue(d.toString(), d.identical()); + compareXml(msg, encoded); } @Test @@ -1437,8 +1427,7 @@ public class XmlParserHl7OrgDstu2Test { String encoded = p.encodeResourceToString(resource); ourLog.info(encoded); - Diff d = new Diff(new StringReader(msg), new StringReader(encoded)); - assertTrue(d.toString(), d.identical()); + compareXml(msg, encoded); } @Test @@ -1679,9 +1668,7 @@ public class XmlParserHl7OrgDstu2Test { ourLog.info("Expected: {}", msg); ourLog.info("Actual: {}", encoded1); - Diff d = new Diff(new StringReader(msg), new StringReader(encoded1)); - assertTrue(d.toString(), d.identical()); - + compareXml(msg, encoded1); } @Test @@ -1709,9 +1696,7 @@ public class XmlParserHl7OrgDstu2Test { String expected = (jsonString); String actual = (encoded.trim()); - Diff d = new Diff(new StringReader(expected), new StringReader(actual)); - assertTrue(d.toString(), d.identical()); - + compareXml(expected, actual); } @Test @@ -1755,9 +1740,6 @@ public class XmlParserHl7OrgDstu2Test { @BeforeClass public static void beforeClass() { - XMLUnit.setIgnoreAttributeOrder(true); - XMLUnit.setIgnoreComments(true); - XMLUnit.setIgnoreWhitespace(true); ourCtx = FhirContext.forDstu2Hl7Org(); } @@ -1784,4 +1766,17 @@ public class XmlParserHl7OrgDstu2Test { } } + public static void compareXml(String content, String reEncoded) { + Diff d = DiffBuilder.compare(Input.fromString(content)) + .withTest(Input.fromString(reEncoded)) + .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)) + .checkForSimilar() + .ignoreWhitespace() + .ignoreComments() + .withComparisonController(ComparisonControllers.Default) + .build(); + + assertTrue(d.toString(), !d.hasDifferences()); + } + } diff --git a/hapi-fhir-structures-r4/pom.xml b/hapi-fhir-structures-r4/pom.xml index 71752b67fa0..8cbe4bf6d15 100644 --- a/hapi-fhir-structures-r4/pom.xml +++ b/hapi-fhir-structures-r4/pom.xml @@ -74,8 +74,8 @@ - xmlunit - xmlunit + org.xmlunit + xmlunit-core test diff --git a/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/elementmodel/ObjectConverter.java b/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/elementmodel/ObjectConverter.java index f8db929b372..19c34f013a2 100644 --- a/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/elementmodel/ObjectConverter.java +++ b/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/elementmodel/ObjectConverter.java @@ -1,30 +1,15 @@ package org.hl7.fhir.r4.elementmodel; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; +import java.io.*; import java.util.ArrayList; import java.util.List; +import org.hl7.fhir.exceptions.*; import org.hl7.fhir.r4.conformance.ProfileUtilities; import org.hl7.fhir.r4.context.IWorkerContext; import org.hl7.fhir.r4.formats.IParser.OutputStyle; -import org.hl7.fhir.r4.model.Base; -import org.hl7.fhir.r4.model.CodeableConcept; -import org.hl7.fhir.r4.model.Coding; -import org.hl7.fhir.r4.model.ElementDefinition; -import org.hl7.fhir.r4.model.Factory; -import org.hl7.fhir.r4.model.PrimitiveType; -import org.hl7.fhir.r4.model.Resource; -import org.hl7.fhir.r4.model.StructureDefinition; +import org.hl7.fhir.r4.model.*; import org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind; -import org.hl7.fhir.r4.model.Type; -import org.hl7.fhir.exceptions.DefinitionException; -import org.hl7.fhir.exceptions.FHIRException; -import org.hl7.fhir.exceptions.FHIRFormatError; -import org.hl7.fhir.utilities.TextFile; - -import com.sun.corba.se.impl.ior.NewObjectKeyTemplateBase; public class ObjectConverter { diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/ClientR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/ClientR4Test.java index 2a179d93f67..65b6f7775fd 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/ClientR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/ClientR4Test.java @@ -29,6 +29,8 @@ import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import com.google.common.base.Charsets; + import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.annotation.ResourceDef; @@ -145,7 +147,7 @@ public class ClientR4Test { assertEquals(HttpPost.class, capt.getValue().getClass()); HttpPost post = (HttpPost) capt.getValue(); - assertThat(IOUtils.toString(post.getEntity().getContent()), StringContains.containsString(" capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); - when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK")); + when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_204_NO_CONTENT, "OK")); when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8")); when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(myHttpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); @@ -1129,13 +1128,42 @@ public class ClientR4Test { assertEquals(HttpPost.class, capt.getValue().getClass()); HttpPost post = (HttpPost) capt.getValue(); - assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/_validate")); - assertThat(IOUtils.toString(post.getEntity().getContent()), StringContains.containsString(" capt = ArgumentCaptor.forClass(HttpUriRequest.class); + when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); + when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); + when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON_NEW + "; charset=UTF-8")); + when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(resp), Charset.forName("UTF-8"))); + when(myHttpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); + + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); + MethodOutcome response = client.validatePatient(patient); + + assertEquals(HttpPost.class, capt.getValue().getClass()); + HttpPost post = (HttpPost) capt.getValue(); + assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/$validate")); + assertThat(IOUtils.toString(post.getEntity().getContent(), Charsets.UTF_8), StringContains.containsString(" capt = ArgumentCaptor.forClass(HttpUriRequest.class); - when(httpClient.execute(capt.capture())).thenReturn(httpResponse); - when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); - when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML_NEW + "; charset=UTF-8")); - when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8"))); + when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); + when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); + when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML_NEW + "; charset=UTF-8")); + when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8"))); IGenericClient client = ctx.newRestfulGenericClient( "http://foo"); Bundle bundle = client @@ -84,10 +84,10 @@ public class IncludedResourceStitchingClientTest { @Test public void testWithDeclaredExtension() throws Exception { ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class); - when(httpClient.execute(capt.capture())).thenReturn(httpResponse); - when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); - when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML_NEW + "; charset=UTF-8")); - when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createLinkedBundle()), Charset.forName("UTF-8"))); + when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); + when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); + when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML_NEW + "; charset=UTF-8")); + when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createLinkedBundle()), Charset.forName("UTF-8"))); IGenericClient client = ctx.newRestfulGenericClient( "http://foo"); Bundle bundle = client.search().forResource(IncludeTest.ExtPatient.class).returnBundle(Bundle.class).execute(); @@ -115,12 +115,25 @@ public class IncludedResourceStitchingClientTest { Patient p1 = new Patient(); p1.addIdentifier().setValue("p1"); + p1.addExtension().setUrl("http://foo#secondOrg").setValue(new Reference("Organization/o1")); bundle.addEntry().setResource(p1); Patient p2 = new Patient(); - p2.addIdentifier().setValue("p1"); + p2.addIdentifier().setValue("p2"); + p2.addExtension().setUrl("http://foo#secondOrg").setValue(new Reference("Organization/o1")); bundle.addEntry().setResource(p2); + Organization o1 = new Organization(); + o1.setId("o1"); + o1.setName("o1"); + o1.getPartOf().setReference("Organization/o2"); + bundle.addEntry().setResource(o1); + + Organization o2 = new Organization(); + o2.setId("o2"); + o2.setName("o2"); + bundle.addEntry().setResource(o2); + return ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle); // //@formatter:off @@ -200,65 +213,85 @@ public class IncludedResourceStitchingClientTest { private String createBundle() { - //@formatter:on - return "\n" + - " \n" + - " <id>f051fd86-4daa-48da-80f7-5a0443bf6f11</id>\n" + - " <link rel=\"self\" href=\"http://localhost:49627/Patient?_query=extInclude&_pretty=true\"/>\n" + - " <link rel=\"fhir-base\" href=\"http://localhost:49627\"/>\n" + - " <os:totalResults xmlns:os=\"http://a9.com/-/spec/opensearch/1.1/\">2</os:totalResults>\n" + - " <author>\n" + - " <name>HAPI FHIR Server</name>\n" + - " </author>\n" + - " <entry>\n" + - " <title>Patient p1\n" + - " http://localhost:49627/Patient/p1\n" + - " 2014-08-05T15:22:08-04:00\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " Patient p2\n" + - " http://localhost:49627/Patient/p2\n" + - " 2014-08-05T15:22:08-04:00\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " Organization o1\n" + - " http://localhost:49627/Organization/o1\n" + - " 2014-08-05T15:22:08-04:00\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; - //@formatter:off + Bundle bundle = new Bundle(); + + Patient p1 = new Patient(); + p1.addIdentifier().setValue("p1"); + p1.addExtension().setUrl("http://foo").setValue(new Reference("Organization/o1")); + bundle.addEntry().setResource(p1); + + Patient p2 = new Patient(); + p2.addIdentifier().setValue("p2"); + p2.addExtension().setUrl("http://foo#secondOrg").setValue(new Reference("Organization/o1")); + bundle.addEntry().setResource(p2); + + Organization o1 = new Organization(); + o1.setId("o1"); + o1.setName("o1"); + o1.getPartOf().setReference("Organization/o2"); + bundle.addEntry().setResource(o1); + + return ctx.newXmlParser().encodeResourceToString(bundle); + +// //@formatter:on +// return "\n" + +// " \n" + +// " <id>f051fd86-4daa-48da-80f7-5a0443bf6f11</id>\n" + +// " <link rel=\"self\" href=\"http://localhost:49627/Patient?_query=extInclude&_pretty=true\"/>\n" + +// " <link rel=\"fhir-base\" href=\"http://localhost:49627\"/>\n" + +// " <os:totalResults xmlns:os=\"http://a9.com/-/spec/opensearch/1.1/\">2</os:totalResults>\n" + +// " <author>\n" + +// " <name>HAPI FHIR Server</name>\n" + +// " </author>\n" + +// " <entry>\n" + +// " <title>Patient p1\n" + +// " http://localhost:49627/Patient/p1\n" + +// " 2014-08-05T15:22:08-04:00\n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " Patient p2\n" + +// " http://localhost:49627/Patient/p2\n" + +// " 2014-08-05T15:22:08-04:00\n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " Organization o1\n" + +// " http://localhost:49627/Organization/o1\n" + +// " 2014-08-05T15:22:08-04:00\n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// " \n" + +// ""; +// //@formatter:off } diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/TransactionClientTest.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/TransactionClientTest.java index 6c6bf87fe8a..312f8dc3359 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/TransactionClientTest.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/TransactionClientTest.java @@ -84,9 +84,9 @@ public class TransactionClientTest { ourLog.info(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle)); assertEquals(2, bundle.getEntry().size()); - assertEquals("Patient/testPersistWithSimpleLinkP01", bundle.getEntry().get(0).getIdElement().getValue()); + assertEquals("Patient/testPersistWithSimpleLinkP01", bundle.getEntry().get(0).getResource().getIdElement().getValue()); - assertTrue(bundle.getEntry().get(1).getId().isEmpty()); + assertTrue(bundle.getEntry().get(1).getResource().getIdElement().isEmpty()); } @@ -102,7 +102,7 @@ public class TransactionClientTest { obs.setSubject(new Reference("Patient/testPersistWithSimpleLinkP01")); Bundle transactionBundle = new Bundle(); - transactionBundle.addEntry().setResource(patient); + transactionBundle.addEntry().setResource(patient).setFullUrl("http://foo/Patient/testPersistWithSimpleLinkP01"); transactionBundle.addEntry().setResource(obs); IBundleClient client = ctx.newRestfulClient(IBundleClient.class, "http://foo"); @@ -125,7 +125,7 @@ public class TransactionClientTest { assertEquals(2, bundle.getEntry().size()); assertEquals("http://foo/Patient/testPersistWithSimpleLinkP01", bundle.getEntry().get(0).getResource().getIdElement().getValue()); - assertTrue(bundle.getEntry().get(1).getId().isEmpty()); + assertTrue(bundle.getEntry().get(1).getResource().getIdElement().isEmpty()); } diff --git a/hapi-fhir-utilities/src/main/java/org/hl7/fhir/utilities/ZipGenerator.java b/hapi-fhir-utilities/src/main/java/org/hl7/fhir/utilities/ZipGenerator.java index 05a78ef90a7..ccf2d9ceb3b 100644 --- a/hapi-fhir-utilities/src/main/java/org/hl7/fhir/utilities/ZipGenerator.java +++ b/hapi-fhir-utilities/src/main/java/org/hl7/fhir/utilities/ZipGenerator.java @@ -114,7 +114,7 @@ public class ZipGenerator { public void addFiles(String actualDir, String statedDir, String ext, String noExt) throws FileNotFoundException, IOException { byte data[] = new byte[BUFFER]; - statedDir.replace("\\", "/"); + statedDir = statedDir.replace("\\", "/"); File f = new CSFile(actualDir); String files[] = f.list(); @@ -136,7 +136,7 @@ public class ZipGenerator { public void addFilesFiltered(String actualDir, String statedDir, String ext, String[] noExt) throws FileNotFoundException, IOException { byte data[] = new byte[BUFFER]; - statedDir.replace("\\", "/"); + statedDir = statedDir.replace("\\", "/"); File f = new CSFile(actualDir); String files[] = f.list(); diff --git a/hapi-fhir-utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java b/hapi-fhir-utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java index cdf6990540a..871cdff78c2 100644 --- a/hapi-fhir-utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java +++ b/hapi-fhir-utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java @@ -167,7 +167,7 @@ public class HierarchicalTableGenerator extends TranslatingUtilities { String html = Processor.process("[$PROFILE$]: extended\n" + md); pieces.addAll(htmlToParagraphPieces(html)); } catch (Exception e) { - e = e; + e.printStackTrace(); } return this; } diff --git a/pom.xml b/pom.xml index ade53b71eee..5884b5f858d 100644 --- a/pom.xml +++ b/pom.xml @@ -368,8 +368,8 @@ 10.13.1.1 2.25.1 - 9.4.5.v20170502 - 5.2.9.Final + 9.4.6.v20170531 + 5.2.10.Final 5.4.1.Final 5.7.0.Final @@ -378,10 +378,9 @@ 1.8 2.4 2.7.1 - 4.4.6 - 4.3.7.RELEASE - 3.0.2.RELEASE - 1.6 + 4.4.11 + 4.3.10.RELEASE + 3.0.7.RELEASE 1.6.0 @@ -400,7 +399,7 @@ ch.qos.logback logback-classic - 1.2.2 + 1.2.3 com.atlassian.commonmark @@ -420,12 +419,12 @@ com.google.errorprone error_prone_core - 2.0.9 + 2.0.21 com.google.guava guava - 21.0 + 22.0 com.phloc @@ -445,7 +444,7 @@ commons-cli commons-cli - 1.3.1 + 1.4 commons-codec @@ -497,7 +496,7 @@ com.google.code.gson gson - 2.8.0 + 2.8.1 javax.mail @@ -560,12 +559,13 @@ net.sf.saxon Saxon-HE + 9.5.1-5 net.ttddyy datasource-proxy - 1.4.1 + 1.4.2 org.antlr @@ -580,7 +580,7 @@ org.apache.commons commons-lang3 - 3.5 + 3.6 org.apache.derby @@ -600,7 +600,7 @@ org.apache.httpcomponents httpclient - 4.5.2 + 4.5.3 org.apache.httpcomponents @@ -610,7 +610,7 @@ org.apache.httpcomponents httpcore - 4.4.5 + 4.4.6 org.apache.lucene @@ -645,7 +645,7 @@ org.apache.maven.wagon wagon-scm - 2.10 + 2.12 org.apache.maven @@ -655,12 +655,12 @@ org.apache.maven maven-plugin-api - 3.2.5 + 3.5.0 org.apache.maven.plugin-tools maven-plugin-annotations - 3.2 + 3.5 org.apache.velocity @@ -672,20 +672,25 @@ velocity-tools 2.0 + + org.codehaus.plexus + plexus-compiler-api + 2.8.2 + org.codehaus.plexus plexus-compiler-javac - 2.8.1 + 2.8.2 org.codehaus.plexus plexus-compiler-javac-errorprone - 2.8.1 + 2.8.2 org.codehaus.plexus plexus-utils - 3.0.22 + 3.0.24 org.codehaus.woodstox @@ -745,7 +750,7 @@ org.fusesource.jansi jansi - 1.15 + 1.16 org.glassfish @@ -908,9 +913,9 @@ ${thymeleaf-version} - xmlunit - xmlunit - 1.6 + org.xmlunit + xmlunit-core + 2.4.0 xpp3 @@ -954,7 +959,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.1 + 3.6.2 1.7 1.7 @@ -974,15 +979,20 @@ error_prone_core 2.0.19 + + org.codehaus.plexus + plexus-compiler-api + 2.8.2 + org.codehaus.plexus plexus-compiler-javac - 2.8.1 + 2.8.2 org.codehaus.plexus plexus-compiler-javac-errorprone - 2.8.1 + 2.8.2 org.codehaus.plexus diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 20eb89f2f49..c27ef6f7d69 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,24 @@ + + Bump the version of a few dependencies to the + latest versions (dependent HAPI modules listed in brackets): + +
  • Gson (JSON Parser): 2.8.0 -> 2.8.1
  • +
  • Commons-lang3 (Everywhere): 3.5 -> 3.6
  • + +
  • Apache HttpClient (FHIR Client): 4.5.2 -> 4.5.3
  • +
  • Apache HttpCore (FHIR Client): 4.4.5 -> 4.4.6
  • +
  • Phloc Commons (Schematron Validator): 4.4.6 -> 4.4.11
  • +
  • Hibernate (JPA): 5.2.9 -> 5.2.10
  • +
  • Spring (JPA): 4.3.7.RELEASE -> 4.3.10.RELEASE
  • +
  • Thymeleaf (Testpage Overlay): 3.0.2.RELEASE -> 3.0.7.RELEASE
  • + + ]]> +
    + hapi-fhir-client-okhttp project POM had dependencies on both hapi-fhir-structures-dstu2 and hapi-fhir-structures-dstu3, which