Hello, I am using testcontainers with wiremock, bu...
# help
Hello, I am using testcontainers with wiremock, but I am getting the error: connect to localhost:8080 failed connection refused no further information. Please suggest some solution to this.
Could you please share the code?
Also note that a random port is set by default in WireMock Testcontainers. You should use the
wiremockServer.getUrl(String relative)
method for the majority of operations in your test clients
Hello @Oleg Nenashev thanks for responding Here is the sample code from the poc that I am doing
Copy code
import com.github.tomakehurst.wiremock.client.WireMock;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

import static org.assertj.core.api.Assertions.assertThat;

public class WireMockContainerPOC {

    public GenericContainer<?> wireMockContainer = new GenericContainer<>(DockerImageName.parse("rodolpheche/wiremock:2.27.2"))

    public void testStubbedAPI() {
        String wireMockBaseUrl = "http://" + wireMockContainer.getHost() + ":" + wireMockContainer.getMappedPort(8080);


                                .withHeader("Content-Type", "application/json")
                                .withBody("{\"message\": \"Stubbed Response\"}"))

        // Make a request to the stubbed API
        String response = wireMockContainer.getHost() + ":" + wireMockContainer.getMappedPort(8080) + "/api/endpoint";

        // Assertions
        assertThat(response).isEqualTo("{\"message\": \"Stubbed Response\"}");

I would need to debug it but I don't see any issue immediately. At the same time, why don't you use https://github.com/wiremock/wiremock-testcontainers-java ?
Regarding your code, I suppose the docker image fails to start, maybe because of missing some configuration. You use an old version of WireMock and the image, so I would advise upgrading before spending too much time on that
oh okay, I faced the same issue with wiremock 2.35.0 as well. I had tried to use https://github.com/wiremock/wiremock-testcontainers-java as well, but I am getting the same error
Do you see anything in the container startup log?
No Oleg
It exits as soon as it starts running
Did you try that environment manually? It is unlikely to exit without no logs at all
I mean manual
docker run
so, when I do docker run. followed by the image name, I can see that the port is 8080 and the rest is all false
@Oleg Nenashev please advice me on this
@Oleg Nenashev Another error that I get while running this https://github.com/wiremock/wiremock-testcontainers-java is
Copy code
Resource WireMockContainerTest/hello-world.json relative to org.wiremock.integrations.testcontainers.WireMockContainerTest not found
I had placed the json mapping exactly like in the repo