Search in sources :

Example 41 with DefaultEntry

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());
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) 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 42 with DefaultEntry

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"));
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 43 with DefaultEntry

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());
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 44 with DefaultEntry

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"));
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 45 with DefaultEntry

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());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Value(org.apache.directory.api.ldap.model.entry.Value) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Aggregations

DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)128 Entry (org.apache.directory.api.ldap.model.entry.Entry)116 Test (org.junit.Test)55 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)41 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)39 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)20 Modification (org.apache.directory.api.ldap.model.entry.Modification)16 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)16 Dn (org.apache.directory.api.ldap.model.name.Dn)15 CreateException (org.apache.directory.fortress.core.CreateException)15 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)14 Value (org.apache.directory.api.ldap.model.entry.Value)12 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)12 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)5 IOException (java.io.IOException)4 ObjectInputStream (java.io.ObjectInputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4