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);
}
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);
}
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()));
}
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());
}
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());
}
Aggregations