Search in sources :

Example 51 with DefaultAttribute

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

the class SchemaAwareEntryTest method testAddEntryAttributeArray.

/**
 * Test method for add( EntryAttribute... )
 */
@Test
public void testAddEntryAttributeArray() throws LdapException {
    Entry entry = createEntry();
    assertEquals(4, entry.size());
    assertTrue(entry.containsAttribute("ObjectClass"));
    assertTrue(entry.containsAttribute("CN"));
    assertTrue(entry.containsAttribute("  sn  "));
    assertTrue(entry.containsAttribute("userPassword"));
    Attribute attr = entry.get("objectclass");
    assertEquals(2, attr.size());
    Attribute attrCN2 = new DefaultAttribute("cn", "test1", "test3");
    entry.add(attrCN2);
    assertEquals(4, entry.size());
    attr = entry.get("cn");
    assertEquals(3, attr.size());
    assertTrue(attr.contains("test1", "test2", "test3"));
    // Check adding some byte[] values (they will not be transformed to Strings)
    attrCN2.clear();
    attrCN2.add(BYTES1, BYTES2);
    entry.add(attrCN2);
    assertEquals(4, entry.size());
    attr = entry.get("cn");
    assertEquals(3, attr.size());
    assertTrue(attr.contains("test1", "test2", "test3"));
    assertFalse(attr.contains("ab", "b"));
}
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) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 52 with DefaultAttribute

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

the class SchemaAwareEntryTest method testRemoveStringValueArray.

/**
 * Test method for remove(String, Value... )
 */
@Test
public void testRemoveStringValueArray() throws LdapException {
    Entry entry = new DefaultEntry(exampleDn);
    Attribute attrCN = new DefaultAttribute("cn", "test1", "test2", (String) null);
    Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, BYTES2, (byte[]) null);
    entry.add(attrCN, attrPWD);
    Value strValue1 = new Value("test1");
    Value strValue2 = new Value("test2");
    Value strValue3 = new Value("test3");
    Value strNullValue = new Value((String) null);
    Value binValue1 = new Value(BYTES1);
    Value binValue2 = new Value(BYTES2);
    Value binValue3 = new Value(BYTES3);
    Value binNullValue = new Value((byte[]) null);
    assertTrue(entry.remove("cn", strValue1, strNullValue));
    assertTrue(entry.contains("cn", strValue2));
    assertFalse(entry.remove("cn", strValue3));
    assertTrue(entry.remove("cn", strValue2));
    assertFalse(entry.containsAttribute("cn"));
    entry.add(attrCN, attrPWD);
    assertTrue(entry.remove("userpassword", binValue1, binNullValue));
    assertTrue(entry.contains("userpassword", binValue2));
    assertFalse(entry.remove("userpassword", binValue3));
    assertTrue(entry.remove("userpassword", binValue2));
    assertFalse(entry.containsAttribute("userpassword"));
}
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) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 53 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute 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 54 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute 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 55 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute 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)

Aggregations

DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)159 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)131 Test (org.junit.Test)106 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)41 Modification (org.apache.directory.api.ldap.model.entry.Modification)40 Entry (org.apache.directory.api.ldap.model.entry.Entry)36 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)35 Value (org.apache.directory.api.ldap.model.entry.Value)20 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ObjectInputStream (java.io.ObjectInputStream)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ObjectOutputStream (java.io.ObjectOutputStream)12 Dn (org.apache.directory.api.ldap.model.name.Dn)12 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)11 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)11 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)8 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)7 ModifyRequestImpl (org.apache.directory.api.ldap.model.message.ModifyRequestImpl)7 ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)7 HashSet (java.util.HashSet)6