LecturerMappingByPersonalNumber extends AbstractMappingByInstitutionalIdentifier { public Identity tryToMap(Long personalNr) { Identity mappedIdentity = tryToMap(UserConstants.INSTITUTIONAL_EMPLOYEE_NUMBER, "%" + personalNr.toString()); if (mappedIdentity != null) { String personalNumber = mappedIdentity.getUser().getRawUserProperty(UserConstants.INSTITUTIONAL_EMPLOYEE_NUMBER); try { Long personalNumberAsLong = Long.valueOf(personalNumber); if (personalNumberAsLong.equals(personalNr)) { return mappedIdentity; } log.warn("User-Property as Long (" + personalNumberAsLong + ") has not the same value as lecturer personal-number=" + personalNr); } catch (NumberFormatException ex) { log.warn("Could not convert personal-number to Long"); } } return null; }  Identity tryToMap(Long personalNr);  }
@Test public void tryToMap_foundNoMapping() { List<Identity> emptyResults = new ArrayList<Identity>(); when( baseSecurityMock.getVisibleIdentitiesByPowerSearch(anyString(), anyMap(), anyBoolean(), any(SecurityGroup[].class), any(PermissionOnResourceable[].class), any(String[].class), any(Date.class), any(Date.class))).thenReturn(emptyResults); Identity mappedIdentity = lecturerMappingByPersonalNumberTestObject.tryToMap(lecturerMock.getPersonalNr()); assertNull("Must return null, when no mapping exists", mappedIdentity); }
@Test public void tryToMap_foundMoreThanOneMapping() { List<Identity> twoIdentities = new ArrayList<Identity>(); twoIdentities.add(identityMockOne); twoIdentities.add(identityMockTwo); when( baseSecurityMock.getVisibleIdentitiesByPowerSearch(anyString(), anyMap(), anyBoolean(), any(SecurityGroup[].class), any(PermissionOnResourceable[].class), any(String[].class), any(Date.class), any(Date.class))).thenReturn(twoIdentities); Identity mappedIdentity = lecturerMappingByPersonalNumberTestObject.tryToMap(lecturerMock.getPersonalNr()); assertNull("Must return null, when more than one mapping exists", mappedIdentity); }
@Test public void tryToMap_foundOneMapping() { List<Identity> oneIdentities = new ArrayList<Identity>(); oneIdentities.add(identityMockOne); when( baseSecurityMock.getVisibleIdentitiesByPowerSearch(anyString(), anyMap(), anyBoolean(), any(SecurityGroup[].class), any(PermissionOnResourceable[].class), any(String[].class), any(Date.class), any(Date.class))).thenReturn(oneIdentities); Identity mappedIdentity = lecturerMappingByPersonalNumberTestObject.tryToMap(lecturerMock.getPersonalNr()); assertNotNull("Must return an identity, when only one mapping exists", mappedIdentity); }