File tree Expand file tree Collapse file tree 4 files changed +81
-0
lines changed
main/java/org/testcontainers/containers
test/java/org/testcontainers/containers Expand file tree Collapse file tree 4 files changed +81
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
99### Changed
1010- Added InfluxDB module ([ \# 686] ( https://github.com/testcontainers/testcontainers-java/pull/686 ) )
11+ - Added MockServer module ([ \# 696] ( https://github.com/testcontainers/testcontainers-java/pull/696 ) )
1112
1213## [ 1.7.2] - 2018-04-30
1314
Original file line number Diff line number Diff line change 1+ description = " Testcontainers :: MockServer"
2+
3+ dependencies {
4+ compile project(' :testcontainers' )
5+
6+ compileOnly ' org.mock-server:mockserver-client-java:5.3.0'
7+ testCompile ' org.mock-server:mockserver-client-java:5.3.0'
8+ }
Original file line number Diff line number Diff line change 1+ package org .testcontainers .containers ;
2+
3+ import com .github .dockerjava .api .command .InspectContainerResponse ;
4+ import lombok .Getter ;
5+ import lombok .extern .slf4j .Slf4j ;
6+ import org .mockserver .client .server .MockServerClient ;
7+
8+ @ Slf4j
9+ public class MockServerContainer extends GenericContainer <MockServerContainer > {
10+
11+ public static final String VERSION = "5.3.0" ;
12+
13+ public static final int PORT = 80 ;
14+
15+ @ Getter
16+ private MockServerClient client ;
17+
18+ public MockServerContainer () {
19+ this (VERSION );
20+ }
21+
22+ public MockServerContainer (String version ) {
23+ super ("jamesdbloom/mockserver:mockserver-" + version );
24+ withCommand ("/opt/mockserver/run_mockserver.sh -logLevel INFO -serverPort " + PORT );
25+ addExposedPorts (PORT );
26+ }
27+
28+ @ Override
29+ protected void containerIsStarted (InspectContainerResponse containerInfo ) {
30+ super .containerIsStarted (containerInfo );
31+
32+ client = new MockServerClient (getContainerIpAddress (), getMappedPort (PORT ));
33+ }
34+
35+ public String getEndpoint () {
36+ return String .format ("http://%s:%d" , getContainerIpAddress (), getMappedPort (PORT ));
37+ }
38+ }
Original file line number Diff line number Diff line change 1+ package org .testcontainers .containers ;
2+
3+ import lombok .Cleanup ;
4+ import org .junit .ClassRule ;
5+ import org .junit .Test ;
6+
7+ import java .io .BufferedReader ;
8+ import java .io .InputStreamReader ;
9+ import java .net .URL ;
10+ import java .net .URLConnection ;
11+
12+ import static org .mockserver .model .HttpRequest .request ;
13+ import static org .mockserver .model .HttpResponse .response ;
14+ import static org .rnorth .visibleassertions .VisibleAssertions .assertTrue ;
15+
16+ public class MockServerContainerTest {
17+
18+ @ ClassRule
19+ public static MockServerContainer mockServer = new MockServerContainer ();
20+
21+ @ Test
22+ public void testBasicScenario () throws Exception {
23+ mockServer .getClient ()
24+ .when (request ("/hello" ))
25+ .respond (response ("Hello World!" ));
26+
27+ URLConnection urlConnection = new URL (mockServer .getEndpoint () + "/hello" ).openConnection ();
28+ @ Cleanup BufferedReader reader = new BufferedReader (new InputStreamReader (urlConnection .getInputStream ()));
29+ String line = reader .readLine ();
30+ System .out .println (line );
31+
32+ assertTrue ("MockServer returns correct result" , line .contains ("Hello World!" ));
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments