Work on porting DSTU1 tests

This commit is contained in:
James 2017-08-01 07:09:29 -04:00
parent 602857f1e2
commit 43c9003258
19 changed files with 1603 additions and 1729 deletions

View File

@ -67,8 +67,6 @@ public class Constants {
public static final String HEADER_AUTHORIZATION = "Authorization";
public static final String HEADER_AUTHORIZATION_VALPREFIX_BASIC = "Basic ";
public static final String HEADER_AUTHORIZATION_VALPREFIX_BEARER = "Bearer ";
public static final String HEADER_CATEGORY = "Category";
public static final String HEADER_CATEGORY_LC = HEADER_CATEGORY.toLowerCase();
public static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition";
public static final String HEADER_CONTENT_ENCODING = "Content-Encoding";
public static final String HEADER_CONTENT_LOCATION = "Content-Location";

View File

@ -1,7 +1,5 @@
package ca.uhn.fhir.rest.param;
import static org.apache.commons.lang3.StringUtils.isBlank;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
/*
@ -32,8 +30,10 @@ import ca.uhn.fhir.context.*;
import ca.uhn.fhir.model.api.*;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.IntegerDt;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.*;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.TagListParam;
import ca.uhn.fhir.rest.api.QualifiedParamList;
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
import ca.uhn.fhir.rest.param.binder.QueryParameterAndBinder;
import ca.uhn.fhir.util.ReflectionUtil;
import ca.uhn.fhir.util.UrlUtil;
@ -44,7 +44,6 @@ public class ParameterUtil {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ParameterUtil.class);
private static final String SCHEME = "scheme=\"";
@SuppressWarnings("unchecked")
public static <T extends IIdType> T convertIdToType(IIdType value, Class<T> theIdParamType) {
if (value != null && !theIdParamType.isAssignableFrom(value.getClass())) {
@ -101,7 +100,7 @@ public class ParameterUtil {
// FIXME null access
return binder.parse(theContext, theUnqualifiedParamName, theParameters);
}
/**
* This is a utility method intended provided to help the JPA module.
*/
@ -111,8 +110,6 @@ public class ParameterUtil {
return parseQueryParams(theContext, paramType, theUnqualifiedParamName, theParameters);
}
/**
* Escapes a string according to the rules for parameter escaping specified in the <a href="http://www.hl7.org/implement/standards/fhir/search.html#escaping">FHIR Specification Escaping
* Section</a>
@ -254,86 +251,6 @@ public class ParameterUtil {
return eTagVersion;
}
@Deprecated
public static void parseTagValue(TagList tagList, String nextTagComplete) {
StringBuilder next = new StringBuilder(nextTagComplete);
parseTagValue(tagList, nextTagComplete, next);
}
@Deprecated
private static void parseTagValue(TagList theTagList, String theCompleteHeaderValue, StringBuilder theBuffer) {
int firstSemicolon = theBuffer.indexOf(";");
int deleteTo;
if (firstSemicolon == -1) {
firstSemicolon = theBuffer.indexOf(",");
if (firstSemicolon == -1) {
firstSemicolon = theBuffer.length();
deleteTo = theBuffer.length();
} else {
deleteTo = firstSemicolon;
}
} else {
deleteTo = firstSemicolon + 1;
}
String term = theBuffer.substring(0, firstSemicolon);
String scheme = null;
String label = null;
if (isBlank(term)) {
return;
}
theBuffer.delete(0, deleteTo);
while (theBuffer.length() > 0 && theBuffer.charAt(0) == ' ') {
theBuffer.deleteCharAt(0);
}
while (theBuffer.length() > 0) {
boolean foundSomething = false;
if (theBuffer.length() > SCHEME.length() && theBuffer.substring(0, SCHEME.length()).equals(SCHEME)) {
int closeIdx = theBuffer.indexOf("\"", SCHEME.length());
scheme = theBuffer.substring(SCHEME.length(), closeIdx);
theBuffer.delete(0, closeIdx + 1);
foundSomething = true;
}
if (theBuffer.length() > LABEL.length() && theBuffer.substring(0, LABEL.length()).equals(LABEL)) {
int closeIdx = theBuffer.indexOf("\"", LABEL.length());
label = theBuffer.substring(LABEL.length(), closeIdx);
theBuffer.delete(0, closeIdx + 1);
foundSomething = true;
}
// TODO: support enc2231-string as described in
// http://tools.ietf.org/html/draft-johnston-http-category-header-02
// TODO: support multiple tags in one header as described in
// http://hl7.org/implement/standards/fhir/http.html#tags
while (theBuffer.length() > 0 && (theBuffer.charAt(0) == ' ' || theBuffer.charAt(0) == ';')) {
theBuffer.deleteCharAt(0);
}
if (!foundSomething) {
break;
}
}
if (theBuffer.length() > 0 && theBuffer.charAt(0) == ',') {
theBuffer.deleteCharAt(0);
while (theBuffer.length() > 0 && theBuffer.charAt(0) == ' ') {
theBuffer.deleteCharAt(0);
}
theTagList.add(new Tag(scheme, term, label));
parseTagValue(theTagList, theCompleteHeaderValue, theBuffer);
} else {
theTagList.add(new Tag(scheme, term, label));
}
if (theBuffer.length() > 0) {
ourLog.warn("Ignoring extra text at the end of " + Constants.HEADER_CATEGORY + " tag '"
+ theBuffer.toString() + "' - Complete tag value was: " + theCompleteHeaderValue);
}
}
public static IQueryParameterOr<?> singleton(final IQueryParameterType theParam, final String theParamName) {
return new IQueryParameterOr<IQueryParameterType>() {
@ -412,7 +329,7 @@ public class ParameterUtil {
return new IntegerDt((Integer) theArgument);
}
if (theArgument instanceof IPrimitiveType) {
IPrimitiveType<?> pt = (IPrimitiveType<?>)theArgument;
IPrimitiveType<?> pt = (IPrimitiveType<?>) theArgument;
return new IntegerDt(pt.getValueAsString());
}
return null;

View File

@ -298,7 +298,7 @@ public abstract class BaseMethodBinding<T> implements IClientResponseHandler<T>
// return sm;
}
private static boolean isResourceInterface(Class<?> theReturnTypeFromMethod) {
public static boolean isResourceInterface(Class<?> theReturnTypeFromMethod) {
return theReturnTypeFromMethod.equals(IBaseResource.class) || theReturnTypeFromMethod.equals(IResource.class) || theReturnTypeFromMethod.equals(IAnyResource.class);
}

View File

@ -2,30 +2,22 @@ package ca.uhn.fhir.rest.client.method;
import java.io.Reader;
import java.lang.reflect.Method;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
abstract class BaseOutcomeReturningMethodBinding extends BaseMethodBinding<MethodOutcome> {
static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseOutcomeReturningMethodBinding.class);
private static EnumSet<RestOperationTypeEnum> ourOperationsWhichAllowPreferHeader = EnumSet.of(RestOperationTypeEnum.CREATE, RestOperationTypeEnum.UPDATE);
private boolean myReturnVoid;
public BaseOutcomeReturningMethodBinding(Method theMethod, FhirContext theContext, Class<?> theMethodAnnotation, Object theProvider) {
@ -47,7 +39,7 @@ abstract class BaseOutcomeReturningMethodBinding extends BaseMethodBinding<Metho
return false;
}
protected abstract BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource resource);
protected abstract BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IBaseResource resource);
/**
* For servers, this method will match only incoming requests that match the given operation, or which have no
@ -55,40 +47,6 @@ abstract class BaseOutcomeReturningMethodBinding extends BaseMethodBinding<Metho
*/
protected abstract String getMatchingOperation();
private int getOperationStatus(MethodOutcome response) {
switch (getRestOperationType()) {
case CREATE:
if (response == null) {
throw new InternalErrorException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null, which is not allowed for create operation");
}
if (response.getCreated() == null || Boolean.TRUE.equals(response.getCreated())) {
return Constants.STATUS_HTTP_201_CREATED;
}
return Constants.STATUS_HTTP_200_OK;
case UPDATE:
if (response == null || response.getCreated() == null || Boolean.FALSE.equals(response.getCreated())) {
return Constants.STATUS_HTTP_200_OK;
}
return Constants.STATUS_HTTP_201_CREATED;
case VALIDATE:
case DELETE:
default:
if (response == null) {
if (isReturnVoid() == false) {
throw new InternalErrorException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null");
}
return Constants.STATUS_HTTP_204_NO_CONTENT;
}
if (response.getOperationOutcome() == null) {
return Constants.STATUS_HTTP_204_NO_CONTENT;
}
return Constants.STATUS_HTTP_200_OK;
}
}
@Override
public MethodOutcome invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException {
if (theResponseStatusCode >= 200 && theResponseStatusCode < 300) {

View File

@ -26,7 +26,6 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@ -76,7 +75,7 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu
@Override
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
IResource resource = (IResource) theArgs[myResourceParameterIndex]; // TODO: use IBaseResource
IBaseResource resource = (IBaseResource) theArgs[myResourceParameterIndex];
if (resource == null) {
throw new NullPointerException("Resource can not be null");
}

View File

@ -175,12 +175,12 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
@SuppressWarnings("unchecked")
private List<Class<? extends IBaseResource>> createPreferTypesList() {
List<Class<? extends IBaseResource>> preferTypes = null;
if (myResourceListCollectionType != null && IBaseResource.class.isAssignableFrom(myResourceListCollectionType)) {
if (myResourceType != null && !BaseMethodBinding.isResourceInterface(myResourceType)) {
preferTypes = new ArrayList<Class<? extends IBaseResource>>(1);
preferTypes.add((Class<? extends IBaseResource>) myResourceType);
} else if (myResourceListCollectionType != null && IBaseResource.class.isAssignableFrom(myResourceListCollectionType) && !BaseMethodBinding.isResourceInterface(myResourceListCollectionType)) {
preferTypes = new ArrayList<Class<? extends IBaseResource>>(1);
preferTypes.add((Class<? extends IBaseResource>) myResourceListCollectionType);
// } else if (myResourceType != null) {
// preferTypes = new ArrayList<Class<? extends IBaseResource>>(1);
// preferTypes.add((Class<? extends IBaseResource>) myResourceListCollectionType);
}
return preferTypes;
}
@ -218,7 +218,8 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
}
public enum ReturnTypeEnum {
BUNDLE, RESOURCE
BUNDLE,
RESOURCE
}
}

View File

@ -45,7 +45,7 @@ public class CreateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
}
@Override
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) {
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IBaseResource theResource) {
FhirContext context = getContext();
BaseHttpClientInvocation retVal = MethodUtil.createCreateInvocation(theResource, context);

View File

@ -21,15 +21,12 @@ package ca.uhn.fhir.rest.client.method;
*/
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.annotation.Delete;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
@ -54,7 +51,7 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
}
@Override
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) {
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IBaseResource theResource) {
StringBuilder urlExtension = new StringBuilder();
urlExtension.append(getContext().getResourceDefinition(theResource).getName());

View File

@ -26,12 +26,10 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Date;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.instance.model.api.*;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
import ca.uhn.fhir.rest.annotation.History;
import ca.uhn.fhir.rest.api.Constants;
@ -88,10 +86,10 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
@Override
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
IdDt id = null;
IIdType id = null;
String resourceName = myResourceName;
if (myIdParamIndex != null) {
id = (IdDt) theArgs[myIdParamIndex];
id = (IIdType) theArgs[myIdParamIndex];
if (id == null || isBlank(id.getValue())) {
throw new NullPointerException("ID can not be null");
}

View File

@ -494,21 +494,6 @@ public class MethodUtil {
}
}
List<String> categoryHeaders = theHeaders.get(Constants.HEADER_CATEGORY_LC);
if (categoryHeaders != null && categoryHeaders.size() > 0 && StringUtils.isNotBlank(categoryHeaders.get(0))) {
TagList tagList = new TagList();
for (String header : categoryHeaders) {
ParameterUtil.parseTagValue(tagList, header);
}
if (resource instanceof IResource) {
ResourceMetadataKeyEnum.TAG_LIST.put((IResource) resource, tagList);
} else if (resource instanceof IAnyResource) {
IBaseMetaType meta = ((IAnyResource) resource).getMeta();
for (Tag next : tagList) {
meta.addTag().setSystem(next.getScheme()).setCode(next.getTerm()).setDisplay(next.getLabel());
}
}
}
}
public static MethodOutcome process2xxResponse(FhirContext theContext, int theResponseStatusCode,

View File

@ -24,11 +24,11 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.*;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.annotation.Patch;
import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.api.*;
@ -81,7 +81,7 @@ public class PatchMethodBinding extends BaseOutcomeReturningMethodBindingWithRes
}
@Override
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) {
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IBaseResource theResource) {
StringBuilder urlExtension = new StringBuilder();
urlExtension.append(getContext().getResourceDefinition(theResource).getName());

View File

@ -10,7 +10,6 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
@ -31,8 +30,8 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
@Override
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) {
IdDt idDt = (IdDt) theArgs[myIdParameterIndex];
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IBaseResource theResource) {
IIdType idDt = (IIdType) theArgs[myIdParameterIndex];
if (idDt == null) {
throw new NullPointerException("ID can not be null");
}

View File

@ -50,7 +50,6 @@ public class ETagClientDstu2Test {
TestUtil.clearAllStaticFieldsForUnitTest();
}
@Before
public void before() {
@ -95,7 +94,6 @@ public class ETagClientDstu2Test {
Header[] headers = new Header[] {
new BasicHeader(Constants.HEADER_LAST_MODIFIED, "Wed, 15 Nov 1995 04:58:08 GMT"),
new BasicHeader(Constants.HEADER_CONTENT_LOCATION, "http://foo.com/Patient/123/_history/2333"),
new BasicHeader(Constants.HEADER_CATEGORY, "http://foo/tagdefinition.html; scheme=\"http://hl7.org/fhir/tag\"; label=\"Some tag\""),
new BasicHeader(Constants.HEADER_ETAG, "\"9999\"")
};
//@formatter:on
@ -257,8 +255,10 @@ public class ETagClientDstu2Test {
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().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
Header[] headers = new Header[] { new BasicHeader(Constants.HEADER_LAST_MODIFIED, "Wed, 15 Nov 1995 04:58:08 GMT"), new BasicHeader(Constants.HEADER_CONTENT_LOCATION, "http://foo.com/Patient/123/_history/2333"),
new BasicHeader(Constants.HEADER_CATEGORY, "http://foo/tagdefinition.html; scheme=\"http://hl7.org/fhir/tag\"; label=\"Some tag\"") };
Header[] headers = new Header[] {
new BasicHeader(Constants.HEADER_LAST_MODIFIED, "Wed, 15 Nov 1995 04:58:08 GMT"),
new BasicHeader(Constants.HEADER_CONTENT_LOCATION, "http://foo.com/Patient/123/_history/2333"),
};
when(myHttpResponse.getAllHeaders()).thenReturn(headers);
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");

View File

@ -35,23 +35,23 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
*/
public class ETagClientTest {
private static FhirContext ourCtx;
private HttpClient myHttpClient;
private static FhirContext ourCtx;
private HttpClient myHttpClient;
private HttpResponse myHttpResponse;
private HttpResponse myHttpResponse;
@Before
public void before() {
@Before
public void before() {
myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs());
ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient);
ourCtx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs());
ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient);
ourCtx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
}
myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
}
private String getResourceResult() {
//@formatter:off
private String getResourceResult() {
//@formatter:off
String msg =
"<Patient xmlns=\"http://hl7.org/fhir\">"
+ "<id value=\"123\"/>"
@ -67,50 +67,50 @@ public class ETagClientTest {
+ "<address><use value=\"home\" /><line value=\"2222 Home Street\" /></address><active value=\"true\" />"
+ "</Patient>";
//@formatter:on
return msg;
}
return msg;
}
private Patient getResource() {
return ourCtx.newXmlParser().parseResource(Patient.class, getResourceResult());
}
private Patient getResource() {
return ourCtx.newXmlParser().parseResource(Patient.class, getResourceResult());
}
@Test
public void testReadWithContentLocationInResponse() throws Exception {
@Test
public void testReadWithContentLocationInResponse() throws Exception {
String msg = getResourceResult();
String msg = getResourceResult();
ArgumentCaptor<HttpUriRequest> 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().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
//@formatter:off
ArgumentCaptor<HttpUriRequest> 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().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
//@formatter:off
Header[] headers = new Header[] {
new BasicHeader(Constants.HEADER_CONTENT_LOCATION, "http://foo.com/Patient/123/_history/2333"),
new BasicHeader(Constants.HEADER_ETAG, "\"9999\"")
};
//@formatter:on
when(myHttpResponse.getAllHeaders()).thenReturn(headers);
when(myHttpResponse.getAllHeaders()).thenReturn(headers);
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
Patient response = client.read(Patient.class, new IdDt("Patient/1234"));
Patient response = client.read(Patient.class, new IdDt("Patient/1234"));
assertEquals("http://foo.com/Patient/123/_history/2333", response.getIdElement().getValue());
}
assertEquals("http://foo.com/Patient/123/_history/2333", response.getIdElement().getValue());
}
@Test
public void testReadWithIfNoneMatch() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_304_NOT_MODIFIED, "Not modified"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
@Test
public void testReadWithIfNoneMatch() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_304_NOT_MODIFIED, "Not modified"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int count = 0;
int count = 0;
//@formatter:off
//@formatter:off
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("")));
try {
client
@ -123,10 +123,10 @@ public class ETagClientTest {
// good!
}
//@formatter:on
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
count++;
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
count++;
//@formatter:off
//@formatter:off
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("")));
Patient expected = new Patient();
Patient response = client
@ -136,25 +136,25 @@ public class ETagClientTest {
.ifVersionMatches("9876").returnResource(expected)
.execute();
//@formatter:on
assertSame(expected, response);
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
assertEquals("\"9876\"", capt.getAllValues().get(count).getHeaders(Constants.HEADER_IF_NONE_MATCH_LC)[0].getValue());
count++;
assertSame(expected, response);
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
assertEquals("\"9876\"", capt.getAllValues().get(count).getHeaders(Constants.HEADER_IF_NONE_MATCH_LC)[0].getValue());
count++;
}
}
@Test
public void testUpdateWithIfMatch() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_200_OK, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
@Test
public void testUpdateWithIfMatch() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_200_OK, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int count = 0;
int count = 0;
//@formatter:off
//@formatter:off
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("")));
client
.update()
@ -162,11 +162,11 @@ public class ETagClientTest {
.withId(new IdDt("Patient/1234"))
.execute();
//@formatter:on
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
assertEquals(0, capt.getAllValues().get(count).getHeaders(Constants.HEADER_IF_MATCH_LC).length);
count++;
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
assertEquals(0, capt.getAllValues().get(count).getHeaders(Constants.HEADER_IF_MATCH_LC).length);
count++;
//@formatter:off
//@formatter:off
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("")));
client
.update()
@ -174,24 +174,24 @@ public class ETagClientTest {
.withId(new IdDt("Patient/1234/_history/9876"))
.execute();
//@formatter:on
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
assertEquals("\"9876\"", capt.getAllValues().get(count).getHeaders(Constants.HEADER_IF_MATCH_LC)[0].getValue());
count++;
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
assertEquals("\"9876\"", capt.getAllValues().get(count).getHeaders(Constants.HEADER_IF_MATCH_LC)[0].getValue());
count++;
}
}
@Test
public void testUpdateWithIfMatchWithPreconditionFailed() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_412_PRECONDITION_FAILED, "Precondition Failed"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
@Test
public void testUpdateWithIfMatchWithPreconditionFailed() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_412_PRECONDITION_FAILED, "Precondition Failed"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int count = 0;
int count = 0;
//@formatter:off
//@formatter:off
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("")));
try {
client
@ -204,11 +204,11 @@ public class ETagClientTest {
// good
}
//@formatter:on
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
assertEquals("\"9876\"", capt.getAllValues().get(count).getHeaders(Constants.HEADER_IF_MATCH_LC)[0].getValue());
count++;
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
assertEquals("\"9876\"", capt.getAllValues().get(count).getHeaders(Constants.HEADER_IF_MATCH_LC)[0].getValue());
count++;
//@formatter:off
//@formatter:off
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("")));
try {
Patient resource = getResource();
@ -222,53 +222,55 @@ public class ETagClientTest {
// good
}
//@formatter:on
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
assertEquals("\"9876\"", capt.getAllValues().get(count).getHeaders(Constants.HEADER_IF_MATCH_LC)[0].getValue());
count++;
}
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count).getURI().toString());
assertEquals("\"9876\"", capt.getAllValues().get(count).getHeaders(Constants.HEADER_IF_MATCH_LC)[0].getValue());
count++;
}
@Test
public void testReadWithETag() throws Exception {
@Test
public void testReadWithETag() throws Exception {
String msg = getResourceResult();
String msg = getResourceResult();
ArgumentCaptor<HttpUriRequest> 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().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
Header[] headers = new Header[] { new BasicHeader(Constants.HEADER_LAST_MODIFIED, "Wed, 15 Nov 1995 04:58:08 GMT"), new BasicHeader(Constants.HEADER_CONTENT_LOCATION, "http://foo.com/Patient/123/_history/2333"),
new BasicHeader(Constants.HEADER_CATEGORY, "http://foo/tagdefinition.html; scheme=\"http://hl7.org/fhir/tag\"; label=\"Some tag\"") };
when(myHttpResponse.getAllHeaders()).thenReturn(headers);
ArgumentCaptor<HttpUriRequest> 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().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
Header[] headers = new Header[] {
new BasicHeader(Constants.HEADER_LAST_MODIFIED, "Wed, 15 Nov 1995 04:58:08 GMT"),
new BasicHeader(Constants.HEADER_CONTENT_LOCATION, "http://foo.com/Patient/123/_history/2333"),
};
when(myHttpResponse.getAllHeaders()).thenReturn(headers);
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
int count = 0;
int count = 0;
Patient response = client.read().resource(Patient.class).withId(new IdDt("Patient/1234")).execute();
assertThat(response.getName().get(0).getFamily().get(0).getValue(), StringContains.containsString("Cardinal"));
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count++).getURI().toString());
Patient response = client.read().resource(Patient.class).withId(new IdDt("Patient/1234")).execute();
assertThat(response.getName().get(0).getFamily().get(0).getValue(), StringContains.containsString("Cardinal"));
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count++).getURI().toString());
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
response = (Patient) client.read().resource("Patient").withId("1234").execute();
assertThat(response.getName().get(0).getFamily().get(0).getValue(), StringContains.containsString("Cardinal"));
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count++).getURI().toString());
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
response = (Patient) client.read().resource("Patient").withId("1234").execute();
assertThat(response.getName().get(0).getFamily().get(0).getValue(), StringContains.containsString("Cardinal"));
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count++).getURI().toString());
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
response = client.read().resource(Patient.class).withIdAndVersion("1234", "22").execute();
assertThat(response.getName().get(0).getFamily().get(0).getValue(), StringContains.containsString("Cardinal"));
assertEquals("http://example.com/fhir/Patient/1234/_history/22", capt.getAllValues().get(count++).getURI().toString());
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
response = client.read().resource(Patient.class).withIdAndVersion("1234", "22").execute();
assertThat(response.getName().get(0).getFamily().get(0).getValue(), StringContains.containsString("Cardinal"));
assertEquals("http://example.com/fhir/Patient/1234/_history/22", capt.getAllValues().get(count++).getURI().toString());
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
response = client.read().resource(Patient.class).withUrl("http://foo/Patient/22").execute();
assertThat(response.getName().get(0).getFamily().get(0).getValue(), StringContains.containsString("Cardinal"));
assertEquals("http://foo/Patient/22", capt.getAllValues().get(count++).getURI().toString());
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
response = client.read().resource(Patient.class).withUrl("http://foo/Patient/22").execute();
assertThat(response.getName().get(0).getFamily().get(0).getValue(), StringContains.containsString("Cardinal"));
assertEquals("http://foo/Patient/22", capt.getAllValues().get(count++).getURI().toString());
}
}
@BeforeClass
public static void beforeClass() {
ourCtx = FhirContext.forDstu2Hl7Org();
}
@BeforeClass
public static void beforeClass() {
ourCtx = FhirContext.forDstu2Hl7Org();
}
}

View File

@ -47,9 +47,13 @@ import ca.uhn.fhir.util.UrlUtil;
public class ClientR4Test {
private HttpClient myHttpClient;
private HttpResponse myHttpResponse;
private static FhirContext ourCtx = FhirContext.forR4();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ClientR4Test.class);
private HttpClient myHttpClient;
private HttpResponse myHttpResponse;
// atom-document-large.xml
@Before
public void before() {
@ -61,8 +65,6 @@ public class ClientR4Test {
myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
}
// atom-document-large.xml
public String getHistoryBundleWithTwoResults() {
/*
* //@formatter:off
@ -115,45 +117,11 @@ public class ClientR4Test {
p.setId("http://foo.com/Patient/123/_history/2333");
p.addName().setFamily("Kramer").addGiven("Doe");
p.addIdentifier().setValue("PRP1660");
String msg = EncodingEnum.XML.newParser(ourCtx).setPrettyPrint(true).encodeResourceToString(p);
return msg;
}
static String getPatientFeedWithOneResult() {
Bundle retVal = new Bundle();
Patient p = new Patient();
p.addName().setFamily("Cardinal").addGiven("John");
p.addIdentifier().setValue("PRP1660");
retVal.addEntry().setResource(p);
return ourCtx.newXmlParser().encodeResourceToString(retVal);
// String msg = "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n" +
// "<title/>\n" +
// "<id>d039f91a-cc3c-4013-988e-af4d8d0614bd</id>\n" +
// "<os:totalResults xmlns:os=\"http://a9.com/-/spec/opensearch/1.1/\">1</os:totalResults>\n" +
// "<author>\n" +
// "<name>ca.uhn.fhir.rest.server.DummyRestfulServer</name>\n" +
// "</author>\n" +
// "<entry>\n" +
// "<content type=\"text/xml\">"
// + "<Patient xmlns=\"http://hl7.org/fhir\">"
// + "<text><status value=\"generated\" /><div xmlns=\"http://www.w3.org/1999/xhtml\">John Cardinal: 444333333 </div></text>"
// + "<identifier><label value=\"SSN\" /><system value=\"http://orionhealth.com/mrn\" /><value value=\"PRP1660\" /></identifier>"
// + "<name><use value=\"official\" /><family value=\"Cardinal\" /><given value=\"John\" /></name>"
// + "<name><family value=\"Kramer\" /><given value=\"Doe\" /></name>"
// + "<telecom><system value=\"phone\" /><value value=\"555-555-2004\" /><use value=\"work\" /></telecom>"
// + "<gender><coding><system value=\"http://hl7.org/fhir/v3/AdministrativeGender\" /><code value=\"M\" /></coding></gender>"
// + "<address><use value=\"home\" /><line value=\"2222 Home Street\" /></address><active value=\"true\" />"
// + "</Patient>"
// + "</content>\n"
// + " </entry>\n"
// + "</feed>";
// return msg;
}
@Test
public void testCreate() throws Exception {
@ -270,7 +238,10 @@ public class ClientR4Test {
@Test
public void testGetConformance() throws Exception {
String msg = IOUtils.toString(ClientR4Test.class.getResourceAsStream("/example-metadata.xml"));
CapabilityStatement cs = new CapabilityStatement();
cs.getPublisherElement().setValue("Health Intersections");
String msg = ourCtx.newXmlParser().encodeResourceToString(cs);
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
@ -418,12 +389,15 @@ public class ClientR4Test {
String msg = getPatient();
ourLog.info(msg);
ArgumentCaptor<HttpUriRequest> 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"));
Header[] headers = new Header[] { new BasicHeader(Constants.HEADER_LAST_MODIFIED, "Wed, 15 Nov 1995 04:58:08 GMT"),
new BasicHeader(Constants.HEADER_CONTENT_LOCATION, "http://foo.com/Patient/123/_history/2333"),
new BasicHeader(Constants.HEADER_CATEGORY, "http://foo/tagdefinition.html; scheme=\"http://hl7.org/fhir/tag\"; label=\"Some tag\"") };
Header[] headers = new Header[] {
new BasicHeader(Constants.HEADER_LAST_MODIFIED, "Wed, 15 Nov 1995 04:58:08 GMT"),
new BasicHeader(Constants.HEADER_CONTENT_LOCATION, "http://foo.com/Patient/123/_history/2333")
};
when(myHttpResponse.getAllHeaders()).thenReturn(headers);
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
@ -443,6 +417,8 @@ public class ClientR4Test {
lm.setTimeZoneZulu(true);
assertEquals("1995-11-15T04:58:08.000Z", lm.getValueAsString());
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
List<Coding> tags = response.getMeta().getTag();
assertNotNull(tags);
assertEquals(1, tags.size());
@ -478,9 +454,9 @@ public class ClientR4Test {
@Test
public void testReadFailureNoCharset() throws Exception {
//@formatter:off
String msg = "<OperationOutcome xmlns=\"http://hl7.org/fhir\"></OperationOutcome>";
//@formatter:on
//@formatter:off
String msg = "<OperationOutcome xmlns=\"http://hl7.org/fhir\"></OperationOutcome>";
//@formatter:on
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
@ -615,7 +591,7 @@ public class ClientR4Test {
param.setUpperBound(new DateParam(ParamPrefixEnum.LESSTHAN_OR_EQUALS, "2021-01-01"));
client.getPatientByDateRange(param);
assertEquals("http://foo/Patient?dateRange=ge2011-01-01&dateRange=%3C%3D2021-01-01", capt.getValue().getURI().toString());
assertEquals("http://foo/Patient?dateRange=ge2011-01-01&dateRange=le2021-01-01", capt.getValue().getURI().toString());
}
@ -655,7 +631,7 @@ public class ClientR4Test {
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
Patient response = client.findPatientQuantity(new QuantityParam(ParamPrefixEnum.GREATERTHAN, 123L, "foo", "bar"));
assertEquals("http://foo/Patient?quantityParam=%3E123%7Cfoo%7Cbar", capt.getValue().getURI().toString());
assertEquals("http://foo/Patient?quantityParam=gt123%7Cfoo%7Cbar", capt.getValue().getURI().toString());
assertEquals("PRP1660", response.getIdentifier().get(0).getValueElement().getValue());
}
@ -1080,7 +1056,7 @@ public class ClientR4Test {
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
when(myHttpResponse.getAllHeaders()).thenReturn(toHeaderArray("Content-Location", "http://example.com/fhir/Patient/100/_history/200"));
when(myHttpResponse.getAllHeaders()).thenReturn(toHeaderArray(Constants.HEADER_LOCATION, "http://example.com/fhir/Patient/100/_history/200"));
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
client.updatePatient(new IdType("Patient/100/_history/200"), patient);
@ -1089,7 +1065,7 @@ public class ClientR4Test {
HttpPut post = (HttpPut) capt.getValue();
assertEquals("http://foo/Patient/100", post.getURI().toASCIIString());
Header h = post.getFirstHeader("content-location");
Header h = post.getFirstHeader(Constants.HEADER_LOCATION);
assertEquals("Patient/100/_history/200", h.getValue());
}
@ -1130,7 +1106,7 @@ public class ClientR4Test {
HttpPut post = (HttpPut) capt.getValue();
assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/100"));
assertThat(IOUtils.toString(post.getEntity().getContent()), StringContains.containsString("<Patient"));
assertThat(post.getFirstHeader("Content-Location").getValue(), StringEndsWith.endsWith("Patient/100/_history/200"));
assertThat(post.getFirstHeader(Constants.HEADER_LOCATION).getValue(), StringEndsWith.endsWith("Patient/100/_history/200"));
assertEquals("http://example.com/fhir/Patient/100/_history/200", response.getId().getValue());
assertEquals("200", response.getId().getVersionIdPart());
}
@ -1214,6 +1190,45 @@ public class ClientR4Test {
TestUtil.clearAllStaticFieldsForUnitTest();
}
private static String getPatientFeedWithOneResult() {
return getPatientFeedWithOneResult(ourCtx);
}
static String getPatientFeedWithOneResult(FhirContext theCtx) {
Bundle retVal = new Bundle();
Patient p = new Patient();
p.addName().setFamily("Cardinal").addGiven("John");
p.addIdentifier().setValue("PRP1660");
retVal.addEntry().setResource(p);
return theCtx.newXmlParser().encodeResourceToString(retVal);
// String msg = "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n" +
// "<title/>\n" +
// "<id>d039f91a-cc3c-4013-988e-af4d8d0614bd</id>\n" +
// "<os:totalResults xmlns:os=\"http://a9.com/-/spec/opensearch/1.1/\">1</os:totalResults>\n" +
// "<author>\n" +
// "<name>ca.uhn.fhir.rest.server.DummyRestfulServer</name>\n" +
// "</author>\n" +
// "<entry>\n" +
// "<content type=\"text/xml\">"
// + "<Patient xmlns=\"http://hl7.org/fhir\">"
// + "<text><status value=\"generated\" /><div xmlns=\"http://www.w3.org/1999/xhtml\">John Cardinal: 444333333 </div></text>"
// + "<identifier><label value=\"SSN\" /><system value=\"http://orionhealth.com/mrn\" /><value value=\"PRP1660\" /></identifier>"
// + "<name><use value=\"official\" /><family value=\"Cardinal\" /><given value=\"John\" /></name>"
// + "<name><family value=\"Kramer\" /><given value=\"Doe\" /></name>"
// + "<telecom><system value=\"phone\" /><value value=\"555-555-2004\" /><use value=\"work\" /></telecom>"
// + "<gender><coding><system value=\"http://hl7.org/fhir/v3/AdministrativeGender\" /><code value=\"M\" /></coding></gender>"
// + "<address><use value=\"home\" /><line value=\"2222 Home Street\" /></address><active value=\"true\" />"
// + "</Patient>"
// + "</content>\n"
// + " </entry>\n"
// + "</feed>";
// return msg;
}
private interface ClientWithoutAnnotation extends IBasicClient {
Patient read(@IdParam IdType theId);
}

View File

@ -64,7 +64,7 @@ public class TransactionClientTest {
obs.getCode().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
obs.setSubject(new Reference("Patient/testPersistWithSimpleLinkP01"));
List<IBaseResource> resources = Arrays.asList((IResource) patient, obs);
List<IBaseResource> resources = Arrays.asList((IBaseResource) patient, obs);
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
@ -123,7 +123,7 @@ public class TransactionClientTest {
ourLog.info(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle));
assertEquals(2, bundle.getEntry().size());
assertEquals("http://foo/Patient/testPersistWithSimpleLinkP01", bundle.getEntry().get(0).getIdElement().getValue());
assertEquals("http://foo/Patient/testPersistWithSimpleLinkP01", bundle.getEntry().get(0).getResource().getIdElement().getValue());
assertTrue(bundle.getEntry().get(1).getId().isEmpty());

View File

@ -554,9 +554,6 @@ public class Controller extends BaseController {
} else {
outcomeDescription = "Create Resource";
ICreateTyped create = client.create().resource(body);
if (isNotBlank(id)) {
create.withId(id);
}
create.execute();
}
}

View File

@ -22,6 +22,12 @@
Schematron validator now applies invariants to resources within a Bundle, not
just to the outer Bundle resource itself
</action>
<action type="fix">
Server and Client both still included Category header for resource tags even though
this feature was only present in FHIR DSTU1 and was removed from the specification in
FHIR DSTU2. The presence of these headers sometimes caused parsed resource instances
to contain duplicate tags
</action>
</release>
<release version="2.6" date="TBD">
<action type="add">