Skip to content

DATAREST-965 Create tests to show issue were PUT is not clearing out nested properties #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
* @author Oliver Gierke
* @author Craig Andrews
* @author Mathias Düsterhöft
* @author Ken Dombeck
*/
@RunWith(MockitoJUnitRunner.class)
public class DomainObjectReaderUnitTests {
Expand Down Expand Up @@ -392,6 +393,49 @@ public void writesArrayWithRemovedItemForPut() throws Exception {
assertThat(result.inner.items.get(0).some, is("value"));
}

/**
* @see DATAREST-965
*/
@Test
public void writesObjectWithRemovedItemsForPut() throws Exception {

Child inner = new Child();
inner.items = new ArrayList<Item>();
inner.items.add(new Item("test1"));
inner.items.add(new Item("test2"));

Parent source = new Parent();
source.inner = inner;

JsonNode node = new ObjectMapper().readTree("{ \"inner\" : { \"object\" : \"value\" } }");

Parent result = reader.readPut((ObjectNode) node, source, new ObjectMapper());

assertThat(result.inner.items, is(isNull()));
assertThat((String) result.inner.object, is("value"));
}

/**
* @see DATAREST-965
*/
@Test
public void writesArrayWithRemovedObjectForPut() throws Exception {

Child inner = new Child();
inner.object = "value";

Parent source = new Parent();
source.inner = inner;

JsonNode node = new ObjectMapper().readTree("{ \"inner\" : { \"items\" : [ { \"some\" : \"value\" } ] } }");

Parent result = reader.readPut((ObjectNode) node, source, new ObjectMapper());

assertThat(result.inner.items.size(), is(1));
assertThat(result.inner.items.get(0).some, is("value"));
assertThat(result.inner.object, is(isNull()));
}

/**
* @see DATAREST-959
*/
Expand Down