Search in sources :

Example 26 with DefaultAttribute

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

the class SchemaAwareAttributeTest method testIsValidSyntaxChecker.

/**
 * Test method isValid( SyntaxChecker )
 */
@Test
public void testIsValidSyntaxChecker() throws LdapException {
    Attribute attr = new DefaultAttribute("test");
    attr.add("test", "another test");
    assertTrue(attr.isValid(atCN));
    attr.add("test an invalid '\uFFFD' char");
    assertFalse(attr.isValid(atCN));
}
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 27 with DefaultAttribute

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

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

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

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

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