use of org.apache.directory.api.ldap.model.entry.Attribute 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.Attribute 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.Attribute 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.Attribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testAddStringStringArray.
/**
* Test method for add( String, String... )
*/
@Test
public void testAddStringStringArray() throws LdapException {
Entry entry = new DefaultEntry();
entry.add("cn", (String) null);
assertEquals(1, entry.size());
Attribute attributeCN = entry.get("cn");
assertEquals(1, attributeCN.size());
assertNotNull(attributeCN.get());
assertNull(attributeCN.get().getValue());
entry.add("sn", "test", "test", "TEST");
assertEquals(2, entry.size());
Attribute attributeSN = entry.get("sn");
assertEquals(2, attributeSN.size());
assertNotNull(attributeSN.get());
assertTrue(attributeSN.contains("test"));
assertTrue(attributeSN.contains("TEST"));
}
use of org.apache.directory.api.ldap.model.entry.Attribute 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