Search in sources :

Example 6 with Response

use of br.com.caelum.restfulie.Response 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 7 with Response

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

the class Entry method happyPathTest.

private static void happyPathTest(URI uri) throws Exception {
    Resources resources = new MappingConfig().getServer();
    // Place the order
    System.out.println(String.format("About to start happy path test. Placing order at [%s] via POST", uri.toString()));
    Order order = createOrder();
    order = resources.entryAt(uri).post(order);
    System.out.println(String.format("Order placed at [%s]", order.getSelfUri()));
    // Pay for the order
    Payment payment = new Payment("12345677878", "guilherme silveira", 12, 2999, order.getCost());
    System.out.println(String.format("About to create a payment resource at [%s] via PUT", resource(order).getRelation("payment").getHref()));
    payment = order.pay(payment);
    System.out.println("Payment made, receipt created at: " + payment.getCreatedAt());
    // Check on the order status
    System.out.println(String.format("About to check order status at [%s] via GET", order.getSelfUri()));
    order = (Order) resource(order).getRelation("self").accessAndRetrieve();
    System.out.println(String.format("Final order placed, current status [%s]", order.getStatus()));
    // Allow the barista some time to make the order
    System.out.println("Pausing the client, press a key to continue");
    System.in.read();
    // Take the order if possible
    System.out.println(String.format("Trying to take the ready order from [%s] via DELETE. Note: the internal state machine must progress the order to ready before this should work, otherwise expect a 405 response.", order.getSelfUri()));
    order = (Order) resource(order).getRelation("self").accessAndRetrieve();
    Response finalResponse = resource(order).getRelation("retrieve").method(HttpMethod.DELETE).access();
    System.out.println(String.format("Tried to take final order, HTTP status [%d]", finalResponse.getCode()));
    if (finalResponse.getCode() == 200) {
        System.out.println(String.format("Order status [%s], enjoy your drink", finalResponse.getCode()));
    }
}
Also used : Order(br.com.caelum.restbucks.model.Order) Response(br.com.caelum.restfulie.Response) Payment(br.com.caelum.restbucks.model.Payment) Resources(br.com.caelum.restfulie.Resources)

Example 8 with Response

use of br.com.caelum.restfulie.Response 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 9 with Response

use of br.com.caelum.restfulie.Response 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 10 with Response

use of br.com.caelum.restfulie.Response 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

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