From 5911f5f825d079291f55347864061a97be1522cb Mon Sep 17 00:00:00 2001 From: vferraro-scottlogic Date: Tue, 14 Nov 2023 16:49:48 +0000 Subject: [PATCH] VUU-81 remove redundant annotation and tidy up --- .../dto/request/LayoutRequestDto.java | 3 --- .../utils/ObjectNodeConverter.java | 2 -- .../integration/LayoutIntegrationTest.java | 15 +++++++++++---- .../service/ApplicationLayoutServiceTest.java | 18 +++++------------- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/layout-server/src/main/java/org/finos/vuu/layoutserver/dto/request/LayoutRequestDto.java b/layout-server/src/main/java/org/finos/vuu/layoutserver/dto/request/LayoutRequestDto.java index 9620c1184..db4607310 100644 --- a/layout-server/src/main/java/org/finos/vuu/layoutserver/dto/request/LayoutRequestDto.java +++ b/layout-server/src/main/java/org/finos/vuu/layoutserver/dto/request/LayoutRequestDto.java @@ -1,6 +1,5 @@ package org.finos.vuu.layoutserver.dto.request; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.Data; @@ -9,11 +8,9 @@ @Data public class LayoutRequestDto { - @JsonProperty(value = "definition", required = true) @NotNull(message = "Definition must not be null") private ObjectNode definition; - @JsonProperty(value = "metadata", required = true) @NotNull(message = "Metadata must not be null") private MetadataRequestDto metadata; } diff --git a/layout-server/src/main/java/org/finos/vuu/layoutserver/utils/ObjectNodeConverter.java b/layout-server/src/main/java/org/finos/vuu/layoutserver/utils/ObjectNodeConverter.java index a8393a9e6..38e8f1832 100644 --- a/layout-server/src/main/java/org/finos/vuu/layoutserver/utils/ObjectNodeConverter.java +++ b/layout-server/src/main/java/org/finos/vuu/layoutserver/utils/ObjectNodeConverter.java @@ -8,10 +8,8 @@ import org.slf4j.LoggerFactory; import javax.persistence.AttributeConverter; -import javax.persistence.Converter; import java.io.IOException; -@Converter public class ObjectNodeConverter implements AttributeConverter { private static final Logger logger = LoggerFactory.getLogger(ObjectNodeConverter.class); private static final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/LayoutIntegrationTest.java b/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/LayoutIntegrationTest.java index 6f7c9fdf2..0fcfbfc37 100644 --- a/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/LayoutIntegrationTest.java +++ b/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/LayoutIntegrationTest.java @@ -24,8 +24,13 @@ import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.iterableWithSize; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -35,6 +40,7 @@ public class LayoutIntegrationTest { private static final String LAYOUT_DEFINITION_STRING = "{\"id\":\"main-tabs\"}"; + private static final String UPDATED_LAYOUT_DEFINITION_STRING = "{\"id\":\"updated-main-tabs\"}"; private static final String DEFAULT_LAYOUT_NAME = "Default layout name"; private static final String DEFAULT_LAYOUT_GROUP = "Default layout group"; private static final String DEFAULT_LAYOUT_SCREENSHOT = "Default layout screenshot"; @@ -121,7 +127,8 @@ void getMetadata_multipleMetadataExists_returnsAllMetadata() throws Exception { UUID layout2Id = UUID.randomUUID(); Layout layout1 = createLayoutWithIdInDatabase(layout1Id); Layout layout2 = createLayoutWithIdInDatabase(layout2Id); - layout2.setDefinition(objectNodeConverter.convertToEntityAttribute(LAYOUT_DEFINITION_STRING)); + layout2.setDefinition(objectNodeConverter.convertToEntityAttribute(UPDATED_LAYOUT_DEFINITION_STRING)); + layout2.getMetadata().getBaseMetadata().setName("Different name"); layout2.getMetadata().getBaseMetadata().setGroup("Different group"); layout2.getMetadata().getBaseMetadata().setScreenshot("Different screenshot"); layout2.getMetadata().getBaseMetadata().setUser("Different user"); @@ -264,7 +271,7 @@ void updateLayout_validIdAndValidRequest_returns204AndLayoutHasChanged() throws initialLayout); LayoutRequestDto layoutRequest = createValidLayoutRequest(); - layoutRequest.setDefinition(objectNodeConverter.convertToEntityAttribute(LAYOUT_DEFINITION_STRING)); + layoutRequest.setDefinition(objectNodeConverter.convertToEntityAttribute(UPDATED_LAYOUT_DEFINITION_STRING)); layoutRequest.getMetadata().getBaseMetadata().setName("Updated name"); layoutRequest.getMetadata().getBaseMetadata().setGroup("Updated group"); layoutRequest.getMetadata().getBaseMetadata().setScreenshot("Updated screenshot"); diff --git a/layout-server/src/test/java/org/finos/vuu/layoutserver/service/ApplicationLayoutServiceTest.java b/layout-server/src/test/java/org/finos/vuu/layoutserver/service/ApplicationLayoutServiceTest.java index 7798c72e8..e5b8ecb20 100644 --- a/layout-server/src/test/java/org/finos/vuu/layoutserver/service/ApplicationLayoutServiceTest.java +++ b/layout-server/src/test/java/org/finos/vuu/layoutserver/service/ApplicationLayoutServiceTest.java @@ -1,7 +1,6 @@ package org.finos.vuu.layoutserver.service; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import org.finos.vuu.layoutserver.model.ApplicationLayout; import org.finos.vuu.layoutserver.repository.ApplicationLayoutRepository; @@ -18,7 +17,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; class ApplicationLayoutServiceTest { @@ -26,7 +28,6 @@ class ApplicationLayoutServiceTest { private static ApplicationLayoutService service; private static final DefaultApplicationLayoutLoader defaultLoader = new DefaultApplicationLayoutLoader(); private static final ObjectNodeConverter objectNodeConverter = new ObjectNodeConverter(); - private static final ObjectMapper objectMapper = new ObjectMapper(); @BeforeEach public void setup() { @@ -71,16 +72,7 @@ public void createApplicationLayout_validDefinition_callsRepoSave() throws JsonP verify(mockRepo, times(1)) .save(new ApplicationLayout(user, definition)); } - - @Test - public void createApplicationLayout_invalidDefinition_throwsJsonException() { - String definition = "invalid JSON"; - - assertThrows(JsonProcessingException.class, () -> - service.persistApplicationLayout("user", (ObjectNode) objectMapper.readTree(definition)) - ); - } - + @Test public void deleteApplicationLayout_entryExists_callsRepoDelete() { String user = "user";