Formatting ...
This commit is contained in:
@@ -11,14 +11,11 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.web.server.LocalServerPort;
|
import org.springframework.boot.web.server.LocalServerPort;
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
import org.springframework.test.context.TestPropertySource;
|
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@TestPropertySource(locations = "/application-integrationtest.yaml")
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class, properties =
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class, properties =
|
||||||
{
|
{
|
||||||
"spring.batch.job.enabled=false",
|
"spring.batch.job.enabled=false",
|
||||||
|
|||||||
@@ -51,37 +51,37 @@ public class ExampleServerR4IT {
|
|||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCreateAndRead() {
|
void testCreateAndRead() {
|
||||||
|
|
||||||
String methodName = "testCreateResourceConditional";
|
String methodName = "testCreateResourceConditional";
|
||||||
|
|
||||||
Patient pt = new Patient();
|
Patient pt = new Patient();
|
||||||
pt.setActive(true);
|
pt.setActive(true);
|
||||||
pt.getBirthDateElement().setValueAsString("2020-01-01");
|
pt.getBirthDateElement().setValueAsString("2020-01-01");
|
||||||
pt.addIdentifier().setSystem("http://foo").setValue("12345");
|
pt.addIdentifier().setSystem("http://foo").setValue("12345");
|
||||||
pt.addName().setFamily(methodName);
|
pt.addName().setFamily(methodName);
|
||||||
IIdType id = ourClient.create().resource(pt).execute().getId();
|
IIdType id = ourClient.create().resource(pt).execute().getId();
|
||||||
|
|
||||||
Patient pt2 = ourClient.read().resource(Patient.class).withId(id).execute();
|
Patient pt2 = ourClient.read().resource(Patient.class).withId(id).execute();
|
||||||
assertEquals(methodName, pt2.getName().get(0).getFamily());
|
assertEquals(methodName, pt2.getName().get(0).getFamily());
|
||||||
|
|
||||||
// Test EMPI
|
// Test EMPI
|
||||||
|
|
||||||
// Wait until the EMPI message has been processed
|
// Wait until the EMPI message has been processed
|
||||||
await().until(() -> getPeople().size() > 0);
|
await().until(() -> getPeople().size() > 0);
|
||||||
List<Person> persons = getPeople();
|
List<Person> persons = getPeople();
|
||||||
|
|
||||||
// Verify a Person was created that links to our Patient
|
// Verify a Person was created that links to our Patient
|
||||||
Optional<String> personLinkToCreatedPatient = persons.stream()
|
Optional<String> personLinkToCreatedPatient = persons.stream()
|
||||||
.map(Person::getLink)
|
.map(Person::getLink)
|
||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
.map(Person.PersonLinkComponent::getTarget)
|
.map(Person.PersonLinkComponent::getTarget)
|
||||||
.map(Reference::getReference)
|
.map(Reference::getReference)
|
||||||
.filter(pid -> id.toUnqualifiedVersionless().getValue().equals(pid))
|
.filter(pid -> id.toUnqualifiedVersionless().getValue().equals(pid))
|
||||||
.findAny();
|
.findAny();
|
||||||
assertTrue(personLinkToCreatedPatient.isPresent());
|
assertTrue(personLinkToCreatedPatient.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Person> getPeople() {
|
private List<Person> getPeople() {
|
||||||
Bundle bundle = ourClient.search().forResource(Person.class).cacheControl(new CacheControlDirective().setNoCache(true)).returnBundle(Bundle.class).execute();
|
Bundle bundle = ourClient.search().forResource(Person.class).cacheControl(new CacheControlDirective().setNoCache(true)).returnBundle(Bundle.class).execute();
|
||||||
@@ -89,69 +89,68 @@ public class ExampleServerR4IT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWebsocketSubscription() throws Exception {
|
public void testWebsocketSubscription() throws Exception {
|
||||||
/*
|
/*
|
||||||
* Create subscription
|
* Create subscription
|
||||||
*/
|
*/
|
||||||
Subscription subscription = new Subscription();
|
Subscription subscription = new Subscription();
|
||||||
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
||||||
subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED);
|
subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED);
|
||||||
subscription.setCriteria("Observation?status=final");
|
subscription.setCriteria("Observation?status=final");
|
||||||
|
|
||||||
Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();
|
Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();
|
||||||
channel.setType(Subscription.SubscriptionChannelType.WEBSOCKET);
|
channel.setType(Subscription.SubscriptionChannelType.WEBSOCKET);
|
||||||
channel.setPayload("application/json");
|
channel.setPayload("application/json");
|
||||||
subscription.setChannel(channel);
|
subscription.setChannel(channel);
|
||||||
|
|
||||||
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
||||||
IIdType mySubscriptionId = methodOutcome.getId();
|
IIdType mySubscriptionId = methodOutcome.getId();
|
||||||
|
|
||||||
// Wait for the subscription to be activated
|
// Wait for the subscription to be activated
|
||||||
await().until(() -> activeSubscriptionCount() == 3);
|
await().until(() -> activeSubscriptionCount() == 3);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attach websocket
|
* Attach websocket
|
||||||
*/
|
*/
|
||||||
|
|
||||||
WebSocketClient myWebSocketClient = new WebSocketClient();
|
WebSocketClient myWebSocketClient = new WebSocketClient();
|
||||||
SocketImplementation mySocketImplementation = new SocketImplementation(mySubscriptionId.getIdPart(), EncodingEnum.JSON);
|
SocketImplementation mySocketImplementation = new SocketImplementation(mySubscriptionId.getIdPart(), EncodingEnum.JSON);
|
||||||
|
|
||||||
myWebSocketClient.start();
|
myWebSocketClient.start();
|
||||||
URI echoUri = new URI("ws://localhost:" + port + "/hapi-fhir-jpaserver/websocket");
|
URI echoUri = new URI("ws://localhost:" + port + "/hapi-fhir-jpaserver/websocket");
|
||||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||||
ourLog.info("Connecting to : {}", echoUri);
|
ourLog.info("Connecting to : {}", echoUri);
|
||||||
Future<Session> connection = myWebSocketClient.connect(mySocketImplementation, echoUri, request);
|
Future<Session> connection = myWebSocketClient.connect(mySocketImplementation, echoUri, request);
|
||||||
Session session = connection.get(2, TimeUnit.SECONDS);
|
Session session = connection.get(2, TimeUnit.SECONDS);
|
||||||
|
|
||||||
ourLog.info("Connected to WS: {}", session.isOpen());
|
ourLog.info("Connected to WS: {}", session.isOpen());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a matching resource
|
* Create a matching resource
|
||||||
*/
|
*/
|
||||||
Observation obs = new Observation();
|
Observation obs = new Observation();
|
||||||
obs.setStatus(Observation.ObservationStatus.FINAL);
|
obs.setStatus(Observation.ObservationStatus.FINAL);
|
||||||
ourClient.create().resource(obs).execute();
|
ourClient.create().resource(obs).execute();
|
||||||
|
|
||||||
// Give some time for the subscription to deliver
|
// Give some time for the subscription to deliver
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ensure that we receive a ping on the websocket
|
* Ensure that we receive a ping on the websocket
|
||||||
*/
|
*/
|
||||||
waitForSize(1, () -> mySocketImplementation.myPingCount);
|
waitForSize(1, () -> mySocketImplementation.myPingCount);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clean up
|
* Clean up
|
||||||
*/
|
*/
|
||||||
ourClient.delete().resourceById(mySubscriptionId).execute();
|
ourClient.delete().resourceById(mySubscriptionId).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int activeSubscriptionCount() {
|
private int activeSubscriptionCount() {
|
||||||
return ourClient.search().forResource(Subscription.class).where(Subscription.STATUS.exactly().code("active")).cacheControl(new CacheControlDirective().setNoCache(true)).returnBundle(Bundle.class).execute().getEntry().size();
|
return ourClient.search().forResource(Subscription.class).where(Subscription.STATUS.exactly().code("active")).cacheControl(new CacheControlDirective().setNoCache(true)).returnBundle(Bundle.class).execute().getEntry().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void beforeEach() {
|
void beforeEach() {
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ public class ExampleServerR5IT {
|
|||||||
/*
|
/*
|
||||||
* Ensure that we receive a ping on the websocket
|
* Ensure that we receive a ping on the websocket
|
||||||
*/
|
*/
|
||||||
await().until(()->mySocketImplementation.myPingCount > 0);
|
await().until(() -> mySocketImplementation.myPingCount > 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clean up
|
* Clean up
|
||||||
|
|||||||
Reference in New Issue
Block a user