use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testGetString.
/**
* Test method getString()
*/
@Test
public void testGetString() throws LdapInvalidAttributeValueException {
Attribute attr1 = new DefaultAttribute(atDC);
assertEquals(1, attr1.add((String) null));
Attribute attr2 = new DefaultAttribute(atDC);
attr2.add("a");
assertEquals("a", attr2.getString());
Attribute attr3 = new DefaultAttribute(atPwd);
attr3.add(BYTES1, BYTES2);
try {
attr3.getString();
fail();
} catch (LdapInvalidAttributeValueException ivae) {
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testSetUpIdStringAttributeType.
/**
* Test method setUpId( String, AttributeType )
*/
@Test
public void testSetUpIdStringAttributeType() throws Exception {
Attribute attr = new DefaultAttribute(atSN);
attr.setUpId(null, atCN);
assertEquals("2.5.4.3", attr.getId());
assertEquals("cn", attr.getUpId());
assertEquals(atCN, attr.getAttributeType());
attr.setUpId(" ", atCN);
assertEquals("2.5.4.3", attr.getId());
assertEquals("cn", attr.getUpId());
assertEquals(atCN, attr.getAttributeType());
attr.setUpId(" CN ", atCN);
assertEquals("2.5.4.3", attr.getId());
assertEquals(" CN ", attr.getUpId());
assertEquals(atCN, attr.getAttributeType());
attr.setUpId(" CommonName ", atCN);
assertEquals("2.5.4.3", attr.getId());
assertEquals(" CommonName ", attr.getUpId());
assertEquals(atCN, attr.getAttributeType());
attr.setUpId(" 2.5.4.3 ", atCN);
assertEquals("2.5.4.3", attr.getId());
assertEquals(" 2.5.4.3 ", attr.getUpId());
assertEquals(atCN, attr.getAttributeType());
// Check with wrong IDs
try {
attr.setUpId("sn", atCN);
fail();
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
try {
attr.setUpId(" 2.5.4.4 ", atCN);
fail();
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.model.entry.Attribute 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());
}
use of org.apache.directory.api.ldap.model.entry.Attribute 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));
}
use of org.apache.directory.api.ldap.model.entry.Attribute 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());
}
}
Aggregations