Search in sources :

Example 6 with Paths

use of io.confluent.examples.streams.microservices.util.Paths 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 7 with Paths

use of io.confluent.examples.streams.microservices.util.Paths 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

Paths (io.confluent.examples.streams.microservices.util.Paths)7 OrderBean (io.confluent.examples.streams.microservices.domain.beans.OrderBean)4 Client (javax.ws.rs.client.Client)4 Test (org.junit.Test)4 HostStoreInfo (io.confluent.examples.streams.interactivequeries.HostStoreInfo)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 GenericType (javax.ws.rs.core.GenericType)2 ManagedAsync (org.glassfish.jersey.server.ManagedAsync)2 Order (io.confluent.examples.streams.avro.microservices.Order)1 Produces (javax.ws.rs.Produces)1 ServerErrorException (javax.ws.rs.ServerErrorException)1 Response (javax.ws.rs.core.Response)1 Before (org.junit.Before)1