Example usage for org.springframework.data.rest.tests.mongodb Receipt Receipt

List of usage examples for org.springframework.data.rest.tests.mongodb Receipt Receipt

Introduction

In this page you can find the example usage for org.springframework.data.rest.tests.mongodb Receipt Receipt.

Prototype

Receipt

Source Link

Usage

From source file:org.springframework.data.rest.tests.mongodb.MongoWebTests.java

/**
 * @see DATAREST-160/*from   w w w.jav a  2s  . c om*/
 */
@Test
public void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception {

    Link receiptLink = client.discoverUnique("receipts");

    Receipt receipt = new Receipt();
    receipt.amount = new BigDecimal(50);
    receipt.saleItem = "Springy Tacos";

    String stringReceipt = mapper.writeValueAsString(receipt);

    MockHttpServletResponse createdReceipt = postAndGet(receiptLink, stringReceipt, MediaType.APPLICATION_JSON);
    Link tacosLink = client.assertHasLinkWithRel("self", createdReceipt);
    assertJsonPathEquals("$.saleItem", "Springy Tacos", createdReceipt);

    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(tacosLink.getHref());
    String concurrencyTag = createdReceipt.getHeader("ETag");

    mvc.perform(patch(builder.build().toUriString()).content("{ \"saleItem\" : \"SpringyBurritos\" }")
            .contentType(MediaType.APPLICATION_JSON).header(IF_MATCH, concurrencyTag))
            .andExpect(status().is2xxSuccessful());

    mvc.perform(patch(builder.build().toUriString()).content("{ \"saleItem\" : \"SpringyTequila\" }")
            .contentType(MediaType.APPLICATION_JSON).header(IF_MATCH, concurrencyTag))
            .andExpect(status().isPreconditionFailed());
}

From source file:org.springframework.data.rest.tests.mongodb.MongoWebTests.java

/**
 * @see DATAREST-506//from   w w  w.  ja  v  a2 s.c o  m
 */
@Test
public void supportsConditionalGetsOnItemResource() throws Exception {

    Receipt receipt = new Receipt();
    receipt.amount = new BigDecimal(50);
    receipt.saleItem = "Springy Tacos";

    Link receiptsLink = client.discoverUnique("receipts");

    MockHttpServletResponse response = postAndGet(receiptsLink, mapper.writeValueAsString(receipt),
            MediaType.APPLICATION_JSON);

    Link receiptLink = client.getDiscoverer(response).findLinkWithRel("self", response.getContentAsString());

    mvc.perform(get(receiptLink.getHref()).header(IF_MODIFIED_SINCE, response.getHeader(LAST_MODIFIED))).//
            andExpect(status().isNotModified()).//
            andExpect(header().string(ETAG, is(notNullValue())));

    mvc.perform(get(receiptLink.getHref()).header(IF_NONE_MATCH, response.getHeader(ETAG))).//
            andExpect(status().isNotModified()).//
            andExpect(header().string(ETAG, is(notNullValue())));
}