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