LecturerMapper { @Transactional(propagation = Propagation.REQUIRES_NEW) public MappingResult synchronizeLecturerMapping(Lecturer lecturer) { if (!userMappingDao.existsMappingForSapUserId(lecturer.getPersonalNr())) { Identity mappedIdentity = mappingByPersonalNumber.tryToMap(lecturer.getPersonalNr()); if (mappedIdentity != null) { userMappingDao.saveMapping(lecturer, mappedIdentity); return MappingResult.NEW_MAPPING_BY_PERSONAL_NR; } mappedIdentity = mappingByEmail.tryToMap(lecturer); if (mappedIdentity != null) { userMappingDao.saveMapping(lecturer, mappedIdentity); return MappingResult.NEW_MAPPING_BY_EMAIL; } if (StringUtils.isNotBlank(lecturer.getAdditionalPersonalNrs())) { List<String> personalNrs = Arrays.asList(lecturer.getAdditionalPersonalNrs().split("\\s*,\\s*")); for (String personalNr : personalNrs) { mappedIdentity = mappingByPersonalNumber.tryToMap(Long.valueOf(personalNr)); if (mappedIdentity != null) { userMappingDao.saveMapping(lecturer, mappedIdentity); return MappingResult.NEW_MAPPING_BY_ADDITIONAL_PERSONAL_NR; } } } mappedIdentity = mappingByFirstNameAndLastName.tryToMap(lecturer.getFirstName(), lecturer.getLastName()); if (mappedIdentity != null) { return MappingResult.COULD_BE_MAPPED_MANUALLY; } else { return MappingResult.COULD_NOT_MAP; } } return MappingResult.MAPPING_ALREADY_EXIST; }  @Transactional(propagation = Propagation.REQUIRES_NEW) MappingResult synchronizeLecturerMapping(Lecturer lecturer);  }
@Test public void synchronizeStudentMapping_MappingAlreadyExist() { when(userMappingDaoMock.existsMappingForSapUserId(lecturerMock.getPersonalNr())).thenReturn(true); MappingResult result = lecturerMapperTestObject.synchronizeLecturerMapping(lecturerMock); assertEquals("", MappingResult.MAPPING_ALREADY_EXIST, result); }
@Test public void synchronizeStudentMapping_CouldNotMap() { when(userMappingDaoMock.existsMappingForSapUserId(lecturerMock.getPersonalNr())).thenReturn(false); when(lecturerMappingByPersonalNumberMock.tryToMap(lecturerMock.getPersonalNr())).thenReturn(null); when(mappingByEmailMock.tryToMap(lecturerMock)).thenReturn(null); when(mappingByFirstNameAndLastNameMock.tryToMap(lecturerMock.getFirstName(), lecturerMock.getLastName())).thenReturn(null); MappingResult result = lecturerMapperTestObject.synchronizeLecturerMapping(lecturerMock); assertEquals("", MappingResult.COULD_NOT_MAP, result); }
@Test public void synchronizeStudentMapping_MappingByMartikelNumber() { when(userMappingDaoMock.existsMappingForSapUserId(lecturerMock.getPersonalNr())).thenReturn(false); when(lecturerMappingByPersonalNumberMock.tryToMap(lecturerMock.getPersonalNr())).thenReturn(identityMock); MappingResult result = lecturerMapperTestObject.synchronizeLecturerMapping(lecturerMock); assertEquals("", MappingResult.NEW_MAPPING_BY_PERSONAL_NR, result); }
@Test public void synchronizeStudentMapping_MappingByEmail() { when(userMappingDaoMock.existsMappingForSapUserId(lecturerMock.getPersonalNr())).thenReturn(false); when(lecturerMappingByPersonalNumberMock.tryToMap(lecturerMock.getPersonalNr())).thenReturn(null); when(mappingByEmailMock.tryToMap(lecturerMock)).thenReturn(identityMock); MappingResult result = lecturerMapperTestObject.synchronizeLecturerMapping(lecturerMock); assertEquals("", MappingResult.NEW_MAPPING_BY_EMAIL, result); }