use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntrySerializationTest method testEntryNoAttributesNoDnSerialization.
@Test
public void testEntryNoAttributesNoDnSerialization() throws IOException, LdapException, ClassNotFoundException {
Entry entry1 = new DefaultEntry(schemaManager, "");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
entry1.writeExternal(out);
ObjectInputStream in = null;
byte[] data = baos.toByteArray();
in = new ObjectInputStream(new ByteArrayInputStream(data));
Entry entry2 = new DefaultEntry(schemaManager);
entry2.readExternal(in);
assertEquals(entry1, entry2);
assertEquals(0, entry2.size());
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testGet.
/**
* Test method for get( String )
*/
@Test
public void testGet() throws LdapException {
Entry entry = new DefaultEntry(exampleDn);
assertNull(entry.get("objectClass"));
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.add(attrOC, attrCN, attrSN, attrPWD);
assertNotNull(entry.get(" CN "));
Attribute attribute = entry.get("cN");
assertEquals(attribute, attrCN);
assertNull(entry.get((String) null));
assertNull(entry.get(" "));
assertNull(entry.get("l"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testToString.
/**
* Test method for for {@link org.apache.directory.api.ldap.model.entry.DefaultEntry#toString()}.
*/
@Test
public void testToString() {
Entry entry = new DefaultEntry(exampleDn);
assertEquals("Entry\n dn: dc=example,dc=com\n\n", entry.toString());
Value strValueTop = new Value("top");
Value strValuePerson = new Value("person");
Value strNullValue = new Value((String) null);
Value binValue1 = new Value(BYTES1);
Value binValue2 = new Value(BYTES2);
Value binNullValue = new Value((byte[]) null);
entry.put("ObjectClass", strValueTop, strValuePerson, strNullValue);
entry.put("UserPassword", binValue1, binValue2, binNullValue);
String expected = "Entry\n" + " dn: dc=example,dc=com\n" + " ObjectClass: top\n" + " ObjectClass: person\n" + " ObjectClass: ''\n" + " UserPassword: 0x61 0x62 \n" + " UserPassword: 0x62 \n" + " UserPassword: ''\n";
assertEquals(expected, entry.toString());
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testPutEntryAttributeArray.
/**
* Test method for put( EntryAttribute... )
*/
@Test
public void testPutEntryAttributeArray() throws LdapException {
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);
List<Attribute> removed = entry.put(attrOC, attrCN, attrSN, attrPWD);
assertEquals(4, entry.size());
assertEquals(0, removed.size());
assertTrue(entry.containsAttribute("ObjectClass"));
assertTrue(entry.containsAttribute("CN"));
assertTrue(entry.containsAttribute(" sn "));
assertTrue(entry.containsAttribute("userPassword"));
Attribute attrCN2 = new DefaultAttribute("cn", "test3", "test4");
removed = entry.put(attrCN2);
assertEquals(4, entry.size());
assertEquals(1, removed.size());
assertTrue(entry.containsAttribute("CN"));
assertTrue(entry.contains("cn", "test3", "test4"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testDefaultClientEntryLdif.
/**
* Test method for DefaultEntry()
*/
@Test
public void testDefaultClientEntryLdif() throws Exception {
Entry entry = new DefaultEntry("ou=example, dc=com", "ObjectClass: top", "ObjectClass: person", "cn: test", "sn: test");
assertNotNull(entry);
assertEquals("ou=example, dc=com", entry.getDn().toString());
assertEquals(3, entry.size());
assertTrue(entry.contains("objectClass", "top", "person"));
assertTrue(entry.contains("cn", "test"));
assertTrue(entry.contains("sn", "test"));
}
Aggregations