Skip to content

Commit

Permalink
server based tests added #36
Browse files Browse the repository at this point in the history
  • Loading branch information
pbelmann committed Jun 27, 2016
1 parent 3355a9f commit c2fa1b3
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
16 changes: 16 additions & 0 deletions JobProxyModel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,20 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
13 changes: 13 additions & 0 deletions JobProxyServer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
<artifactId>JobProxyModel</artifactId>
<version>beta.1.release</version>
</dependency>
<dependency>
<groupId>de.unibi.cebitec.bibiserv</groupId>
<artifactId>JobProxyModel</artifactId>
<version>beta.1.release</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.unibi.cebitec.bibiserv</groupId>
<artifactId>JobProxyDRMAA</artifactId>
Expand All @@ -31,5 +38,11 @@
<artifactId>JobProxyJavaDocker</artifactId>
<version>beta.1.release</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit c2fa1b3

Please sign in to comment.