### Question:
DefaultLdapConfigurationService implements LdapConfigurationService { @Override public String checkUserAttributes(String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException { String userDn; try { LOGGER.info("Checking user attributes for user [{}] ...", testUserName); String filter = FilterBuilder.and( FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()), FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), testUserName)) .toString(); LOGGER.info("Searching for the user: [{}] using the search filter: [{}]", testUserName, filter); userDn = ldapConnectionTemplateFactory.create(ambariLdapConfiguration).searchFirst(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE, getUserDnNameEntryMapper(ambariLdapConfiguration)); if (null == userDn) { LOGGER.info("Could not find test user based on the provided configuration. User attributes may not be complete or the user may not exist."); throw new AmbariLdapException("Could not find test user based on the provided configuration. User attributes may not be complete or the user may not exist."); } LOGGER.info("Attribute validation succeeded. Filter: [{}]", filter); } catch (Exception e) { LOGGER.error("User attributes validation failed.", e); throw new AmbariLdapException(e.getMessage(), e); } return userDn; } @Inject  DefaultLdapConfigurationService(); @Override void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration); @Override String checkUserAttributes(String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration); @Override Set<String> checkGroupAttributes(String userDn, AmbariLdapConfiguration ambariLdapConfiguration);  }### Answer:
@Test public void testShouldUserAttributeConfigurationCheckSucceedWhenUserDnIsFound() throws Exception { Map<String, String> configMap = Maps.newHashMap(); configMap.put(AmbariServerConfigurationKey.USER_OBJECT_CLASS.key(), "person"); configMap.put(AmbariServerConfigurationKey.USER_NAME_ATTRIBUTE.key(), "uid"); AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(configMap); EasyMock.expect(ldapConnectionTemplateFactory.create(ambariLdapConfiguration)).andReturn(ldapConnectionTemplateMock); EasyMock.expect(ldapConnectionTemplateMock.searchFirst(EasyMock.anyObject(Dn.class), EasyMock.anyString(), EasyMock.anyObject(SearchScope.class), EasyMock.anyObject(EntryMapper.class))).andReturn("dn"); replayAll(); String userDn = ldapConfigurationService.checkUserAttributes("testUser", "testPassword", ambariLdapConfiguration); Assert.assertEquals("The found userDn is not the expected one", userDn, "dn"); }
@Test(expected = AmbariLdapException.class) public void testShouldUserAttributeConfigurationCheckFailWhenNoUsersFound() throws Exception { Map<String, String> configMap = Maps.newHashMap(); configMap.put(AmbariServerConfigurationKey.USER_OBJECT_CLASS.key(), "posixAccount"); configMap.put(AmbariServerConfigurationKey.USER_NAME_ATTRIBUTE.key(), "dn"); AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(configMap); EasyMock.expect(ldapConnectionTemplateFactory.create(ambariLdapConfiguration)).andReturn(ldapConnectionTemplateMock); EasyMock.expect(ldapConnectionTemplateMock.searchFirst(EasyMock.anyObject(Dn.class), EasyMock.anyString(), EasyMock.anyObject(SearchScope.class), EasyMock.anyObject(EntryMapper.class))).andReturn(null); replayAll(); String userDn = ldapConfigurationService.checkUserAttributes("testUser", "testPassword", ambariLdapConfiguration); Assert.assertEquals("The found userDn is not the expected one", userDn, "dn"); }