I have an endpoint that makes a request to a server to check the status. I use WebClient
with vertex
. I create a client like this.
WebClient client = WebClient.create(vertx);
and the request looks like the following
client.get(check.url).send(ar -> {
HttpResponse<Buffer> resp = ar.result();
if (resp != null) {
check.response = resp.bodyAsString();
} else {
check.response = "";
}
logger.debug("Received response from app: {} with result:{} on url:{} : {}",
check.appName, check.result, check.url, check.response);
check.result.complete(ar.succeeded());
});
The problem i have is when the client tries to send the request. EDIT: I want to mock that client.send() and return my WebClient with the status I want like 200 or 400. Please be advised that I can't access this WebClient as it's declared under the method I want to test.
I have this test right now that I'm trying to fix. TEST
@Test
public void testWongUrlsAndNormalMode() throws Exception{
when(healthCheckEndpoint.configuration.getMode()).thenReturn(HealthCheckerConfiguration.HealthCheckMode.NORMAL);
when(healthCheckEndpoint.configuration.getHealthCheckUrls()).thenReturn(urls);
Response a = healthCheckEndpoint.checkApplications(); //here is when the client.get(url).send() returns nullPointerException
assertEquals(a.getStatus(), 500);
assertEquals(a.getEntity(), "normal mode no app urls");
}
but as mentioned i get a null pointer exception when the WebClient tries to send the request. I have also tried to mock the WebClient but I can't mock the send() method as it is a void method