Search in sources :

Example 61 with DefaultAttribute

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);
}
Also used : ObjectOutput(java.io.ObjectOutput) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 62 with DefaultAttribute

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);
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 63 with DefaultAttribute

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"));
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 64 with DefaultAttribute

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());
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 65 with DefaultAttribute

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"));
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Aggregations

DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)159 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)131 Test (org.junit.Test)106 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)41 Modification (org.apache.directory.api.ldap.model.entry.Modification)40 Entry (org.apache.directory.api.ldap.model.entry.Entry)36 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)35 Value (org.apache.directory.api.ldap.model.entry.Value)20 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ObjectInputStream (java.io.ObjectInputStream)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ObjectOutputStream (java.io.ObjectOutputStream)12 Dn (org.apache.directory.api.ldap.model.name.Dn)12 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)11 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)11 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)8 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)7 ModifyRequestImpl (org.apache.directory.api.ldap.model.message.ModifyRequestImpl)7 ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)7 HashSet (java.util.HashSet)6