0
@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.

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • Which version of Vert.x do you use? This lazy HttpRequest creation `createHttpClient().get(...)` was removed up to 3 years ago. – zforgo Mar 06 '23 at 18:58
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 07 '23 at 04:49
  • @zforgo vertx version is 3.5.2, all i was trying to write an integration test case to test my API – AnilSrinivas Muddineni Mar 07 '23 at 16:10

0 Answers0