use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class AttributeUtilsTest method testApplyRemoveModificationFromEntrySameAttributeValues.
/**
* Test the deletion of an attribute into an entry which contains the attribute
* with more than one value
*
* The entry should contain the attribute after the operation, but with one less value
*/
@Test
public void testApplyRemoveModificationFromEntrySameAttributeValues() throws LdapException {
Entry entry = new DefaultEntry();
entry.put("cn", "test", "apache");
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());
Attribute modifiedAttr = entry.get("cn");
assertTrue(modifiedAttr.size() != 0);
boolean isFirst = true;
for (Value value : modifiedAttr) {
assertTrue(isFirst);
isFirst = false;
assertEquals("apache", value.getValue());
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class AttributeUtilsTest method testApplyRemoveModificationFromEmptyEntry.
/**
* Test the deletion of an attribute into an empty entry
*/
@Test
public void testApplyRemoveModificationFromEmptyEntry() throws LdapException {
Entry entry = new DefaultEntry();
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 ModifyRequestImplTest method testNotEqualDiffModOps.
/**
* Test for inequality when only the mods ops are different.
*/
@Test
public void testNotEqualDiffModOps() throws LdapException {
ModifyRequestImpl req0 = getRequest();
Attribute attr = new DefaultAttribute("attr3");
attr.add("val0");
attr.add("val1");
attr.add("val2");
Modification item = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attr);
req0.addModification(item);
ModifyRequestImpl req1 = getRequest();
attr = new DefaultAttribute("attr3");
attr.add("val0");
attr.add("val1");
attr.add("val2");
item = new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, attr);
req0.addModification(item);
assertFalse(req0.equals(req1));
assertFalse(req1.equals(req0));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class ModifyRequestImplTest method testNotEqualDiffModIds.
/**
* Test for inequality when only the mods attribute Id's are different.
*/
@Test
public void testNotEqualDiffModIds() throws LdapException {
ModifyRequestImpl req0 = getRequest();
Attribute attr = new DefaultAttribute("attr3");
attr.add("val0");
attr.add("val1");
attr.add("val2");
Modification item = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attr);
req0.addModification(item);
ModifyRequestImpl req1 = getRequest();
attr = new DefaultAttribute("attr4");
attr.add("val0");
attr.add("val1");
attr.add("val2");
item = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attr);
req0.addModification(item);
assertFalse(req0.equals(req1));
assertFalse(req1.equals(req0));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class ModifyRequestImplTest method testNotEqualDiffModValues.
/**
* Test for inequality when only the mods attribute values are different.
*/
@Test
public void testNotEqualDiffModValues() throws LdapException {
ModifyRequestImpl req0 = getRequest();
Attribute attr = new DefaultAttribute("attr3");
attr.add("val0");
attr.add("val1");
attr.add("val2");
Modification item = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attr);
req0.addModification(item);
ModifyRequestImpl req1 = getRequest();
attr = new DefaultAttribute("attr3");
attr.add("val0");
attr.add("val1");
attr.add("val2");
attr.add("val3");
item = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attr);
req0.addModification(item);
assertFalse(req0.equals(req1));
assertFalse(req1.equals(req0));
}
Aggregations