Skip to content

Commit

Permalink
VUU25: Fix tests for recent changes in layout server
Browse files Browse the repository at this point in the history
- Update and delete layout in LayoutControllerTest and LayoutServiceTest
  • Loading branch information
cfisher-scottlogic committed Oct 11, 2023
1 parent 416028f commit 6f97b5d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
Expand Down Expand Up @@ -136,10 +137,23 @@ void createLayout_validLayout_createsLayout() {
}

@Test
void updateLayout_layoutDoesNotExist_returnsInvalidRequest() {
when(layoutService.getLayout(layout.getId())).thenThrow(NoSuchElementException.class);
assertThrows(NoSuchElementException.class,
() -> layoutController.updateLayout(layout.getId(), layoutRequest));
void updateLayout_callsLayoutService() {
layout.setId(null);
layout.getMetadata().setId(null);

when(modelMapper.map(layoutRequest, Layout.class)).thenReturn(layout);

layoutController.updateLayout(validLayoutId, layoutRequest);

verify(layoutService).updateLayout(validLayoutId, layout);
}

@Test
void deleteLayout_callsLayoutService() {
layoutController.deleteLayout(validLayoutId);

verify(layoutService).getLayout(validLayoutId);
verify(layoutService).deleteLayout(validLayoutId);
}

private MetadataResponseDTO getMetadataResponseDTO() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.util.Date;
import java.util.List;
import java.util.NoSuchElementException;
import org.finos.vuu.layoutserver.model.Metadata;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -78,14 +80,23 @@ void createLayout() {
}

@Test
void updateLayout_returnsNothing() {
layoutService.updateLayout(layout);
void updateLayout_layoutExists_callsRepository() {
when(layoutRepository.findById(layoutId)).thenReturn(Optional.of(layout));

layoutService.updateLayout(layoutId, layout);

verify(layoutRepository, times(1)).save(layout);
}

@Test
void deleteLayout_returnsNothing() {
void updateLayout_layoutDoesNotExist_throwsNoSuchElementException() {
when(layoutRepository.findById(layoutId)).thenReturn(Optional.empty());

assertThrows(NoSuchElementException.class, () -> layoutService.updateLayout(layoutId, layout));
}

@Test
void deleteLayout_callsRepository() {
layoutService.deleteLayout(layoutId);

verify(layoutRepository, times(1)).deleteById(layoutId);
Expand Down

0 comments on commit 6f97b5d

Please sign in to comment.