コード例 #1
0
  @Test
  public void testGetFieldValue() throws Exception {
    LDAPConnection conn = ldapServer.getConnection();
    SearchResultEntry item =
        conn.searchForEntry("ou=People,dc=example,dc=com", SearchScope.SUB, "uid=bjensen");
    assertNotNull(item);

    LDAPDataProvider dp = new LDAPDataProvider();
    assertEquals("12345", dp.getFieldValue(item, "postalCode"));

    assertEquals("valid12345", dp.getFieldValue(item, "valid${postalCode}"));

    assertEquals("invalidAttribute", dp.getFieldValue(item, "invalidAttribute"));

    assertEquals("BJ", dp.getFieldValue(item, "${initials}"));
    assertEquals(" BJ ", dp.getFieldValue(item, " ${initials} "));
    assertEquals(" BJ arbitrary string", dp.getFieldValue(item, " ${initials} arbitrary string"));

    assertEquals(
        " BJ Web Developer arbitrary string",
        dp.getFieldValue(item, " ${initials} ${title} arbitrary string"));
    assertEquals(
        " BJWeb Developerarbitrary string",
        dp.getFieldValue(item, " ${initials}${title}arbitrary string"));
  }
コード例 #2
0
  @Test
  public void testFromSearchResultEntry() throws Exception {
    LDAPDataProvider dp = new LDAPDataProvider();
    Configuration cfg = Configuration.getInstance();

    LDAPConnection conn = ldapServer.getConnection();
    SearchResultEntry item =
        conn.searchForEntry(
            cfg.getLDAPConfiguration().getUserBaseDN(), SearchScope.SUB, "uid=bjensen");

    List<Treaty> t =
        new ArrayList<Treaty>() {
          {
            add(Treaty.CMS);
            add(Treaty.AEWA);
          }
        };

    LDAPConfiguration ldap = cfg.getLDAPConfiguration();
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_PREFIX, "personalTitle");
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_COUNTRY, "c");
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_FIRST_NAME, "givenName");
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_LAST_NAME, "sn");
    ldap.setMapping(
        LDAPConfiguration.LDAP_MAPPING_ADDRESS, "Address: ${registeredAddress} ${postalCode}");
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_DEPARTMENT, "ou");
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_EMAIL, "mail");
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_FAX, "facsimileTelephoneNumber");
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_INSTITUTION, "o");
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_PHONE, "telephoneNumber");
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_POSITION, "title");
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_UPDATED, "roomNumber");
    ldap.setMapping(LDAPConfiguration.LDAP_MAPPING_TREATIES, "carLicense");
    cfg.save();

    IContact c = dp.fromSearchResultEntry(item);

    assertEquals("Address: 5th Avenue, NY 12345", c.getAddress());
    assertEquals("bjensen", c.getId());
    assertEquals("RO", c.getCountry());
    assertEquals("Software Development", c.getDepartment());
    assertEquals("*****@*****.**", c.getEmail());
    assertEquals("+1 408 555 1992", c.getFax());
    assertEquals("Barbara", c.getFirstName());
    assertEquals("Eau de Web", c.getInstitution());
    assertEquals("Jensen", c.getLastName());
    assertEquals("+1 408 555 1862", c.getPhoneNumber());
    assertEquals("Web Developer", c.getPosition());
    assertEquals("H.E.", c.getPrefix());
    assertEquals(new Short((short) 1), c.getProtocolVersion());
    assertEquals(t, c.getTreaties());

    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+2"));
    cal.set(2006, 11, 25, 16, 45, 22);
    cal.set(Calendar.MILLISECOND, 0);
    Date d = cal.getTime();
    Date updated = c.getUpdated();
    assertEquals(updated, d);
  }
コード例 #3
0
  @Test(expected = InvalidValueException.class)
  public void testFromSearchResultEntryMissingId() throws Exception {
    LDAPDataProvider dp = new LDAPDataProvider();
    Configuration cfg = Configuration.getInstance();

    LDAPConnection conn = ldapServer.getConnection();
    SearchResultEntry item =
        conn.searchForEntry(
            cfg.getLDAPConfiguration().getUserBaseDN(), SearchScope.SUB, "uid=bjensen");
    cfg.getLDAPConfiguration().setMapping(LDAPConfiguration.LDAP_MAPPING_ID, "unknown");
    dp.fromSearchResultEntry(item);
  }