Skip to content

Commit

Permalink
reproduce DATAREST-1006
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Düsterhöft committed Feb 10, 2017
1 parent afbffe4 commit c46df6e
Showing 1 changed file with 29 additions and 3 deletions.
Expand Up @@ -15,9 +15,15 @@
*/
package org.springframework.data.rest.webmvc.json;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static com.fasterxml.jackson.annotation.JsonProperty.Access.READ_ONLY;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -58,6 +64,7 @@
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
Expand Down Expand Up @@ -194,6 +201,22 @@ public void doesNotWipeIdAndVersionPropertyForPut() throws Exception {
assertThat(result.version, is(1L));
}

@Test //
public void doesNotWipeReadOnlyJsonPropertyForPut() throws Exception {

SampleUser sampleUser = new SampleUser("name", "password");
sampleUser.lastLogin = new Date();

ObjectMapper mapper = new ObjectMapper();
ObjectNode node = (ObjectNode) mapper.readTree("{ \"name\" : \"another\" }");

SampleUser result = reader.readPut(node, sampleUser, mapper);

assertThat(result.name, is("another"));
assertThat(result.password, notNullValue());
assertThat(result.lastLogin, notNullValue());
}

@Test // DATAREST-873
public void doesNotApplyInputToReadOnlyFields() throws Exception {

Expand Down Expand Up @@ -510,6 +533,9 @@ static class SampleUser {
@JsonIgnore String password;
Map<String, SampleUser> relatedUsers;

@JsonProperty(access = READ_ONLY)
private Date lastLogin;

public SampleUser(String name, String password) {

this.name = name;
Expand Down

0 comments on commit c46df6e

Please sign in to comment.