use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testAddOneValue.
@Test
public void testAddOneValue() throws Exception {
AttributeType at = TestEntryUtils.getIA5StringAttributeType();
DefaultAttribute attr = new DefaultAttribute(at);
// Add a String value
attr.add("test");
assertEquals(1, attr.size());
assertTrue(attr.getAttributeType().getSyntax().isHumanReadable());
Value value = attr.get();
assertTrue(value instanceof Value);
assertEquals("test", ((Value) value).getValue());
// Add a binary value
assertEquals(0, attr.add(new byte[] { 0x01 }));
// Add a Value
Value ssv = new Value(at, "test2");
attr.add(ssv);
assertEquals(2, attr.size());
Set<String> expected = new HashSet<String>();
expected.add("test");
expected.add("test2");
for (Value val : attr) {
if (expected.contains(val.getValue())) {
expected.remove(val.getValue());
} else {
fail();
}
}
assertEquals(0, expected.size());
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testDefaultServerAttributeStringAttributeTypeValueArray.
/**
* Test constructor DefaultEntryAttribute( String, AttributeType, Value... )
*/
@Test
public void testDefaultServerAttributeStringAttributeTypeValueArray() throws LdapException {
Attribute attr1 = new DefaultAttribute("dc", atDC, stringValue1, stringValue2, nullStringValue);
assertTrue(attr1.isHumanReadable());
assertEquals(3, attr1.size());
assertEquals("0.9.2342.19200300.100.1.25", attr1.getId());
assertEquals("dc", attr1.getUpId());
assertEquals(atDC, attr1.getAttributeType());
assertTrue(attr1.contains("a", "b"));
assertTrue(attr1.contains(nullStringValue));
Attribute attr2 = new DefaultAttribute(atDC, stringValue1, binaryValue2, nullStringValue);
assertTrue(attr2.isHumanReadable());
assertEquals(2, attr2.size());
assertEquals("0.9.2342.19200300.100.1.25", attr2.getId());
assertEquals("dc", attr2.getUpId());
assertEquals(atDC, attr2.getAttributeType());
assertTrue(attr2.contains("a"));
assertTrue(attr2.contains(nullStringValue));
Attribute attr3 = new DefaultAttribute("DomainComponent", atDC, stringValue1, stringValue2, nullStringValue);
assertTrue(attr3.isHumanReadable());
assertEquals(3, attr3.size());
assertEquals("0.9.2342.19200300.100.1.25", attr3.getId());
assertEquals("DomainComponent", attr3.getUpId());
assertEquals(atDC, attr3.getAttributeType());
assertTrue(attr3.contains("a", "b"));
assertTrue(attr3.contains(nullStringValue));
Attribute attr4 = new DefaultAttribute(" 0.9.2342.19200300.100.1.25 ", atDC, stringValue1, stringValue2, nullStringValue);
assertTrue(attr4.isHumanReadable());
assertEquals(3, attr4.size());
assertEquals("0.9.2342.19200300.100.1.25", attr4.getId());
assertEquals(" 0.9.2342.19200300.100.1.25 ", attr4.getUpId());
assertEquals(atDC, attr4.getAttributeType());
assertTrue(attr4.contains("a", "b"));
assertTrue(attr4.contains(nullStringValue));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testSerializeAttributeNullValue.
/**
* Test the serialization of a server attribute with a null value
*/
@Test
public void testSerializeAttributeNullValue() throws LdapException, IOException, ClassNotFoundException {
DefaultAttribute dsa = new DefaultAttribute(atDC);
dsa.setUpId("DomainComponent");
dsa.add((String) null);
DefaultAttribute dsaSer = deserializeValue(serializeValue(dsa), atDC);
assertEquals(dsa.toString(), dsaSer.toString());
assertEquals("0.9.2342.19200300.100.1.25", dsaSer.getId());
assertEquals("DomainComponent", dsaSer.getUpId());
assertNull(dsaSer.getString());
assertEquals(1, dsaSer.size());
assertTrue(dsaSer.contains((String) null));
assertTrue(dsaSer.isHumanReadable());
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testSerializeAttributeWithNoValue.
/**
* Test the serialization of a server attribute with no value
*/
@Test
public void testSerializeAttributeWithNoValue() throws LdapException, IOException, ClassNotFoundException {
DefaultAttribute dsa = new DefaultAttribute(atCN);
dsa.setUpId("cn");
DefaultAttribute dsaSer = deserializeValue(serializeValue(dsa), atCN);
assertEquals(dsa.toString(), dsaSer.toString());
assertEquals("2.5.4.3", dsaSer.getId());
assertEquals("cn", dsaSer.getUpId());
assertEquals(0, dsaSer.size());
assertTrue(dsaSer.isHumanReadable());
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testDefaultServerAttributeStringAttributeTypeByteArray.
/**
* Test method DefaultEntryAttribute( String, AttributeType, byte[]... )
*/
@Test
public void testDefaultServerAttributeStringAttributeTypeByteArray() throws LdapException {
Attribute attr1 = new DefaultAttribute("userPassword", 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("2.5.4.35", atPwd, stringValue1, binaryValue2, nullBinaryValue);
assertFalse(attr2.isHumanReadable());
assertEquals(2, attr2.size());
assertEquals("2.5.4.35", attr2.getId());
assertEquals("2.5.4.35", attr2.getUpId());
assertEquals(atPwd, attr2.getAttributeType());
assertTrue(attr2.contains(BYTES2));
assertTrue(attr2.contains(nullBinaryValue));
}
Aggregations