From 6ce5e9e9664d9be94ca7a000f0725bd89e83a2d6 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Sat, 30 Jan 2016 09:23:40 -0500 Subject: [PATCH] Fix CLI build --- .../ca/uhn/fhir/jpa/demo/ExampleServerIT.java | 81 ------------------- .../jpa/demo/RandomServerPortProvider.java | 36 --------- 2 files changed, 117 deletions(-) delete mode 100644 hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java delete mode 100644 hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/test/java/ca/uhn/fhir/jpa/demo/RandomServerPortProvider.java diff --git a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java deleted file mode 100644 index f4efde6ddd9..00000000000 --- a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java +++ /dev/null @@ -1,81 +0,0 @@ -package ca.uhn.fhir.jpa.demo; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; - -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.webapp.WebAppContext; -import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.dstu2.resource.Patient; -import ca.uhn.fhir.rest.client.IGenericClient; -import ca.uhn.fhir.rest.client.ServerValidationModeEnum; -import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; - -public class ExampleServerIT { - - private static IGenericClient ourClient; - private static final FhirContext ourCtx = FhirContext.forDstu2(); - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExampleServerIT.class); - - private static int ourPort; - - private static Server ourServer; - private static String ourServerBase; - - @Test - public void testCreateAndRead() throws IOException { - 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()); - } - - @AfterClass - public static void afterClass() throws Exception { - ourServer.stop(); - } - - @BeforeClass - public static void beforeClass() throws Exception { - /* - * This runs under maven, and I'm not sure how else to figure out the target directory from code.. - */ - String path = ExampleServerIT.class.getClassLoader().getResource(".keep_hapi-fhir-jpaserver-example").getPath(); - path = new File(path).getParent(); - path = new File(path).getParent(); - path = new File(path).getParent(); - - ourLog.info("Project base path is: {}", path); - - ourPort = RandomServerPortProvider.findFreePort(); - ourServer = new Server(ourPort); - - WebAppContext webAppContext = new WebAppContext(); - webAppContext.setContextPath("/"); - webAppContext.setDescriptor(path + "/src/main/webapp/WEB-INF/web.xml"); - webAppContext.setResourceBase(path + "/target/hapi-fhir-jpaserver-example"); - webAppContext.setParentLoaderPriority(true); - - ourServer.setHandler(webAppContext); - ourServer.start(); - - ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); - ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000); - ourServerBase = "http://localhost:" + ourPort + "/baseDstu2"; - ourClient = ourCtx.newRestfulGenericClient(ourServerBase); - ourClient.registerInterceptor(new LoggingInterceptor(true)); - - } - -} diff --git a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/test/java/ca/uhn/fhir/jpa/demo/RandomServerPortProvider.java b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/test/java/ca/uhn/fhir/jpa/demo/RandomServerPortProvider.java deleted file mode 100644 index c8f4e49757d..00000000000 --- a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/test/java/ca/uhn/fhir/jpa/demo/RandomServerPortProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -package ca.uhn.fhir.jpa.demo; - -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 ourPorts = new ArrayList(); - - 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 list() { - return ourPorts; - } - -} - \ No newline at end of file