mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
New Forum Sharing Client
This commit is contained in:
@@ -45,7 +45,8 @@ public class ForumManagerTest
|
||||
forum0 = forumManager0.addForum("Test Forum");
|
||||
groupId0 = forum0.getId();
|
||||
// share forum
|
||||
forumSharingManager0.sendInvitation(groupId0, contactId1From0, null);
|
||||
forumSharingManager0.sendInvitation(groupId0, contactId1From0, null,
|
||||
clock.currentTimeMillis());
|
||||
sync0To1(1, true);
|
||||
forumSharingManager1.respondToInvitation(forum0, contact0From1, true);
|
||||
sync1To0(1, true);
|
||||
@@ -189,7 +190,8 @@ public class ForumManagerTest
|
||||
// share a second forum
|
||||
Forum forum1 = forumManager0.addForum("Test Forum1");
|
||||
GroupId g1 = forum1.getId();
|
||||
forumSharingManager0.sendInvitation(g1, contactId1From0, null);
|
||||
forumSharingManager0.sendInvitation(g1, contactId1From0, null,
|
||||
clock.currentTimeMillis());
|
||||
sync0To1(1, true);
|
||||
forumSharingManager1.respondToInvitation(forum1, contact0From1, true);
|
||||
sync1To0(1, true);
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
||||
import org.briarproject.briar.api.sharing.InvitationMessage;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
import org.briarproject.briar.test.BriarIntegrationTest;
|
||||
import org.briarproject.briar.test.BriarIntegrationTestComponent;
|
||||
import org.briarproject.briar.test.DaggerBriarIntegrationTestComponent;
|
||||
@@ -97,10 +98,10 @@ public class GroupInvitationIntegrationTest
|
||||
GroupInvitationRequest request =
|
||||
(GroupInvitationRequest) messages.iterator().next();
|
||||
assertEquals(msg, request.getMessage());
|
||||
assertEquals(author0, request.getCreator());
|
||||
assertEquals(author0, request.getShareable().getCreator());
|
||||
assertEquals(timestamp, request.getTimestamp());
|
||||
assertEquals(contactId0From1, request.getContactId());
|
||||
assertEquals(privateGroup0.getName(), request.getGroupName());
|
||||
assertEquals(privateGroup0.getName(), request.getShareable().getName());
|
||||
assertFalse(request.isLocal());
|
||||
assertFalse(request.isRead());
|
||||
}
|
||||
@@ -123,7 +124,7 @@ public class GroupInvitationIntegrationTest
|
||||
for (InvitationMessage m : messages) {
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
InvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertEquals(contactId0From1, response.getContactId());
|
||||
assertTrue(response.isLocal());
|
||||
assertFalse(response.wasAccepted());
|
||||
@@ -140,7 +141,7 @@ public class GroupInvitationIntegrationTest
|
||||
for (InvitationMessage m : messages) {
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
InvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertEquals(contactId0From1, response.getContactId());
|
||||
assertFalse(response.isLocal());
|
||||
assertFalse(response.wasAccepted());
|
||||
@@ -172,7 +173,7 @@ public class GroupInvitationIntegrationTest
|
||||
for (InvitationMessage m : messages) {
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
InvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertTrue(response.wasAccepted());
|
||||
}
|
||||
}
|
||||
@@ -187,7 +188,7 @@ public class GroupInvitationIntegrationTest
|
||||
for (InvitationMessage m : messages) {
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
InvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertTrue(response.wasAccepted());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +90,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final GroupInvitationManagerImpl groupInvitationManager;
|
||||
|
||||
private final Group localGroup =
|
||||
new Group(new GroupId(getRandomId()), CLIENT_ID, getRandomBytes(5));
|
||||
private final Transaction txn = new Transaction(null, false);
|
||||
private final ContactId contactId = new ContactId(0);
|
||||
private final Author author =
|
||||
@@ -141,8 +139,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(inviteeEngine));
|
||||
oneOf(engineFactory).createPeerEngine();
|
||||
will(returnValue(peerEngine));
|
||||
oneOf(contactGroupFactory).createLocalGroup(CLIENT_ID);
|
||||
will(returnValue(localGroup));
|
||||
}});
|
||||
MetadataParser metadataParser = context.mock(MetadataParser.class);
|
||||
MessageTracker messageTracker = context.mock(MessageTracker.class);
|
||||
@@ -156,7 +152,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testCreateLocalState() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).addGroup(txn, localGroup);
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(Collections.singletonList(contact)));
|
||||
}});
|
||||
@@ -651,6 +646,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
new InviteMessage(message.getId(), contactGroup.getId(),
|
||||
privateGroup.getId(), time1, "name", author,
|
||||
new byte[0], null, new byte[0]);
|
||||
final PrivateGroup pg =
|
||||
new PrivateGroup(privateGroup, invite.getGroupName(),
|
||||
invite.getCreator(), invite.getSalt());
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
@@ -674,6 +672,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(body));
|
||||
oneOf(messageParser).parseInviteMessage(message, body);
|
||||
will(returnValue(invite));
|
||||
oneOf(privateGroupFactory).createPrivateGroup(invite.getGroupName(),
|
||||
invite.getCreator(), invite.getSalt());
|
||||
will(returnValue(pg));
|
||||
oneOf(db).containsGroup(txn, privateGroup.getId());
|
||||
will(returnValue(true));
|
||||
// second message
|
||||
|
||||
@@ -107,7 +107,8 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// create invitation
|
||||
blogSharingManager0
|
||||
.sendInvitation(blog1.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(blog1.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync invitation
|
||||
sync0To1(1, false);
|
||||
@@ -122,7 +123,8 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
blogSharingManager0
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// invitee has own blog and that of the sharer
|
||||
assertEquals(2, blogManager1.getBlogs().size());
|
||||
@@ -194,7 +196,8 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
blogSharingManager0
|
||||
.sendInvitation(blog2.getId(), contactId1From0, null);
|
||||
.sendInvitation(blog2.getId(), contactId1From0, null,
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -251,7 +254,8 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
blogSharingManager0
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -313,7 +317,8 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// sharer sends invitation for 2's blog to 1
|
||||
blogSharingManager0
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -349,7 +354,8 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
blogSharingManager0
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -399,7 +405,8 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// sharer sends invitation for 2's blog to 1
|
||||
blogSharingManager0
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
|
||||
@@ -2,19 +2,14 @@ package org.briarproject.briar.sharing;
|
||||
|
||||
import net.jodah.concurrentunit.Waiter;
|
||||
|
||||
import org.briarproject.bramble.api.Bytes;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||
import org.briarproject.briar.api.client.MessageQueueManager;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||
import org.briarproject.briar.api.forum.Forum;
|
||||
import org.briarproject.briar.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
||||
@@ -38,12 +33,10 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomString;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.FORUM_SALT_LENGTH;
|
||||
import static org.briarproject.briar.api.forum.ForumSharingManager.CLIENT_ID;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_INVITATION;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -56,6 +49,9 @@ public class ForumSharingIntegrationTest
|
||||
private InviteeListener listener1;
|
||||
private Forum forum0;
|
||||
|
||||
@Inject
|
||||
MessageEncoder messageEncoder;
|
||||
|
||||
// objects accessed from background threads need to be volatile
|
||||
private volatile ForumSharingManager forumSharingManager0;
|
||||
private volatile ForumSharingManager forumSharingManager1;
|
||||
@@ -115,7 +111,8 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -171,7 +168,8 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, null);
|
||||
.sendInvitation(forum0.getId(), contactId1From0, null,
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -227,7 +225,8 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -245,9 +244,8 @@ public class ForumSharingIntegrationTest
|
||||
assertTrue(forumManager1.getForums().contains(forum0));
|
||||
|
||||
// sharer shares forum with invitee
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
assertTrue(forumSharingManager0.getSharedWith(forum0.getId())
|
||||
.contains(c1));
|
||||
.contains(contact1From0));
|
||||
// invitee gets forum shared by sharer
|
||||
Contact contact0 = contactManager1.getContact(contactId1From0);
|
||||
assertTrue(forumSharingManager1.getSharedWith(forum0.getId())
|
||||
@@ -265,14 +263,16 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// sharer no longer shares forum with invitee
|
||||
assertFalse(forumSharingManager0.getSharedWith(forum0.getId())
|
||||
.contains(c1));
|
||||
.contains(contact1From0));
|
||||
// invitee no longer gets forum shared by sharer
|
||||
assertFalse(forumSharingManager1.getSharedWith(forum0.getId())
|
||||
.contains(contact0));
|
||||
// forum can be shared again
|
||||
assertTrue(forumSharingManager0.canBeShared(forum0.getId(), c1));
|
||||
Contact c0 = contactManager1.getContact(contactId0From1);
|
||||
assertTrue(forumSharingManager1.canBeShared(forum0.getId(), c0));
|
||||
// forum can be shared again by sharer
|
||||
assertTrue(forumSharingManager0
|
||||
.canBeShared(forum0.getId(), contact1From0));
|
||||
// invitee that left can not share again
|
||||
assertFalse(forumSharingManager1
|
||||
.canBeShared(forum0.getId(), contact0From1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -282,7 +282,8 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, null);
|
||||
.sendInvitation(forum0.getId(), contactId1From0, null,
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -336,7 +337,8 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, null);
|
||||
.sendInvitation(forum0.getId(), contactId1From0, null,
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sharer un-subscribes from forum
|
||||
forumManager0.removeForum(forum0);
|
||||
@@ -360,7 +362,8 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, null);
|
||||
.sendInvitation(forum0.getId(), contactId1From0, null,
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sharer un-subscribes from forum
|
||||
forumManager0.removeForum(forum0);
|
||||
@@ -375,73 +378,15 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionIdReuse() throws Exception {
|
||||
// initialize and let invitee accept all requests
|
||||
listenToEvents(true);
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!");
|
||||
|
||||
// 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);
|
||||
|
||||
// forum was added successfully
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
|
||||
// reset event received state
|
||||
listener1.requestReceived = false;
|
||||
|
||||
// get SessionId from invitation
|
||||
List<InvitationMessage> list = new ArrayList<InvitationMessage>(
|
||||
forumSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
InvitationMessage msg = list.get(0);
|
||||
SessionId sessionId = msg.getSessionId();
|
||||
assertEquals(sessionId, list.get(1).getSessionId());
|
||||
|
||||
// get all sorts of stuff needed to send a message
|
||||
MessageQueueManager queue = c0.getMessageQueueManager();
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
Group group = contactGroupFactory.createContactGroup(CLIENT_ID, c1);
|
||||
long time = clock.currentTimeMillis();
|
||||
BdfList bodyList =
|
||||
BdfList.of(SHARE_MSG_TYPE_INVITATION, sessionId.getBytes(),
|
||||
getRandomString(42), getRandomBytes(FORUM_SALT_LENGTH));
|
||||
byte[] body = clientHelper.toByteArray(bodyList);
|
||||
|
||||
// add the message to the queue
|
||||
Transaction txn = db0.startTransaction(false);
|
||||
try {
|
||||
queue.sendMessage(txn, group, time, body, new Metadata());
|
||||
db0.commitTransaction(txn);
|
||||
} finally {
|
||||
db0.endTransaction(txn);
|
||||
}
|
||||
|
||||
// actually send the message
|
||||
sync0To1(1, false);
|
||||
// make sure there was no new request received
|
||||
assertFalse(listener1.requestReceived);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = ProtocolStateException.class)
|
||||
public void testSharingSameForumWithEachOther() throws Exception {
|
||||
// initialize and let invitee accept all requests
|
||||
listenToEvents(true);
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -455,24 +400,12 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// forum was added successfully
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
assertEquals(2,
|
||||
forumSharingManager0.getInvitationMessages(contactId1From0)
|
||||
.size());
|
||||
|
||||
// invitee now shares same forum back
|
||||
forumSharingManager1.sendInvitation(forum0.getId(),
|
||||
contactId0From1,
|
||||
"I am re-sharing this forum with you.");
|
||||
|
||||
// sync re-share invitation
|
||||
sync1To0(1, false);
|
||||
|
||||
// make sure that no new request was received
|
||||
assertFalse(listener0.requestReceived);
|
||||
assertEquals(2,
|
||||
forumSharingManager0.getInvitationMessages(contactId1From0)
|
||||
.size());
|
||||
assertEquals(0, forumSharingManager0.getInvitations().size());
|
||||
"I am re-sharing this forum with you.",
|
||||
clock.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -482,62 +415,48 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// invitee adds the same forum
|
||||
Transaction txn = db1.startTransaction(false);
|
||||
db1.addGroup(txn, forum0.getGroup());
|
||||
forumManager1.addForum(txn, forum0);
|
||||
db1.commitTransaction(txn);
|
||||
db1.endTransaction(txn);
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// invitee now shares same forum back
|
||||
forumSharingManager1.sendInvitation(forum0.getId(),
|
||||
contactId0From1, "I am re-sharing this forum with you.");
|
||||
contactId0From1, "I am re-sharing this forum with you.",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// find out who should be Alice, because of random keys
|
||||
Bytes key0 = new Bytes(author0.getPublicKey());
|
||||
Bytes key1 = new Bytes(author1.getPublicKey());
|
||||
// prevent automatic responses
|
||||
respond = false;
|
||||
|
||||
// only now sync first request message
|
||||
boolean alice = key1.compareTo(key0) < 0;
|
||||
if (alice) {
|
||||
sync0To1(1, false);
|
||||
assertFalse(listener1.requestReceived);
|
||||
} else {
|
||||
sync0To1(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener1.requestReceived);
|
||||
}
|
||||
sync0To1(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener1.requestReceived);
|
||||
|
||||
// sync second invitation
|
||||
alice = key0.compareTo(key1) < 0;
|
||||
if (alice) {
|
||||
sync1To0(1, false);
|
||||
assertFalse(listener0.requestReceived);
|
||||
// sync second invitation which counts as accept
|
||||
sync1To0(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.requestReceived);
|
||||
|
||||
// sharer did not receive request, but response to own request
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.responseReceived);
|
||||
// both peers should share the forum with each other now
|
||||
assertTrue(forumSharingManager0.getSharedWith(forum0.getId())
|
||||
.contains(contact1From0));
|
||||
assertTrue(forumSharingManager1.getSharedWith(forum0.getId())
|
||||
.contains(contact0From1));
|
||||
|
||||
assertEquals(2, forumSharingManager0
|
||||
.getInvitationMessages(contactId1From0).size());
|
||||
assertEquals(3, forumSharingManager1
|
||||
.getInvitationMessages(contactId0From1).size());
|
||||
} else {
|
||||
sync1To0(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.requestReceived);
|
||||
// and both have each other's invitations (and no response)
|
||||
assertEquals(2, forumSharingManager0
|
||||
.getInvitationMessages(contactId1From0).size());
|
||||
assertEquals(2, forumSharingManager1
|
||||
.getInvitationMessages(contactId0From1).size());
|
||||
|
||||
// send response from sharer to invitee and make sure it arrived
|
||||
sync0To1(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener1.responseReceived);
|
||||
|
||||
assertEquals(3, forumSharingManager0
|
||||
.getInvitationMessages(contactId1From0).size());
|
||||
assertEquals(2, forumSharingManager1
|
||||
.getInvitationMessages(contactId0From1).size());
|
||||
}
|
||||
// there are no more open invitations
|
||||
assertTrue(forumSharingManager0.getInvitations().isEmpty());
|
||||
assertTrue(forumSharingManager1.getInvitations().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -547,7 +466,8 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -564,18 +484,12 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(1,
|
||||
forumSharingManager0.getSharedWith(forum0.getId()).size());
|
||||
|
||||
// remember SessionId from invitation
|
||||
List<InvitationMessage> list = new ArrayList<InvitationMessage>(
|
||||
forumSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
InvitationMessage msg = list.get(0);
|
||||
SessionId sessionId = msg.getSessionId();
|
||||
assertEquals(sessionId, list.get(1).getSessionId());
|
||||
|
||||
// contacts now remove each other
|
||||
removeAllContacts();
|
||||
|
||||
// invitee still has forum
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
|
||||
// make sure sharer does share the forum with nobody now
|
||||
assertEquals(0,
|
||||
forumSharingManager0.getSharedWith(forum0.getId()).size());
|
||||
@@ -584,35 +498,30 @@ public class ForumSharingIntegrationTest
|
||||
addDefaultContacts();
|
||||
addContacts1And2();
|
||||
|
||||
// get all sorts of stuff needed to send a message
|
||||
MessageQueueManager queue = c0.getMessageQueueManager();
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
Group group = contactGroupFactory.createContactGroup(CLIENT_ID, c1);
|
||||
long time = clock.currentTimeMillis();
|
||||
// forum can be shared with contacts again
|
||||
assertTrue(forumSharingManager0
|
||||
.canBeShared(forum0.getId(), contact1From0));
|
||||
assertTrue(forumSharingManager0
|
||||
.canBeShared(forum0.getId(), contact2From0));
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// construct a new message re-using the old SessionId
|
||||
BdfList bodyList = BdfList.of(SHARE_MSG_TYPE_INVITATION,
|
||||
sessionId.getBytes(),
|
||||
getRandomString(42),
|
||||
getRandomBytes(FORUM_SALT_LENGTH)
|
||||
);
|
||||
byte[] body = clientHelper.toByteArray(bodyList);
|
||||
|
||||
// add the message to the queue
|
||||
Transaction txn = db0.startTransaction(false);
|
||||
try {
|
||||
queue.sendMessage(txn, group, time, body, new Metadata());
|
||||
db0.commitTransaction(txn);
|
||||
} finally {
|
||||
db0.endTransaction(txn);
|
||||
}
|
||||
|
||||
// actually send the message
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
// make sure the new request was received with the same sessionId
|
||||
// as proof that the state got deleted along with contacts
|
||||
assertTrue(listener1.requestReceived);
|
||||
|
||||
// sync response back
|
||||
sync1To0(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// forum is still there
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
assertEquals(1,
|
||||
forumSharingManager0.getSharedWith(forum0.getId()).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -633,14 +542,16 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
|
||||
// second sharer sends invitation for same forum
|
||||
assertTrue(contactId1From2 != null);
|
||||
forumSharingManager2
|
||||
.sendInvitation(forum0.getId(), contactId1From2, null);
|
||||
.sendInvitation(forum0.getId(), contactId1From2, null,
|
||||
clock.currentTimeMillis());
|
||||
// sync second request message
|
||||
sync2To1(1, true);
|
||||
|
||||
@@ -650,13 +561,6 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(1, forums.size());
|
||||
assertEquals(2, forums.iterator().next().getNewSharers().size());
|
||||
assertEquals(forum0, forums.iterator().next().getShareable());
|
||||
assertEquals(2,
|
||||
forumSharingManager1.getSharedWith(forum0.getId()).size());
|
||||
|
||||
// make sure both sharers actually share the forum
|
||||
Collection<Contact> contacts =
|
||||
forumSharingManager1.getSharedWith(forum0.getId());
|
||||
assertEquals(2, contacts.size());
|
||||
|
||||
// answer second request
|
||||
assertNotNull(contactId2From1);
|
||||
@@ -675,6 +579,11 @@ public class ForumSharingIntegrationTest
|
||||
sync1To0(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// make sure both sharers actually share the forum
|
||||
Collection<Contact> contacts =
|
||||
forumSharingManager1.getSharedWith(forum0.getId());
|
||||
assertEquals(2, contacts.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -684,7 +593,8 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -745,7 +655,8 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// send invitation again
|
||||
forumSharingManager0
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!");
|
||||
.sendInvitation(forum0.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
|
||||
// sync first request message
|
||||
sync0To1(1, true);
|
||||
@@ -799,8 +710,10 @@ public class ForumSharingIntegrationTest
|
||||
requestReceived = true;
|
||||
Forum f = event.getShareable();
|
||||
try {
|
||||
Contact c = contactManager0.getContact(contactId1From0);
|
||||
forumSharingManager0.respondToInvitation(f, c, true);
|
||||
if (respond) {
|
||||
Contact c = contactManager0.getContact(contactId1From0);
|
||||
forumSharingManager0.respondToInvitation(f, c, true);
|
||||
}
|
||||
} catch (DbException ex) {
|
||||
eventWaiter.rethrow(ex);
|
||||
} finally {
|
||||
@@ -814,7 +727,6 @@ public class ForumSharingIntegrationTest
|
||||
private class InviteeListener implements EventListener {
|
||||
|
||||
private volatile boolean requestReceived = false;
|
||||
private volatile boolean responseReceived = false;
|
||||
|
||||
private final boolean accept, answer;
|
||||
|
||||
@@ -836,13 +748,13 @@ public class ForumSharingIntegrationTest
|
||||
if (!answer) return;
|
||||
Forum f = event.getShareable();
|
||||
try {
|
||||
eventWaiter.assertEquals(1,
|
||||
forumSharingManager1.getInvitations().size());
|
||||
SharingInvitationItem invitation =
|
||||
forumSharingManager1.getInvitations().iterator()
|
||||
.next();
|
||||
eventWaiter.assertEquals(f, invitation.getShareable());
|
||||
if (respond) {
|
||||
eventWaiter.assertEquals(1,
|
||||
forumSharingManager1.getInvitations().size());
|
||||
SharingInvitationItem invitation =
|
||||
forumSharingManager1.getInvitations().iterator()
|
||||
.next();
|
||||
eventWaiter.assertEquals(f, invitation.getShareable());
|
||||
Contact c =
|
||||
contactManager1
|
||||
.getContact(event.getContactId());
|
||||
@@ -859,7 +771,6 @@ public class ForumSharingIntegrationTest
|
||||
ForumInvitationResponseReceivedEvent event =
|
||||
(ForumInvitationResponseReceivedEvent) e;
|
||||
eventWaiter.assertEquals(contactId0From1, event.getContactId());
|
||||
responseReceived = true;
|
||||
eventWaiter.resume();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user