diff --git a/pom.xml b/pom.xml
index 942507cc..4e742d6f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,6 +60,12 @@
spring-boot-starter-test
test
+
+ org.projectlombok
+ lombok
+ 1.18.24
+ provided
+
diff --git a/src/main/java/com/microsoft/azure/sample/controller/TodoListController.java b/src/main/java/com/microsoft/azure/sample/controller/TodoListController.java
index cacd3126..9a7f0726 100644
--- a/src/main/java/com/microsoft/azure/sample/controller/TodoListController.java
+++ b/src/main/java/com/microsoft/azure/sample/controller/TodoListController.java
@@ -63,7 +63,7 @@ public ResponseEntity> getAllTodoItems() {
@RequestMapping(value = "/api/todolist", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity addNewTodoItem(@RequestBody TodoItem item) {
try {
- item.setID(UUID.randomUUID().toString());
+ item.setId(UUID.randomUUID().toString());
todoItemRepository.save(item);
return new ResponseEntity("Entity created", HttpStatus.CREATED);
} catch (Exception e) {
@@ -77,7 +77,7 @@ public ResponseEntity addNewTodoItem(@RequestBody TodoItem item) {
@RequestMapping(value = "/api/todolist", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity updateTodoItem(@RequestBody TodoItem item) {
try {
- todoItemRepository.deleteById(item.getID());
+ todoItemRepository.deleteById(item.getId());
todoItemRepository.save(item);
return new ResponseEntity("Entity updated", HttpStatus.OK);
} catch (Exception e) {
diff --git a/src/main/java/com/microsoft/azure/sample/model/TodoItem.java b/src/main/java/com/microsoft/azure/sample/model/TodoItem.java
index 5f127dd0..21517857 100644
--- a/src/main/java/com/microsoft/azure/sample/model/TodoItem.java
+++ b/src/main/java/com/microsoft/azure/sample/model/TodoItem.java
@@ -6,9 +6,15 @@
package com.microsoft.azure.sample.model;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
import java.util.Objects;
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
@Document
public class TodoItem {
private String id;
@@ -16,65 +22,23 @@ public class TodoItem {
private String owner;
private boolean finished;
- public TodoItem() {
- }
-
- public TodoItem(String id, String description, String owner) {
- this.description = description;
- this.id = id;
- this.owner = owner;
- this.finished = false;
- }
-
- public boolean isFinished() {
- return finished;
- }
-
- public void setFinish(boolean finished) {
- this.finished = finished;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getOwner() {
- return owner;
- }
-
- public void setOwner(String owner) {
- this.owner = owner;
- }
-
- public String getID() {
- return id;
- }
-
- public void setID(String id) {
- this.id = id;
+ public TodoItem(String s, String s1, String s2) {
}
@Override
public boolean equals(Object o) {
- if (o == this) {
- return true;
- }
- if (!(o instanceof TodoItem)) {
- return false;
- }
- final TodoItem group = (TodoItem) o;
- return Objects.equals(this.getDescription(), group.getDescription())
- && Objects.equals(this.getOwner(), group.getOwner())
- && Objects.equals(this.getID(), group.getID());
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ TodoItem todoItem = (TodoItem) o;
+ return finished == todoItem.finished &&
+ Objects.equals(id, todoItem.id) &&
+ Objects.equals(description, todoItem.description) &&
+ Objects.equals(owner, todoItem.owner);
}
@Override
public int hashCode() {
- return Objects.hash(description, id, owner);
+ return Objects.hash(id, description, owner, finished);
}
}
diff --git a/src/test/java/com/microsoft/azure/sample/TodoApplicationTest.java b/src/test/java/com/microsoft/azure/sample/TodoApplicationTest.java
index 780a78d9..1ce2c2f6 100644
--- a/src/test/java/com/microsoft/azure/sample/TodoApplicationTest.java
+++ b/src/test/java/com/microsoft/azure/sample/TodoApplicationTest.java
@@ -58,15 +58,15 @@ public class TodoApplicationTest {
@Before
public void setUp() {
repository.clear();
- repository.put(mockItemA.getID(), mockItemA);
- repository.put(mockItemB.getID(), mockItemB);
+ repository.put(mockItemA.getId(), mockItemA);
+ repository.put(mockItemB.getId(), mockItemB);
given(this.todoItemRepository.save(any(TodoItem.class))).willAnswer((InvocationOnMock invocation) -> {
final TodoItem item = invocation.getArgument(0);
- if (repository.containsKey(item.getID())) {
+ if (repository.containsKey(item.getId())) {
throw new Exception("Conflict.");
}
- repository.put(item.getID(), item);
+ repository.put(item.getId(), item);
return item;
});
@@ -101,16 +101,16 @@ public void shouldRenderDefaultTemplate() throws Exception {
@Test
public void canGetTodoItem() throws Exception {
- mockMvc.perform(get(String.format("/api/todolist/%s", mockItemA.getID()))).andDo(print())
+ mockMvc.perform(get(String.format("/api/todolist/%s", mockItemA.getId()))).andDo(print())
.andExpect(status().isOk())
.andExpect(content().json(String.format("{\"id\":\"%s\",\"description\":\"%s\",\"owner\":\"%s\"}",
- mockItemA.getID(), mockItemA.getDescription(), mockItemA.getOwner())));
+ mockItemA.getId(), mockItemA.getDescription(), mockItemA.getOwner())));
}
@Test
public void canGetAllTodoItems() throws Exception {
mockMvc.perform(get("/api/todolist")).andDo(print()).andExpect(status().isOk()).andExpect(content()
- .json(String.format("[{\"id\":\"%s\"}, {\"id\":\"%s\"}]", mockItemA.getID(), mockItemB.getID())));
+ .json(String.format("[{\"id\":\"%s\"}, {\"id\":\"%s\"}]", mockItemA.getId(), mockItemB.getId())));
}
@Test
@@ -126,19 +126,19 @@ public void canSaveTodoItems() throws Exception {
@Test
public void canDeleteTodoItems() throws Exception {
final int size = repository.size();
- mockMvc.perform(delete(String.format("/api/todolist/%s", mockItemA.getID()))).andDo(print())
+ mockMvc.perform(delete(String.format("/api/todolist/%s", mockItemA.getId()))).andDo(print())
.andExpect(status().isOk());
assertTrue(size - 1 == repository.size());
- assertFalse(repository.containsKey(mockItemA.getID()));
+ assertFalse(repository.containsKey(mockItemA.getId()));
}
@Test
public void canUpdateTodoItems() throws Exception {
final String newItemJsonString = String.format("{\"id\":\"%s\",\"description\":\"%s\",\"owner\":\"%s\"}",
- mockItemA.getID(), mockItemA.getDescription(), "New Owner");
+ mockItemA.getId(), mockItemA.getDescription(), "New Owner");
mockMvc.perform(put("/api/todolist").contentType(MediaType.APPLICATION_JSON_VALUE).content(newItemJsonString))
.andDo(print()).andExpect(status().isOk());
- assertTrue(repository.get(mockItemA.getID()).getOwner().equals("New Owner"));
+ assertTrue(repository.get(mockItemA.getId()).getOwner().equals("New Owner"));
}
@Test
@@ -155,13 +155,13 @@ public void canNotDeleteNonExistingTodoItems() throws Exception {
@Test
public void idempotenceOfPut() throws Exception {
final String newItemJsonString = String.format("{\"id\":\"%s\",\"description\":\"%s\",\"owner\":\"%s\"}",
- mockItemA.getID(), mockItemA.getDescription(), "New Owner");
+ mockItemA.getId(), mockItemA.getDescription(), "New Owner");
mockMvc.perform(put("/api/todolist").contentType(MediaType.APPLICATION_JSON_VALUE).content(newItemJsonString))
.andDo(print()).andExpect(status().isOk());
- final TodoItem firstRes = repository.get(mockItemA.getID());
+ final TodoItem firstRes = repository.get(mockItemA.getId());
mockMvc.perform(put("/api/todolist").contentType(MediaType.APPLICATION_JSON_VALUE).content(newItemJsonString))
.andDo(print()).andExpect(status().isOk());
- final TodoItem secondRes = repository.get(mockItemA.getID());
+ final TodoItem secondRes = repository.get(mockItemA.getId());
assertTrue(firstRes.equals(secondRes));
}
}