From 99aff8adf930ecf7ae09f21cb3d6f53e30c73b91 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 12 Sep 2016 11:02:15 +0200 Subject: [PATCH] DATAREST-885 - Polishing. Formatting. Copyright ranges. --- .../webmvc/json/patch/PatchOperation.java | 6 ++- .../json/patch/ReplaceOperationTest.java | 42 +++++++++---------- .../data/rest/webmvc/json/patch/Todo.java | 4 +- .../data/rest/webmvc/json/patch/TodoType.java | 21 ++++++++-- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java index 8005e5a1a..2bb53eb5c 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -165,7 +165,9 @@ public abstract class PatchOperation { * otherwise. */ protected Object evaluateValueFromTarget(Object targetObject, Class entityType) { - return value instanceof LateObjectEvaluator ? ((LateObjectEvaluator) value).evaluate(spelExpression.getValueType(targetObject)) : value; + + return value instanceof LateObjectEvaluator + ? ((LateObjectEvaluator) value).evaluate(spelExpression.getValueType(targetObject)) : value; } /** diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperationTest.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperationTest.java index 5d33d8d58..f68cd7c63 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperationTest.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperationTest.java @@ -15,9 +15,7 @@ */ package org.springframework.data.rest.webmvc.json.patch; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.ArrayList; import java.util.List; @@ -35,27 +33,13 @@ public class ReplaceOperationTest { todos.add(new Todo(1L, "A", false)); todos.add(new Todo(2L, "B", false)); todos.add(new Todo(3L, "C", false)); - + ReplaceOperation replace = new ReplaceOperation("/1/complete", true); replace.perform(todos, Todo.class); - + assertTrue(todos.get(1).isComplete()); } - @Test - public void replaceObjectPropertyValue() throws Exception { - // initial Todo list - Todo todo = new Todo(1L, "A", false); - - ReplaceOperation replace = new ReplaceOperation("/type", new JsonLateObjectEvaluator(new ObjectMapper().readTree("{\"value\":\"new\"}"))); - replace.perform(todo, Todo.class); - - assertNotNull(todo.getType()); - assertNotNull(todo.getType().getValue()); - assertTrue(todo.getType().getValue().equals("new")); - - } - @Test public void replaceTextPropertyValue() throws Exception { // initial Todo list @@ -63,7 +47,7 @@ public class ReplaceOperationTest { todos.add(new Todo(1L, "A", false)); todos.add(new Todo(2L, "B", false)); todos.add(new Todo(3L, "C", false)); - + ReplaceOperation replace = new ReplaceOperation("/1/description", "BBB"); replace.perform(todos, Todo.class); @@ -77,11 +61,27 @@ public class ReplaceOperationTest { todos.add(new Todo(1L, "A", false)); todos.add(new Todo(2L, "B", false)); todos.add(new Todo(3L, "C", false)); - + ReplaceOperation replace = new ReplaceOperation("/1/description", 22); replace.perform(todos, Todo.class); assertEquals("22", todos.get(1).getDescription()); } + /** + * @see DATAREST-885 + */ + @Test + public void replaceObjectPropertyValue() throws Exception { + + Todo todo = new Todo(1L, "A", false); + + ReplaceOperation replace = new ReplaceOperation("/type", + new JsonLateObjectEvaluator(new ObjectMapper().readTree("{ \"value\" : \"new\" }"))); + replace.perform(todo, Todo.class); + + assertNotNull(todo.getType()); + assertNotNull(todo.getType().getValue()); + assertTrue(todo.getType().getValue().equals("new")); + } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/Todo.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/Todo.java index edf221e1a..c3475c8e9 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/Todo.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/Todo.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import lombok.NoArgsConstructor; * @author Roy Clarkson * @author Craig Walls * @author Mathias Düsterhöft + * @author Oliver Gierke */ @Data @NoArgsConstructor @@ -34,6 +35,7 @@ class Todo { private TodoType type = new TodoType(); public Todo(Long id, String description, boolean complete) { + this.id = id; this.description = description; this.complete = complete; diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoType.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoType.java index c773cafc9..2522293ac 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoType.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TodoType.java @@ -1,18 +1,31 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.rest.webmvc.json.patch; -import javax.persistence.Embeddable; - import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; /** * @author Mathias Düsterhöft + * @author Oliver Gierke */ -@Embeddable @Data @AllArgsConstructor @NoArgsConstructor public class TodoType { - private String value = "none"; + private String value = "none"; }