|
|
|
@ -1,66 +1,43 @@
|
|
|
|
|
package ca.uhn.fhir.android.client;
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
|
|
import static org.hamcrest.Matchers.startsWith;
|
|
|
|
|
import static org.junit.Assert.assertArrayEquals;
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.StringReader;
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
import org.apache.commons.io.input.ReaderInputStream;
|
|
|
|
|
import org.apache.http.Header;
|
|
|
|
|
import org.apache.http.HttpResponse;
|
|
|
|
|
import org.apache.http.ProtocolVersion;
|
|
|
|
|
import org.apache.http.client.ClientProtocolException;
|
|
|
|
|
import org.apache.http.client.HttpClient;
|
|
|
|
|
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
|
|
|
|
import org.apache.http.client.methods.HttpPut;
|
|
|
|
|
import org.apache.http.client.methods.HttpUriRequest;
|
|
|
|
|
import org.apache.http.message.BasicHeader;
|
|
|
|
|
import org.apache.http.message.BasicStatusLine;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.*;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
|
|
|
|
|
import org.junit.*;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Binary;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.OperationOutcome;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Patient;
|
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
|
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
|
|
|
|
import org.mockito.Mockito;
|
|
|
|
|
import org.mockito.invocation.InvocationOnMock;
|
|
|
|
|
import org.mockito.stubbing.Answer;
|
|
|
|
|
|
|
|
|
|
import ca.uhn.fhir.context.FhirContext;
|
|
|
|
|
import ca.uhn.fhir.context.FhirVersionEnum;
|
|
|
|
|
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
|
|
|
|
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
|
|
|
|
import ca.uhn.fhir.model.primitive.StringDt;
|
|
|
|
|
import ca.uhn.fhir.model.primitive.UriDt;
|
|
|
|
|
import ca.uhn.fhir.parser.IParser;
|
|
|
|
|
import ca.uhn.fhir.rest.api.MethodOutcome;
|
|
|
|
|
import ca.uhn.fhir.rest.api.PreferReturnEnum;
|
|
|
|
|
import ca.uhn.fhir.rest.client.IGenericClient;
|
|
|
|
|
import ca.uhn.fhir.rest.client.ServerValidationModeEnum;
|
|
|
|
|
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
|
|
|
|
|
import ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException;
|
|
|
|
|
import ca.uhn.fhir.rest.client.interceptor.UserInfoInterceptor;
|
|
|
|
|
import ca.uhn.fhir.rest.server.Constants;
|
|
|
|
|
import ca.uhn.fhir.rest.server.EncodingEnum;
|
|
|
|
|
import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException;
|
|
|
|
|
import ca.uhn.fhir.rest.server.exceptions.UnclassifiedServerFailureException;
|
|
|
|
|
import ca.uhn.fhir.util.TestUtil;
|
|
|
|
|
import ca.uhn.fhir.util.UrlUtil;
|
|
|
|
|
import ca.uhn.fhir.util.VersionUtil;
|
|
|
|
|
import okhttp3.*;
|
|
|
|
|
import okio.Buffer;
|
|
|
|
|
|
|
|
|
|
public class GenericClientDstu3IT {
|
|
|
|
|
|
|
|
|
@ -68,51 +45,66 @@ public class GenericClientDstu3IT {
|
|
|
|
|
private static FhirContext ourCtx;
|
|
|
|
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(GenericClientDstu3IT.class);
|
|
|
|
|
private int myAnswerCount;
|
|
|
|
|
private HttpClient myHttpClient;
|
|
|
|
|
private HttpResponse myHttpResponse;
|
|
|
|
|
private Call.Factory myHttpClient;
|
|
|
|
|
private ArgumentCaptor<Request> capt;
|
|
|
|
|
private Response myHttpResponse;
|
|
|
|
|
private Request myRequest;
|
|
|
|
|
private Protocol myProtocol;
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
public void before() {
|
|
|
|
|
myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
|
|
|
|
public void before() throws IOException {
|
|
|
|
|
myHttpClient = mock(Call.Factory.class, Mockito.RETURNS_DEEP_STUBS);
|
|
|
|
|
ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient);
|
|
|
|
|
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
|
|
|
|
myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
|
|
|
|
Call httpResponse = mock(Call.class, Mockito.RETURNS_DEEP_STUBS);
|
|
|
|
|
capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(httpResponse);
|
|
|
|
|
|
|
|
|
|
myRequest = new Request.Builder().url("http://127.0.0.1").build();
|
|
|
|
|
myProtocol = Protocol.HTTP_1_1;
|
|
|
|
|
|
|
|
|
|
when(httpResponse.execute()).thenAnswer(new Answer<Response>() {
|
|
|
|
|
@Override
|
|
|
|
|
public Response answer(InvocationOnMock theInvocation) throws Throwable {
|
|
|
|
|
myAnswerCount++;
|
|
|
|
|
return myHttpResponse;
|
|
|
|
|
}});
|
|
|
|
|
myAnswerCount = 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String expectedUserAgent() {
|
|
|
|
|
return "HAPI-FHIR/" + VersionUtil.getVersion() + " (FHIR Client; FHIR " + FhirVersionEnum.DSTU3.getFhirVersionString() + "/DSTU3; apache)";
|
|
|
|
|
return "HAPI-FHIR/" + VersionUtil.getVersion() + " (FHIR Client; FHIR " + FhirVersionEnum.DSTU3.getFhirVersionString() + "/DSTU3; okhttp/3.4.1)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String extractBodyAsString(ArgumentCaptor<HttpUriRequest> capt) throws IOException {
|
|
|
|
|
String body = IOUtils.toString(((HttpEntityEnclosingRequestBase) capt.getAllValues().get(0)).getEntity().getContent(), "UTF-8");
|
|
|
|
|
return body;
|
|
|
|
|
private String extractBodyAsString(ArgumentCaptor<Request> capt) throws IOException {
|
|
|
|
|
Buffer sink = new Buffer();
|
|
|
|
|
capt.getValue().body().writeTo(sink);
|
|
|
|
|
return new String(sink.readByteArray(), "UTF-8");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateUserAgent(ArgumentCaptor<Request> capt) {
|
|
|
|
|
assertEquals(expectedUserAgent(), capt.getAllValues().get(0).header("User-Agent"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TODO: narratives don't work without stax
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
@Ignore
|
|
|
|
|
public void testBinaryCreateWithFhirContentType() throws Exception {
|
|
|
|
|
IParser p = ourCtx.newXmlParser();
|
|
|
|
|
|
|
|
|
|
OperationOutcome conf = new OperationOutcome();
|
|
|
|
|
conf.getText().setDivAsString("OK!");
|
|
|
|
|
String respString = p.encodeResourceToString(conf);
|
|
|
|
|
|
|
|
|
|
final String respString = p.encodeResourceToString(conf);
|
|
|
|
|
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()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
myHttpResponse = new Response.Builder()
|
|
|
|
|
.request(myRequest)
|
|
|
|
|
.protocol(myProtocol)
|
|
|
|
|
.code(200)
|
|
|
|
|
.body(ResponseBody.create(MediaType.parse(Constants.CT_FHIR_XML + "; charset=UTF-8"), respString))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
|
|
|
|
|
|
|
@ -124,13 +116,14 @@ public class GenericClientDstu3IT {
|
|
|
|
|
bin.setContentType(Constants.CT_FHIR_JSON);
|
|
|
|
|
client.create().resource(bin).execute();
|
|
|
|
|
|
|
|
|
|
ourLog.info(Arrays.asList(capt.getAllValues().get(0).getAllHeaders()).toString());
|
|
|
|
|
Request request = capt.getAllValues().get(0);
|
|
|
|
|
ourLog.info(request.headers().toString());
|
|
|
|
|
|
|
|
|
|
assertEquals("http://example.com/fhir/Binary", capt.getAllValues().get(0).getURI().toASCIIString());
|
|
|
|
|
assertEquals("http://example.com/fhir/Binary", request.url().toString());
|
|
|
|
|
validateUserAgent(capt);
|
|
|
|
|
|
|
|
|
|
assertEquals("application/xml+fhir;charset=utf-8", capt.getAllValues().get(0).getHeaders("Content-Type")[0].getValue().toLowerCase().replace(" ", ""));
|
|
|
|
|
assertEquals(Constants.CT_FHIR_XML, capt.getAllValues().get(0).getHeaders("Accept")[0].getValue());
|
|
|
|
|
assertEquals(Constants.CT_FHIR_XML_NEW + ";charset=utf-8", request.body().contentType().toString().toLowerCase().replace(" ", ""));
|
|
|
|
|
assertEquals(Constants.HEADER_ACCEPT_VALUE_XML_NON_LEGACY, request.header("Accept"));
|
|
|
|
|
Binary output = ourCtx.newXmlParser().parseResource(Binary.class, extractBodyAsString(capt));
|
|
|
|
|
assertEquals(Constants.CT_FHIR_JSON, output.getContentType());
|
|
|
|
|
|
|
|
|
@ -143,7 +136,7 @@ public class GenericClientDstu3IT {
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testNullAndEmptyParamValuesAreIgnored() throws Exception {
|
|
|
|
|
ArgumentCaptor<HttpUriRequest> capt = prepareClientForSearchResponse();
|
|
|
|
|
ArgumentCaptor<Request> capt = prepareClientForSearchResponse();
|
|
|
|
|
|
|
|
|
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
|
|
|
int idx = 0;
|
|
|
|
@ -160,7 +153,7 @@ public class GenericClientDstu3IT {
|
|
|
|
|
.execute();
|
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
assertEquals("http://example.com/fhir/Patient?_format=json", capt.getAllValues().get(idx).getURI().toString());
|
|
|
|
|
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(idx).url().toString());
|
|
|
|
|
idx++;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -171,7 +164,6 @@ public class GenericClientDstu3IT {
|
|
|
|
|
* TODO: narratives don't work without stax
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
@Ignore
|
|
|
|
|
public void testBinaryCreateWithNoContentType() throws Exception {
|
|
|
|
|
IParser p = ourCtx.newJsonParser();
|
|
|
|
|
|
|
|
|
@ -179,16 +171,12 @@ public class GenericClientDstu3IT {
|
|
|
|
|
conf.getText().setDivAsString("OK!");
|
|
|
|
|
|
|
|
|
|
final String respString = p.encodeResourceToString(conf);
|
|
|
|
|
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_JSON_NEW + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
myHttpResponse = new Response.Builder()
|
|
|
|
|
.request(myRequest)
|
|
|
|
|
.protocol(myProtocol)
|
|
|
|
|
.code(200)
|
|
|
|
|
.body(ResponseBody.create(MediaType.parse(Constants.CT_FHIR_JSON_NEW + "; charset=UTF-8"), respString))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
|
|
|
|
|
|
|
@ -196,13 +184,14 @@ public class GenericClientDstu3IT {
|
|
|
|
|
bin.setContent(new byte[] { 0, 1, 2, 3, 4 });
|
|
|
|
|
client.create().resource(bin).execute();
|
|
|
|
|
|
|
|
|
|
ourLog.info(Arrays.asList(capt.getAllValues().get(0).getAllHeaders()).toString());
|
|
|
|
|
Request request = capt.getAllValues().get(0);
|
|
|
|
|
ourLog.info(request.headers().toString());
|
|
|
|
|
|
|
|
|
|
assertEquals("http://example.com/fhir/Binary", capt.getAllValues().get(0).getURI().toASCIIString());
|
|
|
|
|
assertEquals("http://example.com/fhir/Binary", request.url().toString());
|
|
|
|
|
validateUserAgent(capt);
|
|
|
|
|
|
|
|
|
|
assertEquals("application/xml+fhir;charset=utf-8", capt.getAllValues().get(0).getHeaders("Content-Type")[0].getValue().toLowerCase().replace(" ", ""));
|
|
|
|
|
assertEquals(Constants.CT_FHIR_XML, capt.getAllValues().get(0).getHeaders("Accept")[0].getValue());
|
|
|
|
|
assertEquals(Constants.CT_FHIR_XML_NEW + ";charset=utf-8", request.body().contentType().toString().toLowerCase().replace(" ", ""));
|
|
|
|
|
assertEquals(Constants.HEADER_ACCEPT_VALUE_XML_NON_LEGACY, request.header("Accept"));
|
|
|
|
|
assertArrayEquals(new byte[] { 0, 1, 2, 3, 4 }, ourCtx.newXmlParser().parseResource(Binary.class, extractBodyAsString(capt)).getContent());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -210,11 +199,15 @@ public class GenericClientDstu3IT {
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@Test
|
|
|
|
|
public void testClientFailures() 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), 200, "OK"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenThrow(IllegalStateException.class, RuntimeException.class, Exception.class);
|
|
|
|
|
ResponseBody body = mock(ResponseBody.class);
|
|
|
|
|
when(body.source()).thenThrow(IllegalStateException.class, RuntimeException.class, Exception.class);
|
|
|
|
|
|
|
|
|
|
myHttpResponse = new Response.Builder()
|
|
|
|
|
.request(myRequest)
|
|
|
|
|
.protocol(myProtocol)
|
|
|
|
|
.code(200)
|
|
|
|
|
.body(body)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
|
|
|
|
|
|
|
@ -246,30 +239,20 @@ public class GenericClientDstu3IT {
|
|
|
|
|
* TODO: narratives don't work without stax
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
@Ignore
|
|
|
|
|
public void testCreateWithPreferRepresentationServerReturnsResource() throws Exception {
|
|
|
|
|
final IParser p = ourCtx.newJsonParser();
|
|
|
|
|
|
|
|
|
|
final Patient resp1 = new Patient();
|
|
|
|
|
resp1.getText().setDivAsString("FINAL VALUE");
|
|
|
|
|
String respString = p.encodeResourceToString(resp1);
|
|
|
|
|
|
|
|
|
|
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.getAllHeaders()).thenAnswer(new Answer<Header[]>() {
|
|
|
|
|
@Override
|
|
|
|
|
public Header[] answer(InvocationOnMock theInvocation) throws Throwable {
|
|
|
|
|
return new Header[] { new BasicHeader(Constants.HEADER_LOCATION, "http://foo.com/base/Patient/222/_history/3") };
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON_NEW + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
|
|
|
myAnswerCount++;
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
myHttpResponse = new Response.Builder()
|
|
|
|
|
.request(myRequest)
|
|
|
|
|
.protocol(myProtocol)
|
|
|
|
|
.code(200)
|
|
|
|
|
.body(ResponseBody.create(MediaType.parse(Constants.CT_FHIR_JSON_NEW + "; charset=UTF-8"), respString))
|
|
|
|
|
.headers(Headers.of(Constants.HEADER_LOCATION, "http://foo.com/base/Patient/222/_history/3"))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
|
|
|
|
|
|
|
@ -278,19 +261,29 @@ public class GenericClientDstu3IT {
|
|
|
|
|
|
|
|
|
|
MethodOutcome outcome = client.create().resource(pt).prefer(PreferReturnEnum.REPRESENTATION).execute();
|
|
|
|
|
|
|
|
|
|
assertEquals(1, myAnswerCount);
|
|
|
|
|
assertNull(outcome.getOperationOutcome());
|
|
|
|
|
assertNotNull(outcome.getResource());
|
|
|
|
|
|
|
|
|
|
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">FINAL VALUE</div>", ((Patient) outcome.getResource()).getText().getDivAsString());
|
|
|
|
|
|
|
|
|
|
assertEquals(myAnswerCount, capt.getAllValues().size());
|
|
|
|
|
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(0).getURI().toASCIIString());
|
|
|
|
|
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(0).url().toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ArgumentCaptor<Request> prepareClientForSearchResponse() throws IOException, ClientProtocolException {
|
|
|
|
|
final String respString = "{\"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\"}]}}]}";
|
|
|
|
|
myHttpResponse = new Response.Builder()
|
|
|
|
|
.request(myRequest)
|
|
|
|
|
.protocol(myProtocol)
|
|
|
|
|
.code(200)
|
|
|
|
|
.body(ResponseBody.create(MediaType.parse(Constants.CT_FHIR_JSON + "; charset=UTF-8"), respString))
|
|
|
|
|
.headers(Headers.of(Constants.HEADER_LOCATION, "http://foo.com/base/Patient/222/_history/3"))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
return capt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -304,10 +297,11 @@ public class GenericClientDstu3IT {
|
|
|
|
|
final Patient patient = new Patient();
|
|
|
|
|
patient.addName().addFamily("FAM");
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON_NEW + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.execute().body()).thenReturn(ResponseBody.create(MediaType.parse(Constants.CT_FHIR_XML + "; charset=UTF-8"), respString));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
private int myCount = 0;
|
|
|
|
|
|
|
|
|
@ -345,8 +339,8 @@ public class GenericClientDstu3IT {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testHttp499() throws Exception {
|
|
|
|
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
|
|
|
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 499, "Wacky Message"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<InputStream>() {
|
|
|
|
@ -370,8 +364,8 @@ public class GenericClientDstu3IT {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testHttp501() throws Exception {
|
|
|
|
|
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
|
|
|
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 501, "Not Implemented"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<InputStream>() {
|
|
|
|
@ -421,9 +415,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
final String encoded = p.encodeResourceToString(bundle);
|
|
|
|
|
assertEquals("{\"resourceType\":\"Bundle\",\"id\":\"BUNDLE1\",\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"PATIENT1\",\"name\":[{\"family\":[\"PATIENT1\"]}]}}]}", encoded);
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON_NEW + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
@ -456,9 +450,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
patient.addName().addFamily("FAM");
|
|
|
|
|
final String respString = p.encodeResourceToString(patient);
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(null);
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
@ -486,9 +480,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
patient.addName().addFamily("FAM");
|
|
|
|
|
final String respString = p.encodeResourceToString(patient);
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", "text/plain"));
|
|
|
|
|
// when(myHttpResponse.getEntity().getContentType()).thenReturn(null);
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
@ -514,9 +508,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
public void testSearchByDate() throws Exception {
|
|
|
|
|
final String msg = "{\"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\"}]}}]}";
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
|
|
|
@Override
|
|
|
|
@ -548,9 +542,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
public void testSearchByString() throws Exception {
|
|
|
|
|
final String msg = "{\"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\"}]}}]}";
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
|
|
|
@Override
|
|
|
|
@ -628,9 +622,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
public void testSearchByUrl() throws Exception {
|
|
|
|
|
final String msg = "{\"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\"}]}}]}";
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
|
|
|
@Override
|
|
|
|
@ -658,9 +652,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
public void testAcceptHeaderWithEncodingSpecified() throws Exception {
|
|
|
|
|
final String msg = "{\"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\"}]}}]}";
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
|
|
|
@Override
|
|
|
|
@ -707,21 +701,6 @@ public class GenericClientDstu3IT {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ArgumentCaptor<HttpUriRequest> prepareClientForSearchResponse() throws IOException, ClientProtocolException {
|
|
|
|
|
final String msg = "{\"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\"}]}}]}";
|
|
|
|
|
|
|
|
|
|
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_JSON + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
|
|
|
|
return new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return capt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -764,9 +743,7 @@ public class GenericClientDstu3IT {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TODO: narratives don't work without stax
|
|
|
|
|
*/
|
|
|
|
|
//TODO: narratives don't work without stax
|
|
|
|
|
@Test
|
|
|
|
|
@Ignore
|
|
|
|
|
public void testUpdateById() throws Exception {
|
|
|
|
@ -776,9 +753,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
conf.getText().setDivAsString("OK!");
|
|
|
|
|
|
|
|
|
|
final String respString = p.encodeResourceToString(conf);
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON_NEW + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
@ -806,9 +783,7 @@ public class GenericClientDstu3IT {
|
|
|
|
|
assertThat(body, containsString("<id value=\"111\"/>"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TODO: narratives don't work without stax
|
|
|
|
|
*/
|
|
|
|
|
// TODO: narratives don't work without stax
|
|
|
|
|
@Test
|
|
|
|
|
@Ignore
|
|
|
|
|
public void testUpdateWithPreferRepresentationServerReturnsOO() throws Exception {
|
|
|
|
@ -820,9 +795,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
final Patient resp1 = new Patient();
|
|
|
|
|
resp1.getText().setDivAsString("FINAL VALUE");
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getAllHeaders()).thenAnswer(new Answer<Header[]>() {
|
|
|
|
|
@Override
|
|
|
|
|
public Header[] answer(InvocationOnMock theInvocation) throws Throwable {
|
|
|
|
@ -868,9 +843,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
final Patient resp1 = new Patient();
|
|
|
|
|
resp1.setActive(true);
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getAllHeaders()).thenAnswer(new Answer<Header[]>() {
|
|
|
|
|
@Override
|
|
|
|
|
public Header[] answer(InvocationOnMock theInvocation) throws Throwable {
|
|
|
|
@ -913,9 +888,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
conf.setCopyright("COPY");
|
|
|
|
|
|
|
|
|
|
final String respString = p.encodeResourceToString(conf);
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON_NEW + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
@ -932,9 +907,7 @@ public class GenericClientDstu3IT {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TODO: narratives don't work without stax
|
|
|
|
|
*/
|
|
|
|
|
// TODO: narratives don't work without stax
|
|
|
|
|
@Test
|
|
|
|
|
@Ignore
|
|
|
|
|
public void testValidate() throws Exception {
|
|
|
|
@ -943,9 +916,9 @@ public class GenericClientDstu3IT {
|
|
|
|
|
final OperationOutcome resp0 = new OperationOutcome();
|
|
|
|
|
resp0.getText().setDivAsString("OK!");
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
ArgumentCaptor<Request> capt = ArgumentCaptor.forClass(Request.class);
|
|
|
|
|
when(myHttpClient.newCall(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
|
when(myHttpResponse.execute().code()).thenReturn(200);
|
|
|
|
|
when(myHttpResponse.getAllHeaders()).thenAnswer(new Answer<Header[]>() {
|
|
|
|
|
@Override
|
|
|
|
|
public Header[] answer(InvocationOnMock theInvocation) throws Throwable {
|
|
|
|
@ -973,11 +946,10 @@ public class GenericClientDstu3IT {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateUserAgent(ArgumentCaptor<HttpUriRequest> capt) {
|
|
|
|
|
assertEquals(1, capt.getAllValues().get(0).getHeaders("User-Agent").length);
|
|
|
|
|
assertEquals(expectedUserAgent(), capt.getAllValues().get(0).getHeaders("User-Agent")[0].getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void afterClassClearContext() {
|
|
|
|
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
|
|
|
@ -986,11 +958,10 @@ public class GenericClientDstu3IT {
|
|
|
|
|
@BeforeClass
|
|
|
|
|
public static void beforeClass() {
|
|
|
|
|
|
|
|
|
|
// Force StAX to fail like it will on android
|
|
|
|
|
System.setProperty("javax.xml.stream.XMLInputFactory", "FOO");
|
|
|
|
|
System.setProperty("javax.xml.stream.XMLOutputFactory", "FOO");
|
|
|
|
|
// // Force StAX to fail like it will on android
|
|
|
|
|
// System.setProperty("javax.xml.stream.XMLInputFactory", "FOO");
|
|
|
|
|
// System.setProperty("javax.xml.stream.XMLOutputFactory", "FOO");
|
|
|
|
|
|
|
|
|
|
ourCtx = FhirContext.forDstu3();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|