Almost have versions tests passing

This commit is contained in:
James Agnew 2014-10-17 14:51:45 -04:00
parent bb0b39627d
commit 47edfb7b01
9 changed files with 160 additions and 74 deletions

View File

@ -34,12 +34,18 @@
builds a client for the Health Intersections reference
server.
</p>
<p>
Note that as of HAPI 0.8, you need to add a dependency to the
plugin containing the version of FHIR you are building custom
structures against.
</p>
<source><![CDATA[<plugins>
<plugin>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-tinder-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<version>${project.version}</version>
<executions>
<execution>
<goals><goal>generate-structures</goal></goals>
@ -50,6 +56,13 @@
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>]]></source>

View File

@ -8,11 +8,27 @@
<body>
<section name="Upgrading to HAPI FHIR 0.5">
<section name="Upgrading to HAPI FHIR 0.8 - DRAFT">
<macro name="toc">
</macro>
<subsection name="Tinder Plugin">
<p>
If you are using the "Tinder" Maven plugin to generate structure code,
you will need to add a structure dependency to the plugin configuration
itself in your project pom.xml. See the
<a href="./doc_tinder.html">Tinder Page</a> for an example of
how to do this.
</p>
</subsection>
</section>
<section name="Upgrading to HAPI FHIR 0.5">
<p>
As the HAPI FHIR API begins to mature, a number of minor changes to the way the library works
have been introduced. Mostly these changes are made in order to make a consistent API across functions.

View File

@ -152,6 +152,13 @@
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu</artifactId>
<version>0.7-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@ -2,6 +2,5 @@
<wb-module deploy-name="hapi-fhir-structures-dstu">
<wb-resource deploy-path="/" source-path="/target/generated-sources/tinder"/>
<wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/test/resources"/>
</wb-module>
</project-modules>

View File

@ -96,8 +96,12 @@
<version>${ebay_cors_filter_version}</version>
<scope>test</scope>
</dependency>
<!-- Only required for Schematron Validator Support -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>${thymeleaf-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.phloc</groupId>
<artifactId>phloc-schematron</artifactId>

View File

@ -19,9 +19,11 @@ import org.junit.BeforeClass;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.BaseResource;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu.resource.Binary;
import ca.uhn.fhir.model.dstu.resource.Organization;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam;
@ -61,6 +63,28 @@ public class ReadTest {
}
@Test
public void testReadForProviderWithAbstractReturnType() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Organization/1");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
IdentifierDt dt = ourCtx.newXmlParser().parseResource(Organization.class,responseContent).getIdentifierFirstRep();
assertEquals("1", dt.getSystem().getValueAsString());
assertEquals(null, dt.getValue().getValueAsString());
Header cl = status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION_LC);
assertNotNull(cl);
assertEquals("http://localhost:" + ourPort + "/Organization/1/_history/1", cl.getValue());
}
}
@Test
public void testBinaryRead() throws Exception {
{
@ -124,7 +148,7 @@ public class ReadTest {
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
ourCtx = servlet.getFhirContext();
servlet.setResourceProviders(patientProvider, new DummyBinaryProvider());
servlet.setResourceProviders(patientProvider, new DummyBinaryProvider(), new OrganizationProviderWithAbstractReturnType());
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
ourServer.setHandler(proxyHandler);
@ -158,6 +182,27 @@ public class ReadTest {
}
/**
* Created by dsotnikov on 2/25/2014.
*/
public static class OrganizationProviderWithAbstractReturnType implements IResourceProvider {
@Read(version = true)
public BaseResource findPatient(@IdParam IdDt theId) {
Organization org = new Organization();
org.addIdentifier(theId.getIdPart(), theId.getVersionIdPart());
org.setId("Organization/1/_history/1");
return org;
}
@Override
public Class<? extends IResource> getResourceType() {
return Organization.class;
}
}
/**
* Created by dsotnikov on 2/25/2014.
*/

View File

@ -21,24 +21,11 @@ import ca.uhn.fhir.rest.param.StringParam;
public class ServerInvalidDefinitionTest {
@Test
public void testNonInstantiableTypeForResourceProvider() {
RestfulServer srv = new RestfulServer();
srv.setPlainProviders(new NonInstantiableTypeForPlainProvider());
try {
srv.init();
fail();
} catch (ServletException e) {
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
}
}
@Test
public void testPrivateResourceProvider() {
RestfulServer srv = new RestfulServer();
srv.setResourceProviders(new PrivateResourceProvider());
try {
srv.init();
fail();
@ -52,7 +39,7 @@ public class ServerInvalidDefinitionTest {
public void testInvalidSpecialNameResourceProvider() {
RestfulServer srv = new RestfulServer();
srv.setResourceProviders(new InvalidSpecialParameterNameResourceProvider());
try {
srv.init();
fail();
@ -61,12 +48,12 @@ public class ServerInvalidDefinitionTest {
assertThat(e.getCause().toString(), StringContains.containsString("_pretty"));
}
}
@Test
public void testReadMethodWithSearchParameters() {
RestfulServer srv = new RestfulServer();
srv.setResourceProviders(new ReadMethodWithSearchParamProvider());
try {
srv.init();
fail();
@ -79,7 +66,7 @@ public class ServerInvalidDefinitionTest {
public void testSearchWithId() {
RestfulServer srv = new RestfulServer();
srv.setResourceProviders(new SearchWithIdParamProvider());
try {
srv.init();
fail();
@ -98,65 +85,36 @@ public class ServerInvalidDefinitionTest {
srv.setResourceProviders(new InstantiableTypeForResourceProvider());
srv.init();
}
private static class PrivateResourceProvider implements IResourceProvider
{
private static class PrivateResourceProvider implements IResourceProvider {
@Override
public Class<? extends IResource> getResourceType() {
return Patient.class;
}
@Read
public Patient read(@IdParam IdDt theId) {
return null;
}
}
public static class ReadMethodWithSearchParamProvider implements IResourceProvider
{
public static class ReadMethodWithSearchParamProvider implements IResourceProvider {
@Override
public Class<? extends IResource> getResourceType() {
return Patient.class;
}
@Read
public Patient read(@IdParam IdDt theId, @RequiredParam(name="aaa") StringParam theParam) {
return null;
}
}
public static class SearchWithIdParamProvider implements IResourceProvider
{
@Override
public Class<? extends IResource> getResourceType() {
return Patient.class;
}
@Search
public List<Patient> read(@IdParam IdDt theId, @RequiredParam(name="aaa") StringParam theParam) {
return null;
}
}
public static class NonInstantiableTypeForPlainProvider
{
@Read
public BaseResource read(@IdParam IdDt theId) {
public Patient read(@IdParam IdDt theId, @RequiredParam(name = "aaa") StringParam theParam) {
return null;
}
}
public static class InvalidSpecialParameterNameResourceProvider implements IResourceProvider
{
public static class SearchWithIdParamProvider implements IResourceProvider {
@Override
public Class<? extends IResource> getResourceType() {
@ -164,26 +122,38 @@ public class ServerInvalidDefinitionTest {
}
@Search
public List<Patient> search(@RequiredParam(name="_pretty") StringParam theParam) {
public List<Patient> read(@IdParam IdDt theId, @RequiredParam(name = "aaa") StringParam theParam) {
return null;
}
}
public static class InstantiableTypeForResourceProvider implements IResourceProvider
{
public static class InvalidSpecialParameterNameResourceProvider implements IResourceProvider {
@Override
public Class<? extends IResource> getResourceType() {
return Patient.class;
}
@Search
public List<Patient> search(@RequiredParam(name = "_pretty") StringParam theParam) {
return null;
}
}
public static class InstantiableTypeForResourceProvider implements IResourceProvider {
@Override
public Class<Patient> getResourceType() {
return Patient.class;
}
@Read
public Patient read(@IdParam IdDt theId) {
return null;
}
}
}

View File

@ -0,0 +1,26 @@
package ca.uhn.fhir.model.dstu;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.model.api.IFhirVersion;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
public class FhirDstu1 implements IFhirVersion {
@Override
public Object createServerConformanceProvider(RestfulServer theServer) {
throw new UnsupportedOperationException();
}
@Override
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
throw new UnsupportedOperationException();
}
@Override
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition) {
throw new UnsupportedOperationException();
}
}

View File

@ -98,7 +98,13 @@
<!-- <execution> <id>client</id> <goals> <goal>generate-client</goal> </goals> <configuration> <clientClassName>ca.uhn.hitest.HiTest</clientClassName> <serverBaseHref>http://fhir.healthintersections.com.au/open</serverBaseHref>
<generateSearchForAllParams>true</generateSearchForAllParams> </configuration> </execution> -->
</executions>
<dependencies>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu</artifactId>
<version>0.7-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>