Search in sources :

Example 56 with Attribute

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

the class SchemaAwareAttributeTest method testDefaultServerAttributeStringAttributeType.

/**
 * Test constructor DefaultEntryAttribute( String, AttributeType )
 */
@Test
public void testDefaultServerAttributeStringAttributeType() {
    Attribute attr1 = new DefaultAttribute("cn", atCN);
    assertTrue(attr1.isHumanReadable());
    assertEquals(0, attr1.size());
    assertEquals("2.5.4.3", attr1.getId());
    assertEquals("cn", attr1.getUpId());
    assertEquals(atCN, attr1.getAttributeType());
    Attribute attr2 = new DefaultAttribute("  CommonName  ", atCN);
    assertTrue(attr2.isHumanReadable());
    assertEquals(0, attr2.size());
    assertEquals("2.5.4.3", attr2.getId());
    assertEquals("  CommonName  ", attr2.getUpId());
    assertEquals(atCN, attr2.getAttributeType());
    Attribute attr3 = new DefaultAttribute("  ", atCN);
    assertTrue(attr3.isHumanReadable());
    assertEquals(0, attr3.size());
    assertEquals("2.5.4.3", attr3.getId());
    assertEquals("cn", attr3.getUpId());
    assertEquals(atCN, attr3.getAttributeType());
}
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 57 with Attribute

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

the class SchemaAwareAttributeTest method testToClientAttribute.

/**
 * Test the conversion method
 */
@Test
public void testToClientAttribute() throws LdapException {
    Attribute attribute = new DefaultAttribute(atCN, "test", "test2");
    Attribute clientAttribute = attribute.clone();
    assertTrue(clientAttribute instanceof Attribute);
    assertTrue(clientAttribute.contains("test", "test2"));
    assertEquals("2.5.4.3", clientAttribute.getId());
    attribute.remove("test", "test2");
    assertTrue(clientAttribute.contains("test", "test2"));
}
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 58 with Attribute

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

the class SchemaAwareAttributeTest method testRemoveStringArray.

/**
 * Test method remove( String... )
 */
@Test
public void testRemoveStringArray() throws Exception {
    Attribute attr1 = new DefaultAttribute(atEMail);
    assertFalse(attr1.remove("a"));
    attr1.add("a", "b", "c");
    assertTrue(attr1.remove("a"));
    assertEquals(2, attr1.size());
    assertTrue(attr1.remove("b", "c"));
    assertEquals(0, attr1.size());
    assertFalse(attr1.remove("d"));
    attr1.clear();
    attr1.add("a", "b", "c");
    assertFalse(attr1.remove("b", "e"));
    assertEquals(2, attr1.size());
    attr1.clear();
    attr1.add("a", (String) null, "b");
    assertTrue(attr1.remove((String) null, "a"));
    assertEquals(1, attr1.size());
    Attribute attr2 = new DefaultAttribute("test");
    attr2.add(BYTES1, BYTES2, BYTES3);
    assertFalse(attr2.remove((String) null));
    assertTrue(attr2.remove("ab", "c"));
    assertFalse(attr2.remove("d"));
}
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 59 with Attribute

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

the class SchemaAwareAttributeTest method testContainsStringArray.

/**
 * Test method contains( String... )
 */
@Test
public void testContainsStringArray() throws LdapException {
    Attribute attr1 = new DefaultAttribute(atEMail);
    assertEquals(0, attr1.size());
    assertFalse(attr1.contains("a"));
    assertFalse(attr1.contains((String) null));
    attr1.add((String) null);
    assertEquals(1, attr1.size());
    assertTrue(attr1.contains((String) null));
    attr1.remove((String) null);
    assertFalse(attr1.contains((String) null));
    assertEquals(0, attr1.size());
    attr1.add("a", "b", "c");
    assertEquals(3, attr1.size());
    assertTrue(attr1.contains("a"));
    assertTrue(attr1.contains("b"));
    assertTrue(attr1.contains("c"));
    assertFalse(attr1.contains("e"));
    assertFalse(attr1.contains((String) null));
}
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 60 with Attribute

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

the class SchemaAwareAttributeTest method testRemoveByteArray.

/**
 * Test method remove( byte... )
 */
@Test
public void testRemoveByteArray() throws Exception {
    Attribute attr1 = new DefaultAttribute(atPwd);
    assertFalse(attr1.remove(BYTES1));
    attr1.add(BYTES1, BYTES2, BYTES3);
    assertTrue(attr1.remove(BYTES1));
    assertEquals(2, attr1.size());
    assertTrue(attr1.remove(BYTES2, BYTES3));
    assertEquals(0, attr1.size());
    assertFalse(attr1.remove(BYTES4));
    attr1.clear();
    attr1.add(BYTES1, BYTES2, BYTES3);
    assertFalse(attr1.remove(BYTES3, BYTES4));
    assertEquals(2, attr1.size());
    attr1.clear();
    attr1.add(BYTES1, (byte[]) null, BYTES2);
    assertTrue(attr1.remove((byte[]) null, BYTES1));
    assertEquals(1, attr1.size());
}
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)

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