Skip to content

Commit

Permalink
VUU-81 remove redundant annotation and tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
vferraro-scottlogic committed Nov 14, 2023
1 parent d0ffeea commit 427f2db
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjectNode, String> {
private static final Logger logger = LoggerFactory.getLogger(ObjectNodeConverter.class);
private static final ObjectMapper objectMapper = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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";
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,15 +17,17 @@
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 {

private static ApplicationLayoutRepository mockRepo;
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() {
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 427f2db

Please sign in to comment.