Search in sources :

Example 41 with LDIFDeleteChangeRecord

use of com.unboundid.ldif.LDIFDeleteChangeRecord in project ldapsdk by pingidentity.

the class ParallelUpdateTestCase method testRejectedDelete.

/**
 * Tests with a rejected delete operation because the entry does not exist.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testRejectedDelete() throws Exception {
    final File ldifFile = createTempFile("dn: ou=People,dc=example,dc=com", "changetype: delete");
    final File rejectFile = createTempFile();
    final InMemoryDirectoryServer ds = getTestDS(false, false);
    assertEquals(ParallelUpdate.main(NO_OUTPUT, NO_OUTPUT, "--hostname", "localhost", "--port", String.valueOf(ds.getListenPort()), "--ldifFile", ldifFile.getAbsolutePath(), "--rejectFile", rejectFile.getAbsolutePath(), "--useFirstRejectResultCodeAsExitCode"), ResultCode.NO_SUCH_OBJECT);
    try (LDIFReader reader = new LDIFReader(rejectFile)) {
        final LDIFChangeRecord changeRecord = reader.readChangeRecord(true);
        assertNotNull(changeRecord);
        assertTrue(changeRecord instanceof LDIFDeleteChangeRecord);
        assertDNsEqual(changeRecord.getDN(), "ou=People,dc=example,dc=com");
        assertNull(reader.readChangeRecord());
    }
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDIFReader(com.unboundid.ldif.LDIFReader) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) File(java.io.File) Test(org.testng.annotations.Test)

Example 42 with LDIFDeleteChangeRecord

use of com.unboundid.ldif.LDIFDeleteChangeRecord in project ldapsdk by pingidentity.

the class LDAPDiffTestCase method testDataSetWithProgress.

/**
 * Tests the behavior when working with data set that is large enough to make
 * use of progress information.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDataSetWithProgress() throws Exception {
    try (InMemoryDirectoryServer sourceDS = createTestDS(true, true, 3_000);
        InMemoryDirectoryServer targetDS = createTestDS(true, true, 3_000)) {
        // First, test with the servers in what should be identical.
        File outputFile = runTool(sourceDS, targetDS, ResultCode.SUCCESS);
        assertTrue(readChangeRecords(outputFile).isEmpty());
        // Alter the contents of the servers to introduce differences.  This
        // includes:
        // - Add an entry only on the source server (resulting in a delete)
        // - Add an entry only on the target server (resulting in an add)
        // - Modify an entry differently on each server (resulting in a modify)
        sourceDS.add(generateUserEntry("source.only", "ou=People,dc=example,dc=com", "Source", "Only", "password"));
        targetDS.add(generateUserEntry("target.only", "ou=People,dc=example,dc=com", "Target", "Only", "password"));
        sourceDS.modify("dn: uid=user.1,ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: source");
        targetDS.modify("dn: uid=user.1,ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: target");
        // Verify that the ldap-diff tool now sees all of the appropriate
        // differences, and in the appropriate order.
        outputFile = runTool(sourceDS, targetDS, ResultCode.COMPARE_FALSE);
        List<LDIFChangeRecord> changeRecords = readChangeRecords(outputFile);
        assertFalse(changeRecords.isEmpty());
        assertEquals(changeRecords.size(), 3, String.valueOf(changeRecords));
        assertEquals(changeRecords.get(0), new LDIFDeleteChangeRecord("uid=source.only,ou=People,dc=example,dc=com"));
        assertEquals(changeRecords.get(1), new LDIFModifyChangeRecord(new ModifyRequest("dn: uid=user.1,ou=People,dc=example,dc=com", "changetype: modify", "delete: description", "description: source", "-", "add: description", "description: target")));
        assertEquals(changeRecords.get(2), new LDIFAddChangeRecord(generateUserEntry("target.only", "ou=People,dc=example,dc=com", "Target", "Only", "password")));
        // Clear the target server and make sure that a diff contains only
        // delete records, and that they are in the appropriate order.
        targetDS.clear();
        outputFile = runTool(sourceDS, targetDS, ResultCode.COMPARE_FALSE);
        changeRecords = readChangeRecords(outputFile);
        assertFalse(changeRecords.isEmpty());
        assertEquals(changeRecords.size(), 3_003);
        for (int i = 0; i < 3_003; i++) {
            final LDIFChangeRecord changeRecord = changeRecords.get(i);
            assertTrue(changeRecord instanceof LDIFDeleteChangeRecord);
            switch(i) {
                case 3_001:
                    assertEquals(changeRecord.getParsedDN(), new DN("ou=People,dc=example,dc=com"));
                    break;
                case 3_002:
                    assertEquals(changeRecord.getParsedDN(), new DN("dc=example,dc=com"));
                    break;
                default:
                    assertEquals(changeRecord.getParsedDN().getParent(), new DN("ou=People,dc=example,dc=com"));
            }
        }
        // Run the same test, but with the source and target servers flipped.
        // This should result in all adds.
        outputFile = runTool(targetDS, sourceDS, ResultCode.COMPARE_FALSE);
        changeRecords = readChangeRecords(outputFile);
        assertFalse(changeRecords.isEmpty());
        assertEquals(changeRecords.size(), 3_003);
        for (int i = 0; i < 3_003; i++) {
            final LDIFChangeRecord changeRecord = changeRecords.get(i);
            assertTrue(changeRecord instanceof LDIFAddChangeRecord);
            switch(i) {
                case 0:
                    assertEquals(changeRecord.getParsedDN(), new DN("dc=example,dc=com"));
                    break;
                case 1:
                    assertEquals(changeRecord.getParsedDN(), new DN("ou=People,dc=example,dc=com"));
                    break;
                default:
                    assertEquals(changeRecord.getParsedDN().getParent(), new DN("ou=People,dc=example,dc=com"));
            }
        }
    }
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) DN(com.unboundid.ldap.sdk.DN) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) File(java.io.File) Test(org.testng.annotations.Test)

Example 43 with LDIFDeleteChangeRecord

use of com.unboundid.ldif.LDIFDeleteChangeRecord in project ldapsdk by pingidentity.

the class ScrambleAttributeTransformationTestCase method testTransformDeleteChangeRecord.

/**
 * Provides basic test coverage for the transformChangeRecord method for a
 * delete record.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testTransformDeleteChangeRecord() throws Exception {
    final Schema schema = Schema.getDefaultStandardSchema();
    final ScrambleAttributeTransformation t = new ScrambleAttributeTransformation(schema, 0L, true, Arrays.asList("uid"), null);
    final LDIFChangeRecord r = t.transformChangeRecord(new LDIFDeleteChangeRecord("uid=user.1,ou=People,dc=example,dc=com"));
    assertNotNull(r);
    assertFalse(r.getDN().equals("uid=user.1,ou=People,dc=example,dc=com"));
    assertTrue(r.getDN().startsWith("uid="));
    assertTrue(r.getDN().endsWith(",ou=People,dc=example,dc=com"));
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) Schema(com.unboundid.ldap.sdk.schema.Schema) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) Test(org.testng.annotations.Test)

Example 44 with LDIFDeleteChangeRecord

use of com.unboundid.ldif.LDIFDeleteChangeRecord in project ldapsdk by pingidentity.

the class ExcludeChangeTypeTransformationTestCase method testExcludeNullSet.

/**
 * Tests the behavior when the set of change types to exclude is
 * {@code null}}.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExcludeNullSet() throws Exception {
    final ExcludeChangeTypeTransformation t = new ExcludeChangeTypeTransformation((ChangeType[]) null);
    final LDIFAddChangeRecord addChangeRecord = new LDIFAddChangeRecord(new Entry("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example"));
    assertNotNull(t.transformChangeRecord(addChangeRecord));
    assertEquals(t.transformChangeRecord(addChangeRecord), addChangeRecord);
    assertNotNull(t.translate(addChangeRecord, 0));
    assertEquals(t.translate(addChangeRecord, 0), addChangeRecord);
    assertNotNull(t.translateChangeRecordToWrite(addChangeRecord));
    assertEquals(t.translateChangeRecordToWrite(addChangeRecord), addChangeRecord);
    final LDIFDeleteChangeRecord deleteChangeRecord = new LDIFDeleteChangeRecord("dc=example,dc=com");
    assertNotNull(t.transformChangeRecord(deleteChangeRecord));
    assertEquals(t.transformChangeRecord(deleteChangeRecord), deleteChangeRecord);
    assertNotNull(t.translate(deleteChangeRecord, 0));
    assertEquals(t.translate(deleteChangeRecord, 0), deleteChangeRecord);
    assertNotNull(t.translateChangeRecordToWrite(deleteChangeRecord));
    assertEquals(t.translateChangeRecordToWrite(deleteChangeRecord), deleteChangeRecord);
    final LDIFModifyChangeRecord modifyChangeRecord = new LDIFModifyChangeRecord(new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: foo"));
    assertNotNull(t.transformChangeRecord(modifyChangeRecord));
    assertEquals(t.transformChangeRecord(modifyChangeRecord), modifyChangeRecord);
    assertNotNull(t.translate(modifyChangeRecord, 0));
    assertEquals(t.translate(modifyChangeRecord, 0), modifyChangeRecord);
    assertNotNull(t.translateChangeRecordToWrite(modifyChangeRecord));
    assertEquals(t.translateChangeRecordToWrite(modifyChangeRecord), modifyChangeRecord);
    final LDIFModifyDNChangeRecord modifyDNChangeRecord = new LDIFModifyDNChangeRecord("ou=People,dc=example,dc=com", "ou=Users", true, null);
    assertNotNull(t.transformChangeRecord(modifyDNChangeRecord));
    assertEquals(t.transformChangeRecord(modifyDNChangeRecord), modifyDNChangeRecord);
    assertNotNull(t.translate(modifyDNChangeRecord, 0));
    assertEquals(t.translate(modifyDNChangeRecord, 0), modifyDNChangeRecord);
    assertNotNull(t.translateChangeRecordToWrite(modifyDNChangeRecord));
    assertEquals(t.translateChangeRecordToWrite(modifyDNChangeRecord), modifyDNChangeRecord);
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) ChangeType(com.unboundid.ldap.sdk.ChangeType) LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 45 with LDIFDeleteChangeRecord

use of com.unboundid.ldif.LDIFDeleteChangeRecord in project ldapsdk by pingidentity.

the class ExcludeAttributeTransformationTestCase method testExcludeForDeleteChangeRecord.

/**
 * Tests the behavior for LDIF delete change records.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExcludeForDeleteChangeRecord() throws Exception {
    final ExcludeAttributeTransformation t = new ExcludeAttributeTransformation(Schema.getDefaultStandardSchema(), "description", "displayName");
    final LDIFChangeRecord r = t.transformChangeRecord(new LDIFDeleteChangeRecord("dc=example,dc=com"));
    assertNotNull(r);
    assertEquals(r, new LDIFDeleteChangeRecord("dc=example,dc=com"));
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) Test(org.testng.annotations.Test)

Aggregations

LDIFDeleteChangeRecord (com.unboundid.ldif.LDIFDeleteChangeRecord)67 Test (org.testng.annotations.Test)58 LDIFAddChangeRecord (com.unboundid.ldif.LDIFAddChangeRecord)29 LDIFChangeRecord (com.unboundid.ldif.LDIFChangeRecord)20 LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)18 LDIFModifyDNChangeRecord (com.unboundid.ldif.LDIFModifyDNChangeRecord)17 Calendar (java.util.Calendar)17 GregorianCalendar (java.util.GregorianCalendar)17 Entry (com.unboundid.ldap.sdk.Entry)10 Attribute (com.unboundid.ldap.sdk.Attribute)9 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)9 ReadOnlyEntry (com.unboundid.ldap.sdk.ReadOnlyEntry)9 DN (com.unboundid.ldap.sdk.DN)7 LDAPException (com.unboundid.ldap.sdk.LDAPException)6 File (java.io.File)5 Schema (com.unboundid.ldap.sdk.schema.Schema)4 Nullable (com.unboundid.util.Nullable)4 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)3 ChangeLogEntry (com.unboundid.ldap.sdk.ChangeLogEntry)3 Modification (com.unboundid.ldap.sdk.Modification)3