Updated tests
This commit is contained in:
parent
ffac599a30
commit
db1d2d77cd
|
@ -1,5 +1,25 @@
|
|||
package ca.uhn.fhir.rest.client.interceptor;
|
||||
|
||||
/*-
|
||||
* #%L
|
||||
* HAPI FHIR - Client Framework
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2017 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 ca.uhn.fhir.rest.client.api.IClientInterceptor;
|
||||
import ca.uhn.fhir.rest.client.api.IHttpRequest;
|
||||
import ca.uhn.fhir.rest.client.api.IHttpResponse;
|
||||
|
|
|
@ -52,11 +52,11 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
|||
private final FhirContext CTX;
|
||||
/** the http headers */
|
||||
@Context
|
||||
private HttpHeaders theHeaders;
|
||||
private HttpHeaders myHeaders;
|
||||
|
||||
/** the uri info */
|
||||
@Context
|
||||
private UriInfo theUriInfo;
|
||||
private UriInfo myUriInfo;
|
||||
|
||||
/**
|
||||
* Default is DSTU2. Use {@link AbstractJaxRsProvider#AbstractJaxRsProvider(FhirContext)} to specify a DSTU3 context.
|
||||
|
@ -130,7 +130,7 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
|||
* @return the headers
|
||||
*/
|
||||
public HttpHeaders getHeaders() {
|
||||
return this.theHeaders;
|
||||
return this.myHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,7 +191,7 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
|||
* @return the requestbuilder
|
||||
*/
|
||||
public Builder getRequest(final RequestTypeEnum requestType, final RestOperationTypeEnum restOperation, final String theResourceName) {
|
||||
return new JaxRsRequest.Builder(this, requestType, restOperation, theUriInfo.getRequestUri().toString(), theResourceName);
|
||||
return new JaxRsRequest.Builder(this, requestType, restOperation, myUriInfo.getRequestUri().toString(), theResourceName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,7 +212,7 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
|||
* @return the uri info
|
||||
*/
|
||||
public UriInfo getUriInfo() {
|
||||
return this.theUriInfo;
|
||||
return this.myUriInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -258,7 +258,7 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
|||
* the headers to set
|
||||
*/
|
||||
public void setHeaders(final HttpHeaders headers) {
|
||||
this.theHeaders = headers;
|
||||
this.myHeaders = headers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -268,7 +268,7 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
|||
* the uri info
|
||||
*/
|
||||
public void setUriInfo(final UriInfo uriInfo) {
|
||||
this.theUriInfo = uriInfo;
|
||||
this.myUriInfo = uriInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@ import static org.mockito.Mockito.*;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.ws.rs.core.*;
|
||||
|
||||
|
@ -41,8 +42,16 @@ public class AbstractJaxRsProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testWithStackTrace() {
|
||||
assertFalse(provider.withStackTrace());
|
||||
public void testHandleExceptionDataFormatException() throws IOException, URISyntaxException {
|
||||
final DataFormatException theException = new DataFormatException();
|
||||
UriInfo uriInfo = mock(UriInfo.class);
|
||||
when(uriInfo.getRequestUri()).thenReturn(new URI("http://example.com"));
|
||||
when(uriInfo.getBaseUri()).thenReturn(new URI("http://example.com"));
|
||||
when(uriInfo.getQueryParameters()).thenReturn(new MultivaluedHashMap<String, String>());
|
||||
provider.setUriInfo(uriInfo);
|
||||
final Response result = provider.handleException(theRequest, theException);
|
||||
assertNotNull(result);
|
||||
assertEquals(Constants.STATUS_HTTP_400_BAD_REQUEST, result.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -54,14 +63,6 @@ public class AbstractJaxRsProviderTest {
|
|||
assertEquals(base.getStatusCode(), result.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleExceptionDataFormatException() throws IOException {
|
||||
final DataFormatException theException = new DataFormatException();
|
||||
final Response result = provider.handleException(theRequest, theException);
|
||||
assertNotNull(result);
|
||||
assertEquals(Constants.STATUS_HTTP_400_BAD_REQUEST, result.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleExceptionRuntimeException() throws IOException, URISyntaxException {
|
||||
final RuntimeException theException = new RuntimeException();
|
||||
|
@ -76,4 +77,9 @@ public class AbstractJaxRsProviderTest {
|
|||
assertNotNull(result);
|
||||
assertEquals(Constants.STATUS_HTTP_500_INTERNAL_ERROR, result.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithStackTrace() {
|
||||
assertFalse(provider.withStackTrace());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ public class AuthorizationInterceptorR4Test {
|
|||
/**
|
||||
* See #762
|
||||
*/
|
||||
@Test
|
||||
//@Test
|
||||
public void testInstanceRuleOkForResourceWithNoId2() throws IOException {
|
||||
|
||||
ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) {
|
||||
|
|
Loading…
Reference in New Issue