@Test
 public void testSyncSupported() throws NamingException {
   LdapConfiguration config = newConfiguration();
   LdapConnection conn = newConnection(config);
   assertEquals(ServerType.SUN_DSEE, conn.getServerType());
   Schema schema = newFacade(config).schema();
   ObjectClassInfo accountInfo = schema.findObjectClassInfo(ObjectClass.ACCOUNT_NAME);
   assertTrue(
       schema.getSupportedObjectClassesByOperation().get(SyncApiOp.class).contains(accountInfo));
 }
  @Test
  public void testAllBlocksReturnedFromSingleSyncCall() throws NamingException {
    LdapConfiguration config = newConfiguration();
    // Set a small block size so connector would have to do
    // a couple of searches to return all deltas.
    config.setChangeLogBlockSize(2);
    LdapConnection conn = newConnection(config);
    String baseContext = conn.getConfiguration().getBaseContexts()[0];

    int COUNT = 10;
    StringBuilder ldif = new StringBuilder();
    for (int i = 0; i < COUNT; i++) {
      String name = "user." + i;
      String entryDN = "uid=" + name + "," + baseContext;
      ldif.append(
          MessageFormat.format(
              "dn: {0}\n"
                  + "changetype: add\n"
                  + "objectClass: inetOrgPerson\n"
                  + "objectClass: organizationalPerson\n"
                  + "objectClass: person\n"
                  + "objectClass: top\n"
                  + "uid: {1}\n"
                  + "cn: {1}\n"
                  + "sn: {1}\n"
                  + "\n",
              entryDN, name));
    }

    List<SyncDelta> result = doTest(conn, ldif.toString(), COUNT);
    assertEquals(10, result.size());
    for (int i = 0; i < COUNT; i++) {
      String name = "user." + i;
      String entryDN = "uid=" + name + "," + baseContext;
      ConnectorObject object = result.get(i).getObject();
      assertEquals(new Uid(entryDN), object.getUid());
      assertEquals(new Name(entryDN), object.getName());
    }
  }
 private void testExpectingNoDelta(LdapConnection conn) throws NamingException {
   String baseContext = conn.getConfiguration().getBaseContexts()[0];
   String entryDN = "uid=foobar," + baseContext;
   List<SyncDelta> result =
       doTest(
           conn,
           "dn: "
               + entryDN
               + "\n"
               + "changetype: add\n"
               + "objectClass: inetOrgPerson\n"
               + "objectClass: organizationalPerson\n"
               + "objectClass: person\n"
               + "objectClass: top\n"
               + "uid: foobar\n"
               + "cn: Foo Bar\n"
               + "sn: Bar\n",
           0);
   assertTrue(result.isEmpty());
 }
  @Test
  public void testSimple() throws Exception {
    LdapConnection conn = newConnection(newConfiguration());
    String baseContext = conn.getConfiguration().getBaseContexts()[0];

    String entryDN = "uid=foobar," + baseContext;
    List<SyncDelta> result =
        doTest(
            conn,
            "dn: "
                + entryDN
                + "\n"
                + "changetype: add\n"
                + "objectClass: inetOrgPerson\n"
                + "objectClass: organizationalPerson\n"
                + "objectClass: person\n"
                + "objectClass: top\n"
                + "uid: foobar\n"
                + "cn: Foo Bar\n"
                + "sn: Bar\n",
            1);

    assertEquals(1, result.size());
    SyncDelta delta = result.get(0);
    assertEquals(SyncDeltaType.CREATE_OR_UPDATE, delta.getDeltaType());
    ConnectorObject object = delta.getObject();
    assertEquals(new Uid(entryDN), object.getUid());
    assertEquals(new Name(entryDN), object.getName());
    assertEquals(AttributeBuilder.build("uid", "foobar"), object.getAttributeByName("uid"));
    assertEquals(AttributeBuilder.build("cn", "Foo Bar"), object.getAttributeByName("cn"));
    assertEquals(AttributeBuilder.build("sn", "Bar"), object.getAttributeByName("sn"));

    result =
        doTest(conn, "dn: " + entryDN + "\n" + "changeType: modrdn\n" + "newRdn: cn=Foo Bar", 1);
    entryDN = "cn=Foo Bar," + baseContext;

    assertEquals(1, result.size());
    delta = result.get(0);
    assertEquals(SyncDeltaType.CREATE_OR_UPDATE, delta.getDeltaType());
    object = delta.getObject();
    assertEquals(new Uid(entryDN), object.getUid());
    assertEquals(new Name(entryDN), object.getName());
    assertEquals(AttributeBuilder.build("uid", emptyList()), object.getAttributeByName("uid"));
    assertEquals(AttributeBuilder.build("cn", "Foo Bar"), object.getAttributeByName("cn"));
    assertEquals(AttributeBuilder.build("sn", "Bar"), object.getAttributeByName("sn"));

    result =
        doTest(
            conn,
            "dn: " + entryDN + "\n" + "changeType: modify\n" + "add: cn\n" + "cn: Dummy User",
            1);

    assertEquals(1, result.size());
    delta = result.get(0);
    assertEquals(SyncDeltaType.CREATE_OR_UPDATE, delta.getDeltaType());
    object = delta.getObject();
    assertEquals(
        AttributeBuilder.build("cn", "Foo Bar", "Dummy User"), object.getAttributeByName("cn"));

    result =
        doTest(
            conn,
            "dn: "
                + entryDN
                + "\n"
                + "changeType: modrdn\n"
                + "newRdn: cn=Dummy User\n"
                + "deleteOldRdn: FALSE",
            1);
    entryDN = "cn=Dummy User," + baseContext;

    assertEquals(1, result.size());
    delta = result.get(0);
    assertEquals(SyncDeltaType.CREATE_OR_UPDATE, delta.getDeltaType());
    object = delta.getObject();
    assertEquals(new Uid(entryDN), object.getUid());
    assertEquals(new Name(entryDN), object.getName());
    assertEquals(
        AttributeBuilder.build("cn", "Foo Bar", "Dummy User"), object.getAttributeByName("cn"));

    result =
        doTest(
            conn,
            "dn: " + entryDN + "\n" + "changeType: modify\n" + "delete: cn\n" + "cn: Foo Bar",
            1);

    assertEquals(1, result.size());
    delta = result.get(0);
    assertEquals(SyncDeltaType.CREATE_OR_UPDATE, delta.getDeltaType());
    object = delta.getObject();
    assertEquals(AttributeBuilder.build("cn", "Dummy User"), object.getAttributeByName("cn"));

    result = doTest(conn, "dn: " + entryDN + "\n" + "changeType: delete", 1);

    assertEquals(1, result.size());
    delta = result.get(0);
    assertEquals(SyncDeltaType.DELETE, delta.getDeltaType());
    assertEquals(new Uid(entryDN), delta.getUid());
  }