Abdera abdera = new Abdera();
Feed f1 = abdera.newFeed();
Feed f2 = abdera.newFeed();
Entry e1 = SharingHelper.createEntry(abdera, "jms", f1);
Entry e2 = SharingHelper.createEntry(abdera, "jms", f2);
Sync s1 = SharingHelper.getSync(e1, false);
Sync s2 = SharingHelper.getSync(e2, false);
s2.setId(s1.getId());
SharingHelper.updateEntry(e1, "bob");
SharingHelper.updateEntry(e2, "jms");
SharingHelper.mergeFeeds(f1, f2);
assertEquals(1, f2.getEntries().size());
Entry entry = f2.getEntries().get(0);
Sync sync = SharingHelper.getSync(entry);
Conflicts conflicts = sync.getConflicts();
assertNotNull(conflicts);
assertEquals(1, conflicts.getEntries().size());
Entry conflict = conflicts.getEntries().get(0);
assertNotNull(conflict);
ConflictResolver r = new ConflictResolver() {
public Entry resolve(Entry entry, List<Entry> conflicts) {
Sync sync = SharingHelper.getSync(entry, false);
Conflicts c = sync.getConflicts(false);
if (c != null)
c.discard();
return entry; // take the latest
}
};
entry = SharingHelper.resolveConflicts(entry, r, "jms");
sync = SharingHelper.getSync(entry);
conflicts = sync.getConflicts();
assertNull(conflicts);
assertEquals(4, sync.getHistory().size());
}