Search in sources :

Example 46 with Attribute

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

the class SchemaAwareAttributeSerializationTest method testEntryAttributeNoValueSerialization.

@Test
public void testEntryAttributeNoValueSerialization() throws IOException, ClassNotFoundException, LdapInvalidAttributeValueException {
    Attribute attribute1 = new DefaultAttribute(cn);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    attribute1.writeExternal(out);
    ObjectInputStream in = null;
    byte[] data = baos.toByteArray();
    in = new ObjectInputStream(new ByteArrayInputStream(data));
    Attribute attribute2 = new DefaultAttribute(cn);
    attribute2.readExternal(in);
    attribute2.apply(cn);
    assertEquals(attribute1, attribute2);
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 47 with Attribute

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

the class SchemaAwareAttributeTest method testDefaultServerAttributeAttributeTypeByteArray.

/**
 * Test method DefaultEntryAttribute( AttributeType, byte[]... )
 */
@Test
public void testDefaultServerAttributeAttributeTypeByteArray() throws LdapException {
    Attribute attr1 = new DefaultAttribute(atPwd, BYTES1, BYTES2, (byte[]) null);
    assertFalse(attr1.isHumanReadable());
    assertEquals(3, attr1.size());
    assertEquals("2.5.4.35", attr1.getId());
    assertEquals("userPassword", attr1.getUpId());
    assertEquals(atPwd, attr1.getAttributeType());
    assertTrue(attr1.contains(BYTES1, BYTES2));
    assertTrue(attr1.contains(nullBinaryValue));
    Attribute attr2 = new DefaultAttribute(atPwd, stringValue1, binaryValue2, nullBinaryValue);
    assertFalse(attr2.isHumanReadable());
    assertEquals(2, attr2.size());
    assertEquals("2.5.4.35", attr2.getId());
    assertEquals("userPassword", attr2.getUpId());
    assertEquals(atPwd, attr2.getAttributeType());
    assertTrue(attr2.contains(BYTES2));
    assertTrue(attr2.contains(nullBinaryValue));
}
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 48 with Attribute

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

the class SchemaAwareAttributeTest method testToString.

/**
 * Test method toString
 */
@Test
public void testToString() throws LdapException {
    Attribute attr = new DefaultAttribute(atEMail);
    assertEquals("email: (null)", attr.toString());
    attr.setUpId("EMail");
    assertEquals("EMail: (null)", attr.toString());
    attr.add((String) null);
    assertEquals("EMail: ''", attr.toString());
    attr.clear();
    attr.add("a", "b");
    assertEquals("EMail: a\nEMail: b", attr.toString());
}
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 49 with Attribute

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

the class SchemaAwareAttributeTest method testContainsByteArray.

/**
 * Test method contains( byte[]... )
 */
@Test
public void testContainsByteArray() throws LdapException {
    Attribute attr1 = new DefaultAttribute(atPwd);
    assertEquals(0, attr1.size());
    assertFalse(attr1.contains(BYTES1));
    assertFalse(attr1.contains((byte[]) null));
    attr1.add((byte[]) null);
    assertEquals(1, attr1.size());
    assertTrue(attr1.contains((byte[]) null));
    attr1.remove((byte[]) null);
    assertFalse(attr1.contains((byte[]) null));
    assertEquals(0, attr1.size());
    attr1.add(BYTES1, BYTES2, BYTES3);
    assertEquals(3, attr1.size());
    assertTrue(attr1.contains(BYTES1));
    assertTrue(attr1.contains(BYTES2));
    assertTrue(attr1.contains(BYTES3));
    assertFalse(attr1.contains(BYTES4));
    assertFalse(attr1.contains((byte[]) null));
}
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 50 with Attribute

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

the class SchemaAwareAttributeTest method testIterator2.

/**
 * Test method getAll()
 */
@Test
public void testIterator2() throws LdapException {
    Attribute attr = new DefaultAttribute(atEMail);
    Iterator<Value> iterator = attr.iterator();
    assertFalse(iterator.hasNext());
    attr.add(nullStringValue);
    iterator = attr.iterator();
    assertTrue(iterator.hasNext());
    Value value = iterator.next();
    assertEquals(nullStringValue, value);
    attr.clear();
    iterator = attr.iterator();
    assertFalse(iterator.hasNext());
    attr.add("a", "b", "c");
    iterator = attr.iterator();
    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next().getValue());
    assertEquals("b", iterator.next().getValue());
    assertEquals("c", iterator.next().getValue());
    assertFalse(iterator.hasNext());
}
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)

Aggregations

Attribute (org.apache.directory.api.ldap.model.entry.Attribute)269 Test (org.junit.Test)180 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)168 Entry (org.apache.directory.api.ldap.model.entry.Entry)94 Modification (org.apache.directory.api.ldap.model.entry.Modification)56 Value (org.apache.directory.api.ldap.model.entry.Value)52 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)46 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)35 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 EncoderException (org.apache.directory.api.asn1.EncoderException)20 ByteBuffer (java.nio.ByteBuffer)18 DecoderException (org.apache.directory.api.asn1.DecoderException)18 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)18 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)18 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)18 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)18 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)16 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)16 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13