From 564746a9a84c73e538b84a7bfe07f516287ecc2d Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Tue, 7 Jul 2015 09:10:26 -0400 Subject: [PATCH] Split databases for test server into one for each FHIR version --- .../ca/uhn/fhirtest/TestRestfulServer.java | 27 ++++---- ...api-fhir-server-database-config-dstu1.xml} | 29 ++------- ...hapi-fhir-server-database-config-dstu2.xml | 64 +++++++++++++++++++ .../WEB-INF/hapi-fhir-server-config.xml | 28 ++++++-- .../src/main/webapp/WEB-INF/web.xml | 7 +- .../java/ca/uhn/fhirtest/UhnFhirTestApp.java | 3 +- 6 files changed, 111 insertions(+), 47 deletions(-) rename hapi-fhir-jpaserver-uhnfhirtest/src/main/{webapp/WEB-INF/hapi-fhir-server-database-config.xml => resources/hapi-fhir-server-database-config-dstu1.xml} (86%) create mode 100644 hapi-fhir-jpaserver-uhnfhirtest/src/main/resources/hapi-fhir-server-database-config-dstu2.xml diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java index 6759d9856aa..cdfbc3b3f07 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java @@ -8,8 +8,9 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; -import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.web.context.ContextLoaderListener; +import org.springframework.web.context.WebApplicationContext; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.dao.IFhirSystemDao; @@ -33,7 +34,7 @@ public class TestRestfulServer extends RestfulServer { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TestRestfulServer.class); - private ApplicationContext myAppCtx; + private ClassPathXmlApplicationContext myAppCtx; @SuppressWarnings("unchecked") @Override @@ -41,7 +42,7 @@ public class TestRestfulServer extends RestfulServer { super.initialize(); // Get the spring context from the web container (it's declared in web.xml) - myAppCtx = ContextLoaderListener.getCurrentWebApplicationContext(); + WebApplicationContext parentAppCtx = ContextLoaderListener.getCurrentWebApplicationContext(); // These two parmeters are also declared in web.xml String implDesc = getInitParameter("ImplementationDescription"); @@ -56,23 +57,15 @@ public class TestRestfulServer extends RestfulServer { List beans; JpaSystemProviderDstu1 systemProviderDstu1 = null; JpaSystemProviderDstu2 systemProviderDstu2 = null; + @SuppressWarnings("rawtypes") IFhirSystemDao systemDao; ETagSupportEnum etagSupport; String baseUrlProperty; switch (fhirVersionParam.trim().toUpperCase()) { - case "BASE": { - setFhirContext(FhirContext.forDstu1()); - beans = myAppCtx.getBean("myResourceProvidersDstu1", List.class); - systemProviderDstu1 = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class); - systemDao = myAppCtx.getBean("mySystemDaoDstu1", IFhirSystemDao.class); - etagSupport = ETagSupportEnum.DISABLED; - JpaConformanceProviderDstu1 confProvider = new JpaConformanceProviderDstu1(this, systemDao); - confProvider.setImplementationDescription(implDesc); - setServerConformanceProvider(confProvider); - baseUrlProperty = "fhir.baseurl"; - break; - } case "DSTU1": { + myAppCtx = new ClassPathXmlApplicationContext(new String[] { + "hapi-fhir-server-database-config-dstu1.xml", + "hapi-fhir-server-resourceproviders-dstu1.xml"}, parentAppCtx); setFhirContext(FhirContext.forDstu1()); beans = myAppCtx.getBean("myResourceProvidersDstu1", List.class); systemProviderDstu1 = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class); @@ -85,6 +78,10 @@ public class TestRestfulServer extends RestfulServer { break; } case "DSTU2": { + myAppCtx = new ClassPathXmlApplicationContext(new String[] { + "hapi-fhir-server-database-config-dstu2.xml", + "hapi-fhir-server-resourceproviders-dstu2.xml", + }, parentAppCtx); setFhirContext(FhirContext.forDstu2()); beans = myAppCtx.getBean("myResourceProvidersDstu2", List.class); systemProviderDstu2 = myAppCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class); diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-database-config.xml b/hapi-fhir-jpaserver-uhnfhirtest/src/main/resources/hapi-fhir-server-database-config-dstu1.xml similarity index 86% rename from hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-database-config.xml rename to hapi-fhir-jpaserver-uhnfhirtest/src/main/resources/hapi-fhir-server-database-config-dstu1.xml index 36e9c165396..40f2e402ccb 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-database-config.xml +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/resources/hapi-fhir-server-database-config-dstu1.xml @@ -9,28 +9,8 @@ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> - - - - - - - + + @@ -71,4 +51,9 @@ + + + + + diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/resources/hapi-fhir-server-database-config-dstu2.xml b/hapi-fhir-jpaserver-uhnfhirtest/src/main/resources/hapi-fhir-server-database-config-dstu2.xml new file mode 100644 index 00000000000..25c9237cc35 --- /dev/null +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/resources/hapi-fhir-server-database-config-dstu2.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml index ee0c94799e4..de236aebcff 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml @@ -16,15 +16,33 @@ - - - - - + + + + + + + + fhirServletDstu1 @@ -76,7 +75,7 @@ - fhirServletBase + fhirServletDstu1 /base/* diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/test/java/ca/uhn/fhirtest/UhnFhirTestApp.java b/hapi-fhir-jpaserver-uhnfhirtest/src/test/java/ca/uhn/fhirtest/UhnFhirTestApp.java index f409dd0bd92..af8903896c1 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/test/java/ca/uhn/fhirtest/UhnFhirTestApp.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/test/java/ca/uhn/fhirtest/UhnFhirTestApp.java @@ -28,6 +28,7 @@ public class UhnFhirTestApp { // new File("target/testdb").mkdirs(); System.setProperty("fhir.db.location", "./target/testdb"); + System.setProperty("fhir.db.location.dstu2", "./target/testdb_dstu2"); System.setProperty("fhir.baseurl", base); Server server = new Server(myPort); @@ -67,7 +68,7 @@ public class UhnFhirTestApp { ResourceMetadataKeyEnum.TAG_LIST.put(p1, list); client.create(p1); - List resources = ctx.newJsonParser().parseBundle(IOUtils.toString(UhnFhirTestApp.class.getResourceAsStream("/test-server-seed-bundle.json"))).toListOfResources(); + List resources = ctx.newJsonParser().parseBundle(IOUtils.toString(UhnFhirTestApp.class.getResourceAsStream("/bundle.json"))).toListOfResources(); client.transaction().withResources(resources).execute(); // for (int i = 0; i < 1000; i++) {