b = a.returnBundle(Bundle.class);
- IClientExecutable, ?> x = b.encodedXml();
- x.execute();
-
- }
{
Bundle returned = ourClient
.search()
@@ -1598,10 +1607,15 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
.encodedXml()
.execute();
assertThat(returned.getEntry().size(), greaterThan(1));
- assertEquals(BundleTypeEnum.SEARCHSET, returned.getType().getValueAsEnum());
+ assertEquals(BundleTypeEnum.SEARCHSET, returned.getTypeElement().getValueAsEnum());
}
{
- Bundle returned = ourClient.search().forResource(Patient.class).encodedJson().execute();
+ Bundle returned = ourClient
+ .search()
+ .forResource(Patient.class)
+ .encodedJson()
+ .returnBundle(Bundle.class)
+ .execute();
assertThat(returned.getEntry().size(), greaterThan(1));
}
}
@@ -1648,7 +1662,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
assertEquals(1, actual.getContained().getContainedResources().size());
assertThat(actual.getText().getDiv().getValueAsString(), containsString("Identifier | testSaveAndRetrieveWithContained01 | "));
- Bundle b = ourClient.search().forResource("Patient").where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system:rpdstu2", "testSaveAndRetrieveWithContained01")).prettyPrint().execute();
+ Bundle b = ourClient
+ .search()
+ .forResource("Patient")
+ .where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system:rpdstu2", "testSaveAndRetrieveWithContained01"))
+ .prettyPrint()
+ .returnBundle(Bundle.class)
+ .execute();
assertEquals(1, b.getEntry().size());
}
@@ -1714,7 +1734,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
p1.addIdentifier().setValue("testSearchByIdentifierWithoutSystem01");
IdDt p1Id = (IdDt) ourClient.create().resource(p1).execute().getId();
- Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode(null, "testSearchByIdentifierWithoutSystem01")).encodedJson().prettyPrint()
+ Bundle actual = ourClient
+ .search()
+ .forResource(Patient.class)
+ .where(Patient.IDENTIFIER.exactly().systemAndCode(null, "testSearchByIdentifierWithoutSystem01"))
+ .encodedJson()
+ .prettyPrint()
+ .returnBundle(Bundle.class)
.execute();
assertEquals(1, actual.getEntry().size());
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
@@ -1736,14 +1762,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
id2 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
}
- //@formatter:off
Bundle found = ourClient
.search()
.forResource(Patient.class)
.where(BaseResource.RES_ID.matches().values(id1.getIdPart(), id2.getIdPart()))
.and(BaseResource.RES_ID.matches().value(id1.getIdPart()))
+ .returnBundle(Bundle.class)
.execute();
- //@formatter:on
assertThat(toIdListUnqualifiedVersionless(found), containsInAnyOrder(id1));
}
@@ -1761,21 +1786,24 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
p1.setManagingOrganization(new ResourceReferenceDt(o1id.toUnqualifiedVersionless()));
IdDt p1Id = (IdDt) ourClient.create().resource(p1).execute().getId();
- //@formatter:off
Bundle actual = ourClient.search()
.forResource(Patient.class)
.where(Patient.ORGANIZATION.hasId(o1id.getIdPart()))
- .encodedJson().prettyPrint().execute();
- //@formatter:on
+ .encodedJson()
+ .prettyPrint()
+ .returnBundle(Bundle.class)
+ .execute();
assertEquals(1, actual.getEntry().size());
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
- //@formatter:off
- actual = ourClient.search()
+ actual = ourClient
+ .search()
.forResource(Patient.class)
.where(Patient.ORGANIZATION.hasId(o1id.getValue()))
- .encodedJson().prettyPrint().execute();
- //@formatter:on
+ .encodedJson()
+ .prettyPrint()
+ .returnBundle(Bundle.class)
+ .execute();
assertEquals(1, actual.getEntry().size());
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
@@ -1802,17 +1830,19 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
p2.setManagingOrganization(new ResourceReferenceDt(o2id.toUnqualifiedVersionless()));
IdDt p2Id = (IdDt) ourClient.create().resource(p2).execute().getId();
- //@formatter:off
Bundle actual = ourClient.search()
.forResource(Patient.class)
.where(Patient.ORGANIZATION.hasAnyOfIds(Arrays.asList(o1id.getIdPart(), o2id.getIdPart())))
- .encodedJson().prettyPrint().execute();
- //@formatter:on
+ .encodedJson()
+ .prettyPrint()
+ .returnBundle(Bundle.class)
+ .execute();
+
Set expectedIds = new HashSet();
expectedIds.add(p1Id.getIdPart());
expectedIds.add(p2Id.getIdPart());
Set actualIds = new HashSet();
- for (BundleEntry ele : actual.getEntry()) {
+ for (Entry ele : actual.getEntry()) {
actualIds.add(ele.getResource().getId().getIdPart());
}
assertEquals("Expects to retrieve the 2 patients which reference the two different organizations", expectedIds, actualIds);
@@ -1828,40 +1858,49 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
o2.setName("testSearchByResourceChainName02");
o2.getMeta().addProfile("http://profile1").addProfile("http://profile3");
IdDt o2id = (IdDt) ourClient.create().resource(o2).execute().getId().toUnqualifiedVersionless();
- //@formatter:off
+
Bundle actual = ourClient.search()
.forResource(Organization.class)
.withProfile("http://profile1")
.withProfile("http://profileX")
- .encodedJson().prettyPrint().execute();
- //@formatter:on
+ .encodedJson()
+ .prettyPrint()
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("nothing matches profile x", Collections.emptyList(), actual.getEntry());
- //@formatter:off
+
actual = ourClient.search()
.forResource(Organization.class)
.withProfile("http://profile1")
.withProfile("http://profile2")
- .encodedJson().prettyPrint().execute();
- //@formatter:on
+ .returnBundle(Bundle.class)
+ .encodedJson()
+ .prettyPrint()
+ .execute();
+
Set expectedIds = new HashSet();
expectedIds.add(o1id.getIdPart());
Set actualIds = new HashSet();
- for (BundleEntry ele : actual.getEntry()) {
+ for (Entry ele : actual.getEntry()) {
actualIds.add(ele.getResource().getId().getIdPart());
}
assertEquals("Expects to retrieve the 1 orgination matching on Org1's profiles", expectedIds, actualIds);
- //@formatter:off
+
actual = ourClient.search()
.forResource(Organization.class)
.withProfile("http://profile1")
.withAnyProfile(Arrays.asList("http://profile3", "http://profile2"))
- .encodedJson().prettyPrint().execute();
- //@formatter:on
+ .encodedJson()
+ .prettyPrint()
+ .returnBundle(Bundle.class)
+ .execute();
+
expectedIds = new HashSet();
expectedIds.add(o1id.getIdPart());
expectedIds.add(o2id.getIdPart());
actualIds = new HashSet();
- for (BundleEntry ele : actual.getEntry()) {
+ for (Entry ele : actual.getEntry()) {
actualIds.add(ele.getResource().getId().getIdPart());
}
assertEquals("Expects to retrieve the 2 orginations, since we match on (the common profile AND (Org1's second profile OR org2's second profile))", expectedIds, actualIds);
@@ -1905,60 +1944,58 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
ourLog.info("Before: {}", beforeAny.getValue());
{
- //@formatter:off
- Bundle found = ourClient.search()
+ Bundle found = ourClient
+ .search()
.forResource(Patient.class)
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
.lastUpdated(new DateRangeParam(beforeAny, null))
+ .returnBundle(Bundle.class)
.execute();
- //@formatter:on
List patients = toIdListUnqualifiedVersionless(found);
assertThat(patients, hasItems(id1a, id1b, id2));
}
{
- //@formatter:off
Bundle found = ourClient.search()
.forResource(Patient.class)
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
+ .returnBundle(Bundle.class)
.execute();
- //@formatter:on
List patients = toIdListUnqualifiedVersionless(found);
assertThat(patients, hasItems(id1a, id1b, id2));
}
{
- //@formatter:off
Bundle found = ourClient.search()
.forResource(Patient.class)
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
.lastUpdated(new DateRangeParam(beforeR2, null))
+ .returnBundle(Bundle.class)
.execute();
- //@formatter:on
List patients = toIdListUnqualifiedVersionless(found);
assertThat(patients, hasItems(id2));
assertThat(patients, not(hasItems(id1a, id1b)));
}
{
- //@formatter:off
Bundle found = ourClient.search()
.forResource(Patient.class)
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
.lastUpdated(new DateRangeParam(beforeAny, beforeR2))
+ .returnBundle(Bundle.class)
.execute();
- //@formatter:on
+
List patients = toIdListUnqualifiedVersionless(found);
assertThat(patients.toString(), patients, not(hasItems(id2)));
assertThat(patients.toString(), patients, (hasItems(id1a, id1b)));
}
{
- //@formatter:off
Bundle found = ourClient.search()
.forResource(Patient.class)
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
.lastUpdated(new DateRangeParam(null, beforeR2))
+ .returnBundle(Bundle.class)
.execute();
- //@formatter:on
+
List patients = toIdListUnqualifiedVersionless(found);
assertThat(patients, (hasItems(id1a, id1b)));
assertThat(patients, not(hasItems(id2)));
@@ -1985,14 +2022,12 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
Date before = new Date();
Thread.sleep(100);
- //@formatter:off
ca.uhn.fhir.model.dstu2.resource.Bundle found = ourClient
.search()
.forResource(Patient.class)
.prettyPrint()
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
.execute();
- //@formatter:on
Thread.sleep(100);
Date after = new Date();
@@ -2018,23 +2053,22 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
pat.getManagingOrganization().setReference(orgId.toUnqualifiedVersionless());
ourClient.create().resource(pat).prettyPrint().encodedXml().execute().getId();
- //@formatter:off
Bundle found = ourClient
.search()
.forResource(Patient.class)
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("urn:system:rpdstu2","testSearchWithInclude02"))
.include(Patient.INCLUDE_ORGANIZATION)
.prettyPrint()
+ .returnBundle(Bundle.class)
.execute();
- //@formatter:on
assertEquals(2, found.getEntry().size());
assertEquals(Patient.class, found.getEntry().get(0).getResource().getClass());
- assertEquals(BundleEntrySearchModeEnum.MATCH, found.getEntry().get(0).getSearchMode().getValueAsEnum());
+ assertEquals(BundleEntrySearchModeEnum.MATCH, found.getEntry().get(0).getSearch().getModeElement().getValueAsEnum());
assertEquals(BundleEntrySearchModeEnum.MATCH, found.getEntry().get(0).getResource().getResourceMetadata().get(ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE));
assertThat(found.getEntry().get(0).getResource().getText().getDiv().getValueAsString(), containsString(" list = toIdListUnqualifiedVersionless(found);
ourLog.info(methodName + ": " + list.toString());
@@ -2104,15 +2135,14 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
assertThat(list, not(containsInRelativeOrder(orgMissing)));
}
- //@formatter:off
- Bundle found = ourClient
- .search()
- .forResource(Organization.class)
- .where(Organization.NAME.isMissing(true))
- .count(100)
- .prettyPrint()
- .execute();
- //@formatter:on
+ Bundle found = ourClient
+ .search()
+ .forResource(Organization.class)
+ .where(Organization.NAME.isMissing(true))
+ .count(100)
+ .prettyPrint()
+ .returnBundle(Bundle.class)
+ .execute();
List list = toIdListUnqualifiedVersionless(found);
ourLog.info(methodName + " found: " + list.toString() + " - Wanted " + orgMissing + " but not " + orgNotMissing);
@@ -2236,7 +2266,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
p.addName().addGiven("Sarah").addFamily("Graham");
ourClient.create().resource(p).execute();
- //@formatter:off
Bundle resp = ourClient
.search()
.forResource(Patient.class)
@@ -2244,14 +2273,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
.sort().ascending(Patient.FAMILY)
.sort().ascending(Patient.GIVEN)
.count(100)
+ .returnBundle(Bundle.class)
.execute();
- //@formatter:on
List names = toNameList(resp);
ourLog.info(StringUtils.join(names, '\n'));
- //@formatter:off
assertThat(names, contains( // this matches in order only
"Daniel Adams",
"Aaron Alexis",
@@ -2269,7 +2297,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
"Brian Gracia",
"Sarah Graham",
"Stephan Graham"));
- //@formatter:om
}
@@ -2474,7 +2501,15 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
assertThat(p1Id.getValue(), containsString("Patient/testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2/_history"));
- Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2")).encodedJson().prettyPrint().execute();
+ Bundle actual = ourClient
+ .search()
+ .forResource(Patient.class)
+ .where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2"))
+ .encodedJson()
+ .prettyPrint()
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals(1, actual.getEntry().size());
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java
index 7e7252b3e2c..dac4ec41112 100644
--- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java
+++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java
@@ -1,12 +1,13 @@
package ca.uhn.fhir.rest.server;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
@@ -21,10 +22,7 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.*;
import org.mockito.InOrder;
import ca.uhn.fhir.context.FhirContext;
@@ -35,10 +33,7 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.UriDt;
-import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.Read;
-import ca.uhn.fhir.rest.annotation.RequiredParam;
-import ca.uhn.fhir.rest.annotation.Search;
+import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchSearchServerDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchSearchServerDstu1Test.java
deleted file mode 100644
index 566e6c97172..00000000000
--- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchSearchServerDstu1Test.java
+++ /dev/null
@@ -1,700 +0,0 @@
-package ca.uhn.fhir.rest.server;
-
-import static ca.uhn.fhir.util.UrlUtil.escape;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.empty;
-import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.message.BasicNameValuePair;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.servlet.ServletHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.google.common.net.UrlEscapers;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.api.Bundle;
-import ca.uhn.fhir.model.api.IResource;
-import ca.uhn.fhir.model.api.Include;
-import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
-import ca.uhn.fhir.model.base.composite.BaseCodingDt;
-import ca.uhn.fhir.model.dstu.composite.CodingDt;
-import ca.uhn.fhir.model.dstu.resource.BaseResource;
-import ca.uhn.fhir.model.dstu.resource.Observation;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
-import ca.uhn.fhir.rest.annotation.Create;
-import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.IncludeParam;
-import ca.uhn.fhir.rest.annotation.OptionalParam;
-import ca.uhn.fhir.rest.annotation.RequiredParam;
-import ca.uhn.fhir.rest.annotation.ResourceParam;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.api.MethodOutcome;
-import ca.uhn.fhir.rest.client.IGenericClient;
-import ca.uhn.fhir.rest.param.ReferenceParam;
-import ca.uhn.fhir.rest.param.StringAndListParam;
-import ca.uhn.fhir.rest.param.StringOrListParam;
-import ca.uhn.fhir.rest.param.StringParam;
-import ca.uhn.fhir.rest.param.TokenOrListParam;
-import ca.uhn.fhir.rest.param.TokenParam;
-import ca.uhn.fhir.util.PortUtil;
-import ca.uhn.fhir.util.TestUtil;
-
-public class SearchSearchServerDstu1Test {
-
- private static CloseableHttpClient ourClient;
- private static FhirContext ourCtx = FhirContext.forDstu1();
- private static IServerAddressStrategy ourDefaultAddressStrategy;
- private static StringAndListParam ourLastAndList;
-
- private static Set ourLastIncludes;
- private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchSearchServerDstu1Test.class);
- private static int ourPort;
- private static Server ourServer;
- private static RestfulServer ourServlet;
-
- @Before
- public void before() {
- ourServlet.setServerAddressStrategy(ourDefaultAddressStrategy);
- ourLastIncludes = null;
- ourLastAndList = null;
- }
-
- @Test
- public void testEncodeConvertsReferencesToRelative() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef");
- HttpResponse status = ourClient.execute(httpGet);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- ourLog.info(responseContent);
-
- assertEquals(200, status.getStatusLine().getStatusCode());
- Patient patient = (Patient) ourCtx.newXmlParser().parseBundle(responseContent).getEntries().get(0).getResource();
- String ref = patient.getManagingOrganization().getReference().getValue();
- assertEquals("Organization/555", ref);
- }
-
- /**
- * Try loading the page as a POST just to make sure we get the right error
- */
- @Test
- public void testGetPagesWithPost() throws Exception {
-
- HttpPost httpPost = new HttpPost("http://localhost:" + ourPort);
- List extends NameValuePair> parameters = Collections.singletonList(new BasicNameValuePair("_getpages", "AAA"));
- httpPost.setEntity(new UrlEncodedFormEntity(parameters));
-
- CloseableHttpResponse status = ourClient.execute(httpPost);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- ourLog.info(responseContent);
- assertEquals(400, status.getStatusLine().getStatusCode());
-// assertThat(responseContent, containsString("Requests for _getpages must use HTTP GET"));
- }
-
- @Test
- public void testOmitEmptyOptionalParam() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=");
- HttpResponse status = ourClient.execute(httpGet);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
- Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
- assertEquals(1, bundle.getEntries().size());
-
- Patient p = bundle.getResources(Patient.class).get(0);
- assertEquals(null, p.getNameFirstRep().getFamilyFirstRep().getValue());
- }
-
- @Test
- public void testParseEscapedValues() throws Exception {
-
- StringBuilder b = new StringBuilder();
- b.append("http://localhost:");
- b.append(ourPort);
- b.append("/Patient?");
- b.append(escape("findPatientWithAndList")).append('=').append(escape("NE\\,NE,NE\\,NE")).append('&');
- b.append(escape("findPatientWithAndList")).append('=').append(escape("NE\\\\NE")).append('&');
- b.append(escape("findPatientWithAndList:exact")).append('=').append(escape("E\\$E")).append('&');
- b.append(escape("findPatientWithAndList:exact")).append('=').append(escape("E\\|E")).append('&');
-
- HttpGet httpGet = new HttpGet(b.toString());
-
- HttpResponse status = ourClient.execute(httpGet);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- ourLog.info(responseContent);
-
- assertEquals(200, status.getStatusLine().getStatusCode());
-
- assertEquals(4, ourLastAndList.getValuesAsQueryTokens().size());
- assertEquals(2, ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().size());
- assertFalse(ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).isExact());
- assertEquals("NE,NE", ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue());
- assertEquals("NE,NE", ourLastAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(1).getValue());
- assertEquals("NE\\NE", ourLastAndList.getValuesAsQueryTokens().get(1).getValuesAsQueryTokens().get(0).getValue());
- assertTrue(ourLastAndList.getValuesAsQueryTokens().get(2).getValuesAsQueryTokens().get(0).isExact());
- assertEquals("E$E", ourLastAndList.getValuesAsQueryTokens().get(2).getValuesAsQueryTokens().get(0).getValue());
- assertEquals("E|E", ourLastAndList.getValuesAsQueryTokens().get(3).getValuesAsQueryTokens().get(0).getValue());
- }
-
- @Test
- public void testReturnLinks() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findWithLinks");
-
- CloseableHttpResponse status = ourClient.execute(httpGet);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
- Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
- assertEquals(10, bundle.getEntries().size());
-
- Patient p = bundle.getResources(Patient.class).get(0);
- assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
- assertEquals("http://foo/Patient?_id=1", bundle.getEntries().get(0).getLinkSearch().getValue());
- assertEquals("http://localhost:" + ourPort + "/Patient/99881", bundle.getEntries().get(0).getLinkAlternate().getValue());
-
- assertEquals("http://foo/Patient?_id=1", ResourceMetadataKeyEnum.LINK_SEARCH.get(p));
- assertEquals("http://localhost:" + ourPort + "/Patient/99881", ResourceMetadataKeyEnum.LINK_ALTERNATE.get(p));
-
- }
-
- /**
- * #149
- */
- @Test
- public void testReturnLinksWithAddressStrategy() throws Exception {
- ourServlet.setServerAddressStrategy(new HardcodedServerAddressStrategy("https://blah.com/base"));
-
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findWithLinks");
-
- CloseableHttpResponse status = ourClient.execute(httpGet);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
- Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
-
- ourLog.info(responseContent);
-
- assertEquals(10, bundle.getEntries().size());
- assertEquals("https://blah.com/base", bundle.getLinkBase().getValue());
- assertEquals("https://blah.com/base/Patient?_query=findWithLinks", bundle.getLinkSelf().getValue());
-
- Patient p = bundle.getResources(Patient.class).get(0);
- assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
- assertEquals("http://foo/Patient?_id=1", bundle.getEntries().get(0).getLinkSearch().getValue());
- assertEquals("https://blah.com/base/Patient/99881", bundle.getEntries().get(0).getLinkAlternate().getValue());
- assertEquals("http://foo/Patient?_id=1", ResourceMetadataKeyEnum.LINK_SEARCH.get(p));
- assertEquals("https://blah.com/base/Patient/99881", ResourceMetadataKeyEnum.LINK_ALTERNATE.get(p));
-
- String linkNext = bundle.getLinkNext().getValue();
- ourLog.info(linkNext);
- assertThat(linkNext, startsWith("https://blah.com/base?_getpages="));
-
- /*
- * Load the second page
- */
- String urlPart = linkNext.substring(linkNext.indexOf('?'));
- String link = "http://localhost:" + ourPort + urlPart;
- httpGet = new HttpGet(link);
-
- status = ourClient.execute(httpGet);
- responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
- bundle = ourCtx.newXmlParser().parseBundle(responseContent);
-
- ourLog.info(responseContent);
-
- assertEquals(10, bundle.getEntries().size());
- assertEquals("https://blah.com/base", bundle.getLinkBase().getValue());
- assertEquals(linkNext, bundle.getLinkSelf().getValue());
-
- p = bundle.getResources(Patient.class).get(0);
- assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
- assertEquals("http://foo/Patient?_id=11", bundle.getEntries().get(0).getLinkSearch().getValue());
- assertEquals("https://blah.com/base/Patient/998811", bundle.getEntries().get(0).getLinkAlternate().getValue());
- assertEquals("http://foo/Patient?_id=11", ResourceMetadataKeyEnum.LINK_SEARCH.get(p));
- assertEquals("https://blah.com/base/Patient/998811", ResourceMetadataKeyEnum.LINK_ALTERNATE.get(p));
-
- }
-
- @Test
- public void testSearchById() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=aaa");
- HttpResponse status = ourClient.execute(httpGet);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
- Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
- assertEquals(1, bundle.getEntries().size());
-
- Patient p = bundle.getResources(Patient.class).get(0);
- assertEquals("idaaa", p.getNameFirstRep().getFamilyAsSingleString());
- }
-
- @Test
- public void testSearchByIdUsingClient() throws Exception {
- IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort);
-
- Bundle bundle = client.search().forResource("Patient").where(BaseResource.RES_ID.matches().value("aaa")).execute();
- assertEquals(1, bundle.getEntries().size());
-
- Patient p = bundle.getResources(Patient.class).get(0);
- assertEquals("idaaa", p.getNameFirstRep().getFamilyAsSingleString());
- }
-
- @Test
- public void testSearchByPost() throws Exception {
- HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient/_search");
-
- // add parameters to the post method
- List parameters = new ArrayList();
- parameters.add(new BasicNameValuePair("_id", "aaa"));
-
- UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, "UTF-8");
- filePost.setEntity(sendentity);
-
- HttpResponse status = ourClient.execute(filePost);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
- Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
- assertEquals(1, bundle.getEntries().size());
-
- Patient p = bundle.getResources(Patient.class).get(0);
- assertEquals("idaaa", p.getNameFirstRep().getFamilyAsSingleString());
- }
-
- /**
- * See #164
- */
- @Test
- public void testSearchByPostWithInvalidPostUrl() throws Exception {
- HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient?name=Central"); // should end with
- // _search
-
- // add parameters to the post method
- List parameters = new ArrayList();
- parameters.add(new BasicNameValuePair("_id", "aaa"));
-
- UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, "UTF-8");
- filePost.setEntity(sendentity);
-
- HttpResponse status = ourClient.execute(filePost);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- ourLog.info(responseContent);
- assertEquals(400, status.getStatusLine().getStatusCode());
- assertThat(responseContent, containsString(" "));
- }
-
- /**
- * See #164
- */
- @Test
- public void testSearchByPostWithMissingContentType() throws Exception {
- HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient?name=Central"); // should end with
- // _search
-
- HttpEntity sendentity = new ByteArrayEntity(new byte[] { 1, 2, 3, 4 });
- filePost.setEntity(sendentity);
-
- HttpResponse status = ourClient.execute(filePost);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- ourLog.info(responseContent);
- assertEquals(400, status.getStatusLine().getStatusCode());
- assertThat(responseContent, containsString(" "));
- }
-
- /**
- * See #164
- */
- @Test
- public void testSearchByPostWithParamsInBodyAndUrl() throws Exception {
- HttpPost filePost = new HttpPost("http://localhost:" + ourPort + "/Patient/_search?name=Central");
-
- // add parameters to the post method
- List parameters = new ArrayList();
- parameters.add(new BasicNameValuePair("_id", "aaa"));
-
- UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, "UTF-8");
- filePost.setEntity(sendentity);
-
- HttpResponse status = ourClient.execute(filePost);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- ourLog.info(responseContent);
- assertEquals(200, status.getStatusLine().getStatusCode());
-
- Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
- assertEquals(1, bundle.getEntries().size());
-
- Patient p = bundle.getResources(Patient.class).get(0);
- assertEquals("idaaa", p.getName().get(0).getFamilyAsSingleString());
- assertEquals("nameCentral", p.getName().get(1).getFamilyAsSingleString());
-
- }
-
- @Test
- public void testSearchCompartment() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/fooCompartment");
- HttpResponse status = ourClient.execute(httpGet);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- ourLog.info(responseContent);
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
- Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
- assertEquals(1, bundle.getEntries().size());
-
- Patient p = bundle.getResources(Patient.class).get(0);
- assertEquals("fooCompartment", p.getIdentifierFirstRep().getValue().getValue());
- assertThat(bundle.getEntries().get(0).getResource().getId().getValue(), containsString("Patient/123"));
- }
-
- @Test
- public void testSearchGetWithUnderscoreSearch() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Observation/_search?subject%3APatient=100&name=3141-9%2C8302-2%2C8287-5%2C39156-5");
-
- HttpResponse status = ourClient.execute(httpGet);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
-
- assertEquals(200, status.getStatusLine().getStatusCode());
- Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
- assertEquals(1, bundle.getEntries().size());
-
- Observation p = bundle.getResources(Observation.class).get(0);
- assertEquals("Patient/100", p.getSubject().getReference().toString());
- assertEquals(4, p.getName().getCoding().size());
- assertEquals("3141-9", p.getName().getCoding().get(0).getCode().getValue());
- assertEquals("8302-2", p.getName().getCoding().get(1).getCode().getValue());
-
- }
-
- @Test
- public void testSearchIncludesParametersIncludes() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchIncludes&_include=foo&_include:recurse=bar");
-
- CloseableHttpResponse status = ourClient.execute(httpGet);
- IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
-
- assertEquals(2, ourLastIncludes.size());
- assertThat(ourLastIncludes, containsInAnyOrder(new Include("foo", false), new Include("bar", true)));
- }
-
- @Test
- public void testSearchIncludesParametersIncludesList() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchIncludesList&_include=foo&_include:recurse=bar");
-
- CloseableHttpResponse status = ourClient.execute(httpGet);
- IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
-
- assertEquals(2, ourLastIncludes.size());
- assertThat(ourLastIncludes, containsInAnyOrder(new Include("foo", false), new Include("bar", true)));
- }
-
- @Test
- public void testSearchIncludesParametersNone() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchIncludes");
-
- CloseableHttpResponse status = ourClient.execute(httpGet);
- IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
-
- assertThat(ourLastIncludes, empty());
- }
-
- @Test
- public void testSearchWithOrList() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?findPatientWithOrList=aaa,bbb");
- HttpResponse status = ourClient.execute(httpGet);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
- Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
- assertEquals(1, bundle.getEntries().size());
-
- Patient p = bundle.getResources(Patient.class).get(0);
- assertEquals("aaa", p.getIdentifier().get(0).getValue().getValue());
- assertEquals("bbb", p.getIdentifier().get(1).getValue().getValue());
- }
-
- @Test
- public void testSearchWithTokenParameter() throws Exception {
- String token = UrlEscapers.urlFragmentEscaper().asFunction().apply("http://www.dmix.gov/vista/2957|301");
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?tokenParam=" + token);
- HttpResponse status = ourClient.execute(httpGet);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
- Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
- assertEquals(1, bundle.getEntries().size());
-
- Patient p = bundle.getResources(Patient.class).get(0);
- assertEquals("http://www.dmix.gov/vista/2957", p.getNameFirstRep().getFamilyAsSingleString());
- assertEquals("301", p.getNameFirstRep().getGivenAsSingleString());
- }
-
- @Test
- public void testSpecificallyNamedQueryGetsPrecedence() throws Exception {
- HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?AAA=123");
-
- HttpResponse status = ourClient.execute(httpGet);
- String responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
- Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
- assertEquals(1, bundle.getEntries().size());
-
- Patient p = bundle.getResources(Patient.class).get(0);
- assertEquals("AAA", p.getIdentifierFirstRep().getValue().getValue());
-
- // Now the named query
-
- httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findPatientByAAA&AAA=123");
-
- status = ourClient.execute(httpGet);
- responseContent = IOUtils.toString(status.getEntity().getContent());
- IOUtils.closeQuietly(status.getEntity().getContent());
- assertEquals(200, status.getStatusLine().getStatusCode());
- bundle = ourCtx.newXmlParser().parseBundle(responseContent);
- assertEquals(1, bundle.getEntries().size());
-
- p = bundle.getResources(Patient.class).get(0);
- assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
- }
-
-
- @AfterClass
- public static void afterClassClearContext() throws Exception {
- ourServer.stop();
- TestUtil.clearAllStaticFieldsForUnitTest();
- }
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- ourPort = PortUtil.findFreePort();
- ourServer = new Server(ourPort);
-
- DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
-
- ServletHandler proxyHandler = new ServletHandler();
- ourServlet = new RestfulServer();
- ourServlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
- ourServlet.setPagingProvider(new FifoMemoryPagingProvider(10).setDefaultPageSize(10));
-
- ourServlet.setResourceProviders(patientProvider, new DummyObservationResourceProvider());
- ServletHolder servletHolder = new ServletHolder(ourServlet);
- proxyHandler.addServletWithMapping(servletHolder, "/*");
- ourServer.setHandler(proxyHandler);
- ourServer.start();
-
- PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
- HttpClientBuilder builder = HttpClientBuilder.create();
- builder.setConnectionManager(connectionManager);
- ourClient = builder.build();
-
- ourDefaultAddressStrategy = ourServlet.getServerAddressStrategy();
- }
-
- public static class DummyObservationResourceProvider implements IResourceProvider {
-
- @Override
- public Class extends IResource> getResourceType() {
- return Observation.class;
- }
-
- @Search
- public Observation search(@RequiredParam(name = "subject") ReferenceParam theSubject, @RequiredParam(name = "name") TokenOrListParam theName) {
- Observation o = new Observation();
- o.setId("1");
-
- o.getSubject().setReference(theSubject.getResourceType() + "/" + theSubject.getIdPart());
- for (BaseCodingDt next : theName.getListAsCodings()) {
- o.getName().getCoding().add(new CodingDt(next));
- }
-
- return o;
- }
-
- }
-
-
- public static class DummyPatientResourceProvider implements IResourceProvider {
-
- @Search(compartmentName = "fooCompartment")
- public List compartment(@IdParam IdDt theId) {
- ArrayList retVal = new ArrayList();
-
- Patient patient = new Patient();
- patient.setId(theId);
- patient.addIdentifier("system", "fooCompartment");
- retVal.add(patient);
- return retVal;
- }
-
- /**
- * Only needed for #164
- */
- @Create
- public MethodOutcome create(@ResourceParam Patient thePatient) {
- throw new IllegalArgumentException();
- }
-
- @Search
- public List findPatient(@RequiredParam(name = "_id") StringParam theParam, @OptionalParam(name = "name") StringParam theName) {
- ArrayList retVal = new ArrayList();
-
- Patient patient = new Patient();
- patient.setId("1");
- patient.addIdentifier("system", "identifier123");
- if (theParam != null) {
- patient.addName().addFamily("id" + theParam.getValue());
- if (theName != null) {
- patient.addName().addFamily("name" + theName.getValue());
- }
- }
- retVal.add(patient);
- return retVal;
- }
-
- @Search
- public List findPatientByAAA01(@RequiredParam(name = "AAA") StringParam theParam) {
- ArrayList retVal = new ArrayList();
-
- Patient patient = new Patient();
- patient.setId("1");
- patient.addIdentifier("system", "AAA");
- retVal.add(patient);
- return retVal;
- }
-
- @Search(queryName = "findPatientByAAA")
- public List findPatientByAAA02Named(@OptionalParam(name = "AAA") StringParam theParam) {
- ArrayList retVal = new ArrayList();
-
- Patient patient = new Patient();
- patient.setId("1");
- patient.addIdentifier("system", "AAANamed");
- retVal.add(patient);
- return retVal;
- }
-
- @Search()
- public List findPatientWithAndList(@RequiredParam(name = "findPatientWithAndList") StringAndListParam theParam) {
- ourLastAndList = theParam;
- ArrayList retVal = new ArrayList();
- return retVal;
- }
-
- @Search()
- public List findPatientWithOrList(@RequiredParam(name = "findPatientWithOrList") StringOrListParam theParam) {
- ArrayList retVal = new ArrayList();
-
- Patient patient = new Patient();
- patient.setId("1");
- for (StringParam next : theParam.getValuesAsQueryTokens()) {
- patient.addIdentifier("system", next.getValue());
- }
- retVal.add(patient);
- return retVal;
- }
-
- @Search()
- public List findPatientWithToken(@RequiredParam(name = "tokenParam") TokenParam theParam) {
- ArrayList retVal = new ArrayList();
-
- Patient patient = new Patient();
- patient.setId("1");
- patient.addName().addFamily(theParam.getSystem()).addGiven(theParam.getValue());
- retVal.add(patient);
- return retVal;
- }
-
- @Search(queryName = "findWithLinks")
- public List findWithLinks() {
- ArrayList retVal = new ArrayList();
-
- for (int i = 1; i <= 20; i++) {
- Patient patient = new Patient();
- patient.setId("" + i);
- patient.addIdentifier("system", "AAANamed");
- ResourceMetadataKeyEnum.LINK_SEARCH.put(patient, ("http://foo/Patient?_id=" + i));
- ResourceMetadataKeyEnum.LINK_ALTERNATE.put(patient, ("Patient/9988" + i));
- retVal.add(patient);
- }
-
- return retVal;
- }
-
- @Override
- public Class extends IResource> getResourceType() {
- return Patient.class;
- }
-
- @Search(queryName = "searchIncludes")
- public List searchIncludes(@IncludeParam Set theIncludes) {
- ourLastIncludes = theIncludes;
-
- ArrayList retVal = new ArrayList();
- return retVal;
- }
-
- @Search(queryName = "searchIncludesList")
- public List searchIncludesList(@IncludeParam List theIncludes) {
- if (theIncludes != null) {
- ourLastIncludes = new HashSet(theIncludes);
- }
-
- ArrayList retVal = new ArrayList();
- return retVal;
- }
-
- @Search(queryName = "searchWithRef")
- public Patient searchWithRef() {
- Patient patient = new Patient();
- patient.setId("Patient/1/_history/1");
- patient.getManagingOrganization().setReference("http://localhost:" + ourPort + "/Organization/555/_history/666");
- return patient;
- }
-
- }
-
-}
diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/org/hl7/fhir/dstu2016may/hapi/rest/server/Dstu2_1BundleFactory.java b/hapi-fhir-structures-dstu2.1/src/main/java/org/hl7/fhir/dstu2016may/hapi/rest/server/Dstu2_1BundleFactory.java
index 05812227f76..dfc86d1d2e4 100644
--- a/hapi-fhir-structures-dstu2.1/src/main/java/org/hl7/fhir/dstu2016may/hapi/rest/server/Dstu2_1BundleFactory.java
+++ b/hapi-fhir-structures-dstu2.1/src/main/java/org/hl7/fhir/dstu2016may/hapi/rest/server/Dstu2_1BundleFactory.java
@@ -265,11 +265,6 @@ public class Dstu2_1BundleFactory implements IVersionSpecificBundleFactory {
}
}
- @Override
- public ca.uhn.fhir.model.api.Bundle getDstu1Bundle() {
- return null;
- }
-
@Override
public IBaseResource getResourceBundle() {
return myBundle;
diff --git a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2_1Test.java b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2_1Test.java
index ef1dd6d2433..7a7a7c81413 100644
--- a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2_1Test.java
+++ b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2_1Test.java
@@ -122,10 +122,10 @@ public class GenericClientDstu2_1Test {
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
MethodOutcome outcome = client
- .patch()
- .withBody(patch)
- .withId("Patient/123")
- .execute();
+ .patch()
+ .withBody(patch)
+ .withId("Patient/123")
+ .execute();
assertEquals("http://example.com/fhir/Patient/123", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
@@ -136,6 +136,7 @@ public class GenericClientDstu2_1Test {
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
}
+
@Test
public void testPatchJsonByIdType() throws Exception {
OperationOutcome conf = new OperationOutcome();
@@ -159,10 +160,10 @@ public class GenericClientDstu2_1Test {
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
MethodOutcome outcome = client
- .patch()
- .withBody(patch)
- .withId(new IdType("http://localhost/fhir/Patient/123/_history/234"))
- .execute();
+ .patch()
+ .withBody(patch)
+ .withId(new IdType("http://localhost/fhir/Patient/123/_history/234"))
+ .execute();
assertEquals("http://example.com/fhir/Patient/123", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
@@ -173,6 +174,7 @@ public class GenericClientDstu2_1Test {
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
}
+
@Test
public void testPatchJsonByConditionalString() throws Exception {
OperationOutcome conf = new OperationOutcome();
@@ -196,10 +198,10 @@ public class GenericClientDstu2_1Test {
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
MethodOutcome outcome = client
- .patch()
- .withBody(patch)
- .conditionalByUrl("Patient?foo=bar")
- .execute();
+ .patch()
+ .withBody(patch)
+ .conditionalByUrl("Patient?foo=bar")
+ .execute();
assertEquals("http://example.com/fhir/Patient?foo=bar", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
@@ -210,6 +212,7 @@ public class GenericClientDstu2_1Test {
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
}
+
@Test
public void testPatchJsonByConditionalParam() throws Exception {
OperationOutcome conf = new OperationOutcome();
@@ -233,11 +236,11 @@ public class GenericClientDstu2_1Test {
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
MethodOutcome outcome = client
- .patch()
- .withBody(patch)
- .conditional("Patient").where(Patient.NAME.matches().value("TEST"))
- .and(Patient.FAMILY.matches().value("TEST2"))
- .execute();
+ .patch()
+ .withBody(patch)
+ .conditional("Patient").where(Patient.NAME.matches().value("TEST"))
+ .and(Patient.FAMILY.matches().value("TEST2"))
+ .execute();
assertEquals("http://example.com/fhir/Patient?name=TEST&family=TEST2", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
@@ -248,6 +251,7 @@ public class GenericClientDstu2_1Test {
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
}
+
@Test
public void testPatchJsonByConditionalParamResourceType() throws Exception {
OperationOutcome conf = new OperationOutcome();
@@ -271,11 +275,11 @@ public class GenericClientDstu2_1Test {
String patch = "[ { \"op\":\"replace\", \"path\":\"/active\", \"value\":false } ]";
MethodOutcome outcome = client
- .patch()
- .withBody(patch)
- .conditional(Patient.class).where(Patient.NAME.matches().value("TEST"))
- .and(Patient.FAMILY.matches().value("TEST2"))
- .execute();
+ .patch()
+ .withBody(patch)
+ .conditional(Patient.class).where(Patient.NAME.matches().value("TEST"))
+ .and(Patient.FAMILY.matches().value("TEST2"))
+ .execute();
assertEquals("http://example.com/fhir/Patient?name=TEST&family=TEST2", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
@@ -286,6 +290,7 @@ public class GenericClientDstu2_1Test {
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
}
+
@Test
public void testPatchXmlByIdString() throws Exception {
OperationOutcome conf = new OperationOutcome();
@@ -309,10 +314,10 @@ public class GenericClientDstu2_1Test {
String patch = "false";
MethodOutcome outcome = client
- .patch()
- .withBody(patch)
- .withId("Patient/123")
- .execute();
+ .patch()
+ .withBody(patch)
+ .withId("Patient/123")
+ .execute();
assertEquals("http://example.com/fhir/Patient/123", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
assertEquals("PATCH", capt.getAllValues().get(0).getRequestLine().getMethod());
@@ -330,10 +335,10 @@ public class GenericClientDstu2_1Test {
try {
client
- .patch()
- .withBody("AA")
- .withId("Patient/123")
- .execute();
+ .patch()
+ .withBody("AA")
+ .withId("Patient/123")
+ .execute();
} catch (IllegalArgumentException e) {
assertEquals("Unable to determine encoding of patch", e.getMessage());
}
@@ -357,24 +362,22 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int idx = 0;
-
client.setEncoding(EncodingEnum.JSON);
client.search()
- .forResource("Device")
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Device")
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Device?_format=json", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
assertEquals(Constants.CT_FHIR_JSON, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_ACCEPT).getValue());
idx++;
-
client.setEncoding(EncodingEnum.XML);
client.search()
- .forResource("Device")
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Device")
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Device?_format=xml", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
assertEquals(Constants.CT_FHIR_XML, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_ACCEPT).getValue());
idx++;
@@ -460,8 +463,6 @@ public class GenericClientDstu2_1Test {
}
-
-
@SuppressWarnings("unchecked")
@Test
public void testClientFailures() throws Exception {
@@ -512,13 +513,11 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
client.registerInterceptor(new CookieInterceptor("foo=bar"));
-
Bundle resp = client
- .history()
- .onType(Patient.class)
- .andReturnBundle(Bundle.class)
- .execute();
-
+ .history()
+ .onType(Patient.class)
+ .andReturnBundle(Bundle.class)
+ .execute();
assertEquals("foo=bar", capt.getAllValues().get(0).getFirstHeader("Cookie").getValue());
}
@@ -633,13 +632,11 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
-
Bundle resp = client
- .history()
- .onType(CustomTypeDstu2_1Test.MyCustomPatient.class)
- .andReturnBundle(Bundle.class)
- .execute();
-
+ .history()
+ .onType(CustomTypeDstu2_1Test.MyCustomPatient.class)
+ .andReturnBundle(Bundle.class)
+ .execute();
assertEquals(1, resp.getEntry().size());
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
@@ -664,25 +661,21 @@ public class GenericClientDstu2_1Test {
Bundle bundle = new Bundle();
bundle.addLink().setRelation("next").setUrl("http://foo/next");
-
Bundle resp = client
- .loadPage()
- .next(bundle)
- .preferResponseType(MyCustomPatient.class)
- .execute();
-
+ .loadPage()
+ .next(bundle)
+ .preferResponseType(MyCustomPatient.class)
+ .execute();
assertEquals(1, resp.getEntry().size());
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
assertEquals("http://foo/next", capt.getAllValues().get(0).getURI().toASCIIString());
-
resp = client
- .loadPage()
- .next(bundle)
- .preferResponseTypes(toTypeList(MyCustomPatient.class))
- .execute();
-
+ .loadPage()
+ .next(bundle)
+ .preferResponseTypes(toTypeList(MyCustomPatient.class))
+ .execute();
assertEquals(1, resp.getEntry().size());
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
@@ -711,28 +704,24 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
-
Parameters resp = client
- .operation()
- .onServer()
- .named("foo")
- .withNoParameters(Parameters.class)
- .preferResponseType(MyCustomPatient.class)
- .execute();
-
+ .operation()
+ .onServer()
+ .named("foo")
+ .withNoParameters(Parameters.class)
+ .preferResponseType(MyCustomPatient.class)
+ .execute();
assertEquals(1, resp.getParameter().size());
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getParameter().get(0).getResource().getClass());
assertEquals("http://example.com/fhir/$foo", capt.getAllValues().get(0).getURI().toASCIIString());
-
resp = client
- .operation()
- .onType(MyCustomPatient.class)
- .named("foo")
- .withNoParameters(Parameters.class)
- .execute();
-
+ .operation()
+ .onType(MyCustomPatient.class)
+ .named("foo")
+ .withNoParameters(Parameters.class)
+ .execute();
assertEquals(1, resp.getParameter().size());
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getParameter().get(0).getResource().getClass());
@@ -755,13 +744,11 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
-
Bundle resp = client
- .search()
- .forResource(CustomTypeDstu2_1Test.MyCustomPatient.class)
- .returnBundle(Bundle.class)
- .execute();
-
+ .search()
+ .forResource(CustomTypeDstu2_1Test.MyCustomPatient.class)
+ .returnBundle(Bundle.class)
+ .execute();
assertEquals(1, resp.getEntry().size());
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
@@ -966,18 +953,6 @@ public class GenericClientDstu2_1Test {
}
- @SuppressWarnings("deprecation")
- @Test
- public void testInvalidConformanceCall() {
- IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
- try {
- client.conformance();
- fail();
- } catch (IllegalArgumentException e) {
- assertEquals("Must call fetchConformance() instead of conformance() for RI/STU3+ structures", e.getMessage());
- }
- }
-
/**
* See #150
*/
@@ -988,41 +963,35 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int idx = 0;
-
- client
- .search()
- .forResource(Patient.class)
- .where(Patient.FAMILY.matches().value((String)null))
- .and(Patient.BIRTHDATE.exactly().day((Date)null))
- .and(Patient.GENDER.exactly().code((String)null))
- .and(Patient.ORGANIZATION.hasId((String)null))
- .returnBundle(Bundle.class)
- .execute();
-
+ client
+ .search()
+ .forResource(Patient.class)
+ .where(Patient.FAMILY.matches().value((String) null))
+ .and(Patient.BIRTHDATE.exactly().day((Date) null))
+ .and(Patient.GENDER.exactly().code((String) null))
+ .and(Patient.ORGANIZATION.hasId((String) null))
+ .returnBundle(Bundle.class)
+ .execute();
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(idx).getURI().toString());
idx++;
-
- client
- .search()
- .forResource(Encounter.class)
- .where(Encounter.LENGTH.exactly().number(null))
- .returnBundle(Bundle.class)
- .execute();
-
+ client
+ .search()
+ .forResource(Encounter.class)
+ .where(Encounter.LENGTH.exactly().number(null))
+ .returnBundle(Bundle.class)
+ .execute();
assertEquals("http://example.com/fhir/Encounter", capt.getAllValues().get(idx).getURI().toString());
idx++;
-
- client
- .search()
- .forResource(Observation.class)
- .where(Observation.VALUE_QUANTITY.exactly().number(null).andUnits(null))
- .returnBundle(Bundle.class)
- .execute();
-
+ client
+ .search()
+ .forResource(Observation.class)
+ .where(Observation.VALUE_QUANTITY.exactly().number(null).andUnits(null))
+ .returnBundle(Bundle.class)
+ .execute();
assertEquals("http://example.com/fhir/Observation", capt.getAllValues().get(idx).getURI().toString());
idx++;
@@ -1058,13 +1027,12 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int idx = 0;
-
client
- .update()
- .resource(bundle)
- .prefer(PreferReturnEnum.REPRESENTATION)
- .encodedJson()
- .execute();
+ .update()
+ .resource(bundle)
+ .prefer(PreferReturnEnum.REPRESENTATION)
+ .encodedJson()
+ .execute();
HttpPut httpRequest = (HttpPut) capt.getValue();
assertEquals("http://example.com/fhir/Bundle/BUNDLE1", httpRequest.getURI().toASCIIString());
@@ -1086,7 +1054,9 @@ public class GenericClientDstu2_1Test {
bundle.addEntry().setResource(patient);
final String encoded = p.encodeResourceToString(bundle);
- assertEquals("", encoded);
+ assertEquals(
+ "",
+ encoded);
ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
@@ -1102,12 +1072,11 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int idx = 0;
-
client
- .update()
- .resource(bundle)
- .prefer(PreferReturnEnum.REPRESENTATION)
- .execute();
+ .update()
+ .resource(bundle)
+ .prefer(PreferReturnEnum.REPRESENTATION)
+ .execute();
HttpPut httpRequest = (HttpPut) capt.getValue();
assertEquals("http://example.com/fhir/Bundle/BUNDLE1", httpRequest.getURI().toASCIIString());
@@ -1132,7 +1101,9 @@ public class GenericClientDstu2_1Test {
client.read().resource("Patient").withId("123").elementsSubset("name", "identifier").execute();
fail();
} catch (FhirClientConnectionException e) {
- assertEquals("Failed to parse response from server when performing GET to URL http://example.com/fhir/Patient/123?_elements=identifier%2Cname - ca.uhn.fhir.parser.DataFormatException: Invalid JSON content detected, missing required element: 'resourceType'", e.getMessage());
+ assertEquals(
+ "Failed to parse response from server when performing GET to URL http://example.com/fhir/Patient/123?_elements=identifier%2Cname - ca.uhn.fhir.parser.DataFormatException: Invalid JSON content detected, missing required element: 'resourceType'",
+ e.getMessage());
}
}
@@ -1146,7 +1117,7 @@ public class GenericClientDstu2_1Test {
ArgumentCaptor 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_XML + "; charset=UTF-8"));
+ // when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(null);
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer() {
@Override
@@ -1163,8 +1134,8 @@ public class GenericClientDstu2_1Test {
assertEquals("Response contains no Content-Type", e.getMessage());
}
- // Patient resp = client.read().resource(Patient.class).withId("1").execute();
- // assertEquals("FAM", resp.getNameFirstRep().getFamilyAsSingleString());
+ // Patient resp = client.read().resource(Patient.class).withId("1").execute();
+ // assertEquals("FAM", resp.getNameFirstRep().getFamilyAsSingleString());
}
@Test
@@ -1178,7 +1149,7 @@ public class GenericClientDstu2_1Test {
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", "text/plain"));
- // when(myHttpResponse.getEntity().getContentType()).thenReturn(null);
+ // when(myHttpResponse.getEntity().getContentType()).thenReturn(null);
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable {
@@ -1194,8 +1165,8 @@ public class GenericClientDstu2_1Test {
assertEquals("Response contains non FHIR Content-Type 'text/plain' : ", e.getMessage());
}
- // Patient resp = client.read().resource(Patient.class).withId("1").execute();
- // assertEquals("FAM", resp.getNameFirstRep().getFamilyAsSingleString());
+ // Patient resp = client.read().resource(Patient.class).withId("1").execute();
+ // assertEquals("FAM", resp.getNameFirstRep().getFamilyAsSingleString());
}
@Test
@@ -1219,93 +1190,84 @@ public class GenericClientDstu2_1Test {
DateTimeDt now = DateTimeDt.withCurrentTime();
String dateString = now.getValueAsString().substring(0, 10);
-
client.search()
- .forResource("Patient")
- .where(Patient.BIRTHDATE.after().day(dateString))
- .returnBundle(Bundle.class)
- .execute();
-
- assertEquals("http://example.com/fhir/Patient?birthdate=gt"+dateString, capt.getAllValues().get(idx).getURI().toString());
+ .forResource("Patient")
+ .where(Patient.BIRTHDATE.after().day(dateString))
+ .returnBundle(Bundle.class)
+ .execute();
+
+ assertEquals("http://example.com/fhir/Patient?birthdate=gt" + dateString, capt.getAllValues().get(idx).getURI().toString());
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.BIRTHDATE.after().day(now.getValue()))
- .returnBundle(Bundle.class)
- .execute();
-
- assertEquals("http://example.com/fhir/Patient?birthdate=gt"+dateString, capt.getAllValues().get(idx).getURI().toString());
+ .forResource("Patient")
+ .where(Patient.BIRTHDATE.after().day(now.getValue()))
+ .returnBundle(Bundle.class)
+ .execute();
+
+ assertEquals("http://example.com/fhir/Patient?birthdate=gt" + dateString, capt.getAllValues().get(idx).getURI().toString());
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.BIRTHDATE.afterOrEquals().day(dateString))
- .returnBundle(Bundle.class)
- .execute();
-
- assertEquals("http://example.com/fhir/Patient?birthdate=ge"+dateString, capt.getAllValues().get(idx).getURI().toString());
+ .forResource("Patient")
+ .where(Patient.BIRTHDATE.afterOrEquals().day(dateString))
+ .returnBundle(Bundle.class)
+ .execute();
+
+ assertEquals("http://example.com/fhir/Patient?birthdate=ge" + dateString, capt.getAllValues().get(idx).getURI().toString());
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.BIRTHDATE.before().day(dateString))
- .returnBundle(Bundle.class)
- .execute();
-
- assertEquals("http://example.com/fhir/Patient?birthdate=lt"+dateString, capt.getAllValues().get(idx).getURI().toString());
+ .forResource("Patient")
+ .where(Patient.BIRTHDATE.before().day(dateString))
+ .returnBundle(Bundle.class)
+ .execute();
+
+ assertEquals("http://example.com/fhir/Patient?birthdate=lt" + dateString, capt.getAllValues().get(idx).getURI().toString());
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.BIRTHDATE.beforeOrEquals().day(dateString))
- .returnBundle(Bundle.class)
- .execute();
-
- assertEquals("http://example.com/fhir/Patient?birthdate=le"+dateString, capt.getAllValues().get(idx).getURI().toString());
+ .forResource("Patient")
+ .where(Patient.BIRTHDATE.beforeOrEquals().day(dateString))
+ .returnBundle(Bundle.class)
+ .execute();
+
+ assertEquals("http://example.com/fhir/Patient?birthdate=le" + dateString, capt.getAllValues().get(idx).getURI().toString());
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.BIRTHDATE.exactly().day(dateString))
- .returnBundle(Bundle.class)
- .execute();
-
- assertEquals("http://example.com/fhir/Patient?birthdate="+dateString, capt.getAllValues().get(idx).getURI().toString());
+ .forResource("Patient")
+ .where(Patient.BIRTHDATE.exactly().day(dateString))
+ .returnBundle(Bundle.class)
+ .execute();
+
+ assertEquals("http://example.com/fhir/Patient?birthdate=" + dateString, capt.getAllValues().get(idx).getURI().toString());
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.BIRTHDATE.after().second("2011-01-02T22:33:01Z"))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.BIRTHDATE.after().second("2011-01-02T22:33:01Z"))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Patient?birthdate=gt2011-01-02T22:33:01Z", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.BIRTHDATE.after().second(now.getValueAsString()))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.BIRTHDATE.after().second(now.getValueAsString()))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + now.getValueAsString(), UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.BIRTHDATE.after().now())
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.BIRTHDATE.after().now())
+ .returnBundle(Bundle.class)
+ .execute();
+
assertThat(capt.getAllValues().get(idx).getURI().toString(), startsWith("http://example.com/fhir/Patient?birthdate=gt2"));
dateString = UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()).substring(44);
ourLog.info(dateString);
@@ -1332,113 +1294,102 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int idx = 0;
-
client.search()
- .forResource("Observation")
- .where(Observation.VALUE_QUANTITY.approximately().number(123).andNoUnits())
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Observation")
+ .where(Observation.VALUE_QUANTITY.approximately().number(123).andNoUnits())
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Observation")
- .where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("CODE"))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Observation")
+ .where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("CODE"))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123||CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Observation")
- .where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("SYSTEM", "CODE"))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Observation")
+ .where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("SYSTEM", "CODE"))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123|SYSTEM|CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Observation")
- .where(Observation.VALUE_QUANTITY.exactly().number(123).andNoUnits())
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Observation")
+ .where(Observation.VALUE_QUANTITY.exactly().number(123).andNoUnits())
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Observation?value-quantity=123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Observation")
- .where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("CODE"))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Observation")
+ .where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("CODE"))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Observation?value-quantity=123||CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Observation")
- .where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("SYSTEM", "CODE"))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Observation")
+ .where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("SYSTEM", "CODE"))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Observation?value-quantity=123|SYSTEM|CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Observation")
- .where(Observation.VALUE_QUANTITY.greaterThan().number(123).andNoUnits())
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Observation")
+ .where(Observation.VALUE_QUANTITY.greaterThan().number(123).andNoUnits())
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Observation?value-quantity=gt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Observation")
- .where(Observation.VALUE_QUANTITY.lessThan().number(123).andNoUnits())
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Observation")
+ .where(Observation.VALUE_QUANTITY.lessThan().number(123).andNoUnits())
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Observation?value-quantity=lt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Observation")
- .where(Observation.VALUE_QUANTITY.greaterThanOrEquals().number(123).andNoUnits())
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Observation")
+ .where(Observation.VALUE_QUANTITY.greaterThanOrEquals().number(123).andNoUnits())
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Observation?value-quantity=ge123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Observation")
- .where(Observation.VALUE_QUANTITY.lessThanOrEquals().number(123).andNoUnits())
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Observation")
+ .where(Observation.VALUE_QUANTITY.lessThanOrEquals().number(123).andNoUnits())
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Observation?value-quantity=le123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Observation")
- .where(Observation.VALUE_QUANTITY.withPrefix(ParamPrefixEnum.GREATERTHAN).number(123).andNoUnits())
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Observation")
+ .where(Observation.VALUE_QUANTITY.withPrefix(ParamPrefixEnum.GREATERTHAN).number(123).andNoUnits())
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Observation?value-quantity=gt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
@@ -1462,83 +1413,75 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int idx = 0;
-
client.search()
- .forResource("Patient")
- .where(Patient.NAME.matches().value("AAA"))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.NAME.matches().value("AAA"))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Patient?name=AAA", capt.getAllValues().get(idx).getURI().toString());
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.NAME.matches().value(new StringDt("AAA")))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.NAME.matches().value(new StringDt("AAA")))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Patient?name=AAA", capt.getAllValues().get(idx).getURI().toString());
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.NAME.matches().values("AAA", "BBB"))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.NAME.matches().values("AAA", "BBB"))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Patient?name=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.NAME.matches().values(Arrays.asList("AAA", "BBB")))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.NAME.matches().values(Arrays.asList("AAA", "BBB")))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Patient?name=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.NAME.matchesExactly().value("AAA"))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.NAME.matchesExactly().value("AAA"))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Patient?name%3Aexact=AAA", capt.getAllValues().get(idx).getURI().toString());
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.NAME.matchesExactly().value(new StringDt("AAA")))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.NAME.matchesExactly().value(new StringDt("AAA")))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Patient?name%3Aexact=AAA", capt.getAllValues().get(idx).getURI().toString());
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.NAME.matchesExactly().values("AAA", "BBB"))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.NAME.matchesExactly().values("AAA", "BBB"))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Patient?name:exact=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
-
client.search()
- .forResource("Patient")
- .where(Patient.NAME.matchesExactly().values(Arrays.asList("AAA", "BBB")))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.NAME.matchesExactly().values(Arrays.asList("AAA", "BBB")))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Patient?name:exact=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
@@ -1562,40 +1505,27 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int idx = 0;
-
client.search()
- .forResource("Device")
- .where(Device.URL.matches().value("http://foo.com"))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Device")
+ .where(Device.URL.matches().value("http://foo.com"))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Device?url=http://foo.com", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
assertEquals("http://example.com/fhir/Device?url=http%3A%2F%2Ffoo.com", capt.getAllValues().get(idx).getURI().toString());
idx++;
-
client.search()
- .forResource("Device")
- .where(Device.URL.matches().value(new StringDt("http://foo.com")))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Device")
+ .where(Device.URL.matches().value(new StringDt("http://foo.com")))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Device?url=http://foo.com", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
}
- @Test
- public void testSearchForUnknownType() throws Exception {
- IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
- try {
- client.search(new UriDt("?aaaa"));
- fail();
- } catch (IllegalArgumentException e) {
- assertEquals("Unable to determine the resource type from the given URI: ?aaaa", e.getMessage());
- }
- }
-
@Test
public void testSearchWithMultipleTokens() throws Exception {
ArgumentCaptor capt = prepareClientForSearchResponse();
@@ -1605,13 +1535,12 @@ public class GenericClientDstu2_1Test {
Collection values = Arrays.asList("VAL1", "VAL2", "VAL3A,B");
-
client.search()
- .forResource("Patient")
- .where(Patient.IDENTIFIER.exactly().systemAndValues("SYS", values))
- .returnBundle(Bundle.class)
- .execute();
-
+ .forResource("Patient")
+ .where(Patient.IDENTIFIER.exactly().systemAndValues("SYS", values))
+ .returnBundle(Bundle.class)
+ .execute();
+
assertEquals("http://example.com/fhir/Patient?identifier=SYS%7CVAL1%2CSYS%7CVAL2%2CSYS%7CVAL3A%5C%2CB", capt.getAllValues().get(idx).getURI().toString());
assertEquals("http://example.com/fhir/Patient?identifier=SYS|VAL1,SYS|VAL2,SYS|VAL3A\\,B", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
@@ -1643,33 +1572,32 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int idx = 0;
-
client
- .search()
- .forResource(Patient.class)
- .sort().ascending("address")
- .returnBundle(Bundle.class)
- .execute();
+ .search()
+ .forResource(Patient.class)
+ .sort().ascending("address")
+ .returnBundle(Bundle.class)
+ .execute();
assertEquals("http://example.com/fhir/Patient?_sort=address", capt.getAllValues().get(idx++).getURI().toASCIIString());
- client
- .search()
- .forResource(Patient.class)
- .sort().descending("address")
- .returnBundle(Bundle.class)
- .execute();
+ client
+ .search()
+ .forResource(Patient.class)
+ .sort().descending("address")
+ .returnBundle(Bundle.class)
+ .execute();
assertEquals("http://example.com/fhir/Patient?_sort=-address", capt.getAllValues().get(idx++).getURI().toASCIIString());
- client
- .search()
- .forResource(Patient.class)
- .sort().descending("address")
- .sort().ascending("name")
- .sort().descending(Patient.BIRTHDATE)
- .returnBundle(Bundle.class)
- .execute();
+ client
+ .search()
+ .forResource(Patient.class)
+ .sort().descending("address")
+ .sort().ascending("name")
+ .sort().descending(Patient.BIRTHDATE)
+ .returnBundle(Bundle.class)
+ .execute();
assertEquals("http://example.com/fhir/Patient?_sort=-address%2Cname%2C-birthdate", capt.getAllValues().get(idx++).getURI().toASCIIString());
-
+
}
@Test
@@ -1708,7 +1636,6 @@ public class GenericClientDstu2_1Test {
assertEquals("Unable to determing encoding of request (body does not appear to be valid XML or JSON)", e.getMessage());
}
-
}
@Test
@@ -1923,13 +1850,11 @@ public class GenericClientDstu2_1Test {
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
client.registerInterceptor(new UserInfoInterceptor("user_id", "user_name", "app-name"));
-
Bundle resp = client
- .history()
- .onType(Patient.class)
- .andReturnBundle(Bundle.class)
- .execute();
-
+ .history()
+ .onType(Patient.class)
+ .andReturnBundle(Bundle.class)
+ .execute();
}
@@ -2016,7 +1941,6 @@ public class GenericClientDstu2_1Test {
patient.getText().setDivAsString("OK!");
b.addEntry().setResource(patient);
-
final String respString = p.encodeResourceToString(b);
ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
@@ -2047,8 +1971,6 @@ public class GenericClientDstu2_1Test {
assertEquals(expectedUserAgent(), capt.getAllValues().get(0).getHeaders("User-Agent")[0].getValue());
}
-
-
@AfterClass
public static void afterClassClearContext() {
TestUtil.clearAllStaticFieldsForUnitTest();
diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactory.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactory.java
index 4bb344d978d..676a1184782 100644
--- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactory.java
+++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactory.java
@@ -258,11 +258,6 @@ public class Dstu2BundleFactory implements IVersionSpecificBundleFactory {
}
}
- @Override
- public ca.uhn.fhir.model.api.Bundle getDstu1Bundle() {
- return null;
- }
-
@Override
public IResource getResourceBundle() {
return myBundle;
diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java
index bc7e82845a7..938263abb2f 100644
--- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java
+++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java
@@ -36,7 +36,6 @@ import com.google.common.collect.Sets;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.*;
-import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
import ca.uhn.fhir.model.dstu2.composite.*;
import ca.uhn.fhir.model.dstu2.resource.*;
@@ -74,7 +73,7 @@ public class JsonParserDstu2Test {
ourCtx = FhirContext.forDstu2();
}
}
-
+
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
try {
@@ -94,30 +93,30 @@ public class JsonParserDstu2Test {
ourCtx = FhirContext.forDstu2();
}
}
-
+
/**
* See #544
*/
@Test
public void testBundleStitchReferencesByUuid() throws Exception {
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = new ca.uhn.fhir.model.dstu2.resource.Bundle();
-
+
DocumentManifest dm = new DocumentManifest();
dm.getSubject().setReference("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3");
bundle.addEntry().setResource(dm);
-
+
Patient patient = new Patient();
patient.addName().addFamily("FAMILY");
bundle.addEntry().setResource(patient).setFullUrl("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3");
-
+
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
ourLog.info(encoded);
-
+
bundle = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, encoded);
dm = (DocumentManifest) bundle.getEntry().get(0).getResource();
-
+
assertEquals("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3", dm.getSubject().getReference().getValue());
-
+
Patient subject = (Patient) dm.getSubject().getResource();
assertNotNull(subject);
assertEquals("FAMILY", subject.getNameFirstRep().getFamilyAsSingleString());
@@ -145,21 +144,6 @@ public class JsonParserDstu2Test {
assertEquals("ORG", o.getName());
}
- @Test
- public void testEncodeBundleOldStyleContainingResourceWithUuidBase() {
- Patient p = new Patient();
- p.setId(IdDt.newRandomUuid());
- p.addName().addFamily("PATIENT");
-
- Bundle b = new Bundle();
- b.addEntry().setResource(p);
-
- String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
- ourLog.info(encoded);
- assertThat(encoded, stringContainsInOrder("fullUrl", p.getId().getValue(), "Patient"));
- }
-
-
/**
* See #308
*/
@@ -536,43 +520,6 @@ public class JsonParserDstu2Test {
}
- @Test
- public void testEncodeBundleOldBundleNoText() {
-
- Bundle b = new Bundle();
-
- BundleEntry e = b.addEntry();
- e.setResource(new Patient());
- b.addCategory("scheme", "term", "label");
-
- String val = ourCtx.newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
- ourLog.info(val);
-
- assertThat(val, not(containsString("text")));
-
- b = ourCtx.newJsonParser().parseBundle(val);
- assertEquals(1, b.getEntries().size());
-
- }
-
- /**
- * Fixing #89
- */
- @Test
- public void testEncodeBundleWithDeletedEntry() throws ConfigurationException, DataFormatException, IOException {
- Bundle b = ourCtx.newXmlParser().parseBundle(IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/xml-bundle.xml")));
- String val = ourCtx.newJsonParser().encodeBundleToString(b);
-
- ourLog.info(val);
-
- //@formatter:off
- assertThat(val, containsString("\"deleted\":{" +
- "\"type\":\"Patient\"," +
- "\"resourceId\":\"4384\"," +
- "\"instant\":\"2015-01-15T11:04:43.054-05:00\"" +
- "}"));
- //@formatter:on
- }
@Test
public void testEncodeDoesntIncludeUuidId() {
@@ -1055,28 +1002,28 @@ public class JsonParserDstu2Test {
public void testParseAndEncodeBundle() throws Exception {
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"));
- Bundle parsed = ourCtx.newJsonParser().parseBundle(content);
+ Bundle parsed = ourCtx.newJsonParser().parseResource(Bundle.class, content);
assertEquals("Bundle/example/_history/1", parsed.getId().getValue());
assertEquals("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
assertEquals("1", parsed.getId().getVersionIdPart());
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
- assertEquals("searchset", parsed.getType().getValue());
- assertEquals(3, parsed.getTotalResults().getValue().intValue());
- assertEquals("https://example.com/base/MedicationOrder?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2", parsed.getLinkNext().getValue());
- assertEquals("https://example.com/base/MedicationOrder?patient=347&_include=MedicationOrder.medication", parsed.getLinkSelf().getValue());
+ assertEquals("searchset", parsed.getTypeElement().getValueAsString());
+ assertEquals(3, parsed.getTotalElement().getValue().intValue());
+ assertEquals("https://example.com/base/MedicationOrder?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2", parsed.getLink("next").getUrl());
+ assertEquals("https://example.com/base/MedicationOrder?patient=347&_include=MedicationOrder.medication", parsed.getLink("self").getUrl());
- assertEquals(2, parsed.getEntries().size());
+ assertEquals(2, parsed.getEntry().size());
- MedicationOrder p = (MedicationOrder) parsed.getEntries().get(0).getResource();
+ MedicationOrder p = (MedicationOrder) parsed.getEntry().get(0).getResource();
assertEquals("Patient/347", p.getPatient().getReference().getValue());
assertEquals("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
assertEquals("http://example.com/base/MedicationOrder/3123/_history/1", p.getId().getValue());
- Medication m = (Medication) parsed.getEntries().get(1).getResource();
+ Medication m = (Medication) parsed.getEntry().get(1).getResource();
assertEquals("http://example.com/base/Medication/example", m.getId().getValue());
assertSame(((ResourceReferenceDt) p.getMedication()).getResource(), m);
- String reencoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(parsed);
+ String reencoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(parsed);
ourLog.info(reencoded);
JsonConfig cfg = new JsonConfig();
@@ -1130,7 +1077,7 @@ public class JsonParserDstu2Test {
assertEquals("1", parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.VERSION));
assertEquals("1", parsed.getId().getVersionIdPart());
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
- assertEquals("searchset", parsed.getType());
+ assertEquals("searchset", parsed.getTypeElement().getValue());
assertEquals(3, parsed.getTotal().intValue());
assertEquals("https://example.com/base/MedicationOrder?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2", parsed.getLink().get(0).getUrlElement().getValueAsString());
assertEquals("https://example.com/base/MedicationOrder?patient=347&_include=MedicationOrder.medication", parsed.getLink().get(1).getUrlElement().getValueAsString());
@@ -1169,25 +1116,25 @@ public class JsonParserDstu2Test {
public void testParseAndEncodeBundleOldStyle() throws Exception {
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"));
- Bundle parsed = ourCtx.newJsonParser().parseBundle(content);
+ Bundle parsed = ourCtx.newJsonParser().parseResource(Bundle.class, content);
assertEquals(new InstantDt("2014-08-18T01:43:30Z"), parsed.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED));
- assertEquals("searchset", parsed.getType().getValue());
- assertEquals(3, parsed.getTotalResults().getValue().intValue());
+ assertEquals("searchset", parsed.getTypeElement().getValue());
+ assertEquals(3, parsed.getTotalElement().getValue().intValue());
- assertEquals(2, parsed.getEntries().size());
+ assertEquals(2, parsed.getEntry().size());
- MedicationOrder p = (MedicationOrder) parsed.getEntries().get(0).getResource();
+ MedicationOrder p = (MedicationOrder) parsed.getEntry().get(0).getResource();
assertEquals("Patient/347", p.getPatient().getReference().getValue());
assertEquals("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
assertEquals("http://example.com/base/MedicationOrder/3123/_history/1", p.getId().getValue());
- Medication m = (Medication) parsed.getEntries().get(1).getResource();
+ Medication m = (Medication) parsed.getEntry().get(1).getResource();
assertEquals("http://example.com/base/Medication/example", m.getId().getValue());
assertEquals("Medication/example", ((ResourceReferenceDt) p.getMedication()).getReference().getValue());
assertSame(((ResourceReferenceDt) p.getMedication()).getResource(), m);
- String reencoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(parsed);
+ String reencoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(parsed);
ourLog.info(reencoded);
JsonConfig cfg = new JsonConfig();
@@ -1211,31 +1158,13 @@ public class JsonParserDstu2Test {
public void testParseAndEncodeBundleResourceWithComments() throws Exception {
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-transaction2.json"));
- ourCtx.newJsonParser().parseBundle(content);
+ ourCtx.newJsonParser().parseResource(Bundle.class, content);
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, content);
// TODO: preserve comments
}
- @Test
- public void testParseAndEncodeBundleWithDeletedEntry() {
-
- Patient res = new Patient();
- res.setId(new IdDt("Patient", "111", "222"));
- ResourceMetadataKeyEnum.DELETED_AT.put(res, new InstantDt("2011-01-01T12:12:22Z"));
-
- Bundle bundle = new Bundle();
- bundle.addResource(res, ourCtx, "http://foo/base");
-
- String actual = ourCtx.newJsonParser().encodeBundleToString(bundle);
- ourLog.info(actual);
-
- String expected = "{\"resourceType\":\"Bundle\",\"entry\":[{\"deleted\":{\"type\":\"Patient\",\"resourceId\":\"111\",\"versionId\":\"222\",\"instant\":\"2011-01-01T12:12:22Z\"}}]}";
- assertEquals(expected, actual);
-
- }
-
@Test
public void testParseAndEncodeBundleWithUuidBase() {
//@formatter:off
@@ -1531,38 +1460,32 @@ public class JsonParserDstu2Test {
" \"lastUpdated\" : \"2001-02-22T11:22:33-05:00\"\n" +
" },\n" +
" \"birthDate\" : \"2012-01-02\"\n" +
- " },\n" +
- " \"search\" : {\n" +
- " \"mode\" : \"match\",\n" +
- " \"score\" : 0.123\n" +
- " },\n" +
- " \"request\" : {\n" +
- " \"method\" : \"POST\",\n" +
- " \"url\" : \"http://foo/Patient?identifier=value\"\n" +
- " }\n" +
+ " }\n" +
" }]\n" +
"}";
//@formatter:on
- Bundle b = ourCtx.newJsonParser().parseBundle(bundle);
- assertEquals(1, b.getEntries().size());
+ Bundle b = ourCtx.newJsonParser().parseResource(Bundle.class, bundle);
+ assertEquals(1, b.getEntry().size());
- Patient pt = (Patient) b.getEntries().get(0).getResource();
+ Patient pt = (Patient) b.getEntry().get(0).getResource();
assertEquals("http://foo/fhirBase2/Patient/1/_history/2", pt.getId().getValue());
assertEquals("2012-01-02", pt.getBirthDateElement().getValueAsString());
- assertEquals("0.123", ResourceMetadataKeyEnum.ENTRY_SCORE.get(pt).getValueAsString());
- assertEquals("match", ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(pt).getCode());
- assertEquals("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
- assertEquals("http://foo/Patient?identifier=value", ResourceMetadataKeyEnum.LINK_SEARCH.get(pt));
- assertEquals("2001-02-22T11:22:33-05:00", ResourceMetadataKeyEnum.UPDATED.get(pt).getValueAsString());
+// assertEquals("match", ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(pt).getCode());
+// assertEquals("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
+// assertEquals("http://foo/Patient?identifier=value", ResourceMetadataKeyEnum.LINK_SEARCH.get(pt));
+// assertEquals("2001-02-22T11:22:33-05:00", ResourceMetadataKeyEnum.UPDATED.get(pt).getValueAsString());
Bundle toBundle = new Bundle();
- toBundle.getLinkBase().setValue("http://foo/fhirBase1");
- toBundle.getTotalResults().setValue(1);
- toBundle.getLinkSelf().setValue("http://localhost:52788/Binary?_pretty=true");
+ toBundle.getTotalElement().setValue(1);
+// toBundle.getLinkOrCreate("base").setUrl("http://foo/fhirBase1");
+ toBundle.getLinkOrCreate("self").setUrl("http://localhost:52788/Binary?_pretty=true");
- toBundle.addResource(pt, ourCtx, "http://foo/fhirBase1");
- String reEncoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(toBundle);
+ toBundle
+ .addEntry()
+ .setFullUrl("http://foo/fhirBase2/Patient/1/_history/2")
+ .setResource(pt);
+ String reEncoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(toBundle);
JsonConfig cfg = new JsonConfig();
@@ -1692,9 +1615,9 @@ public class JsonParserDstu2Test {
String text = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
FhirContext ctx = FhirContext.forDstu2();
- Bundle b = ctx.newJsonParser().parseBundle(text);
+ Bundle b = ctx.newJsonParser().parseResource(Bundle.class, text);
- IResource patient = b.getEntries().get(0).getResource();
+ IResource patient = b.getEntry().get(0).getResource();
assertEquals(Patient.class, patient.getClass());
assertNull(ResourceMetadataKeyEnum.TAG_LIST.get(patient));
@@ -1999,29 +1922,29 @@ public class JsonParserDstu2Test {
patient.setPetName(new StringDt("myName"));
final Bundle bundle = new Bundle();
- final BundleEntry entry = new BundleEntry();
+ final Entry entry = new Entry();
entry.setResource(patient);
bundle.addEntry(entry);
final IParser jsonParser = ourCtx.newJsonParser();
jsonParser.setServerBaseUrl("http://www.example.com");
- final String parsedBundle = jsonParser.encodeBundleToString(bundle);
+ final String parsedBundle = jsonParser.encodeResourceToString(bundle);
System.out.println(parsedBundle);
assertEquals(expected, parsedBundle);
// Parse with string
- Bundle newBundle = jsonParser.parseBundle(parsedBundle);
+ Bundle newBundle = jsonParser.parseResource(Bundle.class, parsedBundle);
assertNotNull(newBundle);
- assertEquals(1, newBundle.getEntries().size());
- Patient newPatient = (Patient) newBundle.getEntries().get(0).getResource();
+ assertEquals(1, newBundle.getEntry().size());
+ Patient newPatient = (Patient) newBundle.getEntry().get(0).getResource();
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
// Parse with stream
- newBundle = jsonParser.parseBundle(new StringReader(parsedBundle));
+ newBundle = jsonParser.parseResource(Bundle.class, new StringReader(parsedBundle));
assertNotNull(newBundle);
- assertEquals(1, newBundle.getEntries().size());
- newPatient = (Patient) newBundle.getEntries().get(0).getResource();
+ assertEquals(1, newBundle.getEntry().size());
+ newPatient = (Patient) newBundle.getEntry().get(0).getResource();
assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue());
}
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 b5fac94dbab..7cf1a816eea 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
@@ -41,7 +41,6 @@ import com.google.common.collect.Sets;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.*;
-import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
@@ -67,7 +66,7 @@ public class XmlParserDstu2Test {
ourCtx = FhirContext.forDstu2();
}
}
-
+
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnFhirContext() {
try {
@@ -88,7 +87,7 @@ public class XmlParserDstu2Test {
ourCtx = null;
}
}
-
+
@Test
public void testOverrideResourceIdWithBundleEntryFullUrlDisabled_ConfiguredOnParser() {
try {
@@ -108,7 +107,7 @@ public class XmlParserDstu2Test {
ourCtx = null;
}
}
-
+
/**
* See #414
*/
@@ -137,10 +136,9 @@ public class XmlParserDstu2Test {
} catch (DataFormatException e) {
assertEquals("Resource is missing required element 'url' in parent element 'extension'", e.getCause().getMessage());
}
-
+
}
-
/**
* See #414
*/
@@ -169,9 +167,9 @@ public class XmlParserDstu2Test {
} catch (DataFormatException e) {
assertEquals("Resource is missing required element 'url' in parent element 'modifierExtension'", e.getCause().getMessage());
}
-
+
}
-
+
/**
* If a contained resource refers to a contained resource that comes after it, it should still be successfully
* woven together.
@@ -179,11 +177,11 @@ public class XmlParserDstu2Test {
@Test
public void testParseWovenContainedResources() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_woven_obs.xml"), StandardCharsets.UTF_8);
-
+
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
-
+
DiagnosticReport resource = (DiagnosticReport) bundle.getEntry().get(0).getResource();
Observation obs = (Observation) resource.getResult().get(1).getResource();
assertEquals("#2", obs.getId().getValue());
@@ -191,30 +189,29 @@ public class XmlParserDstu2Test {
Practitioner performer = (Practitioner) performerFirstRep.getResource();
assertEquals("#3", performer.getId().getValue());
}
-
- @Test(expected=DataFormatException.class)
+
+ @Test(expected = DataFormatException.class)
public void testContainedResourceWithNoId() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
-
+
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
}
-
@Test()
public void testContainedResourceWithNoIdLenient() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_contained_with_no_id.xml"), StandardCharsets.UTF_8);
-
+
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new LenientErrorHandler());
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
}
- @Test(expected=DataFormatException.class)
+ @Test(expected = DataFormatException.class)
public void testParseWithInvalidLocalRef() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml"), StandardCharsets.UTF_8);
-
+
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new StrictErrorHandler());
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
@@ -223,13 +220,12 @@ public class XmlParserDstu2Test {
@Test()
public void testParseWithInvalidLocalRefLenient() throws IOException {
String string = IOUtils.toString(getClass().getResourceAsStream("/bundle_with_invalid_contained_ref.xml"), StandardCharsets.UTF_8);
-
+
IParser parser = ourCtx.newXmlParser();
parser.setParserErrorHandler(new LenientErrorHandler());
parser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, string);
}
-
@Test
public void testBundleWithBinary() {
//@formatter:off
@@ -254,14 +250,14 @@ public class XmlParserDstu2Test {
"";
//@formatter:on
- Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
- assertEquals(1, b.getEntries().size());
+ Bundle b = ourCtx.newXmlParser().parseResource(Bundle.class, bundle);
+ assertEquals(1, b.getEntry().size());
- Binary bin = (Binary) b.getEntries().get(0).getResource();
+ Binary bin = (Binary) b.getEntry().get(0).getResource();
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
}
-
+
@Test
public void testChoiceTypeWithProfiledType() {
//@formatter:off
@@ -281,7 +277,7 @@ public class XmlParserDstu2Test {
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed);
assertThat(encoded, containsString(""));
}
-
+
@Test
public void testChoiceTypeWithProfiledType2() {
Parameters par = new Parameters();
@@ -299,7 +295,6 @@ public class XmlParserDstu2Test {
assertEquals(MarkdownDt.class, par.getParameter().get(1).getValue().getClass());
}
-
@Test
public void testContainedResourceInExtensionUndeclared() {
Patient p = new Patient();
@@ -359,13 +354,14 @@ public class XmlParserDstu2Test {
Organization org = new Organization();
org.addIdentifier().setSystem("urn:system").setValue("someval");
- Bundle bundle = Bundle.withSingleResource(org);
- String str = ourCtx.newXmlParser().encodeBundleToString(bundle);
+ Bundle bundle = new Bundle();
+ bundle.addEntry().setResource(org);
+ String str = ourCtx.newXmlParser().encodeResourceToString(bundle);
ourLog.info(str);
- Bundle parsed = ourCtx.newXmlParser().parseBundle(str);
- assertThat(parsed.getEntries().get(0).getResource().getId().getValue(), emptyOrNullString());
- assertTrue(parsed.getEntries().get(0).getResource().getId().isEmpty());
+ Bundle parsed = ourCtx.newXmlParser().parseResource(Bundle.class, str);
+ assertThat(parsed.getEntry().get(0).getResource().getId().getValue(), emptyOrNullString());
+ assertTrue(parsed.getEntry().get(0).getResource().getId().isEmpty());
}
@Test
@@ -479,20 +475,20 @@ public class XmlParserDstu2Test {
ourCtx = FhirContext.forDstu2();
ourCtx.setDefaultTypeForProfile(CustomObservationDstu2.PROFILE, CustomObservationDstu2.class);
ourCtx.setDefaultTypeForProfile(CustomDiagnosticReportDstu2.PROFILE, CustomDiagnosticReportDstu2.class);
-
+
CustomObservationDstu2 obs = new CustomObservationDstu2();
obs.setStatus(ObservationStatusEnum.FINAL);
-
+
CustomDiagnosticReportDstu2 dr = new CustomDiagnosticReportDstu2();
dr.setStatus(DiagnosticReportStatusEnum.FINAL);
dr.addResult().setResource(obs);
-
+
IParser parser = ourCtx.newXmlParser();
parser.setPrettyPrint(true);
-
+
String output = parser.encodeResourceToString(dr);
ourLog.info(output);
-
+
//@formatter:off
assertThat(output,stringContainsInOrder(
"",
@@ -514,11 +510,11 @@ public class XmlParserDstu2Test {
"",
""));
//@formatter:on
-
+
/*
* Now PARSE!
*/
-
+
dr = (CustomDiagnosticReportDstu2) parser.parseResource(output);
assertEquals(DiagnosticReportStatusEnum.FINAL, dr.getStatusElement().getValueAsEnum());
@@ -549,35 +545,34 @@ public class XmlParserDstu2Test {
"" +
"";
//@formatter:on
-
+
IParser parser = ourCtx.newXmlParser();
CustomDiagnosticReportDstu2 dr = (CustomDiagnosticReportDstu2) parser.parseResource(input);
assertEquals(DiagnosticReportStatusEnum.FINAL, dr.getStatusElement().getValueAsEnum());
List profiles = ResourceMetadataKeyEnum.PROFILES.get(dr);
assertEquals(3, profiles.size());
-
+
ourCtx = null;
}
-
@Test
public void testEncodeAndParseContainedNonCustomTypes() {
ourCtx = FhirContext.forDstu2();
-
+
Observation obs = new Observation();
obs.setStatus(ObservationStatusEnum.FINAL);
-
+
DiagnosticReport dr = new DiagnosticReport();
dr.setStatus(DiagnosticReportStatusEnum.FINAL);
dr.addResult().setResource(obs);
-
+
IParser parser = ourCtx.newXmlParser();
parser.setPrettyPrint(true);
-
+
String output = parser.encodeResourceToString(dr);
ourLog.info(output);
-
+
//@formatter:off
assertThat(output,stringContainsInOrder(
"",
@@ -593,11 +588,11 @@ public class XmlParserDstu2Test {
"",
""));
//@formatter:on
-
+
/*
* Now PARSE!
*/
-
+
dr = (DiagnosticReport) parser.parseResource(output);
assertEquals(DiagnosticReportStatusEnum.FINAL, dr.getStatusElement().getValueAsEnum());
@@ -621,10 +616,10 @@ public class XmlParserDstu2Test {
condition.setOurAbatement(new DateTimeDt(new Date()));
String conditionXml = parser.encodeResourceToString(condition);
-
+
ourLog.info(conditionXml);
assertThat(conditionXml, containsString("abatementDateTime"));
-
+
CustomCondition parsedCondition = (CustomCondition) parser.parseResource(conditionXml);
assertNotNull(parsedCondition.getOurAbatement());
}
@@ -1120,9 +1115,9 @@ public class XmlParserDstu2Test {
p.addName().addFamily("PATIENT");
Bundle b = new Bundle();
- b.addEntry().setResource(p);
+ b.addEntry().setFullUrl(p.getId().getValue()).setResource(p);
- String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
+ String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder("", "", "")));
@@ -1135,10 +1130,10 @@ public class XmlParserDstu2Test {
p.addName().addFamily("PATIENT");
Bundle b = new Bundle();
- b.getLinkBase().setValue("urn:uuid:");
+ b.getLinkOrCreate("base").setUrl("urn:uuid:");
b.addEntry().setResource(p);
- String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
+ String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
ourLog.info(encoded);
// Base element has been removed!
assertThat(encoded, not(stringContainsInOrder("", "