Search in sources :

Example 1 with Payment

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

Aggregations

Order (br.com.caelum.restbucks.model.Order)1 Payment (br.com.caelum.restbucks.model.Payment)1 Resources (br.com.caelum.restfulie.Resources)1 Response (br.com.caelum.restfulie.Response)1