Search in sources :

Example 36 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testClear.

/**
 * Test method clear()
 */
@Test
public void testClear() throws LdapException {
    Attribute attr = new DefaultAttribute("email", atEMail);
    assertEquals(0, attr.size());
    attr.add((String) null, "a", "b");
    assertEquals(3, attr.size());
    attr.clear();
    assertTrue(attr.isHumanReadable());
    assertEquals(0, attr.size());
    assertEquals(atEMail, attr.getAttributeType());
}
Also used : 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 37 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testDefaultServerAttributeAttributeTypeStringArray.

/**
 * Test constructor DefaultEntryAttribute( AttributeType, String... )
 */
@Test
public void testDefaultServerAttributeAttributeTypeStringArray() throws LdapException {
    Attribute attr1 = new DefaultAttribute(atEMail, "a", "b", (String) null);
    assertTrue(attr1.isHumanReadable());
    assertEquals(3, attr1.size());
    assertEquals("1.2.840.113549.1.9.1", attr1.getId());
    assertEquals("email", attr1.getUpId());
    assertEquals(atEMail, attr1.getAttributeType());
    assertTrue(attr1.contains("a", "b"));
    assertTrue(attr1.contains(nullStringValue));
    Attribute attr2 = new DefaultAttribute(atEMail, stringValue1, binaryValue2, nullStringValue);
    assertTrue(attr2.isHumanReadable());
    assertEquals(2, attr2.size());
    assertEquals("1.2.840.113549.1.9.1", attr2.getId());
    assertEquals("email", attr2.getUpId());
    assertEquals(atEMail, attr2.getAttributeType());
    assertTrue(attr2.contains("a"));
    assertTrue(attr2.contains(nullStringValue));
}
Also used : 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 38 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testIterator.

/**
 * Test method iterator()
 */
@Test
public void testIterator() throws LdapException {
    Attribute attr1 = new DefaultAttribute(atCN);
    attr1.add("a", "b", "c");
    Iterator<Value> iter = attr1.iterator();
    assertTrue(iter.hasNext());
    String[] values = new String[] { "a", "b", "c" };
    int pos = 0;
    for (Value val : attr1) {
        assertTrue(val instanceof Value);
        assertEquals(values[pos++], val.getValue());
    }
}
Also used : 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) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 39 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testRemoveValueArray.

/**
 * Test method remove( Value... )
 */
@Test
public void testRemoveValueArray() throws Exception {
    Attribute attr1 = new DefaultAttribute(atEMail);
    assertFalse(attr1.remove(stringValue1));
    attr1.add("a", "b", "c");
    assertTrue(attr1.remove(stringValue1));
    assertEquals(2, attr1.size());
    assertTrue(attr1.remove(stringValue2, stringValue3));
    assertEquals(0, attr1.size());
    assertFalse(attr1.remove(stringValue4));
    attr1.clear();
    attr1.add("a", "b", "c");
    assertFalse(attr1.remove(stringValue2, stringValue4));
    assertEquals(2, attr1.size());
    attr1.clear();
    attr1.add("a", (String) null, "b");
    assertTrue(attr1.remove(nullStringValue, stringValue1));
    assertEquals(1, attr1.size());
    attr1.clear();
    attr1.add("a", (String) null, "b");
    attr1.add(BYTES3);
    assertFalse(attr1.remove(nullStringValue, stringValue1, binaryValue3));
    assertEquals(1, attr1.size());
    Attribute attr2 = new DefaultAttribute(atPwd);
    assertFalse(attr2.remove(binaryValue1));
    attr2.add(BYTES1, BYTES2, BYTES3);
    assertTrue(attr2.remove(binaryValue1));
    assertEquals(2, attr2.size());
    assertTrue(attr2.remove(binaryValue2, binaryValue3));
    assertEquals(0, attr2.size());
    assertFalse(attr2.remove(binaryValue4));
    attr2.clear();
    attr2.add(BYTES1, BYTES2, BYTES3);
    assertFalse(attr2.remove(binaryValue2, stringValue4));
    assertEquals(2, attr2.size());
    attr2.clear();
    attr2.add(BYTES1, (byte[]) null, BYTES3);
    assertFalse(attr2.remove(nullStringValue, binaryValue1));
    assertEquals(2, attr2.size());
    attr2.clear();
    attr2.add(BYTES1, (byte[]) null, BYTES2);
    attr2.add("c");
    assertEquals(4, attr2.size());
    assertFalse(attr2.remove(nullStringValue, binaryValue1, stringValue3));
    assertEquals(3, attr2.size());
}
Also used : 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 40 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testAddByteArray.

/**
 * Test method add( byte[]... )
 */
@Test
public void testAddByteArray() throws LdapInvalidAttributeValueException {
    Attribute attr1 = new DefaultAttribute(atPwd);
    int nbAdded = attr1.add((byte[]) null);
    assertEquals(1, nbAdded);
    assertFalse(attr1.isHumanReadable());
    assertTrue(Arrays.equals(nullBinaryValue.getBytes(), attr1.getBytes()));
    Attribute attr2 = new DefaultAttribute(atPwd);
    nbAdded = attr2.add(Strings.EMPTY_BYTES);
    assertEquals(1, nbAdded);
    assertFalse(attr2.isHumanReadable());
    assertTrue(Arrays.equals(Strings.EMPTY_BYTES, attr2.getBytes()));
    Attribute attr3 = new DefaultAttribute(atPwd);
    nbAdded = attr3.add(BYTES1);
    assertEquals(1, nbAdded);
    assertFalse(attr3.isHumanReadable());
    assertTrue(Arrays.equals(BYTES1, attr3.getBytes()));
    Attribute attr4 = new DefaultAttribute(atPwd);
    nbAdded = attr4.add(BYTES1, BYTES2, BYTES3, BYTES4);
    assertEquals(4, nbAdded);
    assertFalse(attr4.isHumanReadable());
    assertTrue(attr4.contains(BYTES1));
    assertTrue(attr4.contains(BYTES2));
    assertTrue(attr4.contains(BYTES3));
    assertTrue(attr4.contains(BYTES4));
    Attribute attr5 = new DefaultAttribute(atPwd);
    nbAdded = attr5.add(BYTES1, BYTES2, (byte[]) null, BYTES3);
    assertEquals(4, nbAdded);
    assertFalse(attr5.isHumanReadable());
    assertTrue(attr5.contains(BYTES1));
    assertTrue(attr5.contains(BYTES2));
    assertTrue(attr5.contains((byte[]) null));
    assertTrue(attr5.contains(BYTES3));
    Attribute attr6 = new DefaultAttribute(atPwd);
    nbAdded = attr6.add("ab", (String) null);
    assertEquals(2, nbAdded);
    assertFalse(attr6.isHumanReadable());
}
Also used : 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)

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