Add consolidated test package and clean up tests for cobertura

This commit is contained in:
jamesagnew 2015-06-20 14:23:34 -04:00
parent cadf3eaa95
commit 71fbfe5214
148 changed files with 1279 additions and 896 deletions

View File

@ -1,2 +1,7 @@
language: java
jdk:
- oraclejdk6
install: mvn clean install -Dcobertura.skip=true
script: mvn -P COBERTURA clean cobertura:cobertura

View File

@ -19,7 +19,7 @@ public class ClientExamples {
@SuppressWarnings("unused")
public void createProxy() {
// START SNIPPET: proxy
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
// Set connections to access the network via the HTTP proxy at
// example.com : 8888
@ -36,7 +36,7 @@ public class ClientExamples {
@SuppressWarnings("unused")
public void createTimeouts() {
// START SNIPPET: timeouts
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
// Set how long to try and establish the initial TCP connection (in ms)
ctx.getRestfulClientFactory().setConnectTimeout(20 * 1000);
@ -53,7 +53,7 @@ public class ClientExamples {
public void createSecurity() {
// START SNIPPET: security
// Create a context and get the client factory so it can be configured
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory();
// Create an HTTP basic auth interceptor
@ -74,7 +74,7 @@ public class ClientExamples {
public void createCookie() {
// START SNIPPET: cookie
// Create a context and get the client factory so it can be configured
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory();
// Create a cookie interceptor. This cookie will have the name "mycookie" and
@ -95,7 +95,7 @@ public class ClientExamples {
public void createSecurityBearer() {
// START SNIPPET: securityBearer
// Create a context and get the client factory so it can be configured
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory();
// In reality the token would have come from an authorization server
@ -117,7 +117,7 @@ public class ClientExamples {
{
// START SNIPPET: logging
// Create a context and get the client factory so it can be configured
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory();
// Create a logging interceptor
@ -141,7 +141,7 @@ public class ClientExamples {
{
// START SNIPPET: clientConfig
// Create a client
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
IPatientClient client = ctx.newRestfulClient(IPatientClient.class, "http://localhost:9999/");
// Request JSON encoding from the server (_format=json)

View File

@ -37,7 +37,7 @@ public class CompleteExampleClient {
public static void main(String[] args) throws IOException {
// Create a client factory
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
// Create the client
String serverBase = "http://fhir.healthintersections.com.au/open";

View File

@ -11,7 +11,7 @@ public class ExampleRestfulClient {
//START SNIPPET: client
public static void main(String[] args) {
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
String serverBase = "http://foo.com/fhirServerBase";
// Create the client

View File

@ -49,7 +49,8 @@ ExtensionDt givenExt = new ExtensionDt(false, "http://examples.com#moreext", new
given.addUndeclaredExtension(givenExt);
//END SNIPPET: resourceStringExtension
String output = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
FhirContext ctx = FhirContext.forDstu2();
String output = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
System.out.println(output);

View File

@ -39,7 +39,7 @@ public class HttpProxy {
.disableCookieManagement();
CloseableHttpClient httpClient = clientBuilder.build();
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
String serverBase = "http://spark.furore.com/fhir/";
ctx.getRestfulClientFactory().setHttpClient(httpClient);
IGenericClient client = ctx.newRestfulGenericClient(serverBase);

View File

@ -65,19 +65,19 @@ patient.getImportantDates().add(new DateTimeDt("2014-01-26T11:11:11"));
patient.addName().addFamily("Smith").addGiven("John").addGiven("Quincy").addSuffix("Jr");
IParser p = new FhirContext().newXmlParser().setPrettyPrint(true);
IParser p = FhirContext.forDstu2().newXmlParser().setPrettyPrint(true);
String messageString = p.encodeResourceToString(patient);
System.out.println(messageString);
//END SNIPPET: patientUse
//START SNIPPET: patientParse
IParser parser = new FhirContext().newXmlParser();
IParser parser = FhirContext.forDstu2().newXmlParser();
MyPatient newPatient = parser.parseResource(MyPatient.class, messageString);
//END SNIPPET: patientParse
{
FhirContext ctx2 = new FhirContext();
FhirContext ctx2 = FhirContext.forDstu2();
RuntimeResourceDefinition def = ctx2.getResourceDefinition(patient);
System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile()));
}

View File

@ -18,7 +18,7 @@ patient.addIdentifier().setSystem("urn:foo").setValue("7000135");
patient.addName().addFamily("Smith").addGiven("John").addGiven("Edward");
patient.addAddress().addLine("742 Evergreen Terrace").setCity("Springfield").setState("ZZ");
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
// Use the narrative generator
ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());

View File

@ -16,7 +16,7 @@ public class NarrativeGenerator {
String propFile = "classpath:/com/foo/customnarrative.properties";
CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator(propFile);
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
ctx.setNarrativeGenerator(gen);
//END SNIPPET: gen

View File

@ -30,7 +30,7 @@ patient.addName().addFamily("Smith").addGiven("John").addGiven("Q").addSuffix("J
patient.setGender(AdministrativeGenderEnum.MALE);
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
String xmlEncoded = ctx.newXmlParser().encodeResourceToString(patient);
String jsonEncoded = ctx.newJsonParser().encodeResourceToString(patient);

View File

@ -6,7 +6,7 @@ import ca.uhn.fhir.model.dstu2.resource.Patient;
public class ResourceRefs {
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu2();
public static void main(String[] args) {
manualContained();

View File

@ -933,7 +933,7 @@ public interface HistoryClient extends IBasicClient {
public void bbbbb() throws DataFormatException, IOException {
//START SNIPPET: metadataClientUsage
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
MetadataClient client = ctx.newRestfulClient(MetadataClient.class, "http://spark.furore.com/fhir");
Conformance metadata = client.getServerMetadata();
System.out.println(ctx.newXmlParser().encodeResourceToString(metadata));
@ -973,7 +973,7 @@ private interface IPatientClient extends IBasicClient
public void clientRead() {
//START SNIPPET: clientReadTags
IPatientClient client = new FhirContext().newRestfulClient(IPatientClient.class, "http://foo/fhir");
IPatientClient client = FhirContext.forDstu2().newRestfulClient(IPatientClient.class, "http://foo/fhir");
Patient patient = client.readPatient(new IdDt("1234"));
// Access the tag list

View File

@ -43,7 +43,7 @@ ExtensionDt ext2 = new ExtensionDt(false, "http://examples.com#moreext", new Str
given.addUndeclaredExtension(ext2);
//END SNIPPET: resourceStringExtension
String output = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
String output = FhirContext.forDstu2().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
System.out.println(output);

View File

@ -20,7 +20,7 @@ public class TagsExamples {
@SuppressWarnings("unused")
public void getResourceTags() {
// START SNIPPET: getResourceTags
IGenericClient client = new FhirContext().newRestfulGenericClient("http://fhir.healthintersections.com.au/open");
IGenericClient client = FhirContext.forDstu2().newRestfulGenericClient("http://fhir.healthintersections.com.au/open");
Patient p = client.read(Patient.class, "1");
// Retrieve the list of tags from the resource metadata

View File

@ -37,7 +37,7 @@ public class ValidatorExamples {
public void validateResource() {
// START SNIPPET: basicValidation
// As always, you need a context
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
// Create and populate a new patient object
Patient p = new Patient();
@ -73,7 +73,7 @@ public class ValidatorExamples {
private static void validateFiles() throws Exception {
// START SNIPPET: validateFiles
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu2();
// Create a validator and configure it
FhirValidator validator = ctx.newValidator();

View File

@ -292,6 +292,7 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener
loadProperties(next);
}
} catch (IOException e) {
ourLog.info("Failed to load property file " + propFileName, e);
throw new ConfigurationException("Can not load property file " + propFileName, e);
}

View File

@ -103,12 +103,18 @@ public class RestfulServer extends HttpServlet {
private boolean myUseBrowserFriendlyContentTypes;
/**
* Constructor
* Constructor. Note that if no {@link FhirContext} is passed in to the server (either through the constructor, or
* through {@link #setFhirContext(FhirContext)}) the server will determine which version of FHIR to support
* through classpath scanning. This is brittle, and it is highly recommended to explicitly specify
* a FHIR version.
*/
public RestfulServer() {
this(new FhirContext());
this(null);
}
/**
* Constructor
*/
public RestfulServer(FhirContext theCtx) {
myFhirContext = theCtx;
}
@ -200,7 +206,7 @@ public class RestfulServer extends HttpServlet {
int count = 0;
for (Method m : ReflectionUtil.getDeclaredMethods(clazz)) {
BaseMethodBinding<?> foundMethodBinding = BaseMethodBinding.bindMethod(m, myFhirContext, theProvider);
BaseMethodBinding<?> foundMethodBinding = BaseMethodBinding.bindMethod(m, getFhirContext(), theProvider);
if (foundMethodBinding == null) {
continue;
}
@ -220,7 +226,7 @@ public class RestfulServer extends HttpServlet {
if (resourceName == null) {
resourceBinding = myServerBinding;
} else {
RuntimeResourceDefinition definition = myFhirContext.getResourceDefinition(resourceName);
RuntimeResourceDefinition definition = getFhirContext().getResourceDefinition(resourceName);
if (myResourceNameToProvider.containsKey(definition.getName())) {
resourceBinding = myResourceNameToProvider.get(definition.getName());
} else {
@ -270,7 +276,7 @@ public class RestfulServer extends HttpServlet {
if (Modifier.isPublic(m.getModifiers())) {
ourLog.debug("Scanning public method: {}#{}", theSystemProvider.getClass(), m.getName());
BaseMethodBinding<?> foundMethodBinding = BaseMethodBinding.bindMethod(m, myFhirContext, theSystemProvider);
BaseMethodBinding<?> foundMethodBinding = BaseMethodBinding.bindMethod(m, getFhirContext(), theSystemProvider);
if (foundMethodBinding != null) {
if (foundMethodBinding instanceof ConformanceMethodBinding) {
myServerConformanceMethod = foundMethodBinding;
@ -318,6 +324,9 @@ public class RestfulServer extends HttpServlet {
* creating their own.
*/
public FhirContext getFhirContext() {
if (myFhirContext == null) {
myFhirContext = new FhirContext();
}
return myFhirContext;
}
@ -419,7 +428,7 @@ public class RestfulServer extends HttpServlet {
}
public IResourceProvider getServerProfilesProvider() {
return myFhirContext.getVersion().createServerProfilesProvider(this);
return getFhirContext().getVersion().createServerProfilesProvider(this);
}
/**
@ -462,7 +471,7 @@ public class RestfulServer extends HttpServlet {
NarrativeModeEnum narrativeMode = RestfulServerUtils.determineNarrativeMode(theRequest);
boolean respondGzip = theRequest.isRespondGzip();
IVersionSpecificBundleFactory bundleFactory = myFhirContext.newBundleFactory();
IVersionSpecificBundleFactory bundleFactory = getFhirContext().newBundleFactory();
Set<Include> includes = new HashSet<Include>();
String[] reqIncludes = theRequest.getServletRequest().getParameterValues(Constants.PARAM_INCLUDE);
@ -765,7 +774,7 @@ public class RestfulServer extends HttpServlet {
throw new NullPointerException("getResourceType() on class '" + nextProvider.getClass().getCanonicalName() + "' returned null");
}
String resourceName = myFhirContext.getResourceDefinition(resourceType).getName();
String resourceName = getFhirContext().getResourceDefinition(resourceType).getName();
if (typeToProvider.containsKey(resourceName)) {
throw new ServletException("Multiple resource providers return resource type[" + resourceName + "]: First[" + typeToProvider.get(resourceName).getClass().getCanonicalName()
+ "] and Second[" + nextProvider.getClass().getCanonicalName() + "]");
@ -792,7 +801,7 @@ public class RestfulServer extends HttpServlet {
Object confProvider = getServerConformanceProvider();
if (confProvider == null) {
confProvider = myFhirContext.getVersion().createServerConformanceProvider(this);
confProvider = getFhirContext().getVersion().createServerConformanceProvider(this);
}
findSystemMethods(confProvider);

View File

@ -54,7 +54,7 @@ public class ResourceProviderDstu1Test {
private static ClassPathXmlApplicationContext ourAppCtx;
private static IGenericClient ourClient;
private static DaoConfig ourDaoConfig;
private static FhirContext ourFhirCtx;
private static FhirContext ourCtx = FhirContext.forDstu1();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu1Test.class);
private static IFhirResourceDao<Organization> ourOrganizationDao;
// private static IFhirResourceDao<Observation> ourObservationDao;
@ -405,14 +405,14 @@ public class ResourceProviderDstu1Test {
// Read back directly from the DAO
{
Organization returned = ourOrganizationDao.read(orgId);
String val = ourFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
ourLog.info(val);
assertThat(val, containsString("<name value=\"測試醫院\"/>"));
}
// Read back through the HTTP API
{
Organization returned = ourClient.read(Organization.class, orgId);
String val = ourFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
ourLog.info(val);
assertThat(val, containsString("<name value=\"測試醫院\"/>"));
}
@ -492,9 +492,7 @@ public class ResourceProviderDstu1Test {
public static void beforeClass() throws Exception {
int port = RandomServerPortProvider.findFreePort();
RestfulServer restServer = new RestfulServer();
ourFhirCtx = FhirContext.forDstu1();
restServer.setFhirContext(ourFhirCtx);
RestfulServer restServer = new RestfulServer(ourCtx);
String serverBase = "http://localhost:" + port + "/fhir/context";
@ -526,7 +524,7 @@ public class ResourceProviderDstu1Test {
ourServer.setHandler(proxyHandler);
ourServer.start();
ourClient = ourFhirCtx.newRestfulGenericClient(serverBase);
ourClient = ourCtx.newRestfulGenericClient(serverBase);
ourClient.registerInterceptor(new LoggingInterceptor(true));
}

View File

@ -101,7 +101,7 @@ public class ResourceProviderDstu2Test {
private static ClassPathXmlApplicationContext ourAppCtx;
private static IGenericClient ourClient;
private static DaoConfig ourDaoConfig;
private static FhirContext ourFhirCtx;
private static FhirContext ourCtx = FhirContext.forDstu2();
private static CloseableHttpClient ourHttpClient;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu2Test.class);
private static IFhirResourceDao<Organization> ourOrganizationDao;
@ -148,7 +148,7 @@ public class ResourceProviderDstu2Test {
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = client.read().resource(ca.uhn.fhir.model.dstu2.resource.Bundle.class).withId(id).execute();
ourLog.info(ourFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle));
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle));
}
@Test
@ -194,7 +194,7 @@ public class ResourceProviderDstu2Test {
Patient pt = new Patient();
pt.addName().addFamily(methodName);
String resource = ourFhirCtx.newXmlParser().encodeResourceToString(pt);
String resource = ourCtx.newXmlParser().encodeResourceToString(pt);
HttpPost post = new HttpPost(ourServerBase + "/Patient");
post.addHeader(Constants.HEADER_IF_NONE_EXIST, "Patient?name=" + methodName);
@ -284,7 +284,7 @@ public class ResourceProviderDstu2Test {
Patient pt = new Patient();
pt.addName().addFamily(methodName);
String resource = ourFhirCtx.newXmlParser().encodeResourceToString(pt);
String resource = ourCtx.newXmlParser().encodeResourceToString(pt);
HttpPost post = new HttpPost(ourServerBase + "/Patient");
post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
@ -328,7 +328,7 @@ public class ResourceProviderDstu2Test {
Patient pt = new Patient();
pt.addName().addFamily(methodName);
pt.addIdentifier().setSystem("http://ghh.org/patient").setValue(methodName);
String resource = ourFhirCtx.newXmlParser().encodeResourceToString(pt);
String resource = ourCtx.newXmlParser().encodeResourceToString(pt);
HttpPost post = new HttpPost(ourServerBase + "/Patient");
post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
@ -409,8 +409,8 @@ public class ResourceProviderDstu2Test {
*/
@Test
public void testDocumentManifestResources() throws Exception {
ourFhirCtx.getResourceDefinition(Practitioner.class);
ourFhirCtx.getResourceDefinition(ca.uhn.fhir.model.dstu.resource.DocumentManifest.class);
ourCtx.getResourceDefinition(Practitioner.class);
ourCtx.getResourceDefinition(ca.uhn.fhir.model.dstu.resource.DocumentManifest.class);
IGenericClient client = ourClient;
@ -449,7 +449,7 @@ public class ResourceProviderDstu2Test {
@Test
public void testEverythingDoesntRepeatPatient() throws Exception {
ca.uhn.fhir.model.dstu2.resource.Bundle b;
b = ourFhirCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, new InputStreamReader(ResourceProviderDstu2Test.class.getResourceAsStream("/bug147-bundle.json")));
b = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, new InputStreamReader(ResourceProviderDstu2Test.class.getResourceAsStream("/bug147-bundle.json")));
ca.uhn.fhir.model.dstu2.resource.Bundle resp = ourClient.transaction().withBundle(b).execute();
List<IdDt> ids = new ArrayList<IdDt>();
@ -518,7 +518,7 @@ public class ResourceProviderDstu2Test {
ca.uhn.fhir.model.dstu2.resource.Bundle resp = ourClient.transaction().withBundle(b).execute();
ourLog.info(ourFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp));
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp));
IdDt patientId = new IdDt(resp.getEntry().get(1).getTransactionResponse().getLocation());
assertEquals("Patient", patientId.getResourceType());
@ -874,14 +874,14 @@ public class ResourceProviderDstu2Test {
// Read back directly from the DAO
{
Organization returned = ourOrganizationDao.read(orgId);
String val = ourFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
ourLog.info(val);
assertThat(val, containsString("<name value=\"測試醫院\"/>"));
}
// Read back through the HTTP API
{
Organization returned = ourClient.read(Organization.class, orgId);
String val = ourFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
ourLog.info(val);
assertThat(val, containsString("<name value=\"測試醫院\"/>"));
}
@ -938,7 +938,7 @@ public class ResourceProviderDstu2Test {
Patient pt = new Patient();
pt.addName().addFamily(methodName);
String resource = ourFhirCtx.newXmlParser().encodeResourceToString(pt);
String resource = ourCtx.newXmlParser().encodeResourceToString(pt);
HttpPost post = new HttpPost(ourServerBase + "/Patient?name=" + methodName);
post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
@ -996,7 +996,7 @@ public class ResourceProviderDstu2Test {
Parameters input = new Parameters();
input.addParameter().setName("resource").setResource(patient);
String inputStr = ourFhirCtx.newXmlParser().encodeResourceToString(input);
String inputStr = ourCtx.newXmlParser().encodeResourceToString(input);
ourLog.info(inputStr);
HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate");
@ -1024,7 +1024,7 @@ public class ResourceProviderDstu2Test {
Parameters input = new Parameters();
input.addParameter().setName("resource").setResource(patient);
String inputStr = ourFhirCtx.newXmlParser().encodeResourceToString(input);
String inputStr = ourCtx.newXmlParser().encodeResourceToString(input);
ourLog.info(inputStr);
HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate");
@ -1061,9 +1061,8 @@ public class ResourceProviderDstu2Test {
public static void beforeClass() throws Exception {
ourPort = RandomServerPortProvider.findFreePort();
RestfulServer restServer = new RestfulServer();
ourFhirCtx = FhirContext.forDstu2();
restServer.setFhirContext(ourFhirCtx);
RestfulServer restServer = new RestfulServer(ourCtx);
restServer.setFhirContext(ourCtx);
ourServerBase = "http://localhost:" + ourPort + "/fhir/context";
@ -1095,9 +1094,9 @@ public class ResourceProviderDstu2Test {
ourServer.setHandler(proxyHandler);
ourServer.start();
ourFhirCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
ourFhirCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
ourClient = ourFhirCtx.newRestfulGenericClient(ourServerBase);
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
// ourClient.registerInterceptor(new LoggingInterceptor(true));
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);

View File

@ -139,8 +139,7 @@ public class ResourceProviderMultiVersionTest {
* DEV resources
*/
RestfulServer restServerDstu2 = new RestfulServer();
restServerDstu2.setFhirContext(ourAppCtx.getBean("myFhirContextDstu2", FhirContext.class));
RestfulServer restServerDstu2 = new RestfulServer(ourAppCtx.getBean("myFhirContextDstu2", FhirContext.class));
List<IResourceProvider> rpsDstu2 = (List<IResourceProvider>) ourAppCtx.getBean("myResourceProvidersDstu2", List.class);
restServerDstu2.setResourceProviders(rpsDstu2);
@ -155,8 +154,7 @@ public class ResourceProviderMultiVersionTest {
* DSTU resources
*/
RestfulServer restServerDstu1 = new RestfulServer();
restServerDstu1.setFhirContext(ourAppCtx.getBean("myFhirContextDstu1", FhirContext.class));
RestfulServer restServerDstu1 = new RestfulServer(ourAppCtx.getBean("myFhirContextDstu1", FhirContext.class));
List<IResourceProvider> rpsDstu1 = (List<IResourceProvider>) ourAppCtx.getBean("myResourceProvidersDstu1", List.class);
restServerDstu1.setResourceProviders(rpsDstu1);

View File

@ -89,7 +89,7 @@ public class SystemProviderDstu1Test {
OrganizationResourceProvider organizationRp = new OrganizationResourceProvider();
organizationRp.setDao(organizationDao);
RestfulServer restServer = new RestfulServer();
RestfulServer restServer = new RestfulServer(ourCtx);
restServer.setResourceProviders(patientRp, questionnaireRp, observationRp, organizationRp);
JpaSystemProviderDstu1 systemProv = ourAppCtx.getBean(JpaSystemProviderDstu1.class, "mySystemProviderDstu1");

View File

@ -122,7 +122,7 @@ public class SystemProviderDstu2Test {
OrganizationResourceProvider organizationRp = new OrganizationResourceProvider();
organizationRp.setDao(organizationDao);
RestfulServer restServer = new RestfulServer();
RestfulServer restServer = new RestfulServer(ourCtx);
restServer.setResourceProviders(patientRp, questionnaireRp, observationRp, organizationRp);
JpaSystemProviderDstu2 systemProv = ourAppCtx.getBean(JpaSystemProviderDstu2.class, "mySystemProviderDstu2");

View File

@ -14,7 +14,7 @@
<appender-ref ref="STDOUT" />
</logger>
<logger name="ca.uhn.fhir.jpa.dao" additivity="false" level="debug">
<logger name="ca.uhn.fhir.jpa.dao" additivity="false" level="info">
<appender-ref ref="STDOUT" />
</logger>
@ -26,4 +26,4 @@
<appender-ref ref="STDOUT" />
</root>
</configuration>
</configuration>

View File

@ -7,9 +7,10 @@ import ca.uhn.fhir.context.FhirContext;
public class FhirContextFactory implements FactoryBean<FhirContext>, InitializingBean {
private int myConnectionRequestTimeout = 5000;
private int mySocketTimeout = 10000;
private int myConnectionRequestTimeout = 5000;
private int mySocketTimeout = 10000;
private int myConnectTimeout = 4000;
public int getConnectionRequestTimeout() {
return myConnectionRequestTimeout;
}
@ -36,9 +37,9 @@ public class FhirContextFactory implements FactoryBean<FhirContext>, Initializin
private FhirContext myCtx;
public FhirContextFactory() {
public FhirContextFactory() {
}
@Override
public FhirContext getObject() throws Exception {
return myCtx;
@ -56,7 +57,7 @@ public class FhirContextFactory implements FactoryBean<FhirContext>, Initializin
@Override
public void afterPropertiesSet() throws Exception {
myCtx=new FhirContext();
myCtx = new FhirContext();
myCtx.getRestfulClientFactory().setConnectTimeout(myConnectTimeout);
myCtx.getRestfulClientFactory().setSocketTimeout(mySocketTimeout);
myCtx.getRestfulClientFactory().setConnectionRequestTimeout(myConnectionRequestTimeout);

View File

@ -1,17 +0,0 @@
package ca.uhn.fhir;
import static org.junit.Assert.*;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
public class Dstu1EnvTest {
@Test
public void testCorrectDefault() {
FhirContext ctx = new FhirContext();
assertEquals("new FhirContext() is creating a context with the wrong FHIR versions. Something is probably wrong with the classpath.", FhirVersionEnum.DSTU1, ctx.getVersion().getVersion());
}
}

View File

@ -23,7 +23,7 @@ public class DuplicateExtensionTest extends TestCase {
@Test
public void testScannerShouldAddProvidedResources() {
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu1();
RuntimeResourceDefinition patientDef = ctx.getResourceDefinition(CustomPatient.class);
Profile profile = (Profile) patientDef.toProfile("http://foo.org/fhir");

View File

@ -16,7 +16,7 @@ import ca.uhn.fhir.parser.MyPatient;
public class ExtensionTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExtensionTest.class);
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testExtensionType() {
@ -66,19 +66,19 @@ public class ExtensionTest {
patient.addName().addFamily("Smith").addGiven("John").addGiven("Quincy").addSuffix("Jr");
IParser p = new FhirContext().newXmlParser().setPrettyPrint(true);
IParser p = FhirContext.forDstu1().newXmlParser().setPrettyPrint(true);
String messageString = p.encodeResourceToString(patient);
System.out.println(messageString);
// END SNIPPET: patientUse
// START SNIPPET: patientParse
IParser parser = new FhirContext().newXmlParser();
IParser parser = FhirContext.forDstu1().newXmlParser();
MyPatient newPatient = parser.parseResource(MyPatient.class, messageString);
// END SNIPPET: patientParse
{
FhirContext ctx2 = new FhirContext();
FhirContext ctx2 = FhirContext.forDstu1();
RuntimeResourceDefinition def = ctx2.getResourceDefinition(patient);
System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile("http://foo.org/fhir")));
}

View File

@ -9,11 +9,11 @@ import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.resource.ValueSet;
public class FhirContextTest {
public class FhirContextDstu1Test {
@Test
public void testIncrementalScan() {
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu1();
RuntimeResourceDefinition vsDef = ctx.getResourceDefinition(ValueSet.class);
RuntimeResourceDefinition ptDef = ctx.getResourceDefinition(Patient.class);
assertNotNull(ptDef);
@ -24,13 +24,13 @@ public class FhirContextTest {
@Test
public void testFindBinary() {
RuntimeResourceDefinition def = new FhirContext().getResourceDefinition("Binary");
RuntimeResourceDefinition def = FhirContext.forDstu1().getResourceDefinition("Binary");
assertEquals("Binary", def.getName());
}
@Test(expected = IllegalArgumentException.class)
public void testGetResourceDefinitionFails() {
new FhirContext().getResourceDefinition(IResource.class);
FhirContext.forDstu1().getResourceDefinition(IResource.class);
}
@Test

View File

@ -10,7 +10,7 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
public class InvalidResourceTypeTest {
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testNonInstantiableType() {

View File

@ -11,7 +11,7 @@ import ca.uhn.fhir.parser.MyPatient;
public class ModelExtensionTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ModelExtensionTest.class);
private FhirContext ourCtx = new FhirContext();
private FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testModelExtension() throws DataFormatException {

View File

@ -19,7 +19,7 @@ public class ModelScannerTest {
@Test
public void testExtendedClass() {
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu1();
ctx.getResourceDefinition(MyPatient.class);
RuntimeResourceDefinition patient = ctx.getResourceDefinition("Patient");

View File

@ -19,7 +19,7 @@ public class NameChanges {
@SuppressWarnings("unchecked")
@Test
public void testNameChanges() throws IOException, ClassNotFoundException {
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu1();
ImmutableSet<ClassInfo> names = ClassPath.from(getClass().getClassLoader()).getTopLevelClasses(Patient.class.getPackage().getName());
List<String> changes = new ArrayList<String>();

View File

@ -12,7 +12,7 @@ import static org.junit.Assert.assertNull;
public class ProvidedResourceScannerTest extends TestCase {
@Test
public void testScannerShouldAddProvidedResources() {
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu1();
assertEquals(CustomPatient.class, ctx.getElementDefinition(CustomPatient.class).getImplementingClass());
assertEquals(Patient.class, ctx.getResourceDefinition("Patient").getImplementingClass());

View File

@ -13,7 +13,7 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
public class TagListTest {
private FhirContext myCtx = new FhirContext();
private FhirContext myCtx = FhirContext.forDstu1();
@Test
public void testEquals() {

View File

@ -27,7 +27,7 @@ public class BaseDateTimeDtTest {
private FastDateFormat myDateInstantZoneParser;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeDtTest.class);
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
@Before
public void before() {

View File

@ -206,7 +206,7 @@ public class IdDtTest {
@BeforeClass
public static void beforeClass() {
ourCtx = new FhirContext();
ourCtx = FhirContext.forDstu1();
}
}

View File

@ -14,7 +14,7 @@ import ca.uhn.fhir.parser.IParser;
public class ViewGeneratorTest {
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testView() {

View File

@ -46,7 +46,7 @@ public class DefaultThymeleafNarrativeGeneratorTest {
gen.setIgnoreFailures(false);
gen.setIgnoreMissingTemplates(false);
myCtx = new FhirContext();
myCtx = FhirContext.forDstu1();
myCtx.setNarrativeGenerator(gen);
}

View File

@ -13,7 +13,7 @@ import ca.uhn.fhir.model.dstu.resource.Composition;
public class BaseParserTest {
private static final FhirContext ourCtx = new FhirContext();
private static final FhirContext ourCtx = FhirContext.forDstu1();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseParserTest.class);

View File

@ -58,7 +58,7 @@ public class ContainedResourceEncodingTest {
initPatient();
initAuthor();
initComposition();
this.ctx = new FhirContext();
this.ctx = FhirContext.forDstu1();
}

View File

@ -28,6 +28,7 @@ import org.hamcrest.core.IsNot;
import org.hamcrest.core.StringContains;
import org.hamcrest.text.StringContainsInOrder;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@ -294,13 +295,13 @@ public class JsonParserTest {
e.setResource(new Patient());
b.addCategory("scheme", "term", "label");
String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
String val = ourCtx.newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
ourLog.info(val);
assertThat(val, StringContains.containsString("\"category\":[{\"term\":\"term\",\"label\":\"label\",\"scheme\":\"scheme\"}]"));
assertThat(val, not(containsString("text")));
b = new FhirContext().newJsonParser().parseBundle(val);
b = ourCtx.newJsonParser().parseBundle(val);
assertEquals(1, b.getEntries().size());
assertEquals(1, b.getCategories().size());
assertEquals("term", b.getCategories().get(0).getTerm());
@ -489,7 +490,7 @@ public class JsonParserTest {
@Test
public void testEncodeDeclaredExtensionWithAddressContent() {
IParser parser = new FhirContext().newJsonParser();
IParser parser = ourCtx.newJsonParser();
MyPatientWithOneDeclaredAddressExtension patient = new MyPatientWithOneDeclaredAddressExtension();
patient.addAddress().setUse(AddressUseEnum.HOME);
@ -508,7 +509,7 @@ public class JsonParserTest {
@Test
public void testEncodeDeclaredExtensionWithResourceContent() {
IParser parser = new FhirContext().newJsonParser();
IParser parser = ourCtx.newJsonParser();
MyPatientWithOneDeclaredExtension patient = new MyPatientWithOneDeclaredExtension();
patient.addAddress().setUse(AddressUseEnum.HOME);
@ -620,7 +621,7 @@ public class JsonParserTest {
@Test
public void testEncodeExtensionWithResourceContent() {
IParser parser = new FhirContext().newJsonParser();
IParser parser = ourCtx.newJsonParser();
Patient patient = new Patient();
patient.addAddress().setUse(AddressUseEnum.HOME);
@ -751,7 +752,7 @@ public class JsonParserTest {
ExtensionDt parameter = q.addParameter();
parameter.setUrl("http://hl7.org/fhir/query#_query").setValue(new StringDt("example"));
String val = new FhirContext().newJsonParser().encodeResourceToString(q);
String val = ourCtx.newJsonParser().encodeResourceToString(q);
ourLog.info(val);
//@formatter:off
@ -779,7 +780,7 @@ public class JsonParserTest {
Patient patient = new Patient();
patient.setManagingOrganization(new ResourceReferenceDt());
IParser p = new FhirContext().newJsonParser();
IParser p = ourCtx.newJsonParser();
String str = p.encodeResourceToString(patient);
assertThat(str, IsNot.not(StringContains.containsString("managingOrganization")));
@ -797,7 +798,7 @@ public class JsonParserTest {
@Test
public void testEncodeUndeclaredExtensionWithAddressContent() {
IParser parser = new FhirContext().newJsonParser();
IParser parser = ourCtx.newJsonParser();
Patient patient = new Patient();
patient.addAddress().setUse(AddressUseEnum.HOME);
@ -845,15 +846,15 @@ public class JsonParserTest {
HumanNameDt given = name.addGiven("Joe");
ExtensionDt ext2 = new ExtensionDt(false, "http://examples.com#givenext", new StringDt("Hello"));
given.addUndeclaredExtension(ext2);
String enc = new FhirContext().newJsonParser().encodeResourceToString(patient);
String enc = ourCtx.newJsonParser().encodeResourceToString(patient);
ourLog.info(enc);
assertEquals("{\"resourceType\":\"Patient\",\"name\":[{\"extension\":[{\"url\":\"http://examples.com#givenext\",\"valueString\":\"Hello\"}],\"family\":[\"Shmoe\"],\"given\":[\"Joe\"]}]}", enc);
IParser newJsonParser = new FhirContext().newJsonParser();
IParser newJsonParser = ourCtx.newJsonParser();
StringReader reader = new StringReader(enc);
Patient parsed = newJsonParser.parseResource(Patient.class, reader);
ourLog.info(new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed));
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed));
assertEquals(1, parsed.getNameFirstRep().getUndeclaredExtensionsByUrl("http://examples.com#givenext").size());
ExtensionDt ext = parsed.getNameFirstRep().getUndeclaredExtensionsByUrl("http://examples.com#givenext").get(0);
@ -872,7 +873,7 @@ public class JsonParserTest {
ExtensionDt ext2 = new ExtensionDt(false, "http://examples.com#givenext", new StringDt("Hello"));
family.addUndeclaredExtension(ext2);
String enc = new FhirContext().newJsonParser().encodeResourceToString(patient);
String enc = ourCtx.newJsonParser().encodeResourceToString(patient);
ourLog.info(enc);
//@formatter:off
assertThat(enc, containsString(("{\n" +
@ -897,7 +898,7 @@ public class JsonParserTest {
"}").replace("\n", "").replaceAll(" +", "")));
//@formatter:on
Patient parsed = new FhirContext().newJsonParser().parseResource(Patient.class, new StringReader(enc));
Patient parsed = ourCtx.newJsonParser().parseResource(Patient.class, new StringReader(enc));
assertEquals(1, parsed.getNameFirstRep().getFamilyFirstRep().getUndeclaredExtensionsByUrl("http://examples.com#givenext").size());
ExtensionDt ext = parsed.getNameFirstRep().getFamilyFirstRep().getUndeclaredExtensionsByUrl("http://examples.com#givenext").get(0);
assertEquals("Hello", ext.getValueAsPrimitive().getValue());
@ -956,7 +957,7 @@ public class JsonParserTest {
// nothing
}};
FhirContext context = new FhirContext();
FhirContext context = ourCtx;
context.setNarrativeGenerator(gen);
IParser p = context.newJsonParser();
p.encodeResourceToWriter(patient, new OutputStreamWriter(System.out));
@ -967,6 +968,11 @@ public class JsonParserTest {
assertThat(str, StringContains.containsString(",\"text\":{\"status\":\"generated\",\"div\":\"<div>help</div>\"},"));
}
@Before
public void before() {
ourCtx.setNarrativeGenerator(null);
}
@Test
public void testNestedContainedResources() {
@ -1330,7 +1336,7 @@ public class JsonParserTest {
"}";
//@formatter:on
TagList tagList = new FhirContext().newJsonParser().parseTagList(tagListStr);
TagList tagList = ourCtx.newJsonParser().parseTagList(tagListStr);
assertEquals(3, tagList.size());
assertEquals("term0", tagList.get(0).getTerm());
assertEquals("label0", tagList.get(0).getLabel());
@ -1367,14 +1373,14 @@ public class JsonParserTest {
"}";
//@formatter:on
String encoded = new FhirContext().newJsonParser().encodeTagListToString(tagList);
String encoded = ourCtx.newJsonParser().encodeTagListToString(tagList);
assertEquals(expected, encoded);
}
@BeforeClass
public static void beforeClass() {
ourCtx = new FhirContext();
ourCtx = FhirContext.forDstu1();
}
@ResourceDef(name = "Patient")

View File

@ -1700,8 +1700,7 @@ public class XmlParserTest {
@Test
public void testParseFeedWithListResource() throws ConfigurationException, DataFormatException, IOException {
// Use new context here to ensure List isn't already loaded
IParser p = new FhirContext().newXmlParser();
IParser p = FhirContext.forDstu1().newXmlParser(); // Use new context here
String string = IOUtils.toString(XmlParserTest.class.getResourceAsStream("/feed-with-list.xml"), Charset.forName("UTF-8"));
Bundle bundle = p.parseBundle(string);
@ -1920,7 +1919,7 @@ public class XmlParserTest {
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreWhitespace(true);
ourCtx = new FhirContext();
ourCtx = FhirContext.forDstu1();
}
@BeforeClass

View File

@ -97,7 +97,7 @@ public class BasicAuthInterceptorTest {
@BeforeClass
public static void beforeClass() {
ourCtx = new FhirContext();
ourCtx = FhirContext.forDstu1();
}
}

View File

@ -82,7 +82,7 @@ public class BearerTokenAuthInterceptorTest {
@BeforeClass
public static void beforeClass() {
ourCtx = new FhirContext();
ourCtx = FhirContext.forDstu1();
}
}

View File

@ -1,12 +1,8 @@
package ca.uhn.fhir.rest.client;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.io.InputStream;
import java.io.StringReader;
@ -47,7 +43,6 @@ import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.base.resource.BaseConformance;
import ca.uhn.fhir.model.dstu.composite.CodingDt;
import ca.uhn.fhir.model.dstu.resource.Conformance;
import ca.uhn.fhir.model.dstu.resource.Observation;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu.resource.Patient;
@ -77,19 +72,19 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
public class ClientTest {
public class ClientDstu1Test {
private FhirContext ctx;
private FhirContext ourCtx;
private HttpClient httpClient;
private HttpResponse httpResponse;
@Before
public void before() {
ctx = new FhirContext(Patient.class, Conformance.class);
ourCtx = FhirContext.forDstu1();
httpClient = mock(HttpClient.class, new ReturnsDeepStubs());
ctx.getRestfulClientFactory().setHttpClient(httpClient);
ctx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
ourCtx.getRestfulClientFactory().setHttpClient(httpClient);
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
httpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
}
@ -136,7 +131,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200"));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
CapturingInterceptor interceptor = new CapturingInterceptor();
client.registerInterceptor(interceptor);
@ -165,7 +160,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("foobar"), Charset.forName("UTF-8")));
try {
ctx.newRestfulClient(ITestClient.class, "http://foo").createPatient(patient);
ourCtx.newRestfulClient(ITestClient.class, "http://foo").createPatient(patient);
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), StringContains.containsString("foobar"));
@ -185,10 +180,10 @@ public class ClientTest {
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(ctx.newXmlParser().encodeResourceToString(patient)), Charset.forName("UTF-8")));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(ourCtx.newXmlParser().encodeResourceToString(patient)), Charset.forName("UTF-8")));
when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200"));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
MethodOutcome response = client.createPatient(patient);
assertEquals(HttpPost.class, capt.getValue().getClass());
@ -211,7 +206,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200"));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
TagList tagList = new TagList();
tagList.add(new Tag((String) null, "Dog", "DogLabel"));
tagList.add(new Tag("http://cats", "Cat", "CatLabel"));
@ -237,7 +232,7 @@ public class ClientTest {
OperationOutcome oo = new OperationOutcome();
oo.addIssue().setDetails("Hello");
String resp = new FhirContext().newXmlParser().encodeResourceToString(oo);
String resp = ourCtx.newXmlParser().encodeResourceToString(oo);
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
@ -245,7 +240,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(resp), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
MethodOutcome response = client.deletePatient(new IdDt("1234"));
assertEquals(HttpDelete.class, capt.getValue().getClass());
@ -262,7 +257,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
client.deleteDiagnosticReport(new IdDt("1234"));
assertEquals(HttpDelete.class, capt.getValue().getClass());
@ -272,7 +267,7 @@ public class ClientTest {
@Test
public void testGetConformance() throws Exception {
String msg = IOUtils.toString(ClientTest.class.getResourceAsStream("/example-metadata.xml"));
String msg = IOUtils.toString(ClientDstu1Test.class.getResourceAsStream("/example-metadata.xml"));
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
@ -280,7 +275,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
BaseConformance response = client.getServerConformanceStatement();
assertEquals("http://foo/metadata", capt.getValue().getURI().toString());
@ -319,7 +314,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
Bundle response = client.getHistoryPatientInstance(new IdDt("111"));
assertEquals("http://foo/Patient/111/_history", capt.getValue().getURI().toString());
@ -391,7 +386,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
Bundle response = client.getHistoryPatientType();
assertEquals("http://foo/Patient/_history", capt.getValue().getURI().toString());
@ -462,7 +457,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
Bundle response = client.getHistoryServer();
assertEquals("http://foo/_history", capt.getValue().getURI().toString());
@ -521,7 +516,7 @@ public class ClientTest {
}
});
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
// ensures the local timezone
String expectedDateString = new InstantDt(new InstantDt("2012-01-02T12:01:02").getValue()).getValueAsString();
@ -556,7 +551,7 @@ public class ClientTest {
// TODO: remove the read annotation and make sure we get a sensible
// error message to tell the user why the method isn't working
FhirContext ctx = new FhirContext();
FhirContext ctx = ourCtx;
ctx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
ClientWithoutAnnotation client = ctx.newRestfulClient(ClientWithoutAnnotation.class, "http://wildfhir.aegis.net/fhir");
@ -596,7 +591,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
// Patient response = client.findPatientByMrn(new
// IdentifierDt("urn:foo", "123"));
Patient response = client.getPatientById(new IdDt("111"));
@ -640,7 +635,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", "application/fhir+xml; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
// Patient response = client.findPatientByMrn(new
// IdentifierDt("urn:foo", "123"));
Patient response = client.getPatientById(new IdDt("111"));
@ -662,7 +657,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("Internal Failure"), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
try {
client.getPatientById(new IdDt("111"));
fail();
@ -689,7 +684,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
try {
client.getPatientById(new IdDt("111"));
fail();
@ -723,7 +718,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
// Patient response = client.findPatientByMrn(new
// IdentifierDt("urn:foo", "123"));
Patient response = client.getPatientById(new IdDt("111"));
@ -748,7 +743,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
DateRangeParam param = new DateRangeParam();
param.setLowerBound(new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-01"));
param.setUpperBound(new DateParam(QuantityCompararatorEnum.LESSTHAN_OR_EQUALS, "2021-01-01"));
@ -772,7 +767,7 @@ public class ClientTest {
// httpResponse = new BasicHttpResponse(statusline, catalog, locale)
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
List<Patient> response = client.getPatientByDob(new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02"));
assertEquals("http://foo/Patient?birthdate=%3E%3D2011-01-02", capt.getValue().getURI().toString());
@ -793,7 +788,7 @@ public class ClientTest {
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
List<Patient> response = client.getPatientByCompartmentAndDob(new IdDt("123"), new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02"));
assertEquals("http://foo/Patient/123/compartmentName?birthdate=%3E%3D2011-01-02", capt.getValue().getURI().toString());
@ -819,7 +814,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
Patient response = client.findPatientQuantity(new QuantityParam(QuantityCompararatorEnum.GREATERTHAN, 123L, "foo", "bar"));
assertEquals("http://foo/Patient?quantityParam=%3E123%7Cfoo%7Cbar", capt.getValue().getURI().toString());
@ -838,7 +833,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
Patient response = client.findPatientByMrn(new TokenParam("urn:foo", "123"));
assertEquals("http://foo/Patient?identifier=urn%3Afoo%7C123", capt.getValue().getURI().toString());
@ -857,7 +852,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
TokenOrListParam identifiers = new TokenOrListParam();
identifiers.add(new CodingDt("foo", "bar"));
identifiers.add(new CodingDt("baz", "boz"));
@ -878,7 +873,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
client.getPatientNoParams();
assertEquals("http://foo/Patient?_query=someQueryNoParams", capt.getValue().getURI().toString());
@ -896,7 +891,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
client.getPatientOneParam(new StringParam("BB"));
assertEquals("http://foo/Patient?_query=someQueryOneParam&param1=BB", capt.getValue().getURI().toString());
@ -914,7 +909,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClientWithCustomType client = ctx.newRestfulClient(ITestClientWithCustomType.class, "http://foo");
ITestClientWithCustomType client = ourCtx.newRestfulClient(ITestClientWithCustomType.class, "http://foo");
CustomPatient response = client.getPatientByDob(new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02"));
assertEquals("http://foo/Patient?birthdate=%3E%3D2011-01-02", capt.getValue().getURI().toString());
@ -933,7 +928,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClientWithCustomTypeList client = ctx.newRestfulClient(ITestClientWithCustomTypeList.class, "http://foo");
ITestClientWithCustomTypeList client = ourCtx.newRestfulClient(ITestClientWithCustomTypeList.class, "http://foo");
List<CustomPatient> response = client.getPatientByDob(new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02"));
assertEquals("http://foo/Patient?birthdate=%3E%3D2011-01-02", capt.getValue().getURI().toString());
@ -954,7 +949,7 @@ public class ClientTest {
// TODO: document this
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
client.getPatientByDob(new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02"));
assertEquals("http://foo/Patient?birthdate=%3E%3D2011-01-02", capt.getAllValues().get(0).getURI().toString());
@ -982,7 +977,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
client.getPatientWithIncludes(new StringParam("aaa"), Arrays.asList(new Include[] { new Include("inc1"), new Include("inc2") }));
assertEquals("http://foo/Patient?withIncludes=aaa&_include=inc1&_include=inc2", capt.getValue().getURI().toString());
@ -1000,7 +995,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
Bundle response = client.findPatientByName(new StringParam("AAA"), null);
assertEquals("http://foo/Patient?family=AAA", capt.getValue().getURI().toString());
@ -1012,7 +1007,7 @@ public class ClientTest {
*/
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
client = ctx.newRestfulClient(ITestClient.class, "http://foo");
client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
response = client.findPatientByName(new StringParam("AAA"), new StringParam("BBB"));
assertEquals("http://foo/Patient?family=AAA&given=BBB", capt.getValue().getURI().toString());
@ -1032,7 +1027,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
StringParam str = new StringParam("FOO$BAR");
DateParam date = new DateParam("2001-01-01");
client.getObservationByNameValueDate(new CompositeParam<StringParam, DateParam>(str, date));
@ -1052,7 +1047,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClientWithStringIncludes client = ctx.newRestfulClient(ITestClientWithStringIncludes.class, "http://foo");
ITestClientWithStringIncludes client = ourCtx.newRestfulClient(ITestClientWithStringIncludes.class, "http://foo");
client.getPatientWithIncludes(new StringParam("aaa"), "inc1");
assertEquals("http://foo/Patient?withIncludes=aaa&_include=inc1", capt.getValue().getURI().toString());
@ -1072,7 +1067,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200"));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
MethodOutcome response = client.updatePatient(new IdDt("100"), patient);
assertEquals(HttpPut.class, capt.getValue().getClass());
@ -1100,7 +1095,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Content-Location", "http://example.com/fhir/Patient/100/_history/200"));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
client.updatePatient(new IdDt("Patient/100/_history/200"), patient);
assertEquals(HttpPut.class, capt.getValue().getClass());
@ -1124,7 +1119,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_409_CONFLICT, "Conflict"));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
client.updatePatient(new IdDt("Patient/100/_history/200"), patient);
}
@ -1141,7 +1136,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200"));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
MethodOutcome response = client.updatePatient(new IdDt("Patient/100/_history/200"), patient);
assertEquals(HttpPut.class, capt.getValue().getClass());
@ -1166,7 +1161,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200"));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
MethodOutcome response = client.validatePatient(patient);
assertEquals(HttpPost.class, capt.getValue().getClass());
@ -1199,7 +1194,7 @@ public class ClientTest {
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
// Patient response = client.findPatientByMrn(new
// IdentifierDt("urn:foo", "123"));
Patient response = client.getPatientById(new IdDt("Patient/111/_history/999"));
@ -1224,7 +1219,7 @@ public class ClientTest {
}
});
ITestClientWithNarrativeParam client = ctx.newRestfulClient(ITestClientWithNarrativeParam.class, "http://foo");
ITestClientWithNarrativeParam client = ourCtx.newRestfulClient(ITestClientWithNarrativeParam.class, "http://foo");
int idx = 0;

View File

@ -34,6 +34,7 @@ public class ClientIntegrationTest {
private int myPort;
private Server myServer;
private MyPatientResourceProvider myPatientProvider;
private static FhirContext ourCtx = FhirContext.forDstu1();
@Before
public void before() {
@ -43,7 +44,7 @@ public class ClientIntegrationTest {
myPatientProvider = new MyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(myPatientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
@ -57,7 +58,7 @@ public class ClientIntegrationTest {
myServer.start();
FhirContext ctx = new FhirContext();
FhirContext ctx = FhirContext.forDstu1();
HttpClientBuilder builder = HttpClientBuilder.create();
// PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);

View File

@ -38,7 +38,7 @@ public class ExceptionHandlingTest {
@BeforeClass
public static void beforeClass() {
ourCtx = new FhirContext();
ourCtx = FhirContext.forDstu1();
}
@Before

View File

@ -778,7 +778,7 @@ public class GenericClientTest {
@Test
public void testSearchByNumberExact() throws Exception {
String msg = new FhirContext().newXmlParser().encodeBundleToString(new Bundle());
String msg = ourCtx.newXmlParser().encodeBundleToString(new Bundle());
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
@ -1360,7 +1360,7 @@ public class GenericClientTest {
@BeforeClass
public static void beforeClass() {
ourCtx = new FhirContext();
ourCtx = FhirContext.forDstu1();
}
}

View File

@ -49,7 +49,7 @@ public class HttpProxyTest {
myFirstRequest = true;
myAuthHeader = null;
RestfulServer restServer = new RestfulServer() {
RestfulServer restServer = new RestfulServer(ourCtx) {
@Override
protected void doGet(HttpServletRequest theRequest, HttpServletResponse theResponse) throws ServletException, IOException {
@ -69,7 +69,6 @@ public class HttpProxyTest {
}
};
restServer.setFhirContext(ourCtx);
restServer.setResourceProviders(new PatientResourceProvider());
// ServletHandler proxyHandler = new ServletHandler();
@ -123,7 +122,7 @@ public class HttpProxyTest {
@BeforeClass
public static void beforeClass() throws Exception {
ourCtx = new FhirContext();
ourCtx = FhirContext.forDstu1();
}
public static class PatientResourceProvider implements IResourceProvider {

View File

@ -39,8 +39,7 @@ public class LoggingInterceptorTest {
private static int ourPort;
private static Server ourServer;
private static FhirContext ourCtx;
private static final FhirContext ourCtx = FhirContext.forDstu1();
private Appender<ILoggingEvent> myMockAppender;
private Logger myLoggerRoot;
@ -89,15 +88,14 @@ public class LoggingInterceptorTest {
DummyProvider patientProvider = new DummyProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
ourCtx = servlet.getFhirContext();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
ourServer.setHandler(proxyHandler);
ourServer.start();
ourCtx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
}
/**

View File

@ -42,9 +42,9 @@ import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
public class SearchTest {
public class SearchClientDstu1Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchTest.class);
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchClientDstu1Test.class);
private FhirContext ourCtx;
private HttpClient ourHttpClient;

View File

@ -184,7 +184,7 @@ public class BaseOutcomeReturningMethodBindingTest {
"}";
//@formatter:on
TagList parsedFromResource = new FhirContext().newJsonParser().parseTagList(resourceString);
TagList parsedFromResource = FhirContext.forDstu1().newJsonParser().parseTagList(resourceString);
assertEquals(parsedFromHeader.size(), parsedFromResource.size());

View File

@ -38,6 +38,7 @@ public class AcceptHeaderTest {
private static CloseableHttpClient ourClient;
private static int ourPort;
private static Server ourServer;
private static FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testReadNoHeader() throws Exception {
@ -97,7 +98,7 @@ public class AcceptHeaderTest {
ourServer = new Server(ourPort);
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(new PatientProvider());
servlet.setDefaultResponseEncoding(EncodingEnum.XML);
ServletHolder servletHolder = new ServletHolder(servlet);

View File

@ -44,7 +44,7 @@ import ca.uhn.fhir.util.PortUtil;
public class BinaryTest {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
private static Binary ourLast;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BinaryTest.class);
@ -166,7 +166,7 @@ public class BinaryTest {
ResourceProvider patientProvider = new ResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -40,7 +40,7 @@ import ca.uhn.fhir.util.PortUtil;
public class CompositeParameterTest {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx;
private static final FhirContext ourCtx = FhirContext.forDstu1();
private static int ourPort;
private static Server ourServer;
@ -106,8 +106,7 @@ public class CompositeParameterTest {
DummyObservationResourceProvider patientProvider = new DummyObservationResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
ourCtx = servlet.getFhirContext();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
@ -118,8 +117,6 @@ public class CompositeParameterTest {
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connectionManager);
ourClient = builder.build();
ourCtx = servlet.getFhirContext();
}
/**

View File

@ -41,7 +41,7 @@ public class CompressionTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CompressionTest.class);
private static int ourPort;
private static Server ourServer;
private static FhirContext ourCtx;
private static final FhirContext ourCtx = FhirContext.forDstu1();
public static String decompress(byte[] theResource) {
GZIPInputStream is;
@ -107,8 +107,7 @@ public class CompressionTest {
DummyProvider patientProvider = new DummyProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
ourCtx = servlet.getFhirContext();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -37,7 +37,7 @@ import ca.uhn.fhir.util.PortUtil;
*/
public class CorsTest {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx;
private static final FhirContext ourCtx = FhirContext.forDstu1();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CorsTest.class);
@Test
@ -45,8 +45,7 @@ public class CorsTest {
int port = PortUtil.findFreePort();
Server server = new Server(port);
RestfulServer restServer = new RestfulServer();
restServer.setFhirContext(ourCtx);
RestfulServer restServer = new RestfulServer(ourCtx);
restServer.setResourceProviders(new DummyPatientResourceProvider());
// ServletHandler proxyHandler = new ServletHandler();
@ -125,8 +124,6 @@ public class CorsTest {
@BeforeClass
public static void beforeClass() throws Exception {
ourCtx = new FhirContext();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connectionManager);

View File

@ -51,11 +51,11 @@ import ca.uhn.fhir.util.PortUtil;
*/
public class CreateTest {
private static CloseableHttpClient ourClient;
private static final FhirContext ourCtx = FhirContext.forDstu1();
private static EncodingEnum ourLastEncoding;
private static String ourLastResourceBody;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CreateTest.class);
private static int ourPort;
private static DiagnosticReportProvider ourReportProvider;
private static Server ourServer;
@ -65,7 +65,7 @@ public class CreateTest {
ourLastResourceBody=null;
ourLastEncoding=null;
}
@Test
public void testCreate() throws Exception {
@ -74,7 +74,7 @@ public class CreateTest {
patient.addIdentifier().setValue("002");
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -91,31 +91,6 @@ public class CreateTest {
}
@Test
public void testCreateWithNoParsed() throws Exception {
Organization org = new Organization();
org.addIdentifier().setValue("001");
org.addIdentifier().setValue("002");
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Organization");
httpPost.setEntity(new StringEntity(new FhirContext().newJsonParser().encodeResourceToString(org), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
assertEquals(201, status.getStatusLine().getStatusCode());
assertEquals("http://localhost:" + ourPort + "/Organization/001", status.getFirstHeader("location").getValue());
assertThat(status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue(), StringContains.containsString("UTF-8"));
assertThat(ourLastResourceBody, stringContainsInOrder("\"resourceType\":\"Organization\"", "\"identifier\"","\"value\":\"001"));
assertEquals(EncodingEnum.JSON, ourLastEncoding);
}
@Test
public void testCreateById() throws Exception {
@ -124,7 +99,7 @@ public class CreateTest {
patient.addIdentifier().setValue("002");
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/1234");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -144,7 +119,7 @@ public class CreateTest {
obs.getIdentifier().setValue("001");
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Observation");
httpPost.setEntity(new StringEntity(new FhirContext().newJsonParser().encodeResourceToString(obs), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newJsonParser().encodeResourceToString(obs), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -166,7 +141,7 @@ public class CreateTest {
patient.addIdentifier().setValue("002");
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient");
httpPost.setEntity(new StringEntity(new FhirContext().newJsonParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newJsonParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -180,6 +155,31 @@ public class CreateTest {
}
@Test
public void testCreateWithNoParsed() throws Exception {
Organization org = new Organization();
org.addIdentifier().setValue("001");
org.addIdentifier().setValue("002");
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Organization");
httpPost.setEntity(new StringEntity(ourCtx.newJsonParser().encodeResourceToString(org), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
assertEquals(201, status.getStatusLine().getStatusCode());
assertEquals("http://localhost:" + ourPort + "/Organization/001", status.getFirstHeader("location").getValue());
assertThat(status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue(), StringContains.containsString("UTF-8"));
assertThat(ourLastResourceBody, stringContainsInOrder("\"resourceType\":\"Organization\"", "\"identifier\"","\"value\":\"001"));
assertEquals(EncodingEnum.JSON, ourLastEncoding);
}
@Test
public void testCreateWithUnprocessableEntity() throws Exception {
@ -187,7 +187,7 @@ public class CreateTest {
report.getIdentifier().setValue("001");
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/DiagnosticReport");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(report), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(report), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -198,7 +198,7 @@ public class CreateTest {
assertEquals(422, status.getStatusLine().getStatusCode());
OperationOutcome outcome = new FhirContext().newXmlParser().parseResource(OperationOutcome.class, new StringReader(responseContent));
OperationOutcome outcome = ourCtx.newXmlParser().parseResource(OperationOutcome.class, new StringReader(responseContent));
assertEquals("FOOBAR", outcome.getIssueFirstRep().getDetails().getValue());
}
@ -218,7 +218,7 @@ public class CreateTest {
ourReportProvider = new DiagnosticReportProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(
patientProvider, ourReportProvider, new DummyAdverseReactionResourceProvider(), new CustomObservationProvider(),
new OrganizationProvider());
@ -329,6 +329,23 @@ public class CreateTest {
}
public static class OrganizationProvider implements IResourceProvider {
@Create()
public MethodOutcome create(@ResourceParam String theResourceBody, @ResourceParam EncodingEnum theEncoding) {
ourLastResourceBody=theResourceBody;
ourLastEncoding=theEncoding;
return new MethodOutcome(new IdDt("001"));
}
@Override
public Class<? extends IResource> getResourceType() {
return Organization.class;
}
}
public static class PatientProvider implements IResourceProvider {
@Create()
@ -351,21 +368,4 @@ public class CreateTest {
}
public static class OrganizationProvider implements IResourceProvider {
@Create()
public MethodOutcome create(@ResourceParam String theResourceBody, @ResourceParam EncodingEnum theEncoding) {
ourLastResourceBody=theResourceBody;
ourLastEncoding=theEncoding;
return new MethodOutcome(new IdDt("001"));
}
@Override
public Class<? extends IResource> getResourceType() {
return Organization.class;
}
}
}

View File

@ -165,7 +165,7 @@ public class CustomTypeTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
ourServlet = new RestfulServer();
ourServlet = new RestfulServer(ourCtx);
ourServlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
ourServlet.setResourceProviders(patientProvider);

View File

@ -20,6 +20,7 @@ import org.junit.Before;
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.dstu.resource.Patient;
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
@ -37,7 +38,8 @@ public class DateRangeParamSearchTest {
private static CloseableHttpClient ourClient;
private static int ourPort;
private static Server ourServer;
private static final FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testSearchForOneUnqualifiedDate() throws Exception {
String baseUrl = "http://localhost:" + ourPort + "/Patient?" + Patient.SP_BIRTHDATE + "=";
@ -85,7 +87,7 @@ public class DateRangeParamSearchTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
servlet.setResourceProviders(patientProvider);

View File

@ -44,9 +44,8 @@ public class DefaultEncodingTest {
private static CloseableHttpClient ourClient;
private static int ourPort;
private static Server ourServer;
private static FhirContext ourCtx;
private static final FhirContext ourCtx = FhirContext.forDstu1();
private static RestfulServer ourRestfulServer;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DefaultEncodingTest.class);
@Test
public void testReadWithDefaultJsonPretty() throws Exception {
@ -135,8 +134,7 @@ public class DefaultEncodingTest {
ourServer = new Server(ourPort);
ServletHandler proxyHandler = new ServletHandler();
ourRestfulServer = new RestfulServer();
ourCtx = ourRestfulServer.getFhirContext();
ourRestfulServer = new RestfulServer(ourCtx);
ourRestfulServer.setResourceProviders(new PatientProvider());
ServletHolder servletHolder = new ServletHolder(ourRestfulServer);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -1,23 +1,22 @@
package ca.uhn.fhir.rest.server;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import javax.servlet.ServletException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.Destroy;
import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.api.MethodOutcome;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
/**
* Created by Bill de Beaubien on 11/10/2014.
@ -26,70 +25,72 @@ import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
public class DestroyTest {
@Test
public void testDestroyCallsAnnotatedMethodsOnProviders() throws ServletException {
RestfulServer servlet = new RestfulServer();
DiagnosticReportProvider provider = spy(new DiagnosticReportProvider());
servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider));
servlet.init();
servlet.destroy();
verify(provider).destroy();
}
private static final FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testChainsUpThroughSuperclasses() throws ServletException {
RestfulServer servlet = new RestfulServer();
DerivedDiagnosticReportProvider provider = spy(new DerivedDiagnosticReportProvider());
servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider));
servlet.init();
servlet.destroy();
verify(provider).destroy();
}
@Test
public void testDestroyCallsAnnotatedMethodsOnProviders() throws ServletException {
RestfulServer servlet = new RestfulServer(ourCtx);
DiagnosticReportProvider provider = spy(new DiagnosticReportProvider());
servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider));
servlet.init();
servlet.destroy();
verify(provider).destroy();
}
@Test
public void testNoDestroyDoesNotCauseInfiniteRecursion() throws ServletException {
RestfulServer servlet = new RestfulServer();
DiagnosticReportProviderSansDestroy provider = new DiagnosticReportProviderSansDestroy();
servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider));
servlet.init();
servlet.destroy();
// nothing to verify other than the test didn't hang forever
}
@Test
public void testChainsUpThroughSuperclasses() throws ServletException {
RestfulServer servlet = new RestfulServer(ourCtx);
DerivedDiagnosticReportProvider provider = spy(new DerivedDiagnosticReportProvider());
servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider));
servlet.init();
servlet.destroy();
verify(provider).destroy();
}
public class DiagnosticReportProvider implements IResourceProvider {
@Test
public void testNoDestroyDoesNotCauseInfiniteRecursion() throws ServletException {
RestfulServer servlet = new RestfulServer(ourCtx);
DiagnosticReportProviderSansDestroy provider = new DiagnosticReportProviderSansDestroy();
servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider));
servlet.init();
servlet.destroy();
// nothing to verify other than the test didn't hang forever
}
@Override
public Class<? extends IResource> getResourceType() {
return DiagnosticReport.class;
}
public class DiagnosticReportProvider implements IResourceProvider {
@Create
public MethodOutcome createResource(@ResourceParam DiagnosticReport theDiagnosticReport) {
// do nothing
return new MethodOutcome();
}
@Override
public Class<? extends IResource> getResourceType() {
return DiagnosticReport.class;
}
@Destroy
public void destroy() {
// do nothing
}
}
@Create
public MethodOutcome createResource(@ResourceParam DiagnosticReport theDiagnosticReport) {
// do nothing
return new MethodOutcome();
}
public class DerivedDiagnosticReportProvider extends DiagnosticReportProvider {
// move along, nothing to see here
}
@Destroy
public void destroy() {
// do nothing
}
}
public class DiagnosticReportProviderSansDestroy implements IResourceProvider {
public class DerivedDiagnosticReportProvider extends DiagnosticReportProvider {
// move along, nothing to see here
}
@Override
public Class<? extends IResource> getResourceType() {
return DiagnosticReport.class;
}
public class DiagnosticReportProviderSansDestroy implements IResourceProvider {
@Create
public MethodOutcome createResource(@ResourceParam DiagnosticReport theDiagnosticReport) {
// do nothing
return new MethodOutcome();
}
}
@Override
public Class<? extends IResource> getResourceType() {
return DiagnosticReport.class;
}
@Create
public MethodOutcome createResource(@ResourceParam DiagnosticReport theDiagnosticReport) {
// do nothing
return new MethodOutcome();
}
}
}

View File

@ -40,7 +40,7 @@ import ca.uhn.fhir.util.PortUtil;
public class DynamicSearchTest {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DynamicSearchTest.class);
private static int ourPort;
@ -144,7 +144,7 @@ public class DynamicSearchTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
servlet.setResourceProviders(patientProvider);

View File

@ -23,6 +23,7 @@ import org.junit.Before;
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.dstu.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu.resource.Patient;
@ -52,6 +53,7 @@ public class ExceptionTest {
private static int ourPort;
private static Server ourServer;
private static RestfulServer servlet;
private static final FhirContext ourCtx = FhirContext.forDstu1();
@Before
public void before() {
@ -189,7 +191,7 @@ public class ExceptionTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
servlet = new RestfulServer();
servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -37,9 +37,65 @@ import ca.uhn.fhir.util.PortUtil;
public class HistoryTest {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx= FhirContext.forDstu1();
private static int ourPort;
private static Server ourServer;
@Test
public void testInstanceHistory() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/_history");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(2, bundle.getEntries().size());
assertEquals("http://localhost:" + ourPort +"/Patient/ih1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue());
assertEquals("http://localhost:" + ourPort +"/Patient/ih1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue());
}
}
@Test
public void testServerHistory() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/_history");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(2, bundle.getEntries().size());
assertEquals("http://localhost:" + ourPort +"/Patient/h1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue());
assertEquals("http://localhost:" + ourPort +"/Patient/h1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue());
}
}
@Test
public void testTypeHistory() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/_history");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(2, bundle.getEntries().size());
assertEquals("http://localhost:" + ourPort +"/Patient/th1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue());
assertEquals("http://localhost:" + ourPort +"/Patient/th1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue());
}
}
/**
* We test this here because of bug 3- At one point VRead would "steal" instance history calls and handle them
*/
@ -53,65 +109,11 @@ public class HistoryTest {
assertEquals(200, status.getStatusLine().getStatusCode());
Patient bundle = new FhirContext().newXmlParser().parseResource(Patient.class, responseContent);
Patient bundle = ourCtx.newXmlParser().parseResource(Patient.class, responseContent);
assertEquals("vread", bundle.getNameFirstRep().getFamilyFirstRep().getValue());
}
}
@Test
public void testServerHistory() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/_history");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
assertEquals(2, bundle.getEntries().size());
assertEquals("http://localhost:" + ourPort +"/Patient/h1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue());
assertEquals("http://localhost:" + ourPort +"/Patient/h1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue());
}
}
@Test
public void testInstanceHistory() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/_history");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
assertEquals(2, bundle.getEntries().size());
assertEquals("http://localhost:" + ourPort +"/Patient/ih1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue());
assertEquals("http://localhost:" + ourPort +"/Patient/ih1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue());
}
}
@Test
public void testTypeHistory() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/_history");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
assertEquals(2, bundle.getEntries().size());
assertEquals("http://localhost:" + ourPort +"/Patient/th1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue());
assertEquals("http://localhost:" + ourPort +"/Patient/th1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue());
}
}
@AfterClass
public static void afterClass() throws Exception {
ourServer.stop();
@ -126,7 +128,7 @@ public class HistoryTest {
DummyResourceProvider patientProvider = new DummyResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setPlainProviders(plainProvider);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
@ -141,59 +143,6 @@ public class HistoryTest {
}
public static class DummyResourceProvider implements IResourceProvider {
@Override
public Class<? extends IResource> getResourceType() {
return Patient.class;
}
@Read(version=true)
public Patient vread(@IdParam IdDt theId) {
Patient retVal = new Patient();
retVal.addName().addFamily("vread");
retVal.setId(theId);
return retVal;
}
@History
public List<Patient> instanceHistory(@IdParam IdDt theId) {
ArrayList<Patient> retVal = new ArrayList<Patient>();
Patient patient = new Patient();
patient.setId("Patient/ih1/_history/1");
patient.addName().addFamily("history");
retVal.add(patient);
Patient patient2 = new Patient();
patient2.setId("Patient/ih1/_history/2");
patient2.addName().addFamily("history");
retVal.add(patient2);
return retVal;
}
@History
public List<Patient> typeHistory() {
ArrayList<Patient> retVal = new ArrayList<Patient>();
Patient patient = new Patient();
patient.setId("Patient/th1/_history/1");
patient.addName().addFamily("history");
retVal.add(patient);
Patient patient2 = new Patient();
patient2.setId("Patient/th1/_history/2");
patient2.addName().addFamily("history");
retVal.add(patient2);
return retVal;
}
}
/**
* Created by dsotnikov on 2/25/2014.
*/
@ -219,6 +168,59 @@ public class HistoryTest {
}
public static class DummyResourceProvider implements IResourceProvider {
@Override
public Class<? extends IResource> getResourceType() {
return Patient.class;
}
@History
public List<Patient> instanceHistory(@IdParam IdDt theId) {
ArrayList<Patient> retVal = new ArrayList<Patient>();
Patient patient = new Patient();
patient.setId("Patient/ih1/_history/1");
patient.addName().addFamily("history");
retVal.add(patient);
Patient patient2 = new Patient();
patient2.setId("Patient/ih1/_history/2");
patient2.addName().addFamily("history");
retVal.add(patient2);
return retVal;
}
@History
public List<Patient> typeHistory() {
ArrayList<Patient> retVal = new ArrayList<Patient>();
Patient patient = new Patient();
patient.setId("Patient/th1/_history/1");
patient.addName().addFamily("history");
retVal.add(patient);
Patient patient2 = new Patient();
patient2.setId("Patient/th1/_history/2");
patient2.addName().addFamily("history");
retVal.add(patient2);
return retVal;
}
@Read(version=true)
public Patient vread(@IdParam IdDt theId) {
Patient retVal = new Patient();
retVal.addName().addFamily("vread");
retVal.setId(theId);
return retVal;
}
}
}

View File

@ -88,9 +88,8 @@ public class IncludeTest {
assertEquals("Hello", p.getId().getIdPart());
assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue());
}
// @Test
// @Test
public void testMixedContainedAndNonContained() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/DiagnosticReport?_query=stitchedInclude&_pretty=true");
HttpResponse status = ourClient.execute(httpGet);
@ -98,12 +97,11 @@ public class IncludeTest {
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info(responseContent);
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(4, bundle.size());
}
@Test
public void testIIncludedResourcesNonContained() throws Exception {
@ -114,23 +112,22 @@ public class IncludeTest {
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
ourLog.info(responseContent);
assertEquals(3, bundle.size());
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
Patient p1 = (Patient) bundle.toListOfResources().get(0);
assertEquals(0,p1.getContained().getContainedResources().size());
Patient p2 = (Patient) bundle.toListOfResources().get(1);
assertEquals(0,p2.getContained().getContainedResources().size());
Patient p1 = (Patient) bundle.toListOfResources().get(0);
assertEquals(0, p1.getContained().getContainedResources().size());
Patient p2 = (Patient) bundle.toListOfResources().get(1);
assertEquals(0, p2.getContained().getContainedResources().size());
}
@Test
public void testIIncludedResourcesNonContainedInExtension() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=extInclude&_pretty=true");
@ -140,24 +137,22 @@ public class IncludeTest {
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
ourLog.info(responseContent);
assertEquals(3, bundle.size());
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
Patient p1 = (Patient) bundle.toListOfResources().get(0);
assertEquals(0,p1.getContained().getContainedResources().size());
Patient p2 = (Patient) bundle.toListOfResources().get(1);
assertEquals(0,p2.getContained().getContainedResources().size());
Patient p1 = (Patient) bundle.toListOfResources().get(0);
assertEquals(0, p1.getContained().getContainedResources().size());
Patient p2 = (Patient) bundle.toListOfResources().get(1);
assertEquals(0, p2.getContained().getContainedResources().size());
}
@Test
public void testIIncludedResourcesNonContainedInExtensionJson() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=extInclude&_pretty=true&_format=json");
@ -167,21 +162,20 @@ public class IncludeTest {
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent);
ourLog.info(responseContent);
assertEquals(3, bundle.size());
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
Patient p1 = (Patient) bundle.toListOfResources().get(0);
assertEquals(0,p1.getContained().getContainedResources().size());
Patient p2 = (Patient) bundle.toListOfResources().get(1);
assertEquals(0,p2.getContained().getContainedResources().size());
Patient p1 = (Patient) bundle.toListOfResources().get(0);
assertEquals(0, p1.getContained().getContainedResources().size());
Patient p2 = (Patient) bundle.toListOfResources().get(1);
assertEquals(0, p2.getContained().getContainedResources().size());
}
@Test
@ -193,26 +187,23 @@ public class IncludeTest {
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
ourLog.info(responseContent);
assertEquals(4, bundle.size());
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
assertEquals(new IdDt("Organization/o2"), bundle.toListOfResources().get(3).getId().toUnqualifiedVersionless());
Patient p1 = (Patient) bundle.toListOfResources().get(0);
assertEquals(0,p1.getContained().getContainedResources().size());
assertEquals(0, p1.getContained().getContainedResources().size());
Patient p2 = (Patient) bundle.toListOfResources().get(1);
assertEquals(0,p2.getContained().getContainedResources().size());
assertEquals(0, p2.getContained().getContainedResources().size());
}
@Test
public void testTwoInclude() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_include=bar");
@ -229,10 +220,10 @@ public class IncludeTest {
assertEquals("Hello", p.getId().getIdPart());
Set<String> values = new HashSet<String>();
values.add( p.getName().get(0).getFamilyFirstRep().getValue());
values.add( p.getName().get(1).getFamilyFirstRep().getValue());
values.add(p.getName().get(0).getFamilyFirstRep().getValue());
values.add(p.getName().get(1).getFamilyFirstRep().getValue());
assertThat(values, containsInAnyOrder("foo", "bar"));
}
@Test
@ -242,9 +233,9 @@ public class IncludeTest {
assertEquals(400, status.getStatusLine().getStatusCode());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info(responseContent);
assertThat(responseContent,containsString("Invalid _include parameter value"));
assertThat(responseContent, containsString("Invalid _include parameter value"));
}
@AfterClass
@ -254,17 +245,16 @@ public class IncludeTest {
@BeforeClass
public static void beforeClass() throws Exception {
ourCtx = new FhirContext();
ourCtx = FhirContext.forDstu1();
ourPort = PortUtil.findFreePort();
ourServer = new Server(ourPort);
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
servlet.setFhirContext(ourCtx);
servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE);
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE);
servlet.setResourceProviders(patientProvider, new DummyDiagnosticReportResourceProvider());
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
@ -278,11 +268,10 @@ public class IncludeTest {
}
@ResourceDef(name="Patient")
public static class ExtPatient extends Patient
{
@Child(name="secondOrg")
@Extension(url="http://foo#secondOrg", definedLocally = false, isModifier = false)
@ResourceDef(name = "Patient")
public static class ExtPatient extends Patient {
@Child(name = "secondOrg")
@Extension(url = "http://foo#secondOrg", definedLocally = false, isModifier = false)
private ResourceReferenceDt mySecondOrg;
@Override
@ -291,8 +280,8 @@ public class IncludeTest {
}
public ResourceReferenceDt getSecondOrg() {
if (mySecondOrg==null) {
mySecondOrg= new ResourceReferenceDt();
if (mySecondOrg == null) {
mySecondOrg = new ResourceReferenceDt();
}
return mySecondOrg;
}
@ -300,9 +289,9 @@ public class IncludeTest {
public void setSecondOrg(ResourceReferenceDt theSecondOrg) {
mySecondOrg = theSecondOrg;
}
}
/**
* Created by dsotnikov on 2/25/2014.
*/
@ -312,7 +301,7 @@ public class IncludeTest {
public Class<? extends IResource> getResourceType() {
return DiagnosticReport.class;
}
@Search(queryName = "stitchedInclude")
public List<DiagnosticReport> stitchedInclude() {
Practitioner pr1 = new Practitioner();
@ -330,11 +319,11 @@ public class IncludeTest {
Observation o1 = new Observation();
o1.getName().setText("Obs1");
o1.addPerformer().setResource(pr1);
Observation o2 = new Observation();
o2.getName().setText("Obs2");
o2.addPerformer().setResource(pr2);
Observation o3 = new Observation();
o3.getName().setText("Obs3");
o3.addPerformer().setResource(pr3);
@ -345,15 +334,12 @@ public class IncludeTest {
rep.addResult().setResource(o1);
rep.addResult().setResource(o2);
rep.addResult().setResource(o3);
return Collections.singletonList(rep);
}
}
/**
* Created by dsotnikov on 2/25/2014.
*/
@ -377,8 +363,7 @@ public class IncludeTest {
return Arrays.asList(p1, p2);
}
@Search(queryName = "extInclude")
public List<Patient> extInclude() {
Organization o1 = new Organization();
@ -408,7 +393,7 @@ public class IncludeTest {
o2.getName().setValue("o2");
o2.setId("o2");
o1.getPartOf().setResource(o2);
ExtPatient p1 = new ExtPatient();
p1.setId("p1");
p1.addIdentifier().setLabel("p1");
@ -422,7 +407,6 @@ public class IncludeTest {
return Arrays.asList(p1, p2);
}
@Search(queryName = "containedInclude")
public List<Patient> containedInclude() {
Organization o1 = new Organization();
@ -440,11 +424,9 @@ public class IncludeTest {
return Arrays.asList(p1, p2);
}
@Search
public List<Patient> findPatientWithSimpleNames(
@RequiredParam(name = Patient.SP_NAME) StringDt theName,
@IncludeParam(allow = { "foo", "bar" }) Set<Include> theIncludes) {
public List<Patient> findPatientWithSimpleNames(@RequiredParam(name = Patient.SP_NAME) StringDt theName, @IncludeParam(allow = { "foo", "bar" }) Set<Include> theIncludes) {
ArrayList<Patient> retVal = new ArrayList<Patient>();
Patient p = new Patient();
@ -469,23 +451,21 @@ public class IncludeTest {
}
public static void main(String[] args) {
Organization org = new Organization();
org.setId("Organization/65546");
org.getName().setValue("Contained Test Organization");
Patient patient = new Patient();
patient.setId("Patient/1333");
patient.addIdentifier("urn:mrns", "253345");
patient.getManagingOrganization().setResource(patient);
System.out.println(new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient));
System.out.println(FhirContext.forDstu1().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient));
patient.getManagingOrganization().getReference();
}
}

View File

@ -27,6 +27,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.InOrder;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
@ -53,6 +54,7 @@ public class InterceptorTest {
private static RestfulServer servlet;
private IServerInterceptor myInterceptor1;
private IServerInterceptor myInterceptor2;
private static final FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testInterceptorFires() throws Exception {
@ -101,7 +103,7 @@ public class InterceptorTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
servlet = new RestfulServer();
servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -36,7 +36,7 @@ import ca.uhn.fhir.util.PortUtil;
public class MethodPriorityTest {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
private static int ourPort;
private static Server ourServer;
private static RestfulServer ourServlet;
@ -72,8 +72,7 @@ public class MethodPriorityTest {
ourServer = new Server(ourPort);
ServletHandler proxyHandler = new ServletHandler();
ourServlet = new RestfulServer();
ourServlet.setFhirContext(ourCtx);
ourServlet = new RestfulServer(ourCtx);
ourServlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
ServletHolder servletHolder = new ServletHolder(ourServlet);

View File

@ -46,6 +46,7 @@ public class PagingTest {
private static CloseableHttpClient ourClient;
private static int ourPort;
private static final FhirContext ourCtx = FhirContext.forDstu1();
private static Server ourServer;
private static FhirContext ourContext;
private static RestfulServer myRestfulServer;
@ -270,7 +271,7 @@ public class PagingTest {
@BeforeClass
public static void beforeClass() throws Exception {
ourContext = new FhirContext();
ourContext = FhirContext.forDstu1();
ourPort = PortUtil.findFreePort();
ourServer = new Server(ourPort);
@ -278,7 +279,7 @@ public class PagingTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
myRestfulServer = new RestfulServer();
myRestfulServer = new RestfulServer(ourCtx);
myRestfulServer.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(myRestfulServer);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -51,18 +51,17 @@ public class PlainProviderTest {
private int myPort;
private Server myServer;
private CloseableHttpClient myClient;
private FhirContext myCtx;
private static final FhirContext ourCtx = FhirContext.forDstu1();
private RestfulServer myRestfulServer;
@Before
public void before() throws Exception {
myPort = PortUtil.findFreePort();
myServer = new Server(myPort);
myCtx = new FhirContext(Patient.class);
ServletHandler proxyHandler = new ServletHandler();
ServletHolder servletHolder = new ServletHolder();
myRestfulServer = new RestfulServer();
myRestfulServer = new RestfulServer(ourCtx);
servletHolder.setServlet(myRestfulServer);
proxyHandler.addServletWithMapping(servletHolder, "/fhir/context/*");
myServer.setHandler(proxyHandler);
@ -95,7 +94,7 @@ public class PlainProviderTest {
ourLog.info("Response was:\n{}", responseContent);
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = myCtx.newXmlParser().parseBundle(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(1, bundle.getEntries().size());
@ -121,7 +120,7 @@ public class PlainProviderTest {
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = myCtx.newXmlParser().parseBundle(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(3, bundle.getEntries().size());
assertThat(provider.myLastSince.getValueAsString(), StringStartsWith.startsWith("2012-01-02T00:01:02"));
@ -131,7 +130,7 @@ public class PlainProviderTest {
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
bundle = myCtx.newXmlParser().parseBundle(responseContent);
bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(3, bundle.getEntries().size());
assertNull(provider.myLastSince.getValueAsString());
assertThat(provider.myLastCount.getValueAsString(), IsEqual.equalTo("12"));
@ -140,7 +139,7 @@ public class PlainProviderTest {
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
bundle = myCtx.newXmlParser().parseBundle(responseContent);
bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(3, bundle.getEntries().size());
assertThat(provider.myLastSince.getValueAsString(), StringStartsWith.startsWith("2012-01-02T00:01:02"));
assertNull(provider.myLastCount.getValueAsString());
@ -149,7 +148,7 @@ public class PlainProviderTest {
responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
bundle = myCtx.newXmlParser().parseBundle(responseContent);
bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(3, bundle.getEntries().size());
assertNull(provider.myLastSince.getValueAsString());
assertNull(provider.myLastCount.getValueAsString());

View File

@ -1,10 +1,8 @@
package ca.uhn.fhir.rest.server;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.concurrent.TimeUnit;
@ -22,8 +20,6 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.common.net.UrlEscapers;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
@ -39,13 +35,13 @@ import ca.uhn.fhir.util.PortUtil;
/**
* Created by dsotnikov on 2/25/2014.
*/
public class ReadTest {
public class ReadDstu1Test {
private static CloseableHttpClient ourClient;
private static int ourPort;
private static Server ourServer;
private static FhirContext ourCtx;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ReadTest.class);
private static final FhirContext ourCtx = FhirContext.forDstu1();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ReadDstu1Test.class);
@Test
public void testReadXml() throws Exception {
@ -68,7 +64,7 @@ public class ReadTest {
assertThat(responseContent, stringContainsInOrder("1", "\""));
assertThat(responseContent, not(stringContainsInOrder("1", "\"", "1")));
}
@Test
public void testEncodeConvertsReferencesToRelative() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_format=xml");
@ -205,8 +201,8 @@ public class ReadTest {
PatientProvider patientProvider = new PatientProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
ourCtx = servlet.getFhirContext();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider, new BinaryProvider(), new OrganizationProviderWithAbstractReturnType());
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -53,7 +53,7 @@ import ca.uhn.fhir.util.PortUtil;
public class ReferenceParameterTest {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx;
private static final FhirContext ourCtx = FhirContext.forDstu1();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ReferenceParameterTest.class);
private static int ourPort;
private static Server ourServer;
@ -298,9 +298,8 @@ public class ReferenceParameterTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE);
ourCtx = servlet.getFhirContext();
servlet.setResourceProviders(patientProvider, new DummyOrganizationResourceProvider(), new DummyLocationResourceProvider());
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
@ -311,8 +310,6 @@ public class ReferenceParameterTest {
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connectionManager);
ourClient = builder.build();
ourCtx = servlet.getFhirContext();
}
public static class DummyLocationResourceProvider implements IResourceProvider {

View File

@ -32,7 +32,7 @@ public class ResourceMethodTest {
@Before
public void before() throws NoSuchMethodException, SecurityException {
rm = new SearchMethodBinding(Patient.class, ResourceMethodTest.class.getMethod("foo"), new FhirContext(), null);
rm = new SearchMethodBinding(Patient.class, ResourceMethodTest.class.getMethod("foo"), FhirContext.forDstu1(), null);
}
@Test

View File

@ -10,6 +10,7 @@ import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.After;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.resource.Binary;
import ca.uhn.fhir.model.primitive.IdDt;
@ -20,7 +21,8 @@ import ca.uhn.fhir.util.PortUtil;
public class ResourceProviderWithNoMethodsTest {
private Server ourServer;
private static final FhirContext ourCtx = FhirContext.forDstu1();
@After
public void after() throws Exception {
ourServer.stop();
@ -34,7 +36,7 @@ public class ResourceProviderWithNoMethodsTest {
ResourceProvider patientProvider = new ResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
@ -56,7 +58,7 @@ public class ResourceProviderWithNoMethodsTest {
NonPublicMethodProvider patientProvider = new NonPublicMethodProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -91,7 +91,7 @@ import ca.uhn.fhir.util.PortUtil;
public class RestfulServerMethodTest {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx;
private static final FhirContext ourCtx = FhirContext.forDstu1();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RestfulServerMethodTest.class);
private static int ourPort;
private static DummyDiagnosticReportResourceProvider ourReportProvider;
@ -943,7 +943,7 @@ public class RestfulServerMethodTest {
assertEquals("BBB", patient.getName().get(0).getGiven().get(0).getValue());
}
@Test
public void testValidate() throws Exception {
@ -951,7 +951,7 @@ public class RestfulServerMethodTest {
patient.addName().addFamily("FOO");
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_validate");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -962,7 +962,7 @@ public class RestfulServerMethodTest {
assertThat(responseContent, not(containsString("\n ")));
assertEquals(200, status.getStatusLine().getStatusCode());
OperationOutcome oo = new FhirContext().newXmlParser().parseResource(OperationOutcome.class, responseContent);
OperationOutcome oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent);
assertEquals("it passed", oo.getIssueFirstRep().getDetails().getValue());
// Now should fail
@ -971,7 +971,7 @@ public class RestfulServerMethodTest {
patient.addName().addFamily("BAR");
httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_validate");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
status = ourClient.execute(httpPost);
@ -981,7 +981,7 @@ public class RestfulServerMethodTest {
ourLog.info("Response was:\n{}", responseContent);
assertEquals(422, status.getStatusLine().getStatusCode());
oo = new FhirContext().newXmlParser().parseResource(OperationOutcome.class, responseContent);
oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent);
assertEquals("it failed", oo.getIssueFirstRep().getDetails().getValue());
// Should fail with outcome
@ -990,7 +990,7 @@ public class RestfulServerMethodTest {
patient.addName().addFamily("BAZ");
httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_validate");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
status = ourClient.execute(httpPost);
@ -1010,7 +1010,7 @@ public class RestfulServerMethodTest {
patient.addName().addFamily("FOO");
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_validate?_pretty=true");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -1065,7 +1065,6 @@ public class RestfulServerMethodTest {
public static void beforeClass() throws Exception {
ourPort = PortUtil.findFreePort();
ourServer = new Server(ourPort);
ourCtx = new FhirContext(Patient.class);
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ourReportProvider = new DummyDiagnosticReportResourceProvider();
@ -1429,6 +1428,7 @@ public class RestfulServerMethodTest {
private Collection<IResourceProvider> myResourceProviders;
public DummyRestfulServer(IResourceProvider... theResourceProviders) {
super(ourCtx);
myResourceProviders = new ArrayList<IResourceProvider>(Arrays.asList(theResourceProviders));
}

View File

@ -62,7 +62,7 @@ public class RestfulServerSelfReferenceTest {
int port = PortUtil.findFreePort();
Server server = new Server(port);
RestfulServer restServer = new RestfulServer();
RestfulServer restServer = new RestfulServer(ourCtx);
restServer.setFhirContext(ourCtx);
restServer.setResourceProviders(new DummyPatientResourceProvider());
@ -108,7 +108,7 @@ public class RestfulServerSelfReferenceTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer server = new RestfulServer();
RestfulServer server = new RestfulServer(ourCtx);
ServerProfileProvider profProvider = new ServerProfileProvider(server);
server.setFhirContext(ourCtx);
server.setResourceProviders(patientProvider, profProvider);

View File

@ -66,11 +66,11 @@ import com.google.common.net.UrlEscapers;
/**
* Created by dsotnikov on 2/25/2014.
*/
public class SearchTest {
public class SearchSearchServerDstu1Test {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx = new FhirContext();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchTest.class);
private static FhirContext ourCtx = FhirContext.forDstu1();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchSearchServerDstu1Test.class);
private static int ourPort;
private static Server ourServer;

View File

@ -35,7 +35,7 @@ public class ServerBaseTest {
private static CloseableHttpClient ourClient;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerBaseTest.class);
private Server myServer;
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testTransaction() throws Exception {

View File

@ -41,12 +41,12 @@ import javax.servlet.http.HttpServletRequest;
public class ServerConformanceProviderTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerConformanceProviderTest.class);
private FhirContext myCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testSearchParameterDocumentation() throws Exception {
RestfulServer rs = new RestfulServer();
RestfulServer rs = new RestfulServer(ourCtx);
rs.setProviders(new SearchProvider());
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
@ -68,7 +68,7 @@ public class ServerConformanceProviderTest {
assertTrue(found);
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
String conf = myCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
ourLog.info(conf);
assertThat(conf, containsString("<documentation value=\"The patient's identifier (MRN or other card number)\"/>"));
@ -80,7 +80,7 @@ public class ServerConformanceProviderTest {
@Test
public void testValidateGeneratedStatement() throws Exception {
RestfulServer rs = new RestfulServer();
RestfulServer rs = new RestfulServer(ourCtx);
rs.setProviders(new MultiOptionalProvider());
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
@ -90,7 +90,7 @@ public class ServerConformanceProviderTest {
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
myCtx.newValidator().validate(conformance);
ourCtx.newValidator().validate(conformance);
}
@ -98,7 +98,7 @@ public class ServerConformanceProviderTest {
@Test
public void testMultiOptionalDocumentation() throws Exception {
RestfulServer rs = new RestfulServer();
RestfulServer rs = new RestfulServer(ourCtx);
rs.setProviders(new MultiOptionalProvider());
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
@ -119,7 +119,7 @@ public class ServerConformanceProviderTest {
}
assertTrue(found);
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
String conf = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
ourLog.info(conf);
assertThat(conf, containsString("<documentation value=\"The patient's identifier\"/>"));
@ -130,7 +130,7 @@ public class ServerConformanceProviderTest {
@Test
public void testProviderWithRequiredAndOptional() throws Exception {
RestfulServer rs = new RestfulServer();
RestfulServer rs = new RestfulServer(ourCtx);
rs.setProviders(new ProviderWithRequiredAndOptional());
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
@ -139,7 +139,7 @@ public class ServerConformanceProviderTest {
rs.init(createServletConfig());
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
String conf = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
ourLog.info(conf);
Rest rest = conformance.getRestFirstRep();

View File

@ -34,14 +34,17 @@ public class ServerExtraParametersTest {
private int myPort;
private Server myServer;
private RestfulServer myServlet;
private static FhirContext ourCtx = FhirContext.forDstu1();
@Before
public void before() {
myPort = PortUtil.findFreePort();
myServer = new Server(myPort);
ServletHandler proxyHandler = new ServletHandler();
myServlet = new RestfulServer();
myServlet = new RestfulServer(ourCtx);
myServlet.setFhirContext(ourCtx);
ServletHolder servletHolder = new ServletHolder(myServlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
myServer.setHandler(proxyHandler);
@ -55,7 +58,7 @@ public class ServerExtraParametersTest {
myServer.start();
FhirContext ctx = new FhirContext();
FhirContext ctx = ourCtx;
PatientClient client = ctx.newRestfulClient(PatientClient.class, "http://localhost:" + myPort + "/");
List<Patient> actualPatients = client.searchForPatients(new StringDt("AAAABBBB"));
@ -72,7 +75,7 @@ public class ServerExtraParametersTest {
myServer.start();
FhirContext ctx = new FhirContext();
FhirContext ctx = ourCtx;
IGenericClient client = ctx.newRestfulGenericClient("http://localhost:" + myPort + "/");
client.registerInterceptor(new LoggingInterceptor(true));

View File

@ -27,6 +27,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
@ -51,7 +52,8 @@ public class ServerFeaturesTest {
private static int ourPort;
private static Server ourServer;
private static RestfulServer servlet;
private static final FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testPrettyPrint() throws Exception {
/*
@ -295,7 +297,7 @@ public class ServerFeaturesTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
servlet = new RestfulServer();
servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE);
ServletHolder servletHolder = new ServletHolder(servlet);

View File

@ -11,6 +11,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.model.api.IElement;
import ca.uhn.fhir.model.api.IResource;
@ -27,20 +28,21 @@ import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.param.StringParam;
public class ServerInvalidDefinitionTest {
private static final FhirContext ourCtx = FhirContext.forDstu1();
/**
* Normal, should initialize properly
*/
@Test()
public void testBaseline() throws ServletException {
RestfulServer srv = new RestfulServer();
RestfulServer srv = new RestfulServer(ourCtx);
srv.setResourceProviders(new InstantiableTypeForResourceProvider());
srv.init();
}
@Test
public void testInvalidSpecialNameResourceProvider() {
RestfulServer srv = new RestfulServer();
RestfulServer srv = new RestfulServer(ourCtx);
srv.setResourceProviders(new InvalidSpecialParameterNameResourceProvider());
try {
@ -54,7 +56,7 @@ public class ServerInvalidDefinitionTest {
@Test
public void testMultipleResourceProviderForSameType() {
RestfulServer srv = new RestfulServer();
RestfulServer srv = new RestfulServer(ourCtx);
srv.setResourceProviders(new PatientResourceProvider1(), new PatientResourceProvider2());
try {
@ -69,7 +71,7 @@ public class ServerInvalidDefinitionTest {
@Test
public void testPrivateResourceProvider() {
RestfulServer srv = new RestfulServer();
RestfulServer srv = new RestfulServer(ourCtx);
srv.setResourceProviders(new PrivateResourceProvider());
try {
@ -83,7 +85,7 @@ public class ServerInvalidDefinitionTest {
@Test
public void testProviderWithNonResourceType() {
RestfulServer srv = new RestfulServer();
RestfulServer srv = new RestfulServer(ourCtx);
srv.setResourceProviders(new ProviderWithNonResourceType());
try {
@ -97,7 +99,7 @@ public class ServerInvalidDefinitionTest {
@Test
public void testReadMethodWithoutIdParamProvider() {
RestfulServer srv = new RestfulServer();
RestfulServer srv = new RestfulServer(ourCtx);
srv.setResourceProviders(new ReadMethodWithoutIdParamProvider());
try {
@ -110,7 +112,7 @@ public class ServerInvalidDefinitionTest {
@Test
public void testReadMethodWithSearchParameters() {
RestfulServer srv = new RestfulServer();
RestfulServer srv = new RestfulServer(ourCtx);
srv.setResourceProviders(new ReadMethodWithSearchParamProvider());
try {
@ -123,7 +125,7 @@ public class ServerInvalidDefinitionTest {
@Test
public void testSearchWithId() {
RestfulServer srv = new RestfulServer();
RestfulServer srv = new RestfulServer(ourCtx);
srv.setResourceProviders(new SearchWithIdParamProvider());
try {

View File

@ -1,5 +1,6 @@
package ca.uhn.fhir.rest.server;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.annotation.ProvidesResources;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
@ -9,9 +10,11 @@ import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
import junit.framework.TestCase;
import org.junit.Test;
import javax.servlet.ServletException;
import java.util.ArrayList;
import java.util.List;
@ -19,7 +22,9 @@ import java.util.List;
* Created by Bill de Beaubien on 11/1/2014.
*/
public class ServerProvidedResourceScannerTest extends TestCase {
@Test
private static final FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testWhenRestfulServerInitialized_annotatedResources_shouldBeAddedToContext() throws ServletException {
// Given
MyServer server = new MyServer();
@ -35,7 +40,7 @@ public class ServerProvidedResourceScannerTest extends TestCase {
@Test
public void testWhenUnannotatedServerInitialized_annotatedResources_shouldNotBeAddedToContext() throws ServletException {
// Given
RestfulServer server = new RestfulServer();
RestfulServer server = new RestfulServer(ourCtx);
// When
server.init();
@ -67,10 +72,23 @@ public class ServerProvidedResourceScannerTest extends TestCase {
@ProvidesResources(resources={CustomPatient.class,CustomObservation.class})
class MyServer extends RestfulServer {
private static final long serialVersionUID = 1L;
public MyServer() {
super(ourCtx);
}
}
class MyServerWithProvider extends RestfulServer {
@Override
private static final long serialVersionUID = 1L;
public MyServerWithProvider() {
super(ourCtx);
}
@Override
protected void initialize() throws ServletException {
List<IResourceProvider> providers = new ArrayList<IResourceProvider>();
providers.add(new MyObservationProvider());

View File

@ -36,10 +36,10 @@ import ca.uhn.fhir.util.PortUtil;
public class SortTest {
private static CloseableHttpClient ourClient;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SortTest.class);
private static int ourPort;
private static Server ourServer;
private static FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testNoSort() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello");
@ -47,7 +47,7 @@ public class SortTest {
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(1, bundle.size());
Patient p = bundle.getResources(Patient.class).get(0);
@ -63,7 +63,7 @@ public class SortTest {
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(1, bundle.size());
Patient p = bundle.getResources(Patient.class).get(0);
@ -77,7 +77,7 @@ public class SortTest {
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(1, bundle.size());
Patient p = bundle.getResources(Patient.class).get(0);
@ -91,7 +91,7 @@ public class SortTest {
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(1, bundle.size());
Patient p = bundle.getResources(Patient.class).get(0);
@ -110,7 +110,7 @@ public class SortTest {
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(1, bundle.size());
Patient p = bundle.getResources(Patient.class).get(0);
@ -136,7 +136,7 @@ public class SortTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -34,69 +34,30 @@ import ca.uhn.fhir.util.PortUtil;
public class StringParameterTest {
private static CloseableHttpClient ourClient;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(StringParameterTest.class);
private static FhirContext ourCtx = FhirContext.forDstu1();
private static int ourPort;
private static Server ourServer;
@Test
public void testSearchWithFormatAndPretty() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=aaa&_format=xml&_pretty=true");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size());
}
}
@Test
public void testSearchNormalMatch() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=aaa");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size());
}
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=AAA");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size());
}
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=BBB");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(0, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size());
}
}
@Test
public void testRawString() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?plain=aaa");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size());
assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size());
}
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?plain=BBB");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(0, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size());
assertEquals(0, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size());
}
}
@ -105,26 +66,29 @@ public class StringParameterTest {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str:exact=aaa");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size());
assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size());
}
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str:exact=AAA");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(0, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size());
assertEquals(0, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size());
}
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str:exact=BBB");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(0, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size());
assertEquals(0, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size());
}
}
@ -133,14 +97,60 @@ public class StringParameterTest {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?ccc:exact=aaa");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size());
assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size());
}
}
@Test
public void testSearchNormalMatch() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=aaa");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size());
}
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=AAA");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size());
}
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=BBB");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(0, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size());
}
}
@Test
public void testSearchWithFormatAndPretty() throws Exception {
{
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=aaa&_format=xml&_pretty=true");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size());
}
}
@AfterClass
public static void afterClass() throws Exception {
ourServer.stop();
@ -154,7 +164,8 @@ public class StringParameterTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setFhirContext(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
@ -173,6 +184,19 @@ public class StringParameterTest {
*/
public static class DummyPatientResourceProvider implements IResourceProvider {
@Search
public List<Patient> findPatientByString(@RequiredParam(name = "plain") String theParam) {
ArrayList<Patient> retVal = new ArrayList<Patient>();
if (theParam.toLowerCase().equals("aaa")) {
Patient patient = new Patient();
patient.setId("1");
retVal.add(patient);
}
return retVal;
}
@Search
public List<Patient> findPatientByStringParam(@RequiredParam(name = "str") StringParam theParam) {
ArrayList<Patient> retVal = new ArrayList<Patient>();
@ -191,19 +215,6 @@ public class StringParameterTest {
return retVal;
}
@Search
public List<Patient> findPatientByString(@RequiredParam(name = "plain") String theParam) {
ArrayList<Patient> retVal = new ArrayList<Patient>();
if (theParam.toLowerCase().equals("aaa")) {
Patient patient = new Patient();
patient.setId("1");
retVal.add(patient);
}
return retVal;
}
@Search
public List<Patient> findPatientWithOptional(@OptionalParam(name = "ccc") StringParam theParam) {
ArrayList<Patient> retVal = new ArrayList<Patient>();
@ -222,7 +233,6 @@ public class StringParameterTest {
return retVal;
}
@Override
public Class<? extends IResource> getResourceType() {
return Patient.class;

View File

@ -240,7 +240,7 @@ public class TagsServerTest {
ourProvider = new DummyProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setPlainProviders(ourProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -40,7 +40,7 @@ import ca.uhn.fhir.util.PortUtil;
public class TransactionTest {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
private static boolean ourDropFirstResource;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TransactionTest.class);
private static int ourPort;
@ -88,7 +88,7 @@ public class TransactionTest {
ourLog.info(responseContent);
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(3, bundle.size());
BundleEntry entry0 = bundle.getEntries().get(0);
@ -144,7 +144,7 @@ public class TransactionTest {
ourLog.info(responseContent);
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(2, bundle.size());
BundleEntry entry1 = bundle.getEntries().get(0);
@ -195,7 +195,7 @@ public class TransactionTest {
ourLog.info(responseContent);
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(4, bundle.size());
assertEquals(OperationOutcome.class, bundle.getEntries().get(0).getResource().getClass());
@ -228,7 +228,7 @@ public class TransactionTest {
ourServer = new Server(ourPort);
DummyProvider patientProvider = new DummyProvider();
RestfulServer server = new RestfulServer();
RestfulServer server = new RestfulServer(ourCtx);
server.setProviders(patientProvider);
org.eclipse.jetty.servlet.ServletContextHandler proxyHandler = new org.eclipse.jetty.servlet.ServletContextHandler();

View File

@ -40,7 +40,7 @@ import ca.uhn.fhir.util.PortUtil;
public class TransactionWithBundleParamTest {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TransactionWithBundleParamTest.class);
private static int ourPort;
private static boolean ourReturnOperationOutcome;
@ -144,7 +144,7 @@ public class TransactionWithBundleParamTest {
ourLog.info(responseContent);
Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(4, bundle.size());
assertEquals(OperationOutcome.class, bundle.getEntries().get(0).getResource().getClass());
@ -177,7 +177,7 @@ public class TransactionWithBundleParamTest {
ourServer = new Server(ourPort);
DummyProvider patientProvider = new DummyProvider();
RestfulServer server = new RestfulServer();
RestfulServer server = new RestfulServer(ourCtx);
server.setProviders(patientProvider);
org.eclipse.jetty.servlet.ServletContextHandler proxyHandler = new org.eclipse.jetty.servlet.ServletContextHandler();

View File

@ -47,6 +47,7 @@ public class UpdateTest {
private static int ourPort;
private static DiagnosticReportProvider ourReportProvider;
private static Server ourServer;
private static FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testUpdate() throws Exception {
@ -55,7 +56,7 @@ public class UpdateTest {
patient.addIdentifier().setValue("002");
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Patient/001");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -64,7 +65,7 @@ public class UpdateTest {
ourLog.info("Response was:\n{}", responseContent);
OperationOutcome oo = new FhirContext().newXmlParser().parseResource(OperationOutcome.class, responseContent);
OperationOutcome oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent);
assertEquals("OODETAILS", oo.getIssueFirstRep().getDetails().getValue());
assertEquals(200, status.getStatusLine().getStatusCode());
@ -81,7 +82,7 @@ public class UpdateTest {
patient.addIdentifier().setValue("002");
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Patient/001CREATE");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -90,7 +91,7 @@ public class UpdateTest {
ourLog.info("Response was:\n{}", responseContent);
OperationOutcome oo = new FhirContext().newXmlParser().parseResource(OperationOutcome.class, responseContent);
OperationOutcome oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent);
assertEquals("OODETAILS", oo.getIssueFirstRep().getDetails().getValue());
assertEquals(201, status.getStatusLine().getStatusCode());
@ -105,7 +106,7 @@ public class UpdateTest {
patient.addIdentifier().setValue("002");
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/AAAAAA");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -125,7 +126,7 @@ public class UpdateTest {
dr.addCodedDiagnosis().addCoding().setCode("AAA");
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -143,7 +144,7 @@ public class UpdateTest {
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
httpPost.addHeader("Category", "Dog; scheme=\"urn:animals\", Cat; scheme=\"urn:animals\"");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
CloseableHttpResponse status = ourClient.execute(httpPost);
IOUtils.closeQuietly(status.getEntity().getContent());
@ -153,7 +154,7 @@ public class UpdateTest {
httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
httpPost.addHeader("Category", "Dog; label=\"aa\"; scheme=\"urn:animals\", Cat; label=\"bb\"; scheme=\"urn:animals\"");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
status = ourClient.execute(httpPost);
IOUtils.closeQuietly(status.getEntity().getContent());
@ -171,7 +172,7 @@ public class UpdateTest {
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
httpPost.addHeader("Category", "Dog; scheme=\"animals\"");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
CloseableHttpResponse status = ourClient.execute(httpPost);
IOUtils.closeQuietly(status.getEntity().getContent());
@ -188,7 +189,7 @@ public class UpdateTest {
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
CloseableHttpResponse status = ourClient.execute(httpPost);
IOUtils.closeQuietly(status.getEntity().getContent());
@ -197,7 +198,7 @@ public class UpdateTest {
httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\";");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
ourClient.execute(httpPost);
IOUtils.closeQuietly(status.getEntity().getContent());
@ -214,7 +215,7 @@ public class UpdateTest {
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"; label=\"aaaa\"");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
CloseableHttpResponse status = ourClient.execute(httpPost);
assertEquals(1, ourReportProvider.getLastTags().size());
assertEquals(new Tag("http://foo", "Dog", "aaaa"), ourReportProvider.getLastTags().get(0));
@ -222,7 +223,7 @@ public class UpdateTest {
httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"; label=\"aaaa\"; ");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
status=ourClient.execute(httpPost);
IOUtils.closeQuietly(status.getEntity().getContent());
@ -239,7 +240,7 @@ public class UpdateTest {
HttpPut httpPut = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
httpPut.addHeader("Content-Location", "/DiagnosticReport/001/_history/004");
httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPut.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPut);
IOUtils.closeQuietly(status.getEntity().getContent());
@ -261,7 +262,7 @@ public class UpdateTest {
HttpPut httpPut = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
httpPut.addHeader("Content-Location", "/Patient/001/_history/002");
httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPut.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
CloseableHttpResponse status = ourClient.execute(httpPut);
String responseContent = IOUtils.toString(status.getEntity().getContent());
@ -282,7 +283,7 @@ public class UpdateTest {
patient.addIdentifier().setValue("002");
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
ourClient.execute(httpPost);
fail();
@ -295,7 +296,7 @@ public class UpdateTest {
patient.addIdentifier().setValue("002");
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Organization/001");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
CloseableHttpResponse status = ourClient.execute(httpPost);
IOUtils.closeQuietly(status.getEntity().getContent());
@ -320,7 +321,7 @@ public class UpdateTest {
ourReportProvider = new DiagnosticReportProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider, ourReportProvider, new ObservationProvider(), new OrganizationResourceProvider());
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
@ -386,7 +387,6 @@ public class UpdateTest {
return Observation.class;
}
@SuppressWarnings("unused")
@Update()
public MethodOutcome updateDiagnosticReportWithVersion(@IdParam IdDt theId, @ResourceParam DiagnosticOrder thePatient) {
/*

View File

@ -39,8 +39,8 @@ public class ValidateDstu1Test {
private static CloseableHttpClient ourClient;
private static EncodingEnum ourLastEncoding;
private static String ourLastResourceBody;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidateDstu1Test.class);
private static int ourPort;
private static FhirContext ourCtx = FhirContext.forDstu1();
private static Server ourServer;
@Before()
@ -57,7 +57,7 @@ public class ValidateDstu1Test {
patient.addIdentifier().setValue("002");
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_validate");
httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -76,7 +76,7 @@ public class ValidateDstu1Test {
org.addIdentifier().setValue("002");
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Organization/_validate");
httpPost.setEntity(new StringEntity(new FhirContext().newJsonParser().encodeResourceToString(org), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8")));
httpPost.setEntity(new StringEntity(ourCtx.newJsonParser().encodeResourceToString(org), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost);
assertEquals(204, status.getStatusLine().getStatusCode());
@ -99,7 +99,7 @@ public class ValidateDstu1Test {
PatientProvider patientProvider = new PatientProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider, new OrganizationProvider());
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -29,6 +29,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
import ca.uhn.fhir.model.base.resource.BaseSecurityEvent;
@ -64,6 +65,7 @@ public class AuditingInterceptorTest {
private static Server ourServer;
private static RestfulServer servlet;
private IServerInterceptor myInterceptor;
private static final FhirContext ourCtx = FhirContext.forDstu1();
private class MockDataStore implements IAuditDataStore {
@ -190,7 +192,7 @@ public class AuditingInterceptorTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
servlet = new RestfulServer();
servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -24,6 +24,7 @@ import org.junit.Before;
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.dstu.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu.resource.Patient;
@ -52,6 +53,7 @@ public class ExceptionHandlingInterceptorTest {
private static Server ourServer;
private static RestfulServer servlet;
private static ExceptionHandlingInterceptor myInterceptor;
private static final FhirContext ourCtx = FhirContext.forDstu1();
@Before
public void before() {
@ -109,7 +111,7 @@ public class ExceptionHandlingInterceptorTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
servlet = new RestfulServer();
servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -27,6 +27,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.method.RequestDetails;
@ -43,7 +44,8 @@ public class ExceptionInterceptorMethodTest {
private static RestfulServer servlet;
private IServerInterceptor myInterceptor;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExceptionInterceptorMethodTest.class);
private static final FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testThrowUnprocessableEntityException() throws Exception {
@ -112,7 +114,7 @@ public class ExceptionInterceptorMethodTest {
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
servlet = new RestfulServer();
servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");

View File

@ -17,7 +17,7 @@ import ca.uhn.fhir.model.primitive.StringDt;
public class FhirTerserTest {
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testGetAllPopulatedChildElementsOfType() {
@ -29,7 +29,7 @@ public class FhirTerserTest {
p.addAddress().addLine("Line2");
p.addName().addFamily("Line3");
FhirTerser t = new FhirContext().newTerser();
FhirTerser t = ourCtx.newTerser();
List<StringDt> strings = t.getAllPopulatedChildElementsOfType(p, StringDt.class);
assertEquals(3, strings.size());
@ -43,7 +43,7 @@ public class FhirTerserTest {
Observation obs = new Observation();
obs.setValue(new QuantityDt(123L));
FhirTerser t = new FhirContext().newTerser();
FhirTerser t = ourCtx.newTerser();
// As string
{

View File

@ -26,7 +26,7 @@ import static org.junit.Assert.fail;
public class ResourceValidatorTest {
private static FhirContext ourCtx = new FhirContext();
private static FhirContext ourCtx = FhirContext.forDstu1();
private static Locale ourDefaultLocale;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceValidatorTest.class);

View File

@ -13,7 +13,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class ValidationResultTest {
public class ValidationResultDstu1Test {
@Test
public void isSuccessful_IsTrueForNullOperationOutcome() {

View File

@ -8,12 +8,12 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.validation.FhirValidator;
public class ValidatorInstantiatorTest {
private static FhirContext ourCtx = FhirContext.forDstu1();
@Test
public void testValidator() {
FhirContext ctx = new FhirContext();
FhirValidator val = ctx.newValidator();
FhirValidator val = ourCtx.newValidator();
// We have a full classpath, so take advantage
assertTrue(val.isValidateAgainstStandardSchema());

View File

@ -23,8 +23,8 @@
</logger>
-->
<root level="debug">
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
</configuration>

View File

@ -9,7 +9,7 @@
# Format is file:/path/foo.html or classpath:/com/classpath/foo.html
#
practitioner.class=ca.uhn.fhir.model.dstu.resource.Practitioner
practitioner.narrative=file:src/test/resources/narrative/Practitioner.html
practitioner.narrative=classpath:narrative/Practitioner.html
# You may also override/define behaviour for datatypes
humanname.class=ca.uhn.fhir.model.dstu.composite.HumanNameDt

Some files were not shown because too many files have changed in this diff Show More