Search in sources :

Example 56 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testRemoveStringByteArrayArray.

/**
 * Test method for remove(String, byte[]... )
 */
@Test
public void testRemoveStringByteArrayArray() throws LdapException {
    Entry entry = new DefaultEntry(exampleDn);
    Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, (byte[]) null, BYTES2);
    entry.put(attrPWD);
    assertTrue(entry.remove("userPassword", (byte[]) null));
    assertTrue(entry.remove("userPassword", BYTES1, BYTES2));
    assertFalse(entry.containsAttribute("userPassword"));
    entry.add("userPassword", BYTES1, (byte[]) null, BYTES2);
    assertTrue(entry.remove("userPassword", (byte[]) null));
    assertEquals(2, entry.get("userPassword").size());
    assertTrue(entry.remove("userPassword", BYTES1, BYTES3));
    assertEquals(1, entry.get("userPassword").size());
    assertTrue(Arrays.equals(BYTES2, entry.get("userPassword").getBytes()));
    assertFalse(entry.remove("userPassword", BYTES3));
    assertFalse(entry.remove("void", "whatever"));
}
Also used : 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) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 57 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.

the class SchemaAwareModificationSerializationTest method testCreateServerModification.

@Test
public void testCreateServerModification() throws LdapException {
    Attribute attribute = new DefaultAttribute("cn", cnAT);
    attribute.add("test1", "test2");
    Modification mod = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attribute);
    Modification clone = mod.clone();
    attribute.remove("test2");
    Attribute clonedAttribute = clone.getAttribute();
    assertEquals(1, mod.getAttribute().size());
    assertTrue(mod.getAttribute().contains("TEST1"));
    assertEquals(2, clonedAttribute.size());
    assertTrue(clone.getAttribute().contains("test1"));
    assertTrue(clone.getAttribute().contains("test2"));
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) 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) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 58 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.

the class SchemaAwareModificationSerializationTest method testSerializationModificationREMOVE.

@Test
public void testSerializationModificationREMOVE() throws ClassNotFoundException, IOException, LdapInvalidAttributeValueException {
    Attribute attribute = new DefaultAttribute("cn", cnAT);
    attribute.add("test1", "test2");
    DefaultModification mod = new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, attribute);
    Modification modSer = deserializeValue(serializeValue(mod));
    assertEquals(mod, modSer);
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) 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) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 59 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.

the class AddRequestImplTest method getAttribute.

/**
 * Creates and populates a AttributeImpl with a specific id.
 *
 * @param id
 *            the id for the attribute
 * @return the AttributeImpl assembled for testing
 */
private Attribute getAttribute(String id) throws LdapException {
    Attribute attr = new DefaultAttribute(id);
    attr.add("value0");
    attr.add("value1");
    attr.add("value2");
    return attr;
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Example 60 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.

the class ModificationTest method testCreateServerModification.

@Test
public void testCreateServerModification() throws LdapException {
    Attribute attribute = new DefaultAttribute("cn");
    attribute.add("test1", "test2");
    Modification mod = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attribute);
    Modification clone = mod.clone();
    attribute.remove("test2");
    Attribute clonedAttribute = clone.getAttribute();
    assertEquals(1, mod.getAttribute().size());
    assertTrue(mod.getAttribute().contains("test1"));
    assertEquals(2, clonedAttribute.size());
    assertTrue(clone.getAttribute().contains("test1"));
    assertTrue(clone.getAttribute().contains("test2"));
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) 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) 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