Search in sources :

Example 1 with Price

use of org.acme.context.Price in project quarkus-quickstarts by quarkusio.

the class PriceTest method test.

@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);
}
Also used : SseEventSource(javax.ws.rs.sse.SseEventSource) Price(org.acme.context.Price) TypeRef(io.restassured.common.mapper.TypeRef) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 TypeRef (io.restassured.common.mapper.TypeRef)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Client (javax.ws.rs.client.Client)1 WebTarget (javax.ws.rs.client.WebTarget)1 SseEventSource (javax.ws.rs.sse.SseEventSource)1 Price (org.acme.context.Price)1 Test (org.junit.jupiter.api.Test)1