Search in sources :

Example 1 with Item

use of br.com.caelum.example.model.Item 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)

Example 2 with Item

use of br.com.caelum.example.model.Item in project restfulie-java by caelum.

the class ClientTests method shouldBeAbleToGetAnItemWithHypermedia.

@Test
public void shouldBeAbleToGetAnItemWithHypermedia() throws Exception {
    Response response = restfulie.at("http://localhost:8080/restfulie/items/2").accept("application/xml").get();
    Item item = response.getResource();
    assertNotNull(item);
    assertNotNull(item.getName());
    System.out.println(item.getName());
    assertTrue(resource(item).hasLink("self"));
    System.out.println(resource(item).getLink("self").getHref());
}
Also used : Response(br.com.caelum.restfulie.Response) Item(br.com.caelum.example.model.Item) Test(org.junit.Test)

Example 3 with Item

use of br.com.caelum.example.model.Item in project restfulie-java by caelum.

the class ClientTests method shouldBeAbleToPostAnItemWithHypermedia.

@Test
public void shouldBeAbleToPostAnItemWithHypermedia() throws Exception {
    Item item = new Item("pipa", 299.0);
    Response response = restfulie.at("http://localhost:8080/restfulie/items").as("application/xml").post(item);
    Item savedItem = response.getResource();
    assertNotSame(item, savedItem);
    assertEquals("pipa", savedItem.getName());
    assertEquals(Double.valueOf(299.0), savedItem.getPrice());
    assertNotNull(savedItem.getId());
    System.out.println(savedItem.getId());
    assertTrue(resource(savedItem).hasLink("self"));
    System.out.println(savedItem.getName());
}
Also used : Response(br.com.caelum.restfulie.Response) Item(br.com.caelum.example.model.Item) Test(org.junit.Test)

Example 4 with Item

use of br.com.caelum.example.model.Item in project restfulie-java by caelum.

the class ClientTests method shouldBeAbleToGetAnItem.

@Test
public void shouldBeAbleToGetAnItem() throws Exception {
    Response response = restfulie.at("http://localhost:8080/restfulie/items/2").accept("application/xml").get();
    Item item = response.getResource();
    assertNotNull(item);
    assertNotNull(item.getName());
    System.out.println(item.getName());
}
Also used : Response(br.com.caelum.restfulie.Response) Item(br.com.caelum.example.model.Item) Test(org.junit.Test)

Example 5 with Item

use of br.com.caelum.example.model.Item in project restfulie-java by caelum.

the class ClientTests method shouldBeAbleToPostAnItem.

@Test
public void shouldBeAbleToPostAnItem() throws Exception {
    Item item = new Item("pipa", 299.0);
    Response response = restfulie.at("http://localhost:8080/restfulie/items").accept("application/xml").as("application/xml").post(item);
    Item savedItem = response.getResource();
    assertNotSame(item, savedItem);
    assertEquals("pipa", savedItem.getName());
    assertEquals(Double.valueOf(299.0), savedItem.getPrice());
    assertNotNull(savedItem.getId());
    System.out.println(savedItem.getId());
}
Also used : Response(br.com.caelum.restfulie.Response) Item(br.com.caelum.example.model.Item) Test(org.junit.Test)

Aggregations

Item (br.com.caelum.example.model.Item)6 Response (br.com.caelum.restfulie.Response)5 Test (org.junit.Test)5 Basket (br.com.caelum.example.model.Basket)1 Payment (br.com.caelum.example.model.Payment)1 Get (br.com.caelum.vraptor.Get)1 Path (br.com.caelum.vraptor.Path)1