use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class LdifUtilsTest method testReverseModifyDNDeleteOldRdnSuperior.
/**
* Test a reversed ModifyDN with a deleteOldRdn, rdn change, and a superior
*
* @throws NamingException on error
*/
@Test
public void testReverseModifyDNDeleteOldRdnSuperior() throws LdapException {
Dn dn = new Dn("cn=john doe, dc=example, dc=com");
Dn newSuperior = new Dn("ou=system");
Entry entry = new DefaultEntry(dn);
entry.add("objectClass", "person", "uidObject");
entry.add("cn", "john doe");
entry.add("sn", "doe");
entry.add("uid", "jdoe");
List<LdifEntry> reverseds = LdifRevertor.reverseMoveAndRename(entry, newSuperior, new Rdn("cn=jack doe"), false);
assertNotNull(reverseds);
assertEquals(1, reverseds.size());
LdifEntry reversed = reverseds.get(0);
assertEquals("cn=jack doe,ou=system", reversed.getDn().getName());
assertEquals(ChangeType.ModRdn, reversed.getChangeType());
assertTrue(reversed.isDeleteOldRdn());
assertEquals("cn=john doe", reversed.getNewRdn());
assertEquals("dc=example, dc=com", Strings.trim(reversed.getNewSuperior()));
assertNull(reversed.getEntry());
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry 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.DefaultEntry 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.DefaultEntry 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"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry 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());
}
}
Aggregations