@Test
public void dummyTestCase() {
System.out.println(" dummyTestCase ");
HttpClient client = vertx.createHttpClient();
client.request(HttpMethod.GET, 8080, "localhost", "/api/user",
HttpClientResponse -> {
System.out.println(" dummyTestCase inside ");
context.assertEquals(HttpClientResponse.statusCode(), 200);
});
}
@Test
public void getUsers() {
System.out.println("Inside getusers ");
Async async = context.async();
vertx.createHttpClient().get("localhost", "/api/user",
response -> {
System.out.println("Inside vertx");
context.assertEquals(response.statusCode(), 200);
context.assertEquals(response.headers().get("content-type"), "application/json");
response.bodyHandler(body -> {
context.assertTrue(body.toString().contains("Collection"));
async.complete();
});
});
}
I've tried creating integration testing to test API like above two ways but the end point mentioned was not calling. Below is my serviceVertical
class snippet.
@Override
public void start() throws Exception {
// Server Configuration
final HttpServerOptions serverOptions = new HttpServerOptions()
.setCompressionSupported(config().getBoolean("api.compress", true))
.setCompressionLevel(config().getInteger("api.compress.level", 7))
.setDecompressionSupported(config().getBoolean("api.compress", true))
.setHost(config().getString("api.host", "0.0.0.0"))
.setPort(config().getInteger("api.port", 8080));
final Router router = Router.router(vertx);
final HttpServer httpServer = vertx.createHttpServer(serverOptions);
logger.info("Info");
if (!config().getBoolean("authentication.bypass",false)) {
AuthHandler authHandler = JWTAuthHandler.create(new JWTAuth(
config().getString("authentication.issuer"),
config().getBoolean("authentication.bypass"),
config().getString("authentication.clientid")),
"/api/camel/sample");
router.route("/api/*").handler(authHandler);
}
UserService userService = new UserService(config(), vertx);
GroupService groupService = new GroupService(config());
AllService allService = new AllService(config(), vertx);
// users
router.route().handler(BodyHandler.create());
router.route(HttpMethod.GET, "/api/user").handler(e -> { userService.getUsers(e); });
httpServer.requestHandler(router::accept).listen();
logger.info("Service verticle started.");
}
I tried calling the endpoint in the ways mentioned above but they did not work.