Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wiremock mock returning HTTP 500

I am using wireMock and I am getting a consistent response of 500 Internal Server Error even though the stubbed response is 200 OK.

If I debug, I see the connection is always closed. Any idea what might be going wrong? Or what I am doing wrong.

Here's the test

public class MyControllerTest {

@Autowired
MyController myController;

String id1 = "id1";
String id2 = "id2";
Integer offset = 0;
Integer limit = 1;
int port = 8080;
protected WireMockServer wireMockServer;

@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(port);

@Test
public void hosDriversHoursOfServiceGet() throws Exception {
    stubFor(WireMock.get(urlEqualTo("/path/endPoint"))
                    .withQueryParam("id1", equalTo(id1))
                    .withQueryParam("id2", equalTo(id2))
                    .withQueryParam("limit", equalTo(limit.toString()))
                    .withQueryParam("offset", equalTo(offset.toString()))
                    .willReturn(aResponse().withStatus(200).withBody((getJsonString()))));
Response response = myController.hosDriversHoursOfServiceGet(driverId, 1, 1);
    assertEquals(Integer.valueOf(1), response.getCount());
}

private String getJsonString() {
    return "{\"count\":1}";
}


}

Trying to mock: http://localhost:8080/path/endPoint?id1={id1}&id2={id2}&limit={limit}&offset={offset}

The above call is made in a client class which is autowired in MyController. Is that even possible to mock since it's not a direct call?

like image 383
Pavanraotk Avatar asked Apr 26 '17 23:04

Pavanraotk


1 Answers

The issue is resolved, it's all related to Javax-servlet-api dependency in wiremock and my application. Changed the wiremock from wiremock 2.6.0 to wiremock-standalone, which used application's servlet-api dependency, essentially it worked.

Not sure if this is the right answer, but it worked.

like image 158
Pavanraotk Avatar answered Sep 26 '22 23:09

Pavanraotk