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);
}
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);
}
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);
}
Aggregations