コード例 #1
0
 @Test
 public void testOpenResources() {
   LDAPDataProvider dp = new LDAPDataProvider();
   dp.openResources();
   LDAPConnection conn = dp.getConnection();
   assertNotNull(conn);
   assertTrue(conn.isConnected());
   dp.closeResources();
 }
コード例 #2
0
  @Test(expected = RuntimeException.class)
  public void testOpenResourcesException() {
    // Test invalid connection
    LDAPConfiguration ldap = new LDAPConfiguration();
    ldap.setHost("invalid");
    ldap.setPort(-1);
    Configuration cfg = Configuration.getInstance();
    cfg.setLDAPConfiguration(ldap);

    LDAPDataProvider dp = new LDAPDataProvider();
    try {
      dp.openResources();
      assertNull(dp.getConnection());
    } finally {
      // Put back the correct configuration
      ldap.setHost(ldapServer.getListenAddress().getHostAddress());
      ldap.setPort(ldapServer.getListenPort());
      ldap.setBindDN(BIND_DN);
      ldap.setPassword(BIND_PASSWORD);
      ldap.setUserBaseDN("ou=People,dc=example,dc=com");
      ldap.setUsersQueryFilter("uid=*");
      cfg.setLDAPConfiguration(ldap);
    }
  }