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