diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java index 2c618758489..f6d88a86b8e 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java @@ -2651,6 +2651,11 @@ public class GenericClientDstu2Test { // nothing } + @Override + public void setFormatParamStyle(RequestFormatParamStyleEnum theRequestFormatParamStyle) { + // nothing + } + @Override public EncodingEnum getEncoding() { // TODO Auto-generated method stub diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/OperationClientR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/OperationClientR4Test.java index 94d686d93da..b485105735b 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/OperationClientR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/OperationClientR4Test.java @@ -1,41 +1,45 @@ package ca.uhn.fhir.rest.client; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.rest.annotation.Operation; +import ca.uhn.fhir.rest.annotation.OperationParam; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.client.api.IBasicClient; +import ca.uhn.fhir.rest.client.api.IGenericClient; +import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; +import ca.uhn.fhir.rest.param.*; +import ca.uhn.fhir.util.TestUtil; +import com.google.common.base.Charsets; +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.input.ReaderInputStream; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.message.BasicHeader; +import org.apache.http.message.BasicStatusLine; +import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.Parameters; +import org.hl7.fhir.r4.model.StringType; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; import java.io.InputStream; import java.io.StringReader; import java.nio.charset.Charset; import java.util.List; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.input.ReaderInputStream; -import org.apache.http.HttpResponse; -import org.apache.http.ProtocolVersion; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.*; -import org.apache.http.message.BasicHeader; -import org.apache.http.message.BasicStatusLine; -import org.hl7.fhir.r4.model.IdType; -import org.hl7.fhir.r4.model.Parameters; -import org.hl7.fhir.r4.model.StringType; -import org.junit.*; -import org.mockito.ArgumentCaptor; -import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import com.google.common.base.Charsets; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.annotation.Operation; -import ca.uhn.fhir.rest.annotation.OperationParam; -import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.client.api.*; -import ca.uhn.fhir.rest.param.*; -import ca.uhn.fhir.util.TestUtil; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class OperationClientR4Test { @@ -48,13 +52,6 @@ public class OperationClientR4Test { private ArgumentCaptor capt; private IGenericClient ourGenClient; - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @Before public void before() throws Exception { ourCtx = FhirContext.forR4(); @@ -64,7 +61,7 @@ public class OperationClientR4Test { ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); ourHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs()); - + Parameters outParams = new Parameters(); outParams.addParameter().setName("FOO"); final String retVal = ourCtx.newXmlParser().encodeResourceToString(outParams); @@ -75,7 +72,7 @@ public class OperationClientR4Test { when(ourHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(ourHttpResponse.getEntity().getContent()).thenAnswer(new Answer() { @Override - public InputStream answer(InvocationOnMock theInvocation) throws Throwable { + public InputStream answer(InvocationOnMock theInvocation) { return new ReaderInputStream(new StringReader(retVal), Charset.forName("UTF-8")); } }); @@ -95,10 +92,10 @@ public class OperationClientR4Test { .execute(); Parameters response = ourAnnClient.nonrepeating(new StringParam("str"), new TokenParam("sys", "val")); assertEquals("FOO", response.getParameter().get(0).getName()); - + HttpPost value = (HttpPost) capt.getAllValues().get(0); - String requestBody = IOUtils.toString(((HttpPost) value).getEntity().getContent(), Charsets.UTF_8); - IOUtils.closeQuietly(((HttpPost) value).getEntity().getContent()); + String requestBody = IOUtils.toString(value.getEntity().getContent(), Charsets.UTF_8); + IOUtils.closeQuietly(value.getEntity().getContent()); ourLog.info(requestBody); Parameters request = ourCtx.newXmlParser().parseResource(Parameters.class, requestBody); assertEquals("http://foo/$nonrepeating", value.getURI().toASCIIString()); @@ -110,7 +107,7 @@ public class OperationClientR4Test { } @Test - public void testNonRepeatingGenericUsingUrl() throws Exception { + public void testNonRepeatingGenericUsingUrl() { ourGenClient .operation() .onServer() @@ -121,14 +118,13 @@ public class OperationClientR4Test { .execute(); Parameters response = ourAnnClient.nonrepeating(new StringParam("str"), new TokenParam("sys", "val")); assertEquals("FOO", response.getParameter().get(0).getName()); - + HttpGet value = (HttpGet) capt.getAllValues().get(0); assertEquals("http://foo/$nonrepeating?valstr=str&valtok=sys2%7Cval2", value.getURI().toASCIIString()); } - @Test - public void testOperationOnInstanceWithIncompleteInstanceId() throws Exception { + public void testOperationOnInstanceWithIncompleteInstanceId() { try { ourGenClient .operation() @@ -146,10 +142,10 @@ public class OperationClientR4Test { public void testNonRepeatingUsingParameters() throws Exception { Parameters response = ourAnnClient.nonrepeating(new StringParam("str"), new TokenParam("sys", "val")); assertEquals("FOO", response.getParameter().get(0).getName()); - + HttpPost value = (HttpPost) capt.getAllValues().get(0); - String requestBody = IOUtils.toString(((HttpPost) value).getEntity().getContent(), Charsets.UTF_8); - IOUtils.closeQuietly(((HttpPost) value).getEntity().getContent()); + String requestBody = IOUtils.toString(value.getEntity().getContent(), Charsets.UTF_8); + IOUtils.closeQuietly(value.getEntity().getContent()); ourLog.info(requestBody); Parameters request = ourCtx.newXmlParser().parseResource(Parameters.class, requestBody); assertEquals("http://foo/$nonrepeating", value.getURI().toASCIIString()); @@ -160,48 +156,52 @@ public class OperationClientR4Test { assertEquals("sys|val", ((StringType) request.getParameter().get(1).getValue()).getValue()); } - - public interface IOpClient extends IBasicClient { + public interface IOpClient extends IBasicClient { @Operation(name = "$andlist", idempotent = true) - public Parameters andlist( - //@formatter:off - @OperationParam(name="valstr", max=10) StringAndListParam theValStr, - @OperationParam(name="valtok", max=10) TokenAndListParam theValTok - //@formatter:on + Parameters andlist( + //@formatter:off + @OperationParam(name = "valstr", max = 10) StringAndListParam theValStr, + @OperationParam(name = "valtok", max = 10) TokenAndListParam theValTok + //@formatter:on ); @Operation(name = "$andlist-withnomax", idempotent = true) - public Parameters andlistWithNoMax( - //@formatter:off - @OperationParam(name="valstr") StringAndListParam theValStr, - @OperationParam(name="valtok") TokenAndListParam theValTok - //@formatter:on + Parameters andlistWithNoMax( + //@formatter:off + @OperationParam(name = "valstr") StringAndListParam theValStr, + @OperationParam(name = "valtok") TokenAndListParam theValTok + //@formatter:on ); @Operation(name = "$nonrepeating", idempotent = true) - public Parameters nonrepeating( - //@formatter:off - @OperationParam(name="valstr") StringParam theValStr, - @OperationParam(name="valtok") TokenParam theValTok - //@formatter:on + Parameters nonrepeating( + //@formatter:off + @OperationParam(name = "valstr") StringParam theValStr, + @OperationParam(name = "valtok") TokenParam theValTok + //@formatter:on ); @Operation(name = "$orlist", idempotent = true) - public Parameters orlist( - //@formatter:off - @OperationParam(name="valstr", max=10) List theValStr, - @OperationParam(name="valtok", max=10) List theValTok - //@formatter:on + Parameters orlist( + //@formatter:off + @OperationParam(name = "valstr", max = 10) List theValStr, + @OperationParam(name = "valtok", max = 10) List theValTok + //@formatter:on ); @Operation(name = "$orlist-withnomax", idempotent = true) - public Parameters orlistWithNoMax( - //@formatter:off - @OperationParam(name="valstr") List theValStr, - @OperationParam(name="valtok") List theValTok - //@formatter:on + Parameters orlistWithNoMax( + //@formatter:off + @OperationParam(name = "valstr") List theValStr, + @OperationParam(name = "valtok") List theValTok + //@formatter:on ); } + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } }