Search in sources :

Example 16 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class BinaryValueAttributeTypeTest method testServerBinaryValueEmptyValue.

/**
 * Test the constructor with an empty value
 */
@Test
public void testServerBinaryValueEmptyValue() throws LdapInvalidAttributeValueException {
    AttributeType attribute = EntryUtils.getBytesAttributeType();
    Value value = new Value(attribute, Strings.EMPTY_BYTES);
    assertTrue(Arrays.equals(Strings.EMPTY_BYTES, value.getBytes()));
    assertFalse(value.isNull());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 17 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class BinaryValueAttributeTypeTest method testServerBinaryValue.

/**
 * Test the constructor with a value
 */
@Test
public void testServerBinaryValue() throws LdapInvalidAttributeValueException {
    AttributeType attribute = EntryUtils.getBytesAttributeType();
    byte[] val = new byte[] { 0x01 };
    Value value = new Value(attribute, val);
    assertTrue(Arrays.equals(val, value.getBytes()));
    assertFalse(value.isNull());
    assertTrue(Arrays.equals(val, value.getBytes()));
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 18 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class BinaryValueAttributeTypeTest method testGetNormalizedValue.

/**
 * Test the getNormValue method
 */
@Test
public void testGetNormalizedValue() throws LdapInvalidAttributeValueException {
    AttributeType attribute = EntryUtils.getBytesAttributeType();
    Value value = new Value(attribute, (byte[]) null);
    assertNull(value.getBytes());
    value = new Value(attribute, Strings.EMPTY_BYTES);
    assertTrue(Arrays.equals(Strings.EMPTY_BYTES, value.getBytes()));
    value = new Value(attribute, BYTES2);
    assertTrue(Arrays.equals(BYTES2, value.getBytes()));
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 19 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class BinaryValueAttributeTypeTest method testIsValid.

/**
 * Test the isValid method
 *
 * The SyntaxChecker does not accept values longer than 5 chars.
 */
@Test
public void testIsValid() throws LdapInvalidAttributeValueException {
    AttributeType attribute = EntryUtils.getBytesAttributeType();
    new Value(attribute, (byte[]) null);
    new Value(attribute, Strings.EMPTY_BYTES);
    new Value(attribute, new byte[] { 0x01, 0x02 });
    try {
        new Value(attribute, new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });
        fail();
    } catch (LdapInvalidAttributeValueException liave) {
        assertTrue(true);
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) Test(org.junit.Test)

Example 20 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class BinaryValueAttributeTypeTest method testHashCode.

/**
 * Tests to make sure the hashCode method is working properly.
 * @throws Exception on errors
 */
@Test
public void testHashCode() throws LdapInvalidAttributeValueException {
    AttributeType attribute = EntryUtils.getBytesAttributeType();
    Value v0 = new Value(attribute, new byte[] { 0x01, 0x02 });
    Value v1 = new Value(attribute, new byte[] { (byte) 0x81, (byte) 0x82 });
    Value v2 = new Value(attribute, new byte[] { 0x01, 0x02 });
    assertNotSame(v0.hashCode(), v1.hashCode());
    assertNotSame(v1.hashCode(), v2.hashCode());
    assertEquals(v0.hashCode(), v2.hashCode());
    assertNotSame(v0, v1);
    assertEquals(v0, v2);
    assertNotSame(v1, v2);
    Value v3 = new Value(attribute, new byte[] { 0x01, 0x03 });
    assertFalse(v3.equals(v0));
    assertFalse(v3.equals(v1));
    assertFalse(v3.equals(v2));
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Aggregations

AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)135 Test (org.junit.Test)68 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)42 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)25 ParseException (java.text.ParseException)15 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)15 Value (org.apache.directory.api.ldap.model.entry.Value)15 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)11 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)11 HashSet (java.util.HashSet)10 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)10 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)10 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)9 IOException (java.io.IOException)7 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)7 Before (org.junit.Before)7 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)6 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)6 ArrayList (java.util.ArrayList)5 Dn (org.apache.directory.api.ldap.model.name.Dn)4