unrequested changes: commons-logging dependency marked provided (to avoid redundant jar inclusion), removed unused imports in classes that were modified
58 lines
2.0 KiB
Java
58 lines
2.0 KiB
Java
package ca.uhn.fhir.jpa.starter;
|
|
|
|
import ca.uhn.fhir.context.FhirContext;
|
|
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 org.hl7.fhir.instance.model.api.IIdType;
|
|
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.test.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 =
|
|
{
|
|
"hapi.fhir.fhir_version=dstu2",
|
|
"spring.datasource.url=jdbc:h2:mem:dbr2",
|
|
"hapi.fhir.cr_enabled=false",
|
|
})
|
|
class ExampleServerDstu2IT {
|
|
|
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerDstu2IT.class);
|
|
private IGenericClient ourClient;
|
|
private FhirContext ourCtx;
|
|
|
|
@LocalServerPort
|
|
private int port;
|
|
|
|
@Test
|
|
void testCreateAndRead() {
|
|
|
|
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());
|
|
}
|
|
|
|
|
|
@BeforeEach
|
|
void beforeEach() {
|
|
|
|
ourCtx = FhirContext.forDstu2();
|
|
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
|
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
|
String ourServerBase = "http://localhost:" + port + "/fhir/";
|
|
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
|
|
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
|
}
|
|
}
|