StudentMapper { @Transactional(propagation = Propagation.REQUIRES_NEW) public MappingResult synchronizeStudentMapping(Student student) { if (!userMappingDao.existsMappingForSapUserId(student.getId())) { Identity mappedIdentity = studentMappingByMartikelNumber.tryToMap(student); if (mappedIdentity != null) { userMappingDao.saveMapping(student, mappedIdentity); return MappingResult.NEW_MAPPING_BY_MATRIKEL_NR; } mappedIdentity = mappingByEmail.tryToMap(student); if (mappedIdentity != null) { userMappingDao.saveMapping(student, mappedIdentity); return MappingResult.NEW_MAPPING_BY_EMAIL; } mappedIdentity = mappingByFirstNameAndLastName.tryToMap(student.getFirstName(), student.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 synchronizeStudentMapping(Student student);  }
@Test public void synchronizeStudentMapping_MappingAlreadyExist() { when(userMappingDaoMock.existsMappingForSapUserId(studentMock.getId())).thenReturn(true); MappingResult result = studentMapperTestObject.synchronizeStudentMapping(studentMock); assertEquals("", MappingResult.MAPPING_ALREADY_EXIST, result); }
@Test public void synchronizeStudentMapping_CouldNotMap() { when(userMappingDaoMock.existsMappingForSapUserId(studentMock.getId())).thenReturn(false); when(studentMappingByMartikelNumberMock.tryToMap(studentMock)).thenReturn(null); when(mappingByEmailMock.tryToMap(studentMock)).thenReturn(null); when(mappingByFirstNameAndLastNameMock.tryToMap(studentMock.getFirstName(), studentMock.getLastName())).thenReturn(null); MappingResult result = studentMapperTestObject.synchronizeStudentMapping(studentMock); assertEquals("", MappingResult.COULD_NOT_MAP, result); }
@Test public void synchronizeStudentMapping_MappingByMartikelNumber() { when(userMappingDaoMock.existsMappingForSapUserId(studentMock.getId())).thenReturn(false); when(studentMappingByMartikelNumberMock.tryToMap(studentMock)).thenReturn(identityMock); MappingResult result = studentMapperTestObject.synchronizeStudentMapping(studentMock); assertEquals("", MappingResult.NEW_MAPPING_BY_MATRIKEL_NR, result); }
@Test public void synchronizeStudentMapping_MappingByEmail() { when(userMappingDaoMock.existsMappingForSapUserId(studentMock.getId())).thenReturn(false); when(studentMappingByMartikelNumberMock.tryToMap(studentMock)).thenReturn(null); when(mappingByEmailMock.tryToMap(studentMock)).thenReturn(identityMock); MappingResult result = studentMapperTestObject.synchronizeStudentMapping(studentMock); assertEquals("", MappingResult.NEW_MAPPING_BY_EMAIL, result); }