Commit 9a8251cd authored by Ina Curdt's avatar Ina Curdt
Browse files

Merge branch 'SI-77-unterlagerte_Stoerungen_in_Übersicht' of...

Merge branch 'SI-77-unterlagerte_Stoerungen_in_Übersicht' of ssh://git.eclipse.org:29418/openk-usermodules/org.eclipse.openk-usermodules.gridFailureInformation.backend into DEVELOP
parents 01eabef1 1e9a41d2
...@@ -16,6 +16,7 @@ package org.eclipse.openk.gridfailureinformation.service; ...@@ -16,6 +16,7 @@ package org.eclipse.openk.gridfailureinformation.service;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessState; import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessState;
import org.eclipse.openk.gridfailureinformation.config.TestConfiguration; import org.eclipse.openk.gridfailureinformation.config.TestConfiguration;
import org.eclipse.openk.gridfailureinformation.exceptions.BadRequestException;
import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException; import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.exceptions.OperationDeniedException; import org.eclipse.openk.gridfailureinformation.exceptions.OperationDeniedException;
import org.eclipse.openk.gridfailureinformation.model.*; import org.eclipse.openk.gridfailureinformation.model.*;
...@@ -23,6 +24,7 @@ import org.eclipse.openk.gridfailureinformation.repository.*; ...@@ -23,6 +24,7 @@ import org.eclipse.openk.gridfailureinformation.repository.*;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper; import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto; import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
...@@ -582,6 +584,47 @@ public class FailureInformationServiceTest { ...@@ -582,6 +584,47 @@ public class FailureInformationServiceTest {
} }
@Test
public void shouldUpdateSubordinateFailureInfos(){
TblFailureInformation fi = MockDataHelper.mockTblFailureInformation();
when(failureInformationRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(fi));
List<TblFailureInformation> fiMockList = MockDataHelper.mockTblFailureInformationList();
when(failureInformationRepository.findByFailureInformationCondensedUuid(any(UUID.class))).thenReturn(fiMockList);
List<TblFailureInformation> subordinatedFiList = MockDataHelper.mockTblFailureInformationList();
when(failureInformationRepository.findByUuidIn(anyList())).thenReturn(subordinatedFiList);
when(statusRepository.findByStatus(anyString())).thenReturn(Optional.of(MockDataHelper.mockRefStatus()));
when(failureInformationRepository.save(any(TblFailureInformation.class)))
.then((Answer<TblFailureInformation>) invocation -> {
Object[] args = invocation.getArguments();
return (TblFailureInformation) args[0];
});
List<UUID> subordinatedFiUuidList = MockDataHelper.mockUuidList();
FailureInformationDto condensedFi = failureInformationService.updateSubordinatedFailureInfos(UUID.randomUUID(), subordinatedFiUuidList);
assertEquals( condensedFi.getCondensedCount(), subordinatedFiList.size() );
}
@Test
public void shouldNotUpdateSubordinateFailureInfos_emptyUuidList(){
TblFailureInformation fi = MockDataHelper.mockTblFailureInformation();
when(failureInformationRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(fi));
List<TblFailureInformation> fiMockList = MockDataHelper.mockTblFailureInformationList();
when(failureInformationRepository.findByFailureInformationCondensedUuid(any(UUID.class))).thenReturn(fiMockList);
List<TblFailureInformation> subordinatedFiList = MockDataHelper.mockTblFailureInformationList();
when(failureInformationRepository.findByUuidIn(anyList())).thenReturn(subordinatedFiList);
List<UUID> subordinatedFiUuidList = new ArrayList<UUID>();
assertThrows(BadRequestException.class, () -> failureInformationService.updateSubordinatedFailureInfos(UUID.randomUUID(), subordinatedFiUuidList));
}
} }
...@@ -834,8 +834,8 @@ public class MockDataHelper { ...@@ -834,8 +834,8 @@ public class MockDataHelper {
return importDataList; return importDataList;
} }
public static List mockUuidList(){ public static List<UUID> mockUuidList(){
List list = new ArrayList(); List<UUID> list = new ArrayList();
list.add(UUID.randomUUID()); list.add(UUID.randomUUID());
list.add(UUID.randomUUID()); list.add(UUID.randomUUID());
...@@ -844,12 +844,23 @@ public class MockDataHelper { ...@@ -844,12 +844,23 @@ public class MockDataHelper {
return list; return list;
} }
public static List mockTblFailureInformationList(){ public static List<TblFailureInformation> mockTblFailureInformationList(){
List list = new ArrayList(); List<TblFailureInformation> list = new ArrayList();
list.add(mockTblFailureInformation()); list.add(mockTblFailureInformation());
list.add(mockTblFailureInformation()); list.add(mockTblFailureInformation());
list.add(mockTblFailureInformation()); list.add(mockTblFailureInformation());
list.add(mockTblFailureInformation());
return list;
}
public static List<TblFailureInformation> mockTblFailureInformationList2(){
List<TblFailureInformation> list = new ArrayList();
list.add(mockTblFailureInformation2());
list.add(mockTblFailureInformation2());
list.add(mockTblFailureInformation2());
return list; return list;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment