Search in sources :

Example 36 with LDIFModifyDNChangeRecord

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

the class ExcludeChangeTypeTransformationTestCase method testExcludeAddChangeType.

/**
 * Tests the behavior when the set of change types to exclude contains only
 * the add change type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExcludeAddChangeType() throws Exception {
    final ExcludeChangeTypeTransformation t = new ExcludeChangeTypeTransformation(ChangeType.ADD);
    final LDIFAddChangeRecord addChangeRecord = new LDIFAddChangeRecord(new Entry("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example"));
    assertNull(t.transformChangeRecord(addChangeRecord));
    assertNull(t.translate(addChangeRecord, 0));
    assertNull(t.translateChangeRecordToWrite(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) 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 37 with LDIFModifyDNChangeRecord

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

the class ExcludeChangeTypeTransformationTestCase method testExcludeModifyChangeType.

/**
 * Tests the behavior when the set of change types to exclude contains only
 * the modify change type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExcludeModifyChangeType() throws Exception {
    final ExcludeChangeTypeTransformation t = new ExcludeChangeTypeTransformation(ChangeType.MODIFY);
    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"));
    assertNull(t.transformChangeRecord(modifyChangeRecord));
    assertNull(t.translate(modifyChangeRecord, 0));
    assertNull(t.translateChangeRecordToWrite(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) 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 38 with LDIFModifyDNChangeRecord

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

the class RenameAttributeTransformationTestCase method testTransformModifyDNChangeRecordIncludeDNs.

/**
 * Provides test coverage for the transformChangeRecord method for a modify DN
 * change record in which renames should be applied in DNs.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testTransformModifyDNChangeRecordIncludeDNs() throws Exception {
    final Schema schema = Schema.getDefaultStandardSchema();
    final RenameAttributeTransformation t = new RenameAttributeTransformation(schema, "cn", "fullName", true);
    final LDIFChangeRecord r = t.transformChangeRecord(new LDIFModifyDNChangeRecord("cn=A,cn=B,dc=example,dc=com", "cn=C", true, "cn=D,dc=example,dc=com"));
    assertNotNull(r);
    assertEquals(r, new LDIFModifyDNChangeRecord("fullName=A,fullName=B,dc=example,dc=com", "fullName=C", true, "fullName=D,dc=example,dc=com"));
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) Schema(com.unboundid.ldap.sdk.schema.Schema) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) Test(org.testng.annotations.Test)

Example 39 with LDIFModifyDNChangeRecord

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

the class AuditLogReaderTestCase method testBasicAuditLogFile.

/**
 * Tests the behavior when trying to read the basic audit log file.
 *
 * @param  reader  The reader to use for testing.
 * @param  origin  The origin of the provided reader.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "basicAuditLogReaders")
public void testBasicAuditLogFile(final AuditLogReader reader, final String origin) throws Exception {
    AuditLogMessage m = reader.read();
    assertNotNull(m);
    assertTrue(m instanceof AddAuditLogMessage);
    final AddAuditLogMessage addMessage = (AddAuditLogMessage) m;
    assertNotNull(addMessage.getLogMessageLines());
    assertFalse(addMessage.getLogMessageLines().isEmpty());
    assertNotNull(addMessage.getCommentedHeaderLine());
    assertEquals(addMessage.getCommentedHeaderLine(), "# 23/Aug/2018:14:02:40 -0500; conn=28; op=1; " + "authzDN=\"cn=Directory Manager,cn=Root DNs,cn=config\"");
    assertNotNull(addMessage.getUncommentedHeaderLine());
    assertEquals(addMessage.getUncommentedHeaderLine(), "23/Aug/2018:14:02:40 -0500; conn=28; op=1; " + "authzDN=\"cn=Directory Manager,cn=Root DNs,cn=config\"");
    assertNotNull(addMessage.getTimestamp());
    final Calendar calendar = new GregorianCalendar();
    calendar.setTime(addMessage.getTimestamp());
    assertEquals(calendar.get(Calendar.YEAR), 2018);
    assertEquals(calendar.get(Calendar.MONTH), Calendar.AUGUST);
    assertNotNull(addMessage.getHeaderNamedValues());
    assertFalse(addMessage.getHeaderNamedValues().isEmpty());
    assertTrue(addMessage.getHeaderNamedValues().containsKey("conn"));
    assertNull(addMessage.getProductName());
    assertNull(addMessage.getInstanceName());
    assertNull(addMessage.getStartupID());
    assertNull(addMessage.getThreadID());
    assertNull(addMessage.getRequesterDN());
    assertNull(addMessage.getRequesterIPAddress());
    assertNotNull(addMessage.getConnectionID());
    assertEquals(addMessage.getConnectionID().longValue(), 28L);
    assertNotNull(addMessage.getOperationID());
    assertEquals(addMessage.getOperationID().longValue(), 1L);
    assertNull(addMessage.getTriggeredByConnectionID());
    assertNull(addMessage.getTriggeredByOperationID());
    assertNull(addMessage.getReplicationChangeID());
    assertNotNull(addMessage.getAlternateAuthorizationDN());
    assertDNsEqual(addMessage.getAlternateAuthorizationDN(), "cn=Directory Manager,cn=Root DNs,cn=config");
    assertNull(addMessage.getTransactionID());
    assertNull(addMessage.getOrigin());
    assertNull(addMessage.getUsingAdminSessionWorkerThread());
    assertNull(addMessage.getRequestControlOIDs());
    assertNull(addMessage.getOperationPurposeRequestControl());
    assertNull(addMessage.getIntermediateClientRequestControl());
    assertNotNull(addMessage.getDN());
    assertDNsEqual(addMessage.getDN(), "ou=People,dc=example,dc=com");
    assertNotNull(addMessage.getEntry());
    assertNull(addMessage.getIsUndelete());
    assertNotNull(addMessage.getChangeType());
    assertEquals(addMessage.getChangeType(), ChangeType.ADD);
    assertNotNull(addMessage.getChangeRecord());
    assertTrue(addMessage.getChangeRecord() instanceof LDIFAddChangeRecord);
    assertTrue(addMessage.isRevertible());
    assertNotNull(addMessage.getRevertChangeRecords());
    assertFalse(addMessage.getRevertChangeRecords().isEmpty());
    assertEquals(addMessage.getRevertChangeRecords().size(), 1);
    assertTrue(addMessage.getRevertChangeRecords().get(0) instanceof LDIFDeleteChangeRecord);
    final LDIFDeleteChangeRecord revertDeleteChangeRecord = (LDIFDeleteChangeRecord) addMessage.getRevertChangeRecords().get(0);
    assertDNsEqual(revertDeleteChangeRecord.getDN(), "ou=People,dc=example,dc=com");
    assertNotNull(revertDeleteChangeRecord.getControls());
    assertTrue(revertDeleteChangeRecord.getControls().isEmpty());
    assertNotNull(addMessage.toString());
    assertNotNull(addMessage.toMultiLineString());
    m = reader.read();
    assertNotNull(m);
    assertTrue(m instanceof DeleteAuditLogMessage);
    final DeleteAuditLogMessage deleteMessage = (DeleteAuditLogMessage) m;
    assertNotNull(deleteMessage.getLogMessageLines());
    assertFalse(deleteMessage.getLogMessageLines().isEmpty());
    assertNotNull(deleteMessage.getCommentedHeaderLine());
    assertEquals(deleteMessage.getCommentedHeaderLine(), "# 24/Aug/2018:12:11:50 -0500; conn=33; op=1; " + "authzDN=\"cn=Directory Manager,cn=Root DNs,cn=config\"");
    assertNotNull(deleteMessage.getUncommentedHeaderLine());
    assertEquals(deleteMessage.getUncommentedHeaderLine(), "24/Aug/2018:12:11:50 -0500; conn=33; op=1; " + "authzDN=\"cn=Directory Manager,cn=Root DNs,cn=config\"");
    assertNotNull(deleteMessage.getTimestamp());
    calendar.setTime(deleteMessage.getTimestamp());
    assertEquals(calendar.get(Calendar.YEAR), 2018);
    assertEquals(calendar.get(Calendar.MONTH), Calendar.AUGUST);
    assertNotNull(deleteMessage.getHeaderNamedValues());
    assertFalse(deleteMessage.getHeaderNamedValues().isEmpty());
    assertTrue(deleteMessage.getHeaderNamedValues().containsKey("conn"));
    assertNull(deleteMessage.getProductName());
    assertNull(deleteMessage.getInstanceName());
    assertNull(deleteMessage.getStartupID());
    assertNull(deleteMessage.getThreadID());
    assertNull(deleteMessage.getRequesterDN());
    assertNull(deleteMessage.getRequesterIPAddress());
    assertNotNull(deleteMessage.getConnectionID());
    assertEquals(deleteMessage.getConnectionID().longValue(), 33L);
    assertNotNull(deleteMessage.getOperationID());
    assertEquals(deleteMessage.getOperationID().longValue(), 1L);
    assertNull(deleteMessage.getTriggeredByConnectionID());
    assertNull(deleteMessage.getTriggeredByOperationID());
    assertNull(deleteMessage.getReplicationChangeID());
    assertNotNull(deleteMessage.getAlternateAuthorizationDN());
    assertDNsEqual(deleteMessage.getAlternateAuthorizationDN(), "cn=Directory Manager,cn=Root DNs,cn=config");
    assertNull(deleteMessage.getTransactionID());
    assertNull(deleteMessage.getOrigin());
    assertNull(deleteMessage.getUsingAdminSessionWorkerThread());
    assertNull(deleteMessage.getRequestControlOIDs());
    assertNull(deleteMessage.getOperationPurposeRequestControl());
    assertNull(deleteMessage.getIntermediateClientRequestControl());
    assertNotNull(deleteMessage.getDN());
    assertDNsEqual(deleteMessage.getDN(), "ou=People,dc=example,dc=com");
    assertNull(deleteMessage.getIsSubtreeDelete());
    assertNull(deleteMessage.getDeletedAsPartOfSubtreeDelete());
    assertNull(deleteMessage.getIsSoftDelete());
    assertNull(deleteMessage.getSoftDeletedEntryDN());
    assertNull(deleteMessage.getIsSoftDeletedEntry());
    assertNull(deleteMessage.getDeletedEntry());
    assertNull(deleteMessage.getDeletedEntryVirtualAttributes());
    assertNotNull(deleteMessage.getChangeType());
    assertEquals(deleteMessage.getChangeType(), ChangeType.DELETE);
    assertNotNull(deleteMessage.getChangeRecord());
    assertTrue(deleteMessage.getChangeRecord() instanceof LDIFDeleteChangeRecord);
    assertFalse(deleteMessage.isRevertible());
    try {
        deleteMessage.getRevertChangeRecords();
        fail("Expected an exception when trying to revert a non-revertible " + "delete audit log message");
    } catch (final AuditLogException e) {
    // This was expected.
    }
    assertNotNull(deleteMessage.toString());
    assertNotNull(deleteMessage.toMultiLineString());
    m = reader.read();
    assertNotNull(m);
    assertTrue(m instanceof ModifyAuditLogMessage);
    final ModifyAuditLogMessage modifyMessage = (ModifyAuditLogMessage) m;
    assertNotNull(modifyMessage.getLogMessageLines());
    assertFalse(modifyMessage.getLogMessageLines().isEmpty());
    assertNotNull(modifyMessage.getCommentedHeaderLine());
    assertTrue(modifyMessage.getCommentedHeaderLine().startsWith("# 27/Aug/2018:15:09:11.476 -0500; conn=18; op=1; "));
    assertNotNull(modifyMessage.getUncommentedHeaderLine());
    assertTrue(modifyMessage.getUncommentedHeaderLine().startsWith("27/Aug/2018:15:09:11.476 -0500; conn=18; op=1; "));
    assertNotNull(modifyMessage.getTimestamp());
    calendar.setTime(modifyMessage.getTimestamp());
    assertEquals(calendar.get(Calendar.YEAR), 2018);
    assertEquals(calendar.get(Calendar.MONTH), Calendar.AUGUST);
    assertNotNull(modifyMessage.getHeaderNamedValues());
    assertFalse(modifyMessage.getHeaderNamedValues().isEmpty());
    assertTrue(modifyMessage.getHeaderNamedValues().containsKey("conn"));
    assertNotNull(modifyMessage.getProductName());
    assertEquals(modifyMessage.getProductName(), "Directory Server");
    assertNotNull(modifyMessage.getInstanceName());
    assertEquals(modifyMessage.getInstanceName(), "ReplicaOne");
    assertNotNull(modifyMessage.getStartupID());
    assertEquals(modifyMessage.getStartupID(), "W4RZ/w==");
    assertNotNull(modifyMessage.getThreadID());
    assertEquals(modifyMessage.getThreadID().longValue(), 7L);
    assertNotNull(modifyMessage.getRequesterDN());
    assertDNsEqual(modifyMessage.getRequesterDN(), "cn=Proxy User,cn=Root DNs,cn=config");
    assertNotNull(modifyMessage.getRequesterIPAddress());
    assertEquals(modifyMessage.getRequesterIPAddress(), "127.0.0.1");
    assertNotNull(modifyMessage.getConnectionID());
    assertEquals(modifyMessage.getConnectionID().longValue(), 18L);
    assertNotNull(modifyMessage.getOperationID());
    assertEquals(modifyMessage.getOperationID().longValue(), 1L);
    assertNull(modifyMessage.getTriggeredByConnectionID());
    assertNull(modifyMessage.getTriggeredByOperationID());
    assertNotNull(modifyMessage.getReplicationChangeID());
    assertEquals(modifyMessage.getReplicationChangeID(), "000001657D01242C7A0D00000004");
    assertNotNull(modifyMessage.getAlternateAuthorizationDN());
    assertDNsEqual(modifyMessage.getAlternateAuthorizationDN(), "cn=Directory Manager,cn=Root DNs,cn=config");
    assertNull(modifyMessage.getTransactionID());
    assertNull(modifyMessage.getOrigin());
    assertNull(modifyMessage.getUsingAdminSessionWorkerThread());
    assertNotNull(modifyMessage.getRequestControlOIDs());
    assertEquals(modifyMessage.getRequestControlOIDs(), Collections.singletonList("1.3.6.1.4.1.30221.2.5.2"));
    assertNull(modifyMessage.getOperationPurposeRequestControl());
    assertNotNull(modifyMessage.getIntermediateClientRequestControl());
    assertNotNull(modifyMessage.getDN());
    assertDNsEqual(modifyMessage.getDN(), "uid=jdoe,ou=People,dc=example,dc=com");
    assertNotNull(modifyMessage.getModifications());
    assertFalse(modifyMessage.getModifications().isEmpty());
    assertEquals(modifyMessage.getModifications(), Arrays.asList(new Modification(ModificationType.DELETE, "displayName", "Johnny Doe"), new Modification(ModificationType.ADD, "givenName", "Jonathan"), new Modification(ModificationType.DELETE, "description", "Initial description"), new Modification(ModificationType.ADD, "description", "Replaced description"), new Modification(ModificationType.INCREMENT, "intAttr1", "123"), new Modification(ModificationType.INCREMENT, "intAttr2", "-456"), new Modification(ModificationType.DELETE, "modifyTimestamp", "20180827200911.455Z"), new Modification(ModificationType.ADD, "modifyTimestamp", "20180827200911.470Z")));
    assertNull(modifyMessage.getIsSoftDeletedEntry());
    assertNotNull(modifyMessage.getChangeType());
    assertEquals(modifyMessage.getChangeType(), ChangeType.MODIFY);
    assertNotNull(modifyMessage.getChangeRecord());
    assertTrue(modifyMessage.getChangeRecord() instanceof LDIFModifyChangeRecord);
    assertTrue(modifyMessage.isRevertible());
    List<LDIFChangeRecord> revertChangeRecords = modifyMessage.getRevertChangeRecords();
    assertNotNull(revertChangeRecords);
    assertFalse(revertChangeRecords.isEmpty());
    assertEquals(revertChangeRecords.size(), 1);
    assertTrue(revertChangeRecords.get(0) instanceof LDIFModifyChangeRecord);
    final LDIFModifyChangeRecord revertModifyChangeRecord = (LDIFModifyChangeRecord) revertChangeRecords.get(0);
    assertEquals(revertModifyChangeRecord.getModifications(), new Modification[] { new Modification(ModificationType.DELETE, "modifyTimestamp", "20180827200911.470Z"), new Modification(ModificationType.ADD, "modifyTimestamp", "20180827200911.455Z"), new Modification(ModificationType.INCREMENT, "intAttr2", "456"), new Modification(ModificationType.INCREMENT, "intAttr1", "-123"), new Modification(ModificationType.DELETE, "description", "Replaced description"), new Modification(ModificationType.ADD, "description", "Initial description"), new Modification(ModificationType.DELETE, "givenName", "Jonathan"), new Modification(ModificationType.ADD, "displayName", "Johnny Doe") });
    assertNotNull(modifyMessage.toString());
    assertNotNull(modifyMessage.toMultiLineString());
    m = reader.read();
    assertNotNull(m);
    assertTrue(m instanceof ModifyDNAuditLogMessage);
    final ModifyDNAuditLogMessage modifyDNMessage = (ModifyDNAuditLogMessage) m;
    assertNotNull(modifyDNMessage.getLogMessageLines());
    assertFalse(modifyDNMessage.getLogMessageLines().isEmpty());
    assertNotNull(modifyDNMessage.getCommentedHeaderLine());
    assertTrue(modifyDNMessage.getCommentedHeaderLine().startsWith("# 27/Aug/2018:16:33:47.019 -0500; conn=31; op=1; "));
    assertNotNull(modifyDNMessage.getUncommentedHeaderLine());
    assertTrue(modifyDNMessage.getUncommentedHeaderLine().startsWith("27/Aug/2018:16:33:47.019 -0500; conn=31; op=1; "));
    assertNotNull(modifyDNMessage.getTimestamp());
    calendar.setTime(modifyDNMessage.getTimestamp());
    assertEquals(calendar.get(Calendar.YEAR), 2018);
    assertEquals(calendar.get(Calendar.MONTH), Calendar.AUGUST);
    assertNotNull(modifyDNMessage.getHeaderNamedValues());
    assertFalse(modifyDNMessage.getHeaderNamedValues().isEmpty());
    assertTrue(modifyDNMessage.getHeaderNamedValues().containsKey("conn"));
    assertNotNull(modifyDNMessage.getProductName());
    assertEquals(modifyDNMessage.getProductName(), "Directory Server");
    assertNotNull(modifyDNMessage.getInstanceName());
    assertEquals(modifyDNMessage.getInstanceName(), "ReplicaOne");
    assertNotNull(modifyDNMessage.getStartupID());
    assertEquals(modifyDNMessage.getStartupID(), "W4Rt1g==");
    assertNotNull(modifyDNMessage.getThreadID());
    assertEquals(modifyDNMessage.getThreadID().longValue(), 8L);
    assertNotNull(modifyDNMessage.getRequesterDN());
    assertDNsEqual(modifyDNMessage.getRequesterDN(), "cn=Proxy User,cn=Root DNs,cn=config");
    assertNotNull(modifyDNMessage.getRequesterIPAddress());
    assertEquals(modifyDNMessage.getRequesterIPAddress(), "127.0.0.1");
    assertNotNull(modifyDNMessage.getConnectionID());
    assertEquals(modifyDNMessage.getConnectionID().longValue(), 31L);
    assertNotNull(modifyDNMessage.getOperationID());
    assertEquals(modifyDNMessage.getOperationID().longValue(), 1L);
    assertNull(modifyDNMessage.getTriggeredByConnectionID());
    assertNull(modifyDNMessage.getTriggeredByOperationID());
    assertNotNull(modifyDNMessage.getReplicationChangeID());
    assertEquals(modifyDNMessage.getReplicationChangeID(), "000001657D4E9677214B00000005");
    assertNotNull(modifyDNMessage.getAlternateAuthorizationDN());
    assertDNsEqual(modifyDNMessage.getAlternateAuthorizationDN(), "cn=Directory Manager,cn=Root DNs,cn=config");
    assertNull(modifyDNMessage.getTransactionID());
    assertNull(modifyDNMessage.getOrigin());
    assertNull(modifyDNMessage.getUsingAdminSessionWorkerThread());
    assertNotNull(modifyDNMessage.getRequestControlOIDs());
    assertEquals(modifyDNMessage.getRequestControlOIDs(), Collections.singletonList("1.3.6.1.4.1.30221.2.5.2"));
    assertNull(modifyDNMessage.getOperationPurposeRequestControl());
    assertNotNull(modifyDNMessage.getIntermediateClientRequestControl());
    assertNotNull(modifyDNMessage.getDN());
    assertDNsEqual(modifyDNMessage.getDN(), "uid=jdoe,ou=People,dc=example,dc=com");
    assertNotNull(modifyDNMessage.getNewRDN());
    assertDNsEqual(modifyDNMessage.getNewRDN(), "uid=john.doe");
    assertTrue(modifyDNMessage.deleteOldRDN());
    assertNull(modifyDNMessage.getNewSuperiorDN());
    assertNotNull(modifyDNMessage.getAttributeModifications());
    assertEquals(modifyDNMessage.getAttributeModifications(), Arrays.asList(new Modification(ModificationType.DELETE, "uid", "jdoe"), new Modification(ModificationType.ADD, "uid", "john.doe")));
    assertNotNull(modifyDNMessage.getChangeType());
    assertEquals(modifyDNMessage.getChangeType(), ChangeType.MODIFY_DN);
    assertNotNull(modifyDNMessage.getChangeRecord());
    assertTrue(modifyDNMessage.getChangeRecord() instanceof LDIFModifyDNChangeRecord);
    assertTrue(modifyDNMessage.isRevertible());
    revertChangeRecords = modifyDNMessage.getRevertChangeRecords();
    assertNotNull(revertChangeRecords);
    assertFalse(revertChangeRecords.isEmpty());
    assertEquals(revertChangeRecords.size(), 1);
    assertTrue(revertChangeRecords.get(0) instanceof LDIFModifyDNChangeRecord);
    final LDIFModifyDNChangeRecord revertModifyDNChangeRecord = (LDIFModifyDNChangeRecord) revertChangeRecords.get(0);
    assertDNsEqual(revertModifyDNChangeRecord.getDN(), "uid=john.doe,ou=People,dc=example,dc=com");
    assertDNsEqual(revertModifyDNChangeRecord.getNewRDN(), "uid=jdoe");
    assertTrue(revertModifyDNChangeRecord.deleteOldRDN());
    assertNull(revertModifyDNChangeRecord.getNewSuperiorDN());
    assertNotNull(modifyDNMessage.toString());
    assertNotNull(modifyDNMessage.toMultiLineString());
    try {
        m = reader.read();
        fail("Expected an exception when trying to read message " + m);
    } catch (final AuditLogException e) {
    // This was expected.
    }
    assertNull(reader.read());
    reader.close();
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord) LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) Test(org.testng.annotations.Test)

Example 40 with LDIFModifyDNChangeRecord

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

the class InMemoryRequestHandler method applyChangesFromLDIF.

/**
 * Reads entries from the provided LDIF reader and adds them to the server,
 * optionally clearing any existing entries before beginning to add the new
 * entries.  If an error is encountered while adding entries from LDIF then
 * the server will remain populated with the data it held before the import
 * attempt (even if the {@code clear} is given with a value of {@code true}).
 * <BR><BR>
 * This method may be used regardless of whether the server is listening for
 * client connections.
 *
 * @param  ldifReader  The LDIF reader to use to obtain the change records to
 *                     be applied.
 *
 * @return  The number of changes applied from the LDIF file.
 *
 * @throws  LDAPException  If a problem occurs while reading change records
 *                         or applying them to the server.
 */
public int applyChangesFromLDIF(@NotNull final LDIFReader ldifReader) throws LDAPException {
    synchronized (entryMap) {
        final InMemoryDirectoryServerSnapshot snapshot = createSnapshot();
        boolean restoreSnapshot = true;
        try {
            int changesApplied = 0;
            while (true) {
                final LDIFChangeRecord changeRecord;
                try {
                    changeRecord = ldifReader.readChangeRecord(true);
                    if (changeRecord == null) {
                        restoreSnapshot = false;
                        return changesApplied;
                    }
                } catch (final LDIFException le) {
                    Debug.debugException(le);
                    throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_MEM_HANDLER_APPLY_CHANGES_FROM_LDIF_READ_ERROR.get(le.getMessage()), le);
                } catch (final Exception e) {
                    Debug.debugException(e);
                    throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_MEM_HANDLER_APPLY_CHANGES_FROM_LDIF_READ_ERROR.get(StaticUtils.getExceptionMessage(e)), e);
                }
                if (changeRecord instanceof LDIFAddChangeRecord) {
                    final LDIFAddChangeRecord addChangeRecord = (LDIFAddChangeRecord) changeRecord;
                    add(addChangeRecord.toAddRequest());
                } else if (changeRecord instanceof LDIFDeleteChangeRecord) {
                    final LDIFDeleteChangeRecord deleteChangeRecord = (LDIFDeleteChangeRecord) changeRecord;
                    delete(deleteChangeRecord.toDeleteRequest());
                } else if (changeRecord instanceof LDIFModifyChangeRecord) {
                    final LDIFModifyChangeRecord modifyChangeRecord = (LDIFModifyChangeRecord) changeRecord;
                    modify(modifyChangeRecord.toModifyRequest());
                } else if (changeRecord instanceof LDIFModifyDNChangeRecord) {
                    final LDIFModifyDNChangeRecord modifyDNChangeRecord = (LDIFModifyDNChangeRecord) changeRecord;
                    modifyDN(modifyDNChangeRecord.toModifyDNRequest());
                } else {
                    throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_MEM_HANDLER_APPLY_CHANGES_UNSUPPORTED_CHANGE.get(String.valueOf(changeRecord)));
                }
                changesApplied++;
            }
        } finally {
            try {
                ldifReader.close();
            } catch (final Exception e) {
                Debug.debugException(e);
            }
            if (restoreSnapshot) {
                restoreSnapshot(snapshot);
            }
        }
    }
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) LDIFException(com.unboundid.ldif.LDIFException) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) LDIFDeleteChangeRecord(com.unboundid.ldif.LDIFDeleteChangeRecord) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDIFException(com.unboundid.ldif.LDIFException) LDIFModifyDNChangeRecord(com.unboundid.ldif.LDIFModifyDNChangeRecord)

Aggregations

LDIFModifyDNChangeRecord (com.unboundid.ldif.LDIFModifyDNChangeRecord)45 Test (org.testng.annotations.Test)35 LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)20 LDIFChangeRecord (com.unboundid.ldif.LDIFChangeRecord)19 LDIFAddChangeRecord (com.unboundid.ldif.LDIFAddChangeRecord)17 LDIFDeleteChangeRecord (com.unboundid.ldif.LDIFDeleteChangeRecord)17 Calendar (java.util.Calendar)13 GregorianCalendar (java.util.GregorianCalendar)13 Entry (com.unboundid.ldap.sdk.Entry)10 Modification (com.unboundid.ldap.sdk.Modification)8 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)8 DN (com.unboundid.ldap.sdk.DN)7 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 Schema (com.unboundid.ldap.sdk.schema.Schema)5 LDIFReader (com.unboundid.ldif.LDIFReader)4 Nullable (com.unboundid.util.Nullable)4 File (java.io.File)4 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)3 Attribute (com.unboundid.ldap.sdk.Attribute)3 RDN (com.unboundid.ldap.sdk.RDN)3