Search in sources :

Example 31 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testRemoveStringByteArrayArray.

/**
 * Test method for remove(String, byte[]... )
 */
@Test
public void testRemoveStringByteArrayArray() throws LdapException {
    Entry entry = new DefaultEntry(exampleDn);
    Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, (byte[]) null, BYTES2);
    entry.put(attrPWD);
    assertTrue(entry.remove("userPassword", (byte[]) null));
    assertTrue(entry.remove("userPassword", BYTES1, BYTES2));
    assertFalse(entry.containsAttribute("userPassword"));
    entry.add("userPassword", BYTES1, (byte[]) null, BYTES2);
    assertTrue(entry.remove("userPassword", (byte[]) null));
    assertEquals(2, entry.get("userPassword").size());
    assertTrue(entry.remove("userPassword", BYTES1, BYTES3));
    assertEquals(1, entry.get("userPassword").size());
    assertTrue(Arrays.equals(BYTES2, entry.get("userPassword").getBytes()));
    assertFalse(entry.remove("userPassword", BYTES3));
    assertFalse(entry.remove("void", "whatever"));
}
Also used : 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) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 32 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testPutStringStringArray.

/**
 * Test method for put( String, String... )
 */
@Test
public void testPutStringStringArray() {
    Entry entry = new DefaultEntry(exampleDn);
    try {
        entry.put((String) null, "a");
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(true);
    }
    try {
        entry.put("   ", "a");
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(true);
    }
    entry.put("sn", (String) null);
    assertEquals(1, entry.size());
    assertNotNull("sn", entry.get("sn"));
    assertEquals(1, entry.get("sn").size());
    assertNull(entry.get("sn").get().getValue());
    entry.put("ObjectClass", "top", "person", "top");
    assertEquals(2, entry.size());
    assertNotNull("objectclass", entry.get("sn"));
    assertEquals(2, entry.get("OBJECTCLASS").size());
    Attribute attribute = entry.get("objectClass");
    assertTrue(attribute.contains("top"));
    assertTrue(attribute.contains("person"));
    assertEquals("objectclass", attribute.getId());
    assertEquals("ObjectClass", attribute.getUpId());
}
Also used : 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) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Test(org.junit.Test)

Example 33 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testSerializeEntryWithNoDNNoAttribute.

/**
 * Test the serialization of an entry with no attribute and no Dn
 */
@Test
public void testSerializeEntryWithNoDNNoAttribute() throws LdapException, IOException, ClassNotFoundException {
    Entry entry = new DefaultEntry();
    Entry entrySer = deserializeValue(serializeValue(entry));
    assertEquals(entry, entrySer);
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Test(org.junit.Test)

Example 34 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testGetDn.

/**
 * Test method for getDN()
 */
@Test
public void testGetDn() throws LdapException {
    Entry entry = new DefaultEntry(exampleDn);
    assertEquals(exampleDn, entry.getDn());
    Dn testDn = new Dn("cn=test");
    entry.setDn(testDn);
    assertEquals(testDn, entry.getDn());
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) Test(org.junit.Test)

Example 35 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testClone.

/**
 * Test method for clone()
 */
@Test
public void testClone() throws LdapException {
    Entry entry1 = new DefaultEntry();
    Entry entry2 = entry1.clone();
    assertEquals(entry1, entry2);
    entry2.setDn(exampleDn);
    assertEquals(Dn.EMPTY_DN, entry1.getDn());
    entry1.setDn(exampleDn);
    entry2 = entry1.clone();
    assertEquals(entry1, entry2);
    entry1.add("objectClass", "top", "person");
    entry1.add("cn", "test1", "test2");
    entry2 = entry1.clone();
    assertEquals(entry1, entry2);
    entry1.add("cn", "test3");
    assertEquals(2, entry2.get("cn").size());
    assertFalse(entry2.contains("cn", "test3"));
    entry1.add("sn", (String) null);
    assertFalse(entry2.containsAttribute("sn"));
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) 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