Search in sources :

Example 11 with LdifControl

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

the class LdifEntryTest method testLdifEntryChangeTypeModddnWithControls.

/**
 * Test a ModDN changeType LdifEntry with controls
 * @throws Exception
 */
@Test
public void testLdifEntryChangeTypeModddnWithControls() 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: 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());
    assertTrue(ldifEntry.isDeleteOldRdn());
    assertNull(ldifEntry.getNewSuperior());
    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 12 with LdifControl

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

the class LdifEntryTest method testLdifParserChangeTypeDeleteWithControl.

/**
 * Test a Delete changeType LdifEntry with one control
 *
 * @throws Exception
 */
@Test
public void testLdifParserChangeTypeDeleteWithControl() 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" + "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());
}
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 13 with LdifControl

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

the class LdifEntryTest method testLdifEntryChangeTypeAddWithControls.

/**
 * Test a Add changeType LdifEntry with controls
 * @throws Exception
 */
@Test
public void testLdifEntryChangeTypeAddWithControls() 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: 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());
    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 : 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