Search in sources :

Example 1 with LdifControl

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

the class LdifControlSerializationTest method testControlNoCriticalWithDataSerialization.

@Test
public void testControlNoCriticalWithDataSerialization() throws IOException, ClassNotFoundException {
    LdifControl ldifControl1 = new LdifControl(controlNoCriticalWithData.getOid());
    ldifControl1.setCritical(controlNoCriticalWithData.isCritical());
    ldifControl1.setValue(((OpaqueControl) controlNoCriticalWithData).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 2 with LdifControl

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

the class LdifControlSerializationTest method testControlNoCriticalNoDataSerialization.

@Test
public void testControlNoCriticalNoDataSerialization() throws IOException, ClassNotFoundException {
    LdifControl ldifControl1 = new LdifControl(controlNoCriticalNoData.getOid());
    ldifControl1.setCritical(controlNoCriticalNoData.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 3 with LdifControl

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

the class LdifEntryTest method testLdifParserChangeTypeDeleteWithControls.

/**
 * Test a Delete changeType LdifEntry with controls
 *
 * @throws Exception
 */
@Test
public void testLdifParserChangeTypeDeleteWithControls() throws Exception {
    String ldif = "# Delete an entry. The operation will attach the LDAPv3\n" + "# Tree Delete Control defined in [9]. The criticality\n" + "# field is \"true\" and the controlValue field is\n" + "# absent, as required by [9].\n" + "control: 1.2.840.113556.1.4.805 true\n" + "control: 1.2.840.113556.1.4.806 false: test\n" + "changetype: delete\n";
    LdifEntry ldifEntry = new LdifEntry("ou=Product Development, dc=airius, dc=com", ldif);
    assertNotNull(ldifEntry);
    assertEquals(ChangeType.Delete, ldifEntry.getChangeType());
    assertNull(ldifEntry.getEntry());
    assertEquals("ou=Product Development, dc=airius, dc=com", ldifEntry.getDn().getName());
    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 : LdifControl(org.apache.directory.api.ldap.model.ldif.LdifControl) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 4 with LdifControl

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

the class LdifEntryTest method testLdifEntryChangeTypeModdnWithControl.

/**
 * Test a ModDn changeType LdifEntry with a control
 * @throws Exception
 */
@Test
public void testLdifEntryChangeTypeModdnWithControl() throws Exception {
    String ldif = "control: 1.2.840.113556.1.4.805 true\n" + "changetype: moddn\n" + "newrdn: cn=app2\n" + "deleteoldrdn: 1\n";
    LdifEntry ldifEntry = new LdifEntry("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldif);
    assertNotNull(ldifEntry);
    assertEquals(ChangeType.ModDn, ldifEntry.getChangeType());
    assertNull(ldifEntry.getEntry());
    assertEquals("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldifEntry.getDn().getName());
    assertTrue(ldifEntry.isLdifChange());
    assertEquals("cn=app2", ldifEntry.getNewRdn());
    assertNull(ldifEntry.getNewSuperior());
    assertTrue(ldifEntry.isDeleteOldRdn());
    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());
}
Also used : LdifControl(org.apache.directory.api.ldap.model.ldif.LdifControl) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 5 with LdifControl

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

the class LdifEntryTest method testLdifEntryChangeTypeAddWithControl.

/**
 * Test a Add changeType LdifEntry with a control
 * @throws Exception
 */
@Test
public void testLdifEntryChangeTypeAddWithControl() throws Exception {
    String ldif = "control: 1.2.840.113556.1.4.805 true\n" + "changetype: add\n" + "cn: app1\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName:   app1   \n" + "dependencies:\n" + "envVars:";
    LdifEntry ldifEntry = new LdifEntry("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldif);
    assertNotNull(ldifEntry);
    assertEquals(ChangeType.Add, ldifEntry.getChangeType());
    assertNotNull(ldifEntry.getEntry());
    assertEquals("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldifEntry.getDn().getName());
    assertTrue(ldifEntry.isLdifChange());
    Attribute attr = ldifEntry.get("displayname");
    assertTrue(attr.contains("app1"));
    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());
}
Also used : 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