Search in sources :

Example 16 with DefaultAttribute

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

the class SchemaAwareAttributeSerializationTest method testEntryAttributeManyBinaryValuesSerialization.

@Test
public void testEntryAttributeManyBinaryValuesSerialization() throws IOException, ClassNotFoundException, LdapInvalidAttributeValueException {
    Attribute attribute1 = new DefaultAttribute("UserCertificate", userCertificate, data1, data2, data3);
    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(userCertificate);
    attribute2.readExternal(in);
    attribute2.apply(userCertificate);
    assertEquals(attribute1, attribute2);
    assertEquals("UserCertificate", attribute2.getUpId());
}
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 17 with DefaultAttribute

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

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

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

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

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