hapi-fhir/restful-server-example-test/src/test/java/ca/uhn/example/ExampleTest.java

88 lines
2.2 KiB
Java
Raw Normal View History

2014-09-03 18:03:44 -04:00
package ca.uhn.example;
2014-10-31 15:00:26 -04:00
import static org.junit.Assert.assertEquals;
2014-09-03 18:03:44 -04:00
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.AfterClass;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.rest.client.IGenericClient;
public class ExampleTest {
2014-10-31 15:00:26 -04:00
private static Integer ourPort;
2014-09-03 18:03:44 -04:00
private static Server ourServer;
private static FhirContext ourCtx;
private static IGenericClient ourClient;
@AfterClass
public static void afterClass() throws Exception {
ourServer.stop();
2014-09-04 18:03:19 -04:00
System.clearProperty("ca.uhn.fhir.to.TesterConfig_SYSPROP_FORCE_SERVERS");
2014-09-03 18:03:44 -04:00
}
2014-10-31 15:00:26 -04:00
public static boolean isWindows()
{
return System.getProperty("os.name").startsWith("Windows");
}
2014-09-03 18:03:44 -04:00
@Test
2014-10-31 15:00:26 -04:00
public void test01Search() throws Exception {
if (isWindows()) {
/*
* Tests here have some weird windows inconsistency relating to the path for finding the WAR file.
* Since this test isn't really important to work multiplatform, we can skip it
*/
return;
}
beforeClass();
2014-09-03 18:03:44 -04:00
Bundle results = ourClient.search().forResource(Patient.class).execute();
assertEquals(1, results.size());
}
2014-10-31 15:00:26 -04:00
/**
* Not annotated with @BeforeClass so that we can skip if we're not running tests here
*/
2014-09-03 18:03:44 -04:00
public static void beforeClass() throws Exception {
2014-10-31 15:00:26 -04:00
if (ourPort != null) {
return;
}
2014-09-03 18:03:44 -04:00
ourPort = RandomServerPortProvider.findFreePort();
ourServer = new Server(ourPort);
2014-09-04 18:03:19 -04:00
String base = "http://localhost:" + ourPort+"/fhir";
System.setProperty("ca.uhn.fhir.to.TesterConfig_SYSPROP_FORCE_SERVERS", "example , Restful Server Example , " + base);
2014-09-03 18:03:44 -04:00
WebAppContext root = new WebAppContext();
2014-09-17 09:07:01 -04:00
root.setAllowDuplicateFragmentNames(true);
2014-09-03 18:03:44 -04:00
root.setWar("file:../restful-server-example/target/restful-server-example.war");
root.setContextPath("/");
root.setAttribute(WebAppContext.BASETEMPDIR, "target/tempextrtact");
root.setParentLoaderPriority(false);
root.setCopyWebInf(true);
root.setCopyWebDir(true);
ourServer.setHandler(root);
ourServer.start();
ourCtx = new FhirContext();
2014-09-04 18:03:19 -04:00
ourClient = ourCtx.newRestfulGenericClient(base);
2014-09-03 18:03:44 -04:00
}
}