Search in sources :

Example 61 with Attribute

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

the class SchemaAwareAttributeTest method testGetString.

/**
 * Test method getString()
 */
@Test
public void testGetString() throws LdapInvalidAttributeValueException {
    Attribute attr1 = new DefaultAttribute(atDC);
    assertEquals(1, attr1.add((String) null));
    Attribute attr2 = new DefaultAttribute(atDC);
    attr2.add("a");
    assertEquals("a", attr2.getString());
    Attribute attr3 = new DefaultAttribute(atPwd);
    attr3.add(BYTES1, BYTES2);
    try {
        attr3.getString();
        fail();
    } catch (LdapInvalidAttributeValueException ivae) {
        assertTrue(true);
    }
}
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) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) Test(org.junit.Test)

Example 62 with Attribute

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

the class SchemaAwareAttributeTest method testSetUpIdStringAttributeType.

/**
 * Test method setUpId( String, AttributeType )
 */
@Test
public void testSetUpIdStringAttributeType() throws Exception {
    Attribute attr = new DefaultAttribute(atSN);
    attr.setUpId(null, atCN);
    assertEquals("2.5.4.3", attr.getId());
    assertEquals("cn", attr.getUpId());
    assertEquals(atCN, attr.getAttributeType());
    attr.setUpId("  ", atCN);
    assertEquals("2.5.4.3", attr.getId());
    assertEquals("cn", attr.getUpId());
    assertEquals(atCN, attr.getAttributeType());
    attr.setUpId("  CN  ", atCN);
    assertEquals("2.5.4.3", attr.getId());
    assertEquals("  CN  ", attr.getUpId());
    assertEquals(atCN, attr.getAttributeType());
    attr.setUpId("  CommonName  ", atCN);
    assertEquals("2.5.4.3", attr.getId());
    assertEquals("  CommonName  ", attr.getUpId());
    assertEquals(atCN, attr.getAttributeType());
    attr.setUpId("  2.5.4.3  ", atCN);
    assertEquals("2.5.4.3", attr.getId());
    assertEquals("  2.5.4.3  ", attr.getUpId());
    assertEquals(atCN, attr.getAttributeType());
    // Check with wrong IDs
    try {
        attr.setUpId("sn", atCN);
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(true);
    }
    try {
        attr.setUpId("  2.5.4.4  ", atCN);
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(true);
    }
}
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 63 with Attribute

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

the class SchemaAwareAttributeTest method testClear.

/**
 * Test method clear()
 */
@Test
public void testClear() throws LdapException {
    Attribute attr = new DefaultAttribute("email", atEMail);
    assertEquals(0, attr.size());
    attr.add((String) null, "a", "b");
    assertEquals(3, attr.size());
    attr.clear();
    assertTrue(attr.isHumanReadable());
    assertEquals(0, attr.size());
    assertEquals(atEMail, attr.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 64 with Attribute

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

the class SchemaAwareAttributeTest method testDefaultServerAttributeAttributeTypeStringArray.

/**
 * Test constructor DefaultEntryAttribute( AttributeType, String... )
 */
@Test
public void testDefaultServerAttributeAttributeTypeStringArray() throws LdapException {
    Attribute attr1 = new DefaultAttribute(atEMail, "a", "b", (String) null);
    assertTrue(attr1.isHumanReadable());
    assertEquals(3, attr1.size());
    assertEquals("1.2.840.113549.1.9.1", attr1.getId());
    assertEquals("email", attr1.getUpId());
    assertEquals(atEMail, attr1.getAttributeType());
    assertTrue(attr1.contains("a", "b"));
    assertTrue(attr1.contains(nullStringValue));
    Attribute attr2 = new DefaultAttribute(atEMail, stringValue1, binaryValue2, nullStringValue);
    assertTrue(attr2.isHumanReadable());
    assertEquals(2, attr2.size());
    assertEquals("1.2.840.113549.1.9.1", attr2.getId());
    assertEquals("email", attr2.getUpId());
    assertEquals(atEMail, attr2.getAttributeType());
    assertTrue(attr2.contains("a"));
    assertTrue(attr2.contains(nullStringValue));
}
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 65 with Attribute

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

the class SchemaAwareAttributeTest method testIterator.

/**
 * Test method iterator()
 */
@Test
public void testIterator() throws LdapException {
    Attribute attr1 = new DefaultAttribute(atCN);
    attr1.add("a", "b", "c");
    Iterator<Value> iter = attr1.iterator();
    assertTrue(iter.hasNext());
    String[] values = new String[] { "a", "b", "c" };
    int pos = 0;
    for (Value val : attr1) {
        assertTrue(val instanceof Value);
        assertEquals(values[pos++], val.getValue());
    }
}
Also used : 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) 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