Address review comments for new sharing client

This commit is contained in:
Torsten Grote
2017-01-03 11:40:54 -02:00
parent 694e662028
commit 51b78cf9b1
35 changed files with 322 additions and 231 deletions

View File

@@ -666,11 +666,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
oneOf(messageParser).parseMetadata(meta);
will(returnValue(messageMetadata1));
oneOf(db).getMessageStatus(txn, contactId, message.getId());
oneOf(clientHelper).getMessage(txn, message.getId());
will(returnValue(message));
oneOf(clientHelper).toList(message);
will(returnValue(body));
oneOf(messageParser).parseInviteMessage(message, body);
oneOf(messageParser).getInviteMessage(txn, message.getId());
will(returnValue(invite));
oneOf(privateGroupFactory).createPrivateGroup(invite.getGroupName(),
invite.getCreator(), invite.getSalt());
@@ -743,21 +739,13 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
contactGroup.getId(), query);
will(returnValue(results));
// message 1
oneOf(clientHelper).getMessage(txn, message.getId());
will(returnValue(message));
oneOf(clientHelper).toList(message);
will(returnValue(body));
oneOf(messageParser).parseInviteMessage(message, body);
oneOf(messageParser).getInviteMessage(txn, message.getId());
will(returnValue(inviteMessage1));
oneOf(privateGroupFactory).createPrivateGroup(groupName, author,
salt);
will(returnValue(pg));
// message 2
oneOf(clientHelper).getMessage(txn, messageId2);
will(returnValue(message2));
oneOf(clientHelper).toList(message2);
will(returnValue(body2));
oneOf(messageParser).parseInviteMessage(message2, body2);
oneOf(messageParser).getInviteMessage(txn, messageId2);
will(returnValue(inviteMessage2));
oneOf(privateGroupFactory).createPrivateGroup(groupName, author,
salt);

View File

@@ -144,11 +144,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
expectSendJoinMessage(properJoinMessage, true);
context.checking(new Expectations() {{
oneOf(messageTracker).trackOutgoingMessage(txn, message);
oneOf(clientHelper).getMessage(txn, lastRemoteMessageId);
will(returnValue(inviteMsg));
oneOf(clientHelper).toList(inviteMsg);
will(returnValue(inviteList));
oneOf(messageParser).parseInviteMessage(inviteMsg, inviteList);
oneOf(messageParser).getInviteMessage(txn, lastRemoteMessageId);
will(returnValue(inviteMessage));
oneOf(privateGroupFactory)
.createPrivateGroup(inviteMessage.getGroupName(),

View File

@@ -33,8 +33,6 @@ 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.getRandomString;
import static org.junit.Assert.assertEquals;
@@ -49,9 +47,6 @@ 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;

View File

@@ -3,6 +3,8 @@ package org.briarproject.briar.sharing;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.UniqueId;
import org.briarproject.bramble.api.client.BdfMessageContext;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.test.TestUtils;
@@ -20,7 +22,6 @@ import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.briar.api.forum.ForumConstants.FORUM_SALT_LENGTH;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_NAME_LENGTH;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_MESSAGE_LENGTH;
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_ABORT;
import static org.briarproject.briar.sharing.MessageType.ABORT;
import static org.briarproject.briar.sharing.MessageType.ACCEPT;
import static org.briarproject.briar.sharing.MessageType.DECLINE;
@@ -46,6 +47,8 @@ public class ForumSharingValidatorTest extends ValidatorTestCase {
private final BdfList descriptor = BdfList.of(forumName, salt);
private final String content =
TestUtils.getRandomString(MAX_INVITATION_MESSAGE_LENGTH);
private final BdfDictionary meta =
BdfDictionary.of(new BdfEntry("meta", "data"));
@Test
public void testAcceptsInvitationWithContent() throws Exception {
@@ -121,21 +124,20 @@ public class ForumSharingValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsInvalidMessageType() throws Exception {
int invalidMessageType = SHARE_MSG_TYPE_ABORT + 1;
int invalidMessageType = ABORT.getValue() + 1;
v.validateMessage(message, group,
BdfList.of(invalidMessageType, groupId, previousMsgId));
}
@Test(expected = FormatException.class)
public void testRejectsNullGroupId() throws Exception {
public void testRejectsNullSessionId() throws Exception {
v.validateMessage(message, group,
BdfList.of(ABORT.getValue(), null, previousMsgId));
}
@Test(expected = FormatException.class)
public void testRejectsNonRawSessionId() throws Exception {
v.validateMessage(message, group,
BdfList.of(SHARE_MSG_TYPE_ABORT, 123));
v.validateMessage(message, group, BdfList.of(ABORT.getValue(), 123));
}
@Test(expected = FormatException.class)
@@ -161,13 +163,13 @@ public class ForumSharingValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsTooLongBodyForAbort() throws Exception {
v.validateMessage(message, group,
BdfList.of(SHARE_MSG_TYPE_ABORT, groupId, previousMsgId, 123));
BdfList.of(ABORT.getValue(), groupId, previousMsgId, 123));
}
@Test(expected = FormatException.class)
public void testRejectsTooShortBodyForInvitation() throws Exception {
v.validateMessage(message, group,
BdfList.of(INVITE.getValue(), groupId, forumName));
BdfList.of(INVITE.getValue(), previousMsgId, descriptor));
}
@Test(expected = FormatException.class)
@@ -207,9 +209,10 @@ public class ForumSharingValidatorTest extends ValidatorTestCase {
BdfList validDescriptor = BdfList.of(shortForumName, salt);
expectCreateForum(shortForumName);
expectEncodeMetadata(INVITE);
v.validateMessage(message, group,
BdfMessageContext messageContext = v.validateMessage(message, group,
BdfList.of(INVITE.getValue(), previousMsgId, validDescriptor,
null));
assertExpectedContext(messageContext, previousMsgId);
}
@Test(expected = FormatException.class)
@@ -295,6 +298,7 @@ public class ForumSharingValidatorTest extends ValidatorTestCase {
oneOf(messageEncoder)
.encodeMetadata(type, groupId, timestamp, false, false,
false, false);
will(returnValue(meta));
}});
}
@@ -307,6 +311,7 @@ public class ForumSharingValidatorTest extends ValidatorTestCase {
assertEquals(1, dependencies.size());
assertTrue(dependencies.contains(previousMsgId));
}
assertEquals(meta, messageContext.getDictionary());
}
}