use of org.apache.directory.api.ldap.model.entry.DefaultEntry 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.DefaultEntry 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.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testDefaultClientEntryLdapDN.
/**
* Test method for DefaultEntry( Dn )
*/
@Test
public void testDefaultClientEntryLdapDN() {
Entry entry = new DefaultEntry(exampleDn);
assertNotNull(entry);
assertNotNull(entry.getDn());
assertEquals(exampleDn, entry.getDn());
assertEquals(0, entry.size());
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry 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);
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testAddStringValueArray.
/**
* Test method for add( String, Value... )
*/
@Test
public void testAddStringValueArray() throws LdapException {
Entry entry = new DefaultEntry();
Value value = new Value((String) null);
entry.add("cn", value);
assertEquals(1, entry.size());
Attribute attributeCN = entry.get("cn");
assertEquals(1, attributeCN.size());
assertNotNull(attributeCN.get());
assertNull(attributeCN.get().getValue());
Value value1 = new Value("test1");
Value value2 = new Value("test2");
Value value3 = new Value("test1");
entry.add("sn", value1, value2, value3);
assertEquals(2, entry.size());
Attribute attributeSN = entry.get("sn");
assertEquals(2, attributeSN.size());
assertNotNull(attributeSN.get());
assertTrue(attributeSN.contains(value1));
assertTrue(attributeSN.contains(value2));
Value value4 = new Value(BYTES1);
entry.add("l", value1, value4);
assertEquals(3, entry.size());
Attribute attributeL = entry.get("l");
assertEquals(2, attributeL.size());
assertNotNull(attributeL.get());
assertTrue(attributeL.contains(value1));
// The byte[] value must have been transformed to a String
assertTrue(attributeL.contains("ab"));
}
Aggregations