String user1entryUUID = "11111111-1112-1113-1114-111111111115";
String baseUUID = "22222222-2222-2222-2222-222222222222";
// Publish DEL
ChangeNumber cn1 = new ChangeNumber(TimeThread.getTime(), ts++, 1201);
DeleteMsg delMsg =
new DeleteMsg("uid="+tn+"1," + TEST_ROOT_DN_STRING, cn1,
user1entryUUID);
server01.publish(delMsg);
debugInfo(tn, " publishes " + delMsg.getChangeNumber());
// Publish ADD
gblCN = new ChangeNumber(TimeThread.getTime(), ts++, 1201);
String lentry = new String(
"dn: uid="+tn+"2," + TEST_ROOT_DN_STRING + "\n"
+ "objectClass: top\n"
+ "objectClass: domain\n"
+ "entryUUID: "+user1entryUUID+"\n");
Entry entry = TestCaseUtils.entryFromLdifString(lentry);
AddMsg addMsg = new AddMsg(
gblCN,
"uid="+tn+"2," + TEST_ROOT_DN_STRING,
user1entryUUID,
baseUUID,
entry.getObjectClassAttribute(),
entry.getAttributes(),
new ArrayList<Attribute>());
server01.publish(addMsg);
debugInfo(tn, " publishes " + addMsg.getChangeNumber());
// Publish MOD
ChangeNumber cn3 = new ChangeNumber(TimeThread.getTime(), ts++, 1201);
Attribute attr1 = Attributes.create("description", "new value");
Modification mod1 = new Modification(ModificationType.REPLACE, attr1);
List<Modification> mods = new ArrayList<Modification>();
mods.add(mod1);
ModifyMsg modMsg = new ModifyMsg(cn3, DN
.decode("uid="+tn+"3," + TEST_ROOT_DN_STRING), mods, user1entryUUID);
server01.publish(modMsg);
debugInfo(tn, " publishes " + modMsg.getChangeNumber());
// Publish modDN
ChangeNumber cn4 = new ChangeNumber(TimeThread.getTime(), ts++, 1201);
ModifyDNOperationBasis op = new ModifyDNOperationBasis(connection, 1, 1, null,
DN.decode("uid="+tn+"4," + TEST_ROOT_DN_STRING), // entryDN
RDN.decode("uid="+tn+"new4"), // new rdn
true, // deleteoldrdn
DN.decode(TEST_ROOT_DN_STRING2)); // new superior
op.setAttachment(SYNCHROCONTEXT, new ModifyDnContext(cn4, user1entryUUID,
"newparentId"));
LocalBackendModifyDNOperation localOp = new LocalBackendModifyDNOperation(op);
ModifyDNMsg modDNMsg = new ModifyDNMsg(localOp);
server01.publish(modDNMsg);
debugInfo(tn, " publishes " + modDNMsg.getChangeNumber());
sleep(1000);
// search on 'cn=changelog'
LinkedHashSet<String> attributes = new LinkedHashSet<String>();
attributes.add("+");
attributes.add("*");
String filter = "(targetdn=*"+tn.toLowerCase()+"*,o=test)";
debugInfo(tn, " Search: " + filter);
InternalSearchOperation searchOp =
connection.processSearch(
ByteString.valueOf("cn=changelog"),
SearchScope.WHOLE_SUBTREE,
DereferencePolicy.NEVER_DEREF_ALIASES,
0, // Size limit
0, // Time limit
false, // Types only
LDAPFilter.decode(filter),
attributes,
NO_CONTROL,
null);
waitOpResult(searchOp, ResultCode.SUCCESS);
// test 4 entries returned
LinkedList<SearchResultEntry> entries = searchOp.getSearchEntries();
// 4 entries expected
assertEquals(searchOp.getSearchEntries().size(), 4);
if (entries != null)
{
int i=0;
for (SearchResultEntry resultEntry : entries)
{
i++;
debugInfo(tn, "Result entry returned:" + resultEntry.toLDIFString());
ldifWriter.writeEntry(resultEntry);
if (i==1)
{
// check the DEL entry has the right content
assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
"changenumber="+String.valueOf(firstDraftChangeNumber+0)+",cn=changelog"),
"Result entry DN : actual=" + resultEntry.getDN().toNormalizedString() +
" expected=" + "changenumber="+String.valueOf(firstDraftChangeNumber+0)+",cn=changelog");
checkValue(resultEntry,"replicationcsn",cn1.toString());
checkValue(resultEntry,"replicaidentifier","1201");
checkValue(resultEntry,"targetdn","uid="+tn+"1," + TEST_ROOT_DN_STRING);
checkValue(resultEntry,"changetype","delete");
checkValue(resultEntry,"changelogcookie","o=test:"+cn1.toString()+";");
checkValue(resultEntry,"targetentryuuid",user1entryUUID);
checkValue(resultEntry,"changenumber",String.valueOf(firstDraftChangeNumber+0));
checkValue(resultEntry,"targetuniqueid","11111111-11121113-11141111-11111115");
} else if (i==2)
{
// check the ADD entry has the right content
assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
"changenumber="+String.valueOf(firstDraftChangeNumber+1)+",cn=changelog"));
String expectedValue1 = "objectClass: domain\nobjectClass: top\n" +
"entryUUID: "+user1entryUUID+"\n\n";
String expectedValue2 = "entryUUID: "+user1entryUUID+"\n" +
"objectClass: domain\nobjectClass: top\n\n";
checkPossibleValues(resultEntry,"changes",expectedValue1, expectedValue2);
checkValue(resultEntry,"replicationcsn",gblCN.toString());
checkValue(resultEntry,"replicaidentifier","1201");
checkValue(resultEntry,"targetdn","uid="+tn+"2," + TEST_ROOT_DN_STRING);
checkValue(resultEntry,"changetype","add");
checkValue(resultEntry,"changelogcookie","o=test:"+gblCN.toString()+";");
checkValue(resultEntry,"targetentryuuid",user1entryUUID);
checkValue(resultEntry,"changenumber",String.valueOf(firstDraftChangeNumber+1));
} else if (i==3)
{
// check the MOD entry has the right content
assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
"changenumber="+String.valueOf(firstDraftChangeNumber+2)+",cn=changelog"));
String expectedValue = "replace: description\n" +
"description: new value\n-\n";
checkValue(resultEntry,"changes",expectedValue);
checkValue(resultEntry,"replicationcsn",cn3.toString());
checkValue(resultEntry,"replicaidentifier","1201");
checkValue(resultEntry,"targetdn","uid="+tn+"3," + TEST_ROOT_DN_STRING);
checkValue(resultEntry,"changetype","modify");
checkValue(resultEntry,"changelogcookie","o=test:"+cn3.toString()+";");
checkValue(resultEntry,"targetentryuuid",user1entryUUID);
checkValue(resultEntry,"changenumber",String.valueOf(firstDraftChangeNumber+2));
} else if (i==4)
{
// check the MODDN entry has the right content
assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
"changenumber="+String.valueOf(firstDraftChangeNumber+3)+",cn=changelog"));
checkValue(resultEntry,"replicationcsn",cn4.toString());
checkValue(resultEntry,"replicaidentifier","1201");
checkValue(resultEntry,"targetdn","uid="+tn+"4," + TEST_ROOT_DN_STRING);
checkValue(resultEntry,"changetype","modrdn");
checkValue(resultEntry,"changelogcookie","o=test:"+cn4.toString()+";");
checkValue(resultEntry,"targetentryuuid",user1entryUUID);
checkValue(resultEntry,"newrdn","uid="+tn+"new4");
checkValue(resultEntry,"newsuperior",TEST_ROOT_DN_STRING2);
checkValue(resultEntry,"deleteoldrdn","true");
checkValue(resultEntry,"changenumber",String.valueOf(firstDraftChangeNumber+3));
}
}
}
server01.stop();
// Test with filter on draft changenumber
filter = "(&(targetdn=*"+tn.toLowerCase()+"*,o=test)(&(changenumber>="+
firstDraftChangeNumber+")(changenumber<="+(firstDraftChangeNumber+3)+")))";
debugInfo(tn, " Search: " + filter);
searchOp =
connection.processSearch(
ByteString.valueOf("cn=changelog"),
SearchScope.WHOLE_SUBTREE,
DereferencePolicy.NEVER_DEREF_ALIASES,
0, // Size limit
0, // Time limit
false, // Types only
LDAPFilter.decode(filter),
attributes,
NO_CONTROL,
null);
waitOpResult(searchOp, ResultCode.SUCCESS);
entries = searchOp.getSearchEntries();
if (entries != null)
{
int i=0;
for (SearchResultEntry resultEntry : entries)
{
i++;
debugInfo(tn, "Result entry returned:" + resultEntry.toLDIFString());
ldifWriter.writeEntry(resultEntry);
if (i==1)
{
// check the DEL entry has the right content
assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
"changenumber="+String.valueOf(firstDraftChangeNumber+0)+",cn=changelog"));
checkValue(resultEntry,"replicationcsn",cn1.toString());
checkValue(resultEntry,"replicaidentifier","1201");
checkValue(resultEntry,"targetdn","uid="+tn+"1," + TEST_ROOT_DN_STRING);
checkValue(resultEntry,"changetype","delete");
checkValue(resultEntry,"changelogcookie","o=test:"+cn1.toString()+";");
checkValue(resultEntry,"targetentryuuid",user1entryUUID);
checkValue(resultEntry,"changenumber",String.valueOf(firstDraftChangeNumber+0));
checkValue(resultEntry,"targetuniqueid","11111111-11121113-11141111-11111115");
} else if (i==2)
{
// check the ADD entry has the right content
assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
"changenumber="+String.valueOf(firstDraftChangeNumber+1)+",cn=changelog"));
String expectedValue1 = "objectClass: domain\nobjectClass: top\n" +
"entryUUID: "+user1entryUUID+"\n\n";
String expectedValue2 = "entryUUID: "+user1entryUUID+"\n" +
"objectClass: domain\nobjectClass: top\n\n";
checkPossibleValues(resultEntry,"changes",expectedValue1, expectedValue2);
checkValue(resultEntry,"replicationcsn",gblCN.toString());
checkValue(resultEntry,"replicaidentifier","1201");
checkValue(resultEntry,"targetdn","uid="+tn+"2," + TEST_ROOT_DN_STRING);
checkValue(resultEntry,"changetype","add");
checkValue(resultEntry,"changelogcookie","o=test:"+gblCN.toString()+";");
checkValue(resultEntry,"targetentryuuid",user1entryUUID);
checkValue(resultEntry,"changenumber",String.valueOf(firstDraftChangeNumber+1));
} else if (i==3)
{
// check the MOD entry has the right content
assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
"changenumber="+String.valueOf(firstDraftChangeNumber+2)+",cn=changelog"));
String expectedValue = "replace: description\n" +
"description: new value\n-\n";
checkValue(resultEntry,"changes",expectedValue);
checkValue(resultEntry,"replicationcsn",cn3.toString());
checkValue(resultEntry,"replicaidentifier","1201");
checkValue(resultEntry,"targetdn","uid="+tn+"3," + TEST_ROOT_DN_STRING);
checkValue(resultEntry,"changetype","modify");
checkValue(resultEntry,"changelogcookie","o=test:"+cn3.toString()+";");
checkValue(resultEntry,"targetentryuuid",user1entryUUID);
checkValue(resultEntry,"changenumber",String.valueOf(firstDraftChangeNumber+2));
} else if (i==4)
{
// check the MODDN entry has the right content
assertTrue(resultEntry.getDN().toNormalizedString().equalsIgnoreCase(
"changenumber="+String.valueOf(firstDraftChangeNumber+3)+",cn=changelog"));
checkValue(resultEntry,"replicationcsn",cn4.toString());
checkValue(resultEntry,"replicaidentifier","1201");
checkValue(resultEntry,"targetdn","uid="+tn+"4," + TEST_ROOT_DN_STRING);
checkValue(resultEntry,"changetype","modrdn");
checkValue(resultEntry,"changelogcookie","o=test:"+cn4.toString()+";");
checkValue(resultEntry,"targetentryuuid",user1entryUUID);
checkValue(resultEntry,"newrdn","uid="+tn+"new4");
checkValue(resultEntry,"newsuperior",TEST_ROOT_DN_STRING2);
checkValue(resultEntry,"deleteoldrdn","true");
checkValue(resultEntry,"changenumber",String.valueOf(firstDraftChangeNumber+3));