Search in sources :

Example 6 with Ava

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

the class AvaSerializationTest method testStringAtavStaticSerialization.

/**
 * Test serialization of a simple ATAV
 */
@Test
public void testStringAtavStaticSerialization() 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 7 with Ava

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

the class AvaSerializationTest method testEmptyUpValueStaticSerialization.

@Test
public void testEmptyUpValueStaticSerialization() 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 8 with Ava

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

the class AvaSerializationTest method testBinaryAtavSerialization.

@Test
public void testBinaryAtavSerialization() throws LdapException, IOException, ClassNotFoundException {
    byte[] upValue = Strings.getBytesUtf8("  Test  ");
    Ava atav = new Ava(schemaManager, "CN", upValue);
    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 9 with Ava

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

the class AvaSerializationTest method testEmptyNormValueStaticSerialization.

@Test
public void testEmptyNormValueStaticSerialization() 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 10 with Ava

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

the class AvaSerializationTest method testSerializationPerf.

@Test
@Ignore
public void testSerializationPerf() throws LdapException, IOException, ClassNotFoundException {
    Ava atav = new Ava(schemaManager, "cn", "This is a serialization test");
    long t0 = System.currentTimeMillis();
    for (int j = 0; j < 1000; j++) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(baos);
        for (int i = 0; i < 100000; i++) {
            atav.writeExternal(out);
            out.flush();
        }
        out.close();
        baos.close();
    }
    long t1 = System.currentTimeMillis();
    System.out.println("delta AVA new serialization : " + (t1 - t0));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Ava(org.apache.directory.api.ldap.model.name.Ava) Ignore(org.junit.Ignore) 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