|
|
|
@ -7,8 +7,13 @@ import ca.uhn.fhir.model.primitive.StringDt;
|
|
|
|
|
import ca.uhn.fhir.parser.CustomTypeR4Test;
|
|
|
|
|
import ca.uhn.fhir.parser.CustomTypeR4Test.MyCustomPatient;
|
|
|
|
|
import ca.uhn.fhir.parser.IParser;
|
|
|
|
|
import ca.uhn.fhir.rest.api.DeleteCascadeModeEnum;
|
|
|
|
|
import ca.uhn.fhir.rest.api.Constants;
|
|
|
|
|
import ca.uhn.fhir.rest.api.*;
|
|
|
|
|
import ca.uhn.fhir.rest.api.EncodingEnum;
|
|
|
|
|
import ca.uhn.fhir.rest.api.MethodOutcome;
|
|
|
|
|
import ca.uhn.fhir.rest.api.PreferReturnEnum;
|
|
|
|
|
import ca.uhn.fhir.rest.api.SortOrderEnum;
|
|
|
|
|
import ca.uhn.fhir.rest.api.SortSpec;
|
|
|
|
|
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
|
|
|
|
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
|
|
|
|
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
|
|
|
|
@ -31,6 +36,8 @@ 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.instance.model.api.IBaseOperationOutcome;
|
|
|
|
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
|
|
|
|
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
|
|
|
|
import org.hl7.fhir.r4.model.*;
|
|
|
|
|
import org.hl7.fhir.r4.model.Bundle.BundleType;
|
|
|
|
@ -43,13 +50,24 @@ import java.io.ByteArrayInputStream;
|
|
|
|
|
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.*;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
|
|
import static org.hamcrest.Matchers.startsWith;
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
import static org.junit.Assert.assertArrayEquals;
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
|
@ -115,7 +133,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -125,7 +143,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
pt.getText().setDivAsString("A PATIENT");
|
|
|
|
|
|
|
|
|
|
Binary bin = new Binary();
|
|
|
|
|
bin.setContent(ourCtx.newJsonParser().encodeResourceToString(pt).getBytes("UTF-8"));
|
|
|
|
|
bin.setContent(ourCtx.newJsonParser().encodeResourceToString(pt).getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
bin.setContentType(Constants.CT_FHIR_JSON);
|
|
|
|
|
client.create().resource(bin).execute();
|
|
|
|
|
|
|
|
|
@ -139,7 +157,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
Binary output = ourCtx.newJsonParser().parseResource(Binary.class, extractBodyAsString(capt));
|
|
|
|
|
assertEquals(Constants.CT_FHIR_JSON, output.getContentType());
|
|
|
|
|
|
|
|
|
|
Patient outputPt = (Patient) ourCtx.newJsonParser().parseResource(new String(output.getContent(), "UTF-8"));
|
|
|
|
|
Patient outputPt = (Patient) ourCtx.newJsonParser().parseResource(new String(output.getContent(), StandardCharsets.UTF_8));
|
|
|
|
|
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">A PATIENT</div>", outputPt.getText().getDivAsString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -158,7 +176,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -222,7 +240,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -262,9 +280,9 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
if (myAnswerCount++ == 0) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), StandardCharsets.UTF_8);
|
|
|
|
|
} else {
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -311,7 +329,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
myAnswerCount++;
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -332,6 +350,78 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(0).getURI().toASCIIString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testDeleteCascade() throws Exception {
|
|
|
|
|
final IParser p = ourCtx.newXmlParser();
|
|
|
|
|
|
|
|
|
|
OperationOutcome oo = new OperationOutcome();
|
|
|
|
|
oo.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"));
|
|
|
|
|
when(myHttpResponse.getAllHeaders()).thenAnswer(new Answer<Header[]>() {
|
|
|
|
|
@Override
|
|
|
|
|
public Header[] answer(InvocationOnMock theInvocation) {
|
|
|
|
|
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_XML + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
myAnswerCount++;
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(oo)), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
|
|
|
IBaseOperationOutcome outcome;
|
|
|
|
|
|
|
|
|
|
// Regular delete
|
|
|
|
|
outcome = client
|
|
|
|
|
.delete()
|
|
|
|
|
.resourceById(new IdType("Patient/222"))
|
|
|
|
|
.execute();
|
|
|
|
|
assertNotNull(outcome);
|
|
|
|
|
assertEquals(1, capt.getAllValues().size());
|
|
|
|
|
assertEquals("http://example.com/fhir/Patient/222", capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
|
|
|
|
|
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
|
|
|
|
|
|
|
|
|
|
// NONE Cascading delete
|
|
|
|
|
outcome = client
|
|
|
|
|
.delete()
|
|
|
|
|
.resourceById(new IdType("Patient/222"))
|
|
|
|
|
.cascade(DeleteCascadeModeEnum.NONE)
|
|
|
|
|
.execute();
|
|
|
|
|
assertNotNull(outcome);
|
|
|
|
|
assertEquals(2, capt.getAllValues().size());
|
|
|
|
|
assertEquals("http://example.com/fhir/Patient/222", capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
|
|
|
|
|
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
|
|
|
|
|
|
|
|
|
|
// DELETE Cascading delete
|
|
|
|
|
outcome = client
|
|
|
|
|
.delete()
|
|
|
|
|
.resourceById(new IdType("Patient/222"))
|
|
|
|
|
.cascade(DeleteCascadeModeEnum.DELETE)
|
|
|
|
|
.execute();
|
|
|
|
|
assertNotNull(outcome);
|
|
|
|
|
assertEquals(myAnswerCount, capt.getAllValues().size());
|
|
|
|
|
assertEquals("http://example.com/fhir/Patient/222?" + Constants.PARAMETER_CASCADE_DELETE + "=" + Constants.CASCADE_DELETE, capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
|
|
|
|
|
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
|
|
|
|
|
|
|
|
|
|
// DELETE Cascading delete on search URL
|
|
|
|
|
outcome = client
|
|
|
|
|
.delete()
|
|
|
|
|
.resourceConditionalByUrl("Patient?identifier=sys|val")
|
|
|
|
|
.cascade(DeleteCascadeModeEnum.DELETE)
|
|
|
|
|
.execute();
|
|
|
|
|
assertNotNull(outcome);
|
|
|
|
|
assertEquals(myAnswerCount, capt.getAllValues().size());
|
|
|
|
|
assertEquals("http://example.com/fhir/Patient?identifier=sys%7Cval&" + Constants.PARAMETER_CASCADE_DELETE + "=" + Constants.CASCADE_DELETE, capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
|
|
|
|
|
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testExplicitCustomTypeHistoryType() throws Exception {
|
|
|
|
|
final String respString = CustomTypeR4Test.createBundle(CustomTypeR4Test.createResource(false));
|
|
|
|
@ -342,7 +432,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -369,7 +459,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -414,7 +504,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -454,7 +544,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -499,7 +589,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
respString = p.encodeResourceToString(conf);
|
|
|
|
|
}
|
|
|
|
|
myCount++;
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -547,7 +637,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
respString = p.encodeResourceToString(conf);
|
|
|
|
|
}
|
|
|
|
|
myAnswerCount++;
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -587,7 +677,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> {
|
|
|
|
|
IParser p = ourCtx.newXmlParser();
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
|
|
@ -748,7 +838,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -792,7 +882,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -836,7 +926,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -879,7 +969,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
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/html"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8")));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8));
|
|
|
|
|
when(myHttpResponse.getAllHeaders()).thenReturn(new Header[]{
|
|
|
|
|
new BasicHeader("content-type", "text/html")
|
|
|
|
|
});
|
|
|
|
@ -914,7 +1004,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
Parameters inputParams = new Parameters();
|
|
|
|
|
inputParams.addParameter().setName("name").setValue(new BooleanType(true));
|
|
|
|
|
|
|
|
|
|
final byte[] respBytes = new byte[]{0,1,2,3,4,5,6,7,8,9,100};
|
|
|
|
|
final byte[] respBytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 100};
|
|
|
|
|
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"));
|
|
|
|
@ -959,7 +1049,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1013,7 +1103,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public InputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1052,7 +1142,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public InputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1091,7 +1181,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public InputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1129,7 +1219,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public InputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1167,7 +1257,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public InputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1205,7 +1295,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public InputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1252,7 +1342,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(encoded), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(encoded), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1297,7 +1387,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(encoded), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(encoded), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1326,7 +1416,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
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()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8));
|
|
|
|
|
|
|
|
|
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
|
|
|
|
|
|
|
@ -1355,7 +1445,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1386,7 +1476,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1433,6 +1523,8 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
DateTimeDt now = DateTimeDt.withCurrentTime();
|
|
|
|
|
String dateString = now.getValueAsString().substring(0, 10);
|
|
|
|
|
|
|
|
|
|
DateTimeDt nowWithMillis = new DateTimeDt(new Date(), TemporalPrecisionEnum.MILLI, TimeZone.getDefault());
|
|
|
|
|
|
|
|
|
|
client.search()
|
|
|
|
|
.forResource("Patient")
|
|
|
|
|
.where(Patient.BIRTHDATE.after().day(dateString))
|
|
|
|
@ -1505,6 +1597,24 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
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().millis("2011-01-02T22:33:01.123Z"))
|
|
|
|
|
.returnBundle(Bundle.class)
|
|
|
|
|
.execute();
|
|
|
|
|
|
|
|
|
|
assertEquals("http://example.com/fhir/Patient?birthdate=gt2011-01-02T22:33:01.123Z", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
|
|
|
|
idx++;
|
|
|
|
|
|
|
|
|
|
client.search()
|
|
|
|
|
.forResource("Patient")
|
|
|
|
|
.where(Patient.BIRTHDATE.after().millis(nowWithMillis.getValue()))
|
|
|
|
|
.returnBundle(Bundle.class)
|
|
|
|
|
.execute();
|
|
|
|
|
|
|
|
|
|
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + nowWithMillis.getValueAsString(), UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
|
|
|
|
idx++;
|
|
|
|
|
|
|
|
|
|
client.search()
|
|
|
|
|
.forResource("Patient")
|
|
|
|
|
.where(Patient.BIRTHDATE.after().now())
|
|
|
|
@ -1735,12 +1845,12 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
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()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8));
|
|
|
|
|
|
|
|
|
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
|
|
|
|
|
|
|
|
HashMap<String, List<IQueryParameterType>> params = new HashMap<String, List<IQueryParameterType>>();
|
|
|
|
|
params.put("foo", Arrays.asList((IQueryParameterType) new DateParam("2001")));
|
|
|
|
|
params.put("foo", Arrays.asList(new DateParam("2001")));
|
|
|
|
|
Bundle response = client
|
|
|
|
|
.search()
|
|
|
|
|
.forResource(Patient.class)
|
|
|
|
@ -1783,7 +1893,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
|
|
|
|
|
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")));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8));
|
|
|
|
|
|
|
|
|
|
// httpResponse = new BasicHttpResponse(statusline, catalog, locale)
|
|
|
|
|
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
|
|
|
@ -1834,7 +1944,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> {
|
|
|
|
|
IParser p = ourCtx.newXmlParser();
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
|
|
@ -1872,7 +1982,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1925,7 +2035,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> {
|
|
|
|
|
IParser p = ourCtx.newXmlParser();
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
|
|
|
@ -2004,7 +2114,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -2051,9 +2161,9 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
if (myAnswerCount++ == 0) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), StandardCharsets.UTF_8);
|
|
|
|
|
} else {
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -2099,7 +2209,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
myAnswerCount++;
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -2136,7 +2246,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -2173,7 +2283,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -2194,7 +2304,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -2229,7 +2339,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -2262,7 +2372,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -2300,7 +2410,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|
|
|
|
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReaderInputStream answer(InvocationOnMock theInvocation) {
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
|
|
|
|
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|