Search in sources :

Example 26 with DefaultEntry

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

the class SchemaAwareEntryTest method createEntry.

/**
 * Helper method which creates an entry with 4 attributes.
 */
private Entry createEntry() {
    try {
        Entry entry = new DefaultEntry(exampleDn);
        Attribute attrOC = new DefaultAttribute("objectClass", "top", "person");
        Attribute attrCN = new DefaultAttribute("cn", "test1", "test2");
        Attribute attrSN = new DefaultAttribute("sn", "Test1", "Test2");
        Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, BYTES2);
        entry.put(attrOC, attrCN, attrSN, attrPWD);
        return entry;
    } catch (LdapException ne) {
        // Do nothing
        return null;
    }
}
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) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 27 with DefaultEntry

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

the class SchemaAwareEntryTest method testHasObjectClass.

/**
 * Test method for hasObjectClass( String )
 */
@Test
public void testHasObjectClass() throws LdapException {
    Entry entry = new DefaultEntry(exampleDn);
    assertFalse(entry.containsAttribute("objectClass"));
    assertFalse(entry.hasObjectClass("top"));
    entry.add(new DefaultAttribute("objectClass", "top", "person"));
    assertTrue(entry.hasObjectClass("top"));
    assertTrue(entry.hasObjectClass("person"));
    assertFalse(entry.hasObjectClass("inetorgperson"));
    assertFalse(entry.hasObjectClass((String) null));
    assertFalse(entry.hasObjectClass(""));
}
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) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 28 with DefaultEntry

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

the class SchemaAwareEntryTest method testDefaultClientEntry.

/**
 * Test method for DefaultEntry()
 */
@Test
public void testDefaultClientEntry() {
    Entry entry = new DefaultEntry();
    assertNotNull(entry);
    assertEquals(Dn.EMPTY_DN, entry.getDn());
    assertEquals(0, entry.size());
}
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 29 with DefaultEntry

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

the class SchemaAwareEntryTest method testContainsStringStringArray.

/**
 * Test method for contains( String, String... )
 */
@Test
public void testContainsStringStringArray() throws LdapException {
    Entry entry = new DefaultEntry(exampleDn);
    assertFalse(entry.containsAttribute("objectClass"));
    Attribute attrOC = new DefaultAttribute("objectClass", "top", "person");
    Attribute attrCN = new DefaultAttribute("cn", "test1", "test2");
    Attribute attrSN = new DefaultAttribute("sn", "Test1", "Test2", (String) null);
    Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, BYTES2);
    entry.add(attrOC, attrCN, attrSN, attrPWD);
    assertTrue(entry.contains("OBJECTCLASS", "top", "person"));
    assertTrue(entry.contains(" cn ", "test1", "test2"));
    assertTrue(entry.contains("Sn", "Test1", "Test2", (String) null));
    assertTrue(entry.contains("  userPASSWORD  ", "ab", "b"));
    assertFalse(entry.contains("OBJECTCLASS", "PERSON"));
    assertFalse(entry.contains(" cn ", "test1", "test3"));
    assertFalse(entry.contains("Sn", "Test"));
    assertFalse(entry.contains("  userPASSWORD  ", (String) null));
}
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 30 with DefaultEntry

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

the class SchemaAwareEntryTest method testSerializeEntryWithNoDN.

/**
 * Test the serialization of an entry with no Dn
 */
@Test
public void testSerializeEntryWithNoDN() throws LdapException, IOException, ClassNotFoundException {
    byte[] password = Strings.getBytesUtf8("secret");
    Entry entry = new DefaultEntry();
    entry.add("ObjectClass", "top", "person");
    entry.add("cn", "test1");
    entry.add("userPassword", password);
    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)

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