add test for conformance
This commit is contained in:
parent
9f7a104315
commit
d2cb35b6a1
|
@ -1,33 +1,40 @@
|
|||
package ca.uhn.fhir.jaxrs.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Local;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.OPTIONS;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Conformance;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||
import ca.uhn.fhir.rest.method.BaseMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.ParseAction;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.IRestfulResponse;
|
||||
import ca.uhn.fhir.rest.server.ResourceBinding;
|
||||
import ca.uhn.fhir.rest.server.RestulfulServerConfiguration;
|
||||
import ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider;
|
||||
|
@ -37,8 +44,11 @@ import ca.uhn.fhir.util.ReflectionUtil;
|
|||
* Conformance Rest Service
|
||||
* @author Peter Van Houte
|
||||
*/
|
||||
@Local
|
||||
@Path("")
|
||||
@Stateless
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public abstract class AbstractJaxRsConformanceProvider extends AbstractJaxRsProvider implements IJaxRsConformanceProvider {
|
||||
public abstract class AbstractJaxRsConformanceProvider extends AbstractJaxRsProvider {
|
||||
|
||||
public static final String PATH = "/";
|
||||
private static final org.slf4j.Logger ourLog = LoggerFactory.getLogger(AbstractJaxRsConformanceProvider.class);
|
||||
|
@ -49,15 +59,19 @@ public abstract class AbstractJaxRsConformanceProvider extends AbstractJaxRsProv
|
|||
|
||||
private Conformance myConformance;
|
||||
|
||||
protected AbstractJaxRsConformanceProvider(String implementationDescription, String serverName, String serverVersion) {
|
||||
public AbstractJaxRsConformanceProvider(String implementationDescription, String serverName, String serverVersion) {
|
||||
serverConfiguration.setFhirContext(getFhirContext());
|
||||
serverConfiguration.setImplementationDescription(implementationDescription);
|
||||
serverConfiguration.setServerName(serverName);
|
||||
serverConfiguration.setServerVersion(serverVersion);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
protected void setUpPostConstruct()
|
||||
throws Exception {
|
||||
for (Entry<Class<? extends IResourceProvider>, IResourceProvider> provider : getProviders().entrySet()) {
|
||||
addProvider(provider.getValue(), provider.getKey());
|
||||
}
|
||||
List<BaseMethodBinding<?>> serverBindings = new ArrayList<BaseMethodBinding<?>>();
|
||||
for (ResourceBinding baseMethodBinding : myResourceNameToBinding.values()) {
|
||||
serverBindings.addAll(baseMethodBinding.getMethodBindings());
|
||||
|
@ -72,20 +86,27 @@ public abstract class AbstractJaxRsConformanceProvider extends AbstractJaxRsProv
|
|||
myConformance = serverConformanceProvider.getServerConformance(null);
|
||||
}
|
||||
|
||||
@GET
|
||||
protected abstract ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider> getProviders() throws Exception;
|
||||
|
||||
@OPTIONS
|
||||
@Path("/metadata")
|
||||
public Response conformance(String string) {
|
||||
String conformanceString = getParser(createRequestDetails(null, RequestTypeEnum.OPTIONS, RestOperationTypeEnum.METADATA)).encodeResourceToString(myConformance);
|
||||
ResponseBuilder entity = Response.status(Constants.STATUS_HTTP_200_OK).entity(conformanceString);
|
||||
entity.header("Access-Control-Allow-Origin", "*");
|
||||
return entity.build();
|
||||
public Response conformanceUsingOptions() throws IOException {
|
||||
return conformance();
|
||||
}
|
||||
|
||||
protected int findResourceMethods(Object theProvider, Class<?> clazz) throws ConfigurationException {
|
||||
@GET
|
||||
@Path("/metadata")
|
||||
public Response conformance() throws IOException {
|
||||
JaxRsRequest request = createRequestDetails(null, RequestTypeEnum.OPTIONS, RestOperationTypeEnum.METADATA);
|
||||
IRestfulResponse response = request.getResponse();
|
||||
response.addHeader(Constants.HEADER_CORS_ALLOW_ORIGIN, "*");
|
||||
return (Response) response.returnResponse(ParseAction.create(myConformance), Constants.STATUS_HTTP_200_OK, true, null, getResourceType().getSimpleName());
|
||||
}
|
||||
|
||||
public int addProvider(Object theProvider, Class<?> theProviderInterface) throws ConfigurationException {
|
||||
int count = 0;
|
||||
|
||||
for (Method m : ReflectionUtil.getDeclaredMethods(clazz)) {
|
||||
for (Method m : ReflectionUtil.getDeclaredMethods(theProviderInterface)) {
|
||||
BaseMethodBinding<?> foundMethodBinding = BaseMethodBinding.bindMethod(m, getFhirContext(), theProvider);
|
||||
if (foundMethodBinding == null) {
|
||||
continue;
|
||||
|
@ -144,9 +165,8 @@ public abstract class AbstractJaxRsConformanceProvider extends AbstractJaxRsProv
|
|||
return count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends IBaseResource> getResourceType() {
|
||||
public Class<Conformance> getResourceType() {
|
||||
return Conformance.class;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package ca.uhn.fhir.jaxrs.server;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
@ -16,6 +18,7 @@ import ca.uhn.fhir.rest.server.AddProfileTagEnum;
|
|||
import ca.uhn.fhir.rest.server.ETagSupportEnum;
|
||||
import ca.uhn.fhir.rest.server.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.IRestfulServerDefaults;
|
||||
import ca.uhn.fhir.rest.server.IServerAddressStrategy;
|
||||
import ca.uhn.fhir.rest.server.RestfulServerUtils;
|
||||
|
@ -25,7 +28,7 @@ import ca.uhn.fhir.rest.server.RestfulServerUtils;
|
|||
* @author Peter Van Houte
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
||||
public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults, IResourceProvider {
|
||||
|
||||
public static FhirContext CTX = FhirContext.forDstu2();
|
||||
|
||||
|
@ -43,10 +46,10 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
|||
* param and query methods
|
||||
*/
|
||||
public HashMap<String, String[]> getQueryMap() {
|
||||
MultivaluedMap<String, String> queryParameters = getInfo().getQueryParameters();
|
||||
MultivaluedMap<String, String> queryParameters = getUriInfo().getQueryParameters();
|
||||
HashMap<String, String[]> params = new HashMap<String, String[]>();
|
||||
for (String key : queryParameters.keySet()) {
|
||||
params.put(key, queryParameters.get(key).toArray(new String[] {}));
|
||||
for (Entry<String, List<String>> paramEntry : queryParameters.entrySet()) {
|
||||
params.put(paramEntry.getKey(), paramEntry.getValue().toArray(new String[paramEntry.getValue().size()]));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
@ -58,7 +61,7 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
|||
}
|
||||
|
||||
public String getBaseUri() {
|
||||
return getInfo().getBaseUri().toASCIIString();
|
||||
return getUriInfo().getBaseUri().toASCIIString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,19 +76,35 @@ public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the info
|
||||
* @return the info
|
||||
* Get the uriInfo
|
||||
* @return the uri info
|
||||
*/
|
||||
public UriInfo getInfo() {
|
||||
return theUriInfo;
|
||||
public UriInfo getUriInfo() {
|
||||
return this.theUriInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Uri Info
|
||||
* @param uriInfo the uri info
|
||||
*/
|
||||
public void setUriInfo(UriInfo uriInfo) {
|
||||
this.theUriInfo = uriInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the headers
|
||||
* @return the headers
|
||||
*/
|
||||
public HttpHeaders getHeaders() {
|
||||
return theHeaders;
|
||||
return this.theHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the headers
|
||||
* @param headers the headers to set
|
||||
*/
|
||||
public void setHeaders(HttpHeaders headers) {
|
||||
this.theHeaders = headers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,6 +31,7 @@ import ca.uhn.fhir.rest.method.RequestDetails;
|
|||
import ca.uhn.fhir.rest.server.BundleInclusionRule;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.IPagingProvider;
|
||||
import ca.uhn.fhir.rest.server.IRestfulServer;
|
||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
|
@ -43,7 +44,7 @@ import ca.uhn.fhir.util.UrlUtil;
|
|||
*/
|
||||
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
|
||||
@Consumes({MediaType.APPLICATION_FORM_URLENCODED,MediaType.APPLICATION_JSON, "application/json+fhir", "application/xml+fhir"})
|
||||
public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends AbstractJaxRsProvider implements IJaxRsResourceProvider<R> {
|
||||
public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends AbstractJaxRsProvider implements IRestfulServer<JaxRsRequest> {
|
||||
|
||||
private final MethodBindings bindings;
|
||||
|
||||
|
@ -56,9 +57,9 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getBaseUri() {
|
||||
public String getBaseUri() {
|
||||
try {
|
||||
return new URL(getInfo().getBaseUri().toURL(), getResourceType().getSimpleName()).toExternalForm();
|
||||
return new URL(getUriInfo().getBaseUri().toURL(), getResourceType().getSimpleName()).toExternalForm();
|
||||
} catch(Exception e) {
|
||||
// cannot happen
|
||||
return null;
|
||||
|
@ -66,7 +67,6 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
}
|
||||
|
||||
@POST
|
||||
@Override
|
||||
@Interceptors(JaxRsExceptionInterceptor.class)
|
||||
public Response create(final String resourceString)
|
||||
throws Exception {
|
||||
|
@ -76,20 +76,17 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
@POST
|
||||
@Interceptors(JaxRsExceptionInterceptor.class)
|
||||
@Path("/_search")
|
||||
@Override
|
||||
public Response searchWithPost() throws Exception {
|
||||
return executeMethod(null, RequestTypeEnum.POST, RestOperationTypeEnum.SEARCH_TYPE, null);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Override
|
||||
@Interceptors(JaxRsExceptionInterceptor.class)
|
||||
public Response search() throws Exception {
|
||||
return executeMethod(null, RequestTypeEnum.GET, RestOperationTypeEnum.SEARCH_TYPE, null);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Override
|
||||
@Path("/{id}")
|
||||
@Interceptors(JaxRsExceptionInterceptor.class)
|
||||
public Response update(@PathParam("id") final String id, final String resourceString)
|
||||
|
@ -98,7 +95,6 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
}
|
||||
|
||||
@DELETE
|
||||
@Override
|
||||
@Path("/{id}")
|
||||
@Interceptors(JaxRsExceptionInterceptor.class)
|
||||
public Response delete(@PathParam("id") final String id) throws Exception {
|
||||
|
@ -107,7 +103,6 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
|
||||
|
||||
@GET
|
||||
@Override
|
||||
@Path("/{id}")
|
||||
@Interceptors(JaxRsExceptionInterceptor.class)
|
||||
public Response find(@PathParam("id") final String id) throws Exception {
|
||||
|
@ -120,7 +115,6 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
}
|
||||
|
||||
@GET
|
||||
@Override
|
||||
@Path("/{id}/_history/{version}")
|
||||
@Interceptors(JaxRsExceptionInterceptor.class)
|
||||
public Response findHistory(@PathParam("id") final String id, @PathParam("version") final String versionString)
|
||||
|
@ -128,21 +122,20 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
BaseMethodBinding<?> method = getBindings().getBinding(RestOperationTypeEnum.VREAD);
|
||||
final RequestDetails theRequest = createRequestDetails(null, RequestTypeEnum.GET, RestOperationTypeEnum.VREAD);
|
||||
if (id == null) {
|
||||
throw new InvalidRequestException("Don't know how to handle request path: " + getInfo().getRequestUri().toASCIIString());
|
||||
throw new InvalidRequestException("Don't know how to handle request path: " + getUriInfo().getRequestUri().toASCIIString());
|
||||
}
|
||||
theRequest.setId(new IdDt(getBaseUri(), id, UrlUtil.unescape(versionString)));
|
||||
return (Response) method.invokeServer(this, theRequest);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Override
|
||||
@GET
|
||||
@Path("/{id}/{compartment}")
|
||||
@Interceptors(JaxRsExceptionInterceptor.class)
|
||||
public Response findCompartment(@PathParam("id") final String id, @PathParam("compartment") final String compartment) throws BaseServerResponseException, IOException {
|
||||
BaseMethodBinding<?> method = getBindings().getBinding(RestOperationTypeEnum.SEARCH_TYPE, compartment);
|
||||
final RequestDetails theRequest = createRequestDetails(null, RequestTypeEnum.GET, RestOperationTypeEnum.VREAD);
|
||||
if (id == null) {
|
||||
throw new InvalidRequestException("Don't know how to handle request path: " + getInfo().getRequestUri().toASCIIString());
|
||||
throw new InvalidRequestException("Don't know how to handle request path: " + getUriInfo().getRequestUri().toASCIIString());
|
||||
}
|
||||
theRequest.setCompartmentName(compartment);
|
||||
theRequest.setId(new IdDt(getBaseUri(), id));
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package ca.uhn.fhir.jaxrs.server;
|
||||
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.IRestfulServerDefaults;
|
||||
|
||||
public interface IJaxRsConformanceProvider extends IResourceProvider, IRestfulServerDefaults {
|
||||
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package ca.uhn.fhir.jaxrs.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.IRestfulServer;
|
||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
||||
|
||||
public interface IJaxRsResourceProvider<T> extends IRestfulServer<JaxRsRequest>, IResourceProvider {
|
||||
|
||||
Response search()
|
||||
throws Exception;
|
||||
|
||||
Response create(String resourceString)
|
||||
throws Exception;
|
||||
|
||||
Response searchWithPost()
|
||||
throws Exception;
|
||||
|
||||
Response find(String id) throws Exception;
|
||||
|
||||
Response update(String id, String resourceString)
|
||||
throws Exception;
|
||||
|
||||
Response delete(String id)
|
||||
throws Exception;
|
||||
|
||||
Response findHistory(String id, String version) throws BaseServerResponseException, IOException;
|
||||
|
||||
Response findCompartment(String id, String compartment) throws BaseServerResponseException, IOException;
|
||||
|
||||
|
||||
}
|
|
@ -13,6 +13,7 @@ import javax.ws.rs.core.MediaType;
|
|||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
|
@ -43,7 +44,8 @@ public class JaxRsResponse extends RestfulResponse<JaxRsRequest> {
|
|||
@Override
|
||||
public Response sendWriterResponse(int status, String contentType, String charset, Writer writer) {
|
||||
Object entity = writer instanceof StringWriter ? writer.toString() : writer;
|
||||
return buildResponse(status)/*.header(HttpHeaders.CONTENT_TYPE, charset)*/.header(Constants.HEADER_CONTENT_TYPE, contentType).entity(entity).build();
|
||||
String charContentType = contentType+";charset="+StringUtils.defaultIfBlank(charset, Constants.CHARSET_NAME_UTF8);
|
||||
return buildResponse(status).header(Constants.HEADER_CONTENT_TYPE, charContentType).entity(entity).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
package ca.uhn.fhir.jaxrs.server;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.MultivaluedHashMap;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.glassfish.jersey.internal.MapPropertiesDelegate;
|
||||
import org.glassfish.jersey.server.ContainerRequest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.jaxrs.server.example.TestJaxRsPatientRestProvider;
|
||||
import ca.uhn.fhir.jaxrs.server.example.TestDummyPatientProvider;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
|
||||
public class AbstractJaxRsConformanceProviderTest {
|
||||
|
||||
private static final String BASEURI = "http://basiuri";
|
||||
private static final String REQUESTURI = BASEURI + "/metadata";
|
||||
AbstractJaxRsConformanceProvider provider;
|
||||
private ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider> providers;
|
||||
private ContainerRequest headers;
|
||||
private MultivaluedHashMap<String, String> queryParameters;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// headers
|
||||
headers = new ContainerRequest(new URI(BASEURI), new URI(REQUESTURI), HttpMethod.GET, null,
|
||||
new MapPropertiesDelegate());
|
||||
// uri info
|
||||
queryParameters = new MultivaluedHashMap<String, String>();
|
||||
|
||||
|
||||
providers = new ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider>();
|
||||
provider = createConformanceProvider(providers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConformance() throws Exception {
|
||||
providers.put(AbstractJaxRsConformanceProvider.class, provider);
|
||||
providers.put(TestDummyPatientProvider.class, new TestDummyPatientProvider());
|
||||
Response response = createConformanceProvider(providers).conformance();
|
||||
System.out.println(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConformanceWithMethods() throws Exception {
|
||||
providers.put(AbstractJaxRsConformanceProvider.class, provider);
|
||||
providers.put(TestJaxRsPatientRestProvider.class, new TestJaxRsPatientRestProvider());
|
||||
Response response = createConformanceProvider(providers).conformance();
|
||||
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
|
||||
assertTrue(response.getEntity().toString().contains("\"type\":\"Patient\""));
|
||||
assertTrue(response.getEntity().toString().contains("\"$last"));
|
||||
System.out.println(response);
|
||||
System.out.println(response.getEntity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConformanceInXml() throws Exception {
|
||||
queryParameters.put(Constants.PARAM_FORMAT, Arrays.asList(Constants.CT_XML));
|
||||
providers.put(AbstractJaxRsConformanceProvider.class, provider);
|
||||
providers.put(TestJaxRsPatientRestProvider.class, new TestJaxRsPatientRestProvider());
|
||||
Response response = createConformanceProvider(providers).conformance();
|
||||
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
|
||||
System.out.println(response.getEntity());
|
||||
assertTrue(response.getEntity().toString().contains(" <type value=\"Patient\"/>"));
|
||||
assertTrue(response.getEntity().toString().contains("\"$last"));
|
||||
System.out.println(response.getEntity());
|
||||
}
|
||||
|
||||
private AbstractJaxRsConformanceProvider createConformanceProvider(final ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider> providers)
|
||||
throws Exception {
|
||||
AbstractJaxRsConformanceProvider result = new AbstractJaxRsConformanceProvider(null, null, null) {
|
||||
@Override
|
||||
protected ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider> getProviders() {
|
||||
return providers;
|
||||
}
|
||||
};
|
||||
// mocks
|
||||
UriInfo uriInfo = mock(UriInfo.class);
|
||||
when(uriInfo.getQueryParameters()).thenReturn(queryParameters);
|
||||
when(uriInfo.getBaseUri()).thenReturn(new URI(BASEURI));
|
||||
result.setUriInfo(uriInfo);
|
||||
result.setHeaders(headers);
|
||||
result.setUpPostConstruct();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package ca.uhn.fhir.jaxrs.server;
|
||||
package ca.uhn.fhir.jaxrs.server.example;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
@ -16,8 +16,6 @@ import org.junit.Ignore;
|
|||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.jaxrs.server.example.JaxRsPatientRestProvider;
|
||||
import ca.uhn.fhir.jaxrs.server.example.RandomServerPortProvider;
|
||||
import ca.uhn.fhir.model.api.BundleEntry;
|
||||
import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||
|
@ -56,7 +54,7 @@ public class JaxRsPatientProviderTest {
|
|||
jettyServer.setHandler(context);
|
||||
ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*");
|
||||
jerseyServlet.setInitOrder(0);
|
||||
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames", JaxRsPatientRestProvider.class.getCanonicalName());
|
||||
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames", TestJaxRsPatientRestProvider.class.getCanonicalName() + "," +TestJaxRsConformanceRestProvider.class.getCanonicalName());
|
||||
jettyServer.start();
|
||||
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
|
@ -75,7 +73,7 @@ public class JaxRsPatientProviderTest {
|
|||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Search/Query - Type */
|
||||
@Test
|
||||
public void findUsingGenericClientBySearch() {
|
||||
|
@ -236,7 +234,6 @@ public class JaxRsPatientProviderTest {
|
|||
|
||||
/** Conformance - Server */
|
||||
@Test
|
||||
@Ignore
|
||||
public void testConformance() {
|
||||
final Conformance conf = client.fetchConformance().ofType(Conformance.class).execute();
|
||||
System.out.println(conf.getRest().get(0).getResource().get(0).getType());
|
|
@ -0,0 +1,35 @@
|
|||
package ca.uhn.fhir.jaxrs.server.example;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import ca.uhn.fhir.jaxrs.server.AbstractJaxRsConformanceProvider;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
|
||||
/**
|
||||
* Fhir Physician Rest Service
|
||||
* @author axmpm
|
||||
*
|
||||
*/
|
||||
@Path(TestJaxRsConformanceRestProvider.PATH)
|
||||
@Stateless
|
||||
@Produces({MediaType.APPLICATION_JSON, Constants.CT_FHIR_JSON, Constants.CT_FHIR_XML})
|
||||
public class TestJaxRsConformanceRestProvider extends AbstractJaxRsConformanceProvider {
|
||||
|
||||
public TestJaxRsConformanceRestProvider() {
|
||||
super("", "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider> getProviders() throws Exception {
|
||||
ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider> map = new ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider>();
|
||||
map.put(TestJaxRsPatientRestProvider.class, new TestJaxRsPatientRestProvider());
|
||||
map.put(TestJaxRsConformanceRestProvider.class, new TestJaxRsConformanceRestProvider());
|
||||
return map;
|
||||
}
|
||||
}
|
|
@ -53,18 +53,18 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
|||
* @author axmpm
|
||||
*
|
||||
*/
|
||||
@Path(JaxRsPatientRestProvider.PATH)
|
||||
@Path(TestJaxRsPatientRestProvider.PATH)
|
||||
@Stateless
|
||||
@Produces({MediaType.APPLICATION_JSON, Constants.CT_FHIR_JSON, Constants.CT_FHIR_XML})
|
||||
public class JaxRsPatientRestProvider extends AbstractJaxRsResourceProvider<Patient> /*implements IJaxRsPatientProvider*/ {
|
||||
public class TestJaxRsPatientRestProvider extends AbstractJaxRsResourceProvider<Patient> {
|
||||
|
||||
static final String PATH = "/Patient";
|
||||
|
||||
private static Long counter = 1L;
|
||||
private static final ConcurrentHashMap<String, List<Patient>> patients = new ConcurrentHashMap<String, List<Patient>>();
|
||||
|
||||
public JaxRsPatientRestProvider() throws Exception {
|
||||
super(JaxRsPatientRestProvider.class);
|
||||
public TestJaxRsPatientRestProvider() throws Exception {
|
||||
super(TestJaxRsPatientRestProvider.class);
|
||||
}
|
||||
|
||||
static {
|
|
@ -111,7 +111,7 @@ public class JaxRsRequestTest {
|
|||
|
||||
//mocks
|
||||
provider = spy(TestDummyPatientProvider.class);
|
||||
doReturn(uriInfo).when(provider).getInfo();
|
||||
doReturn(uriInfo).when(provider).getUriInfo();
|
||||
doReturn(BASEURI).when(provider).getBaseUri();
|
||||
doReturn(headers).when(provider).getHeaders();
|
||||
|
||||
|
|
Loading…
Reference in New Issue