Search in sources :

Example 6 with LdifControl

use of org.apache.directory.api.ldap.model.ldif.LdifControl in project directory-ldap-api by apache.

the class LdifControlSerializationTest method testControlNoCriticalEmptyDataSerialization.

@Test
public void testControlNoCriticalEmptyDataSerialization() throws IOException, ClassNotFoundException {
    LdifControl ldifControl1 = new LdifControl(controlNoCriticalEmptyData.getOid());
    ldifControl1.setCritical(controlNoCriticalEmptyData.isCritical());
    ldifControl1.setValue(((OpaqueControl) controlNoCriticalEmptyData).getEncodedValue());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    ldifControl1.writeExternal(out);
    ObjectInputStream in = null;
    byte[] data = baos.toByteArray();
    in = new ObjectInputStream(new ByteArrayInputStream(data));
    LdifControl ldifControl2 = new LdifControl();
    ldifControl2.readExternal(in);
    assertEquals(ldifControl1, ldifControl2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LdifControl(org.apache.directory.api.ldap.model.ldif.LdifControl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 7 with LdifControl

use of org.apache.directory.api.ldap.model.ldif.LdifControl in project directory-ldap-api by apache.

the class LdifControlSerializationTest method testControlCriticalNoDataSerialization.

@Test
public void testControlCriticalNoDataSerialization() throws IOException, ClassNotFoundException {
    LdifControl ldifControl1 = new LdifControl(controlCriticalNoData.getOid());
    ldifControl1.setCritical(controlCriticalNoData.isCritical());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    ldifControl1.writeExternal(out);
    ObjectInputStream in = null;
    byte[] data = baos.toByteArray();
    in = new ObjectInputStream(new ByteArrayInputStream(data));
    LdifControl ldifControl2 = new LdifControl();
    ldifControl2.readExternal(in);
    assertEquals(ldifControl1, ldifControl2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LdifControl(org.apache.directory.api.ldap.model.ldif.LdifControl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 8 with LdifControl

use of org.apache.directory.api.ldap.model.ldif.LdifControl in project directory-ldap-api by apache.

the class LdifControlSerializationTest method testControlCriticalWithDataSerialization.

@Test
public void testControlCriticalWithDataSerialization() throws IOException, ClassNotFoundException {
    LdifControl ldifControl1 = new LdifControl(controlCriticalWithData.getOid());
    ldifControl1.setCritical(controlCriticalWithData.isCritical());
    ldifControl1.setValue(((OpaqueControl) controlCriticalWithData).getEncodedValue());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    ldifControl1.writeExternal(out);
    ObjectInputStream in = null;
    byte[] data = baos.toByteArray();
    in = new ObjectInputStream(new ByteArrayInputStream(data));
    LdifControl ldifControl2 = new LdifControl();
    ldifControl2.readExternal(in);
    assertEquals(ldifControl1, ldifControl2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LdifControl(org.apache.directory.api.ldap.model.ldif.LdifControl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 9 with LdifControl

use of org.apache.directory.api.ldap.model.ldif.LdifControl in project directory-ldap-api by apache.

the class LdifControlSerializationTest method testControlCriticalEmptyDataSerialization.

@Test
public void testControlCriticalEmptyDataSerialization() throws IOException, ClassNotFoundException {
    LdifControl ldifControl1 = new LdifControl(controlCriticalEmptyData.getOid());
    ldifControl1.setCritical(controlCriticalEmptyData.isCritical());
    ldifControl1.setValue(((OpaqueControl) controlCriticalEmptyData).getEncodedValue());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    ldifControl1.writeExternal(out);
    ObjectInputStream in = null;
    byte[] data = baos.toByteArray();
    in = new ObjectInputStream(new ByteArrayInputStream(data));
    LdifControl ldifControl2 = new LdifControl();
    ldifControl2.readExternal(in);
    assertEquals(ldifControl1, ldifControl2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LdifControl(org.apache.directory.api.ldap.model.ldif.LdifControl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 10 with LdifControl

use of org.apache.directory.api.ldap.model.ldif.LdifControl in project directory-ldap-api by apache.

the class LdifEntryTest method testLdifEntryChangeTypeModifyNoAttributeWithControls.

/**
 * Test a Modify changeType LdifEntry with no attributes and controls
 */
@Test
public void testLdifEntryChangeTypeModifyNoAttributeWithControls() throws Exception {
    String ldif = "control: 1.2.840.113556.1.4.805 true\n" + "control: 1.2.840.113556.1.4.806 false: test\n" + "changetype: modify\n" + "add: cn\n" + "-";
    LdifEntry ldifEntry = new LdifEntry("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldif);
    assertNotNull(ldifEntry);
    assertEquals(ChangeType.Modify, ldifEntry.getChangeType());
    assertNull(ldifEntry.getEntry());
    assertEquals("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldifEntry.getDn().getName());
    assertTrue(ldifEntry.isLdifChange());
    // Check the modification
    assertNotNull(ldifEntry.getModifications());
    for (Modification modification : ldifEntry.getModifications()) {
        assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
        Attribute attribute = modification.getAttribute();
        assertNotNull(attribute);
        assertEquals("cn", attribute.getId());
        assertEquals(1, attribute.size());
        assertTrue(attribute.get().isNull());
    }
    assertTrue(ldifEntry.hasControls());
    LdifControl ldifControl = ldifEntry.getControl("1.2.840.113556.1.4.805");
    assertNotNull(ldifControl);
    assertEquals("1.2.840.113556.1.4.805", ldifControl.getOid());
    assertTrue(ldifControl.isCritical());
    assertNull(ldifControl.getValue());
    ldifControl = ldifEntry.getControl("1.2.840.113556.1.4.806");
    assertNotNull(ldifControl);
    assertEquals("1.2.840.113556.1.4.806", ldifControl.getOid());
    assertFalse(ldifControl.isCritical());
    assertNotNull(ldifControl.getValue());
    assertEquals("test", Strings.utf8ToString(ldifControl.getValue()));
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdifControl(org.apache.directory.api.ldap.model.ldif.LdifControl) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Aggregations

LdifControl (org.apache.directory.api.ldap.model.ldif.LdifControl)13 Test (org.junit.Test)13 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ObjectInputStream (java.io.ObjectInputStream)6 ObjectOutputStream (java.io.ObjectOutputStream)6 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)3 Modification (org.apache.directory.api.ldap.model.entry.Modification)1