Search in sources :

Example 96 with ByteStringBuffer

use of com.unboundid.util.ByteStringBuffer in project ldapsdk by pingidentity.

the class LDIFAddChangeRecordTestCase method testConstructor2.

/**
 * Tests the second constructor.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructor2() throws Exception {
    Entry e = new Entry("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
    LDIFAddChangeRecord r = new LDIFAddChangeRecord(e);
    assertNotNull(r.getDN());
    assertEquals(r.getDN(), "dc=example,dc=com");
    assertEquals(r.getParsedDN(), new DN("dc=example,dc=com"));
    assertNotNull(r.getAttributes());
    assertEquals(r.getAttributes().length, 2);
    AddRequest addRequest = r.toAddRequest();
    assertNotNull(addRequest);
    assertEquals(addRequest.getDN(), "dc=example,dc=com");
    assertEquals(r.getChangeType(), ChangeType.ADD);
    String[] ldifLines = r.toLDIF();
    assertNotNull(ldifLines);
    assertEquals(ldifLines.length, 5);
    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());
    assertNotNull(r.getEntryToAdd());
    assertEquals(r.getEntryToAdd(), new Entry(r.getDN(), r.getAttributes()));
}
Also used : AddRequest(com.unboundid.ldap.sdk.AddRequest) Entry(com.unboundid.ldap.sdk.Entry) DN(com.unboundid.ldap.sdk.DN) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) Test(org.testng.annotations.Test)

Example 97 with ByteStringBuffer

use of com.unboundid.util.ByteStringBuffer in project ldapsdk by pingidentity.

the class LDIFChangeRecordTestCase method testModifyChangeRecordWithMultipleChanges.

/**
 * Performs a set of general tests for a modify change record with multiple
 * changes.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyChangeRecordWithMultipleChanges() throws Exception {
    LDIFModifyChangeRecord r = new LDIFModifyChangeRecord("dc=example,dc=com", new Modification(ModificationType.REPLACE, "description", "foo"), new Modification(ModificationType.REPLACE, "o", "example.com"));
    assertNotNull(r.getDN());
    assertEquals(new DN(r.getDN()), new DN("dc=example,dc=com"));
    assertNotNull(r.getParsedDN());
    assertEquals(r.getParsedDN(), new DN("dc=example,dc=com"));
    assertEquals(r.getChangeType(), ChangeType.MODIFY);
    try {
        assertNotNull(r.toEntry());
        fail("Expected an exception when trying to convert a modify change " + "record with multiple changes to an entry.");
    } catch (LDIFException le) {
    // This was expected.
    }
    assertNotNull(r.toLDIF());
    assertFalse(r.toLDIF().length == 0);
    assertEquals(LDIFReader.decodeChangeRecord(r.toLDIF()), r);
    assertNotNull(r.toLDIF(10));
    assertFalse(r.toLDIF(10).length == 0);
    assertEquals(LDIFReader.decodeChangeRecord(r.toLDIF(10)), r);
    ByteStringBuffer byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer);
    assertFalse(byteBuffer.length() == 0);
    byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer, 10);
    assertFalse(byteBuffer.length() == 0);
    assertNotNull(r.toLDIFString());
    assertNotNull(r.toLDIFString(10));
    StringBuilder stringBuffer = new StringBuilder();
    r.toLDIFString(stringBuffer);
    assertFalse(stringBuffer.length() == 0);
    stringBuffer = new StringBuilder();
    r.toLDIFString(stringBuffer, 10);
    assertFalse(stringBuffer.length() == 0);
    assertNotNull(r.toString());
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) DN(com.unboundid.ldap.sdk.DN) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) Test(org.testng.annotations.Test)

Example 98 with ByteStringBuffer

use of com.unboundid.util.ByteStringBuffer in project ldapsdk by pingidentity.

the class LDIFModifyChangeRecordTestCase method testConstructor2MultipleModifications.

/**
 * Tests the second constructor with multiple modifications.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructor2MultipleModifications() throws Exception {
    List<Modification> mods = Arrays.asList(new Modification(ModificationType.REPLACE, "description", "foo", "bar"), new Modification(ModificationType.ADD, "objectClass", "extensibleObject"), new Modification(ModificationType.DELETE, "cn"), new Modification(ModificationType.INCREMENT, "intValue", "5"));
    LDIFModifyChangeRecord r = new LDIFModifyChangeRecord("dc=example,dc=com", mods);
    assertNotNull(r.getDN());
    assertEquals(r.getDN(), "dc=example,dc=com");
    assertEquals(r.getParsedDN(), new DN("dc=example,dc=com"));
    assertNotNull(r.getModifications());
    assertEquals(r.getModifications().length, 4);
    ModifyRequest modifyRequest = r.toModifyRequest();
    assertEquals(modifyRequest.getDN(), "dc=example,dc=com");
    assertEquals(r.getChangeType(), ChangeType.MODIFY);
    assertTrue(LDIFModifyChangeRecord.alwaysIncludeTrailingDash());
    String[] ldifLines = r.toLDIF();
    assertNotNull(ldifLines);
    assertEquals(ldifLines.length, 14);
    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());
    LDIFModifyChangeRecord.setAlwaysIncludeTrailingDash(false);
    assertFalse(LDIFModifyChangeRecord.alwaysIncludeTrailingDash());
    ldifLines = r.toLDIF();
    assertNotNull(ldifLines);
    assertEquals(ldifLines.length, 13);
    LDIFModifyChangeRecord.setAlwaysIncludeTrailingDash(true);
    assertTrue(LDIFModifyChangeRecord.alwaysIncludeTrailingDash());
    r.hashCode();
    byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer);
    assertNotNull(byteBuffer.toString());
    byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer, 10);
    assertNotNull(byteBuffer.toString());
    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 : Modification(com.unboundid.ldap.sdk.Modification) DN(com.unboundid.ldap.sdk.DN) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) Test(org.testng.annotations.Test)

Example 99 with ByteStringBuffer

use of com.unboundid.util.ByteStringBuffer in project ldapsdk by pingidentity.

the class LDIFModifyChangeRecordTestCase method testConstructor3.

/**
 * Tests the third constructor.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructor3() throws Exception {
    Modification[] mods = { new Modification(ModificationType.ADD, "description", "foo") };
    ModifyRequest modifyRequest = new ModifyRequest("dc=example,dc=com", mods);
    LDIFModifyChangeRecord r = new LDIFModifyChangeRecord(modifyRequest);
    assertNotNull(r.getDN());
    assertEquals(r.getDN(), "dc=example,dc=com");
    assertEquals(r.getParsedDN(), new DN("dc=example,dc=com"));
    assertNotNull(r.getModifications());
    assertEquals(r.getModifications().length, 1);
    modifyRequest = r.toModifyRequest();
    assertEquals(modifyRequest.getDN(), "dc=example,dc=com");
    assertEquals(r.getChangeType(), ChangeType.MODIFY);
    assertTrue(LDIFModifyChangeRecord.alwaysIncludeTrailingDash());
    String[] ldifLines = r.toLDIF();
    assertNotNull(ldifLines);
    assertEquals(ldifLines.length, 5);
    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());
    LDIFModifyChangeRecord.setAlwaysIncludeTrailingDash(false);
    assertFalse(LDIFModifyChangeRecord.alwaysIncludeTrailingDash());
    ldifLines = r.toLDIF();
    assertNotNull(ldifLines);
    assertEquals(ldifLines.length, 4);
    LDIFModifyChangeRecord.setAlwaysIncludeTrailingDash(true);
    assertTrue(LDIFModifyChangeRecord.alwaysIncludeTrailingDash());
    r.hashCode();
    byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer);
    assertNotNull(byteBuffer.toString());
    byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer, 10);
    assertNotNull(byteBuffer.toString());
    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 : Modification(com.unboundid.ldap.sdk.Modification) DN(com.unboundid.ldap.sdk.DN) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) Test(org.testng.annotations.Test)

Example 100 with ByteStringBuffer

use of com.unboundid.util.ByteStringBuffer in project ldapsdk by pingidentity.

the class LDIFModifyChangeRecordTestCase method testConstructor2SingleModification.

/**
 * Tests the second constructor with a single modification.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructor2SingleModification() throws Exception {
    List<Modification> mods = Arrays.asList(new Modification(ModificationType.ADD, "description", "foo"));
    LDIFModifyChangeRecord r = new LDIFModifyChangeRecord("dc=example,dc=com", mods);
    assertNotNull(r.getDN());
    assertEquals(r.getDN(), "dc=example,dc=com");
    assertEquals(r.getParsedDN(), new DN("dc=example,dc=com"));
    assertNotNull(r.getModifications());
    assertEquals(r.getModifications().length, 1);
    ModifyRequest modifyRequest = r.toModifyRequest();
    assertEquals(modifyRequest.getDN(), "dc=example,dc=com");
    assertEquals(r.getChangeType(), ChangeType.MODIFY);
    assertTrue(LDIFModifyChangeRecord.alwaysIncludeTrailingDash());
    String[] ldifLines = r.toLDIF();
    assertNotNull(ldifLines);
    assertEquals(ldifLines.length, 5);
    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());
    LDIFModifyChangeRecord.setAlwaysIncludeTrailingDash(false);
    assertFalse(LDIFModifyChangeRecord.alwaysIncludeTrailingDash());
    ldifLines = r.toLDIF();
    assertNotNull(ldifLines);
    assertEquals(ldifLines.length, 4);
    LDIFModifyChangeRecord.setAlwaysIncludeTrailingDash(true);
    assertTrue(LDIFModifyChangeRecord.alwaysIncludeTrailingDash());
    r.hashCode();
    byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer);
    assertNotNull(byteBuffer.toString());
    byteBuffer = new ByteStringBuffer();
    r.toLDIF(byteBuffer, 10);
    assertNotNull(byteBuffer.toString());
    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 : Modification(com.unboundid.ldap.sdk.Modification) DN(com.unboundid.ldap.sdk.DN) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) Test(org.testng.annotations.Test)

Aggregations

ByteStringBuffer (com.unboundid.util.ByteStringBuffer)142 Test (org.testng.annotations.Test)99 NotNull (com.unboundid.util.NotNull)22 DN (com.unboundid.ldap.sdk.DN)20 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)11 Entry (com.unboundid.ldap.sdk.Entry)10 ResultCode (com.unboundid.ldap.sdk.ResultCode)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 InputStream (java.io.InputStream)8 Modification (com.unboundid.ldap.sdk.Modification)7 File (java.io.File)6 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)5 RDN (com.unboundid.ldap.sdk.RDN)5 FileOutputStream (java.io.FileOutputStream)5 Map (java.util.Map)5 Control (com.unboundid.ldap.sdk.Control)4 LDAPException (com.unboundid.ldap.sdk.LDAPException)4 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)4 ArgumentException (com.unboundid.util.args.ArgumentException)4