From 0a3738782d2ec919bfa7d11f5d8fb953460ebbb4 Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Wed, 5 Feb 2014 16:29:54 -0600 Subject: [PATCH] DATAREST-150 - Added test case showing PUT now works correctly. The JIRA issue asserts that PUT wasn't properly storing things. But now it does. A partial record causes all other fields to get nulled out. Added a test case to confirm this. Original pull request: #134. --- .../data/rest/webmvc/jpa/JpaWebTests.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) 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 d549321fe..619394564 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 @@ -207,8 +207,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); @@ -221,6 +223,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 {