Skip to content

Commit

Permalink
#32 - increased coverage for both unit and integration testing of the…
Browse files Browse the repository at this point in the history
… request forward logic
  • Loading branch information
jamesdbloom committed May 17, 2014
1 parent ad826fa commit aca74d3
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 36 deletions.
Expand Up @@ -20,7 +20,6 @@
<groupId>org.mock-server</groupId>
<artifactId>mockserver-integration-testing</artifactId>
<version>${mockserver.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Expand Up @@ -20,7 +20,6 @@
<groupId>org.mock-server</groupId>
<artifactId>mockserver-integration-testing</artifactId>
<version>${mockserver.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
@@ -1,43 +1,69 @@
package org.mockserver;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.mockserver.client.server.MockServerClient;
import org.mockserver.integration.server.AbstractClientServerIntegrationTest;
import org.mockserver.integration.testserver.TestServer;
import org.mockserver.socket.PortFactory;

/**
* @author jamesdbloom
*/
public class ClientServerMavenPluginIntegrationTest extends AbstractClientServerIntegrationTest {

private final static int port = 8080;
private final static int serverSecurePort = 8082;
private final static int TEST_SERVER_HTTP_PORT = PortFactory.findFreePort();
private final static int TEST_SERVER_HTTPS_PORT = PortFactory.findFreePort();
private final static int SERVER_HTTP_PORT = 8080;
private final static int SERVER_HTTPS_PORT = 8082;
private static TestServer testServer = new TestServer();

@BeforeClass
public static void createClient() throws Exception {
// do nothing maven build should have started server

// start test server
testServer.startServer(TEST_SERVER_HTTP_PORT, TEST_SERVER_HTTPS_PORT);

// start client
mockServerClient = new MockServerClient("localhost", port, servletContext);
mockServerClient = new MockServerClient("localhost", SERVER_HTTP_PORT, servletContext);
}

@Before
public void clearServer() {
mockServerClient.reset();
}

@AfterClass
public static void stopServer() throws Exception {
// do nothing maven build should stop server

// stop test server
if (testServer != null) {
testServer.stop();
}
}

@Override
public int getPort() {
return port;
public int getMockServerPort() {
return SERVER_HTTP_PORT;
}

@Override
public int getSecurePort() {
return serverSecurePort;
public int getMockServerSecurePort() {
return SERVER_HTTPS_PORT;
}

@After
public void stopServer() throws Exception {
// do nothing maven build should stop server
@Override
public int getTestServerPort() {
return TEST_SERVER_HTTP_PORT;
}

@Override
public int getTestServerSecurePort() {
return TEST_SERVER_HTTPS_PORT;
}

}
Expand Up @@ -9,6 +9,7 @@
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
Expand All @@ -19,7 +20,6 @@
<groupId>org.mock-server</groupId>
<artifactId>mockserver-integration-testing</artifactId>
<version>${mockserver.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
@@ -1,43 +1,68 @@
package org.mockserver;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.mockserver.client.server.MockServerClient;
import org.mockserver.integration.server.AbstractClientServerIntegrationTest;
import org.mockserver.integration.testserver.TestServer;
import org.mockserver.socket.PortFactory;

/**
* @author jamesdbloom
*/
public class ClientServerMavenPluginIntegrationTest extends AbstractClientServerIntegrationTest {

private final static int port = 8080;
private final static int serverSecurePort = 8082;
private final static int TEST_SERVER_HTTP_PORT = PortFactory.findFreePort();
private final static int TEST_SERVER_HTTPS_PORT = PortFactory.findFreePort();
private final static int SERVER_HTTP_PORT = 8080;
private final static int SERVER_HTTPS_PORT = 8082;
private static TestServer testServer = new TestServer();

@BeforeClass
public static void createClient() throws Exception {
// do nothing maven build should have started server

// start test server
testServer.startServer(TEST_SERVER_HTTP_PORT, TEST_SERVER_HTTPS_PORT);

// start client
mockServerClient = new MockServerClient("localhost", port, servletContext);
mockServerClient = new MockServerClient("localhost", SERVER_HTTP_PORT, servletContext);
}

@Before
public void clearServer() {
mockServerClient.reset();
}

@AfterClass
public static void stopServer() throws Exception {
// do nothing maven build should stop server

// stop test server
if (testServer != null) {
testServer.stop();
}
}

@Override
public int getPort() {
return port;
public int getMockServerPort() {
return SERVER_HTTP_PORT;
}

@Override
public int getSecurePort() {
return serverSecurePort;
public int getMockServerSecurePort() {
return SERVER_HTTPS_PORT;
}

@After
public void stopServer() throws Exception {
// do nothing maven build should stop server
@Override
public int getTestServerPort() {
return TEST_SERVER_HTTP_PORT;
}

@Override
public int getTestServerSecurePort() {
return TEST_SERVER_HTTPS_PORT;
}

}
Expand Up @@ -9,6 +9,7 @@
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
Expand All @@ -19,7 +20,6 @@
<groupId>org.mock-server</groupId>
<artifactId>mockserver-integration-testing</artifactId>
<version>${mockserver.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Expand Up @@ -5,41 +5,64 @@
import org.junit.BeforeClass;
import org.mockserver.client.server.MockServerClient;
import org.mockserver.integration.server.AbstractClientServerIntegrationTest;
import org.mockserver.integration.testserver.TestServer;
import org.mockserver.socket.PortFactory;

/**
* @author jamesdbloom
*/
public class ClientServerMavenPluginIntegrationTest extends AbstractClientServerIntegrationTest {

private final static int serverPort = 8080;
private final static int serverSecurePort = 8082;
private final static int TEST_SERVER_HTTP_PORT = PortFactory.findFreePort();
private final static int TEST_SERVER_HTTPS_PORT = PortFactory.findFreePort();
private final static int SERVER_HTTP_PORT = 8080;
private final static int SERVER_HTTPS_PORT = 8082;
private static TestServer testServer = new TestServer();

@BeforeClass
public static void startServer() throws Exception {
public static void createClient() throws Exception {
// do nothing maven build should have started server

// start test server
testServer.startServer(TEST_SERVER_HTTP_PORT, TEST_SERVER_HTTPS_PORT);

// start client
mockServerClient = new MockServerClient("localhost", serverPort, servletContext);
mockServerClient = new MockServerClient("localhost", SERVER_HTTP_PORT, servletContext);
}

@Before
public void clearServer() {
mockServerClient.reset();
}

@AfterClass
public static void stopServer() throws Exception {
// do nothing maven build should stop server

// stop test server
if (testServer != null) {
testServer.stop();
}
}

@Override
public int getPort() {
return serverPort;
public int getMockServerPort() {
return SERVER_HTTP_PORT;
}

@Override
public int getSecurePort() {
return serverSecurePort;
public int getMockServerSecurePort() {
return SERVER_HTTPS_PORT;
}

@AfterClass
public static void stopServer() throws Exception {
// do nothing maven build should stop server
@Override
public int getTestServerPort() {
return TEST_SERVER_HTTP_PORT;
}

@Override
public int getTestServerSecurePort() {
return TEST_SERVER_HTTPS_PORT;
}

}

0 comments on commit aca74d3

Please sign in to comment.