Search in sources :

Example 41 with Dn

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());
}
Also used : LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 42 with Dn

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());
}
Also used : LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 43 with Dn

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());
}
Also used : LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) Rdn(org.apache.directory.api.ldap.model.name.Rdn) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 44 with Dn

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());
}
Also used : LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) Rdn(org.apache.directory.api.ldap.model.name.Rdn) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 45 with Dn

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);
}
Also used : LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Aggregations

Dn (org.apache.directory.api.ldap.model.name.Dn)307 Test (org.junit.Test)183 Rdn (org.apache.directory.api.ldap.model.name.Rdn)63 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)50 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)39 Entry (org.apache.directory.api.ldap.model.entry.Entry)34 DnNode (org.apache.directory.api.ldap.util.tree.DnNode)30 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)20 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)19 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)17 Modification (org.apache.directory.api.ldap.model.entry.Modification)17 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)16 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)10 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)10 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)10 Referral (org.apache.directory.api.ldap.model.message.Referral)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)8 Value (org.apache.directory.api.ldap.model.entry.Value)8