LdapUserNodeMapper extends BaseAttributeMapper<LdapUserNode> { @Override public LdapUserNode mapFromAttributes(Attributes attributes) throws NamingException { var idAttrValue = getSingleAttributeValue(attributes, idAttribute, String.class); var nameAttrValue = getSingleAttributeValue(attributes, "name", String.class); var givenNameAttrValue = getSingleAttributeValue(attributes, "givenName", String.class); var mailAttrValue = getSingleAttributeValue(attributes, "mail", String.class); var managerAttrValue = getSingleAttributeValue(attributes, "manager", String.class); var snAttrValue = getSingleAttributeValue(attributes, "sn", String.class); var departmentAttrValue = getSingleAttributeValue(attributes, "department", String.class); var divisionAttrValue = getSingleAttributeValue(attributes, "division", String.class); var dnAttrValue = getSingleAttributeValue(attributes, "distinguishedName", String.class); var directReportsAttrValue = getAllAttributeValues(attributes, "directReports", String.class); return new LdapUserNode(idAttrValue, nameAttrValue, givenNameAttrValue, snAttrValue, mailAttrValue, divisionAttrValue, departmentAttrValue, dnAttrValue, managerAttrValue, directReportsAttrValue); } LdapUserNodeMapper(String idAttribute); @Override LdapUserNode mapFromAttributes(Attributes attributes);  }
@Test public void mapFromAttributeReturnsExpectedNode() throws NamingException { var expectedId = "ID"; var expectedName = "full name"; var expectedGivenName = "given name"; var expectedMail = "mail@test.com"; var expectedManagerDn = "manager DN"; var expectedSurname = "surname"; var expectedDepartment = "department"; var expectedDivision = "division"; var expectedDn = "user DN"; var expectedDirectReports = List.of("D1", "D2"); var idAttr = createAttribute(ID_ATTR_ID, expectedId); var nameAttr = createAttribute("name", expectedName); var givenNameAttr = createAttribute("givenName", expectedGivenName); var mailAttr = createAttribute("mail", expectedMail); var managerAttr = createAttribute("manager", expectedManagerDn); var surnameAttr = createAttribute("sn", expectedSurname); var departmentAttr = createAttribute("department", expectedDepartment); var divisionAttr = createAttribute("division", expectedDivision); var dnAttr = createAttribute("distinguishedName", expectedDn); var directReportsAttr = createAttribute("directReports", "D1", "D2"); var attributes = new BasicAttributes(); for(var attr : List.of(idAttr, nameAttr, givenNameAttr, mailAttr, managerAttr, surnameAttr, departmentAttr, divisionAttr, dnAttr, directReportsAttr)) { attributes.put(attr); } var expectedNode = new LdapUserNode(expectedId, expectedName, expectedGivenName, expectedSurname, expectedMail, expectedDivision, expectedDepartment, expectedDn, expectedManagerDn, expectedDirectReports); var actualNode = mapper.mapFromAttributes(attributes); assertThat(actualNode).isEqualTo(expectedNode); }