diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/valueset/SecurityEventObjectSensitivityEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/valueset/SecurityEventObjectSensitivityEnum.java deleted file mode 100644 index bb5fc970c81..00000000000 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/valueset/SecurityEventObjectSensitivityEnum.java +++ /dev/null @@ -1,125 +0,0 @@ - -package ca.uhn.fhir.model.dstu.valueset; - -/* - * #%L - * HAPI FHIR - Core Library - * %% - * Copyright (C) 2014 - 2016 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import java.util.HashMap; -import java.util.Map; - -import ca.uhn.fhir.model.api.IValueSetEnumBinder; -import ca.uhn.fhir.util.CoverageIgnore; - -@CoverageIgnore -public enum SecurityEventObjectSensitivityEnum { - - ; - - /** - * Identifier for this Value Set: - * http://hl7.org/fhir/vs/security-event-sensitivity - */ - public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/security-event-sensitivity"; - - /** - * Name for this Value Set: - * Security Event Object Sensitivity - */ - public static final String VALUESET_NAME = "Security Event Object Sensitivity"; - - private static Map CODE_TO_ENUM = new HashMap(); - private static Map> SYSTEM_TO_CODE_TO_ENUM = new HashMap>(); - - private final String myCode; - private final String mySystem; - - static { - for (SecurityEventObjectSensitivityEnum next : SecurityEventObjectSensitivityEnum.values()) { - CODE_TO_ENUM.put(next.getCode(), next); - - if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) { - SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap()); - } - SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next); - } - } - - /** - * Returns the code associated with this enumerated value - */ - public String getCode() { - return myCode; - } - - /** - * Returns the code system associated with this enumerated value - */ - public String getSystem() { - return mySystem; - } - - /** - * Returns the enumerated value associated with this code - */ - public SecurityEventObjectSensitivityEnum forCode(String theCode) { - SecurityEventObjectSensitivityEnum retVal = CODE_TO_ENUM.get(theCode); - return retVal; - } - - /** - * Converts codes to their respective enumerated values - */ - public static final IValueSetEnumBinder VALUESET_BINDER = new IValueSetEnumBinder() { - @Override - public String toCodeString(SecurityEventObjectSensitivityEnum theEnum) { - return theEnum.getCode(); - } - - @Override - public String toSystemString(SecurityEventObjectSensitivityEnum theEnum) { - return theEnum.getSystem(); - } - - @Override - public SecurityEventObjectSensitivityEnum fromCodeString(String theCodeString) { - return CODE_TO_ENUM.get(theCodeString); - } - - @Override - public SecurityEventObjectSensitivityEnum fromCodeString(String theCodeString, String theSystemString) { - Map map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString); - if (map == null) { - return null; - } - return map.get(theCodeString); - } - - }; - - /** - * Constructor - */ - SecurityEventObjectSensitivityEnum(String theCode, String theSystem) { - myCode = theCode; - mySystem = theSystem; - } - - -} diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/valueset/SecurityEventObjectTypeEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/valueset/SecurityEventObjectTypeEnum.java deleted file mode 100644 index 67459ba11d5..00000000000 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/valueset/SecurityEventObjectTypeEnum.java +++ /dev/null @@ -1,153 +0,0 @@ - -package ca.uhn.fhir.model.dstu.valueset; - -/* - * #%L - * HAPI FHIR - Core Library - * %% - * Copyright (C) 2014 - 2016 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import java.util.HashMap; -import java.util.Map; - -import ca.uhn.fhir.model.api.IValueSetEnumBinder; -import ca.uhn.fhir.util.CoverageIgnore; - -@CoverageIgnore -public enum SecurityEventObjectTypeEnum { - - /** - * Code Value: 1 - * - * Person. - */ - PERSON("1", "http://hl7.org/fhir/object-type"), - - /** - * Code Value: 2 - * - * System Object. - */ - SYSTEM_OBJECT("2", "http://hl7.org/fhir/object-type"), - - /** - * Code Value: 3 - * - * Organization. - */ - ORGANIZATION("3", "http://hl7.org/fhir/object-type"), - - /** - * Code Value: 4 - * - * Other. - */ - OTHER("4", "http://hl7.org/fhir/object-type"), - - ; - - /** - * Identifier for this Value Set: - * http://hl7.org/fhir/vs/object-type - */ - public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/object-type"; - - /** - * Name for this Value Set: - * SecurityEventObjectType - */ - public static final String VALUESET_NAME = "SecurityEventObjectType"; - - private static Map CODE_TO_ENUM = new HashMap(); - private static Map> SYSTEM_TO_CODE_TO_ENUM = new HashMap>(); - - private final String myCode; - private final String mySystem; - - static { - for (SecurityEventObjectTypeEnum next : SecurityEventObjectTypeEnum.values()) { - CODE_TO_ENUM.put(next.getCode(), next); - - if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) { - SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap()); - } - SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next); - } - } - - /** - * Returns the code associated with this enumerated value - */ - public String getCode() { - return myCode; - } - - /** - * Returns the code system associated with this enumerated value - */ - public String getSystem() { - return mySystem; - } - - /** - * Returns the enumerated value associated with this code - */ - public SecurityEventObjectTypeEnum forCode(String theCode) { - SecurityEventObjectTypeEnum retVal = CODE_TO_ENUM.get(theCode); - return retVal; - } - - /** - * Converts codes to their respective enumerated values - */ - public static final IValueSetEnumBinder VALUESET_BINDER = new IValueSetEnumBinder() { - @Override - public String toCodeString(SecurityEventObjectTypeEnum theEnum) { - return theEnum.getCode(); - } - - @Override - public String toSystemString(SecurityEventObjectTypeEnum theEnum) { - return theEnum.getSystem(); - } - - @Override - public SecurityEventObjectTypeEnum fromCodeString(String theCodeString) { - return CODE_TO_ENUM.get(theCodeString); - } - - @Override - public SecurityEventObjectTypeEnum fromCodeString(String theCodeString, String theSystemString) { - Map map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString); - if (map == null) { - return null; - } - return map.get(theCodeString); - } - - }; - - /** - * Constructor - */ - SecurityEventObjectTypeEnum(String theCode, String theSystem) { - myCode = theCode; - mySystem = theSystem; - } - - -} diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java index 47f0567f663..653199656d6 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java @@ -137,7 +137,7 @@ import ca.uhn.fhir.rest.method.SearchStyleEnum; import ca.uhn.fhir.rest.method.SortParameter; import ca.uhn.fhir.rest.method.TransactionMethodBinding; import ca.uhn.fhir.rest.method.ValidateMethodBindingDstu1; -import ca.uhn.fhir.rest.method.ValidateMethodBindingDstu2; +import ca.uhn.fhir.rest.method.ValidateMethodBindingDstu2Plus; import ca.uhn.fhir.rest.param.DateParam; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.TokenParam; @@ -556,7 +556,7 @@ public class GenericClient extends BaseClient implements IGenericClient { if (myContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) { invocation = ValidateMethodBindingDstu1.createValidateInvocation(theResource, null, myContext); } else { - invocation = ValidateMethodBindingDstu2.createValidateInvocation(myContext, theResource); + invocation = ValidateMethodBindingDstu2Plus.createValidateInvocation(myContext, theResource); } if (isKeepResponses()) { @@ -2409,7 +2409,7 @@ public class GenericClient extends BaseClient implements IGenericClient { @Override public MethodOutcome execute() { - BaseHttpClientInvocation invocation = ValidateMethodBindingDstu2.createValidateInvocation(myContext, myResource); + BaseHttpClientInvocation invocation = ValidateMethodBindingDstu2Plus.createValidateInvocation(myContext, myResource); ResourceResponseHandler handler = new ResourceResponseHandler(null, null); IBaseOperationOutcome outcome = invoke(null, handler, invocation); MethodOutcome retVal = new MethodOutcome(); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseMethodBinding.java index 5b85b4c3549..8b96fa8230e 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseMethodBinding.java @@ -516,7 +516,7 @@ public abstract class BaseMethodBinding implements IClientResponseHandler if (theContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) { return new ValidateMethodBindingDstu1(theMethod, theContext, theProvider); } else { - return new ValidateMethodBindingDstu2(returnType, returnTypeFromRp, theMethod, theContext, theProvider, validate); + return new ValidateMethodBindingDstu2Plus(returnType, returnTypeFromRp, theMethod, theContext, theProvider, validate); } } else if (getTags != null) { return new GetTagsMethodBinding(theMethod, theContext, theProvider, getTags); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2Plus.java similarity index 92% rename from hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2.java rename to hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2Plus.java index ae74a088d6f..fdec32451b8 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2Plus.java @@ -37,9 +37,9 @@ import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.util.ParametersUtil; -public class ValidateMethodBindingDstu2 extends OperationMethodBinding { +public class ValidateMethodBindingDstu2Plus extends OperationMethodBinding { - public ValidateMethodBindingDstu2(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, + public ValidateMethodBindingDstu2Plus(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, Validate theAnnotation) { super(theReturnResourceType, theReturnTypeFromRp, theMethod, theContext, theProvider, true, Constants.EXTOP_VALIDATE, theAnnotation.type(), new OperationParam[0], BundleTypeEnum.COLLECTION); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu3.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu3.java deleted file mode 100644 index fc76589cacb..00000000000 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu3.java +++ /dev/null @@ -1,84 +0,0 @@ -package ca.uhn.fhir.rest.method; - -/* - * #%L - * HAPI FHIR - Core Library - * %% - * Copyright (C) 2014 - 2016 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import org.hl7.fhir.instance.model.api.IBaseParameters; -import org.hl7.fhir.instance.model.api.IBaseResource; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.valueset.BundleTypeEnum; -import ca.uhn.fhir.rest.annotation.OperationParam; -import ca.uhn.fhir.rest.annotation.Validate; -import ca.uhn.fhir.rest.client.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.ResourceParameter; -import ca.uhn.fhir.rest.server.Constants; -import ca.uhn.fhir.rest.server.EncodingEnum; -import ca.uhn.fhir.util.ParametersUtil; - -public class ValidateMethodBindingDstu3 extends OperationMethodBinding { - - public ValidateMethodBindingDstu3(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, - Validate theAnnotation) { - super(theReturnResourceType, theReturnTypeFromRp, theMethod, theContext, theProvider, true, Constants.EXTOP_VALIDATE, theAnnotation.type(), new OperationParam[0], BundleTypeEnum.COLLECTION); - - List newParams = new ArrayList(); - int idx = 0; - for (IParameter next : getParameters()) { - if (next instanceof ResourceParameter) { - if (IBaseResource.class.isAssignableFrom(((ResourceParameter) next).getResourceType())) { - Class parameterType = theMethod.getParameterTypes()[idx]; - if (String.class.equals(parameterType) || EncodingEnum.class.equals(parameterType)) { - newParams.add(next); - } else { - OperationParameter parameter = new OperationParameter(theContext, Constants.EXTOP_VALIDATE, Constants.EXTOP_VALIDATE_RESOURCE, 0, 1); - parameter.initializeTypes(theMethod, null, null, parameterType); - newParams.add(parameter); - } - } else { - newParams.add(next); - } - } else { - newParams.add(next); - } - idx++; - } - setParameters(newParams); - - } - - - public static BaseHttpClientInvocation createValidateInvocation(FhirContext theContext, IBaseResource theResource) { - IBaseParameters parameters = (IBaseParameters) theContext.getResourceDefinition("Parameters").newInstance(); - ParametersUtil.addParameterToParameters(theContext, parameters, theResource, "resource"); - - String resourceName = theContext.getResourceDefinition(theResource).getName(); - String resourceId = theResource.getIdElement().getIdPart(); - - BaseHttpClientInvocation retVal = createOperationInvocation(theContext, resourceName, resourceId, Constants.EXTOP_VALIDATE, parameters, false); - return retVal; - } - - -} diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu3Test.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu3Test.java index d92eae7e6a9..504f4425fb8 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu3Test.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu3Test.java @@ -65,6 +65,7 @@ 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.api.SummaryEnum; +import ca.uhn.fhir.rest.client.BaseClient; import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.client.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.api.Header; @@ -94,6 +95,7 @@ public class GenericJaxRsClientDstu3Test { ourCtx.setRestfulClientFactory(clientFactory); ourResponseCount = 0; + System.setProperty("hapi.client.keepresponses", "true"); } private String getPatientFeedWithOneResult() { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaPlainProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaPlainProvider.java deleted file mode 100644 index 3df224f2bc7..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaPlainProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -package ca.uhn.fhir.jpa.provider; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2016 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import org.springframework.beans.factory.annotation.Required; - -import ca.uhn.fhir.jpa.dao.IFhirSystemDao; - -public class BaseJpaPlainProvider extends BaseJpaProvider { - - private IFhirSystemDao myDao; - - public BaseJpaPlainProvider() { - // nothing - } - - @Required - public void setDao(IFhirSystemDao theDao) { - myDao = theDao; - } - - public IFhirSystemDao getDao() { - return myDao; - } - -} diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/audit/IResourceAuditor.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/IResourceAuditor.java similarity index 100% rename from hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/audit/IResourceAuditor.java rename to hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/IResourceAuditor.java 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 91a1413ba4c..fcd36e88b55 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 @@ -127,6 +127,8 @@ public class GenericClientDstu2Test { ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs()); myResponseCount = 0; + + System.setProperty(BaseClient.HAPI_CLIENT_KEEPRESPONSES, "true"); } private String extractBody(ArgumentCaptor capt, int count) throws IOException { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu3Test.java index af55c39d2eb..47df4e697f9 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu3Test.java @@ -61,6 +61,8 @@ import ca.uhn.fhir.parser.CustomTypeDstu3Test.MyCustomPatient; 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.interceptor.CookieInterceptor; +import ca.uhn.fhir.rest.client.interceptor.UserInfoInterceptor; import ca.uhn.fhir.rest.param.ParamPrefixEnum; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.util.TestUtil; @@ -81,6 +83,9 @@ public class GenericClientDstu3Test { ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs()); myAnswerCount = 0; + + System.setProperty(BaseClient.HAPI_CLIENT_KEEPRESPONSES, "true"); + } private String expectedUserAgent() { @@ -279,7 +284,61 @@ public class GenericClientDstu3Test { assertEquals(myAnswerCount, capt.getAllValues().size()); assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(0).getURI().toASCIIString()); } + @Test + public void testUserInfoInterceptor() throws Exception { + final String respString = CustomTypeDstu3Test.createBundle(CustomTypeDstu3Test.createResource(false)); + ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class); + when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); + when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); + when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); + when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer() { + @Override + public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable { + return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8")); + } + }); + IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir"); + client.registerInterceptor(new UserInfoInterceptor("user_id", "user_name", "app-name")); + + //@formatter:off + Bundle resp = client + .history() + .onType(Patient.class) + .andReturnBundle(Bundle.class) + .execute(); + //@formatter:on + + } + + @Test + public void testCookieInterceptor() throws Exception { + final String respString = CustomTypeDstu3Test.createBundle(CustomTypeDstu3Test.createResource(false)); + ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class); + when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); + when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); + when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); + when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer() { + @Override + public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable { + return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8")); + } + }); + + IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir"); + client.registerInterceptor(new CookieInterceptor("foo=bar")); + + //@formatter:off + Bundle resp = client + .history() + .onType(Patient.class) + .andReturnBundle(Bundle.class) + .execute(); + //@formatter:on + + assertEquals("foo=bar", capt.getAllValues().get(0).getFirstHeader("Cookie").getValue()); + } + @Test public void testExplicitCustomTypeHistoryType() throws Exception { final String respString = CustomTypeDstu3Test.createBundle(CustomTypeDstu3Test.createResource(false)); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java index 857ecf5ee8b..ba706f6dcc1 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.any; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; @@ -8,6 +9,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import java.util.ArrayList; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; @@ -25,6 +27,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.dstu3.model.Patient; +import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -50,7 +53,7 @@ public class InterceptorDstu3Test { private static final FhirContext ourCtx = FhirContext.forDstu3(); private static int ourPort; private static Server ourServer; - private static RestfulServer servlet; + private static RestfulServer ourServlet; private IServerInterceptor myInterceptor1; private IServerInterceptor myInterceptor2; @@ -58,7 +61,7 @@ public class InterceptorDstu3Test { public void before() { myInterceptor1 = mock(IServerInterceptor.class); myInterceptor2 = mock(IServerInterceptor.class); - servlet.setInterceptors(myInterceptor1, myInterceptor2); + ourServlet.setInterceptors(myInterceptor1, myInterceptor2); } @@ -121,6 +124,13 @@ public class InterceptorDstu3Test { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } + + @After + public void after() { + for (IServerInterceptor next : new ArrayList(ourServlet.getInterceptors())) { + ourServlet.unregisterInterceptor(next); + } + } @BeforeClass public static void beforeClass() throws Exception { @@ -130,9 +140,9 @@ public class InterceptorDstu3Test { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - servlet = new RestfulServer(ourCtx); - servlet.setResourceProviders(patientProvider); - ServletHolder servletHolder = new ServletHolder(servlet); + ourServlet = new RestfulServer(ourCtx); + ourServlet.setResourceProviders(patientProvider); + ServletHolder servletHolder = new ServletHolder(ourServlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu3Test.java index 0df8e26b752..f9e57d5d00a 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu3Test.java @@ -30,8 +30,6 @@ import org.junit.BeforeClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.base.resource.BaseOperationOutcome; import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Validate; import ca.uhn.fhir.rest.api.MethodOutcome;