SI-731 correction with plz list mapping. Asserted by unit tests.
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/DistributionGroupMemberMapper.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/DistributionGroupMemberMapper.java
index c773c97..9b772da 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/DistributionGroupMemberMapper.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/mapper/DistributionGroupMemberMapper.java
@@ -45,6 +45,7 @@
.split(","));
targetDto.setPostcodeList(result.stream()
+ .filter( x -> !x.isEmpty() )
.sorted( String::compareTo )
.collect(Collectors.toList())
);
@@ -61,6 +62,7 @@
default void mapPostcodesFromList(DistributionGroupMemberDto srcDto, @MappingTarget TblDistributionGroupMember targetTbl) {
StringBuilder sb = new StringBuilder();
Optional.ofNullable(srcDto.getPostcodeList()).orElse( new ArrayList<>()).stream()
+ .filter( x -> x!=null && !x.isEmpty() )
.sorted(String::compareTo)
.forEach(x -> sb.append("," + x));
targetTbl.setPostcodes(
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/DistributionGroupServiceMemberTest.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/DistributionGroupServiceMemberTest.java
index 21cff40..de3606b 100644
--- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/DistributionGroupServiceMemberTest.java
+++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/DistributionGroupServiceMemberTest.java
@@ -18,6 +18,7 @@
import org.eclipse.openk.gridfailureinformation.config.TestConfiguration;
import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.exceptions.OperationDeniedException;
+import org.eclipse.openk.gridfailureinformation.mapper.DistributionGroupMemberMapper;
import org.eclipse.openk.gridfailureinformation.model.TblDistributionGroup;
import org.eclipse.openk.gridfailureinformation.model.TblDistributionGroupMember;
import org.eclipse.openk.gridfailureinformation.repository.DistributionGroupMemberRepository;
@@ -36,6 +37,7 @@
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
+import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -54,11 +56,14 @@
@DataJpaTest
@ContextConfiguration(classes = {TestConfiguration.class})
-public class DistributionGroupServiceMemberTest {
+class DistributionGroupServiceMemberTest {
@Qualifier("myDistributionGroupMemberService")
@Autowired
private DistributionGroupMemberService distributionGroupMemberService;
+ @Autowired
+ private DistributionGroupMemberMapper distributionGroupMemberMapper;
+
@MockBean
private DistributionGroupMemberRepository distributionGroupMemberRepository;
@@ -69,7 +74,7 @@
private ContactApi contactApi;
@Test
- public void shouldGetAllDistributionGroupMembers() {
+ void shouldGetAllDistributionGroupMembers() {
List<TblDistributionGroupMember> groupMembers = MockDataHelper.mockDistributionGroupMemberList();
when(distributionGroupMemberRepository.findAll()).thenReturn(groupMembers);
List<DistributionGroupMemberDto> groupMemberDtoList = distributionGroupMemberService.getDistributionGroupMembers();
@@ -81,7 +86,7 @@
@Test
@WithMockUser(username = "admin", authorities = { "ADMIN", "USER" })
- public void shouldGetAllMembersOfASingleDistributionGroup() {
+ void shouldGetAllMembersOfASingleDistributionGroup() {
List<TblDistributionGroupMember> groupMembers = MockDataHelper.mockDistributionGroupMemberList();
when(distributionGroupMemberRepository.findByTblDistributionGroupUuid(any(UUID.class))).thenReturn(groupMembers);
List<DistributionGroupMemberDto> groupMemberDtoList = distributionGroupMemberService.getMembersByGroupId(groupMembers.get(1).getTblDistributionGroup().getUuid());
@@ -92,8 +97,36 @@
}
@Test
+ void shouldMapEmptyPlzListCorrectly() {
+ TblDistributionGroupMember tbl1 = MockDataHelper.mockTblDistributionGroupMember();
+ tbl1.setPostcodes(null);
+ assertTrue(distributionGroupMemberMapper.toDistributionGroupMemberDto(tbl1).getPostcodeList().isEmpty());
+
+ TblDistributionGroupMember tbl2 = MockDataHelper.mockTblDistributionGroupMember();
+ tbl2.setPostcodes("");
+ assertTrue(distributionGroupMemberMapper.toDistributionGroupMemberDto(tbl2).getPostcodeList().isEmpty());
+
+ TblDistributionGroupMember tbl3 = MockDataHelper.mockTblDistributionGroupMember();
+ tbl3.setPostcodes("5,3,1");
+ DistributionGroupMemberDto dto3 = distributionGroupMemberMapper.toDistributionGroupMemberDto(tbl3);
+ assertEquals("1", dto3.getPostcodeList().get(0));
+ assertEquals("3", dto3.getPostcodeList().get(1));
+ assertEquals("5", dto3.getPostcodeList().get(2));
+
+ List<String> testList = new LinkedList<>();
+ testList.add(null);
+ testList.add("");
+ testList.add("32");
+ testList.add("23");
+
+ dto3.setPostcodeList(testList);
+ TblDistributionGroupMember tblResult = distributionGroupMemberMapper.toTblDistributionGroupMember(dto3);
+ assertEquals( "23,32", tblResult.getPostcodes());
+ }
+
+ @Test
@WithMockUser(username = "admin", authorities = { "ADMIN", "USER" })
- public void shouldFindASingleDistributionGroupMember() {
+ void shouldFindASingleDistributionGroupMember() {
TblDistributionGroupMember groupMember = MockDataHelper.mockTblDistributionGroupMember();
when(distributionGroupMemberRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(groupMember));
DistributionGroupMemberDto dto = distributionGroupMemberService.getMemberByUuid(groupMember.getTblDistributionGroup().getUuid(), UUID.randomUUID());
@@ -106,7 +139,8 @@
@Test
void shouldHandleLoadFileWithNotFoundException() {
when(distributionGroupRepository.findByUuid(any(UUID.class))).thenReturn(Optional.empty());
- assertThrows( NotFoundException.class, () -> distributionGroupMemberService.handleLoadFile(UUID.randomUUID()));
+ UUID uuid = UUID.randomUUID();
+ assertThrows( NotFoundException.class, () -> distributionGroupMemberService.handleLoadFile(uuid));
}
@Test
@@ -126,15 +160,17 @@
}
@Test
- public void shouldThrowExceptionWhenFailureNotFound() {
+ void shouldThrowExceptionWhenFailureNotFound() {
TblDistributionGroupMember groupMember = MockDataHelper.mockTblDistributionGroupMember();
when(distributionGroupMemberRepository.findByUuid(any(UUID.class))).thenReturn(Optional.empty());
+ UUID uuid = UUID.randomUUID();
+ UUID dgMemberUuid = groupMember.getTblDistributionGroup().getUuid();
assertThrows(NotFoundException.class,
- () -> distributionGroupMemberService.getMemberByUuid(groupMember.getTblDistributionGroup().getUuid(), UUID.randomUUID()));
+ () -> distributionGroupMemberService.getMemberByUuid(dgMemberUuid, uuid));
}
@Test
- public void shouldInsertADistributionGroupMember() {
+ void shouldInsertADistributionGroupMember() {
DistributionGroupMemberDto memberDto = MockDataHelper.mockDistributionGroupMemberDto();
TblDistributionGroupMember tblDistributionGroupMember = MockDataHelper.mockTblDistributionGroupMember();
@@ -152,7 +188,7 @@
}
@Test
- public void shouldNotInsertMember_Exception_Member_Exists() {
+ void shouldNotInsertMember_Exception_Member_Exists() {
DistributionGroupMemberDto memberDto = MockDataHelper.mockDistributionGroupMemberDto();
TblDistributionGroupMember tblDistributionGroupMember = MockDataHelper.mockTblDistributionGroupMember();
@@ -161,12 +197,12 @@
when(distributionGroupRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(tblDistributionGroup));
when(distributionGroupMemberRepository.countByDistributionGroupIdAndContactId(anyLong(),any(UUID.class))).thenReturn(4L);
when(distributionGroupMemberRepository.save(any(TblDistributionGroupMember.class))).thenReturn(tblDistributionGroupMember);
-
- assertThrows(OperationDeniedException.class, () -> distributionGroupMemberService.insertDistributionGroupMember(UUID.randomUUID(), memberDto));
+ UUID uuid = UUID.randomUUID();
+ assertThrows(OperationDeniedException.class, () -> distributionGroupMemberService.insertDistributionGroupMember(uuid, memberDto));
}
@Test
- public void shouldDeleteDistributionGroupMember() {
+ void shouldDeleteDistributionGroupMember() {
TblDistributionGroupMember tblDistributionGroupMember = MockDataHelper.mockTblDistributionGroupMember();
TblDistributionGroup tblDistributionGroup = MockDataHelper.mockTblDistributionGroup();
@@ -181,7 +217,7 @@
@Test
- public void shouldUpdateDistributionGroupMember() {
+ void shouldUpdateDistributionGroupMember() {
DistributionGroupMemberDto memberDto = MockDataHelper.mockDistributionGroupMemberDto();
TblDistributionGroupMember tblDistributionGroupMember = MockDataHelper.mockTblDistributionGroupMember();
TblDistributionGroup tblDistributionGroup = MockDataHelper.mockTblDistributionGroup();
@@ -195,7 +231,7 @@
}
@Test
- public void shouldNotUpdateMember_Exception_GroupNotFound() {
+ void shouldNotUpdateMember_Exception_GroupNotFound() {
DistributionGroupMemberDto memberDto = MockDataHelper.mockDistributionGroupMemberDto();
TblDistributionGroupMember tblDistributionGroupMember = MockDataHelper.mockTblDistributionGroupMember();
TblDistributionGroup tblDistributionGroup = MockDataHelper.mockTblDistributionGroup();
@@ -209,7 +245,8 @@
Object[] args = invocation.getArguments();
return (TblDistributionGroupMember) args[0];
});
- assertThrows(NotFoundException.class, () -> distributionGroupMemberService.updateGroupMember(UUID.randomUUID(), memberDto));
+ UUID uuid = UUID.randomUUID();
+ assertThrows(NotFoundException.class, () -> distributionGroupMemberService.updateGroupMember(uuid, memberDto));
}