From c2fa1b37ed8b65744ced68198740ca9dd9feb13a Mon Sep 17 00:00:00 2001 From: pbelmann Date: Mon, 27 Jun 2016 23:19:17 +0200 Subject: [PATCH] server based tests added #36 --- JobProxyModel/pom.xml | 16 ++++ JobProxyServer/pom.xml | 13 +++ .../jobproxy/server/JobProxyServerTest.java | 80 +++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 JobProxyServer/src/test/java/de/unibi/cebitec/bibiserv/jobproxy/server/JobProxyServerTest.java diff --git a/JobProxyModel/pom.xml b/JobProxyModel/pom.xml index 8621f40..0da4be8 100644 --- a/JobProxyModel/pom.xml +++ b/JobProxyModel/pom.xml @@ -35,4 +35,20 @@ test + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + test-jar + + + + + + diff --git a/JobProxyServer/pom.xml b/JobProxyServer/pom.xml index 2c4abc8..5e68d50 100644 --- a/JobProxyServer/pom.xml +++ b/JobProxyServer/pom.xml @@ -16,6 +16,13 @@ JobProxyModel beta.1.release + + de.unibi.cebitec.bibiserv + JobProxyModel + beta.1.release + test-jar + test + de.unibi.cebitec.bibiserv JobProxyDRMAA @@ -31,5 +38,11 @@ JobProxyJavaDocker beta.1.release + + junit + junit + 4.12 + test + diff --git a/JobProxyServer/src/test/java/de/unibi/cebitec/bibiserv/jobproxy/server/JobProxyServerTest.java b/JobProxyServer/src/test/java/de/unibi/cebitec/bibiserv/jobproxy/server/JobProxyServerTest.java new file mode 100644 index 0000000..32d783c --- /dev/null +++ b/JobProxyServer/src/test/java/de/unibi/cebitec/bibiserv/jobproxy/server/JobProxyServerTest.java @@ -0,0 +1,80 @@ +package de.unibi.cebitec.bibiserv.jobproxy.server; + +import de.unibi.cebitec.bibiserv.jobproxy.DummyFramework; +import de.unibi.cebitec.bibiserv.jobproxy.model.exceptions.FrameworkException; +import org.junit.Test; + +import javax.ws.rs.ProcessingException; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * Created by pbelmann on 27.06.16. + */ +public class JobProxyServerTest { + + private JobProxyServer server; + + private static String TARGET = "/v1/jobproxy/ping"; + + private static String ALTERNATIVE_URI = "http://localhost:9998/"; + + @Test(expected = ProcessingException.class) + public void canStop(){ + try { + server = new JobProxyServer(DummyFramework.NAME, new Properties()); + } catch (FrameworkException e) { + e.printStackTrace(); + } + + server.startServer(); + server.stopServer(); + + Client client = ClientBuilder.newClient(); + Response noServerResponse = client.target(server.getURI()).path(TARGET).request().get(); + assertEquals(Response.Status.Family.CLIENT_ERROR, noServerResponse.getStatusInfo().getFamily()); + } + + @Test + public void canReceive(){ + try { + server = new JobProxyServer(DummyFramework.NAME, new Properties()); + } catch (FrameworkException e) { + e.printStackTrace(); + } + + server.startServer(); + + Client client = ClientBuilder.newClient(); + assertNotNull(server.getURI()); + Response res = client.target(server.getURI()).path(TARGET).request().get(); + assertEquals(Response.Status.Family.SUCCESSFUL, res.getStatusInfo().getFamily()); + server.stopServer(); + } + + @Test + public void canChangeDefaultURI(){ + + Properties properties = new Properties(); + properties.setProperty("serveruri", ALTERNATIVE_URI); + + try { + server = new JobProxyServer(DummyFramework.NAME, properties); + } catch (FrameworkException e) { + e.printStackTrace(); + } + + server.startServer(); + + Client client = ClientBuilder.newClient(); + assertNotNull(server.getURI()); + Response res = client.target(ALTERNATIVE_URI).path(TARGET).request().get(); + assertEquals(Response.Status.Family.SUCCESSFUL, res.getStatusInfo().getFamily()); + server.stopServer(); + } +}