Search in sources :

Example 16 with DefaultEntry

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

the class SchemaAwareEntryTest method testContainsStringByteArray.

/**
 * Test method for contains( String, byte[]... )
 */
@Test
public void testContainsStringByteArray() throws LdapException {
    Entry entry = new DefaultEntry(exampleDn);
    assertFalse(entry.containsAttribute("objectClass"));
    Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, (byte[]) null, BYTES2);
    entry.add(attrPWD);
    assertTrue(entry.contains("  userPASSWORD  ", BYTES1, BYTES2));
    assertTrue(entry.contains("  userPASSWORD  ", (byte[]) null));
    // We can search for byte[] using Strings. the strings will be converted to byte[]
    assertTrue(entry.contains("  userPASSWORD  ", "ab", "b"));
    assertFalse(entry.contains("  userPASSWORD  ", "ab", "b", "d"));
}
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 17 with DefaultEntry

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

the class SchemaAwareEntryTest method testAddStringStringArray.

/**
 * Test method for add( String, String... )
 */
@Test
public void testAddStringStringArray() throws LdapException {
    Entry entry = new DefaultEntry();
    entry.add("cn", (String) null);
    assertEquals(1, entry.size());
    Attribute attributeCN = entry.get("cn");
    assertEquals(1, attributeCN.size());
    assertNotNull(attributeCN.get());
    assertNull(attributeCN.get().getValue());
    entry.add("sn", "test", "test", "TEST");
    assertEquals(2, entry.size());
    Attribute attributeSN = entry.get("sn");
    assertEquals(2, attributeSN.size());
    assertNotNull(attributeSN.get());
    assertTrue(attributeSN.contains("test"));
    assertTrue(attributeSN.contains("TEST"));
}
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 18 with DefaultEntry

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

the class SchemaAwareEntryTest method testDefaultClientEntryLdapDN.

/**
 * Test method for DefaultEntry( Dn )
 */
@Test
public void testDefaultClientEntryLdapDN() {
    Entry entry = new DefaultEntry(exampleDn);
    assertNotNull(entry);
    assertNotNull(entry.getDn());
    assertEquals(exampleDn, 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 19 with DefaultEntry

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

the class SchemaAwareEntryTest method testEqualsObject.

/**
 * Test method for equals()
 */
@Test
public void testEqualsObject() throws LdapException {
    Entry entry1 = new DefaultEntry();
    Entry entry2 = new DefaultEntry();
    assertEquals(entry1, entry2);
    entry1.setDn(exampleDn);
    assertNotSame(entry1, entry2);
    entry2.setDn(exampleDn);
    assertEquals(entry1, entry2);
    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);
    entry1.put(attrOC, attrCN, attrSN, attrPWD);
    entry2.put(attrOC, attrCN, attrSN);
    assertNotSame(entry1, entry2);
    entry2.put(attrPWD);
    assertEquals(entry1, entry2);
    Attribute attrL1 = new DefaultAttribute("l", "Paris", "New-York");
    Attribute attrL2 = new DefaultAttribute("l", "Paris", "Tokyo");
    entry1.put(attrL1);
    entry2.put(attrL1);
    assertEquals(entry1, entry2);
    entry1.add("l", "London");
    assertNotSame(entry1, entry2);
    entry2.add(attrL2);
    assertNotSame(entry1, entry2);
    entry1.clear();
    entry2.clear();
    assertEquals(entry1, entry2);
}
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 20 with DefaultEntry

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

the class SchemaAwareEntryTest method testAddStringValueArray.

/**
 * Test method for add( String, Value... )
 */
@Test
public void testAddStringValueArray() throws LdapException {
    Entry entry = new DefaultEntry();
    Value value = new Value((String) null);
    entry.add("cn", value);
    assertEquals(1, entry.size());
    Attribute attributeCN = entry.get("cn");
    assertEquals(1, attributeCN.size());
    assertNotNull(attributeCN.get());
    assertNull(attributeCN.get().getValue());
    Value value1 = new Value("test1");
    Value value2 = new Value("test2");
    Value value3 = new Value("test1");
    entry.add("sn", value1, value2, value3);
    assertEquals(2, entry.size());
    Attribute attributeSN = entry.get("sn");
    assertEquals(2, attributeSN.size());
    assertNotNull(attributeSN.get());
    assertTrue(attributeSN.contains(value1));
    assertTrue(attributeSN.contains(value2));
    Value value4 = new Value(BYTES1);
    entry.add("l", value1, value4);
    assertEquals(3, entry.size());
    Attribute attributeL = entry.get("l");
    assertEquals(2, attributeL.size());
    assertNotNull(attributeL.get());
    assertTrue(attributeL.contains(value1));
    // The byte[] value must have been transformed to a String
    assertTrue(attributeL.contains("ab"));
}
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) Value(org.apache.directory.api.ldap.model.entry.Value) 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