Search in sources :

Example 26 with LDIFModifyChangeRecord

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

the class LDAPDiffTestCase method testByteForByte.

/**
 * Tests the behavior for the byteForByte argument.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testByteForByte() throws Exception {
    try (InMemoryDirectoryServer sourceDS = createTestDS(true, true, 1);
        InMemoryDirectoryServer targetDS = createTestDS(true, true, 1)) {
        // Alter the user entry on each server to set description values that are
        // logically equivalent but not byte-for-byte equivalent.
        sourceDS.modify("dn: uid=user.1,ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: logically equivalent");
        targetDS.modify("dn: uid=user.1,ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: Logically    Equivalent");
        // Test the tool without the --byteForByte argument and verify that the
        // servers are considered in sync.
        File outputFile = runTool(sourceDS, targetDS, ResultCode.SUCCESS);
        List<LDIFChangeRecord> changeRecords = readChangeRecords(outputFile);
        assertEquals(changeRecords.size(), 0, String.valueOf(changeRecords));
        // Test with the --byteForByte argument and verify that the different
        // description value is identified.
        outputFile = runTool(sourceDS, targetDS, ResultCode.COMPARE_FALSE, "--byteForByte");
        changeRecords = readChangeRecords(outputFile);
        assertEquals(changeRecords.size(), 1, String.valueOf(changeRecords));
        assertEquals(changeRecords.get(0), new LDIFModifyChangeRecord(new ModifyRequest("dn: uid=user.1,ou=People,dc=example,dc=com", "changetype: modify", "delete: description", "description: logically equivalent", "-", "add: description", "description: Logically    Equivalent")), changeRecords.get(0).toLDIFString());
    }
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) File(java.io.File) Test(org.testng.annotations.Test)

Example 27 with LDIFModifyChangeRecord

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

the class ParallelUpdateTestCase method testRejectedModify.

/**
 * Tests with a rejected modify operation because the entry does not exist.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testRejectedModify() throws Exception {
    final File ldifFile = createTempFile("dn: ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
    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 LDIFModifyChangeRecord);
        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) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) File(java.io.File) Test(org.testng.annotations.Test)

Example 28 with LDIFModifyChangeRecord

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

the class ChangeLogEntryTestCase method testGetNewDN.

/**
 * Provides test coverage for the {@code getNewDN} method with various types
 * of changes.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetNewDN() throws Exception {
    // For add and modify operations, the new DN should always be the same as
    // the target DN.
    ChangeLogEntry e = ChangeLogEntry.constructChangeLogEntry(1L, new LDIFAddChangeRecord(new Entry("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example")));
    assertEquals(new DN(e.getNewDN()), new DN("dc=example,dc=com"));
    e = ChangeLogEntry.constructChangeLogEntry(2L, new LDIFModifyChangeRecord("dc=example,dc=com", new Modification(ModificationType.REPLACE, "description", "foo")));
    assertEquals(new DN(e.getNewDN()), new DN("dc=example,dc=com"));
    // For delete operations, the new DN should always be null.
    e = ChangeLogEntry.constructChangeLogEntry(3L, new LDIFDeleteChangeRecord("dc=example,dc=com"));
    assertNull(e.getNewDN());
    // For modify DN operations, then the new DN will depend on whether or not
    // there's a new superior DN.
    e = ChangeLogEntry.constructChangeLogEntry(4L, new LDIFModifyDNChangeRecord("ou=People,dc=example,dc=com", "ou=Users", true, null));
    assertEquals(new DN(e.getNewDN()), new DN("ou=Users,dc=example,dc=com"));
    e = ChangeLogEntry.constructChangeLogEntry(5L, new LDIFModifyDNChangeRecord("ou=People,dc=example,dc=com", "ou=Users", true, "o=example.com"));
    assertEquals(new DN(e.getNewDN()), new DN("ou=Users,o=example.com"));
    e = ChangeLogEntry.constructChangeLogEntry(6L, new LDIFModifyDNChangeRecord("o=example.com", "o=example.net", true, null));
    assertEquals(new DN(e.getNewDN()), new DN("o=example.net"));
}
Also used : LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 29 with LDIFModifyChangeRecord

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

the class ModifyAuditLogMessageTestCase method testNonRevertibleBecauseOfNoValueDeleteModifyAuditLogMessage.

/**
 * Tests the behavior for a modify audit log message that is not revertible
 * because it includes a delete modification that doesn't have any values.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testNonRevertibleBecauseOfNoValueDeleteModifyAuditLogMessage() throws Exception {
    final ModifyAuditLogMessage m = new ModifyAuditLogMessage(Arrays.asList("# 27/Aug/2018:15:09:11.476 -0500; conn=18; op=1; " + "productName=\"Directory Server\"; " + "instanceName=\"ReplicaOne\"; startupID=W4RZ/w==; threadID=7; " + "clientIP=127.0.0.1; " + "requesterDN=\"cn=Proxy User,cn=Root DNs,cn=config\"; " + "replicationChangeID=\"000001657D01242C7A0D00000004\"; " + "authzDN=\"cn=Directory Manager,cn=Root DNs,cn=config\"; " + "requestControlOIDs=\"1.3.6.1.4.1.30221.2.5.2\"; " + "intermediateClientRequestControl={ " + "\"clientIdentity\":\"dn:cn=Directory Manager,cn=Root " + "DNs,cn=config\", \"downstreamClientAddress\":\"127.0.0.1\", " + "\"downstreamClientSecure\":false, " + "\"clientName\":\"PingDirectory\", " + "\"clientSessionID\":\"conn=8\", \"clientRequestID\":\"op=4\", " + "\"downstreamRequest\":{ " + "\"clientName\":\"Unidentified Directory Application\" } }", "dn: uid=jdoe,ou=People,dc=example,dc=com", "changetype: modify", "delete: displayName", "-", "add: givenName", "givenName: Jonathan", "-", "replace: description", "description: Replaced description", "-", "replace: modifyTimestamp", "modifyTimestamp: 20180827200911.470Z"));
    assertNotNull(m.getLogMessageLines());
    assertFalse(m.getLogMessageLines().isEmpty());
    assertNotNull(m.getCommentedHeaderLine());
    assertTrue(m.getCommentedHeaderLine().startsWith("# 27/Aug/2018:15:09:11.476 -0500; conn=18; op=1; "));
    assertNotNull(m.getUncommentedHeaderLine());
    assertTrue(m.getUncommentedHeaderLine().startsWith("27/Aug/2018:15:09:11.476 -0500; conn=18; op=1; "));
    assertNotNull(m.getTimestamp());
    final Calendar calendar = new GregorianCalendar();
    calendar.setTime(m.getTimestamp());
    assertEquals(calendar.get(Calendar.YEAR), 2018);
    assertEquals(calendar.get(Calendar.MONTH), Calendar.AUGUST);
    assertNotNull(m.getHeaderNamedValues());
    assertFalse(m.getHeaderNamedValues().isEmpty());
    assertTrue(m.getHeaderNamedValues().containsKey("conn"));
    assertNotNull(m.getProductName());
    assertEquals(m.getProductName(), "Directory Server");
    assertNotNull(m.getInstanceName());
    assertEquals(m.getInstanceName(), "ReplicaOne");
    assertNotNull(m.getStartupID());
    assertEquals(m.getStartupID(), "W4RZ/w==");
    assertNotNull(m.getThreadID());
    assertEquals(m.getThreadID().longValue(), 7L);
    assertNotNull(m.getRequesterDN());
    assertDNsEqual(m.getRequesterDN(), "cn=Proxy User,cn=Root DNs,cn=config");
    assertNotNull(m.getRequesterIPAddress());
    assertEquals(m.getRequesterIPAddress(), "127.0.0.1");
    assertNotNull(m.getConnectionID());
    assertEquals(m.getConnectionID().longValue(), 18L);
    assertNotNull(m.getOperationID());
    assertEquals(m.getOperationID().longValue(), 1L);
    assertNull(m.getTriggeredByConnectionID());
    assertNull(m.getTriggeredByOperationID());
    assertNotNull(m.getReplicationChangeID());
    assertEquals(m.getReplicationChangeID(), "000001657D01242C7A0D00000004");
    assertNotNull(m.getAlternateAuthorizationDN());
    assertDNsEqual(m.getAlternateAuthorizationDN(), "cn=Directory Manager,cn=Root DNs,cn=config");
    assertNull(m.getTransactionID());
    assertNull(m.getOrigin());
    assertNull(m.getUsingAdminSessionWorkerThread());
    assertNotNull(m.getRequestControlOIDs());
    assertEquals(m.getRequestControlOIDs(), Collections.singletonList("1.3.6.1.4.1.30221.2.5.2"));
    assertNull(m.getOperationPurposeRequestControl());
    assertNotNull(m.getIntermediateClientRequestControl());
    assertNotNull(m.getDN());
    assertDNsEqual(m.getDN(), "uid=jdoe,ou=People,dc=example,dc=com");
    assertNotNull(m.getModifications());
    assertFalse(m.getModifications().isEmpty());
    assertEquals(m.getModifications(), Arrays.asList(new Modification(ModificationType.DELETE, "displayName"), new Modification(ModificationType.ADD, "givenName", "Jonathan"), new Modification(ModificationType.REPLACE, "description", "Replaced description"), new Modification(ModificationType.REPLACE, "modifyTimestamp", "20180827200911.470Z")));
    assertNull(m.getIsSoftDeletedEntry());
    assertNotNull(m.getChangeType());
    assertEquals(m.getChangeType(), ChangeType.MODIFY);
    assertNotNull(m.getChangeRecord());
    assertTrue(m.getChangeRecord() instanceof LDIFModifyChangeRecord);
    assertFalse(m.isRevertible());
    try {
        m.getRevertChangeRecords();
        fail("Expected an exception when trying to revert a non-revertible " + "modify audit log message");
    } catch (final AuditLogException e) {
    // This was expected.
    }
    assertNotNull(m.toString());
    assertNotNull(m.toMultiLineString());
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) Test(org.testng.annotations.Test)

Example 30 with LDIFModifyChangeRecord

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

the class ModifyAuditLogMessageTestCase method testNonRevertibleMessageWithLinesAndChangeRecord.

/**
 * Tests the behavior for a non-revertible modify audit log message with a
 * minimal set of content.  The message will be created from a list of lines
 * and a change record.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testNonRevertibleMessageWithLinesAndChangeRecord() throws Exception {
    final ModifyAuditLogMessage m = new ModifyAuditLogMessage(Arrays.asList("# 27/Aug/2018:15:09:11.476 -0500; conn=18; op=1", "dn: uid=jdoe,ou=People,dc=example,dc=com", "changetype: modify", "delete: displayName"), new LDIFModifyChangeRecord(new ModifyRequest("dn: uid=jdoe,ou=People,dc=example,dc=com", "changetype: modify", "delete: displayName")));
    assertNotNull(m.getLogMessageLines());
    assertFalse(m.getLogMessageLines().isEmpty());
    assertNotNull(m.getCommentedHeaderLine());
    assertEquals(m.getCommentedHeaderLine(), "# 27/Aug/2018:15:09:11.476 -0500; conn=18; op=1");
    assertNotNull(m.getUncommentedHeaderLine());
    assertEquals(m.getUncommentedHeaderLine(), "27/Aug/2018:15:09:11.476 -0500; conn=18; op=1");
    assertNotNull(m.getTimestamp());
    final Calendar calendar = new GregorianCalendar();
    calendar.setTime(m.getTimestamp());
    assertEquals(calendar.get(Calendar.YEAR), 2018);
    assertEquals(calendar.get(Calendar.MONTH), Calendar.AUGUST);
    assertNotNull(m.getHeaderNamedValues());
    assertFalse(m.getHeaderNamedValues().isEmpty());
    assertTrue(m.getHeaderNamedValues().containsKey("conn"));
    assertNull(m.getProductName());
    assertNull(m.getInstanceName());
    assertNull(m.getStartupID());
    assertNull(m.getThreadID());
    assertNull(m.getRequesterDN());
    assertNull(m.getRequesterIPAddress());
    assertNotNull(m.getConnectionID());
    assertEquals(m.getConnectionID().longValue(), 18L);
    assertNotNull(m.getOperationID());
    assertEquals(m.getOperationID().longValue(), 1L);
    assertNull(m.getTriggeredByConnectionID());
    assertNull(m.getTriggeredByOperationID());
    assertNull(m.getReplicationChangeID());
    assertNull(m.getAlternateAuthorizationDN());
    assertNull(m.getTransactionID());
    assertNull(m.getOrigin());
    assertNull(m.getUsingAdminSessionWorkerThread());
    assertNull(m.getRequestControlOIDs());
    assertNull(m.getOperationPurposeRequestControl());
    assertNull(m.getIntermediateClientRequestControl());
    assertNotNull(m.getDN());
    assertDNsEqual(m.getDN(), "uid=jdoe,ou=People,dc=example,dc=com");
    assertNotNull(m.getModifications());
    assertFalse(m.getModifications().isEmpty());
    assertEquals(m.getModifications(), Collections.singletonList(new Modification(ModificationType.DELETE, "displayName")));
    assertNull(m.getIsSoftDeletedEntry());
    assertNotNull(m.getChangeType());
    assertEquals(m.getChangeType(), ChangeType.MODIFY);
    assertNotNull(m.getChangeRecord());
    assertTrue(m.getChangeRecord() instanceof LDIFModifyChangeRecord);
    assertFalse(m.isRevertible());
    try {
        m.getRevertChangeRecords();
        fail("Expected an exception when trying to revert a non-revertible " + "modify audit log message");
    } catch (final AuditLogException e) {
    // This was expected.
    }
    assertNotNull(m.toString());
    assertNotNull(m.toMultiLineString());
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) Test(org.testng.annotations.Test)

Aggregations

LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)60 Test (org.testng.annotations.Test)40 Modification (com.unboundid.ldap.sdk.Modification)24 LDIFChangeRecord (com.unboundid.ldif.LDIFChangeRecord)23 LDIFModifyDNChangeRecord (com.unboundid.ldif.LDIFModifyDNChangeRecord)20 LDIFAddChangeRecord (com.unboundid.ldif.LDIFAddChangeRecord)19 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)18 LDIFDeleteChangeRecord (com.unboundid.ldif.LDIFDeleteChangeRecord)18 Entry (com.unboundid.ldap.sdk.Entry)17 DN (com.unboundid.ldap.sdk.DN)15 File (java.io.File)11 Attribute (com.unboundid.ldap.sdk.Attribute)9 NotNull (com.unboundid.util.NotNull)9 LDAPException (com.unboundid.ldap.sdk.LDAPException)8 ArrayList (java.util.ArrayList)8 Calendar (java.util.Calendar)8 GregorianCalendar (java.util.GregorianCalendar)8 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)7 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)7 Nullable (com.unboundid.util.Nullable)7