use of org.apache.directory.api.ldap.model.entry.DefaultAttribute 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());
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testEquals.
/**
* Test method testEquals()
*/
@Test
public void testEquals() throws LdapException {
Attribute attr1 = new DefaultAttribute(atCN);
assertFalse(attr1.equals(null));
Attribute attr2 = new DefaultAttribute(atCN);
assertTrue(attr1.equals(attr2));
attr2.setUpId("CN");
assertTrue(attr1.equals(attr2));
attr1.setUpId("CommonName");
assertTrue(attr1.equals(attr2));
attr1.setUpId("CN");
assertTrue(attr1.equals(attr2));
attr1.add("a", "b", "c");
attr2.add("c", "b", "a");
assertTrue(attr1.equals(attr2));
assertTrue(attr1.equals(attr2));
Attribute attr3 = new DefaultAttribute(atPwd);
Attribute attr4 = new DefaultAttribute(atPwd);
attr3.add(nullBinaryValue);
attr4.add(nullBinaryValue);
assertTrue(attr3.equals(attr4));
Attribute attr5 = new DefaultAttribute(atPwd);
Attribute attr6 = new DefaultAttribute(atDC);
assertFalse(attr5.equals(attr6));
attr5.add(nullBinaryValue);
attr6.add(nullStringValue);
assertFalse(attr5.equals(attr6));
Attribute attr7 = new DefaultAttribute(atCN);
Attribute attr8 = new DefaultAttribute(atPwd);
attr7.add("a");
attr8.add(BYTES2);
assertFalse(attr7.equals(attr8));
Attribute attr9 = new DefaultAttribute(atCN);
Attribute attr10 = new DefaultAttribute(atPwd);
attr9.add("a");
attr9.add(BYTES2);
attr10.add("a", "b");
assertFalse(attr9.equals(attr10));
Attribute attr11 = new DefaultAttribute(atPwd, BYTES1);
Attribute attr12 = new DefaultAttribute(atPwd, BYTES1);
assertTrue(attr11.get().equals(attr12.get()));
assertTrue(attr12.get().equals(attr11.get()));
Attribute attr13 = new DefaultAttribute("userPassword", BYTES1);
assertTrue(attr11.get().equals(attr13.get()));
assertTrue(attr13.get().equals(attr11.get()));
Attribute attr14 = new DefaultAttribute("userPassword", BYTES1);
assertTrue(attr14.get().equals(attr13.get()));
assertTrue(attr13.get().equals(attr14.get()));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testDefaultServerAttributeStringAttributeTypeStringArray.
/**
* Test constructor DefaultEntryAttribute( String, AttributeType, String... )
*/
@Test
public void testDefaultServerAttributeStringAttributeTypeStringArray() throws LdapException {
Attribute attr1 = new DefaultAttribute("email", 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("EMail", atEMail, "a", "b", (String) null);
assertTrue(attr2.isHumanReadable());
assertEquals(3, attr2.size());
assertEquals("1.2.840.113549.1.9.1", attr2.getId());
assertEquals("EMail", attr2.getUpId());
assertEquals(atEMail, attr2.getAttributeType());
assertTrue(attr2.contains("a", "b"));
assertTrue(attr2.contains(nullStringValue));
Attribute attr3 = new DefaultAttribute(" 1.2.840.113549.1.9.1 ", atEMail, "a", "b", (String) null);
assertTrue(attr3.isHumanReadable());
assertEquals(3, attr3.size());
assertEquals("1.2.840.113549.1.9.1", attr3.getId());
assertEquals(" 1.2.840.113549.1.9.1 ", attr3.getUpId());
assertEquals(atEMail, attr3.getAttributeType());
assertTrue(attr3.contains("a", "b"));
assertTrue(attr3.contains(nullStringValue));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testSetAttributeType.
/**
* Test method setAttributeType( AttributeType )
*/
@Test
public void testSetAttributeType() throws Exception {
Attribute attr = new DefaultAttribute(atCN);
try {
attr.apply(null);
fail();
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
attr.apply(atSN);
assertTrue(attr.isInstanceOf(atSN));
assertEquals("2.5.4.4", attr.getId());
assertEquals("sn", attr.getUpId());
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testPutStringArray.
/**
* Test method put( String... )
*/
@Test
public void testPutStringArray() throws LdapInvalidAttributeValueException {
Attribute attr1 = new DefaultAttribute(atDC);
int nbAdded = attr1.add((String) null);
assertEquals(1, nbAdded);
assertTrue(attr1.isHumanReadable());
assertEquals(nullStringValue, attr1.get());
Attribute attr2 = new DefaultAttribute(atDC);
nbAdded = attr2.add("");
assertEquals(1, nbAdded);
assertTrue(attr2.isHumanReadable());
assertEquals("", attr2.getString());
Attribute attr3 = new DefaultAttribute(atDC);
nbAdded = attr3.add("t");
assertEquals(1, nbAdded);
assertTrue(attr3.isHumanReadable());
assertEquals("t", attr3.getString());
Attribute attr4 = new DefaultAttribute(atEMail);
nbAdded = attr4.add("a", "b", "c", "d");
assertEquals(4, nbAdded);
assertTrue(attr4.isHumanReadable());
assertEquals("a", attr4.getString());
assertTrue(attr4.contains("a"));
assertTrue(attr4.contains("b"));
assertTrue(attr4.contains("c"));
assertTrue(attr4.contains("d"));
attr4.clear();
nbAdded = attr4.add("e");
assertEquals(1, nbAdded);
assertTrue(attr4.isHumanReadable());
assertEquals("e", attr4.getString());
assertFalse(attr4.contains("a"));
assertFalse(attr4.contains("b"));
assertFalse(attr4.contains("c"));
assertFalse(attr4.contains("d"));
assertTrue(attr4.contains("e"));
attr4.clear();
nbAdded = attr4.add(BYTES1);
assertEquals(0, nbAdded);
assertTrue(attr4.isHumanReadable());
Attribute attr5 = new DefaultAttribute(atEMail);
nbAdded = attr5.add("a", "b", (String) null, "d");
assertEquals(4, nbAdded);
assertTrue(attr5.isHumanReadable());
assertTrue(attr5.contains("a"));
assertTrue(attr5.contains("b"));
assertTrue(attr5.contains(nullStringValue));
assertTrue(attr5.contains("d"));
Attribute attr6 = new DefaultAttribute(atPwd);
nbAdded = attr6.add("a", (String) null);
assertEquals(2, nbAdded);
assertFalse(attr6.isHumanReadable());
}
Aggregations