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