rewrote unit tests
This commit is contained in:
@@ -7,13 +7,13 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
|
||||
@ServletComponentScan(basePackageClasses = {JpaRestfulServer.class})
|
||||
@SpringBootApplication(exclude = ElasticsearchRestClientAutoConfiguration.class)
|
||||
public class Application {
|
||||
public class Demo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.setProperty("spring.profiles.active", "r4");
|
||||
System.setProperty("spring.batch.job.enabled", "false");
|
||||
SpringApplication.run(Application.class, args);
|
||||
SpringApplication.run(Demo.class, args);
|
||||
|
||||
//Server is now accessible at eg. http://localhost:8080/metadata
|
||||
}
|
||||
@@ -5,80 +5,54 @@ import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
||||
import ca.uhn.fhir.test.utilities.JettyUtil;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class, properties =
|
||||
{
|
||||
"spring.batch.job.enabled=false",
|
||||
"spring.profiles.active=dstu2",
|
||||
"spring.datasource.url=jdbc:h2:mem:dbr2"
|
||||
})
|
||||
public class ExampleServerDstu2IT {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerDstu2IT.class);
|
||||
private static IGenericClient ourClient;
|
||||
private static FhirContext ourCtx;
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private IGenericClient ourClient;
|
||||
private FhirContext ourCtx;
|
||||
|
||||
static {
|
||||
ourCtx = FhirContext.forDstu2();
|
||||
System.setProperty("spring.profiles.active", "dstu2");
|
||||
System.setProperty("spring.batch.job.enabled", "false");
|
||||
System.setProperty("spring.datasource.url", "jdbc:h2:mem:dbr2");
|
||||
}
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Test
|
||||
void testCreateAndRead() {
|
||||
|
||||
@Test
|
||||
public void testCreateAndRead() {
|
||||
ourLog.info("Base URL is: " + HapiProperties.getServerAddress());
|
||||
String methodName = "testCreateResourceConditional";
|
||||
|
||||
Patient pt = new Patient();
|
||||
pt.addName().addFamily(methodName);
|
||||
IIdType id = ourClient.create().resource(pt).execute().getId();
|
||||
|
||||
Patient pt2 = ourClient.read().resource(Patient.class).withId(id).execute();
|
||||
assertEquals(methodName, pt2.getName().get(0).getFamily().get(0).getValue());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void afterClass() throws Exception {
|
||||
ourServer.stop();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
public static void beforeClass() throws Exception {
|
||||
String path = Paths.get("").toAbsolutePath().toString();
|
||||
|
||||
ourLog.info("Project base path is: {}", path);
|
||||
|
||||
ourServer = new Server(0);
|
||||
|
||||
WebAppContext webAppContext = new WebAppContext();
|
||||
webAppContext.setContextPath("/hapi-fhir-jpaserver");
|
||||
|
||||
|
||||
webAppContext.setResourceBase(path + "/target/hapi-fhir-jpaserver-starter");
|
||||
webAppContext.setParentLoaderPriority(true);
|
||||
|
||||
ourServer.setHandler(webAppContext);
|
||||
ourServer.start();
|
||||
|
||||
ourPort = JettyUtil.getPortForStartedServer(ourServer);
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
|
||||
ourCtx = FhirContext.forDstu2();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = "http://localhost:" + ourPort + "/hapi-fhir-jpaserver/fhir/";
|
||||
String ourServerBase = "http://localhost:" + port + "/hapi-fhir-jpaserver/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
|
||||
public static void main(String[] theArgs) throws Exception {
|
||||
ourPort = 8080;
|
||||
beforeClass();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
||||
import ca.uhn.fhir.test.utilities.JettyUtil;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
@@ -18,39 +15,44 @@ import org.hl7.fhir.dstu3.model.Observation;
|
||||
import org.hl7.fhir.dstu3.model.Patient;
|
||||
import org.hl7.fhir.dstu3.model.Subscription;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static ca.uhn.fhir.util.TestUtil.waitForSize;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class, properties =
|
||||
{
|
||||
"spring.batch.job.enabled=false",
|
||||
"spring.profiles.active=dstu3",
|
||||
"spring.datasource.url=jdbc:h2:mem:dbr3",
|
||||
"hapi.fhir.subscription.websocket_enabled=true",
|
||||
"hapi.fhir.allow_external_references=true",
|
||||
"hapi.fhir.allow_placeholder_references=true",
|
||||
})
|
||||
|
||||
|
||||
public class ExampleServerDstu3IT {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerDstu3IT.class);
|
||||
private static IGenericClient ourClient;
|
||||
private static FhirContext ourCtx;
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerDstu2IT.class);
|
||||
private IGenericClient ourClient;
|
||||
private FhirContext ourCtx;
|
||||
|
||||
static {
|
||||
HapiProperties.forceReload();
|
||||
HapiProperties.setProperty(HapiProperties.FHIR_VERSION, "DSTU3");
|
||||
HapiProperties.setProperty(HapiProperties.DATASOURCE_URL, "jdbc:h2:mem:dbr3");
|
||||
HapiProperties.setProperty(HapiProperties.SUBSCRIPTION_WEBSOCKET_ENABLED, "true");
|
||||
HapiProperties.setProperty(HapiProperties.ALLOW_EXTERNAL_REFERENCES, "true");
|
||||
HapiProperties.setProperty(HapiProperties.ALLOW_PLACEHOLDER_REFERENCES, "true");
|
||||
ourCtx = FhirContext.forDstu3();
|
||||
}
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Test
|
||||
public void testCreateAndRead() {
|
||||
ourLog.info("Base URL is: " + HapiProperties.getServerAddress());
|
||||
|
||||
String methodName = "testCreateResourceConditional";
|
||||
|
||||
Patient pt = new Patient();
|
||||
@@ -90,7 +92,7 @@ public class ExampleServerDstu3IT {
|
||||
SocketImplementation mySocketImplementation = new SocketImplementation(mySubscriptionId.getIdPart(), EncodingEnum.JSON);
|
||||
|
||||
myWebSocketClient.start();
|
||||
URI echoUri = new URI("ws://localhost:" + ourPort + "/hapi-fhir-jpaserver/websocket");
|
||||
URI echoUri = new URI("ws://localhost:" + port + "/hapi-fhir-jpaserver/websocket");
|
||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
ourLog.info("Connecting to : {}", echoUri);
|
||||
Future<Session> connection = myWebSocketClient.connect(mySocketImplementation, echoUri, request);
|
||||
@@ -119,39 +121,15 @@ public class ExampleServerDstu3IT {
|
||||
ourClient.delete().resourceById(mySubscriptionId).execute();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void afterClass() throws Exception {
|
||||
ourServer.stop();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
public static void beforeClass() throws Exception {
|
||||
String path = Paths.get("").toAbsolutePath().toString();
|
||||
|
||||
ourLog.info("Project base path is: {}", path);
|
||||
|
||||
ourServer = new Server(0);
|
||||
|
||||
WebAppContext webAppContext = new WebAppContext();
|
||||
webAppContext.setContextPath("/hapi-fhir-jpaserver");
|
||||
webAppContext.setDescriptor(path + "/src/main/webapp/WEB-INF/web.xml");
|
||||
webAppContext.setResourceBase(path + "/target/hapi-fhir-jpaserver-starter");
|
||||
webAppContext.setParentLoaderPriority(true);
|
||||
|
||||
ourServer.setHandler(webAppContext);
|
||||
ourServer.start();
|
||||
|
||||
ourPort = JettyUtil.getPortForStartedServer(ourServer);
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
|
||||
ourCtx = FhirContext.forDstu3();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = "http://localhost:" + ourPort + "/hapi-fhir-jpaserver/fhir/";
|
||||
String ourServerBase = "http://localhost:" + port + "/hapi-fhir-jpaserver/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
|
||||
public static void main(String[] theArgs) throws Exception {
|
||||
ourPort = 8080;
|
||||
beforeClass();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,26 +7,20 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
||||
import ca.uhn.fhir.test.utilities.JettyUtil;
|
||||
import ca.uhn.fhir.util.BundleUtil;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.Observation;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.hl7.fhir.r4.model.Person;
|
||||
import org.hl7.fhir.r4.model.Reference;
|
||||
import org.hl7.fhir.r4.model.Subscription;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -38,26 +32,28 @@ import static org.awaitility.Awaitility.await;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class, properties =
|
||||
{
|
||||
"spring.batch.job.enabled=false",
|
||||
"spring.profiles.active=r5",
|
||||
"spring.datasource.url=jdbc:h2:mem:dbr5",
|
||||
"hapi.fhir.subscription.websocket_enabled=true",
|
||||
"hapi.fhir.empi_enabled=true"
|
||||
})
|
||||
public class ExampleServerR4IT {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerR4IT.class);
|
||||
private static IGenericClient ourClient;
|
||||
private static FhirContext ourCtx;
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerDstu2IT.class);
|
||||
private IGenericClient ourClient;
|
||||
private FhirContext ourCtx;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
static {
|
||||
HapiProperties.forceReload();
|
||||
HapiProperties.setProperty(HapiProperties.DATASOURCE_URL, "jdbc:h2:mem:dbr4");
|
||||
HapiProperties.setProperty(HapiProperties.FHIR_VERSION, "R4");
|
||||
HapiProperties.setProperty(HapiProperties.SUBSCRIPTION_WEBSOCKET_ENABLED, "true");
|
||||
HapiProperties.setProperty(HapiProperties.EMPI_ENABLED, "true");
|
||||
ourCtx = FhirContext.forR4();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndRead() {
|
||||
ourLog.info("Base URL is: " + HapiProperties.getServerAddress());
|
||||
void testCreateAndRead() {
|
||||
|
||||
String methodName = "testCreateResourceConditional";
|
||||
|
||||
Patient pt = new Patient();
|
||||
@@ -121,7 +117,7 @@ public class ExampleServerR4IT {
|
||||
SocketImplementation mySocketImplementation = new SocketImplementation(mySubscriptionId.getIdPart(), EncodingEnum.JSON);
|
||||
|
||||
myWebSocketClient.start();
|
||||
URI echoUri = new URI("ws://localhost:" + ourPort + "/hapi-fhir-jpaserver/websocket");
|
||||
URI echoUri = new URI("ws://localhost:" + port + "/hapi-fhir-jpaserver/websocket");
|
||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
ourLog.info("Connecting to : {}", echoUri);
|
||||
Future<Session> connection = myWebSocketClient.connect(mySocketImplementation, echoUri, request);
|
||||
@@ -154,42 +150,16 @@ public class ExampleServerR4IT {
|
||||
return ourClient.search().forResource(Subscription.class).where(Subscription.STATUS.exactly().code("active")).cacheControl(new CacheControlDirective().setNoCache(true)).returnBundle(Bundle.class).execute().getEntry().size();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void afterClass() throws Exception {
|
||||
ourServer.stop();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
public static void beforeClass() throws Exception {
|
||||
String path = Paths.get("").toAbsolutePath().toString();
|
||||
|
||||
ourLog.info("Project base path is: {}", path);
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
|
||||
ourServer = new Server(0);
|
||||
|
||||
WebAppContext webAppContext = new WebAppContext();
|
||||
webAppContext.setContextPath("/hapi-fhir-jpaserver");
|
||||
webAppContext.setDisplayName("HAPI FHIR");
|
||||
webAppContext.setDescriptor(path + "/src/main/webapp/WEB-INF/web.xml");
|
||||
webAppContext.setResourceBase(path + "/target/hapi-fhir-jpaserver-starter");
|
||||
webAppContext.setParentLoaderPriority(true);
|
||||
|
||||
ourServer.setHandler(webAppContext);
|
||||
ourServer.start();
|
||||
|
||||
ourPort = JettyUtil.getPortForStartedServer(ourServer);
|
||||
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = HapiProperties.getServerAddress();
|
||||
ourServerBase = "http://localhost:" + ourPort + "/hapi-fhir-jpaserver/fhir/";
|
||||
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
|
||||
public static void main(String[] theArgs) throws Exception {
|
||||
ourPort = 8080;
|
||||
beforeClass();
|
||||
}
|
||||
ourCtx = FhirContext.forR4();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = "http://localhost:" + port + "/hapi-fhir-jpaserver/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,12 @@ import org.hl7.fhir.r5.model.Subscription;
|
||||
import org.hl7.fhir.r5.model.SubscriptionTopic;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
@@ -33,25 +38,27 @@ import static ca.uhn.fhir.util.TestUtil.waitForSize;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class, properties =
|
||||
{
|
||||
"spring.batch.job.enabled=false",
|
||||
"spring.profiles.active=r5",
|
||||
"spring.datasource.url=jdbc:h2:mem:dbr5",
|
||||
"hapi.fhir.subscription.websocket_enabled=true"
|
||||
})
|
||||
public class ExampleServerR5IT {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerR5IT.class);
|
||||
private static IGenericClient ourClient;
|
||||
private static FhirContext ourCtx;
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerDstu2IT.class);
|
||||
private IGenericClient ourClient;
|
||||
private FhirContext ourCtx;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
static {
|
||||
HapiProperties.forceReload();
|
||||
HapiProperties.setProperty(HapiProperties.DATASOURCE_URL, "jdbc:h2:mem:dbr5");
|
||||
HapiProperties.setProperty(HapiProperties.FHIR_VERSION, "R5");
|
||||
HapiProperties.setProperty(HapiProperties.SUBSCRIPTION_WEBSOCKET_ENABLED, "true");
|
||||
ourCtx = FhirContext.forR5();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndRead() {
|
||||
ourLog.info("Base URL is: " + HapiProperties.getServerAddress());
|
||||
|
||||
String methodName = "testCreateResourceConditional";
|
||||
|
||||
Patient pt = new Patient();
|
||||
@@ -97,7 +104,7 @@ public class ExampleServerR5IT {
|
||||
SocketImplementation mySocketImplementation = new SocketImplementation(mySubscriptionId.getIdPart(), EncodingEnum.JSON);
|
||||
|
||||
myWebSocketClient.start();
|
||||
URI echoUri = new URI("ws://localhost:" + ourPort + "/hapi-fhir-jpaserver/websocket");
|
||||
URI echoUri = new URI("ws://localhost:" + port + "/hapi-fhir-jpaserver/websocket");
|
||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
ourLog.info("Connecting to : {}", echoUri);
|
||||
Future<Session> connection = myWebSocketClient.connect(mySocketImplementation, echoUri, request);
|
||||
@@ -123,41 +130,14 @@ public class ExampleServerR5IT {
|
||||
ourClient.delete().resourceById(mySubscriptionId).execute();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void afterClass() throws Exception {
|
||||
ourServer.stop();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
public static void beforeClass() throws Exception {
|
||||
String path = Paths.get("").toAbsolutePath().toString();
|
||||
|
||||
ourLog.info("Project base path is: {}", path);
|
||||
|
||||
ourServer = new Server(0);
|
||||
|
||||
WebAppContext webAppContext = new WebAppContext();
|
||||
webAppContext.setContextPath("/hapi-fhir-jpaserver");
|
||||
webAppContext.setDisplayName("HAPI FHIR");
|
||||
webAppContext.setDescriptor(path + "/src/main/webapp/WEB-INF/web.xml");
|
||||
webAppContext.setResourceBase(path + "/target/hapi-fhir-jpaserver-starter");
|
||||
webAppContext.setParentLoaderPriority(true);
|
||||
|
||||
ourServer.setHandler(webAppContext);
|
||||
ourServer.start();
|
||||
|
||||
ourPort = JettyUtil.getPortForStartedServer(ourServer);
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
|
||||
ourCtx = FhirContext.forR5();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = "http://localhost:" + ourPort + "/hapi-fhir-jpaserver/fhir/";
|
||||
|
||||
String ourServerBase = "http://localhost:" + port + "/hapi-fhir-jpaserver/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
|
||||
public static void main(String[] theArgs) throws Exception {
|
||||
ourPort = 8080;
|
||||
beforeClass();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,44 +7,43 @@ import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
||||
import ca.uhn.fhir.rest.client.interceptor.UrlTenantSelectionInterceptor;
|
||||
import ca.uhn.fhir.rest.server.provider.ProviderConstants;
|
||||
import ca.uhn.fhir.test.utilities.JettyUtil;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.CodeType;
|
||||
import org.hl7.fhir.r4.model.IntegerType;
|
||||
import org.hl7.fhir.r4.model.Parameters;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class, properties =
|
||||
{
|
||||
"spring.batch.job.enabled=false",
|
||||
"spring.profiles.active=r4",
|
||||
"spring.datasource.url=jdbc:h2:mem:dbr4-mt",
|
||||
"hapi.fhir.subscription.websocket_enabled=true",
|
||||
"hapi.fhir.subscription.websocket_enabled=true",
|
||||
"hapi.fhir.partitioning_multitenancy_enabled"
|
||||
|
||||
})
|
||||
public class MultitenantServerR4IT {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(MultitenantServerR4IT.class);
|
||||
private static IGenericClient ourClient;
|
||||
private static FhirContext ourCtx;
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerDstu2IT.class);
|
||||
private IGenericClient ourClient;
|
||||
private FhirContext ourCtx;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
private static UrlTenantSelectionInterceptor ourClientTenantInterceptor;
|
||||
|
||||
static {
|
||||
HapiProperties.forceReload();
|
||||
HapiProperties.setProperty(HapiProperties.DATASOURCE_URL, "jdbc:h2:mem:dbr4-mt");
|
||||
HapiProperties.setProperty(HapiProperties.FHIR_VERSION, "R4");
|
||||
HapiProperties.setProperty(HapiProperties.SUBSCRIPTION_WEBSOCKET_ENABLED, "true");
|
||||
HapiProperties.setProperty(HapiProperties.PARTITIONING_ENABLED, "true");
|
||||
HapiProperties.setProperty(HapiProperties.PARTITIONING_MULTITENANCY_ENABLED, "true");
|
||||
ourCtx = FhirContext.forR4();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndReadInTenantA() {
|
||||
ourLog.info("Base URL is: " + HapiProperties.getServerAddress());
|
||||
|
||||
|
||||
// Create tenant A
|
||||
ourClientTenantInterceptor.setTenantId("DEFAULT");
|
||||
@@ -70,7 +69,7 @@ public class MultitenantServerR4IT {
|
||||
|
||||
@Test
|
||||
public void testCreateAndReadInTenantB() {
|
||||
ourLog.info("Base URL is: " + HapiProperties.getServerAddress());
|
||||
|
||||
|
||||
// Create tenant A
|
||||
ourClientTenantInterceptor.setTenantId("DEFAULT");
|
||||
@@ -94,45 +93,14 @@ public class MultitenantServerR4IT {
|
||||
assertEquals("Family B", pt2.getName().get(0).getFamily());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void afterClass() throws Exception {
|
||||
ourServer.stop();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
public static void beforeClass() throws Exception {
|
||||
String path = Paths.get("").toAbsolutePath().toString();
|
||||
|
||||
ourLog.info("Project base path is: {}", path);
|
||||
|
||||
ourServer = new Server(0);
|
||||
|
||||
WebAppContext webAppContext = new WebAppContext();
|
||||
webAppContext.setContextPath("/hapi-fhir-jpaserver");
|
||||
webAppContext.setDisplayName("HAPI FHIR");
|
||||
webAppContext.setDescriptor(path + "/src/main/webapp/WEB-INF/web.xml");
|
||||
webAppContext.setResourceBase(path + "/target/hapi-fhir-jpaserver-starter");
|
||||
webAppContext.setParentLoaderPriority(true);
|
||||
|
||||
ourServer.setHandler(webAppContext);
|
||||
ourServer.start();
|
||||
|
||||
ourPort = JettyUtil.getPortForStartedServer(ourServer);
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
|
||||
ourCtx = FhirContext.forR4();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
String ourServerBase = HapiProperties.getServerAddress();
|
||||
ourServerBase = "http://localhost:" + ourPort + "/hapi-fhir-jpaserver/fhir/";
|
||||
|
||||
String ourServerBase = "http://localhost:" + port + "/hapi-fhir-jpaserver/fhir/";
|
||||
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
||||
|
||||
ourClientTenantInterceptor = new UrlTenantSelectionInterceptor();
|
||||
ourClient.registerInterceptor(ourClientTenantInterceptor);
|
||||
}
|
||||
|
||||
public static void main(String[] theArgs) throws Exception {
|
||||
ourPort = 8080;
|
||||
beforeClass();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package ca.uhn.fhir.jpa.starter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides server ports
|
||||
*/
|
||||
public class RandomServerPortProvider {
|
||||
|
||||
private static List<Integer> ourPorts = new ArrayList<Integer>();
|
||||
|
||||
public static int findFreePort() {
|
||||
ServerSocket server;
|
||||
try {
|
||||
server = new ServerSocket(0);
|
||||
int port = server.getLocalPort();
|
||||
ourPorts.add(port);
|
||||
server.close();
|
||||
Thread.sleep(500);
|
||||
return port;
|
||||
} catch (IOException e) {
|
||||
throw new Error(e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Integer> list() {
|
||||
return ourPorts;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
103
src/test/resources/application-integrationtest.yaml
Normal file
103
src/test/resources/application-integrationtest.yaml
Normal file
@@ -0,0 +1,103 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: 'jdbc:h2:file:./target/database/h2'
|
||||
username: sa
|
||||
password: null
|
||||
driverClassName: org.h2.Driver
|
||||
max-active: 15
|
||||
profiles:
|
||||
### This is the FHIR version. Choose between, dstu2, dstu3, r4 or r5
|
||||
active: r4
|
||||
hapi:
|
||||
fhir:
|
||||
#supported_resource_types:
|
||||
# - Patient
|
||||
# - Observation
|
||||
# allow_cascading_deletes: true
|
||||
# allow_contains_searches: true
|
||||
# allow_external_references: true
|
||||
# allow_multiple_delete: true
|
||||
# allow_override_default_search_params: true
|
||||
# allow_placeholder_references: true
|
||||
# auto_create_placeholder_reference_targets: false
|
||||
# default_encoding: JSON
|
||||
# default_pretty_print: true
|
||||
# default_page_size: 20
|
||||
# enable_index_missing_fields: false
|
||||
# enforce_referential_integrity_on_delete: false
|
||||
# enforce_referential_integrity_on_write: false
|
||||
# etag_support_enabled: true
|
||||
# expunge_enabled: true
|
||||
# daoconfig_client_id_strategy: null
|
||||
# fhirpath_interceptor_enabled: false
|
||||
# filter_search_enabled: true
|
||||
# graphql_enabled: true
|
||||
#partitioning:
|
||||
# cross_partition_reference_mode: true
|
||||
# multitenancy_enabled: true
|
||||
# partitioning_include_in_search_hashes: true
|
||||
#cors:
|
||||
# allow_Credentials: true
|
||||
# Supports multiple, comma separated allowed origin entries
|
||||
# cors.allowed_origin=http://localhost:8080,https://localhost:8080,https://fhirtest.uhn.ca
|
||||
# allowed_origin:
|
||||
# - '*'
|
||||
|
||||
# logger:
|
||||
# error_format: 'ERROR - ${requestVerb} ${requestUrl}'
|
||||
# format: >-
|
||||
# Path[${servletPath}] Source[${requestHeader.x-forwarded-for}]
|
||||
# Operation[${operationType} ${operationName} ${idOrResourceName}]
|
||||
# UA[${requestHeader.user-agent}] Params[${requestParameters}]
|
||||
# ResponseEncoding[${responseEncodingNoDefault}]
|
||||
# log_exceptions: true
|
||||
# name: fhirtest.access
|
||||
# max_binary_size: 104857600
|
||||
# max_page_size: 200
|
||||
# retain_cached_searches_mins: 60
|
||||
# reuse_cached_search_results_millis: 60000
|
||||
tester:
|
||||
-
|
||||
id: home
|
||||
name: Local Tester
|
||||
server_address: 'http://localhost:8080/hapi-fhir-jpaserver/fhir'
|
||||
refuse_to_fetch_third_party_urls: false
|
||||
fhir_version: R4
|
||||
-
|
||||
id: global
|
||||
name: Global Tester
|
||||
server_address: "http://hapi.fhir.org/baseR4"
|
||||
refuse_to_fetch_third_party_urls: false
|
||||
fhir_version: R4
|
||||
# validation:
|
||||
# requests_enabled: true
|
||||
# responses_enabled: true
|
||||
# binary_storage_enabled: true
|
||||
# bulk_export_enabled: true
|
||||
# partitioning_multitenancy_enabled:
|
||||
# subscription:
|
||||
# resthook_enabled: false
|
||||
# websocket_enabled: false
|
||||
# email:
|
||||
# from: some@test.com
|
||||
# host: google.com
|
||||
# port:
|
||||
# username:
|
||||
# password:
|
||||
# auth:
|
||||
# startTlsEnable:
|
||||
# startTlsRequired:
|
||||
# quitWait:
|
||||
|
||||
|
||||
#
|
||||
#elasticsearch:
|
||||
# debug:
|
||||
# pretty_print_json_log: false
|
||||
# refresh_after_write: false
|
||||
# enabled: false
|
||||
# password: SomePassword
|
||||
# required_index_status: YELLOW
|
||||
# rest_url: 'http://localhost:9200'
|
||||
# schema_management_strategy: CREATE
|
||||
# username: SomeUsername
|
||||
Reference in New Issue
Block a user