use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class AttributeSerializationTest method testEntryAttributeNoStringValueSerialization.
@Test
public void testEntryAttributeNoStringValueSerialization() throws IOException, ClassNotFoundException {
Attribute attribute1 = new DefaultAttribute("CN");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(baos);
attribute1.writeExternal(out);
ObjectInputStream in = null;
byte[] data = baos.toByteArray();
in = new ObjectInputStream(new ByteArrayInputStream(data));
Attribute attribute2 = new DefaultAttribute();
attribute2.readExternal(in);
assertEquals(attribute1, attribute2);
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class AttributeSerializationTest method testEntryAttributeManyBinaryValuesSerialization.
@Test
public void testEntryAttributeManyBinaryValuesSerialization() throws IOException, ClassNotFoundException {
Attribute attribute1 = new DefaultAttribute("UserCertificate", data1, data2, data3);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
attribute1.writeExternal(out);
ObjectInputStream in = null;
byte[] data = baos.toByteArray();
in = new ObjectInputStream(new ByteArrayInputStream(data));
Attribute attribute2 = new DefaultAttribute();
attribute2.readExternal(in);
assertEquals(attribute1, attribute2);
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class AttributeUtilsTest method testApplyRemoveModificationFromEntryAttributeNotSameValue.
/**
* Test the deletion of an attribute into an entry which contains the attribute
* but without the value to be deleted
*/
@Test
public void testApplyRemoveModificationFromEntryAttributeNotSameValue() throws LdapException {
Entry entry = new DefaultEntry();
Attribute cn = new DefaultAttribute("cn", "apache");
entry.put(cn);
Attribute attr = new DefaultAttribute("cn", "test");
Modification modification = new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, attr);
AttributeUtils.applyModification(entry, modification);
assertNotNull(entry.get("cn"));
assertEquals(1, entry.size());
assertEquals(cn, entry.get("cn"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class AttributeUtilsTest method testApplyRemoveModificationFromEntrySameAttributeSameValue.
/**
* Test the deletion of an attribute into an entry which contains the attribute.
*
* The entry should not contain the attribute after the operation
*/
@Test
public void testApplyRemoveModificationFromEntrySameAttributeSameValue() throws LdapException {
Entry entry = new DefaultEntry();
entry.put("cn", "test");
Attribute attr = new DefaultAttribute("cn", "test");
Modification modification = new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, attr);
AttributeUtils.applyModification(entry, modification);
assertNull(entry.get("cn"));
assertEquals(0, entry.size());
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class AttributeUtilsTest method testApplyAddModificationToEntry.
/**
* Test a addModification applied to an entry
*/
@Test
public void testApplyAddModificationToEntry() throws LdapException {
Entry entry = new DefaultEntry();
entry.add("dc", "apache");
assertEquals(1, entry.size());
Attribute attr = new DefaultAttribute("cn", "test");
Modification modification = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attr);
AttributeUtils.applyModification(entry, modification);
assertNotNull(entry.get("cn"));
assertEquals(2, entry.size());
assertEquals(attr, entry.get("cn"));
}
Aggregations