Skip to content

Commit cc4750f

Browse files
committed
feat: #141 Allow getting partial mocks paths
Signed-off-by: Laurent Broudoux <laurent.broudoux@gmail.com>
1 parent 19f2269 commit cc4750f

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

src/main/java/io/github/microcks/testcontainers/MicrocksContainer.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,17 @@ public String getHttpEndpoint() {
235235
* @return A usable endpoint to interact with Microcks mocks.
236236
*/
237237
public String getSoapMockEndpoint(String service, String version) {
238-
return String.format("%s/soap/%s/%s", getHttpEndpoint(), service, version);
238+
return String.format("%s/soap/%s/%s", getHttpEndpoint(), service, version);
239+
}
240+
241+
/**
242+
* Get the exposed mock endpoint path for a SOAP Service.
243+
* @param service The name of Service/API
244+
* @param version The version of Service/API
245+
* @return A path endpoint to interact with Microcks mocks - starts with '/'.
246+
*/
247+
public String getSoapMockEndpointPath(String service, String version) {
248+
return String.format("/soap/%s/%s", service, version);
239249
}
240250

241251
/**
@@ -245,7 +255,17 @@ public String getSoapMockEndpoint(String service, String version) {
245255
* @return A usable endpoint to interact with Microcks mocks.
246256
*/
247257
public String getRestMockEndpoint(String service, String version) {
248-
return String.format("%s/rest/%s/%s", getHttpEndpoint(), service, version);
258+
return String.format("%s/rest/%s/%s", getHttpEndpoint(), service, version);
259+
}
260+
261+
/**
262+
* Get the exposed mock endpoint path for a REST API.
263+
* @param service The name of Service/API
264+
* @param version The version of Service/API
265+
* @return A path endpoint to interact with Microcks mocks - starts with '/'.
266+
*/
267+
public String getRestMockEndpointPath(String service, String version) {
268+
return String.format("/rest/%s/%s", service, version);
249269
}
250270

251271
/**
@@ -258,6 +278,16 @@ public String getGraphQLMockEndpoint(String service, String version) {
258278
return String.format("%s/graphql/%s/%s", getHttpEndpoint(), service, version);
259279
}
260280

281+
/**
282+
* Get the exposed mock endpoint path for a GRPC Service.
283+
* @param service The name of Service/API
284+
* @param version The version of Service/API
285+
* @return A path endpoint to interact with Microcks mocks - starts with '/'.
286+
*/
287+
public String getGraphQLMockEndpointPath(String service, String version) {
288+
return String.format("/graphql/%s/%s", service, version);
289+
}
290+
261291
/**
262292
* Get the exposed mock endpoint for a GRPC Service.
263293
* @return A usable endpoint to interact with Microcks mocks.

src/main/java/io/github/microcks/testcontainers/MicrocksContainersEnsemble.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
*/
3939
public class MicrocksContainersEnsemble implements Startable {
4040

41+
/** The default network alias for Microcks container. */
42+
public static final String MICROCKS_CONTAINER_ALIAS = "microcks";
43+
/** The default network alias for Postman container. */
44+
public static final String POSTMAN_CONTAINER_ALIAS = "postman";
45+
/** The default network alias for Async Minion container. */
46+
public static final String MICROCKS_ASYNC_MINION_CONTAINER_ALIAS = "microcks-async-minion";
47+
4148
private final Network network;
4249

4350
private GenericContainer<?> postman;
@@ -79,10 +86,12 @@ public MicrocksContainersEnsemble(Network network, DockerImageName image) {
7986
this.network = network;
8087
this.microcks = new MicrocksContainer(image)
8188
.withNetwork(network)
82-
.withNetworkAliases("microcks")
89+
.withNetworkAliases(MICROCKS_CONTAINER_ALIAS)
8390
.withEnv("POSTMAN_RUNNER_URL", "http://postman:3000")
84-
.withEnv("TEST_CALLBACK_URL", "http://microcks:" + MicrocksContainer.MICROCKS_HTTP_PORT)
85-
.withEnv("ASYNC_MINION_URL", "http://microcks-async-minion:" + MicrocksAsyncMinionContainer.MICROCKS_ASYNC_MINION_HTTP_PORT);
91+
.withEnv("TEST_CALLBACK_URL", "http://" + MICROCKS_CONTAINER_ALIAS
92+
+ ":" + MicrocksContainer.MICROCKS_HTTP_PORT)
93+
.withEnv("ASYNC_MINION_URL", "http://" + MICROCKS_ASYNC_MINION_CONTAINER_ALIAS
94+
+ ":" + MicrocksAsyncMinionContainer.MICROCKS_ASYNC_MINION_HTTP_PORT);
8695
}
8796

8897
/**
@@ -101,7 +110,7 @@ public MicrocksContainersEnsemble withPostman() {
101110
public MicrocksContainersEnsemble withPostman(String image) {
102111
this.postman = new GenericContainer<>(DockerImageName.parse(image))
103112
.withNetwork(network)
104-
.withNetworkAliases("postman")
113+
.withNetworkAliases(POSTMAN_CONTAINER_ALIAS)
105114
.waitingFor(Wait.forLogMessage(".*postman-runtime wrapper listening on port.*", 1));
106115
return this;
107116
}
@@ -114,7 +123,7 @@ public MicrocksContainersEnsemble withPostman(String image) {
114123
public MicrocksContainersEnsemble withPostman(DockerImageName image) {
115124
this.postman = new GenericContainer<>(image)
116125
.withNetwork(network)
117-
.withNetworkAliases("postman")
126+
.withNetworkAliases(POSTMAN_CONTAINER_ALIAS)
118127
.waitingFor(Wait.forLogMessage(".*postman-runtime wrapper listening on port.*", 1));
119128
return this;
120129
}

src/test/java/io/github/microcks/testcontainers/MicrocksContainerTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ private void testMockEndpoints(MicrocksContainer microcks) {
219219

220220
String baseGrpcUrl = microcks.getGrpcMockEndpoint();
221221
assertEquals("grpc://" + microcks.getHost() + ":" + microcks.getMappedPort(MicrocksContainer.MICROCKS_GRPC_PORT), baseGrpcUrl);
222+
223+
String baseWsPath = microcks.getSoapMockEndpointPath("Pastries Service", "1.0");
224+
assertEquals("/soap/Pastries Service/1.0", baseWsPath);
225+
226+
String baseApiPath = microcks.getRestMockEndpointPath("API Pastries", "0.0.1");
227+
assertEquals("/rest/API Pastries/0.0.1", baseApiPath);
228+
229+
String baseGraphPath = microcks.getGraphQLMockEndpointPath("Pastries Graph", "1");
230+
assertEquals("/graphql/Pastries Graph/1", baseGraphPath);
222231
}
223232

224233
private void testMicrocksMockingFunctionality(MicrocksContainer microcks) {

0 commit comments

Comments
 (0)