Search in sources :

Example 76 with Attribute

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

the class SchemaAwareEntryTest method testAddEntryAttributeArray.

/**
 * Test method for add( EntryAttribute... )
 */
@Test
public void testAddEntryAttributeArray() throws LdapException {
    Entry entry = createEntry();
    assertEquals(4, entry.size());
    assertTrue(entry.containsAttribute("ObjectClass"));
    assertTrue(entry.containsAttribute("CN"));
    assertTrue(entry.containsAttribute("  sn  "));
    assertTrue(entry.containsAttribute("userPassword"));
    Attribute attr = entry.get("objectclass");
    assertEquals(2, attr.size());
    Attribute attrCN2 = new DefaultAttribute("cn", "test1", "test3");
    entry.add(attrCN2);
    assertEquals(4, entry.size());
    attr = entry.get("cn");
    assertEquals(3, attr.size());
    assertTrue(attr.contains("test1", "test2", "test3"));
    // Check adding some byte[] values (they will not be transformed to Strings)
    attrCN2.clear();
    attrCN2.add(BYTES1, BYTES2);
    entry.add(attrCN2);
    assertEquals(4, entry.size());
    attr = entry.get("cn");
    assertEquals(3, attr.size());
    assertTrue(attr.contains("test1", "test2", "test3"));
    assertFalse(attr.contains("ab", "b"));
}
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) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 77 with Attribute

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

Example 78 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute 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 79 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute 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 80 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute 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

Attribute (org.apache.directory.api.ldap.model.entry.Attribute)269 Test (org.junit.Test)180 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)168 Entry (org.apache.directory.api.ldap.model.entry.Entry)94 Modification (org.apache.directory.api.ldap.model.entry.Modification)56 Value (org.apache.directory.api.ldap.model.entry.Value)52 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)46 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)35 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 EncoderException (org.apache.directory.api.asn1.EncoderException)20 ByteBuffer (java.nio.ByteBuffer)18 DecoderException (org.apache.directory.api.asn1.DecoderException)18 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)18 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)18 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)18 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)18 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)16 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)16 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13