Search in sources :

Example 41 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testAddOneValue.

@Test
public void testAddOneValue() throws Exception {
    AttributeType at = TestEntryUtils.getIA5StringAttributeType();
    DefaultAttribute attr = new DefaultAttribute(at);
    // Add a String value
    attr.add("test");
    assertEquals(1, attr.size());
    assertTrue(attr.getAttributeType().getSyntax().isHumanReadable());
    Value value = attr.get();
    assertTrue(value instanceof Value);
    assertEquals("test", ((Value) value).getValue());
    // Add a binary value
    assertEquals(0, attr.add(new byte[] { 0x01 }));
    // Add a Value
    Value ssv = new Value(at, "test2");
    attr.add(ssv);
    assertEquals(2, attr.size());
    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)

Example 42 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testDefaultServerAttributeStringAttributeTypeValueArray.

/**
 * Test constructor DefaultEntryAttribute( String, AttributeType, Value... )
 */
@Test
public void testDefaultServerAttributeStringAttributeTypeValueArray() throws LdapException {
    Attribute attr1 = new DefaultAttribute("dc", atDC, stringValue1, stringValue2, nullStringValue);
    assertTrue(attr1.isHumanReadable());
    assertEquals(3, attr1.size());
    assertEquals("0.9.2342.19200300.100.1.25", attr1.getId());
    assertEquals("dc", attr1.getUpId());
    assertEquals(atDC, attr1.getAttributeType());
    assertTrue(attr1.contains("a", "b"));
    assertTrue(attr1.contains(nullStringValue));
    Attribute attr2 = new DefaultAttribute(atDC, stringValue1, binaryValue2, nullStringValue);
    assertTrue(attr2.isHumanReadable());
    assertEquals(2, attr2.size());
    assertEquals("0.9.2342.19200300.100.1.25", attr2.getId());
    assertEquals("dc", attr2.getUpId());
    assertEquals(atDC, attr2.getAttributeType());
    assertTrue(attr2.contains("a"));
    assertTrue(attr2.contains(nullStringValue));
    Attribute attr3 = new DefaultAttribute("DomainComponent", atDC, stringValue1, stringValue2, nullStringValue);
    assertTrue(attr3.isHumanReadable());
    assertEquals(3, attr3.size());
    assertEquals("0.9.2342.19200300.100.1.25", attr3.getId());
    assertEquals("DomainComponent", attr3.getUpId());
    assertEquals(atDC, attr3.getAttributeType());
    assertTrue(attr3.contains("a", "b"));
    assertTrue(attr3.contains(nullStringValue));
    Attribute attr4 = new DefaultAttribute(" 0.9.2342.19200300.100.1.25 ", atDC, stringValue1, stringValue2, nullStringValue);
    assertTrue(attr4.isHumanReadable());
    assertEquals(3, attr4.size());
    assertEquals("0.9.2342.19200300.100.1.25", attr4.getId());
    assertEquals(" 0.9.2342.19200300.100.1.25 ", attr4.getUpId());
    assertEquals(atDC, attr4.getAttributeType());
    assertTrue(attr4.contains("a", "b"));
    assertTrue(attr4.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 43 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testSerializeAttributeNullValue.

/**
 * Test the serialization of a server attribute with a null value
 */
@Test
public void testSerializeAttributeNullValue() throws LdapException, IOException, ClassNotFoundException {
    DefaultAttribute dsa = new DefaultAttribute(atDC);
    dsa.setUpId("DomainComponent");
    dsa.add((String) null);
    DefaultAttribute dsaSer = deserializeValue(serializeValue(dsa), atDC);
    assertEquals(dsa.toString(), dsaSer.toString());
    assertEquals("0.9.2342.19200300.100.1.25", dsaSer.getId());
    assertEquals("DomainComponent", dsaSer.getUpId());
    assertNull(dsaSer.getString());
    assertEquals(1, dsaSer.size());
    assertTrue(dsaSer.contains((String) null));
    assertTrue(dsaSer.isHumanReadable());
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 44 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testSerializeAttributeWithNoValue.

/**
 * Test the serialization of a server attribute with no value
 */
@Test
public void testSerializeAttributeWithNoValue() throws LdapException, IOException, ClassNotFoundException {
    DefaultAttribute dsa = new DefaultAttribute(atCN);
    dsa.setUpId("cn");
    DefaultAttribute dsaSer = deserializeValue(serializeValue(dsa), atCN);
    assertEquals(dsa.toString(), dsaSer.toString());
    assertEquals("2.5.4.3", dsaSer.getId());
    assertEquals("cn", dsaSer.getUpId());
    assertEquals(0, dsaSer.size());
    assertTrue(dsaSer.isHumanReadable());
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 45 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testDefaultServerAttributeStringAttributeTypeByteArray.

/**
 * Test method DefaultEntryAttribute( String, AttributeType, byte[]... )
 */
@Test
public void testDefaultServerAttributeStringAttributeTypeByteArray() throws LdapException {
    Attribute attr1 = new DefaultAttribute("userPassword", atPwd, BYTES1, BYTES2, (byte[]) null);
    assertFalse(attr1.isHumanReadable());
    assertEquals(3, attr1.size());
    assertEquals("2.5.4.35", attr1.getId());
    assertEquals("userPassword", attr1.getUpId());
    assertEquals(atPwd, attr1.getAttributeType());
    assertTrue(attr1.contains(BYTES1, BYTES2));
    assertTrue(attr1.contains(nullBinaryValue));
    Attribute attr2 = new DefaultAttribute("2.5.4.35", atPwd, stringValue1, binaryValue2, nullBinaryValue);
    assertFalse(attr2.isHumanReadable());
    assertEquals(2, attr2.size());
    assertEquals("2.5.4.35", attr2.getId());
    assertEquals("2.5.4.35", attr2.getUpId());
    assertEquals(atPwd, attr2.getAttributeType());
    assertTrue(attr2.contains(BYTES2));
    assertTrue(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)

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