Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VUU86: Add tests for layout server #68

Merged
merged 76 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
444364d
VUU25: Initialise module
cfisher-scottlogic Sep 21, 2023
3e8e738
VUU25: Basic Controller infrastructure
cfisher-scottlogic Sep 21, 2023
7061d64
VUU25: Implement Layout & Metadata models
cfisher-scottlogic Sep 21, 2023
d444cad
VUU25: Add OpenAPI docs (Swagger)
cfisher-scottlogic Sep 22, 2023
2bb9c0a
VUU25: Add basic H2 database
cfisher-scottlogic Sep 22, 2023
55aa632
VUU25: Implement DTOs
cfisher-scottlogic Sep 22, 2023
e0d6728
VUU25: Change server port and swagger URL
cfisher-scottlogic Sep 26, 2023
2cbb5e2
VUU25: Wire up Controller, Service and Repository for full implementa…
cfisher-scottlogic Sep 26, 2023
4f3f4cb
VUU25: Implement model mapper to replace manual entity<->DTO conversion
cfisher-scottlogic Sep 26, 2023
9b2f6ff
VUU25: Fix one-to-one entity persistence issue
cfisher-scottlogic Sep 28, 2023
a7ed2bd
VUU25: Pluralise layout endpoint resource
cfisher-scottlogic Oct 4, 2023
ed7f151
VUU25: Amend annotations, javadocs, and updateLayout signature in the…
cfisher-scottlogic Oct 4, 2023
7d72461
VUU25: Add javadocs to definition field in LayoutDTOs
cfisher-scottlogic Oct 4, 2023
2653ab1
VUU25: Remove no args constructor on entities
cfisher-scottlogic Oct 4, 2023
29a71ce
VUU25: Replace layoutRepository with metadataRepository in LayoutServ…
cfisher-scottlogic Oct 4, 2023
42f4863
VUU25: Add date to create layout HTTP response body
cfisher-scottlogic Oct 4, 2023
10e53ad
VUU25: Introduce MetadataService
cfisher-scottlogic Oct 4, 2023
715cbac
VUU25: Create layout controller unit tests (backend)
cfisher-scottlogic Oct 3, 2023
9895e10
VUU25: Create layout integration tests (backend)
cfisher-scottlogic Oct 5, 2023
3990408
VUU25: Add global exception handling to give appropriate HTTP responses
cfisher-scottlogic Oct 5, 2023
13142bb
VUU25: Rename LayoutResponseDTO to GetLayoutResponseDTO
cfisher-scottlogic Oct 5, 2023
681dd93
VUU25: Reformatting
cfisher-scottlogic Oct 5, 2023
7b5dc5a
VUU25: Make deleteLayout generate 404 if layout does not exist (backend)
cfisher-scottlogic Oct 5, 2023
09b9e73
VUU25: Downgrade Java 17 -> 11 and Springboot 3 -> 2
cfisher-scottlogic Oct 9, 2023
dd5c120
VUU25: Change DB persistence from file to in-memory
cfisher-scottlogic Oct 9, 2023
594e454
Merge branch 'VUU25-layout-server' into VUU25-layout-server-with-tests
cfisher-scottlogic Oct 9, 2023
07c179a
VUU25: Fix issues caused by downgrading Java & Springboot
cfisher-scottlogic Oct 9, 2023
5fcb328
VUU25: Write description for layout-server pom.xml
cfisher-scottlogic Oct 10, 2023
1c05d6b
VUU25: Implement interface for Metadata DTOs
cfisher-scottlogic Oct 10, 2023
a0b2630
Merge branch 'VUU25-layout-server' into VUU25-layout-server-with-tests
cfisher-scottlogic Oct 10, 2023
3c32c6a
VUU25: Create layout service unit tests (backend)
cfisher-scottlogic Oct 10, 2023
3d5697b
VUU25: Add test for transactional nature of LayoutService.createLayout()
cfisher-scottlogic Oct 10, 2023
3d25ff8
VUU25: Remove unnecessary LayoutController unit tests
cfisher-scottlogic Oct 10, 2023
b9ec7ca
VUU25: Mock out model mapper in LayoutController tests
cfisher-scottlogic Oct 10, 2023
bee7f43
VUU25: Remove TODO
cfisher-scottlogic Oct 11, 2023
67e5a52
Merge branch 'main' into VUU25-layout-server
cfisher-scottlogic Oct 11, 2023
6629880
VUU25: Move 'updated date' logic from DTO to service for update layou…
cfisher-scottlogic Oct 11, 2023
90545b0
VUU25: Move updateLayout logic from mapper in controller to setters i…
cfisher-scottlogic Oct 11, 2023
416028f
Merge branch 'VUU25-layout-server' into VUU25-layout-server-with-tests
cfisher-scottlogic Oct 11, 2023
6f97b5d
VUU25: Fix tests for recent changes in layout server
cfisher-scottlogic Oct 11, 2023
6116b28
VUU25: Remove unnecessary autogenerated content
cfisher-scottlogic Oct 11, 2023
4613103
VUU25: Make create layout (with a valid layout) integration test more…
cfisher-scottlogic Oct 11, 2023
6c0de9a
VUU25: Increase max length of screenshot column
cfisher-scottlogic Oct 16, 2023
ae2d2cc
VUU25: Change create layout endpoint to return whole layout object
cfisher-scottlogic Oct 16, 2023
00bb5d2
Merge branch 'VUU25-layout-server' into VUU25-layout-server-with-tests
cfisher-scottlogic Oct 16, 2023
4d46371
VUU25: Fix tests for new create layout response
cfisher-scottlogic Oct 16, 2023
8a6d60a
VUU25: Simplify LayoutControllerTest test name
cfisher-scottlogic Oct 16, 2023
d0ca229
VUU25: Fix tests for changed unidirectional Layout<->Metadata relatio…
cfisher-scottlogic Oct 16, 2023
524ae69
Merge branch 'main' into VUU25-layout-server-with-tests
cfisher-scottlogic Oct 20, 2023
300b897
VUU25: Fix tests since merging in main with BaseMetadata
cfisher-scottlogic Oct 23, 2023
e36c635
VUU25: Fix exception not being resolved due to invalid parameters
cfisher-scottlogic Oct 23, 2023
436d437
VUU25: Add response body content message assertion for non-200 test r…
cfisher-scottlogic Oct 23, 2023
333a244
VUU25: Cleanup conflict resolution mistakes from merge commit
cfisher-scottlogic Oct 24, 2023
4251502
VUU25: Modify exception handling for deleteLayout
cfisher-scottlogic Oct 24, 2023
7dd8233
VUU25: Improve non-200 response messages
cfisher-scottlogic Oct 25, 2023
32372f3
VUU86: ID -> Id in test names
cfisher-scottlogic Oct 31, 2023
bf7278e
VUU86: Add assertion that no metadata is saved upon invalid create la…
cfisher-scottlogic Oct 31, 2023
45ff964
VUU86: Add test case for blank layout definition in create layout req…
cfisher-scottlogic Oct 31, 2023
71401dc
VUU86: Refactor odd formatting
cfisher-scottlogic Nov 1, 2023
fc3cd39
VUU86: Remove `LayoutService.getMetadata()`
cfisher-scottlogic Nov 1, 2023
44d9719
VUU86: Move GlobalExceptionHandler to new `exceptions` package
cfisher-scottlogic Nov 1, 2023
510900d
VUU86: Create generic `handleBadRequest` exception handler
cfisher-scottlogic Nov 1, 2023
474c23e
VUU86: Refactor test variables as constants
cfisher-scottlogic Nov 1, 2023
d8fd1b5
VUU86: Remove incorrect `returns404` on test name
cfisher-scottlogic Nov 1, 2023
62d3a90
VUU86: Refactor abstraction in `LayoutController.getMetadata_metadata…
cfisher-scottlogic Nov 1, 2023
bc6e526
VUU86: Implement test naming convention for 'stateUnderTest'
cfisher-scottlogic Nov 1, 2023
ad5ddeb
VUU86: Use Metadata builder in tests
cfisher-scottlogic Nov 1, 2023
3009319
VUU86: Add test cases for when repo returns empty
cfisher-scottlogic Nov 1, 2023
5493de8
VUU86: Remove assertion from helper method
cfisher-scottlogic Nov 1, 2023
92ebfab
VUU86: Add integration test for multiple metadata
cfisher-scottlogic Nov 1, 2023
5c23160
VUU86: _validLayout -> _validRequest_
cfisher-scottlogic Nov 1, 2023
324444e
VUU86: Refactor `updateLayout_validIdAndValidRequest_returns204AndLay…
cfisher-scottlogic Nov 1, 2023
0ccaee4
VUU86: Separate _definitionIsBlankAndMetadataIsNull_ into two tests
cfisher-scottlogic Nov 1, 2023
f2ca868
VUU86: Remove `@Transactional` on LayoutIntegrationTest
cfisher-scottlogic Nov 1, 2023
c1692d7
VUU86: Date -> LocalDate
cfisher-scottlogic Nov 1, 2023
f4dce71
VUU86: Improve tests
cfisher-scottlogic Nov 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions layout-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down Expand Up @@ -54,6 +58,12 @@
<artifactId>modelmapper</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>13.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.RequiredArgsConstructor;
import org.finos.vuu.layoutserver.dto.request.LayoutRequestDTO;
import org.finos.vuu.layoutserver.dto.request.MetadataRequestDTO;
import org.finos.vuu.layoutserver.dto.response.MetadataResponseDTO;
import org.finos.vuu.layoutserver.model.Layout;
import org.finos.vuu.layoutserver.model.Metadata;
Expand All @@ -29,16 +28,6 @@ public ModelMapper modelMapper() {
metadata -> layoutService.getLayoutByMetadataId(metadata.getId()),
MetadataResponseDTO::setLayoutId));

mapper.typeMap(MetadataRequestDTO.class, Metadata.class)
.addMappings(m -> m.map(
MetadataRequestDTO::getBaseMetadata,
Metadata::setBaseMetadata));

mapper.typeMap(Metadata.class, MetadataResponseDTO.class)
.addMappings(m -> m.map(
Metadata::getBaseMetadata,
MetadataResponseDTO::setBaseMetadata));

return mapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.UUID;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.finos.vuu.layoutserver.dto.request.LayoutRequestDTO;
import org.finos.vuu.layoutserver.dto.response.LayoutResponseDTO;
Expand All @@ -11,6 +12,7 @@
import org.finos.vuu.layoutserver.service.MetadataService;
import org.modelmapper.ModelMapper;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -24,6 +26,7 @@
@RequiredArgsConstructor
@RestController
@RequestMapping("/layouts")
@Validated
public class LayoutController {

private final LayoutService layoutService;
Expand Down Expand Up @@ -65,7 +68,7 @@ public List<MetadataResponseDTO> getMetadata() {
*/
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public LayoutResponseDTO createLayout(@RequestBody LayoutRequestDTO layoutToCreate) {
public LayoutResponseDTO createLayout(@Valid @RequestBody LayoutRequestDTO layoutToCreate) {
Layout layout = mapper.map(layoutToCreate, Layout.class);

Layout createdLayout = layoutService.getLayout(layoutService.createLayout(layout));
Expand All @@ -81,7 +84,7 @@ public LayoutResponseDTO createLayout(@RequestBody LayoutRequestDTO layoutToCrea
*/
@ResponseStatus(HttpStatus.NO_CONTENT)
@PutMapping("/{id}")
public void updateLayout(@PathVariable UUID id, @RequestBody LayoutRequestDTO layout) {
public void updateLayout(@PathVariable UUID id, @Valid @RequestBody LayoutRequestDTO layout) {
Layout newLayout = mapper.map(layout, Layout.class);

layoutService.updateLayout(id, newLayout);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package org.finos.vuu.layoutserver.dto.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Data;

@Data
public class LayoutRequestDTO {

/**
* The definition of the layout as a string (i.e. stringified JSON structure containing components)
* The definition of the layout as a string (e.g. stringified JSON structure containing
* components)
*/
@JsonProperty(value = "definition", required = true)
@NotBlank(message = "Definition must not be blank")
private String 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
@@ -1,7 +1,7 @@
package org.finos.vuu.layoutserver.dto.response;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import java.util.Date;
import java.time.LocalDate;
import java.util.UUID;
import lombok.Data;
import org.finos.vuu.layoutserver.model.BaseMetadata;
Expand All @@ -14,6 +14,6 @@ public class MetadataResponseDTO {
@JsonUnwrapped
BaseMetadata baseMetadata;

private Date created;
private Date updated;
private LocalDate created;
private LocalDate updated;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.finos.vuu.layoutserver.exceptions;

import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

@ControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(NoSuchElementException.class)
public ResponseEntity<String> handleNotFound(NoSuchElementException ex) {
return new ResponseEntity<>(ex.getMessage(),
org.springframework.http.HttpStatus.NOT_FOUND);
}

@ExceptionHandler({
HttpMessageNotReadableException.class,
MethodArgumentTypeMismatchException.class})
public ResponseEntity<String> handleBadRequest(Exception ex) {
return new ResponseEntity<>(ex.getMessage(),
org.springframework.http.HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<String> handleMethodArgumentNotValid(MethodArgumentNotValidException ex) {
List<String> errors = ex.getFieldErrors()
.stream()
.map(fieldError -> fieldError.getField() + ": " + fieldError.getDefaultMessage())
.collect(Collectors.toList());

return new ResponseEntity<>(errors.toString(),
org.springframework.http.HttpStatus.BAD_REQUEST);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.finos.vuu.layoutserver.model;

import java.util.UUID;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -9,7 +10,6 @@
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import lombok.Data;
import java.util.UUID;

@Data
@Entity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.finos.vuu.layoutserver.model;

import java.util.Date;
import java.time.LocalDate;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Embedded;
Expand Down Expand Up @@ -28,8 +28,7 @@ public class Metadata {
@Embedded
private BaseMetadata baseMetadata;

private Date created = new Date();

private Date updated;
private final LocalDate created = LocalDate.now();

private LocalDate updated;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.finos.vuu.layoutserver.repository;

import java.util.UUID;
import org.finos.vuu.layoutserver.model.Metadata;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;

@Repository
public interface MetadataRepository extends CrudRepository<Metadata, UUID> {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.finos.vuu.layoutserver.service;

import java.util.Date;
import java.time.LocalDate;
import java.util.NoSuchElementException;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.finos.vuu.layoutserver.model.Layout;
Expand All @@ -15,7 +16,8 @@ public class LayoutService {
private final LayoutRepository layoutRepository;

public Layout getLayout(UUID id) {
return layoutRepository.findById(id).orElseThrow();
return layoutRepository.findById(id)
.orElseThrow(() -> new NoSuchElementException("Layout with ID '" + id + "' not found"));
}

public Layout getLayoutByMetadataId(UUID id) {
Expand All @@ -32,7 +34,7 @@ public void updateLayout(UUID layoutId, Layout newLayout) {

Metadata updatedMetadata = Metadata.builder()
.baseMetadata(newMetadata.getBaseMetadata())
.updated(new Date())
.updated(LocalDate.now())
.build();

layoutToUpdate.setDefinition(newLayout.getDefinition());
Expand All @@ -42,6 +44,10 @@ public void updateLayout(UUID layoutId, Layout newLayout) {
}

public void deleteLayout(UUID id) {
layoutRepository.deleteById(id);
try {
layoutRepository.deleteById(id);
} catch (Exception e) {
throw new NoSuchElementException("Layout with ID '" + id + "' not found");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.finos.vuu.layoutserver.service;

import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.finos.vuu.layoutserver.model.Metadata;
import org.finos.vuu.layoutserver.repository.MetadataRepository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
@Service
public class MetadataService {
Expand Down
Loading
Loading