// also check encode/decode
try
{
bsb.clear();
ecnc.write(writer);
LDAPControl control = LDAPReader.readControl(ASN1.getReader(bsb));
newEcnc = EntryChangeNotificationControl.DECODER.decode(control.isCritical(), control.getValue());
assertNotNull(newEcnc);
assertEquals(ecnc.getOID(), newEcnc.getOID());
assertEquals(ecnc.getChangeNumber(), newEcnc.getChangeNumber());
assertEquals(ecnc.getChangeType(), newEcnc.getChangeType());
assertNull(newEcnc.getPreviousDN());
assertEquals(ecnc.isCritical(), newEcnc.isCritical());
}
catch (DirectoryException e)
{
if (type.compareTo(PersistentSearchChangeType.MODIFY_DN) == 0)
{
assertTrue(true,"could decode a control with previousDN=null " +
"and type=modDN");
}
else
{
assertTrue(false,"could decode a control with previousDN=null " +
"and type=modDN");
}
}
}
// Test contructor EntryChangeNotificationControl
// (PersistentSearchChangeType changeType, DN previousDN, long
// changeNumber)
DN dn = DN.decode(dnString);
for (PersistentSearchChangeType type : types)
{
ecnc = new EntryChangeNotificationControl(type, dn, changeNumber);
assertNotNull(ecnc);
assertEquals(OID_ENTRY_CHANGE_NOTIFICATION, ecnc.getOID());
assertEquals(changeNumber, ecnc.getChangeNumber());
assertEquals(type, ecnc.getChangeType());
assertEquals(dn, ecnc.getPreviousDN());
assertEquals(false, ecnc.isCritical()) ;
checkEntryChangeNotificationControlToString(ecnc);
// also check encode/decode
try
{
bsb.clear();
ecnc.write(writer);
LDAPControl control = LDAPReader.readControl(ASN1.getReader(bsb));
newEcnc = EntryChangeNotificationControl.DECODER.decode(control.isCritical(), control.getValue());
assertNotNull(newEcnc);
assertEquals(ecnc.getOID(),newEcnc.getOID());
assertEquals(ecnc.getChangeNumber(),newEcnc.getChangeNumber());
assertEquals(ecnc.getChangeType(),newEcnc.getChangeType());
assertEquals(ecnc.getPreviousDN(),newEcnc.getPreviousDN());
assertEquals(ecnc.isCritical(),newEcnc.isCritical()) ;
}
catch (DirectoryException e)
{
if (type.compareTo(PersistentSearchChangeType.MODIFY_DN) == 0)
{
assertTrue(false,"couldn't decode a control with previousDN " +
"not null and type=modDN");
}
else
{
assertTrue(true,"couldn't decode a control with previousDN " +
"not null and type=modDN");
}
}
}
// Test contructor EntryChangeNotificationControl(boolean
// isCritical, PersistentSearchChangeType changeType,
// DN previousDN, long changeNumber)
for (PersistentSearchChangeType type : types)
{
ecnc = new EntryChangeNotificationControl(isCritical, type, dn,
changeNumber);
assertNotNull(ecnc);
assertEquals(OID_ENTRY_CHANGE_NOTIFICATION, ecnc.getOID());
assertEquals(changeNumber, ecnc.getChangeNumber());
assertEquals(type, ecnc.getChangeType());
assertEquals(dn, ecnc.getPreviousDN());
assertEquals(isCritical, ecnc.isCritical()) ;
checkEntryChangeNotificationControlToString(ecnc);
// also check encode/decode
try
{
bsb.clear();
ecnc.write(writer);
LDAPControl control = LDAPReader.readControl(ASN1.getReader(bsb));
newEcnc = EntryChangeNotificationControl.DECODER.decode(control.isCritical(), control.getValue());
assertNotNull(newEcnc);
assertEquals(ecnc.getOID(),newEcnc.getOID());
assertEquals(ecnc.getChangeNumber(),newEcnc.getChangeNumber());
assertEquals(ecnc.getChangeType(),newEcnc.getChangeType());
assertEquals(ecnc.getPreviousDN(),newEcnc.getPreviousDN());
assertEquals(ecnc.isCritical(),newEcnc.isCritical()) ;
}
catch (DirectoryException e)
{
if (type.compareTo(PersistentSearchChangeType.MODIFY_DN) == 0)
{
assertTrue(false,"couldn't decode a control with previousDN " +
"not null and type=modDN");
}
else
{
assertTrue(true,"couldn't decode a control with previousDN " +
"not null and type=modDN");
}
}
}
// Check error on decode
try
{
LDAPControl control =
new LDAPControl(OID_ENTRY_CHANGE_NOTIFICATION, isCritical);
newEcnc = EntryChangeNotificationControl.DECODER.decode(control.isCritical(), control.getValue());
assertTrue(false,"couldn't decode a control with null");
}
catch (DirectoryException e)
{
assertTrue(true,"couldn't decode a control with null");