Search in sources :

Example 26 with ModifyDNRequest

use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.

the class LDIFModifyDNChangeRecordTestCase method testConstructor2WithoutNewSuperior.

/**
 * Tests the second constructor without a newSuperior DN.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructor2WithoutNewSuperior() throws Exception {
    ModifyDNRequest modifyDNRequest = new ModifyDNRequest("ou=People,dc=example,dc=com", "ou=Users", true);
    LDIFModifyDNChangeRecord r = new LDIFModifyDNChangeRecord(modifyDNRequest);
    assertNotNull(r.getDN());
    assertEquals(r.getDN(), "ou=People,dc=example,dc=com");
    assertEquals(r.getParsedDN(), new DN("ou=People,dc=example,dc=com"));
    assertNotNull(r.getNewRDN());
    assertEquals(r.getNewRDN(), "ou=Users");
    assertEquals(r.getParsedNewRDN(), new RDN("ou=Users"));
    assertTrue(r.deleteOldRDN());
    assertNull(r.getNewSuperiorDN());
    assertNull(r.getParsedNewSuperiorDN());
    assertEquals(r.getNewDN(), new DN("ou=Users,dc=example,dc=com"));
    modifyDNRequest = r.toModifyDNRequest();
    assertEquals(modifyDNRequest.getDN(), "ou=People,dc=example,dc=com");
    String[] ldifLines = r.toLDIF();
    assertNotNull(ldifLines);
    assertEquals(ldifLines.length, 4);
    assertEquals(r.getChangeType(), ChangeType.MODIFY_DN);
    r.hashCode();
    ByteStringBuffer byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer);
    assertNotNull(byteBuffer.toString());
    byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer, 10);
    assertNotNull(byteBuffer.toString());
    StringBuilder stringBuffer = new StringBuilder();
    r.toLDIFString(stringBuffer);
    assertNotNull(r.toString());
    stringBuffer = new StringBuilder();
    r.toLDIFString(stringBuffer, 10);
    assertNotNull(r.toString());
    assertNotNull(r.toLDIFString());
    assertNotNull(r.toLDIFString(10));
    assertNotNull(r.toString());
}
Also used : ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) RDN(com.unboundid.ldap.sdk.RDN) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) Test(org.testng.annotations.Test)

Example 27 with ModifyDNRequest

use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.

the class LDIFModifyDNChangeRecordTestCase method testConstructor1WithoutNewSuperior.

/**
 * Tests the first constructor with a {@code null} newSuperior DN.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructor1WithoutNewSuperior() throws Exception {
    LDIFModifyDNChangeRecord r = new LDIFModifyDNChangeRecord("ou=People,dc=example,dc=com", "ou=Users", false, null);
    assertNotNull(r.getDN());
    assertEquals(r.getDN(), "ou=People,dc=example,dc=com");
    assertEquals(r.getParsedDN(), new DN("ou=People,dc=example,dc=com"));
    assertNotNull(r.getNewRDN());
    assertEquals(r.getNewRDN(), "ou=Users");
    assertEquals(r.getParsedNewRDN(), new RDN("ou=Users"));
    assertFalse(r.deleteOldRDN());
    assertNull(r.getNewSuperiorDN());
    assertNull(r.getParsedNewSuperiorDN());
    assertEquals(r.getNewDN(), new DN("ou=Users,dc=example,dc=com"));
    ModifyDNRequest modifyDNRequest = r.toModifyDNRequest();
    assertEquals(modifyDNRequest.getDN(), "ou=People,dc=example,dc=com");
    String[] ldifLines = r.toLDIF();
    assertNotNull(ldifLines);
    assertEquals(ldifLines.length, 4);
    assertEquals(r.getChangeType(), ChangeType.MODIFY_DN);
    r.hashCode();
    ByteStringBuffer byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer);
    assertNotNull(byteBuffer.toString());
    byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer, 10);
    assertNotNull(byteBuffer.toString());
    StringBuilder stringBuffer = new StringBuilder();
    r.toLDIFString(stringBuffer);
    assertNotNull(r.toString());
    stringBuffer = new StringBuilder();
    r.toLDIFString(stringBuffer, 10);
    assertNotNull(r.toString());
    assertNotNull(r.toLDIFString());
    assertNotNull(r.toLDIFString(10));
    assertNotNull(r.toString());
}
Also used : ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) RDN(com.unboundid.ldap.sdk.RDN) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) Test(org.testng.annotations.Test)

Example 28 with ModifyDNRequest

use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.

the class LDIFModifyDNChangeRecordTestCase method testConstructor2WithNewSuperior.

/**
 * Tests the second constructor with a newSuperior DN.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructor2WithNewSuperior() throws Exception {
    ModifyDNRequest modifyDNRequest = new ModifyDNRequest("ou=People,dc=example,dc=com", "ou=Users", false, "o=example.com");
    LDIFModifyDNChangeRecord r = new LDIFModifyDNChangeRecord(modifyDNRequest);
    assertNotNull(r.getDN());
    assertEquals(r.getDN(), "ou=People,dc=example,dc=com");
    assertEquals(r.getParsedDN(), new DN("ou=People,dc=example,dc=com"));
    assertNotNull(r.getNewRDN());
    assertEquals(r.getNewRDN(), "ou=Users");
    assertEquals(r.getParsedNewRDN(), new RDN("ou=Users"));
    assertFalse(r.deleteOldRDN());
    assertNotNull(r.getNewSuperiorDN());
    assertEquals(r.getNewSuperiorDN(), "o=example.com");
    assertEquals(r.getParsedNewSuperiorDN(), new DN("o=example.com"));
    assertEquals(r.getNewDN(), new DN("ou=Users,o=example.com"));
    modifyDNRequest = r.toModifyDNRequest();
    assertEquals(modifyDNRequest.getDN(), "ou=People,dc=example,dc=com");
    String[] ldifLines = r.toLDIF();
    assertNotNull(ldifLines);
    assertEquals(ldifLines.length, 5);
    assertEquals(r.getChangeType(), ChangeType.MODIFY_DN);
    r.hashCode();
    ByteStringBuffer byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer);
    assertNotNull(byteBuffer.toString());
    byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer, 10);
    assertNotNull(byteBuffer.toString());
    StringBuilder stringBuffer = new StringBuilder();
    r.toLDIFString(stringBuffer);
    assertNotNull(r.toString());
    stringBuffer = new StringBuilder();
    r.toLDIFString(stringBuffer, 10);
    assertNotNull(r.toString());
    assertNotNull(r.toLDIFString());
    assertNotNull(r.toLDIFString(10));
    assertNotNull(r.toString());
}
Also used : ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) RDN(com.unboundid.ldap.sdk.RDN) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) Test(org.testng.annotations.Test)

Example 29 with ModifyDNRequest

use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.

the class LDIFControlsTestCase method testModifyDNChangeRecordAsModRDN.

/**
 * Tests control behavior for an LDIF modify DN change record using a
 * changetype of modrdn.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyDNChangeRecordAsModRDN() throws Exception {
    // Decode the modify DN change record from raw strings.
    LDIFChangeRecord r = LDIFReader.decodeChangeRecord(generateChangeRecordLines("ou=People,dc=example,dc=com", "modrdn", "newrdn: ou=Users", "deleteoldrdn: 1", "newsuperior: o=example.com"));
    assertTrue(r instanceof LDIFModifyDNChangeRecord);
    assertNotNull(r.toString());
    LDIFModifyDNChangeRecord modifyDNRecord = (LDIFModifyDNChangeRecord) r;
    assertEquals(modifyDNRecord.getControls(), controls);
    assertDNsEqual(modifyDNRecord.getDN(), "ou=People,dc=example,dc=com");
    assertEquals(new RDN(modifyDNRecord.getNewRDN()), new RDN("ou=Users"));
    assertTrue(modifyDNRecord.deleteOldRDN());
    assertDNsEqual(modifyDNRecord.getNewSuperiorDN(), "o=example.com");
    // Generate an LDIF representation from the modify DN change record and
    // ensure it decodes to the same thing.
    r = LDIFReader.decodeChangeRecord(modifyDNRecord.toLDIF());
    assertTrue(r instanceof LDIFModifyDNChangeRecord);
    assertNotNull(r.toString());
    modifyDNRecord = (LDIFModifyDNChangeRecord) r;
    assertEquals(modifyDNRecord.getControls(), controls);
    assertDNsEqual(modifyDNRecord.getDN(), "ou=People,dc=example,dc=com");
    assertEquals(new RDN(modifyDNRecord.getNewRDN()), new RDN("ou=Users"));
    assertTrue(modifyDNRecord.deleteOldRDN());
    assertDNsEqual(modifyDNRecord.getNewSuperiorDN(), "o=example.com");
    // Write the LDIF representation to a file, read it back, and ensure it
    // decodes to the same thing.
    final File ldifFile = createTempFile();
    assertTrue(ldifFile.delete());
    final LDIFWriter writer = new LDIFWriter(ldifFile);
    writer.writeChangeRecord(modifyDNRecord);
    writer.close();
    final LDIFReader reader = new LDIFReader(ldifFile);
    r = reader.readChangeRecord();
    assertNull(reader.readLDIFRecord());
    assertTrue(r instanceof LDIFModifyDNChangeRecord);
    assertNotNull(r.toString());
    modifyDNRecord = (LDIFModifyDNChangeRecord) r;
    assertEquals(modifyDNRecord.getControls(), controls);
    assertDNsEqual(modifyDNRecord.getDN(), "ou=People,dc=example,dc=com");
    assertEquals(new RDN(modifyDNRecord.getNewRDN()), new RDN("ou=Users"));
    assertTrue(modifyDNRecord.deleteOldRDN());
    assertDNsEqual(modifyDNRecord.getNewSuperiorDN(), "o=example.com");
    final ModifyDNRequest modifyDNRequest = modifyDNRecord.toModifyDNRequest();
    assertEquals(modifyDNRequest.getControlList(), controls);
    assertDNsEqual(modifyDNRequest.getDN(), "ou=People,dc=example,dc=com");
    assertEquals(new RDN(modifyDNRequest.getNewRDN()), new RDN("ou=Users"));
    assertTrue(modifyDNRequest.deleteOldRDN());
    assertDNsEqual(modifyDNRequest.getNewSuperiorDN(), "o=example.com");
}
Also used : ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) RDN(com.unboundid.ldap.sdk.RDN) File(java.io.File) Test(org.testng.annotations.Test)

Example 30 with ModifyDNRequest

use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.

the class LDIFControlsTestCase method testModifyDNChangeRecordAsModDN.

/**
 * Tests control behavior for an LDIF modify DN change record using a
 * changetype of moddn.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyDNChangeRecordAsModDN() throws Exception {
    // Decode the modify DN change record from raw strings.
    LDIFChangeRecord r = LDIFReader.decodeChangeRecord(generateChangeRecordLines("ou=People,dc=example,dc=com", "moddn", "newrdn: ou=Users", "deleteoldrdn: 1"));
    assertTrue(r instanceof LDIFModifyDNChangeRecord);
    assertNotNull(r.toString());
    LDIFModifyDNChangeRecord modifyDNRecord = (LDIFModifyDNChangeRecord) r;
    assertEquals(modifyDNRecord.getControls(), controls);
    assertDNsEqual(modifyDNRecord.getDN(), "ou=People,dc=example,dc=com");
    assertEquals(new RDN(modifyDNRecord.getNewRDN()), new RDN("ou=Users"));
    assertTrue(modifyDNRecord.deleteOldRDN());
    assertNull(modifyDNRecord.getNewSuperiorDN());
    // Generate an LDIF representation from the modify DN change record and
    // ensure it decodes to the same thing.
    r = LDIFReader.decodeChangeRecord(modifyDNRecord.toLDIF());
    assertTrue(r instanceof LDIFModifyDNChangeRecord);
    assertNotNull(r.toString());
    modifyDNRecord = (LDIFModifyDNChangeRecord) r;
    assertEquals(modifyDNRecord.getControls(), controls);
    assertDNsEqual(modifyDNRecord.getDN(), "ou=People,dc=example,dc=com");
    assertEquals(new RDN(modifyDNRecord.getNewRDN()), new RDN("ou=Users"));
    assertTrue(modifyDNRecord.deleteOldRDN());
    assertNull(modifyDNRecord.getNewSuperiorDN());
    // Write the LDIF representation to a file, read it back, and ensure it
    // decodes to the same thing.
    final File ldifFile = createTempFile();
    assertTrue(ldifFile.delete());
    final LDIFWriter writer = new LDIFWriter(ldifFile);
    writer.writeChangeRecord(modifyDNRecord);
    writer.close();
    final LDIFReader reader = new LDIFReader(ldifFile);
    r = reader.readChangeRecord();
    assertNull(reader.readLDIFRecord());
    assertTrue(r instanceof LDIFModifyDNChangeRecord);
    assertNotNull(r.toString());
    modifyDNRecord = (LDIFModifyDNChangeRecord) r;
    assertEquals(modifyDNRecord.getControls(), controls);
    assertDNsEqual(modifyDNRecord.getDN(), "ou=People,dc=example,dc=com");
    assertEquals(new RDN(modifyDNRecord.getNewRDN()), new RDN("ou=Users"));
    assertTrue(modifyDNRecord.deleteOldRDN());
    assertNull(modifyDNRecord.getNewSuperiorDN());
    final ModifyDNRequest modifyDNRequest = modifyDNRecord.toModifyDNRequest();
    assertEquals(modifyDNRequest.getControlList(), controls);
    assertDNsEqual(modifyDNRequest.getDN(), "ou=People,dc=example,dc=com");
    assertEquals(new RDN(modifyDNRequest.getNewRDN()), new RDN("ou=Users"));
    assertTrue(modifyDNRequest.deleteOldRDN());
    assertNull(modifyDNRequest.getNewSuperiorDN());
}
Also used : ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) RDN(com.unboundid.ldap.sdk.RDN) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

ModifyDNRequest (com.unboundid.ldap.sdk.ModifyDNRequest)39 Test (org.testng.annotations.Test)32 AddRequest (com.unboundid.ldap.sdk.AddRequest)21 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)21 DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)20 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)20 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)11 Control (com.unboundid.ldap.sdk.Control)11 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)11 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)10 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)10 DN (com.unboundid.ldap.sdk.DN)9 LDAPConnectionOptions (com.unboundid.ldap.sdk.LDAPConnectionOptions)8 LDAPException (com.unboundid.ldap.sdk.LDAPException)8 TransactionSpecificationRequestControl (com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl)7 SearchResult (com.unboundid.ldap.sdk.SearchResult)6 TestUnsolicitedNotificationHandler (com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler)6 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)6 RDN (com.unboundid.ldap.sdk.RDN)5 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)5