简体   繁体   中英

Java REST API GET test

im wondering how to test GET given below. I don't have much experience with testing so would be glad if some 1 could show me proper approach or comment what should i do better.

@Path("/some")
public class SomeApi {

    @Inject
    SomeLogic someLogic;

    @GET
    @Produces({"application/json;charset=utf-8","application/json"})
    @RolesAllowed("ek_external")
    public Response getSome(@QueryParam("id") Long id, @QueryParam("name") String name, @Min(0) @DefaultValue("0") @QueryParam("offset") Integer offset, @Min(1) @Max(50) @DefaultValue("20") @QueryParam("limit") Integer limit, @Context SecurityContext securityContext) {
        return someLogic.getSome(id, name, offset, limit, securityContext);
    }
}

This is my GET. Im not sure how to handle all these QueryParams and annotated args.

Im trying something like this

@QuarkusTest
public class SomeApiTest {

    @Test
    public void testGetSome() {
        given()
                .when().get("/some")
                .then()
                .statusCode(200)
                .body()
    }
}

i ll be glad for showing me which way to go :)

The example in the documentation here: https://quarkus.io/guides/getting-started-testing#recap-of-http-based-testing-in-jvm-mode suggests the only thing missing might be setting the body... ...(200).body(is(someBody)) .

The example given here: https://quarkus.io/guides/getting-started-testing#restassured also looks relevant.

Also ensure you provide @TestConfiguration so that when you @Inject the class for SomeLogic , it is not null .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM