@Test
  public void roleSearchWithEscapedCharacterSucceeds() throws Exception {
    String param = "cn=mouse\\, jerry,ou=people,dc=springframework,dc=org";

    Set<String> values =
        template.searchForSingleAttributeValues(
            "ou=groups", "(member={0})", new String[] {param}, "cn");

    assertEquals(1, values.size());
  }
  @Test
  public void testRoleSearchForMissingAttributeFailsGracefully() {
    String param = "uid=ben,ou=people,dc=springframework,dc=org";

    Set<String> values =
        template.searchForSingleAttributeValues(
            "ou=groups", "(member={0})", new String[] {param}, "mail");

    assertEquals(0, values.size());
  }
  @Test
  public void roleSearchReturnsCorrectNumberOfRoles() {
    String param = "uid=ben,ou=people,dc=springframework,dc=org";

    Set<String> values =
        template.searchForSingleAttributeValues(
            "ou=groups", "(member={0})", new String[] {param}, "ou");

    assertEquals("Expected 3 results from search", 3, values.size());
    assertTrue(values.contains("developer"));
    assertTrue(values.contains("manager"));
    assertTrue(values.contains("submanager"));
  }
 @Test
 public void namingExceptionIsTranslatedCorrectly() {
   try {
     template.executeReadOnly(
         new ContextExecutor() {
           public Object executeWithContext(DirContext dirContext) throws NamingException {
             throw new NamingException();
           }
         });
     fail("Expected UncategorizedLdapException on NamingException");
   } catch (UncategorizedLdapException expected) {
   }
 }
 @Test
 public void testMultiAttributeRetrievalWithSpecifiedAttributeNames() {
   Set<Map<String, List<String>>> values =
       template.searchForMultipleAttributeValues(
           "ou=people", "(uid={0})", new String[] {"bob"}, new String[] {"uid", "cn", "sn"});
   assertEquals(1, values.size());
   Map<String, List<String>> record = values.iterator().next();
   assertAttributeValue(record, "uid", "bob");
   assertAttributeValue(record, "cn", "Bob Hamilton");
   assertAttributeValue(record, "sn", "Hamilton");
   assertFalse(record.containsKey("userPassword"));
   assertFalse(record.containsKey("objectclass"));
 }
 @Test
 public void testMultiAttributeRetrievalWithZeroLengthAttributeNames() {
   Set<Map<String, List<String>>> values =
       template.searchForMultipleAttributeValues(
           "ou=people", "(uid={0})", new String[] {"bob"}, new String[0]);
   assertEquals(1, values.size());
   Map<String, List<String>> record = values.iterator().next();
   assertAttributeValue(record, "uid", "bob");
   assertAttributeValue(
       record, "objectclass", "top", "person", "organizationalPerson", "inetOrgPerson");
   assertAttributeValue(record, "cn", "Bob Hamilton");
   assertAttributeValue(record, "sn", "Hamilton");
   assertFalse(record.containsKey("userPassword"));
 }
 @Test
 public void compareOfWrongValueFails() {
   assertFalse(template.compare("uid=bob,ou=people", "uid", "wrongvalue"));
 }
 @Test
 public void compareOfWrongByteValueFails() {
   assertFalse(template.compare("uid=bob,ou=people", "userPassword", Utf8.encode("wrongvalue")));
 }
 @Test
 public void compareOfCorrectByteValueSucceeds() {
   assertTrue(template.compare("uid=bob,ou=people", "userPassword", Utf8.encode("bobspassword")));
 }
 @Test
 public void compareOfCorrectValueSucceeds() {
   assertTrue(template.compare("uid=bob,ou=people", "uid", "bob"));
 }
  @Test
  public void searchForSingleEntryWithEscapedCharsInDnSucceeds() {
    String param = "mouse, jerry";

    template.searchForSingleEntry("ou=people", "(cn={0})", new String[] {param});
  }