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);
}
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));
}
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());
}
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));
}
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());
}
Aggregations