Search in sources :

Example 1 with Response

use of br.com.caelum.restfulie.Response in project restfulie-java by caelum.

the class ClientTest method search.

private Response search(String term, int page) {
    Response response = restfulie.at("http://localhost:3000/products/opensearch.xml").accept("application/opensearchdescription+xml").get();
    SearchDescription desc = response.getResource();
    response = desc.use("application/xml").with(queryFor(term)).and(page(page)).get();
    return response;
}
Also used : Response(br.com.caelum.restfulie.Response) SearchDescription(br.com.caelum.restfulie.opensearch.SearchDescription)

Example 2 with Response

use of br.com.caelum.restfulie.Response in project restfulie-java by caelum.

the class ClientTest method shouldBeAbleToCreateAnEmptyOrder.

@Test
public void shouldBeAbleToCreateAnEmptyOrder() {
    Response response = search("20", 1);
    List<Product> products = response.getResource();
    response = resource(products).getLink("order").follow().accept("application/xml").post(newOrder("Av. Princesa Isabel 350, Copacabana, Rio de Janeiro"));
    Order order = response.getResource();
    assertThat(order.getAddress(), is(equalTo("Av. Princesa Isabel 350, Copacabana, Rio de Janeiro")));
}
Also used : Response(br.com.caelum.restfulie.Response) Test(org.junit.Test)

Example 3 with Response

use of br.com.caelum.restfulie.Response in project restfulie-java by caelum.

the class ClientTest method shouldBeAbleToAddAnItemToAnOrder.

@Test
public void shouldBeAbleToAddAnItemToAnOrder() {
    Response response = search("20", 1);
    List<Product> product = response.getResource();
    response = resource(product).getLink("order").follow().handling("application/xml").post(newOrder("Av. Princesa Isabel 350, Copacabana, Rio de Janeiro"));
    Order orderParam = newOrder(product.get(0).getId());
    Order order = response.getResource();
    System.out.println(resource(order).getLink("self").getType());
    response = resource(order).getLink("self").follow().handling("application/xml").put(orderParam);
    order = response.getResource();
    assertThat(order.getPrice(), is(equalTo(800.0)));
}
Also used : Response(br.com.caelum.restfulie.Response) Test(org.junit.Test)

Example 4 with Response

use of br.com.caelum.restfulie.Response in project restfulie-java by caelum.

the class ClientTest method shouldBeAbletToPay.

@Test
public void shouldBeAbletToPay() {
    Response response = search("20", 1);
    List<Product> products = response.getResource();
    Product product = products.get(0);
    Order orderParam = newOrder(product.getId());
    response = resource(products).getLink("order").follow().handling("application/xml").post(newOrder("Av. Princesa Isabel 350, Copacabana, Rio de Janeiro"));
    Order order = response.getResource();
    response = resource(order).getLink("self").follow().handling("application/xml").put(orderParam);
    order = response.getResource();
    response = pay(order);
    order = response.getResource();
    assertThat(order.getState(), is(equalTo("processing_payment")));
}
Also used : Response(br.com.caelum.restfulie.Response) Test(org.junit.Test)

Example 5 with Response

use of br.com.caelum.restfulie.Response in project restfulie-java by caelum.

the class ClientTests method shouldBeAbleToNavigateThroughLinks.

@Test
public void shouldBeAbleToNavigateThroughLinks() throws Exception {
    Response response = restfulie.at("http://localhost:8080/restfulie/items").accept(XML).get();
    List<Item> items = response.getResource();
    assertNotNull(items);
    assertFalse(items.isEmpty());
    List<Item> selectedItems = items.subList(0, 2);
    assertTrue(resource(items).hasLink("basket"));
    response = resource(items).getLink("basket").follow().as(XML).accept(XML).post(new Basket(selectedItems));
    Basket basket = response.getResource();
    assertNotNull(basket.getId());
    assertEquals(basket.getItems().size(), selectedItems.size());
    System.out.println(basket.getItems());
    assertTrue(resource(basket).hasLink("payment"));
    response = resource(basket).getLink("payment").follow().as(XML).accept(XML).post(new Payment(basket.getCost()));
    Payment payment = response.getResource();
    assertEquals(Status.ACCEPTED, payment.getStatus());
    System.out.println(payment.getStatus());
}
Also used : Response(br.com.caelum.restfulie.Response) Item(br.com.caelum.example.model.Item) Payment(br.com.caelum.example.model.Payment) Basket(br.com.caelum.example.model.Basket) Test(org.junit.Test)

Aggregations

Response (br.com.caelum.restfulie.Response)13 Test (org.junit.Test)10 Item (br.com.caelum.example.model.Item)5 Basket (br.com.caelum.example.model.Basket)1 Payment (br.com.caelum.example.model.Payment)1 Order (br.com.caelum.restbucks.model.Order)1 Payment (br.com.caelum.restbucks.model.Payment)1 Resources (br.com.caelum.restfulie.Resources)1 SearchDescription (br.com.caelum.restfulie.opensearch.SearchDescription)1