use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testRemoveStringByteArrayArray.
/**
* Test method for remove(String, byte[]... )
*/
@Test
public void testRemoveStringByteArrayArray() throws LdapException {
Entry entry = new DefaultEntry(exampleDn);
Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, (byte[]) null, BYTES2);
entry.put(attrPWD);
assertTrue(entry.remove("userPassword", (byte[]) null));
assertTrue(entry.remove("userPassword", BYTES1, BYTES2));
assertFalse(entry.containsAttribute("userPassword"));
entry.add("userPassword", BYTES1, (byte[]) null, BYTES2);
assertTrue(entry.remove("userPassword", (byte[]) null));
assertEquals(2, entry.get("userPassword").size());
assertTrue(entry.remove("userPassword", BYTES1, BYTES3));
assertEquals(1, entry.get("userPassword").size());
assertTrue(Arrays.equals(BYTES2, entry.get("userPassword").getBytes()));
assertFalse(entry.remove("userPassword", BYTES3));
assertFalse(entry.remove("void", "whatever"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testPutStringStringArray.
/**
* Test method for put( String, String... )
*/
@Test
public void testPutStringStringArray() {
Entry entry = new DefaultEntry(exampleDn);
try {
entry.put((String) null, "a");
fail();
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
try {
entry.put(" ", "a");
fail();
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
entry.put("sn", (String) null);
assertEquals(1, entry.size());
assertNotNull("sn", entry.get("sn"));
assertEquals(1, entry.get("sn").size());
assertNull(entry.get("sn").get().getValue());
entry.put("ObjectClass", "top", "person", "top");
assertEquals(2, entry.size());
assertNotNull("objectclass", entry.get("sn"));
assertEquals(2, entry.get("OBJECTCLASS").size());
Attribute attribute = entry.get("objectClass");
assertTrue(attribute.contains("top"));
assertTrue(attribute.contains("person"));
assertEquals("objectclass", attribute.getId());
assertEquals("ObjectClass", attribute.getUpId());
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testSerializeEntryWithNoDNNoAttribute.
/**
* Test the serialization of an entry with no attribute and no Dn
*/
@Test
public void testSerializeEntryWithNoDNNoAttribute() throws LdapException, IOException, ClassNotFoundException {
Entry entry = new DefaultEntry();
Entry entrySer = deserializeValue(serializeValue(entry));
assertEquals(entry, entrySer);
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testGetDn.
/**
* Test method for getDN()
*/
@Test
public void testGetDn() throws LdapException {
Entry entry = new DefaultEntry(exampleDn);
assertEquals(exampleDn, entry.getDn());
Dn testDn = new Dn("cn=test");
entry.setDn(testDn);
assertEquals(testDn, entry.getDn());
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testClone.
/**
* Test method for clone()
*/
@Test
public void testClone() throws LdapException {
Entry entry1 = new DefaultEntry();
Entry entry2 = entry1.clone();
assertEquals(entry1, entry2);
entry2.setDn(exampleDn);
assertEquals(Dn.EMPTY_DN, entry1.getDn());
entry1.setDn(exampleDn);
entry2 = entry1.clone();
assertEquals(entry1, entry2);
entry1.add("objectClass", "top", "person");
entry1.add("cn", "test1", "test2");
entry2 = entry1.clone();
assertEquals(entry1, entry2);
entry1.add("cn", "test3");
assertEquals(2, entry2.get("cn").size());
assertFalse(entry2.contains("cn", "test3"));
entry1.add("sn", (String) null);
assertFalse(entry2.containsAttribute("sn"));
}
Aggregations