Search in sources :

Example 71 with Attribute

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

the class SchemaAwareAttributeTest method testContainsValueArray.

/**
 * Test method contains( Value... ) throws LdapException
 */
@Test
public void testContainsValueArray() throws LdapException {
    Attribute attr1 = new DefaultAttribute(atEMail);
    assertEquals(0, attr1.size());
    assertFalse(attr1.contains(stringValue1));
    assertFalse(attr1.contains(nullStringValue));
    attr1.add((String) null);
    assertEquals(1, attr1.size());
    assertTrue(attr1.contains(nullStringValue));
    attr1.remove((String) null);
    assertFalse(attr1.contains(nullStringValue));
    assertEquals(0, attr1.size());
    attr1.add("a", "b", "c");
    assertEquals(3, attr1.size());
    assertTrue(attr1.contains(stringValue1));
    assertTrue(attr1.contains(stringValue2));
    assertTrue(attr1.contains(stringValue3));
    assertTrue(attr1.contains(stringValue1, stringValue3));
    assertFalse(attr1.contains(stringValue4));
    assertFalse(attr1.contains(nullStringValue));
    Attribute attr2 = new DefaultAttribute(atPwd);
    assertEquals(0, attr2.size());
    assertFalse(attr2.contains(BYTES1));
    assertFalse(attr2.contains(nullBinaryValue));
    attr2.add((byte[]) null);
    assertEquals(1, attr2.size());
    assertTrue(attr2.contains(nullBinaryValue));
    attr2.remove((byte[]) null);
    assertFalse(attr2.contains(nullBinaryValue));
    assertEquals(0, attr2.size());
    attr2.add(BYTES1, BYTES2, BYTES3);
    assertEquals(3, attr2.size());
    assertTrue(attr2.contains(binaryValue1));
    assertTrue(attr2.contains(binaryValue2));
    assertTrue(attr2.contains(binaryValue3));
    assertFalse(attr2.contains(nullBinaryValue));
}
Also used : 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 72 with Attribute

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

the class SchemaAwareAttributeTest method testInstanceOf.

/**
 * Test method instanceOf()
 */
@Test
public void testInstanceOf() throws Exception {
    Attribute attr = new DefaultAttribute(atCN);
    assertTrue(attr.isInstanceOf(atCN));
    assertTrue(attr.isInstanceOf(atName));
    assertFalse(attr.isInstanceOf(atSN));
}
Also used : 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 73 with Attribute

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

the class SchemaAwareEntryTest method testContainsStringByteArray.

/**
 * Test method for contains( String, byte[]... )
 */
@Test
public void testContainsStringByteArray() throws LdapException {
    Entry entry = new DefaultEntry(exampleDn);
    assertFalse(entry.containsAttribute("objectClass"));
    Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, (byte[]) null, BYTES2);
    entry.add(attrPWD);
    assertTrue(entry.contains("  userPASSWORD  ", BYTES1, BYTES2));
    assertTrue(entry.contains("  userPASSWORD  ", (byte[]) null));
    // We can search for byte[] using Strings. the strings will be converted to byte[]
    assertTrue(entry.contains("  userPASSWORD  ", "ab", "b"));
    assertFalse(entry.contains("  userPASSWORD  ", "ab", "b", "d"));
}
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 74 with Attribute

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

the class SchemaAwareEntryTest method testAddStringStringArray.

/**
 * Test method for add( String, String... )
 */
@Test
public void testAddStringStringArray() throws LdapException {
    Entry entry = new DefaultEntry();
    entry.add("cn", (String) null);
    assertEquals(1, entry.size());
    Attribute attributeCN = entry.get("cn");
    assertEquals(1, attributeCN.size());
    assertNotNull(attributeCN.get());
    assertNull(attributeCN.get().getValue());
    entry.add("sn", "test", "test", "TEST");
    assertEquals(2, entry.size());
    Attribute attributeSN = entry.get("sn");
    assertEquals(2, attributeSN.size());
    assertNotNull(attributeSN.get());
    assertTrue(attributeSN.contains("test"));
    assertTrue(attributeSN.contains("TEST"));
}
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 75 with Attribute

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

the class SchemaAwareEntryTest method testEqualsObject.

/**
 * Test method for equals()
 */
@Test
public void testEqualsObject() throws LdapException {
    Entry entry1 = new DefaultEntry();
    Entry entry2 = new DefaultEntry();
    assertEquals(entry1, entry2);
    entry1.setDn(exampleDn);
    assertNotSame(entry1, entry2);
    entry2.setDn(exampleDn);
    assertEquals(entry1, entry2);
    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);
    entry1.put(attrOC, attrCN, attrSN, attrPWD);
    entry2.put(attrOC, attrCN, attrSN);
    assertNotSame(entry1, entry2);
    entry2.put(attrPWD);
    assertEquals(entry1, entry2);
    Attribute attrL1 = new DefaultAttribute("l", "Paris", "New-York");
    Attribute attrL2 = new DefaultAttribute("l", "Paris", "Tokyo");
    entry1.put(attrL1);
    entry2.put(attrL1);
    assertEquals(entry1, entry2);
    entry1.add("l", "London");
    assertNotSame(entry1, entry2);
    entry2.add(attrL2);
    assertNotSame(entry1, entry2);
    entry1.clear();
    entry2.clear();
    assertEquals(entry1, entry2);
}
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)

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