use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testAddStringArray.
/**
* Test method add( String... )
*/
@Test
public void testAddStringArray() 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(atCN);
nbAdded = attr3.add("t");
assertEquals(1, nbAdded);
assertTrue(attr3.isHumanReadable());
assertEquals("t", attr3.getString());
Attribute attr4 = new DefaultAttribute(atCN);
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"));
nbAdded = attr4.add("e");
assertEquals(1, nbAdded);
assertTrue(attr4.isHumanReadable());
assertEquals("a", attr4.getString());
assertTrue(attr4.contains("a"));
assertTrue(attr4.contains("b"));
assertTrue(attr4.contains("c"));
assertTrue(attr4.contains("d"));
assertTrue(attr4.contains("e"));
nbAdded = attr4.add(BYTES1);
assertEquals(0, nbAdded);
assertTrue(attr4.isHumanReadable());
assertEquals("a", attr4.getString());
assertTrue(attr4.contains("a"));
assertTrue(attr4.contains("b"));
assertTrue(attr4.contains("c"));
assertTrue(attr4.contains("d"));
assertTrue(attr4.contains("e"));
assertFalse(attr4.contains("ab"));
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());
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testContainsValueArray.
/**
* Test method contains( Value... ) throws LdapException
*/
@Test
public void testContainsValueArray() throws LdapException {
Attribute attr1 = new DefaultAttribute(atEMail);
assertEquals(0, attr1.size());
assertFalse(attr1.contains(stringValue1));
assertFalse(attr1.contains(nullStringValue));
attr1.add((String) null);
assertEquals(1, attr1.size());
assertTrue(attr1.contains(nullStringValue));
attr1.remove((String) null);
assertFalse(attr1.contains(nullStringValue));
assertEquals(0, attr1.size());
attr1.add("a", "b", "c");
assertEquals(3, attr1.size());
assertTrue(attr1.contains(stringValue1));
assertTrue(attr1.contains(stringValue2));
assertTrue(attr1.contains(stringValue3));
assertTrue(attr1.contains(stringValue1, stringValue3));
assertFalse(attr1.contains(stringValue4));
assertFalse(attr1.contains(nullStringValue));
Attribute attr2 = new DefaultAttribute(atPwd);
assertEquals(0, attr2.size());
assertFalse(attr2.contains(BYTES1));
assertFalse(attr2.contains(nullBinaryValue));
attr2.add((byte[]) null);
assertEquals(1, attr2.size());
assertTrue(attr2.contains(nullBinaryValue));
attr2.remove((byte[]) null);
assertFalse(attr2.contains(nullBinaryValue));
assertEquals(0, attr2.size());
attr2.add(BYTES1, BYTES2, BYTES3);
assertEquals(3, attr2.size());
assertTrue(attr2.contains(binaryValue1));
assertTrue(attr2.contains(binaryValue2));
assertTrue(attr2.contains(binaryValue3));
assertFalse(attr2.contains(nullBinaryValue));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testInstanceOf.
/**
* Test method instanceOf()
*/
@Test
public void testInstanceOf() throws Exception {
Attribute attr = new DefaultAttribute(atCN);
assertTrue(attr.isInstanceOf(atCN));
assertTrue(attr.isInstanceOf(atName));
assertFalse(attr.isInstanceOf(atSN));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testContainsStringByteArray.
/**
* Test method for contains( String, byte[]... )
*/
@Test
public void testContainsStringByteArray() throws LdapException {
Entry entry = new DefaultEntry(exampleDn);
assertFalse(entry.containsAttribute("objectClass"));
Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, (byte[]) null, BYTES2);
entry.add(attrPWD);
assertTrue(entry.contains(" userPASSWORD ", BYTES1, BYTES2));
assertTrue(entry.contains(" userPASSWORD ", (byte[]) null));
// We can search for byte[] using Strings. the strings will be converted to byte[]
assertTrue(entry.contains(" userPASSWORD ", "ab", "b"));
assertFalse(entry.contains(" userPASSWORD ", "ab", "b", "d"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testEqualsObject.
/**
* Test method for equals()
*/
@Test
public void testEqualsObject() throws LdapException {
Entry entry1 = new DefaultEntry();
Entry entry2 = new DefaultEntry();
assertEquals(entry1, entry2);
entry1.setDn(exampleDn);
assertNotSame(entry1, entry2);
entry2.setDn(exampleDn);
assertEquals(entry1, entry2);
Attribute attrOC = new DefaultAttribute("objectClass", "top", "person");
Attribute attrCN = new DefaultAttribute("cn", "test1", "test2");
Attribute attrSN = new DefaultAttribute("sn", "Test1", "Test2");
Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, BYTES2);
entry1.put(attrOC, attrCN, attrSN, attrPWD);
entry2.put(attrOC, attrCN, attrSN);
assertNotSame(entry1, entry2);
entry2.put(attrPWD);
assertEquals(entry1, entry2);
Attribute attrL1 = new DefaultAttribute("l", "Paris", "New-York");
Attribute attrL2 = new DefaultAttribute("l", "Paris", "Tokyo");
entry1.put(attrL1);
entry2.put(attrL1);
assertEquals(entry1, entry2);
entry1.add("l", "London");
assertNotSame(entry1, entry2);
entry2.add(attrL2);
assertNotSame(entry1, entry2);
entry1.clear();
entry2.clear();
assertEquals(entry1, entry2);
}
Aggregations