Search in sources :

Example 21 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testAddStringByteArrayArray.

/**
 * Test method for add( String, byte[]... )
 */
@Test
public void testAddStringByteArrayArray() throws LdapException {
    Entry entry = new DefaultEntry();
    entry.add("userPassword", (byte[]) null);
    assertEquals(1, entry.size());
    Attribute attributePWD = entry.get("userPassword");
    assertEquals(1, attributePWD.size());
    assertNotNull(attributePWD.get());
    assertNull(attributePWD.get().getBytes());
    entry.add("jpegPhoto", BYTES1, BYTES1, BYTES2);
    assertEquals(2, entry.size());
    Attribute attributeJPG = entry.get("jpegPhoto");
    assertEquals(2, attributeJPG.size());
    assertNotNull(attributeJPG.get());
    assertTrue(attributeJPG.contains(BYTES1));
    assertTrue(attributeJPG.contains(BYTES2));
}
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) Test(org.junit.Test)

Example 22 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testUserCertificateBinary.

/**
 * Test method for userCertificate;binary AT
 */
@Test
public void testUserCertificateBinary() throws LdapException {
    Entry entry = new DefaultEntry(schemaManager);
    entry.add("objectClass", "top", "person", "inetorgPerson");
    entry.add("cn", "test1", "test2");
    entry.add("sn", "Test1", "Test2");
    entry.add("userPassword", BYTES1, BYTES2);
    entry.add("userCertificate;binary", Strings.getBytesUtf8("secret"));
    assertTrue(entry.containsAttribute("userCertificate;binary"));
    assertTrue(entry.containsAttribute("userCertificate"));
    entry.removeAttributes("userCertificate;binary");
    assertFalse(entry.containsAttribute("userCertificate;binary"));
    assertFalse(entry.containsAttribute("userCertificate"));
    entry.add("userCertificate", Strings.getBytesUtf8("secret"));
    assertTrue(entry.containsAttribute("userCertificate;binary"));
    assertTrue(entry.containsAttribute("userCertificate"));
}
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)

Example 23 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testSerializeCompleteEntry.

/**
 * Test the serialization of a complete entry
 */
@Test
public void testSerializeCompleteEntry() throws LdapException, IOException, ClassNotFoundException {
    Dn dn = new Dn(schemaManager, "ou=system");
    byte[] password = Strings.getBytesUtf8("secret");
    Entry entry = new DefaultEntry(dn);
    entry.add("ObjectClass", "top", "person");
    entry.add("cn", "test1");
    entry.add("userPassword", password);
    Entry entrySer = deserializeValue(serializeValue(entry));
    assertEquals(entry, entrySer);
}
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) Dn(org.apache.directory.api.ldap.model.name.Dn) Test(org.junit.Test)

Example 24 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry 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"));
}
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) Value(org.apache.directory.api.ldap.model.entry.Value) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 25 with DefaultEntry

use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testPutStringByteArrayArray.

/**
 * Test method for put( String, byte[]... )
 */
@Test
public void testPutStringByteArrayArray() {
    Entry entry = new DefaultEntry(exampleDn);
    try {
        entry.put((String) null, BYTES1);
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(true);
    }
    try {
        entry.put("   ", BYTES1);
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(true);
    }
    entry.put("userPassword", (byte[]) null);
    assertEquals(1, entry.size());
    assertNotNull(entry.get("userPassword"));
    assertEquals(1, entry.get("userPassword").size());
    assertNull(entry.get("userPassword").get().getBytes());
    entry.put("jpegPhoto", BYTES1, BYTES2, BYTES1);
    assertEquals(2, entry.size());
    assertNotNull(entry.get("jpegPhoto"));
    assertEquals(2, entry.get("JPEGPhoto").size());
    Attribute attribute = entry.get("jpegPhoto");
    assertTrue(attribute.contains(BYTES1));
    assertTrue(attribute.contains(BYTES2));
    assertEquals("jpegphoto", attribute.getId());
    assertEquals("jpegPhoto", attribute.getUpId());
}
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) 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