-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make MockServer compatible with newer (5.11.x) versions (#3437)
Co-authored-by: Sergei Egorov <[email protected]>
- Loading branch information
Showing
5 changed files
with
80 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...s/mockserver/src/test/java/org/testcontainers/containers/MockServerContainerRuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockserver.client.MockServerClient; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
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.assertThat; | ||
|
||
public class MockServerContainerRuleTest { | ||
|
||
public static final DockerImageName MOCKSERVER_IMAGE = DockerImageName.parse("jamesdbloom/mockserver:mockserver-5.5.4"); | ||
|
||
// creatingProxy { | ||
@Rule | ||
public MockServerContainer mockServer = new MockServerContainer(MOCKSERVER_IMAGE); | ||
// } | ||
|
||
@Test | ||
public void shouldReturnExpectation() throws Exception { | ||
// testSimpleExpectation { | ||
new MockServerClient(mockServer.getHost(), mockServer.getServerPort()) | ||
.when(request() | ||
.withPath("/person") | ||
.withQueryStringParameter("name", "peter")) | ||
.respond(response() | ||
.withBody("Peter the person!")); | ||
|
||
// ...a GET request to '/person?name=peter' returns "Peter the person!" | ||
// } | ||
|
||
assertThat("Expectation returns expected response body", | ||
SimpleHttpClient.responseFromMockserver(mockServer, "/person?name=peter"), | ||
containsString("Peter the person") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
modules/mockserver/src/test/java/org/testcontainers/containers/SimpleHttpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.testcontainers.containers; | ||
|
||
import lombok.Cleanup; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
|
||
public class SimpleHttpClient { | ||
public static String responseFromMockserver(MockServerContainer mockServer, String path) throws IOException { | ||
URLConnection urlConnection = new URL(mockServer.getEndpoint() + path).openConnection(); | ||
@Cleanup BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); | ||
return reader.readLine(); | ||
} | ||
} |