diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java index da9b68704..2aed654c3 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java @@ -206,8 +206,10 @@ public class JpaWebTests extends AbstractWebIntegrationTests { @Test public void createThenPatch() throws Exception { - MockHttpServletResponse bilbo = postAndGet(new Link("/people"), - "{ \"firstName\" : \"Bilbo\", \"lastName\" : \"Baggins\" }", MediaType.APPLICATION_JSON); + Link peopleLink = discoverUnique("people"); + + MockHttpServletResponse bilbo = postAndGet(peopleLink, "{ \"firstName\" : \"Bilbo\", \"lastName\" : \"Baggins\" }", + MediaType.APPLICATION_JSON); Link bilboLink = assertHasLinkWithRel("self", bilbo); @@ -220,6 +222,31 @@ public class JpaWebTests extends AbstractWebIntegrationTests { assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.lastName"), equalTo("Baggins")); } + /** + * @see DATAREST-150 + */ + @Test + public void createThenPut() throws Exception { + + Link peopleLink = discoverUnique("people"); + + MockHttpServletResponse bilbo = postAndGet(peopleLink,// + "{ \"firstName\" : \"Bilbo\", \"lastName\" : \"Baggins\" }",// + MediaType.APPLICATION_JSON); + + Link bilboLink = assertHasLinkWithRel("self", bilbo); + + assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.firstName"), equalTo("Bilbo")); + assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.lastName"), equalTo("Baggins")); + + MockHttpServletResponse frodo = putAndGet(bilboLink,// + "{ \"firstName\" : \"Frodo\" }",// + MediaType.APPLICATION_JSON); + + assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.firstName"), equalTo("Frodo")); + assertNull(JsonPath.read(frodo.getContentAsString(), "$.lastName")); + } + @Test public void listsSiblingsWithContentCorrectly() throws Exception {