mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Properly remove the blog when deleting a contact and inform all peers
Fixes #816
This commit is contained in:
@@ -4,6 +4,7 @@ import net.jodah.concurrentunit.Waiter;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.NoSuchGroupException;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
@@ -34,7 +35,9 @@ import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
|
||||
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class BlogSharingIntegrationTest
|
||||
extends BriarIntegrationTest<BriarIntegrationTestComponent> {
|
||||
@@ -424,6 +427,65 @@ public class BlogSharingIntegrationTest
|
||||
assertFalse(blogManager1.canBeRemoved(blog2.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSharerIsInformedWhenBlogIsRemovedDueToContactDeletion()
|
||||
throws Exception {
|
||||
// initialize and let invitee accept all requests
|
||||
listenToEvents(true);
|
||||
|
||||
// sharer sends invitation for 2's blog to 1
|
||||
blogSharingManager0
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener1.requestReceived);
|
||||
|
||||
// sync response back
|
||||
sync1To0(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// 1 and 2 are adding each other
|
||||
addContacts1And2();
|
||||
assertEquals(3, blogManager1.getBlogs().size());
|
||||
|
||||
// make sure blog2 is shared between 0 and 1
|
||||
Collection<Contact> contacts =
|
||||
blogSharingManager1.getSharedWith(blog2.getId());
|
||||
assertEquals(2, contacts.size());
|
||||
assertTrue(contacts.contains(contact0From1));
|
||||
contacts = blogSharingManager0.getSharedWith(blog2.getId());
|
||||
assertEquals(2, contacts.size());
|
||||
assertTrue(contacts.contains(contact1From0));
|
||||
|
||||
// 1 removes contact 2
|
||||
assertNotNull(contactId2From1);
|
||||
contactManager1.removeContact(contactId2From1);
|
||||
|
||||
// sync leave message to 0
|
||||
sync1To0(1, true);
|
||||
|
||||
// make sure blog2 is no longer shared between 0 and 1
|
||||
contacts = blogSharingManager0.getSharedWith(blog2.getId());
|
||||
assertEquals(1, contacts.size());
|
||||
assertFalse(contacts.contains(contact1From0));
|
||||
|
||||
// 1 doesn't even have blog2 anymore
|
||||
try {
|
||||
blogManager1.getBlog(blog2.getId());
|
||||
fail();
|
||||
} catch (NoSuchGroupException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
// 0 can share blog2 again with 1
|
||||
assertTrue(
|
||||
blogSharingManager0.canBeShared(blog2.getId(), contact1From0));
|
||||
}
|
||||
|
||||
@NotNullByDefault
|
||||
private class SharerListener implements EventListener {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user