use of org.apache.directory.api.ldap.model.name.Ava in project directory-ldap-api by apache.
the class RdnTest method testSingleValuedIterator.
@Test
public void testSingleValuedIterator() throws LdapException {
Rdn rdn = new Rdn("cn=Kate Bush");
Iterator<Ava> iterator = rdn.iterator();
assertNotNull(iterator);
assertTrue(iterator.hasNext());
assertNotNull(iterator.next());
assertFalse(iterator.hasNext());
}
use of org.apache.directory.api.ldap.model.name.Ava in project directory-ldap-api by apache.
the class RdnTest method testIterator.
/**
* test the iterator over a RDN
*/
@Test
public void testIterator() throws LdapException {
Rdn rdn = new Rdn("cn=John + sn=Doe");
String[] expected = new String[] { "cn=John ", " sn=Doe" };
int i = 0;
for (Ava ava : rdn) {
assertEquals(expected[i], ava.getName());
i++;
}
}
use of org.apache.directory.api.ldap.model.name.Ava in project directory-ldap-api by apache.
the class LdifRevertor method generateModify.
/**
* A helper method to generate the modified attribute after a rename.
*/
private static LdifEntry generateModify(Dn parentDn, Entry entry, Rdn oldRdn, Rdn newRdn) {
LdifEntry restored = new LdifEntry();
restored.setChangeType(ChangeType.Modify);
// We have to use the parent Dn, the entry has already
// been renamed
restored.setDn(parentDn);
for (Ava ava : newRdn) {
// in the previous modification
if (!entry.contains(ava.getNormType(), ava.getValue().getValue()) && !(ava.getNormType().equals(oldRdn.getNormType()) && ava.getValue().getValue().equals(oldRdn.getValue()))) {
// Create the modification, which is an Remove
Modification modification = new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, new DefaultAttribute(ava.getType(), ava.getValue().getValue()));
restored.addModification(modification);
}
}
return restored;
}
use of org.apache.directory.api.ldap.model.name.Ava in project directory-ldap-api by apache.
the class AvaSerializationTest method testNullUpValueSerialization.
@Test
public void testNullUpValueSerialization() 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);
}
}
use of org.apache.directory.api.ldap.model.name.Ava in project directory-ldap-api by apache.
the class AvaSerializationTest method testBinaryAtavStaticSerialization.
@Test
public void testBinaryAtavStaticSerialization() 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);
}
Aggregations