Search in sources :

Example 96 with DefaultEntry

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());
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 97 with DefaultEntry

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"));
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 98 with DefaultEntry

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());
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) Value(org.apache.directory.api.ldap.model.entry.Value) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Test(org.junit.Test)

Example 99 with DefaultEntry

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"));
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 100 with DefaultEntry

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"));
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Test(org.junit.Test)

Aggregations

DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)128 Entry (org.apache.directory.api.ldap.model.entry.Entry)116 Test (org.junit.Test)55 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)41 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)39 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)20 Modification (org.apache.directory.api.ldap.model.entry.Modification)16 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)16 Dn (org.apache.directory.api.ldap.model.name.Dn)15 CreateException (org.apache.directory.fortress.core.CreateException)15 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)14 Value (org.apache.directory.api.ldap.model.entry.Value)12 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)12 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)5 IOException (java.io.IOException)4 ObjectInputStream (java.io.ObjectInputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4