Search in sources :

Example 6 with OrderBean

use of io.confluent.examples.streams.microservices.domain.beans.OrderBean in project kafka-streams-examples by confluentinc.

the class OrdersServiceTest method shouldGetValidatedOrderOnRequest.

@Test
public void shouldGetValidatedOrderOnRequest() {
    Order orderV1 = new Order(id(1L), 3L, OrderState.CREATED, Product.JUMPERS, 10, 100d);
    OrderBean beanV1 = OrderBean.toBean(orderV1);
    final Client client = ClientBuilder.newClient();
    // Given a rest service
    rest = new OrdersService("localhost");
    rest.start(CLUSTER.bootstrapServers());
    Paths paths = new Paths("localhost", rest.port());
    // When we post an order
    client.target(paths.urlPost()).request(APPLICATION_JSON_TYPE).post(Entity.json(beanV1));
    // Simulate the order being validated
    MicroserviceTestUtils.sendOrders(Collections.singletonList(newBuilder(orderV1).setState(OrderState.VALIDATED).build()));
    // When we GET the order from the returned location
    OrderBean returnedBean = client.target(paths.urlGetValidated(beanV1.getId())).queryParam("timeout", MIN / 2).request(APPLICATION_JSON_TYPE).get(new GenericType<OrderBean>() {
    });
    // Then status should be Validated
    assertThat(returnedBean.getState()).isEqualTo(OrderState.VALIDATED);
}
Also used : Order(io.confluent.examples.streams.avro.microservices.Order) Paths(io.confluent.examples.streams.microservices.util.Paths) OrderBean(io.confluent.examples.streams.microservices.domain.beans.OrderBean) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 7 with OrderBean

use of io.confluent.examples.streams.microservices.domain.beans.OrderBean in project kafka-streams-examples by confluentinc.

the class OrdersServiceTest method shouldGetOrderByIdWhenOnDifferentHost.

@Test
public void shouldGetOrderByIdWhenOnDifferentHost() {
    OrderBean order = new OrderBean(id(1L), 4L, OrderState.VALIDATED, Product.JUMPERS, 10, 100d);
    final Client client = ClientBuilder.newClient();
    // Given two rest servers on different ports
    rest = new OrdersService("localhost");
    rest.start(CLUSTER.bootstrapServers());
    Paths paths1 = new Paths("localhost", rest.port());
    rest2 = new OrdersService("localhost");
    rest2.start(CLUSTER.bootstrapServers());
    Paths paths2 = new Paths("localhost", rest2.port());
    // And one order
    client.target(paths1.urlPost()).request(APPLICATION_JSON_TYPE).post(Entity.json(order));
    // When GET to rest1
    OrderBean returnedOrder = client.target(paths1.urlGet(order.getId())).queryParam("timeout", MIN / 2).request(APPLICATION_JSON_TYPE).get(new GenericType<OrderBean>() {
    });
    // Then we should get the order back
    assertThat(returnedOrder).isEqualTo(order);
    // When GET to rest2
    returnedOrder = client.target(paths2.urlGet(order.getId())).queryParam("timeout", MIN / 2).request(APPLICATION_JSON_TYPE).get(new GenericType<OrderBean>() {
    });
    // Then we should get the order back also
    assertThat(returnedOrder).isEqualTo(order);
}
Also used : GenericType(javax.ws.rs.core.GenericType) Paths(io.confluent.examples.streams.microservices.util.Paths) OrderBean(io.confluent.examples.streams.microservices.domain.beans.OrderBean) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 8 with OrderBean

use of io.confluent.examples.streams.microservices.domain.beans.OrderBean in project kafka-streams-examples by confluentinc.

the class OrdersServiceTest method shouldPostOrderAndGetItBack.

@Test
public void shouldPostOrderAndGetItBack() {
    OrderBean bean = new OrderBean(id(1L), 2L, OrderState.CREATED, Product.JUMPERS, 10, 100d);
    final Client client = ClientBuilder.newClient();
    // Given a rest service
    rest = new OrdersService("localhost");
    rest.start(CLUSTER.bootstrapServers());
    Paths paths = new Paths("localhost", rest.port());
    // When we POST an order
    Response response = client.target(paths.urlPost()).request(APPLICATION_JSON_TYPE).post(Entity.json(bean));
    // Then
    assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_CREATED);
    // When GET the bean back via it's location
    OrderBean returnedBean = client.target(response.getLocation()).queryParam("timeout", MIN / 2).request(APPLICATION_JSON_TYPE).get(new GenericType<OrderBean>() {
    });
    // Then it should be the bean we PUT
    assertThat(returnedBean).isEqualTo(bean);
    // When GET the bean back explicitly
    returnedBean = client.target(paths.urlGet(1)).queryParam("timeout", MIN / 2).request(APPLICATION_JSON_TYPE).get(new GenericType<OrderBean>() {
    });
    // Then it should be the bean we PUT
    assertThat(returnedBean).isEqualTo(bean);
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) Paths(io.confluent.examples.streams.microservices.util.Paths) OrderBean(io.confluent.examples.streams.microservices.domain.beans.OrderBean) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Aggregations

OrderBean (io.confluent.examples.streams.microservices.domain.beans.OrderBean)8 Test (org.junit.Test)7 Paths (io.confluent.examples.streams.microservices.util.Paths)4 Client (javax.ws.rs.client.Client)4 KeyValue (org.apache.kafka.streams.KeyValue)3 GenericType (javax.ws.rs.core.GenericType)2 Order (io.confluent.examples.streams.avro.microservices.Order)1 URISyntaxException (java.net.URISyntaxException)1 ServerErrorException (javax.ws.rs.ServerErrorException)1 Response (javax.ws.rs.core.Response)1 InvalidStateStoreException (org.apache.kafka.streams.errors.InvalidStateStoreException)1