Search in sources :

Example 51 with Attribute

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

the class SchemaAwareAttributeTest method testEquals.

/**
 * Test method testEquals()
 */
@Test
public void testEquals() throws LdapException {
    Attribute attr1 = new DefaultAttribute(atCN);
    assertFalse(attr1.equals(null));
    Attribute attr2 = new DefaultAttribute(atCN);
    assertTrue(attr1.equals(attr2));
    attr2.setUpId("CN");
    assertTrue(attr1.equals(attr2));
    attr1.setUpId("CommonName");
    assertTrue(attr1.equals(attr2));
    attr1.setUpId("CN");
    assertTrue(attr1.equals(attr2));
    attr1.add("a", "b", "c");
    attr2.add("c", "b", "a");
    assertTrue(attr1.equals(attr2));
    assertTrue(attr1.equals(attr2));
    Attribute attr3 = new DefaultAttribute(atPwd);
    Attribute attr4 = new DefaultAttribute(atPwd);
    attr3.add(nullBinaryValue);
    attr4.add(nullBinaryValue);
    assertTrue(attr3.equals(attr4));
    Attribute attr5 = new DefaultAttribute(atPwd);
    Attribute attr6 = new DefaultAttribute(atDC);
    assertFalse(attr5.equals(attr6));
    attr5.add(nullBinaryValue);
    attr6.add(nullStringValue);
    assertFalse(attr5.equals(attr6));
    Attribute attr7 = new DefaultAttribute(atCN);
    Attribute attr8 = new DefaultAttribute(atPwd);
    attr7.add("a");
    attr8.add(BYTES2);
    assertFalse(attr7.equals(attr8));
    Attribute attr9 = new DefaultAttribute(atCN);
    Attribute attr10 = new DefaultAttribute(atPwd);
    attr9.add("a");
    attr9.add(BYTES2);
    attr10.add("a", "b");
    assertFalse(attr9.equals(attr10));
    Attribute attr11 = new DefaultAttribute(atPwd, BYTES1);
    Attribute attr12 = new DefaultAttribute(atPwd, BYTES1);
    assertTrue(attr11.get().equals(attr12.get()));
    assertTrue(attr12.get().equals(attr11.get()));
    Attribute attr13 = new DefaultAttribute("userPassword", BYTES1);
    assertTrue(attr11.get().equals(attr13.get()));
    assertTrue(attr13.get().equals(attr11.get()));
    Attribute attr14 = new DefaultAttribute("userPassword", BYTES1);
    assertTrue(attr14.get().equals(attr13.get()));
    assertTrue(attr13.get().equals(attr14.get()));
}
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 52 with Attribute

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

the class SchemaAwareAttributeTest method testDefaultServerAttributeStringAttributeTypeStringArray.

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

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

the class SchemaAwareAttributeTest method testSetAttributeType.

/**
 * Test method setAttributeType( AttributeType )
 */
@Test
public void testSetAttributeType() throws Exception {
    Attribute attr = new DefaultAttribute(atCN);
    try {
        attr.apply(null);
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(true);
    }
    attr.apply(atSN);
    assertTrue(attr.isInstanceOf(atSN));
    assertEquals("2.5.4.4", attr.getId());
    assertEquals("sn", attr.getUpId());
}
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 54 with Attribute

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

the class SchemaAwareAttributeTest method testPutStringArray.

/**
 * Test method put( String... )
 */
@Test
public void testPutStringArray() throws LdapInvalidAttributeValueException {
    Attribute attr1 = new DefaultAttribute(atDC);
    int nbAdded = attr1.add((String) null);
    assertEquals(1, nbAdded);
    assertTrue(attr1.isHumanReadable());
    assertEquals(nullStringValue, attr1.get());
    Attribute attr2 = new DefaultAttribute(atDC);
    nbAdded = attr2.add("");
    assertEquals(1, nbAdded);
    assertTrue(attr2.isHumanReadable());
    assertEquals("", attr2.getString());
    Attribute attr3 = new DefaultAttribute(atDC);
    nbAdded = attr3.add("t");
    assertEquals(1, nbAdded);
    assertTrue(attr3.isHumanReadable());
    assertEquals("t", attr3.getString());
    Attribute attr4 = new DefaultAttribute(atEMail);
    nbAdded = attr4.add("a", "b", "c", "d");
    assertEquals(4, nbAdded);
    assertTrue(attr4.isHumanReadable());
    assertEquals("a", attr4.getString());
    assertTrue(attr4.contains("a"));
    assertTrue(attr4.contains("b"));
    assertTrue(attr4.contains("c"));
    assertTrue(attr4.contains("d"));
    attr4.clear();
    nbAdded = attr4.add("e");
    assertEquals(1, nbAdded);
    assertTrue(attr4.isHumanReadable());
    assertEquals("e", attr4.getString());
    assertFalse(attr4.contains("a"));
    assertFalse(attr4.contains("b"));
    assertFalse(attr4.contains("c"));
    assertFalse(attr4.contains("d"));
    assertTrue(attr4.contains("e"));
    attr4.clear();
    nbAdded = attr4.add(BYTES1);
    assertEquals(0, nbAdded);
    assertTrue(attr4.isHumanReadable());
    Attribute attr5 = new DefaultAttribute(atEMail);
    nbAdded = attr5.add("a", "b", (String) null, "d");
    assertEquals(4, nbAdded);
    assertTrue(attr5.isHumanReadable());
    assertTrue(attr5.contains("a"));
    assertTrue(attr5.contains("b"));
    assertTrue(attr5.contains(nullStringValue));
    assertTrue(attr5.contains("d"));
    Attribute attr6 = new DefaultAttribute(atPwd);
    nbAdded = attr6.add("a", (String) null);
    assertEquals(2, nbAdded);
    assertFalse(attr6.isHumanReadable());
}
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 55 with Attribute

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

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