Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update mockserver to 5.5.1 and bind to port 1080 which is default #1109

Merged
merged 7 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/mockserver/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ description = "Testcontainers :: MockServer"
dependencies {
compile project(':testcontainers')

testCompile 'org.mock-server:mockserver-client-java:5.5.0'
testCompile 'org.mock-server:mockserver-client-java:5.5.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
@Slf4j
public class MockServerContainer extends GenericContainer<MockServerContainer> {

public static final String VERSION = "5.5.0";
public static final String VERSION = "5.5.1";

public static final int PORT = 80;
public static final int PORT = 1080;

public MockServerContainer() {
this(VERSION);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,57 @@
package org.testcontainers.containers;

import lombok.Cleanup;
import org.junit.ClassRule;
import org.junit.Test;
import org.mockserver.client.MockServerClient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import static org.hamcrest.CoreMatchers.containsString;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;
import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue;
import static org.rnorth.visibleassertions.VisibleAssertions.assertThat;

public class MockServerContainerTest {

@ClassRule
public static MockServerContainer mockServer = new MockServerContainer();
@Test
public void shouldCallActualMockserverVersion() throws Exception {
String actualVersion = MockServerClient.class.getPackage().getImplementationVersion();
try (MockServerContainer mockServer = new MockServerContainer(actualVersion)) {
mockServer.start();

String expectedBody = "Hello World!";

assertThat("MockServer returns correct result",
responseFromMockserver(mockServer, expectedBody, "/hello"),
containsString(expectedBody)
);
}
}

@Test
public void testBasicScenario() throws Exception {
public void shouldCallDefaultMockserverVersion() throws Exception {
try (MockServerContainer mockServerDefault = new MockServerContainer()) {
mockServerDefault.start();
String expectedBody = "Hello Default World!";

assertThat("MockServer returns correct result for default constructor",
responseFromMockserver(mockServerDefault, expectedBody, "/hellodefault"),
containsString(expectedBody)
);
}
}

private static String responseFromMockserver(MockServerContainer mockServer, String expectedBody, String path) throws IOException {
new MockServerClient(mockServer.getContainerIpAddress(), mockServer.getServerPort())
.when(request("/hello"))
.respond(response("Hello World!"));
.when(request(path))
.respond(response(expectedBody));

URLConnection urlConnection = new URL(mockServer.getEndpoint() + "/hello").openConnection();
URLConnection urlConnection = new URL(mockServer.getEndpoint() + path).openConnection();
@Cleanup BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line = reader.readLine();
System.out.println(line);

assertTrue("MockServer returns correct result", line.contains("Hello World!"));
return reader.readLine();
}
}