Search in sources :

Example 31 with DefaultAttribute

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

Example 32 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testContains.

/**
 * Test the contains() method
 */
@Test
public void testContains() throws Exception {
    AttributeType at = TestEntryUtils.getIA5StringAttributeType();
    DefaultAttribute attr = new DefaultAttribute(at);
    attr.add("Test  1");
    attr.add("Test  2");
    attr.add("Test  3");
    assertTrue(attr.contains("test 1"));
    assertTrue(attr.contains("Test 2"));
    assertTrue(attr.contains("TEST     3"));
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 33 with DefaultAttribute

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

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

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

the class SchemaAwareAttributeTest method testAddTwoValue.

@Test
public void testAddTwoValue() throws Exception {
    AttributeType at = TestEntryUtils.getIA5StringAttributeType();
    DefaultAttribute attr = new DefaultAttribute(at);
    // Add String values
    attr.add("test");
    attr.add("test2");
    assertEquals(2, attr.size());
    assertTrue(attr.getAttributeType().getSyntax().isHumanReadable());
    Set<String> expected = new HashSet<String>();
    expected.add("test");
    expected.add("test2");
    for (Value val : attr) {
        if (expected.contains(val.getValue())) {
            expected.remove(val.getValue());
        } else {
            fail();
        }
    }
    assertEquals(0, expected.size());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) Value(org.apache.directory.api.ldap.model.entry.Value) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)159 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)131 Test (org.junit.Test)106 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)41 Modification (org.apache.directory.api.ldap.model.entry.Modification)40 Entry (org.apache.directory.api.ldap.model.entry.Entry)36 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)35 Value (org.apache.directory.api.ldap.model.entry.Value)20 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ObjectInputStream (java.io.ObjectInputStream)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ObjectOutputStream (java.io.ObjectOutputStream)12 Dn (org.apache.directory.api.ldap.model.name.Dn)12 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)11 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)11 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)8 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)7 ModifyRequestImpl (org.apache.directory.api.ldap.model.message.ModifyRequestImpl)7 ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)7 HashSet (java.util.HashSet)6