mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Factor MessageTracker out of BdfIncomingMessageHook.
This commit is contained in:
@@ -16,6 +16,7 @@ import org.briarproject.api.db.Transaction;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.InvalidMessageException;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageContext;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
@@ -37,8 +38,8 @@ import static org.briarproject.api.clients.QueueMessage.QUEUE_MESSAGE_HEADER_LEN
|
||||
import static org.briarproject.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
|
||||
@@ -152,7 +153,12 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
MessageValidator delegate = captured.get();
|
||||
assertNotNull(delegate);
|
||||
// The message should be invalid
|
||||
assertNull(delegate.validateMessage(message, group));
|
||||
try {
|
||||
delegate.validateMessage(message, group);
|
||||
fail();
|
||||
} catch (InvalidMessageException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -193,7 +199,12 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
MessageValidator delegate = captured.get();
|
||||
assertNotNull(delegate);
|
||||
// The message should be invalid
|
||||
assertNull(delegate.validateMessage(message, group));
|
||||
try {
|
||||
delegate.validateMessage(message, group);
|
||||
fail();
|
||||
} catch (InvalidMessageException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.TestUtils;
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.clients.ClientHelper;
|
||||
import org.briarproject.api.clients.MessageTracker;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
@@ -41,9 +42,6 @@ import static org.briarproject.api.introduction.IntroductionConstants.TYPE;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_REQUEST;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_RESPONSE;
|
||||
import static org.briarproject.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||
import static org.briarproject.clients.BdfConstants.GROUP_KEY_LATEST_MSG;
|
||||
import static org.briarproject.clients.BdfConstants.GROUP_KEY_MSG_COUNT;
|
||||
import static org.briarproject.clients.BdfConstants.GROUP_KEY_UNREAD_COUNT;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
@@ -54,6 +52,7 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
private final IntroduceeManager introduceeManager;
|
||||
private final DatabaseComponent db;
|
||||
private final ClientHelper clientHelper;
|
||||
private final MessageTracker messageTracker;
|
||||
private final IntroductionGroupFactory introductionGroupFactory;
|
||||
private final SessionId sessionId = new SessionId(TestUtils.getRandomId());
|
||||
private final long time = 42L;
|
||||
@@ -63,7 +62,6 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
private final Group introductionGroup2;
|
||||
private final Message message1;
|
||||
private Transaction txn;
|
||||
private BdfDictionary metadataBefore, metadataAfter;
|
||||
|
||||
public IntroductionManagerImplTest() {
|
||||
AuthorId authorId1 = new AuthorId(TestUtils.getRandomId());
|
||||
@@ -94,16 +92,6 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
time,
|
||||
TestUtils.getRandomBytes(MESSAGE_HEADER_LENGTH + 1)
|
||||
);
|
||||
metadataBefore = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_MSG_COUNT, 41),
|
||||
new BdfEntry(GROUP_KEY_UNREAD_COUNT, 0),
|
||||
new BdfEntry(GROUP_KEY_LATEST_MSG, 0)
|
||||
);
|
||||
metadataAfter = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_MSG_COUNT, 42),
|
||||
new BdfEntry(GROUP_KEY_UNREAD_COUNT, 0),
|
||||
new BdfEntry(GROUP_KEY_LATEST_MSG, time)
|
||||
);
|
||||
|
||||
// mock ALL THE THINGS!!!
|
||||
context = new Mockery();
|
||||
@@ -113,12 +101,12 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
db = context.mock(DatabaseComponent.class);
|
||||
clientHelper = context.mock(ClientHelper.class);
|
||||
MetadataParser metadataParser = context.mock(MetadataParser.class);
|
||||
messageTracker = context.mock(MessageTracker.class);
|
||||
introductionGroupFactory = context.mock(IntroductionGroupFactory.class);
|
||||
|
||||
introductionManager = new IntroductionManagerImpl(
|
||||
db, clientHelper, metadataParser, introducerManager,
|
||||
introduceeManager, introductionGroupFactory
|
||||
);
|
||||
introductionManager = new IntroductionManagerImpl(db, clientHelper,
|
||||
metadataParser, messageTracker, introducerManager,
|
||||
introduceeManager, introductionGroupFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,19 +127,11 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
.createIntroductionGroup(introducee2);
|
||||
will(returnValue(introductionGroup2));
|
||||
// track message for group 1
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
introductionGroup1.getId());
|
||||
will(returnValue(metadataBefore));
|
||||
oneOf(clientHelper)
|
||||
.mergeGroupMetadata(txn, introductionGroup1.getId(),
|
||||
metadataAfter);
|
||||
oneOf(messageTracker).trackMessage(txn,
|
||||
introductionGroup1.getId(), time, true);
|
||||
// track message for group 2
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
introductionGroup2.getId());
|
||||
will(returnValue(metadataBefore));
|
||||
oneOf(clientHelper)
|
||||
.mergeGroupMetadata(txn, introductionGroup2.getId(),
|
||||
metadataAfter);
|
||||
oneOf(messageTracker).trackMessage(txn,
|
||||
introductionGroup2.getId(), time, true);
|
||||
oneOf(db).commitTransaction(txn);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
@@ -181,12 +161,8 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(state));
|
||||
oneOf(introduceeManager).acceptIntroduction(txn, state, time);
|
||||
// track message
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
introductionGroup1.getId());
|
||||
will(returnValue(metadataBefore));
|
||||
oneOf(clientHelper)
|
||||
.mergeGroupMetadata(txn, introductionGroup1.getId(),
|
||||
metadataAfter);
|
||||
oneOf(messageTracker).trackMessage(txn,
|
||||
introductionGroup1.getId(), time, true);
|
||||
oneOf(db).commitTransaction(txn);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
@@ -216,12 +192,8 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(state));
|
||||
oneOf(introduceeManager).declineIntroduction(txn, state, time);
|
||||
// track message
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
introductionGroup1.getId());
|
||||
will(returnValue(metadataBefore));
|
||||
oneOf(clientHelper)
|
||||
.mergeGroupMetadata(txn, introductionGroup1.getId(),
|
||||
metadataAfter);
|
||||
oneOf(messageTracker).trackMessage(txn,
|
||||
introductionGroup1.getId(), time, true);
|
||||
oneOf(db).commitTransaction(txn);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
@@ -272,9 +244,6 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
final BdfDictionary state = new BdfDictionary();
|
||||
txn = new Transaction(null, false);
|
||||
|
||||
metadataBefore.put(GROUP_KEY_UNREAD_COUNT, 1);
|
||||
metadataAfter.put(GROUP_KEY_UNREAD_COUNT, 2);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(introduceeManager)
|
||||
.initialize(txn, introductionGroup1.getId(), msg);
|
||||
@@ -282,12 +251,7 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
oneOf(introduceeManager)
|
||||
.incomingMessage(txn, state, msg);
|
||||
// track message
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
introductionGroup1.getId());
|
||||
will(returnValue(metadataBefore));
|
||||
oneOf(clientHelper)
|
||||
.mergeGroupMetadata(txn, introductionGroup1.getId(),
|
||||
metadataAfter);
|
||||
oneOf(messageTracker).trackIncomingMessage(txn, message1);
|
||||
}});
|
||||
|
||||
introductionManager
|
||||
@@ -313,20 +277,12 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
|
||||
txn = new Transaction(null, false);
|
||||
|
||||
metadataBefore.put(GROUP_KEY_UNREAD_COUNT, 41);
|
||||
metadataAfter.put(GROUP_KEY_UNREAD_COUNT, 42);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, sessionId);
|
||||
will(returnValue(state));
|
||||
oneOf(introducerManager).incomingMessage(txn, state, msg);
|
||||
// track message
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
introductionGroup1.getId());
|
||||
will(returnValue(metadataBefore));
|
||||
oneOf(clientHelper)
|
||||
.mergeGroupMetadata(txn, introductionGroup1.getId(),
|
||||
metadataAfter);
|
||||
oneOf(messageTracker).trackIncomingMessage(txn, message1);
|
||||
}});
|
||||
|
||||
introductionManager
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.InvalidMessageException;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageContext;
|
||||
import org.briarproject.api.sync.MessageFactory;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.api.sync.ValidationManager.IncomingMessageHook;
|
||||
import org.briarproject.api.sync.ValidationManager.MessageValidator;
|
||||
@@ -74,6 +75,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -97,6 +100,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(txn1));
|
||||
oneOf(db).getRawMessage(txn1, messageId);
|
||||
will(returnValue(raw));
|
||||
oneOf(messageFactory).createMessage(messageId, raw);
|
||||
will(returnValue(message));
|
||||
oneOf(db).getGroup(txn1, groupId);
|
||||
will(returnValue(group));
|
||||
oneOf(db).commitTransaction(txn1);
|
||||
@@ -122,6 +127,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(txn3));
|
||||
oneOf(db).getRawMessage(txn3, messageId1);
|
||||
will(returnValue(raw));
|
||||
oneOf(messageFactory).createMessage(messageId1, raw);
|
||||
will(returnValue(message1));
|
||||
oneOf(db).getGroup(txn3, groupId);
|
||||
will(returnValue(group));
|
||||
oneOf(db).commitTransaction(txn3);
|
||||
@@ -159,7 +166,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.startService();
|
||||
@@ -173,6 +180,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -207,6 +216,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
// Get the message and its metadata to deliver
|
||||
oneOf(db).getRawMessage(txn2, messageId);
|
||||
will(returnValue(raw));
|
||||
oneOf(messageFactory).createMessage(messageId, raw);
|
||||
will(returnValue(message));
|
||||
oneOf(db).getGroup(txn2, groupId);
|
||||
will(returnValue(group));
|
||||
oneOf(db).getMessageMetadataForValidator(txn2, messageId);
|
||||
@@ -230,6 +241,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
// Get the dependent and its metadata to deliver
|
||||
oneOf(db).getRawMessage(txn3, messageId2);
|
||||
will(returnValue(raw));
|
||||
oneOf(messageFactory).createMessage(messageId2, raw);
|
||||
will(returnValue(message2));
|
||||
oneOf(db).getGroup(txn3, groupId);
|
||||
will(returnValue(group));
|
||||
oneOf(db).getMessageMetadataForValidator(txn3, messageId2);
|
||||
@@ -254,7 +267,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.startService();
|
||||
@@ -268,6 +281,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -319,7 +334,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.startService();
|
||||
@@ -333,6 +348,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -380,7 +397,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.eventOccurred(new MessageAddedEvent(message, contactId));
|
||||
@@ -395,6 +412,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -424,6 +443,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(txn2));
|
||||
oneOf(db).getRawMessage(txn2, messageId1);
|
||||
will(returnValue(raw));
|
||||
oneOf(messageFactory).createMessage(messageId1, raw);
|
||||
will(returnValue(message1));
|
||||
oneOf(db).getGroup(txn2, groupId);
|
||||
will(returnValue(group));
|
||||
oneOf(db).commitTransaction(txn2);
|
||||
@@ -461,7 +482,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.startService();
|
||||
@@ -476,6 +497,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -498,6 +521,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(txn1));
|
||||
oneOf(db).getRawMessage(txn1, messageId);
|
||||
will(returnValue(raw));
|
||||
oneOf(messageFactory).createMessage(messageId, raw);
|
||||
will(returnValue(message));
|
||||
// Load the group - *gasp* it's gone!
|
||||
oneOf(db).getGroup(txn1, groupId);
|
||||
will(throwException(new NoSuchGroupException()));
|
||||
@@ -508,6 +533,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(txn2));
|
||||
oneOf(db).getRawMessage(txn2, messageId1);
|
||||
will(returnValue(raw));
|
||||
oneOf(messageFactory).createMessage(messageId1, raw);
|
||||
will(returnValue(message1));
|
||||
oneOf(db).getGroup(txn2, groupId);
|
||||
will(returnValue(group));
|
||||
oneOf(db).commitTransaction(txn2);
|
||||
@@ -545,7 +572,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.startService();
|
||||
@@ -559,6 +586,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -591,7 +620,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.eventOccurred(new MessageAddedEvent(message, contactId));
|
||||
@@ -605,12 +634,14 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.eventOccurred(new MessageAddedEvent(message, null));
|
||||
@@ -626,6 +657,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -656,7 +689,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.eventOccurred(new MessageAddedEvent(message, contactId));
|
||||
@@ -671,6 +704,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -707,7 +742,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.eventOccurred(new MessageAddedEvent(message, contactId));
|
||||
@@ -722,6 +757,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -773,7 +810,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.eventOccurred(new MessageAddedEvent(message, contactId));
|
||||
@@ -787,6 +824,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -888,7 +927,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.eventOccurred(new MessageAddedEvent(message, contactId));
|
||||
@@ -902,6 +941,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -958,6 +999,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
// Get message 1 and its metadata
|
||||
oneOf(db).getRawMessage(txn2, messageId1);
|
||||
will(returnValue(raw));
|
||||
oneOf(messageFactory).createMessage(messageId1, raw);
|
||||
will(returnValue(message1));
|
||||
oneOf(db).getGroup(txn2, groupId);
|
||||
will(returnValue(group));
|
||||
oneOf(db).getMessageMetadataForValidator(txn2, messageId1);
|
||||
@@ -981,6 +1024,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
// Get message 2 and its metadata
|
||||
oneOf(db).getRawMessage(txn3, messageId2);
|
||||
will(returnValue(raw));
|
||||
oneOf(messageFactory).createMessage(messageId2, raw);
|
||||
will(returnValue(message2));
|
||||
oneOf(db).getGroup(txn3, groupId);
|
||||
will(returnValue(group));
|
||||
oneOf(db).getMessageMetadataForValidator(txn3, messageId2);
|
||||
@@ -1004,6 +1049,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
// Get message 3 and its metadata
|
||||
oneOf(db).getRawMessage(txn4, messageId3);
|
||||
will(returnValue(raw));
|
||||
oneOf(messageFactory).createMessage(messageId3, raw);
|
||||
will(returnValue(message3));
|
||||
oneOf(db).getGroup(txn4, groupId);
|
||||
will(returnValue(group));
|
||||
oneOf(db).getMessageMetadataForValidator(txn4, messageId3);
|
||||
@@ -1033,6 +1080,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
// Get message 4 and its metadata
|
||||
oneOf(db).getRawMessage(txn6, messageId4);
|
||||
will(returnValue(raw));
|
||||
oneOf(messageFactory).createMessage(messageId4, raw);
|
||||
will(returnValue(message4));
|
||||
oneOf(db).getGroup(txn6, groupId);
|
||||
will(returnValue(group));
|
||||
oneOf(db).getMessageMetadataForValidator(txn6, messageId4);
|
||||
@@ -1049,7 +1098,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.eventOccurred(new MessageAddedEvent(message, contactId));
|
||||
@@ -1063,6 +1112,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -1108,7 +1159,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.eventOccurred(new MessageAddedEvent(message, contactId));
|
||||
@@ -1125,6 +1176,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Executor dbExecutor = new ImmediateExecutor();
|
||||
final Executor cryptoExecutor = new ImmediateExecutor();
|
||||
final MessageFactory messageFactory =
|
||||
context.mock(MessageFactory.class);
|
||||
final MessageValidator validator = context.mock(MessageValidator.class);
|
||||
final IncomingMessageHook hook =
|
||||
context.mock(IncomingMessageHook.class);
|
||||
@@ -1178,7 +1231,7 @@ public class ValidationManagerImplTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
|
||||
cryptoExecutor);
|
||||
cryptoExecutor, messageFactory);
|
||||
vm.registerMessageValidator(clientId, validator);
|
||||
vm.registerIncomingMessageHook(clientId, hook);
|
||||
vm.eventOccurred(new MessageAddedEvent(message, contactId));
|
||||
|
||||
Reference in New Issue
Block a user