use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.
the class LdifRevertorTest method testReverseModifyAddNewOuValue.
/**
* Test a reversed Modify adding a new attribute value
* in an exiting attribute
*/
@Test
public void testReverseModifyAddNewOuValue() throws LdapException {
Entry modifiedEntry = buildEntry();
modifiedEntry.put("ou", "apache", "acme corp");
Dn dn = new Dn("cn=test, ou=system");
Modification mod = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, new DefaultAttribute("ou", "BigCompany inc."));
LdifEntry reversed = LdifRevertor.reverseModify(dn, Collections.<Modification>singletonList(mod), modifiedEntry);
assertNotNull(reversed);
assertEquals(dn.getName(), reversed.getDn().getName());
assertEquals(ChangeType.Modify, reversed.getChangeType());
assertNull(reversed.getEntry());
List<Modification> mods = reversed.getModifications();
assertNotNull(mods);
assertEquals(1, mods.size());
Modification modif = mods.get(0);
assertEquals(ModificationOperation.REMOVE_ATTRIBUTE, modif.getOperation());
Attribute attr = modif.getAttribute();
assertNotNull(attr);
assertEquals("ou", attr.getId());
assertEquals("BigCompany inc.", attr.getString());
}
use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.
the class LdifRevertorTest method testReverseModifyDelExistingOuValue.
/**
* Test a reversed Modify adding a existing value from an existing attribute
*/
@Test
public void testReverseModifyDelExistingOuValue() throws LdapException {
Entry modifiedEntry = buildEntry();
modifiedEntry.put("ou", "apache", "acme corp");
Dn dn = new Dn("cn=test, ou=system");
Modification mod = new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, new DefaultAttribute("ou", "acme corp"));
LdifEntry reversed = LdifRevertor.reverseModify(dn, Collections.<Modification>singletonList(mod), modifiedEntry);
assertNotNull(reversed);
assertEquals(dn.getName(), reversed.getDn().getName());
assertEquals(ChangeType.Modify, reversed.getChangeType());
assertNull(reversed.getEntry());
List<Modification> mods = reversed.getModifications();
assertNotNull(mods);
assertEquals(1, mods.size());
Modification modif = mods.get(0);
assertEquals(ModificationOperation.ADD_ATTRIBUTE, modif.getOperation());
Attribute attr = modif.getAttribute();
assertNotNull(attr);
assertEquals("ou", attr.getId());
assertEquals("acme corp", attr.getString());
}
use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.
the class LdifRevertorTest method test101ReverseRenameCompositeCompositeNotOverlappingKeepOldRdnDontExistInEntry.
/**
* Test a reversed rename ModifyDN, where the initial Rdn is composite,
* the new Rdn is composite, they don't overlap, with deleteOldRdn = false, and
* none of new values exists in the entry.
*
* Covers case 10.1 of http://cwiki.apache.org/confluence/display/DIRxSRVx11/Reverse+LDIF
*
* Initial entry
* dn: sn=small+cn=test,ou=system
* objectclass: top
* objectclass: person
* cn: test
* cn: big
* sn: small
* sn: This is a test
*
* new Rdn : cn=joe+cn=plumber
*
* @throws LdapException on error
*/
@Test
public void test101ReverseRenameCompositeCompositeNotOverlappingKeepOldRdnDontExistInEntry() throws LdapException {
Dn dn = new Dn("sn=small+cn=test,ou=system");
Rdn oldRdn = new Rdn("sn=small+cn=test");
Rdn newRdn = new Rdn("cn=joe+sn=plumber");
Entry entry = new DefaultEntry(dn, "objectClass: top", "objectClass: person", "cn: test", "cn: big", "sn: small", "sn: this is a test");
List<LdifEntry> reverseds = LdifRevertor.reverseRename(entry, newRdn, LdifRevertor.KEEP_OLD_RDN);
assertNotNull(reverseds);
assertEquals(1, reverseds.size());
LdifEntry reversed = reverseds.get(0);
assertEquals("cn=joe+sn=plumber,ou=system", reversed.getDn().getName());
assertEquals(ChangeType.ModRdn, reversed.getChangeType());
assertTrue(reversed.isDeleteOldRdn());
assertEquals(oldRdn.getName(), reversed.getNewRdn());
assertNull(reversed.getNewSuperior());
}
use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.
the class LdifRevertorTest method test92ReverseRenameSimpleCompositeOverlappingDeleteOldRdnDontExistInEntry.
/**
* Test a reversed rename ModifyDN, where the initial Rdn is simple,
* the new Rdn is composite, they overlap, with deleteOldRdn = true, and
* some of the new values exists in the entry.
*
* Covers case 9.2 of http://cwiki.apache.org/confluence/display/DIRxSRVx11/Reverse+LDIF
*
* Initial entry
* dn: cn=test,ou=system
* objectclass: top
* objectclass: person
* cn: test
* seeAlso: big
* sn: This is a test
*
* new Rdn : cn=small+cn=test+cn=big
*
* @throws LdapException on error
*/
@Test
public void test92ReverseRenameSimpleCompositeOverlappingDeleteOldRdnDontExistInEntry() throws LdapException {
Dn dn = new Dn("cn=test,ou=system");
Rdn oldRdn = new Rdn("cn=test");
Rdn newRdn = new Rdn("sn=small+cn=test+seeAlso=big");
Entry entry = new DefaultEntry(dn, "objectClass: top", "objectClass: person", "cn: test", "seeAlso: big", "sn: this is a test");
List<LdifEntry> reverseds = LdifRevertor.reverseRename(entry, newRdn, LdifRevertor.DELETE_OLD_RDN);
assertNotNull(reverseds);
assertEquals(2, reverseds.size());
LdifEntry reversed = reverseds.get(0);
assertEquals("sn=small+cn=test+seeAlso=big,ou=system", reversed.getDn().getName());
assertEquals(ChangeType.ModRdn, reversed.getChangeType());
assertFalse(reversed.isDeleteOldRdn());
assertEquals(oldRdn.getName(), reversed.getNewRdn());
assertNull(reversed.getNewSuperior());
reversed = reverseds.get(1);
assertEquals("cn=test,ou=system", reversed.getDn().getName());
assertEquals(ChangeType.Modify, reversed.getChangeType());
Modification[] mods = reversed.getModificationArray();
assertNotNull(mods);
assertEquals(1, mods.length);
assertEquals(ModificationOperation.REMOVE_ATTRIBUTE, mods[0].getOperation());
assertNotNull(mods[0].getAttribute());
assertEquals("sn", mods[0].getAttribute().getId());
assertEquals("small", mods[0].getAttribute().getString());
}
use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.
the class LdifRevertorTest method testReverseModifyReplaceExistingOuValues.
/**
* Test a reversed Modify replacing existing values with new values
*/
@Test
public void testReverseModifyReplaceExistingOuValues() throws LdapException {
Entry modifiedEntry = buildEntry();
Attribute ou = new DefaultAttribute("ou", "apache", "acme corp");
modifiedEntry.put(ou);
Dn dn = new Dn("cn=test, ou=system");
Attribute ouModified = new DefaultAttribute("ou", "directory", "BigCompany inc.");
Modification mod = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, ouModified);
LdifEntry reversed = LdifRevertor.reverseModify(dn, Collections.<Modification>singletonList(mod), modifiedEntry);
assertNotNull(reversed);
assertEquals(dn.getName(), reversed.getDn().getName());
assertEquals(ChangeType.Modify, reversed.getChangeType());
assertNull(reversed.getEntry());
List<Modification> mods = reversed.getModifications();
assertNotNull(mods);
assertEquals(1, mods.size());
Modification modif = mods.get(0);
assertEquals(ModificationOperation.REPLACE_ATTRIBUTE, modif.getOperation());
Attribute attr = modif.getAttribute();
assertNotNull(attr);
assertEquals(ou, attr);
}
Aggregations