Search in sources :

Example 31 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class LdifRevertorTest method testReverseMultipleModifications.

/**
 * Test a multiple modifications reverse.
 *
 * On the following entry :
 *  dn: cn=test, ou=system
 *  objectclass: top
 *  objectclass: person
 *  cn: test
 *  sn: joe doe
 *  l: USA
 *  ou: apache
 *  ou: acme corp
 *
 * We will :
 *  - add an 'ou' value 'BigCompany inc.'
 *  - delete the 'l' attribute
 *  - add the 'l=FR' attribute
 *  - replace the 'l=FR' by a 'l=USA' attribute
 *  - replace the 'ou' attribute with 'apache' value.
 *
 * The modify ldif will be :
 *
 *  dn: cn=test, ou=system
 *  changetype: modify
 *  add: ou
 *  ou: BigCompany inc.
 *  -
 *  delete: l
 *  -
 *  add: l
 *  l: FR
 *  -
 *  replace: l
 *  l: USA
 *  -
 *  replace: ou
 *  ou: apache
 *  -
 *
 * At the end, the entry will looks like :
 *  dn: cn=test, ou=system
 *  objectclass: top
 *  objectclass: person
 *  cn: test
 *  sn: joe doe
 *  l: USA
 *  ou: apache
 *
 * and the reversed LDIF will be :
 *
 *  dn: cn=test, ou=system
 *  changetype: modify
 *  replace: ou
 *  ou: apache
 *  ou: acme corp
 *  -
 *  replace: l
 *  l: USA
 *  -
 *  delete: l
 *  l: FR
 *  -
 *  add: l
 *  l: USA
 *  -
 *  delete: ou
 *  ou: BigCompany inc.
 *  -
 */
@Test
public void testReverseMultipleModifications() throws Exception {
    String initialEntryLdif = "dn: cn=test, ou=system\n" + "objectclass: top\n" + "objectclass: person\n" + "cn: test\n" + "sn: joe doe\n" + "l: USA\n" + "ou: apache\n" + "ou: acme corp\n";
    LdifReader reader = new LdifReader();
    List<LdifEntry> entries = reader.parseLdif(initialEntryLdif);
    reader.close();
    LdifEntry initialEntry = entries.get(0);
    // We will :
    // - add an 'ou' value 'BigCompany inc.'
    // - delete the 'l' attribute
    // - add the 'l=FR' attribute
    // - replace the 'l=FR' by a 'l=USA' attribute
    // - replace the 'ou' attribute with 'apache' value.
    Dn dn = new Dn("cn=test, ou=system");
    List<Modification> modifications = new ArrayList<Modification>();
    // First, inject the 'ou'
    Modification mod = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, new DefaultAttribute("ou", "BigCompany inc."));
    modifications.add(mod);
    // Remove the 'l'
    mod = new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, new DefaultAttribute("l"));
    modifications.add(mod);
    // Add 'l=FR'
    mod = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, new DefaultAttribute("l", "FR"));
    modifications.add(mod);
    // Replace it with 'l=USA'
    mod = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, new DefaultAttribute("l", "USA"));
    modifications.add(mod);
    // Replace the ou value
    mod = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, new DefaultAttribute("ou", "apache"));
    modifications.add(mod);
    LdifEntry reversedEntry = LdifRevertor.reverseModify(dn, modifications, initialEntry.getEntry());
    String expectedEntryLdif = "dn: cn=test, ou=system\n" + "changetype: modify\n" + "replace: ou\n" + "ou: apache\n" + "ou: acme corp\n" + "ou: BigCompany inc.\n" + "-\n" + "replace: l\n" + "l: FR\n" + "-\n" + "delete: l\n" + "l: FR\n" + "-\n" + "add: l\n" + "l: USA\n" + "-\n" + "delete: ou\n" + "ou: BigCompany inc.\n" + "-\n\n";
    reader = new LdifReader();
    entries = reader.parseLdif(expectedEntryLdif);
    reader.close();
    LdifEntry expectedEntry = entries.get(0);
    assertEquals(expectedEntry, reversedEntry);
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) ArrayList(java.util.ArrayList) Dn(org.apache.directory.api.ldap.model.name.Dn) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 32 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class LdifRevertorTest method testReverseAddBase64DN.

/**
 * Test a AddRequest reverse where the Dn is to be base64 encoded
 *
 * @throws LdapException
 */
@Test
public void testReverseAddBase64DN() throws LdapException {
    Dn dn = new Dn("dc=Emmanuel L\u00c9charny");
    LdifEntry reversed = LdifRevertor.reverseAdd(dn);
    assertNotNull(reversed);
    assertEquals(dn.getName(), reversed.getDn().getName());
    assertEquals(ChangeType.Delete, reversed.getChangeType());
    assertNull(reversed.getEntry());
}
Also used : Dn(org.apache.directory.api.ldap.model.name.Dn) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 33 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class LdifRevertorTest method test132ReverseRenameCompositeCompositeOverlappingDeleteOldRdnExistInEntry.

/**
 * Test a reversed rename ModifyDN, where the initial Rdn is composite,
 * the new Rdn is composite, they are overlapping, with deleteOldRdn = true, and
 * some of the new values exists in the entry.
 *
 * Covers case 13.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
 * sn: small
 * sn: big
 * sn: This is a test
 *
 * new Rdn : sn=big+cn=test
 *
 * @throws LdapException on error
 */
@Test
public void test132ReverseRenameCompositeCompositeOverlappingDeleteOldRdnExistInEntry() throws LdapException {
    Dn dn = new Dn("sn=small+cn=test,ou=system");
    Rdn oldRdn = new Rdn("sn=small+cn=test");
    Rdn newRdn = new Rdn("sn=big+cn=test");
    Entry entry = new DefaultEntry(dn, "objectClass: top", "objectClass: person", "cn: test", "sn: small", "sn: big", "sn: this is a test");
    List<LdifEntry> reverseds = LdifRevertor.reverseRename(entry, newRdn, LdifRevertor.DELETE_OLD_RDN);
    assertNotNull(reverseds);
    assertEquals(1, reverseds.size());
    LdifEntry reversed = reverseds.get(0);
    assertEquals("sn=big+cn=test,ou=system", reversed.getDn().getName());
    assertEquals(ChangeType.ModRdn, reversed.getChangeType());
    assertFalse(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 34 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class LdifRevertorTest method test91ReverseRenameSimpleCompositeOverlappingDeleteOldRdnDontExistInEntry.

/**
 * Test a reversed rename ModifyDN, where the initial Rdn is simple,
 * the new Rdn is composite, they overlap, with deleteOldRdn = true, and
 * none of new values exists in the entry.
 *
 * Covers case 9.1 of http://cwiki.apache.org/confluence/display/DIRxSRVx11/Reverse+LDIF
 *
 * Initial entry
 * dn: cn=test,ou=system
 * objectclass: top
 * objectclass: person
 * cn: test
 * cn: big
 * sn: This is a test
 *
 * new Rdn : sn=small+cn=test
 *
 * @throws LdapException on error
 */
@Test
public void test91ReverseRenameSimpleCompositeOverlappingDeleteOldRdnDontExistInEntry() throws LdapException {
    Dn dn = new Dn("cn=test,ou=system");
    Rdn oldRdn = new Rdn("cn=test");
    Rdn newRdn = new Rdn("sn=small+cn=test");
    Entry entry = new DefaultEntry(dn, "objectClass: top", "objectClass: person", "cn: test", "cn: big", "sn: this is a test");
    List<LdifEntry> reverseds = LdifRevertor.reverseRename(entry, newRdn, LdifRevertor.DELETE_OLD_RDN);
    assertNotNull(reverseds);
    assertEquals(1, reverseds.size());
    LdifEntry reversed = reverseds.get(0);
    assertEquals("sn=small+cn=test,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 35 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class LdifRevertorTest method test12ReverseRenameSimpleSimpleNotOverlappingKeepOldRdnExistInEntry.

/**
 * Test a reversed rename ModifyDN, where the Rdn are both simple, not overlapping,
 * with deleteOldRdn = false, and with a Ava present in the initial entry.
 *
 * Covers case 1.2 of http://cwiki.apache.org/confluence/display/DIRxSRVx11/Reverse+LDIF
 *
 * Initial entry
 * dn: cn=test,ou=system
 * objectclass: top
 * objectclass: person
 * cn: test
 * cn: small
 * sn: This is a test
 *
 * new Rdn : cn=small
 *
 * @throws LdapException on error
 */
@Test
public void test12ReverseRenameSimpleSimpleNotOverlappingKeepOldRdnExistInEntry() throws LdapException {
    Dn dn = new Dn("cn=test,ou=system");
    Rdn oldRdn = new Rdn("cn=test");
    Rdn newRdn = new Rdn("cn=small");
    Entry entry = new DefaultEntry(dn, "objectClass: top", "objectClass: person", "cn: test", "cn: 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=small,ou=system", reversed.getDn().getName());
    assertEquals(ChangeType.ModRdn, reversed.getChangeType());
    assertFalse(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)

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