Search in sources :

Example 11 with Ava

use of org.apache.directory.api.ldap.model.name.Ava in project directory-ldap-api by apache.

the class AvaSerializationTest method testNullUpValueStaticSerialization.

@Test
public void testNullUpValueStaticSerialization() throws LdapException, IOException, ClassNotFoundException {
    Ava atav = new Ava(schemaManager, "CN", (String) null);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    try {
        atav.writeExternal(out);
        fail();
    } catch (IOException ioe) {
        String message = ioe.getMessage();
        assertEquals("ERR_13619_CANNOT_SERIALIZE_AVA_VALUE_NULL Cannot serialize a wrong ATAV, the value should not be null", message);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) Ava(org.apache.directory.api.ldap.model.name.Ava) Test(org.junit.Test)

Example 12 with Ava

use of org.apache.directory.api.ldap.model.name.Ava in project directory-ldap-api by apache.

the class AvaSerializationTest method testEmptyUpValueSerialization.

@Test
public void testEmptyUpValueSerialization() throws LdapException, IOException, ClassNotFoundException {
    Ava atav = new Ava(schemaManager, "CN", "");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    atav.writeExternal(out);
    ObjectInputStream in = null;
    byte[] data = baos.toByteArray();
    in = new ObjectInputStream(new ByteArrayInputStream(data));
    Ava atav2 = new Ava(schemaManager);
    atav2.readExternal(in);
    assertEquals(atav, atav2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Ava(org.apache.directory.api.ldap.model.name.Ava) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 13 with Ava

use of org.apache.directory.api.ldap.model.name.Ava in project directory-ldap-api by apache.

the class AvaSerializationTest method testEmptyNormValueSerialization.

@Test
public void testEmptyNormValueSerialization() throws LdapException, IOException, ClassNotFoundException {
    Ava atav = new Ava(schemaManager, "CN", "test");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    atav.writeExternal(out);
    ObjectInputStream in = null;
    byte[] data = baos.toByteArray();
    in = new ObjectInputStream(new ByteArrayInputStream(data));
    Ava atav2 = new Ava(schemaManager);
    atav2.readExternal(in);
    assertEquals(atav, atav2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Ava(org.apache.directory.api.ldap.model.name.Ava) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 14 with Ava

use of org.apache.directory.api.ldap.model.name.Ava in project directory-ldap-api by apache.

the class AvaTest method testAvaEscapedMiddleChar.

@Test
public void testAvaEscapedMiddleChar() throws LdapException {
    // Trail char : 0x00
    Ava atav = new Ava(schemaManager, "cn", new byte[] { 'a', 0x00, 'b' });
    assertEquals("cn=a\\00b", atav.getName());
    assertEquals("cn=a\\00b", atav.getEscaped());
    // Trail char : 0x20 (it should not be escaped)
    atav = new Ava(schemaManager, "cn", new byte[] { 'a', 0x20, 'b' });
    assertEquals("cn=a b", atav.getName());
    assertEquals("cn=a b", atav.getEscaped());
    // Trail char : '#' (it should not be escaped)
    atav = new Ava(schemaManager, "cn", new byte[] { 'a', '#', 'b' });
    assertEquals("cn=a#b", atav.getName());
    assertEquals("cn=a#b", atav.getEscaped());
    // Trail char : ','
    atav = new Ava(schemaManager, "cn", new byte[] { 'a', ',', 'b' });
    assertEquals("cn=a\\,b", atav.getName());
    assertEquals("cn=a\\,b", atav.getEscaped());
    // Trail char : ';'
    atav = new Ava(schemaManager, "cn", new byte[] { 'a', ';', 'b' });
    assertEquals("cn=a\\;b", atav.getName());
    assertEquals("cn=a\\;b", atav.getEscaped());
    // Trail char : '+'
    atav = new Ava(schemaManager, "cn", new byte[] { 'a', '+', 'b' });
    assertEquals("cn=a\\+b", atav.getName());
    assertEquals("cn=a\\+b", atav.getEscaped());
    // Trail char : '"'
    atav = new Ava(schemaManager, "cn", new byte[] { 'a', '"', 'b' });
    assertEquals("cn=a\\\"b", atav.getName());
    assertEquals("cn=a\\\"b", atav.getEscaped());
    // Trail char : '<'
    atav = new Ava(schemaManager, "cn", new byte[] { 'a', '<', 'b' });
    assertEquals("cn=a\\<b", atav.getName());
    assertEquals("cn=a\\<b", atav.getEscaped());
    // Trail char : '>'
    atav = new Ava(schemaManager, "cn", new byte[] { 'a', '>', 'b' });
    assertEquals("cn=a\\>b", atav.getName());
    assertEquals("cn=a\\>b", atav.getEscaped());
    // Trail char : '\'
    atav = new Ava(schemaManager, "cn", new byte[] { 'a', '\\', 'b' });
    assertEquals("cn=a\\\\b", atav.getName());
    assertEquals("cn=a\\\\b", atav.getEscaped());
}
Also used : Ava(org.apache.directory.api.ldap.model.name.Ava) Test(org.junit.Test)

Example 15 with Ava

use of org.apache.directory.api.ldap.model.name.Ava in project directory-ldap-api by apache.

the class AvaTest method testEqualsAtav1TypeSuperior.

/**
 * Compare two atavs : the first one is superior because its type is
 * superior
 */
@Test
public void testEqualsAtav1TypeSuperior() throws LdapException {
    Ava atav1 = new Ava(schemaManager, "b", "b");
    Ava atav2 = new Ava(schemaManager, "a", "b");
    assertFalse(atav1.equals(atav2));
}
Also used : Ava(org.apache.directory.api.ldap.model.name.Ava) Test(org.junit.Test)

Aggregations

Ava (org.apache.directory.api.ldap.model.name.Ava)44 Test (org.junit.Test)39 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 ObjectOutputStream (java.io.ObjectOutputStream)14 Rdn (org.apache.directory.api.ldap.model.name.Rdn)12 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ObjectInputStream (java.io.ObjectInputStream)8 IOException (java.io.IOException)5 Dn (org.apache.directory.api.ldap.model.name.Dn)3 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)2 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)1 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)1 Modification (org.apache.directory.api.ldap.model.entry.Modification)1 Value (org.apache.directory.api.ldap.model.entry.Value)1 Anonymizer (org.apache.directory.api.ldap.model.ldif.anonymizer.Anonymizer)1 BinaryAnonymizer (org.apache.directory.api.ldap.model.ldif.anonymizer.BinaryAnonymizer)1 CaseSensitiveStringAnonymizer (org.apache.directory.api.ldap.model.ldif.anonymizer.CaseSensitiveStringAnonymizer)1