Minimise use of message constructor.

This commit is contained in:
akwizgran
2018-08-24 11:27:53 +01:00
parent d4a4351786
commit 27a169c6e2
18 changed files with 283 additions and 359 deletions

View File

@@ -40,6 +40,7 @@ public class TestUtils {
private static final AtomicInteger nextTestDir = private static final AtomicInteger nextTestDir =
new AtomicInteger((int) (Math.random() * 1000 * 1000)); new AtomicInteger((int) (Math.random() * 1000 * 1000));
private static final Random random = new Random(); private static final Random random = new Random();
private static final long timestamp = System.currentTimeMillis();
public static File getTestDirectory() { public static File getTestDirectory() {
int name = nextTestDir.getAndIncrement(); int name = nextTestDir.getAndIncrement();
@@ -101,9 +102,8 @@ public class TestUtils {
String name = getRandomString(nameLength); String name = getRandomString(nameLength);
byte[] publicKey = getRandomBytes(MAX_PUBLIC_KEY_LENGTH); byte[] publicKey = getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
byte[] privateKey = getRandomBytes(MAX_PUBLIC_KEY_LENGTH); byte[] privateKey = getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
long created = System.currentTimeMillis();
return new LocalAuthor(id, FORMAT_VERSION, name, publicKey, privateKey, return new LocalAuthor(id, FORMAT_VERSION, name, publicKey, privateKey,
created); timestamp);
} }
public static Author getAuthor() { public static Author getAuthor() {
@@ -137,7 +137,6 @@ public class TestUtils {
public static Message getMessage(GroupId groupId, int rawLength) { public static Message getMessage(GroupId groupId, int rawLength) {
MessageId id = new MessageId(getRandomId()); MessageId id = new MessageId(getRandomId());
byte[] raw = getRandomBytes(rawLength); byte[] raw = getRandomBytes(rawLength);
long timestamp = System.currentTimeMillis();
return new Message(id, groupId, timestamp, raw); return new Message(id, groupId, timestamp, raw);
} }

View File

@@ -18,6 +18,8 @@ import org.junit.Test;
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH; import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE; import static org.briarproject.bramble.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
@@ -28,8 +30,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
new BdfMessageValidator(clientHelper, metadataEncoder, clock) { new BdfMessageValidator(clientHelper, metadataEncoder, clock) {
@Override @Override
protected BdfMessageContext validateMessage(Message m, Group g, protected BdfMessageContext validateMessage(Message m, Group g,
BdfList body) BdfList body) {
throws InvalidMessageException, FormatException {
throw new AssertionError(); throw new AssertionError();
} }
}; };
@@ -69,7 +70,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
metadataEncoder, clock) { metadataEncoder, clock) {
@Override @Override
protected BdfMessageContext validateMessage(Message m, Group g, protected BdfMessageContext validateMessage(Message m, Group g,
BdfList b) throws InvalidMessageException, FormatException { BdfList b) {
assertSame(message, m); assertSame(message, m);
assertSame(group, g); assertSame(group, g);
assertSame(body, b); assertSame(body, b);
@@ -83,11 +84,12 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
@Test(expected = InvalidMessageException.class) @Test(expected = InvalidMessageException.class)
public void testRejectsTooShortMessage() throws Exception { public void testRejectsTooShortMessage() throws Exception {
byte[] invalidRaw = new byte[MESSAGE_HEADER_LENGTH]; byte[] invalidRaw = getRandomBytes(MESSAGE_HEADER_LENGTH);
// Use a mock message so the length of the raw message can be invalid // Use a mock message so the length of the raw message can be invalid
Message invalidMessage = context.mock(Message.class); Message invalidMessage = context.mock(Message.class);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
//noinspection ResultOfMethodCallIgnored
oneOf(invalidMessage).getTimestamp(); oneOf(invalidMessage).getTimestamp();
will(returnValue(timestamp)); will(returnValue(timestamp));
oneOf(clock).currentTimeMillis(); oneOf(clock).currentTimeMillis();
@@ -101,15 +103,13 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
@Test @Test
public void testAcceptsMinLengthMessage() throws Exception { public void testAcceptsMinLengthMessage() throws Exception {
byte[] shortRaw = new byte[MESSAGE_HEADER_LENGTH + 1]; Message shortMessage = getMessage(groupId, MESSAGE_HEADER_LENGTH + 1);
Message shortMessage =
new Message(messageId, groupId, timestamp, shortRaw);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(clock).currentTimeMillis(); oneOf(clock).currentTimeMillis();
will(returnValue(timestamp)); will(returnValue(timestamp));
oneOf(clientHelper).toList(shortRaw, MESSAGE_HEADER_LENGTH, oneOf(clientHelper).toList(shortMessage.getRaw(),
shortRaw.length - MESSAGE_HEADER_LENGTH); MESSAGE_HEADER_LENGTH, 1);
will(returnValue(body)); will(returnValue(body));
oneOf(metadataEncoder).encode(dictionary); oneOf(metadataEncoder).encode(dictionary);
will(returnValue(meta)); will(returnValue(meta));
@@ -120,7 +120,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
metadataEncoder, clock) { metadataEncoder, clock) {
@Override @Override
protected BdfMessageContext validateMessage(Message m, Group g, protected BdfMessageContext validateMessage(Message m, Group g,
BdfList b) throws InvalidMessageException, FormatException { BdfList b) {
assertSame(shortMessage, m); assertSame(shortMessage, m);
assertSame(group, g); assertSame(group, g);
assertSame(body, b); assertSame(body, b);
@@ -160,7 +160,7 @@ public class BdfMessageValidatorTest extends ValidatorTestCase {
metadataEncoder, clock) { metadataEncoder, clock) {
@Override @Override
protected BdfMessageContext validateMessage(Message m, Group g, protected BdfMessageContext validateMessage(Message m, Group g,
BdfList b) throws InvalidMessageException, FormatException { BdfList b) throws FormatException {
throw new FormatException(); throw new FormatException();
} }
}; };

View File

@@ -39,6 +39,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_N
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.briarproject.bramble.util.StringUtils.getRandomString;
@@ -67,11 +68,10 @@ public class ClientHelperImplTest extends BrambleTestCase {
private final GroupId groupId = new GroupId(getRandomId()); private final GroupId groupId = new GroupId(getRandomId());
private final BdfDictionary dictionary = new BdfDictionary(); private final BdfDictionary dictionary = new BdfDictionary();
private final long timestamp = 42L; private final Message message = getMessage(groupId);
private final byte[] rawMessage = getRandomBytes(42); private final MessageId messageId = message.getId();
private final MessageId messageId = new MessageId(getRandomId()); private final long timestamp = message.getTimestamp();
private final Message message = private final byte[] rawMessage = message.getRaw();
new Message(messageId, groupId, timestamp, rawMessage);
private final Metadata metadata = new Metadata(); private final Metadata metadata = new Metadata();
private final BdfList list = BdfList.of("Sign this!", getRandomBytes(42)); private final BdfList list = BdfList.of("Sign this!", getRandomBytes(42));
private final String label = StringUtils.getRandomString(5); private final String label = StringUtils.getRandomString(5);

View File

@@ -64,6 +64,7 @@ import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE; import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE; import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH;
import static org.briarproject.bramble.api.sync.ValidationManager.State.DELIVERED; import static org.briarproject.bramble.api.sync.ValidationManager.State.DELIVERED;
import static org.briarproject.bramble.api.sync.ValidationManager.State.UNKNOWN; import static org.briarproject.bramble.api.sync.ValidationManager.State.UNKNOWN;
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE; import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
@@ -72,6 +73,7 @@ import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getClientId; import static org.briarproject.bramble.test.TestUtils.getClientId;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.briarproject.bramble.test.TestUtils.getTransportId; import static org.briarproject.bramble.test.TestUtils.getTransportId;
@@ -97,10 +99,9 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
private final Group group; private final Group group;
private final Author author; private final Author author;
private final LocalAuthor localAuthor; private final LocalAuthor localAuthor;
private final MessageId messageId, messageId1;
private final int size;
private final byte[] raw;
private final Message message; private final Message message;
private final MessageId messageId, messageId1;
private final byte[] raw, raw1;
private final Metadata metadata; private final Metadata metadata;
private final TransportId transportId; private final TransportId transportId;
private final int maxLatency; private final int maxLatency;
@@ -115,12 +116,12 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
groupId = group.getId(); groupId = group.getId();
author = getAuthor(); author = getAuthor();
localAuthor = getLocalAuthor(); localAuthor = getLocalAuthor();
messageId = new MessageId(getRandomId()); message = getMessage(groupId);
messageId1 = new MessageId(getRandomId()); Message message1 = getMessage(groupId);
long timestamp = System.currentTimeMillis(); messageId = message.getId();
size = 1234; messageId1 = message1.getId();
raw = new byte[size]; raw = message.getRaw();
message = new Message(messageId, groupId, timestamp, raw); raw1 = message1.getRaw();
metadata = new Metadata(); metadata = new Metadata();
metadata.put("foo", new byte[] {'b', 'a', 'r'}); metadata.put("foo", new byte[] {'b', 'a', 'r'});
transportId = getTransportId(); transportId = getTransportId();
@@ -865,7 +866,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
@Test @Test
public void testGenerateBatch() throws Exception { public void testGenerateBatch() throws Exception {
byte[] raw1 = new byte[size];
Collection<MessageId> ids = Arrays.asList(messageId, messageId1); Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
Collection<byte[]> messages = Arrays.asList(raw, raw1); Collection<byte[]> messages = Arrays.asList(raw, raw1);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -873,7 +873,8 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
will(returnValue(txn)); will(returnValue(txn));
oneOf(database).containsContact(txn, contactId); oneOf(database).containsContact(txn, contactId);
will(returnValue(true)); will(returnValue(true));
oneOf(database).getMessagesToSend(txn, contactId, size * 2); oneOf(database).getMessagesToSend(txn, contactId,
MAX_MESSAGE_LENGTH * 2);
will(returnValue(ids)); will(returnValue(ids));
oneOf(database).getRawMessage(txn, messageId); oneOf(database).getRawMessage(txn, messageId);
will(returnValue(raw)); will(returnValue(raw));
@@ -893,7 +894,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
Transaction transaction = db.startTransaction(false); Transaction transaction = db.startTransaction(false);
try { try {
assertEquals(messages, db.generateBatch(transaction, contactId, assertEquals(messages, db.generateBatch(transaction, contactId,
size * 2, maxLatency)); MAX_MESSAGE_LENGTH * 2, maxLatency));
db.commitTransaction(transaction); db.commitTransaction(transaction);
} finally { } finally {
db.endTransaction(transaction); db.endTransaction(transaction);
@@ -961,7 +962,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
@Test @Test
public void testGenerateRequestedBatch() throws Exception { public void testGenerateRequestedBatch() throws Exception {
byte[] raw1 = new byte[size];
Collection<MessageId> ids = Arrays.asList(messageId, messageId1); Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
Collection<byte[]> messages = Arrays.asList(raw, raw1); Collection<byte[]> messages = Arrays.asList(raw, raw1);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -970,7 +970,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
oneOf(database).containsContact(txn, contactId); oneOf(database).containsContact(txn, contactId);
will(returnValue(true)); will(returnValue(true));
oneOf(database).getRequestedMessagesToSend(txn, contactId, oneOf(database).getRequestedMessagesToSend(txn, contactId,
size * 2); MAX_MESSAGE_LENGTH * 2);
will(returnValue(ids)); will(returnValue(ids));
oneOf(database).getRawMessage(txn, messageId); oneOf(database).getRawMessage(txn, messageId);
will(returnValue(raw)); will(returnValue(raw));
@@ -990,7 +990,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
Transaction transaction = db.startTransaction(false); Transaction transaction = db.startTransaction(false);
try { try {
assertEquals(messages, db.generateRequestedBatch(transaction, assertEquals(messages, db.generateRequestedBatch(transaction,
contactId, size * 2, maxLatency)); contactId, MAX_MESSAGE_LENGTH * 2, maxLatency));
db.commitTransaction(transaction); db.commitTransaction(transaction);
} finally { } finally {
db.endTransaction(transaction); db.endTransaction(transaction);

View File

@@ -53,7 +53,7 @@ import static org.briarproject.bramble.api.db.Metadata.REMOVE;
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE; import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE; import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH; import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
import static org.briarproject.bramble.api.sync.ValidationManager.State.DELIVERED; import static org.briarproject.bramble.api.sync.ValidationManager.State.DELIVERED;
import static org.briarproject.bramble.api.sync.ValidationManager.State.INVALID; import static org.briarproject.bramble.api.sync.ValidationManager.State.INVALID;
import static org.briarproject.bramble.api.sync.ValidationManager.State.PENDING; import static org.briarproject.bramble.api.sync.ValidationManager.State.PENDING;
@@ -62,7 +62,7 @@ import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getClientId; import static org.briarproject.bramble.test.TestUtils.getClientId;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.briarproject.bramble.test.TestUtils.getTestDirectory; import static org.briarproject.bramble.test.TestUtils.getTestDirectory;
@@ -89,11 +89,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
private final Group group; private final Group group;
private final Author author; private final Author author;
private final LocalAuthor localAuthor; private final LocalAuthor localAuthor;
private final MessageId messageId;
private final long timestamp;
private final int size;
private final byte[] raw;
private final Message message; private final Message message;
private final MessageId messageId;
private final TransportId transportId; private final TransportId transportId;
private final ContactId contactId; private final ContactId contactId;
private final KeySetId keySetId, keySetId1; private final KeySetId keySetId, keySetId1;
@@ -106,11 +103,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
groupId = group.getId(); groupId = group.getId();
author = getAuthor(); author = getAuthor();
localAuthor = getLocalAuthor(); localAuthor = getLocalAuthor();
messageId = new MessageId(getRandomId()); message = getMessage(groupId);
timestamp = System.currentTimeMillis(); messageId = message.getId();
size = 1234;
raw = getRandomBytes(size);
message = new Message(messageId, groupId, timestamp, raw);
transportId = getTransportId(); transportId = getTransportId();
contactId = new ContactId(1); contactId = new ContactId(1);
keySetId = new KeySetId(1); keySetId = new KeySetId(1);
@@ -150,8 +144,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
assertTrue(db.containsContact(txn, contactId)); assertTrue(db.containsContact(txn, contactId));
assertTrue(db.containsGroup(txn, groupId)); assertTrue(db.containsGroup(txn, groupId));
assertTrue(db.containsMessage(txn, messageId)); assertTrue(db.containsMessage(txn, messageId));
byte[] raw1 = db.getRawMessage(txn, messageId); assertArrayEquals(message.getRaw(), db.getRawMessage(txn, messageId));
assertArrayEquals(raw, raw1);
// Delete the records // Delete the records
db.removeMessage(txn, messageId); db.removeMessage(txn, messageId);
@@ -361,11 +354,11 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// The message is sendable, but too large to send // The message is sendable, but too large to send
Collection<MessageId> ids = db.getMessagesToSend(txn, contactId, Collection<MessageId> ids = db.getMessagesToSend(txn, contactId,
size - 1); message.getLength() - 1);
assertTrue(ids.isEmpty()); assertTrue(ids.isEmpty());
// The message is just the right size to send // The message is just the right size to send
ids = db.getMessagesToSend(txn, contactId, size); ids = db.getMessagesToSend(txn, contactId, message.getLength());
assertEquals(singletonList(messageId), ids); assertEquals(singletonList(messageId), ids);
db.commitTransaction(txn); db.commitTransaction(txn);
@@ -385,8 +378,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
db.addGroupVisibility(txn, contactId, groupId, false); db.addGroupVisibility(txn, contactId, groupId, false);
// Add some messages to ack // Add some messages to ack
MessageId messageId1 = new MessageId(getRandomId()); Message message1 = getMessage(groupId);
Message message1 = new Message(messageId1, groupId, timestamp, raw); MessageId messageId1 = message1.getId();
db.addMessage(txn, message, DELIVERED, true, contactId); db.addMessage(txn, message, DELIVERED, true, contactId);
db.addMessage(txn, message1, DELIVERED, true, contactId); db.addMessage(txn, message1, DELIVERED, true, contactId);
@@ -449,9 +442,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
@Test @Test
public void testGetFreeSpace() throws Exception { public void testGetFreeSpace() throws Exception {
byte[] largeBody = new byte[MAX_MESSAGE_LENGTH]; Message message = getMessage(groupId, MAX_MESSAGE_BODY_LENGTH);
for (int i = 0; i < largeBody.length; i++) largeBody[i] = (byte) i;
Message message = new Message(messageId, groupId, timestamp, largeBody);
Database<Connection> db = open(false); Database<Connection> db = open(false);
// Sanity check: there should be enough space on disk for this test // Sanity check: there should be enough space on disk for this test
@@ -1105,8 +1096,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
@Test @Test
public void testMetadataQueries() throws Exception { public void testMetadataQueries() throws Exception {
MessageId messageId1 = new MessageId(getRandomId()); Message message1 = getMessage(groupId);
Message message1 = new Message(messageId1, groupId, timestamp, raw); MessageId messageId1 = message1.getId();
Database<Connection> db = open(false); Database<Connection> db = open(false);
Connection txn = db.startTransaction(); Connection txn = db.startTransaction();
@@ -1209,8 +1200,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
@Test @Test
public void testMetadataQueriesOnlyForDeliveredMessages() throws Exception { public void testMetadataQueriesOnlyForDeliveredMessages() throws Exception {
MessageId messageId1 = new MessageId(getRandomId()); Message message1 = getMessage(groupId);
Message message1 = new Message(messageId1, groupId, timestamp, raw); MessageId messageId1 = message1.getId();
Database<Connection> db = open(false); Database<Connection> db = open(false);
Connection txn = db.startTransaction(); Connection txn = db.startTransaction();
@@ -1280,14 +1271,14 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
@Test @Test
public void testMessageDependencies() throws Exception { public void testMessageDependencies() throws Exception {
MessageId messageId1 = new MessageId(getRandomId()); Message message1 = getMessage(groupId);
MessageId messageId2 = new MessageId(getRandomId()); Message message2 = getMessage(groupId);
MessageId messageId3 = new MessageId(getRandomId()); Message message3 = getMessage(groupId);
MessageId messageId4 = new MessageId(getRandomId()); Message message4 = getMessage(groupId);
Message message1 = new Message(messageId1, groupId, timestamp, raw); MessageId messageId1 = message1.getId();
Message message2 = new Message(messageId2, groupId, timestamp, raw); MessageId messageId2 = message2.getId();
Message message3 = new Message(messageId3, groupId, timestamp, raw); MessageId messageId3 = message3.getId();
Message message4 = new Message(messageId4, groupId, timestamp, raw); MessageId messageId4 = message4.getId();
Database<Connection> db = open(false); Database<Connection> db = open(false);
Connection txn = db.startTransaction(); Connection txn = db.startTransaction();
@@ -1385,16 +1376,16 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
db.addGroup(txn, group1); db.addGroup(txn, group1);
// Add a message to the second group // Add a message to the second group
MessageId messageId1 = new MessageId(getRandomId()); Message message1 = getMessage(groupId1);
Message message1 = new Message(messageId1, groupId1, timestamp, raw); MessageId messageId1 = message1.getId();
db.addMessage(txn, message1, DELIVERED, true, contactId); db.addMessage(txn, message1, DELIVERED, true, contactId);
// Create an ID for a missing message // Create an ID for a missing message
MessageId messageId2 = new MessageId(getRandomId()); MessageId messageId2 = new MessageId(getRandomId());
// Add another message to the first group // Add another message to the first group
MessageId messageId3 = new MessageId(getRandomId()); Message message3 = getMessage(groupId);
Message message3 = new Message(messageId3, groupId, timestamp, raw); MessageId messageId3 = message3.getId();
db.addMessage(txn, message3, DELIVERED, true, contactId); db.addMessage(txn, message3, DELIVERED, true, contactId);
// Add dependencies between the messages // Add dependencies between the messages
@@ -1428,36 +1419,32 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
@Test @Test
public void testGetPendingMessagesForDelivery() throws Exception { public void testGetPendingMessagesForDelivery() throws Exception {
MessageId mId1 = new MessageId(getRandomId()); Message message1 = getMessage(groupId);
MessageId mId2 = new MessageId(getRandomId()); Message message2 = getMessage(groupId);
MessageId mId3 = new MessageId(getRandomId()); Message message3 = getMessage(groupId);
MessageId mId4 = new MessageId(getRandomId()); Message message4 = getMessage(groupId);
Message m1 = new Message(mId1, groupId, timestamp, raw);
Message m2 = new Message(mId2, groupId, timestamp, raw);
Message m3 = new Message(mId3, groupId, timestamp, raw);
Message m4 = new Message(mId4, groupId, timestamp, raw);
Database<Connection> db = open(false); Database<Connection> db = open(false);
Connection txn = db.startTransaction(); Connection txn = db.startTransaction();
// Add a group and some messages with different states // Add a group and some messages with different states
db.addGroup(txn, group); db.addGroup(txn, group);
db.addMessage(txn, m1, UNKNOWN, true, contactId); db.addMessage(txn, message1, UNKNOWN, true, contactId);
db.addMessage(txn, m2, INVALID, true, contactId); db.addMessage(txn, message2, INVALID, true, contactId);
db.addMessage(txn, m3, PENDING, true, contactId); db.addMessage(txn, message3, PENDING, true, contactId);
db.addMessage(txn, m4, DELIVERED, true, contactId); db.addMessage(txn, message4, DELIVERED, true, contactId);
Collection<MessageId> result; Collection<MessageId> result;
// Retrieve messages to be validated // Retrieve messages to be validated
result = db.getMessagesToValidate(txn); result = db.getMessagesToValidate(txn);
assertEquals(1, result.size()); assertEquals(1, result.size());
assertTrue(result.contains(mId1)); assertTrue(result.contains(message1.getId()));
// Retrieve pending messages // Retrieve pending messages
result = db.getPendingMessages(txn); result = db.getPendingMessages(txn);
assertEquals(1, result.size()); assertEquals(1, result.size());
assertTrue(result.contains(mId3)); assertTrue(result.contains(message3.getId()));
db.commitTransaction(txn); db.commitTransaction(txn);
db.close(); db.close();
@@ -1465,35 +1452,31 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
@Test @Test
public void testGetMessagesToShare() throws Exception { public void testGetMessagesToShare() throws Exception {
MessageId mId1 = new MessageId(getRandomId()); Message message1 = getMessage(groupId);
MessageId mId2 = new MessageId(getRandomId()); Message message2 = getMessage(groupId);
MessageId mId3 = new MessageId(getRandomId()); Message message3 = getMessage(groupId);
MessageId mId4 = new MessageId(getRandomId()); Message message4 = getMessage(groupId);
Message m1 = new Message(mId1, groupId, timestamp, raw);
Message m2 = new Message(mId2, groupId, timestamp, raw);
Message m3 = new Message(mId3, groupId, timestamp, raw);
Message m4 = new Message(mId4, groupId, timestamp, raw);
Database<Connection> db = open(false); Database<Connection> db = open(false);
Connection txn = db.startTransaction(); Connection txn = db.startTransaction();
// Add a group and some messages // Add a group and some messages
db.addGroup(txn, group); db.addGroup(txn, group);
db.addMessage(txn, m1, DELIVERED, true, contactId); db.addMessage(txn, message1, DELIVERED, true, contactId);
db.addMessage(txn, m2, DELIVERED, false, contactId); db.addMessage(txn, message2, DELIVERED, false, contactId);
db.addMessage(txn, m3, DELIVERED, false, contactId); db.addMessage(txn, message3, DELIVERED, false, contactId);
db.addMessage(txn, m4, DELIVERED, true, contactId); db.addMessage(txn, message4, DELIVERED, true, contactId);
// Introduce dependencies between the messages // Introduce dependencies between the messages
db.addMessageDependency(txn, m1, mId2, DELIVERED); db.addMessageDependency(txn, message1, message2.getId(), DELIVERED);
db.addMessageDependency(txn, m3, mId1, DELIVERED); db.addMessageDependency(txn, message3, message1.getId(), DELIVERED);
db.addMessageDependency(txn, m4, mId3, DELIVERED); db.addMessageDependency(txn, message4, message3.getId(), DELIVERED);
// Retrieve messages to be shared // Retrieve messages to be shared
Collection<MessageId> result = db.getMessagesToShare(txn); Collection<MessageId> result = db.getMessagesToShare(txn);
assertEquals(2, result.size()); assertEquals(2, result.size());
assertTrue(result.contains(mId2)); assertTrue(result.contains(message2.getId()));
assertTrue(result.contains(mId3)); assertTrue(result.contains(message3.getId()));
db.commitTransaction(txn); db.commitTransaction(txn);
db.close(); db.close();
@@ -1656,7 +1639,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
assertEquals(singletonList(messageId), ids); assertEquals(singletonList(messageId), ids);
// The raw message should be available // The raw message should be available
assertArrayEquals(raw, db.getRawMessage(txn, messageId)); assertArrayEquals(message.getRaw(), db.getRawMessage(txn, messageId));
// Delete the message // Delete the message
db.deleteMessage(txn, messageId); db.deleteMessage(txn, messageId);

View File

@@ -34,11 +34,10 @@ import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID; import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
import static org.briarproject.bramble.api.properties.TransportPropertyManager.MAJOR_VERSION; import static org.briarproject.bramble.api.properties.TransportPropertyManager.MAJOR_VERSION;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@@ -187,8 +186,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
throws Exception { throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
GroupId contactGroupId = new GroupId(getRandomId()); GroupId contactGroupId = new GroupId(getRandomId());
long timestamp = 123456789; Message message = getMessage(contactGroupId);
Message message = getMessage(contactGroupId, timestamp);
Metadata meta = new Metadata(); Metadata meta = new Metadata();
BdfDictionary metaDictionary = BdfDictionary.of( BdfDictionary metaDictionary = BdfDictionary.of(
new BdfEntry("transportId", "foo"), new BdfEntry("transportId", "foo"),
@@ -229,8 +227,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
throws Exception { throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
GroupId contactGroupId = new GroupId(getRandomId()); GroupId contactGroupId = new GroupId(getRandomId());
long timestamp = 123456789; Message message = getMessage(contactGroupId);
Message message = getMessage(contactGroupId, timestamp);
Metadata meta = new Metadata(); Metadata meta = new Metadata();
// Version 4 is being delivered // Version 4 is being delivered
BdfDictionary metaDictionary = BdfDictionary.of( BdfDictionary metaDictionary = BdfDictionary.of(
@@ -267,8 +264,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
public void testDeletesObsoleteUpdateWhenDelivered() throws Exception { public void testDeletesObsoleteUpdateWhenDelivered() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
GroupId contactGroupId = new GroupId(getRandomId()); GroupId contactGroupId = new GroupId(getRandomId());
long timestamp = 123456789; Message message = getMessage(contactGroupId);
Message message = getMessage(contactGroupId, timestamp);
Metadata meta = new Metadata(); Metadata meta = new Metadata();
// Version 3 is being delivered // Version 3 is being delivered
BdfDictionary metaDictionary = BdfDictionary.of( BdfDictionary metaDictionary = BdfDictionary.of(
@@ -619,12 +615,6 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
true, active); true, active);
} }
private Message getMessage(GroupId g, long timestamp) {
MessageId messageId = new MessageId(getRandomId());
byte[] raw = getRandomBytes(MAX_MESSAGE_BODY_LENGTH);
return new Message(messageId, g, timestamp, raw);
}
private void expectGetLocalProperties(Transaction txn) throws Exception { private void expectGetLocalProperties(Transaction txn) throws Exception {
Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>(); Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>();
// The latest update for transport "foo" should be returned // The latest update for transport "foo" should be returned
@@ -664,9 +654,9 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
private void expectStoreMessage(Transaction txn, GroupId g, private void expectStoreMessage(Transaction txn, GroupId g,
String transportId, BdfDictionary properties, long version, String transportId, BdfDictionary properties, long version,
boolean local, boolean shared) throws Exception { boolean local, boolean shared) throws Exception {
long timestamp = 123456789;
BdfList body = BdfList.of(transportId, version, properties); BdfList body = BdfList.of(transportId, version, properties);
Message message = getMessage(g, timestamp); Message message = getMessage(g);
long timestamp = message.getTimestamp();
BdfDictionary meta = BdfDictionary.of( BdfDictionary meta = BdfDictionary.of(
new BdfEntry("transportId", transportId), new BdfEntry("transportId", transportId),
new BdfEntry("version", version), new BdfEntry("version", version),

View File

@@ -18,6 +18,7 @@ import java.util.Collections;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_IDS; import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_IDS;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
public class SimplexOutgoingSessionTest extends BrambleMockTestCase { public class SimplexOutgoingSessionTest extends BrambleMockTestCase {
@@ -72,7 +73,7 @@ public class SimplexOutgoingSessionTest extends BrambleMockTestCase {
@Test @Test
public void testSomethingToSend() throws Exception { public void testSomethingToSend() throws Exception {
Ack ack = new Ack(Collections.singletonList(messageId)); Ack ack = new Ack(Collections.singletonList(messageId));
byte[] raw = new byte[1234]; byte[] raw = getRandomBytes(1234);
SimplexOutgoingSession session = new SimplexOutgoingSession(db, SimplexOutgoingSession session = new SimplexOutgoingSession(db,
dbExecutor, eventBus, contactId, MAX_LATENCY, streamWriter, dbExecutor, eventBus, contactId, MAX_LATENCY, streamWriter,
recordWriter); recordWriter);

View File

@@ -1,6 +1,5 @@
package org.briarproject.bramble.sync; package org.briarproject.bramble.sync;
import org.briarproject.bramble.api.UniqueId;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.Metadata; import org.briarproject.bramble.api.db.Metadata;
@@ -21,23 +20,26 @@ import org.briarproject.bramble.api.sync.ValidationManager.State;
import org.briarproject.bramble.api.sync.event.MessageAddedEvent; import org.briarproject.bramble.api.sync.event.MessageAddedEvent;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.ImmediateExecutor; import org.briarproject.bramble.test.ImmediateExecutor;
import org.briarproject.bramble.util.ByteUtils;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.briarproject.bramble.api.sync.ValidationManager.State.DELIVERED; import static org.briarproject.bramble.api.sync.ValidationManager.State.DELIVERED;
import static org.briarproject.bramble.api.sync.ValidationManager.State.INVALID; import static org.briarproject.bramble.api.sync.ValidationManager.State.INVALID;
import static org.briarproject.bramble.api.sync.ValidationManager.State.PENDING; import static org.briarproject.bramble.api.sync.ValidationManager.State.PENDING;
import static org.briarproject.bramble.api.sync.ValidationManager.State.UNKNOWN; import static org.briarproject.bramble.api.sync.ValidationManager.State.UNKNOWN;
import static org.briarproject.bramble.test.TestUtils.getClientId; import static org.briarproject.bramble.test.TestUtils.getClientId;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
public class ValidationManagerImplTest extends BrambleMockTestCase { public class ValidationManagerImplTest extends BrambleMockTestCase {
@@ -54,34 +56,23 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
private final Executor validationExecutor = new ImmediateExecutor(); private final Executor validationExecutor = new ImmediateExecutor();
private final ClientId clientId = getClientId(); private final ClientId clientId = getClientId();
private final int majorVersion = 123; private final int majorVersion = 123;
private final MessageId messageId = new MessageId(getRandomId());
private final MessageId messageId1 = new MessageId(getRandomId());
private final MessageId messageId2 = new MessageId(getRandomId());
private final Group group = getGroup(clientId, majorVersion); private final Group group = getGroup(clientId, majorVersion);
private final GroupId groupId = group.getId(); private final GroupId groupId = group.getId();
private final long timestamp = System.currentTimeMillis(); private final Message message = getMessage(groupId);
private final byte[] raw = new byte[123]; private final Message message1 = getMessage(groupId);
private final Message message = new Message(messageId, groupId, timestamp, private final Message message2 = getMessage(groupId);
raw); private final MessageId messageId = message.getId();
private final Message message1 = new Message(messageId1, groupId, timestamp, private final MessageId messageId1 = message1.getId();
raw); private final MessageId messageId2 = message2.getId();
private final Message message2 = new Message(messageId2, groupId, timestamp,
raw);
private final Metadata metadata = new Metadata(); private final Metadata metadata = new Metadata();
private final MessageContext validResult = new MessageContext(metadata); private final MessageContext validResult = new MessageContext(metadata);
private final ContactId contactId = new ContactId(234); private final ContactId contactId = new ContactId(234);
private final MessageContext validResultWithDependencies = private final MessageContext validResultWithDependencies =
new MessageContext(metadata, Collections.singletonList(messageId1)); new MessageContext(metadata, singletonList(messageId1));
private ValidationManagerImpl vm; private ValidationManagerImpl vm;
public ValidationManagerImplTest() {
// Encode the messages
System.arraycopy(groupId.getBytes(), 0, raw, 0, UniqueId.LENGTH);
ByteUtils.writeUint64(timestamp, raw, UniqueId.LENGTH);
}
@Before @Before
public void setUp() { public void setUp() {
vm = new ValidationManagerImpl(db, dbExecutor, validationExecutor, vm = new ValidationManagerImpl(db, dbExecutor, validationExecutor,
@@ -101,21 +92,21 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn)); will(returnValue(txn));
oneOf(db).getMessagesToValidate(txn); oneOf(db).getMessagesToValidate(txn);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn); oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn); oneOf(db).endTransaction(txn);
// deliverOutstandingMessages() // deliverOutstandingMessages()
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn1)); will(returnValue(txn1));
oneOf(db).getPendingMessages(txn1); oneOf(db).getPendingMessages(txn1);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn1); oneOf(db).commitTransaction(txn1);
oneOf(db).endTransaction(txn1); oneOf(db).endTransaction(txn1);
// shareOutstandingMessages() // shareOutstandingMessages()
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn2)); will(returnValue(txn2));
oneOf(db).getMessagesToShare(txn2); oneOf(db).getMessagesToShare(txn2);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn2); oneOf(db).commitTransaction(txn2);
oneOf(db).endTransaction(txn2); oneOf(db).endTransaction(txn2);
}}); }});
@@ -146,8 +137,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn1)); will(returnValue(txn1));
oneOf(db).getRawMessage(txn1, messageId); oneOf(db).getRawMessage(txn1, messageId);
will(returnValue(raw)); will(returnValue(message.getRaw()));
oneOf(messageFactory).createMessage(messageId, raw); oneOf(messageFactory).createMessage(messageId, message.getRaw());
will(returnValue(message)); will(returnValue(message));
oneOf(db).getGroup(txn1, groupId); oneOf(db).getGroup(txn1, groupId);
will(returnValue(group)); will(returnValue(group));
@@ -166,15 +157,15 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setMessageState(txn2, messageId, DELIVERED); oneOf(db).setMessageState(txn2, messageId, DELIVERED);
// Get any pending dependents // Get any pending dependents
oneOf(db).getMessageDependents(txn2, messageId); oneOf(db).getMessageDependents(txn2, messageId);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn2); oneOf(db).commitTransaction(txn2);
oneOf(db).endTransaction(txn2); oneOf(db).endTransaction(txn2);
// Load the second raw message and group // Load the second raw message and group
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn3)); will(returnValue(txn3));
oneOf(db).getRawMessage(txn3, messageId1); oneOf(db).getRawMessage(txn3, messageId1);
will(returnValue(raw)); will(returnValue(message1.getRaw()));
oneOf(messageFactory).createMessage(messageId1, raw); oneOf(messageFactory).createMessage(messageId1, message1.getRaw());
will(returnValue(message1)); will(returnValue(message1));
oneOf(db).getGroup(txn3, groupId); oneOf(db).getGroup(txn3, groupId);
will(returnValue(group)); will(returnValue(group));
@@ -193,21 +184,21 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).deleteMessageMetadata(txn4, messageId1); oneOf(db).deleteMessageMetadata(txn4, messageId1);
// Recursively invalidate any dependents // Recursively invalidate any dependents
oneOf(db).getMessageDependents(txn4, messageId1); oneOf(db).getMessageDependents(txn4, messageId1);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn4); oneOf(db).commitTransaction(txn4);
oneOf(db).endTransaction(txn4); oneOf(db).endTransaction(txn4);
// Get pending messages to deliver // Get pending messages to deliver
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn5)); will(returnValue(txn5));
oneOf(db).getPendingMessages(txn5); oneOf(db).getPendingMessages(txn5);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn5); oneOf(db).commitTransaction(txn5);
oneOf(db).endTransaction(txn5); oneOf(db).endTransaction(txn5);
// Get messages to share // Get messages to share
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn6)); will(returnValue(txn6));
oneOf(db).getMessagesToShare(txn6); oneOf(db).getMessagesToShare(txn6);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn6); oneOf(db).commitTransaction(txn6);
oneOf(db).endTransaction(txn6); oneOf(db).endTransaction(txn6);
}}); }});
@@ -228,14 +219,14 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn)); will(returnValue(txn));
oneOf(db).getMessagesToValidate(txn); oneOf(db).getMessagesToValidate(txn);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn); oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn); oneOf(db).endTransaction(txn);
// Get pending messages to deliver // Get pending messages to deliver
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn1)); will(returnValue(txn1));
oneOf(db).getPendingMessages(txn1); oneOf(db).getPendingMessages(txn1);
will(returnValue(Collections.singletonList(messageId))); will(returnValue(singletonList(messageId)));
oneOf(db).commitTransaction(txn1); oneOf(db).commitTransaction(txn1);
oneOf(db).endTransaction(txn1); oneOf(db).endTransaction(txn1);
// Check whether the message is ready to deliver // Check whether the message is ready to deliver
@@ -244,11 +235,11 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).getMessageState(txn2, messageId); oneOf(db).getMessageState(txn2, messageId);
will(returnValue(PENDING)); will(returnValue(PENDING));
oneOf(db).getMessageDependencies(txn2, messageId); oneOf(db).getMessageDependencies(txn2, messageId);
will(returnValue(Collections.singletonMap(messageId1, DELIVERED))); will(returnValue(singletonMap(messageId1, DELIVERED)));
// Get the message and its metadata to deliver // Get the message and its metadata to deliver
oneOf(db).getRawMessage(txn2, messageId); oneOf(db).getRawMessage(txn2, messageId);
will(returnValue(raw)); will(returnValue(message.getRaw()));
oneOf(messageFactory).createMessage(messageId, raw); oneOf(messageFactory).createMessage(messageId, message.getRaw());
will(returnValue(message)); will(returnValue(message));
oneOf(db).getGroup(txn2, groupId); oneOf(db).getGroup(txn2, groupId);
will(returnValue(group)); will(returnValue(group));
@@ -260,7 +251,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setMessageState(txn2, messageId, DELIVERED); oneOf(db).setMessageState(txn2, messageId, DELIVERED);
// Get any pending dependents // Get any pending dependents
oneOf(db).getMessageDependents(txn2, messageId); oneOf(db).getMessageDependents(txn2, messageId);
will(returnValue(Collections.singletonMap(messageId2, PENDING))); will(returnValue(singletonMap(messageId2, PENDING)));
oneOf(db).commitTransaction(txn2); oneOf(db).commitTransaction(txn2);
oneOf(db).endTransaction(txn2); oneOf(db).endTransaction(txn2);
// Check whether the dependent is ready to deliver // Check whether the dependent is ready to deliver
@@ -269,11 +260,11 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).getMessageState(txn3, messageId2); oneOf(db).getMessageState(txn3, messageId2);
will(returnValue(PENDING)); will(returnValue(PENDING));
oneOf(db).getMessageDependencies(txn3, messageId2); oneOf(db).getMessageDependencies(txn3, messageId2);
will(returnValue(Collections.singletonMap(messageId1, DELIVERED))); will(returnValue(singletonMap(messageId1, DELIVERED)));
// Get the dependent and its metadata to deliver // Get the dependent and its metadata to deliver
oneOf(db).getRawMessage(txn3, messageId2); oneOf(db).getRawMessage(txn3, messageId2);
will(returnValue(raw)); will(returnValue(message2.getRaw()));
oneOf(messageFactory).createMessage(messageId2, raw); oneOf(messageFactory).createMessage(messageId2, message2.getRaw());
will(returnValue(message2)); will(returnValue(message2));
oneOf(db).getGroup(txn3, groupId); oneOf(db).getGroup(txn3, groupId);
will(returnValue(group)); will(returnValue(group));
@@ -285,7 +276,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setMessageState(txn3, messageId2, DELIVERED); oneOf(db).setMessageState(txn3, messageId2, DELIVERED);
// Get any pending dependents // Get any pending dependents
oneOf(db).getMessageDependents(txn3, messageId2); oneOf(db).getMessageDependents(txn3, messageId2);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn3); oneOf(db).commitTransaction(txn3);
oneOf(db).endTransaction(txn3); oneOf(db).endTransaction(txn3);
@@ -293,7 +284,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn4)); will(returnValue(txn4));
oneOf(db).getMessagesToShare(txn4); oneOf(db).getMessagesToShare(txn4);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn4); oneOf(db).commitTransaction(txn4);
oneOf(db).endTransaction(txn4); oneOf(db).endTransaction(txn4);
}}); }});
@@ -314,14 +305,14 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn)); will(returnValue(txn));
oneOf(db).getMessagesToValidate(txn); oneOf(db).getMessagesToValidate(txn);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn); oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn); oneOf(db).endTransaction(txn);
// No pending messages to deliver // No pending messages to deliver
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn1)); will(returnValue(txn1));
oneOf(db).getPendingMessages(txn1); oneOf(db).getPendingMessages(txn1);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn1); oneOf(db).commitTransaction(txn1);
oneOf(db).endTransaction(txn1); oneOf(db).endTransaction(txn1);
@@ -329,7 +320,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn2)); will(returnValue(txn2));
oneOf(db).getMessagesToShare(txn2); oneOf(db).getMessagesToShare(txn2);
will(returnValue(Collections.singletonList(messageId))); will(returnValue(singletonList(messageId)));
oneOf(db).commitTransaction(txn2); oneOf(db).commitTransaction(txn2);
oneOf(db).endTransaction(txn2); oneOf(db).endTransaction(txn2);
// Share message and get dependencies // Share message and get dependencies
@@ -337,7 +328,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
will(returnValue(txn3)); will(returnValue(txn3));
oneOf(db).setMessageShared(txn3, messageId); oneOf(db).setMessageShared(txn3, messageId);
oneOf(db).getMessageDependencies(txn3, messageId); oneOf(db).getMessageDependencies(txn3, messageId);
will(returnValue(Collections.singletonMap(messageId2, DELIVERED))); will(returnValue(singletonMap(messageId2, DELIVERED)));
oneOf(db).commitTransaction(txn3); oneOf(db).commitTransaction(txn3);
oneOf(db).endTransaction(txn3); oneOf(db).endTransaction(txn3);
// Share dependency // Share dependency
@@ -345,7 +336,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
will(returnValue(txn4)); will(returnValue(txn4));
oneOf(db).setMessageShared(txn4, messageId2); oneOf(db).setMessageShared(txn4, messageId2);
oneOf(db).getMessageDependencies(txn4, messageId2); oneOf(db).getMessageDependencies(txn4, messageId2);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn4); oneOf(db).commitTransaction(txn4);
oneOf(db).endTransaction(txn4); oneOf(db).endTransaction(txn4);
}}); }});
@@ -376,7 +367,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).addMessageDependencies(txn1, message, oneOf(db).addMessageDependencies(txn1, message,
validResultWithDependencies.getDependencies()); validResultWithDependencies.getDependencies());
oneOf(db).getMessageDependencies(txn1, messageId); oneOf(db).getMessageDependencies(txn1, messageId);
will(returnValue(Collections.singletonMap(messageId1, DELIVERED))); will(returnValue(singletonMap(messageId1, DELIVERED)));
oneOf(db).mergeMessageMetadata(txn1, messageId, metadata); oneOf(db).mergeMessageMetadata(txn1, messageId, metadata);
// Deliver the message // Deliver the message
oneOf(hook).incomingMessage(txn1, message, metadata); oneOf(hook).incomingMessage(txn1, message, metadata);
@@ -384,7 +375,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setMessageState(txn1, messageId, DELIVERED); oneOf(db).setMessageState(txn1, messageId, DELIVERED);
// Get any pending dependents // Get any pending dependents
oneOf(db).getMessageDependents(txn1, messageId); oneOf(db).getMessageDependents(txn1, messageId);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
// Share message // Share message
oneOf(db).setMessageShared(txn1, messageId); oneOf(db).setMessageShared(txn1, messageId);
oneOf(db).commitTransaction(txn1); oneOf(db).commitTransaction(txn1);
@@ -394,7 +385,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
will(returnValue(txn2)); will(returnValue(txn2));
oneOf(db).setMessageShared(txn2, messageId1); oneOf(db).setMessageShared(txn2, messageId1);
oneOf(db).getMessageDependencies(txn2, messageId1); oneOf(db).getMessageDependencies(txn2, messageId1);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn2); oneOf(db).commitTransaction(txn2);
oneOf(db).endTransaction(txn2); oneOf(db).endTransaction(txn2);
}}); }});
@@ -431,8 +422,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn2)); will(returnValue(txn2));
oneOf(db).getRawMessage(txn2, messageId1); oneOf(db).getRawMessage(txn2, messageId1);
will(returnValue(raw)); will(returnValue(message1.getRaw()));
oneOf(messageFactory).createMessage(messageId1, raw); oneOf(messageFactory).createMessage(messageId1, message1.getRaw());
will(returnValue(message1)); will(returnValue(message1));
oneOf(db).getGroup(txn2, groupId); oneOf(db).getGroup(txn2, groupId);
will(returnValue(group)); will(returnValue(group));
@@ -451,21 +442,21 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).deleteMessageMetadata(txn3, messageId1); oneOf(db).deleteMessageMetadata(txn3, messageId1);
// Recursively invalidate dependents // Recursively invalidate dependents
oneOf(db).getMessageDependents(txn3, messageId1); oneOf(db).getMessageDependents(txn3, messageId1);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn3); oneOf(db).commitTransaction(txn3);
oneOf(db).endTransaction(txn3); oneOf(db).endTransaction(txn3);
// Get pending messages to deliver // Get pending messages to deliver
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn4)); will(returnValue(txn4));
oneOf(db).getPendingMessages(txn4); oneOf(db).getPendingMessages(txn4);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn4); oneOf(db).commitTransaction(txn4);
oneOf(db).endTransaction(txn4); oneOf(db).endTransaction(txn4);
// Get messages to share // Get messages to share
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn5)); will(returnValue(txn5));
oneOf(db).getMessagesToShare(txn5); oneOf(db).getMessagesToShare(txn5);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn5); oneOf(db).commitTransaction(txn5);
oneOf(db).endTransaction(txn5); oneOf(db).endTransaction(txn5);
}}); }});
@@ -495,8 +486,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn1)); will(returnValue(txn1));
oneOf(db).getRawMessage(txn1, messageId); oneOf(db).getRawMessage(txn1, messageId);
will(returnValue(raw)); will(returnValue(message.getRaw()));
oneOf(messageFactory).createMessage(messageId, raw); oneOf(messageFactory).createMessage(messageId, message.getRaw());
will(returnValue(message)); will(returnValue(message));
// Load the group - *gasp* it's gone! // Load the group - *gasp* it's gone!
oneOf(db).getGroup(txn1, groupId); oneOf(db).getGroup(txn1, groupId);
@@ -507,8 +498,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn2)); will(returnValue(txn2));
oneOf(db).getRawMessage(txn2, messageId1); oneOf(db).getRawMessage(txn2, messageId1);
will(returnValue(raw)); will(returnValue(message1.getRaw()));
oneOf(messageFactory).createMessage(messageId1, raw); oneOf(messageFactory).createMessage(messageId1, message1.getRaw());
will(returnValue(message1)); will(returnValue(message1));
oneOf(db).getGroup(txn2, groupId); oneOf(db).getGroup(txn2, groupId);
will(returnValue(group)); will(returnValue(group));
@@ -527,21 +518,21 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).deleteMessageMetadata(txn3, messageId1); oneOf(db).deleteMessageMetadata(txn3, messageId1);
// Recursively invalidate dependents // Recursively invalidate dependents
oneOf(db).getMessageDependents(txn3, messageId1); oneOf(db).getMessageDependents(txn3, messageId1);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn3); oneOf(db).commitTransaction(txn3);
oneOf(db).endTransaction(txn3); oneOf(db).endTransaction(txn3);
// Get pending messages to deliver // Get pending messages to deliver
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn4)); will(returnValue(txn4));
oneOf(db).getPendingMessages(txn4); oneOf(db).getPendingMessages(txn4);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn4); oneOf(db).commitTransaction(txn4);
oneOf(db).endTransaction(txn4); oneOf(db).endTransaction(txn4);
// Get messages to share // Get messages to share
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn5)); will(returnValue(txn5));
oneOf(db).getMessagesToShare(txn5); oneOf(db).getMessagesToShare(txn5);
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).commitTransaction(txn5); oneOf(db).commitTransaction(txn5);
oneOf(db).endTransaction(txn5); oneOf(db).endTransaction(txn5);
}}); }});
@@ -575,7 +566,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setMessageState(txn1, messageId, DELIVERED); oneOf(db).setMessageState(txn1, messageId, DELIVERED);
// Get any pending dependents // Get any pending dependents
oneOf(db).getMessageDependents(txn1, messageId); oneOf(db).getMessageDependents(txn1, messageId);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn1); oneOf(db).commitTransaction(txn1);
oneOf(db).endTransaction(txn1); oneOf(db).endTransaction(txn1);
}}); }});
@@ -584,7 +575,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
} }
@Test @Test
public void testLocalMessagesAreNotValidatedWhenAdded() throws Exception { public void testLocalMessagesAreNotValidatedWhenAdded() {
vm.eventOccurred(new MessageAddedEvent(message, null)); vm.eventOccurred(new MessageAddedEvent(message, null));
} }
@@ -611,7 +602,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).addMessageDependencies(txn1, message, oneOf(db).addMessageDependencies(txn1, message,
validResultWithDependencies.getDependencies()); validResultWithDependencies.getDependencies());
oneOf(db).getMessageDependencies(txn1, messageId); oneOf(db).getMessageDependencies(txn1, messageId);
will(returnValue(Collections.singletonMap(messageId1, UNKNOWN))); will(returnValue(singletonMap(messageId1, UNKNOWN)));
oneOf(db).mergeMessageMetadata(txn1, messageId, metadata); oneOf(db).mergeMessageMetadata(txn1, messageId, metadata);
oneOf(db).setMessageState(txn1, messageId, PENDING); oneOf(db).setMessageState(txn1, messageId, PENDING);
oneOf(db).commitTransaction(txn1); oneOf(db).commitTransaction(txn1);
@@ -644,7 +635,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).addMessageDependencies(txn1, message, oneOf(db).addMessageDependencies(txn1, message,
validResultWithDependencies.getDependencies()); validResultWithDependencies.getDependencies());
oneOf(db).getMessageDependencies(txn1, messageId); oneOf(db).getMessageDependencies(txn1, messageId);
will(returnValue(Collections.singletonMap(messageId1, DELIVERED))); will(returnValue(singletonMap(messageId1, DELIVERED)));
oneOf(db).mergeMessageMetadata(txn1, messageId, metadata); oneOf(db).mergeMessageMetadata(txn1, messageId, metadata);
// Deliver the message // Deliver the message
oneOf(hook).incomingMessage(txn1, message, metadata); oneOf(hook).incomingMessage(txn1, message, metadata);
@@ -652,7 +643,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setMessageState(txn1, messageId, DELIVERED); oneOf(db).setMessageState(txn1, messageId, DELIVERED);
// Get any pending dependents // Get any pending dependents
oneOf(db).getMessageDependents(txn1, messageId); oneOf(db).getMessageDependents(txn1, messageId);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn1); oneOf(db).commitTransaction(txn1);
oneOf(db).endTransaction(txn1); oneOf(db).endTransaction(txn1);
}}); }});
@@ -685,7 +676,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
validResultWithDependencies.getDependencies()); validResultWithDependencies.getDependencies());
// Check for invalid dependencies // Check for invalid dependencies
oneOf(db).getMessageDependencies(txn1, messageId); oneOf(db).getMessageDependencies(txn1, messageId);
will(returnValue(Collections.singletonMap(messageId1, INVALID))); will(returnValue(singletonMap(messageId1, INVALID)));
// Invalidate message // Invalidate message
oneOf(db).getMessageState(txn1, messageId); oneOf(db).getMessageState(txn1, messageId);
will(returnValue(UNKNOWN)); will(returnValue(UNKNOWN));
@@ -694,7 +685,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).deleteMessageMetadata(txn1, messageId); oneOf(db).deleteMessageMetadata(txn1, messageId);
// Recursively invalidate dependents // Recursively invalidate dependents
oneOf(db).getMessageDependents(txn1, messageId); oneOf(db).getMessageDependents(txn1, messageId);
will(returnValue(Collections.singletonMap(messageId2, UNKNOWN))); will(returnValue(singletonMap(messageId2, UNKNOWN)));
oneOf(db).commitTransaction(txn1); oneOf(db).commitTransaction(txn1);
oneOf(db).endTransaction(txn1); oneOf(db).endTransaction(txn1);
// Invalidate dependent in a new transaction // Invalidate dependent in a new transaction
@@ -706,7 +697,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).deleteMessage(txn2, messageId2); oneOf(db).deleteMessage(txn2, messageId2);
oneOf(db).deleteMessageMetadata(txn2, messageId2); oneOf(db).deleteMessageMetadata(txn2, messageId2);
oneOf(db).getMessageDependents(txn2, messageId2); oneOf(db).getMessageDependents(txn2, messageId2);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn2); oneOf(db).commitTransaction(txn2);
oneOf(db).endTransaction(txn2); oneOf(db).endTransaction(txn2);
}}); }});
@@ -763,7 +754,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).deleteMessageMetadata(txn2, messageId1); oneOf(db).deleteMessageMetadata(txn2, messageId1);
// Message 1 has one dependent: 3 // Message 1 has one dependent: 3
oneOf(db).getMessageDependents(txn2, messageId1); oneOf(db).getMessageDependents(txn2, messageId1);
will(returnValue(Collections.singletonMap(messageId3, PENDING))); will(returnValue(singletonMap(messageId3, PENDING)));
oneOf(db).commitTransaction(txn2); oneOf(db).commitTransaction(txn2);
oneOf(db).endTransaction(txn2); oneOf(db).endTransaction(txn2);
// Invalidate message 2 // Invalidate message 2
@@ -776,7 +767,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).deleteMessageMetadata(txn3, messageId2); oneOf(db).deleteMessageMetadata(txn3, messageId2);
// Message 2 has one dependent: 3 (same dependent as 1) // Message 2 has one dependent: 3 (same dependent as 1)
oneOf(db).getMessageDependents(txn3, messageId2); oneOf(db).getMessageDependents(txn3, messageId2);
will(returnValue(Collections.singletonMap(messageId3, PENDING))); will(returnValue(singletonMap(messageId3, PENDING)));
oneOf(db).commitTransaction(txn3); oneOf(db).commitTransaction(txn3);
oneOf(db).endTransaction(txn3); oneOf(db).endTransaction(txn3);
// Invalidate message 3 (via 1) // Invalidate message 3 (via 1)
@@ -789,7 +780,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).deleteMessageMetadata(txn4, messageId3); oneOf(db).deleteMessageMetadata(txn4, messageId3);
// Message 3 has one dependent: 4 // Message 3 has one dependent: 4
oneOf(db).getMessageDependents(txn4, messageId3); oneOf(db).getMessageDependents(txn4, messageId3);
will(returnValue(Collections.singletonMap(messageId4, PENDING))); will(returnValue(singletonMap(messageId4, PENDING)));
oneOf(db).commitTransaction(txn4); oneOf(db).commitTransaction(txn4);
oneOf(db).endTransaction(txn4); oneOf(db).endTransaction(txn4);
// Invalidate message 3 (again, via 2) // Invalidate message 3 (again, via 2)
@@ -809,7 +800,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).deleteMessageMetadata(txn6, messageId4); oneOf(db).deleteMessageMetadata(txn6, messageId4);
// Message 4 has no dependents // Message 4 has no dependents
oneOf(db).getMessageDependents(txn6, messageId4); oneOf(db).getMessageDependents(txn6, messageId4);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn6); oneOf(db).commitTransaction(txn6);
oneOf(db).endTransaction(txn6); oneOf(db).endTransaction(txn6);
}}); }});
@@ -819,12 +810,10 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testPendingDependentsGetDelivered() throws Exception { public void testPendingDependentsGetDelivered() throws Exception {
MessageId messageId3 = new MessageId(getRandomId()); Message message3 = getMessage(groupId);
MessageId messageId4 = new MessageId(getRandomId()); Message message4 = getMessage(groupId);
Message message3 = new Message(messageId3, groupId, timestamp, MessageId messageId3 = message3.getId();
raw); MessageId messageId4 = message4.getId();
Message message4 = new Message(messageId4, groupId, timestamp,
raw);
Map<MessageId, State> twoDependents = new LinkedHashMap<>(); Map<MessageId, State> twoDependents = new LinkedHashMap<>();
twoDependents.put(messageId1, PENDING); twoDependents.put(messageId1, PENDING);
twoDependents.put(messageId2, PENDING); twoDependents.put(messageId2, PENDING);
@@ -869,11 +858,11 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).getMessageState(txn2, messageId1); oneOf(db).getMessageState(txn2, messageId1);
will(returnValue(PENDING)); will(returnValue(PENDING));
oneOf(db).getMessageDependencies(txn2, messageId1); oneOf(db).getMessageDependencies(txn2, messageId1);
will(returnValue(Collections.singletonMap(messageId, DELIVERED))); will(returnValue(singletonMap(messageId, DELIVERED)));
// Get message 1 and its metadata // Get message 1 and its metadata
oneOf(db).getRawMessage(txn2, messageId1); oneOf(db).getRawMessage(txn2, messageId1);
will(returnValue(raw)); will(returnValue(message1.getRaw()));
oneOf(messageFactory).createMessage(messageId1, raw); oneOf(messageFactory).createMessage(messageId1, message1.getRaw());
will(returnValue(message1)); will(returnValue(message1));
oneOf(db).getGroup(txn2, groupId); oneOf(db).getGroup(txn2, groupId);
will(returnValue(group)); will(returnValue(group));
@@ -885,7 +874,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setMessageState(txn2, messageId1, DELIVERED); oneOf(db).setMessageState(txn2, messageId1, DELIVERED);
// Message 1 has one pending dependent: 3 // Message 1 has one pending dependent: 3
oneOf(db).getMessageDependents(txn2, messageId1); oneOf(db).getMessageDependents(txn2, messageId1);
will(returnValue(Collections.singletonMap(messageId3, PENDING))); will(returnValue(singletonMap(messageId3, PENDING)));
oneOf(db).commitTransaction(txn2); oneOf(db).commitTransaction(txn2);
oneOf(db).endTransaction(txn2); oneOf(db).endTransaction(txn2);
// Check whether message 2 is ready to be delivered // Check whether message 2 is ready to be delivered
@@ -894,11 +883,11 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).getMessageState(txn3, messageId2); oneOf(db).getMessageState(txn3, messageId2);
will(returnValue(PENDING)); will(returnValue(PENDING));
oneOf(db).getMessageDependencies(txn3, messageId2); oneOf(db).getMessageDependencies(txn3, messageId2);
will(returnValue(Collections.singletonMap(messageId, DELIVERED))); will(returnValue(singletonMap(messageId, DELIVERED)));
// Get message 2 and its metadata // Get message 2 and its metadata
oneOf(db).getRawMessage(txn3, messageId2); oneOf(db).getRawMessage(txn3, messageId2);
will(returnValue(raw)); will(returnValue(message2.getRaw()));
oneOf(messageFactory).createMessage(messageId2, raw); oneOf(messageFactory).createMessage(messageId2, message2.getRaw());
will(returnValue(message2)); will(returnValue(message2));
oneOf(db).getGroup(txn3, groupId); oneOf(db).getGroup(txn3, groupId);
will(returnValue(group)); will(returnValue(group));
@@ -910,7 +899,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setMessageState(txn3, messageId2, DELIVERED); oneOf(db).setMessageState(txn3, messageId2, DELIVERED);
// Message 2 has one pending dependent: 3 (same dependent as 1) // Message 2 has one pending dependent: 3 (same dependent as 1)
oneOf(db).getMessageDependents(txn3, messageId2); oneOf(db).getMessageDependents(txn3, messageId2);
will(returnValue(Collections.singletonMap(messageId3, PENDING))); will(returnValue(singletonMap(messageId3, PENDING)));
oneOf(db).commitTransaction(txn3); oneOf(db).commitTransaction(txn3);
oneOf(db).endTransaction(txn3); oneOf(db).endTransaction(txn3);
// Check whether message 3 is ready to be delivered (via 1) // Check whether message 3 is ready to be delivered (via 1)
@@ -922,8 +911,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
will(returnValue(twoDependencies)); will(returnValue(twoDependencies));
// Get message 3 and its metadata // Get message 3 and its metadata
oneOf(db).getRawMessage(txn4, messageId3); oneOf(db).getRawMessage(txn4, messageId3);
will(returnValue(raw)); will(returnValue(message3.getRaw()));
oneOf(messageFactory).createMessage(messageId3, raw); oneOf(messageFactory).createMessage(messageId3, message3.getRaw());
will(returnValue(message3)); will(returnValue(message3));
oneOf(db).getGroup(txn4, groupId); oneOf(db).getGroup(txn4, groupId);
will(returnValue(group)); will(returnValue(group));
@@ -934,7 +923,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setMessageState(txn4, messageId3, DELIVERED); oneOf(db).setMessageState(txn4, messageId3, DELIVERED);
// Message 3 has one pending dependent: 4 // Message 3 has one pending dependent: 4
oneOf(db).getMessageDependents(txn4, messageId3); oneOf(db).getMessageDependents(txn4, messageId3);
will(returnValue(Collections.singletonMap(messageId4, PENDING))); will(returnValue(singletonMap(messageId4, PENDING)));
oneOf(db).commitTransaction(txn4); oneOf(db).commitTransaction(txn4);
oneOf(db).endTransaction(txn4); oneOf(db).endTransaction(txn4);
// Check whether message 3 is ready to be delivered (again, via 2) // Check whether message 3 is ready to be delivered (again, via 2)
@@ -950,11 +939,11 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).getMessageState(txn6, messageId4); oneOf(db).getMessageState(txn6, messageId4);
will(returnValue(PENDING)); will(returnValue(PENDING));
oneOf(db).getMessageDependencies(txn6, messageId4); oneOf(db).getMessageDependencies(txn6, messageId4);
will(returnValue(Collections.singletonMap(messageId3, DELIVERED))); will(returnValue(singletonMap(messageId3, DELIVERED)));
// Get message 4 and its metadata // Get message 4 and its metadata
oneOf(db).getRawMessage(txn6, messageId4); oneOf(db).getRawMessage(txn6, messageId4);
will(returnValue(raw)); will(returnValue(message4.getRaw()));
oneOf(messageFactory).createMessage(messageId4, raw); oneOf(messageFactory).createMessage(messageId4, message4.getRaw());
will(returnValue(message4)); will(returnValue(message4));
oneOf(db).getGroup(txn6, groupId); oneOf(db).getGroup(txn6, groupId);
will(returnValue(group)); will(returnValue(group));
@@ -966,7 +955,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setMessageState(txn6, messageId4, DELIVERED); oneOf(db).setMessageState(txn6, messageId4, DELIVERED);
// Message 4 has no pending dependents // Message 4 has no pending dependents
oneOf(db).getMessageDependents(txn6, messageId4); oneOf(db).getMessageDependents(txn6, messageId4);
will(returnValue(Collections.emptyMap())); will(returnValue(emptyMap()));
oneOf(db).commitTransaction(txn6); oneOf(db).commitTransaction(txn6);
oneOf(db).endTransaction(txn6); oneOf(db).endTransaction(txn6);
}}); }});
@@ -1004,7 +993,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setMessageState(txn1, messageId, DELIVERED); oneOf(db).setMessageState(txn1, messageId, DELIVERED);
// Get any pending dependents // Get any pending dependents
oneOf(db).getMessageDependents(txn1, messageId); oneOf(db).getMessageDependents(txn1, messageId);
will(returnValue(Collections.singletonMap(messageId1, PENDING))); will(returnValue(singletonMap(messageId1, PENDING)));
oneOf(db).commitTransaction(txn1); oneOf(db).commitTransaction(txn1);
oneOf(db).endTransaction(txn1); oneOf(db).endTransaction(txn1);
// Check whether the pending dependent is ready to be delivered // Check whether the pending dependent is ready to be delivered

View File

@@ -32,10 +32,9 @@ import org.junit.Test;
import static org.briarproject.bramble.api.identity.Author.Status.NONE; import static org.briarproject.bramble.api.identity.Author.Status.NONE;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES; import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED; import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR; import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
@@ -75,9 +74,9 @@ public class BlogManagerImplTest extends BriarTestCase {
private final LocalAuthor localAuthor1, localAuthor2, rssLocalAuthor; private final LocalAuthor localAuthor1, localAuthor2, rssLocalAuthor;
private final BdfList authorList1, authorList2, rssAuthorList; private final BdfList authorList1, authorList2, rssAuthorList;
private final Blog blog1, blog2, rssBlog; private final Blog blog1, blog2, rssBlog;
private final long timestamp, timeReceived;
private final MessageId messageId, rssMessageId;
private final Message message, rssMessage; private final Message message, rssMessage;
private final MessageId messageId, rssMessageId;
private final long timestamp, timeReceived;
private final String comment; private final String comment;
public BlogManagerImplTest() { public BlogManagerImplTest() {
@@ -94,14 +93,12 @@ public class BlogManagerImplTest extends BriarTestCase {
blog1 = createBlog(localAuthor1, false); blog1 = createBlog(localAuthor1, false);
blog2 = createBlog(localAuthor2, false); blog2 = createBlog(localAuthor2, false);
rssBlog = createBlog(rssLocalAuthor, true); rssBlog = createBlog(rssLocalAuthor, true);
timestamp = System.currentTimeMillis(); message = getMessage(blog1.getId());
rssMessage = getMessage(rssBlog.getId());
messageId = message.getId();
rssMessageId = rssMessage.getId();
timestamp = message.getTimestamp();
timeReceived = timestamp + 1; timeReceived = timestamp + 1;
messageId = new MessageId(getRandomId());
rssMessageId = new MessageId(getRandomId());
message = new Message(messageId, blog1.getId(), timestamp,
getRandomBytes(MAX_MESSAGE_LENGTH));
rssMessage = new Message(rssMessageId, rssBlog.getId(), timestamp,
getRandomBytes(MAX_MESSAGE_LENGTH));
comment = getRandomString(MAX_BLOG_COMMENT_LENGTH); comment = getRandomString(MAX_BLOG_COMMENT_LENGTH);
} }
@@ -372,9 +369,8 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TIMESTAMP, timestamp), new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived) new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
); );
MessageId commentId = new MessageId(getRandomId()); Message commentMsg = getMessage(blog1.getId());
Message commentMsg = new Message(commentId, blog1.getId(), MessageId commentId = commentMsg.getId();
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
BdfDictionary commentMeta = BdfDictionary.of( BdfDictionary commentMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, COMMENT.getInt()), new BdfEntry(KEY_TYPE, COMMENT.getInt()),
new BdfEntry(KEY_COMMENT, comment), new BdfEntry(KEY_COMMENT, comment),
@@ -457,9 +453,8 @@ public class BlogManagerImplTest extends BriarTestCase {
// The post was originally posted to blog 1, then reblogged to // The post was originally posted to blog 1, then reblogged to
// blog 2 with a comment // blog 2 with a comment
BdfList originalPostBody = BdfList.of("originalPostBody"); BdfList originalPostBody = BdfList.of("originalPostBody");
MessageId wrappedPostId = new MessageId(getRandomId()); Message wrappedPostMsg = getMessage(blog2.getId());
Message wrappedPostMsg = new Message(wrappedPostId, blog2.getId(), MessageId wrappedPostId = wrappedPostMsg.getId();
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
BdfDictionary wrappedPostMeta = BdfDictionary.of( BdfDictionary wrappedPostMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()), new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
new BdfEntry(KEY_RSS_FEED, false), new BdfEntry(KEY_RSS_FEED, false),
@@ -468,9 +463,8 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TIMESTAMP, timestamp), new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived) new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
); );
MessageId commentId = new MessageId(getRandomId()); Message commentMsg = getMessage(blog2.getId());
Message commentMsg = new Message(commentId, blog2.getId(), MessageId commentId = commentMsg.getId();
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
BdfDictionary commentMeta = BdfDictionary.of( BdfDictionary commentMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, COMMENT.getInt()), new BdfEntry(KEY_TYPE, COMMENT.getInt()),
new BdfEntry(KEY_COMMENT, comment), new BdfEntry(KEY_COMMENT, comment),
@@ -568,9 +562,8 @@ public class BlogManagerImplTest extends BriarTestCase {
// The post was originally posted to the RSS blog, then reblogged to // The post was originally posted to the RSS blog, then reblogged to
// blog 1 with a comment // blog 1 with a comment
BdfList originalPostBody = BdfList.of("originalPostBody"); BdfList originalPostBody = BdfList.of("originalPostBody");
MessageId wrappedPostId = new MessageId(getRandomId()); Message wrappedPostMsg = getMessage(blog1.getId());
Message wrappedPostMsg = new Message(wrappedPostId, blog1.getId(), MessageId wrappedPostId = wrappedPostMsg.getId();
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
BdfDictionary wrappedPostMeta = BdfDictionary.of( BdfDictionary wrappedPostMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()), new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
new BdfEntry(KEY_RSS_FEED, true), new BdfEntry(KEY_RSS_FEED, true),
@@ -579,9 +572,8 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TIMESTAMP, timestamp), new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived) new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
); );
MessageId commentId = new MessageId(getRandomId()); Message commentMsg = getMessage(blog1.getId());
Message commentMsg = new Message(commentId, blog1.getId(), MessageId commentId = commentMsg.getId();
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
BdfDictionary commentMeta = BdfDictionary.of( BdfDictionary commentMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, COMMENT.getInt()), new BdfEntry(KEY_TYPE, COMMENT.getInt()),
new BdfEntry(KEY_COMMENT, comment), new BdfEntry(KEY_COMMENT, comment),
@@ -681,9 +673,8 @@ public class BlogManagerImplTest extends BriarTestCase {
MessageId originalCommentId = new MessageId(getRandomId()); MessageId originalCommentId = new MessageId(getRandomId());
BdfList originalCommentBody = BdfList.of("originalCommentBody"); BdfList originalCommentBody = BdfList.of("originalCommentBody");
// The post and comment were reblogged to blog 2 with another comment // The post and comment were reblogged to blog 2 with another comment
MessageId rewrappedPostId = new MessageId(getRandomId()); Message rewrappedPostMsg = getMessage(blog2.getId());
Message rewrappedPostMsg = new Message(rewrappedPostId, MessageId rewrappedPostId = rewrappedPostMsg.getId();
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
BdfDictionary rewrappedPostMeta = BdfDictionary.of( BdfDictionary rewrappedPostMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()), new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
new BdfEntry(KEY_RSS_FEED, true), new BdfEntry(KEY_RSS_FEED, true),
@@ -692,9 +683,8 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TIMESTAMP, timestamp), new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived) new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
); );
MessageId wrappedCommentId = new MessageId(getRandomId()); Message wrappedCommentMsg = getMessage(blog2.getId());
Message wrappedCommentMsg = new Message(wrappedCommentId, MessageId wrappedCommentId = wrappedCommentMsg.getId();
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
BdfDictionary wrappedCommentMeta = BdfDictionary.of( BdfDictionary wrappedCommentMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, WRAPPED_COMMENT.getInt()), new BdfEntry(KEY_TYPE, WRAPPED_COMMENT.getInt()),
new BdfEntry(KEY_COMMENT, comment), new BdfEntry(KEY_COMMENT, comment),
@@ -705,9 +695,8 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TIME_RECEIVED, timeReceived) new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
); );
String localComment = getRandomString(MAX_BLOG_COMMENT_LENGTH); String localComment = getRandomString(MAX_BLOG_COMMENT_LENGTH);
MessageId localCommentId = new MessageId(getRandomId()); Message localCommentMsg = getMessage(blog2.getId());
Message localCommentMsg = new Message(localCommentId, MessageId localCommentId = localCommentMsg.getId();
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
BdfDictionary localCommentMeta = BdfDictionary.of( BdfDictionary localCommentMeta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, COMMENT.getInt()), new BdfEntry(KEY_TYPE, COMMENT.getInt()),
new BdfEntry(KEY_COMMENT, localComment), new BdfEntry(KEY_COMMENT, localComment),

View File

@@ -25,6 +25,7 @@ import java.security.GeneralSecurityException;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.briarproject.bramble.util.StringUtils.getRandomString;
@@ -74,17 +75,12 @@ public class BlogPostValidatorTest extends BriarTestCase {
); );
blog = new Blog(group, author, false); blog = new Blog(group, author, false);
rssBlog = new Blog(group, author, true); rssBlog = new Blog(group, author, true);
message = getMessage(group.getId());
MessageId messageId = new MessageId(getRandomId());
long timestamp = System.currentTimeMillis();
byte[] raw = getRandomBytes(123);
message = new Message(messageId, group.getId(), timestamp, raw);
MetadataEncoder metadataEncoder = context.mock(MetadataEncoder.class); MetadataEncoder metadataEncoder = context.mock(MetadataEncoder.class);
Clock clock = new SystemClock(); Clock clock = new SystemClock();
validator = validator = new BlogPostValidator(groupFactory, messageFactory,
new BlogPostValidator(groupFactory, messageFactory, blogFactory, blogFactory, clientHelper, metadataEncoder, clock);
clientHelper, metadataEncoder, clock);
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
@@ -117,8 +113,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
} }
@Test(expected = FormatException.class) @Test(expected = FormatException.class)
public void testValidateBlogPostWithoutAttachments() public void testValidateBlogPostWithoutAttachments() throws IOException {
throws IOException, GeneralSecurityException {
BdfList content = BdfList.of(null, null, body); BdfList content = BdfList.of(null, null, body);
BdfList m = BdfList.of(POST.getInt(), content, null); BdfList m = BdfList.of(POST.getInt(), content, null);
@@ -126,8 +121,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
} }
@Test(expected = FormatException.class) @Test(expected = FormatException.class)
public void testValidateBlogPostWithoutSignature() public void testValidateBlogPostWithoutSignature() throws IOException {
throws IOException, GeneralSecurityException {
BdfList content = BdfList.of(null, null, body, null); BdfList content = BdfList.of(null, null, body, null);
BdfList m = BdfList.of(POST.getInt(), content, null); BdfList m = BdfList.of(POST.getInt(), content, null);

View File

@@ -14,7 +14,6 @@ import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.Message; import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.api.system.Clock; import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.ImmediateExecutor; import org.briarproject.bramble.test.ImmediateExecutor;
@@ -39,8 +38,7 @@ import okhttp3.Dns;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEEDS; import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEEDS;
import static org.briarproject.briar.api.feed.FeedManager.CLIENT_ID; import static org.briarproject.briar.api.feed.FeedManager.CLIENT_ID;
import static org.briarproject.briar.api.feed.FeedManager.MAJOR_VERSION; import static org.briarproject.briar.api.feed.FeedManager.MAJOR_VERSION;
@@ -109,8 +107,7 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
entry.setUpdatedDate(new Date()); entry.setUpdatedDate(new Date());
entries.add(entry); entries.add(entry);
String body = "<p> (" + entry.getUpdatedDate().toString() + ")</p>"; String body = "<p> (" + entry.getUpdatedDate().toString() + ")</p>";
Message msg = new Message(new MessageId(getRandomId()), blogGroupId, 0, Message msg = getMessage(blogGroupId);
getRandomBytes(42));
BlogPost post = new BlogPost(msg, null, localAuthor); BlogPost post = new BlogPost(msg, null, localAuthor);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -118,9 +115,8 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
will(returnValue(txn)); will(returnValue(txn));
oneOf(clock).currentTimeMillis(); oneOf(clock).currentTimeMillis();
will(returnValue(42L)); will(returnValue(42L));
oneOf(blogPostFactory) oneOf(blogPostFactory).createBlogPost(feed.getBlogId(), 42L, null,
.createBlogPost(feed.getBlogId(), 42L, null, localAuthor, localAuthor, body);
body);
will(returnValue(post)); will(returnValue(post));
oneOf(blogManager).addLocalPost(txn, post); oneOf(blogManager).addLocalPost(txn, post);
oneOf(db).commitTransaction(txn); oneOf(db).commitTransaction(txn);

View File

@@ -11,8 +11,11 @@ import org.briarproject.bramble.test.BrambleMockTestCase;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.junit.Test; import org.junit.Test;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH; import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH;
@@ -27,9 +30,9 @@ public class MessageEncoderTest extends BrambleMockTestCase {
new MessageEncoderImpl(clientHelper, messageFactory); new MessageEncoderImpl(clientHelper, messageFactory);
private final GroupId groupId = new GroupId(getRandomId()); private final GroupId groupId = new GroupId(getRandomId());
private final Message message = getMessage(groupId); private final Message message = getMessage(groupId, MAX_MESSAGE_LENGTH);
private final long timestamp = message.getTimestamp(); private final long timestamp = message.getTimestamp();
private final byte[] body = message.getRaw(); private final byte[] body = getRandomBytes(MAX_MESSAGE_BODY_LENGTH);
private final Author author = getAuthor(); private final Author author = getAuthor();
private final BdfList authorList = new BdfList(); private final BdfList authorList = new BdfList();
private final String text = getRandomString(MAX_REQUEST_MESSAGE_LENGTH); private final String text = getRandomString(MAX_REQUEST_MESSAGE_LENGTH);
@@ -43,8 +46,8 @@ public class MessageEncoderTest extends BrambleMockTestCase {
expectCreateMessage( expectCreateMessage(
BdfList.of(REQUEST.getValue(), null, authorList, text)); BdfList.of(REQUEST.getValue(), null, authorList, text));
messageEncoder messageEncoder.encodeRequestMessage(groupId, timestamp, null,
.encodeRequestMessage(groupId, timestamp, null, author, text); author, text);
} }
private void expectCreateMessage(BdfList bodyList) throws FormatException { private void expectCreateMessage(BdfList bodyList) throws FormatException {

View File

@@ -44,7 +44,7 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
@Inject @Inject
ForumPostFactory forumPostFactory; ForumPostFactory forumPostFactory;
public MessageSizeIntegrationTest() throws Exception { public MessageSizeIntegrationTest() {
MessageSizeIntegrationTestComponent component = MessageSizeIntegrationTestComponent component =
DaggerMessageSizeIntegrationTestComponent.builder().build(); DaggerMessageSizeIntegrationTestComponent.builder().build();
component.inject(this); component.inject(this);
@@ -60,9 +60,9 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
PrivateMessage message = privateMessageFactory.createPrivateMessage( PrivateMessage message = privateMessageFactory.createPrivateMessage(
groupId, timestamp, body); groupId, timestamp, body);
// Check the size of the serialised message // Check the size of the serialised message
int length = message.getMessage().getRaw().length; int length = message.getMessage().getLength();
assertTrue( assertTrue(length > UniqueId.LENGTH + 8
length > UniqueId.LENGTH + 8 + MAX_PRIVATE_MESSAGE_BODY_LENGTH); + MAX_PRIVATE_MESSAGE_BODY_LENGTH);
assertTrue(length <= MAX_RECORD_PAYLOAD_BYTES); assertTrue(length <= MAX_RECORD_PAYLOAD_BYTES);
} }
@@ -83,7 +83,7 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
ForumPost post = forumPostFactory.createPost(groupId, ForumPost post = forumPostFactory.createPost(groupId,
timestamp, parent, author, body); timestamp, parent, author, body);
// Check the size of the serialised message // Check the size of the serialised message
int length = post.getMessage().getRaw().length; int length = post.getMessage().getLength();
assertTrue(length > UniqueId.LENGTH + 8 + UniqueId.LENGTH + 4 assertTrue(length > UniqueId.LENGTH + 8 + UniqueId.LENGTH + 4
+ MAX_AUTHOR_NAME_LENGTH + MAX_PUBLIC_KEY_LENGTH + MAX_AUTHOR_NAME_LENGTH + MAX_PUBLIC_KEY_LENGTH
+ MAX_FORUM_POST_BODY_LENGTH); + MAX_FORUM_POST_BODY_LENGTH);

View File

@@ -29,6 +29,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATUR
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.briarproject.bramble.util.StringUtils.getRandomString;
@@ -44,94 +45,83 @@ import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN;
import static org.briarproject.briar.privategroup.invitation.MessageType.LEAVE; import static org.briarproject.briar.privategroup.invitation.MessageType.LEAVE;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase { abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
protected final DatabaseComponent db = final DatabaseComponent db = context.mock(DatabaseComponent.class);
context.mock(DatabaseComponent.class); final ClientHelper clientHelper = context.mock(ClientHelper.class);
protected final ClientHelper clientHelper = final ClientVersioningManager clientVersioningManager =
context.mock(ClientHelper.class);
protected final ClientVersioningManager clientVersioningManager =
context.mock(ClientVersioningManager.class); context.mock(ClientVersioningManager.class);
protected final PrivateGroupFactory privateGroupFactory = final PrivateGroupFactory privateGroupFactory =
context.mock(PrivateGroupFactory.class); context.mock(PrivateGroupFactory.class);
protected final PrivateGroupManager privateGroupManager = final PrivateGroupManager privateGroupManager =
context.mock(PrivateGroupManager.class); context.mock(PrivateGroupManager.class);
protected final MessageParser messageParser = final MessageParser messageParser = context.mock(MessageParser.class);
context.mock(MessageParser.class); final GroupMessageFactory groupMessageFactory =
protected final GroupMessageFactory groupMessageFactory =
context.mock(GroupMessageFactory.class); context.mock(GroupMessageFactory.class);
protected final IdentityManager identityManager = final IdentityManager identityManager = context.mock(IdentityManager.class);
context.mock(IdentityManager.class); final MessageEncoder messageEncoder = context.mock(MessageEncoder.class);
protected final MessageEncoder messageEncoder = final MessageTracker messageTracker = context.mock(MessageTracker.class);
context.mock(MessageEncoder.class); final Clock clock = context.mock(Clock.class);
protected final MessageTracker messageTracker =
context.mock(MessageTracker.class);
protected final Clock clock = context.mock(Clock.class);
protected final Transaction txn = new Transaction(null, false); final Transaction txn = new Transaction(null, false);
protected final GroupId contactGroupId = new GroupId(getRandomId()); final GroupId contactGroupId = new GroupId(getRandomId());
protected final Group privateGroupGroup = final Group privateGroupGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
getGroup(CLIENT_ID, MAJOR_VERSION); final GroupId privateGroupId = privateGroupGroup.getId();
protected final GroupId privateGroupId = privateGroupGroup.getId(); final Author author = getAuthor();
protected final Author author = getAuthor(); final PrivateGroup privateGroup = new PrivateGroup(privateGroupGroup,
protected final PrivateGroup privateGroup = getRandomString(MAX_GROUP_NAME_LENGTH), author,
new PrivateGroup(privateGroupGroup, getRandomBytes(GROUP_SALT_LENGTH));
getRandomString(MAX_GROUP_NAME_LENGTH), author, final byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH);
getRandomBytes(GROUP_SALT_LENGTH)); final MessageId lastLocalMessageId = new MessageId(getRandomId());
protected final byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH); final MessageId lastRemoteMessageId = new MessageId(getRandomId());
protected final MessageId lastLocalMessageId = new MessageId(getRandomId()); final Message message = getMessage(contactGroupId);
protected final MessageId lastRemoteMessageId = final MessageId messageId = message.getId();
new MessageId(getRandomId()); final long messageTimestamp = message.getTimestamp();
protected final long localTimestamp = 3L; final long inviteTimestamp = messageTimestamp - 1;
protected final long inviteTimestamp = 6L; final long localTimestamp = inviteTimestamp - 1;
protected final long messageTimestamp = inviteTimestamp + 1;
protected final MessageId messageId = new MessageId(getRandomId());
protected final Message message = new Message(messageId, contactGroupId,
messageTimestamp, getRandomBytes(42));
private final BdfDictionary meta = private final BdfDictionary meta =
BdfDictionary.of(new BdfEntry("me", "ta")); BdfDictionary.of(new BdfEntry("me", "ta"));
protected final ContactId contactId = new ContactId(5); final ContactId contactId = new ContactId(5);
protected final Contact contact = new Contact(contactId, author, final Contact contact = new Contact(contactId, author,
new AuthorId(getRandomId()), true, true); new AuthorId(getRandomId()), true, true);
protected final InviteMessage inviteMessage = final InviteMessage inviteMessage =
new InviteMessage(new MessageId(getRandomId()), contactGroupId, new InviteMessage(new MessageId(getRandomId()), contactGroupId,
privateGroupId, 0L, privateGroup.getName(), privateGroupId, 0L, privateGroup.getName(),
privateGroup.getCreator(), privateGroup.getSalt(), privateGroup.getCreator(), privateGroup.getSalt(),
getRandomString(MAX_GROUP_INVITATION_MSG_LENGTH), getRandomString(MAX_GROUP_INVITATION_MSG_LENGTH),
signature); signature);
protected final JoinMessage joinMessage = final JoinMessage joinMessage =
new JoinMessage(new MessageId(getRandomId()), contactGroupId, new JoinMessage(new MessageId(getRandomId()), contactGroupId,
privateGroupId, 0L, lastRemoteMessageId); privateGroupId, 0L, lastRemoteMessageId);
protected final LeaveMessage leaveMessage = final LeaveMessage leaveMessage =
new LeaveMessage(new MessageId(getRandomId()), contactGroupId, new LeaveMessage(new MessageId(getRandomId()), contactGroupId,
privateGroupId, 0L, lastRemoteMessageId); privateGroupId, 0L, lastRemoteMessageId);
protected final AbortMessage abortMessage = final AbortMessage abortMessage =
new AbortMessage(messageId, contactGroupId, privateGroupId, new AbortMessage(messageId, contactGroupId, privateGroupId,
inviteTimestamp + 1); inviteTimestamp + 1);
protected void assertSessionConstantsUnchanged(Session s1, Session s2) { void assertSessionConstantsUnchanged(Session s1, Session s2) {
assertEquals(s1.getRole(), s2.getRole()); assertEquals(s1.getRole(), s2.getRole());
assertEquals(s1.getContactGroupId(), s2.getContactGroupId()); assertEquals(s1.getContactGroupId(), s2.getContactGroupId());
assertEquals(s1.getPrivateGroupId(), s2.getPrivateGroupId()); assertEquals(s1.getPrivateGroupId(), s2.getPrivateGroupId());
} }
protected void assertSessionRecordedSentMessage(Session s) { void assertSessionRecordedSentMessage(Session s) {
assertEquals(messageId, s.getLastLocalMessageId()); assertEquals(messageId, s.getLastLocalMessageId());
assertEquals(lastRemoteMessageId, s.getLastRemoteMessageId()); assertEquals(lastRemoteMessageId, s.getLastRemoteMessageId());
assertEquals(messageTimestamp, s.getLocalTimestamp()); assertEquals(messageTimestamp, s.getLocalTimestamp());
assertEquals(inviteTimestamp, s.getInviteTimestamp()); assertEquals(inviteTimestamp, s.getInviteTimestamp());
} }
protected void expectGetLocalTimestamp(long time) { void expectGetLocalTimestamp(long time) {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(clock).currentTimeMillis(); oneOf(clock).currentTimeMillis();
will(returnValue(time)); will(returnValue(time));
}}); }});
} }
protected void expectSendInviteMessage(String msg) void expectSendInviteMessage(String msg) throws Exception {
throws Exception {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageEncoder) oneOf(messageEncoder)
.encodeInviteMessage(contactGroupId, privateGroupId, .encodeInviteMessage(contactGroupId, privateGroupId,
@@ -142,7 +132,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
expectSendMessage(INVITE, true); expectSendMessage(INVITE, true);
} }
protected void expectSendJoinMessage(JoinMessage m, boolean visible) void expectSendJoinMessage(JoinMessage m, boolean visible)
throws Exception { throws Exception {
expectGetLocalTimestamp(messageTimestamp); expectGetLocalTimestamp(messageTimestamp);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -154,7 +144,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
expectSendMessage(JOIN, visible); expectSendMessage(JOIN, visible);
} }
protected void expectSendLeaveMessage(boolean visible) throws Exception { void expectSendLeaveMessage(boolean visible) throws Exception {
expectGetLocalTimestamp(messageTimestamp); expectGetLocalTimestamp(messageTimestamp);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageEncoder) oneOf(messageEncoder)
@@ -165,7 +155,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
expectSendMessage(LEAVE, visible); expectSendMessage(LEAVE, visible);
} }
protected void expectSendAbortMessage() throws Exception { void expectSendAbortMessage() throws Exception {
expectGetLocalTimestamp(messageTimestamp); expectGetLocalTimestamp(messageTimestamp);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageEncoder) oneOf(messageEncoder)
@@ -186,8 +176,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
}}); }});
} }
protected void expectSetPrivateGroupVisibility(Visibility v) void expectSetPrivateGroupVisibility(Visibility v) throws Exception {
throws Exception {
expectGetContactId(); expectGetContactId();
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(clientVersioningManager).getClientVisibility(txn, contactId, oneOf(clientVersioningManager).getClientVisibility(txn, contactId,
@@ -197,7 +186,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
}}); }});
} }
protected void expectGetContactId() throws Exception { void expectGetContactId() throws Exception {
BdfDictionary groupMeta = BdfDictionary BdfDictionary groupMeta = BdfDictionary
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt())); .of(new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -207,8 +196,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
}}); }});
} }
protected void expectIsSubscribedPrivateGroup() void expectIsSubscribedPrivateGroup() throws Exception {
throws Exception {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(db).containsGroup(txn, privateGroupId); oneOf(db).containsGroup(txn, privateGroupId);
will(returnValue(true)); will(returnValue(true));
@@ -217,19 +205,17 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
}}); }});
} }
protected void expectIsNotSubscribedPrivateGroup() void expectIsNotSubscribedPrivateGroup() throws Exception {
throws Exception {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(db).containsGroup(txn, privateGroupId); oneOf(db).containsGroup(txn, privateGroupId);
will(returnValue(false)); will(returnValue(false));
}}); }});
} }
protected void expectMarkMessageVisibleInUi(MessageId m, boolean visible) void expectMarkMessageVisibleInUi(MessageId m) throws Exception {
throws Exception {
BdfDictionary d = new BdfDictionary(); BdfDictionary d = new BdfDictionary();
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageEncoder).setVisibleInUi(d, visible); oneOf(messageEncoder).setVisibleInUi(d, true);
oneOf(clientHelper).mergeMessageMetadata(txn, m, d); oneOf(clientHelper).mergeMessageMetadata(txn, m, d);
}}); }});
} }

View File

@@ -305,7 +305,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
lastRemoteMessageId); lastRemoteMessageId);
expectSendJoinMessage(properJoinMessage, false); expectSendJoinMessage(properJoinMessage, false);
expectMarkMessageVisibleInUi(properJoinMessage.getId(), true); expectMarkMessageVisibleInUi(properJoinMessage.getId());
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageTracker) oneOf(messageTracker)
.trackMessage(txn, contactGroupId, inviteTimestamp + 1, .trackMessage(txn, contactGroupId, inviteTimestamp + 1,
@@ -394,7 +394,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
lastRemoteMessageId); lastRemoteMessageId);
CreatorSession session = getDefaultSession(INVITED); CreatorSession session = getDefaultSession(INVITED);
expectMarkMessageVisibleInUi(properLeaveMessage.getId(), true); expectMarkMessageVisibleInUi(properLeaveMessage.getId());
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageTracker) oneOf(messageTracker)
.trackMessage(txn, contactGroupId, inviteTimestamp + 1, .trackMessage(txn, contactGroupId, inviteTimestamp + 1,
@@ -463,7 +463,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
} }
private void assertSessionAborted(CreatorSession oldSession, private void assertSessionAborted(CreatorSession oldSession,
CreatorSession newSession) throws Exception { CreatorSession newSession) {
assertEquals(ERROR, newSession.getState()); assertEquals(ERROR, newSession.getState());
assertSessionRecordedSentMessage(newSession); assertSessionRecordedSentMessage(newSession);
assertSessionConstantsUnchanged(oldSession, newSession); assertSessionConstantsUnchanged(oldSession, newSession);

View File

@@ -46,7 +46,6 @@ import javax.annotation.Nullable;
import static junit.framework.TestCase.fail; import static junit.framework.TestCase.fail;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
@@ -106,9 +105,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION); private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final Group privateGroup = getGroup(CLIENT_ID, MAJOR_VERSION); private final Group privateGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final BdfDictionary meta = BdfDictionary.of(new BdfEntry("m", "e")); private final BdfDictionary meta = BdfDictionary.of(new BdfEntry("m", "e"));
private final Message message = private final Message message = getMessage(contactGroup.getId());
new Message(new MessageId(getRandomId()), contactGroup.getId(),
0L, getRandomBytes(MESSAGE_HEADER_LENGTH + 1));
private final BdfList body = BdfList.of("body"); private final BdfList body = BdfList.of("body");
private final SessionId sessionId = private final SessionId sessionId =
new SessionId(privateGroup.getId().getBytes()); new SessionId(privateGroup.getId().getBytes());
@@ -725,13 +722,11 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testGetInvitations() throws Exception { public void testGetInvitations() throws Exception {
BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u")); BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
MessageId messageId2 = new MessageId(TestUtils.getRandomId()); Message message2 = getMessage(contactGroup.getId());
BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e")); BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
Map<MessageId, BdfDictionary> results = new HashMap<>(); Map<MessageId, BdfDictionary> results = new HashMap<>();
results.put(message.getId(), meta); results.put(message.getId(), meta);
results.put(messageId2, meta2); results.put(message2.getId(), meta2);
Message message2 = new Message(messageId2, contactGroup.getId(),
0L, getRandomBytes(MESSAGE_HEADER_LENGTH + 1));
long time1 = 1L, time2 = 2L; long time1 = 1L, time2 = 2L;
String groupName = getRandomString(MAX_GROUP_NAME_LENGTH); String groupName = getRandomString(MAX_GROUP_NAME_LENGTH);
byte[] salt = getRandomBytes(GROUP_SALT_LENGTH); byte[] salt = getRandomBytes(GROUP_SALT_LENGTH);
@@ -766,7 +761,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
salt); salt);
will(returnValue(pg)); will(returnValue(pg));
// message 2 // message 2
oneOf(messageParser).getInviteMessage(txn, messageId2); oneOf(messageParser).getInviteMessage(txn, message2.getId());
will(returnValue(inviteMessage2)); will(returnValue(inviteMessage2));
oneOf(privateGroupFactory).createPrivateGroup(groupName, author, oneOf(privateGroupFactory).createPrivateGroup(groupName, author,
salt); salt);

View File

@@ -360,7 +360,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
oneOf(db).getContact(txn, contactId); oneOf(db).getContact(txn, contactId);
will(returnValue(contact)); will(returnValue(contact));
}}); }});
expectMarkMessageVisibleInUi(properInviteMessage.getId(), true); expectMarkMessageVisibleInUi(properInviteMessage.getId());
expectMarkMessageAvailableToAnswer(properInviteMessage.getId(), true); expectMarkMessageAvailableToAnswer(properInviteMessage.getId(), true);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageTracker).trackMessage(txn, contactGroupId, oneOf(messageTracker).trackMessage(txn, contactGroupId,
@@ -766,7 +766,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
} }
private void assertSessionAborted(InviteeSession oldSession, private void assertSessionAborted(InviteeSession oldSession,
InviteeSession newSession) throws Exception { InviteeSession newSession) {
assertEquals(ERROR, newSession.getState()); assertEquals(ERROR, newSession.getState());
assertSessionRecordedSentMessage(newSession); assertSessionRecordedSentMessage(newSession);
assertSessionConstantsUnchanged(oldSession, newSession); assertSessionConstantsUnchanged(oldSession, newSession);

View File

@@ -36,7 +36,7 @@ import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID; import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
import static org.briarproject.briar.api.blog.BlogSharingManager.MAJOR_VERSION; import static org.briarproject.briar.api.blog.BlogSharingManager.MAJOR_VERSION;
@@ -198,8 +198,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
throws Exception { throws Exception {
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
BdfDictionary sessionDict = new BdfDictionary(); BdfDictionary sessionDict = new BdfDictionary();
Message message = new Message(new MessageId(getRandomId()), Message message = getMessage(contactGroup.getId());
contactGroup.getId(), 42L, getRandomBytes(1337));
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact); MAJOR_VERSION, contact);