コード例 #1
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);
  }