https://linen.dev logo
#help
Title
# help
e

Eric Deandrea

07/19/2023, 6:52 PM
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

Lee Turner

07/19/2023, 8:40 PM
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

Eric Deandrea

07/19/2023, 8:40 PM
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

Lee Turner

07/19/2023, 8:43 PM
That
.withMapping
method is different from the one you are using though I think ?
e

Eric Deandrea

07/19/2023, 8:44 PM
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

Lee Turner

07/19/2023, 8:45 PM
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

Eric Deandrea

07/19/2023, 8:46 PM
i got some much different error when i used the signature with the
Class
And the structure of the mapping files
e

Eric Deandrea

07/19/2023, 8:48 PM
ahhhh let me try that
l

Lee Turner

07/19/2023, 8:48 PM
Never used it myself so running a little blind here but hopefully that might work
e

Eric Deandrea

07/19/2023, 8:50 PM
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

Lee Turner

07/19/2023, 8:51 PM
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

Eric Deandrea

07/19/2023, 8:58 PM
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

Lee Turner

07/19/2023, 8:58 PM
😀
e

Eric Deandrea

07/19/2023, 8:59 PM
so i’ll take the small win
🙂
l

Lee Turner

07/19/2023, 8:59 PM
Kotlin ?
e

Eric Deandrea

07/19/2023, 8:59 PM
ha!
don’t even suggest Lombok to me…
l

Lee Turner

07/19/2023, 8:59 PM
Ha. Haven’t used that for ages now.
e

Eric Deandrea

07/19/2023, 9:00 PM
Lombok & I don’t get along
l

Lee Turner

07/19/2023, 9:00 PM
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

Eric Deandrea

07/19/2023, 9:01 PM
now if it only had a verification API 🙂
l

Lee Turner

07/19/2023, 9:01 PM
🤔
o

Oleg Nenashev

07/20/2023, 7:58 AM
@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
35 Views