io.restassured.common.mapper.TypeRef Java Examples

The following examples show how to use io.restassured.common.mapper.TypeRef. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArtemisHealthCheckTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    Response response = RestAssured.with().get("/health/ready");
    Assertions.assertEquals(Status.OK.getStatusCode(), response.statusCode());

    Map<String, Object> body = response.as(new TypeRef<Map<String, Object>>() {
    });
    Assertions.assertEquals("UP", body.get("status"));

    @SuppressWarnings("unchecked")
    List<Map<String, Object>> checks = (List<Map<String, Object>>) body.get("checks");
    Assertions.assertEquals(1, checks.size());
    Assertions.assertEquals("Artemis Core health check", checks.get(0).get("name"));
}
 
Example #2
Source File: ArtemisHealthCheckTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    Response response = RestAssured.with().get("/health/ready");
    Assertions.assertEquals(Status.OK.getStatusCode(), response.statusCode());

    Map<String, Object> body = response.as(new TypeRef<Map<String, Object>>() {
    });
    Assertions.assertEquals("UP", body.get("status"));

    @SuppressWarnings("unchecked")
    List<Map<String, Object>> checks = (List<Map<String, Object>>) body.get("checks");
    Assertions.assertEquals(1, checks.size());
    Assertions.assertEquals("Artemis JMS health check", checks.get(0).get("name"));
}
 
Example #3
Source File: PriceTest.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    // Check we don't have any prices
    List<Price> prices = RestAssured.get("/prices/all").as(new TypeRef<List<Price>>() {});
    Assertions.assertTrue(prices.isEmpty());

    // Stream the prices
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(PRICES_SSE_ENDPOINT);
    List<Double> received = new CopyOnWriteArrayList<>();
    SseEventSource source = SseEventSource.target(target).build();
    source.register(inboundSseEvent -> received.add(Double.valueOf(inboundSseEvent.readData())));
    source.open();

    // Send the prices
    Price p1 = new Price();
    p1.value = 1.0;
    Price p2 = new Price();
    p2.value = 4.0;
    Price p3 = new Price();
    p3.value = 2.0;
    RestAssured.given().header("Content-Type", "application/json").body(p1).post("/").then().statusCode(204);
    RestAssured.given().header("Content-Type", "application/json").body(p2).post("/").then().statusCode(204);
    RestAssured.given().header("Content-Type", "application/json").body(p3).post("/").then().statusCode(204);

    await().atMost(100000, MILLISECONDS).until(() -> received.size() == 3);
    source.close();

    Assertions.assertTrue(received.contains(p1.value));
    Assertions.assertTrue(received.contains(p2.value));
    Assertions.assertTrue(received.contains(p3.value));

    prices = RestAssured.get("/prices/all").as(new TypeRef<List<Price>>() {});
    Assertions.assertEquals(prices.size(), 3);
}
 
Example #4
Source File: BookResourceTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private void callTheEndpoint(String endpoint) {
    List<Book> list = get(endpoint).as(new TypeRef<List<Book>>() {
    });
    Assertions.assertEquals(0, list.size());

    Book book1 = new Book().setAuthor("Victor Hugo").setTitle("Les Misérables")
            .setCategories(Arrays.asList("long", "very long"))
            .setDetails(new BookDetail().setRating(3).setSummary("A very long book"));
    Response response = RestAssured
            .given()
            .header("Content-Type", "application/json")
            .body(book1)
            .post(endpoint)
            .andReturn();
    Assertions.assertEquals(202, response.statusCode());

    Book book2 = new Book().setAuthor("Victor Hugo").setTitle("Notre-Dame de Paris")
            .setCategories(Arrays.asList("long", "quasimodo"))
            .setDetails(new BookDetail().setRating(4).setSummary("quasimodo and esmeralda"));
    response = RestAssured
            .given()
            .header("Content-Type", "application/json")
            .body(book2)
            .post(endpoint)
            .andReturn();
    Assertions.assertEquals(202, response.statusCode());

    list = get(endpoint).as(new TypeRef<List<Book>>() {
    });
    Assertions.assertEquals(2, list.size());

    Book book3 = new Book().setAuthor("Charles Baudelaire").setTitle("Les fleurs du mal")
            .setCategories(Collections.singletonList("poem"))
            .setDetails(new BookDetail().setRating(2).setSummary("Les Fleurs du mal is a volume of poetry."));
    response = RestAssured
            .given()
            .header("Content-Type", "application/json")
            .body(book3)
            .post(endpoint)
            .andReturn();
    Assertions.assertEquals(202, response.statusCode());

    list = get(endpoint).as(new TypeRef<List<Book>>() {
    });
    Assertions.assertEquals(3, list.size());

    list = get(endpoint + "/Victor Hugo").as(new TypeRef<List<Book>>() {
    });
    Assertions.assertEquals(2, list.size());
}
 
Example #5
Source File: PetApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * POST /fake/{petId}/uploadImageWithRequiredFile
 * @param handler handler
 * @return ModelApiResponse
 */
public ModelApiResponse executeAs(Function<Response, Response> handler) {
    TypeRef<ModelApiResponse> type = new TypeRef<ModelApiResponse>(){};
    return execute(handler).as(type);
}
 
Example #6
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * PATCH /fake
 * @param handler handler
 * @return Client
 */
public Client executeAs(Function<Response, Response> handler) {
    TypeRef<Client> type = new TypeRef<Client>(){};
    return execute(handler).as(type);
}
 
Example #7
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * POST /fake/outer/string
 * @param handler handler
 * @return String
 */
public String executeAs(Function<Response, Response> handler) {
    TypeRef<String> type = new TypeRef<String>(){};
    return execute(handler).as(type);
}
 
Example #8
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * POST /fake/outer/number
 * @param handler handler
 * @return BigDecimal
 */
public BigDecimal executeAs(Function<Response, Response> handler) {
    TypeRef<BigDecimal> type = new TypeRef<BigDecimal>(){};
    return execute(handler).as(type);
}
 
Example #9
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * POST /fake/outer/composite
 * @param handler handler
 * @return OuterComposite
 */
public OuterComposite executeAs(Function<Response, Response> handler) {
    TypeRef<OuterComposite> type = new TypeRef<OuterComposite>(){};
    return execute(handler).as(type);
}
 
Example #10
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * POST /fake/outer/boolean
 * @param handler handler
 * @return Boolean
 */
public Boolean executeAs(Function<Response, Response> handler) {
    TypeRef<Boolean> type = new TypeRef<Boolean>(){};
    return execute(handler).as(type);
}
 
Example #11
Source File: FakeClassnameTags123Api.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * PATCH /fake_classname_test
 * @param handler handler
 * @return Client
 */
public Client executeAs(Function<Response, Response> handler) {
    TypeRef<Client> type = new TypeRef<Client>(){};
    return execute(handler).as(type);
}
 
Example #12
Source File: StoreApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * GET /store/inventory
 * @param handler handler
 * @return Map&lt;String, Integer&gt;
 */
public Map<String, Integer> executeAs(Function<Response, Response> handler) {
    TypeRef<Map<String, Integer>> type = new TypeRef<Map<String, Integer>>(){};
    return execute(handler).as(type);
}
 
Example #13
Source File: PetApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * POST /pet/{petId}/uploadImage
 * @param handler handler
 * @return ModelApiResponse
 */
public ModelApiResponse executeAs(Function<Response, Response> handler) {
    TypeRef<ModelApiResponse> type = new TypeRef<ModelApiResponse>(){};
    return execute(handler).as(type);
}
 
Example #14
Source File: PetApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * GET /pet/{petId}
 * @param handler handler
 * @return Pet
 */
public Pet executeAs(Function<Response, Response> handler) {
    TypeRef<Pet> type = new TypeRef<Pet>(){};
    return execute(handler).as(type);
}
 
Example #15
Source File: PetApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * GET /pet/findByTags
 * @param handler handler
 * @return Set&lt;Pet&gt;
 */
public Set<Pet> executeAs(Function<Response, Response> handler) {
    TypeRef<Set<Pet>> type = new TypeRef<Set<Pet>>(){};
    return execute(handler).as(type);
}
 
Example #16
Source File: PetApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * GET /pet/findByStatus
 * @param handler handler
 * @return List&lt;Pet&gt;
 */
public List<Pet> executeAs(Function<Response, Response> handler) {
    TypeRef<List<Pet>> type = new TypeRef<List<Pet>>(){};
    return execute(handler).as(type);
}
 
Example #17
Source File: UserApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * GET /user/login
 * @param handler handler
 * @return String
 */
public String executeAs(Function<Response, Response> handler) {
    TypeRef<String> type = new TypeRef<String>(){};
    return execute(handler).as(type);
}
 
Example #18
Source File: UserApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * GET /user/{username}
 * @param handler handler
 * @return User
 */
public User executeAs(Function<Response, Response> handler) {
    TypeRef<User> type = new TypeRef<User>(){};
    return execute(handler).as(type);
}
 
Example #19
Source File: AnotherFakeApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * PATCH /another-fake/dummy
 * @param handler handler
 * @return Client
 */
public Client executeAs(Function<Response, Response> handler) {
    TypeRef<Client> type = new TypeRef<Client>(){};
    return execute(handler).as(type);
}
 
Example #20
Source File: StoreApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * POST /store/order
 * @param handler handler
 * @return Order
 */
public Order executeAs(Function<Response, Response> handler) {
    TypeRef<Order> type = new TypeRef<Order>(){};
    return execute(handler).as(type);
}
 
Example #21
Source File: StoreApi.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * GET /store/order/{order_id}
 * @param handler handler
 * @return Order
 */
public Order executeAs(Function<Response, Response> handler) {
    TypeRef<Order> type = new TypeRef<Order>(){};
    return execute(handler).as(type);
}