use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testAddEntryAttributeArray.
/**
* Test method for add( EntryAttribute... )
*/
@Test
public void testAddEntryAttributeArray() throws LdapException {
Entry entry = createEntry();
assertEquals(4, entry.size());
assertTrue(entry.containsAttribute("ObjectClass"));
assertTrue(entry.containsAttribute("CN"));
assertTrue(entry.containsAttribute(" sn "));
assertTrue(entry.containsAttribute("userPassword"));
Attribute attr = entry.get("objectclass");
assertEquals(2, attr.size());
Attribute attrCN2 = new DefaultAttribute("cn", "test1", "test3");
entry.add(attrCN2);
assertEquals(4, entry.size());
attr = entry.get("cn");
assertEquals(3, attr.size());
assertTrue(attr.contains("test1", "test2", "test3"));
// Check adding some byte[] values (they will not be transformed to Strings)
attrCN2.clear();
attrCN2.add(BYTES1, BYTES2);
entry.add(attrCN2);
assertEquals(4, entry.size());
attr = entry.get("cn");
assertEquals(3, attr.size());
assertTrue(attr.contains("test1", "test2", "test3"));
assertFalse(attr.contains("ab", "b"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testRemoveStringValueArray.
/**
* Test method for remove(String, Value... )
*/
@Test
public void testRemoveStringValueArray() throws LdapException {
Entry entry = new DefaultEntry(exampleDn);
Attribute attrCN = new DefaultAttribute("cn", "test1", "test2", (String) null);
Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, BYTES2, (byte[]) null);
entry.add(attrCN, attrPWD);
Value strValue1 = new Value("test1");
Value strValue2 = new Value("test2");
Value strValue3 = new Value("test3");
Value strNullValue = new Value((String) null);
Value binValue1 = new Value(BYTES1);
Value binValue2 = new Value(BYTES2);
Value binValue3 = new Value(BYTES3);
Value binNullValue = new Value((byte[]) null);
assertTrue(entry.remove("cn", strValue1, strNullValue));
assertTrue(entry.contains("cn", strValue2));
assertFalse(entry.remove("cn", strValue3));
assertTrue(entry.remove("cn", strValue2));
assertFalse(entry.containsAttribute("cn"));
entry.add(attrCN, attrPWD);
assertTrue(entry.remove("userpassword", binValue1, binNullValue));
assertTrue(entry.contains("userpassword", binValue2));
assertFalse(entry.remove("userpassword", binValue3));
assertTrue(entry.remove("userpassword", binValue2));
assertFalse(entry.containsAttribute("userpassword"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method createEntry.
/**
* Helper method which creates an entry with 4 attributes.
*/
private Entry createEntry() {
try {
Entry entry = new DefaultEntry(exampleDn);
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);
entry.put(attrOC, attrCN, attrSN, attrPWD);
return entry;
} catch (LdapException ne) {
// Do nothing
return null;
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testHasObjectClass.
/**
* Test method for hasObjectClass( String )
*/
@Test
public void testHasObjectClass() throws LdapException {
Entry entry = new DefaultEntry(exampleDn);
assertFalse(entry.containsAttribute("objectClass"));
assertFalse(entry.hasObjectClass("top"));
entry.add(new DefaultAttribute("objectClass", "top", "person"));
assertTrue(entry.hasObjectClass("top"));
assertTrue(entry.hasObjectClass("person"));
assertFalse(entry.hasObjectClass("inetorgperson"));
assertFalse(entry.hasObjectClass((String) null));
assertFalse(entry.hasObjectClass(""));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testContainsStringStringArray.
/**
* Test method for contains( String, String... )
*/
@Test
public void testContainsStringStringArray() throws LdapException {
Entry entry = new DefaultEntry(exampleDn);
assertFalse(entry.containsAttribute("objectClass"));
Attribute attrOC = new DefaultAttribute("objectClass", "top", "person");
Attribute attrCN = new DefaultAttribute("cn", "test1", "test2");
Attribute attrSN = new DefaultAttribute("sn", "Test1", "Test2", (String) null);
Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, BYTES2);
entry.add(attrOC, attrCN, attrSN, attrPWD);
assertTrue(entry.contains("OBJECTCLASS", "top", "person"));
assertTrue(entry.contains(" cn ", "test1", "test2"));
assertTrue(entry.contains("Sn", "Test1", "Test2", (String) null));
assertTrue(entry.contains(" userPASSWORD ", "ab", "b"));
assertFalse(entry.contains("OBJECTCLASS", "PERSON"));
assertFalse(entry.contains(" cn ", "test1", "test3"));
assertFalse(entry.contains("Sn", "Test"));
assertFalse(entry.contains(" userPASSWORD ", (String) null));
}
Aggregations