Hi there! I’m trying to follow the WireMock/Testco...
# help
e
Hi there! I’m trying to follow the WireMock/Testcontainers guide at https://wiremock.org/docs/solutions/testcontainers/ and can’t seem to get the container running. Not sure if maybe I’m just doing things wrong. When I use
Copy code
private final WireMockContainer wireMockContainer =
		new WireMockContainer(DockerImageName.parse("wiremock/wiremock:2.35.0-1"))
			.withMapping("twitter",  "wiremock/mappings/twitter.com-current-stubs.json");
The container never starts up
Copy code
2023-07-19 14:38:13,104 INFO  [org.tes.con.wai.str.HttpWaitStrategy] (pool-2-thread-1) /goofy_ishizaka: Waiting for 60 seconds for URL: <http://localhost:58970/__admin/mappings> (where port 58970 maps to container port 8080)
2023-07-19 14:39:13,126 ERROR [tc.wir.35.0-1] (pool-2-thread-1) Could not start container: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
If I remove the
.withMapping
then it works fine. Here’s a screenshot of my filesystem layout:
and it seems to work ok if I do this:
Copy code
private final WireMockContainer wireMockContainer =
		new WireMockContainer(DockerImageName.parse("wiremock/wiremock:2.35.0-1"))
			.withClasspathResourceMapping("wiremock", "/home/wiremock", BindMode.READ_ONLY);
wondering what i’m doing wrong with
.withMapping
l
Hi Eric, haven’t used this myself but from looking at the wiremock test containers code I am wondering whether the
.withMapping(name, json)
method means you need to pass the contents of the json file as a
String
rather than the path to the json file ?
e
Thanks Lee for the reply. That’s not what I see on https://wiremock.org/docs/solutions/testcontainers/
it looks like its just some json file, but I wish the documentation showed the layout of the project & filesystem
l
That
.withMapping
method is different from the one you are using though I think ?
e
i first tried
Copy code
private final WireMockContainer wireMockContainer =
		new WireMockContainer(DockerImageName.parse("wiremock/wiremock:2.35.0-1"))
			.withMapping("twitter",  "wiremock/mappings/twitter.com-current-stubs.json");
and that was getting the error
so I switched to
Copy code
private final WireMockContainer wireMockContainer =
		new WireMockContainer(DockerImageName.parse("wiremock/wiremock:2.35.0-1"))
			.withClasspathResourceMapping("wiremock", "/home/wiremock", BindMode.READ_ONLY);
and that does work
but makes me have to know more about the structure of the image and how the filesystem is laid out
l
Maybe I am reading this wrong. In the wiremock docs, they are using
public WireMockContainer withMapping(String name, Class<?> resource, String resourceJson)
.
Your code looks like you are using
public WireMockContainer withMapping(String name, String json)
e
i got some much different error when i used the signature with the
Class
And the structure of the mapping files
e
ahhhh let me try that
l
Never used it myself so running a little blind here but hopefully that might work
e
yeah that works
just would be nice to not have to create a folder structure like
com/acme/todo/WIremockResourceTestLifecycleManager
Maybe you’re right though on the
.withMapping
that doesn’t take a class. maybe it expects the actual json
and not a file reference
👍 2
l
Awesome. Maybe try loading the json file from the classpath into a string and passing the whole json string into the
withMapping(String name, String json)
I guess that would allow you to have the folder structure you want but would require a little classpath to String code
e
yeah but now i’m dealing with handling all the checked exceptions in the
Files
&
Paths
classes 🙂 Which doesn’t work if it want to set it up as a class-level attribute 🙂
damn java
l
😀
e
so i’ll take the small win
🙂
l
Kotlin ?
e
ha!
don’t even suggest Lombok to me…
l
Ha. Haven’t used that for ages now.
e
Lombok & I don’t get along
l
I had the same relationship with Lombok. We parted ways a long time ago.
Glad it worked in the end even if the folder structure isn’t perfect.
e
now if it only had a verification API 🙂
l
🤔
o
@Eric Deandrea I guess it is the same as https://github.com/wiremock/wiremock-testcontainers-java/issues/61 . It also reminds me that we should publish Javadoc...
👍 1
@Eric Deandrea do you also use JitPack at the moment? It provides Javadoc, so you should be getting help for methods in all modern IDEs https://github.com/wiremock/wiremock-testcontainers-java/blob/main/src/main/java/org/wiremock/integrations/testcontainers/WireMockContainer.java#L127-L135
151 Views