mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Effectively final.
This commit is contained in:
@@ -111,7 +111,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testCreateLocalState() throws DbException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
@@ -127,9 +127,9 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemovingContact() throws DbException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
final ContactId contactId = new ContactId(0);
|
||||
ContactId contactId = new ContactId(0);
|
||||
Contact contact = new Contact(contactId, blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), true, true);
|
||||
|
||||
@@ -149,9 +149,9 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemovingContactAfterRemovingBlog() throws DbException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
final ContactId contactId = new ContactId(0);
|
||||
ContactId contactId = new ContactId(0);
|
||||
Contact contact = new Contact(contactId, blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), true, true);
|
||||
|
||||
@@ -168,7 +168,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testIncomingMessage() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
BdfList body = BdfList.of("body");
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
@@ -207,7 +207,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testIncomingRssMessage() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
BdfList body = BdfList.of("body");
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
@@ -241,7 +241,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemoveBlog() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -259,9 +259,9 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalPost() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final BlogPost post = new BlogPost(message, null, localAuthor1);
|
||||
final BdfDictionary meta = BdfDictionary.of(
|
||||
Transaction txn = new Transaction(null, false);
|
||||
BlogPost post = new BlogPost(message, null, localAuthor1);
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_AUTHOR, authorDict1),
|
||||
@@ -305,9 +305,9 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalRssPost() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final BlogPost post = new BlogPost(rssMessage, null, rssLocalAuthor);
|
||||
final BdfDictionary meta = BdfDictionary.of(
|
||||
Transaction txn = new Transaction(null, false);
|
||||
BlogPost post = new BlogPost(rssMessage, null, rssLocalAuthor);
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
|
||||
@@ -350,10 +350,10 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalCommentToLocalPost() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
// The post was originally posted to blog 1, then reblogged to the
|
||||
// same blog (commenting on own post)
|
||||
final BdfDictionary postMeta = BdfDictionary.of(
|
||||
BdfDictionary postMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, false),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
||||
@@ -361,10 +361,10 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
final MessageId commentId = new MessageId(getRandomId());
|
||||
final Message commentMsg = new Message(commentId, blog1.getId(),
|
||||
MessageId commentId = new MessageId(getRandomId());
|
||||
Message commentMsg = new Message(commentId, blog1.getId(),
|
||||
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary commentMeta = BdfDictionary.of(
|
||||
BdfDictionary commentMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
|
||||
new BdfEntry(KEY_COMMENT, comment),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
@@ -436,14 +436,14 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalCommentToRemotePost() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
// The post was originally posted to blog 1, then reblogged to
|
||||
// blog 2 with a comment
|
||||
final BdfList originalPostBody = BdfList.of("originalPostBody");
|
||||
final MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
final Message wrappedPostMsg = new Message(wrappedPostId, blog2.getId(),
|
||||
BdfList originalPostBody = BdfList.of("originalPostBody");
|
||||
MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
Message wrappedPostMsg = new Message(wrappedPostId, blog2.getId(),
|
||||
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary wrappedPostMeta = BdfDictionary.of(
|
||||
BdfDictionary wrappedPostMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, false),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
||||
@@ -451,10 +451,10 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
final MessageId commentId = new MessageId(getRandomId());
|
||||
final Message commentMsg = new Message(commentId, blog2.getId(),
|
||||
MessageId commentId = new MessageId(getRandomId());
|
||||
Message commentMsg = new Message(commentId, blog2.getId(),
|
||||
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary commentMeta = BdfDictionary.of(
|
||||
BdfDictionary commentMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
|
||||
new BdfEntry(KEY_COMMENT, comment),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
@@ -539,14 +539,14 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalCommentToRemoteRssPost() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
// The post was originally posted to the RSS blog, then reblogged to
|
||||
// blog 1 with a comment
|
||||
final BdfList originalPostBody = BdfList.of("originalPostBody");
|
||||
final MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
final Message wrappedPostMsg = new Message(wrappedPostId, blog1.getId(),
|
||||
BdfList originalPostBody = BdfList.of("originalPostBody");
|
||||
MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
Message wrappedPostMsg = new Message(wrappedPostId, blog1.getId(),
|
||||
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary wrappedPostMeta = BdfDictionary.of(
|
||||
BdfDictionary wrappedPostMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, true),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, rssMessageId),
|
||||
@@ -554,10 +554,10 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
final MessageId commentId = new MessageId(getRandomId());
|
||||
final Message commentMsg = new Message(commentId, blog1.getId(),
|
||||
MessageId commentId = new MessageId(getRandomId());
|
||||
Message commentMsg = new Message(commentId, blog1.getId(),
|
||||
timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary commentMeta = BdfDictionary.of(
|
||||
BdfDictionary commentMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
|
||||
new BdfEntry(KEY_COMMENT, comment),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
@@ -640,18 +640,18 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddLocalCommentToRebloggedRemoteRssPost() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
// The post was originally posted to the RSS blog, then reblogged to
|
||||
// blog 1 with a comment
|
||||
final MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
final BdfList wrappedPostBody = BdfList.of("wrappedPostBody");
|
||||
final MessageId originalCommentId = new MessageId(getRandomId());
|
||||
final BdfList originalCommentBody = BdfList.of("originalCommentBody");
|
||||
MessageId wrappedPostId = new MessageId(getRandomId());
|
||||
BdfList wrappedPostBody = BdfList.of("wrappedPostBody");
|
||||
MessageId originalCommentId = new MessageId(getRandomId());
|
||||
BdfList originalCommentBody = BdfList.of("originalCommentBody");
|
||||
// The post and comment were reblogged to blog 2 with another comment
|
||||
final MessageId rewrappedPostId = new MessageId(getRandomId());
|
||||
final Message rewrappedPostMsg = new Message(rewrappedPostId,
|
||||
MessageId rewrappedPostId = new MessageId(getRandomId());
|
||||
Message rewrappedPostMsg = new Message(rewrappedPostId,
|
||||
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary rewrappedPostMeta = BdfDictionary.of(
|
||||
BdfDictionary rewrappedPostMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
|
||||
new BdfEntry(KEY_RSS_FEED, true),
|
||||
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
|
||||
@@ -659,10 +659,10 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
final MessageId wrappedCommentId = new MessageId(getRandomId());
|
||||
final Message wrappedCommentMsg = new Message(wrappedCommentId,
|
||||
MessageId wrappedCommentId = new MessageId(getRandomId());
|
||||
Message wrappedCommentMsg = new Message(wrappedCommentId,
|
||||
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary wrappedCommentMeta = BdfDictionary.of(
|
||||
BdfDictionary wrappedCommentMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, WRAPPED_COMMENT.getInt()),
|
||||
new BdfEntry(KEY_COMMENT, comment),
|
||||
new BdfEntry(KEY_PARENT_MSG_ID, rewrappedPostId),
|
||||
@@ -671,11 +671,11 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
|
||||
);
|
||||
final String localComment = getRandomString(MAX_BLOG_COMMENT_LENGTH);
|
||||
final MessageId localCommentId = new MessageId(getRandomId());
|
||||
final Message localCommentMsg = new Message(localCommentId,
|
||||
String localComment = getRandomString(MAX_BLOG_COMMENT_LENGTH);
|
||||
MessageId localCommentId = new MessageId(getRandomId());
|
||||
Message localCommentMsg = new Message(localCommentId,
|
||||
blog2.getId(), timestamp, getRandomBytes(MAX_MESSAGE_LENGTH));
|
||||
final BdfDictionary localCommentMeta = BdfDictionary.of(
|
||||
BdfDictionary localCommentMeta = BdfDictionary.of(
|
||||
new BdfEntry(KEY_TYPE, COMMENT.getInt()),
|
||||
new BdfEntry(KEY_COMMENT, localComment),
|
||||
new BdfEntry(KEY_TIMESTAMP, timestamp),
|
||||
@@ -796,7 +796,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testBlogCanBeRemoved() throws Exception {
|
||||
// check that own personal blogs can not be removed
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
Transaction txn = new Transaction(null, true);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
@@ -809,7 +809,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// check that blogs of contacts can be removed
|
||||
final Transaction txn2 = new Transaction(null, true);
|
||||
Transaction txn2 = new Transaction(null, true);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn2));
|
||||
|
||||
@@ -126,7 +126,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testBlogPost() throws Exception {
|
||||
// check that blog0 has no posts
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
Collection<BlogPostHeader> headers0 =
|
||||
blogManager0.getPostHeaders(blog0.getId());
|
||||
assertEquals(0, headers0.size());
|
||||
@@ -164,7 +164,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testBlogPostInWrongBlog() throws Exception {
|
||||
// add a post to blog1
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog1.getId(), clock.currentTimeMillis(), null,
|
||||
author0, body);
|
||||
@@ -203,7 +203,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testBlogComment() throws Exception {
|
||||
// add a post to blog0
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, body);
|
||||
@@ -248,7 +248,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testBlogCommentOnOwnPost() throws Exception {
|
||||
// add a post to blog0
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, body);
|
||||
@@ -284,7 +284,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testCommentOnComment() throws Exception {
|
||||
// add a post to blog0
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, body);
|
||||
@@ -372,7 +372,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testCommentOnOwnComment() throws Exception {
|
||||
// add a post to blog0
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, body);
|
||||
@@ -417,7 +417,7 @@ public class BlogManagerIntegrationTest
|
||||
assertTrue(rssBlog.isRssFeed());
|
||||
|
||||
// add a feed post to rssBlog
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(rssBlog.getId(), clock.currentTimeMillis(),
|
||||
null, author0, body);
|
||||
@@ -436,7 +436,7 @@ public class BlogManagerIntegrationTest
|
||||
@Test
|
||||
public void testFeedReblog() throws Exception {
|
||||
// add a feed post to rssBlog
|
||||
final String body = getRandomString(42);
|
||||
String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(rssBlog.getId(), clock.currentTimeMillis(),
|
||||
null, author0, body);
|
||||
|
||||
@@ -111,12 +111,12 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
|
||||
private void testValidateProperBlogPost(Blog b, boolean rssFeed)
|
||||
throws IOException, GeneralSecurityException {
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m = BdfList.of(POST.getInt(), body, sigBytes);
|
||||
|
||||
BdfList signed = BdfList.of(b.getId(), message.getTimestamp(), body);
|
||||
expectCrypto(b, SIGNING_LABEL_POST, signed, sigBytes);
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
@@ -150,14 +150,14 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
String comment = "This is a blog comment";
|
||||
MessageId pOriginalId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId currentId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m = BdfList.of(COMMENT.getInt(), comment, pOriginalId,
|
||||
currentId, sigBytes);
|
||||
|
||||
BdfList signed = BdfList.of(blog.getId(), message.getTimestamp(),
|
||||
comment, pOriginalId, currentId);
|
||||
expectCrypto(blog, SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(comment, result.getString(KEY_COMMENT));
|
||||
@@ -175,14 +175,14 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
// comment, parent_original_id, signature, parent_current_id
|
||||
MessageId originalId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId currentId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m = BdfList.of(COMMENT.getInt(), null, originalId, currentId,
|
||||
sigBytes);
|
||||
|
||||
BdfList signed = BdfList.of(blog.getId(), message.getTimestamp(), null,
|
||||
originalId, currentId);
|
||||
expectCrypto(blog, SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertFalse(result.containsKey(KEY_COMMENT));
|
||||
@@ -201,18 +201,18 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
testValidateProperWrappedPost(rssBlog, true);
|
||||
}
|
||||
|
||||
private void testValidateProperWrappedPost(final Blog b, boolean rssFeed)
|
||||
private void testValidateProperWrappedPost(Blog b, boolean rssFeed)
|
||||
throws IOException, GeneralSecurityException {
|
||||
// group descriptor, timestamp, content, signature
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
BdfList m = BdfList.of(WRAPPED_POST.getInt(), descriptor,
|
||||
message.getTimestamp(), body, sigBytes);
|
||||
|
||||
BdfList signed = BdfList.of(b.getId(), message.getTimestamp(), body);
|
||||
expectCrypto(b, SIGNING_LABEL_POST, signed, sigBytes);
|
||||
|
||||
final BdfList originalList = BdfList.of(POST.getInt(), body, sigBytes);
|
||||
final byte[] originalBody = TestUtils.getRandomBytes(42);
|
||||
BdfList originalList = BdfList.of(POST.getInt(), body, sigBytes);
|
||||
byte[] originalBody = TestUtils.getRandomBytes(42);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(groupFactory).createGroup(clientId, descriptor);
|
||||
@@ -227,7 +227,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
will(returnValue(message));
|
||||
}});
|
||||
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
@@ -243,7 +243,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
String comment = "This is another comment";
|
||||
MessageId originalId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId oldId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] sigBytes = TestUtils.getRandomBytes(42);
|
||||
MessageId currentId = new MessageId(TestUtils.getRandomId());
|
||||
BdfList m = BdfList.of(WRAPPED_COMMENT.getInt(), descriptor,
|
||||
message.getTimestamp(), comment, originalId, oldId, sigBytes,
|
||||
@@ -253,9 +253,9 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
comment, originalId, oldId);
|
||||
expectCrypto(blog, SIGNING_LABEL_COMMENT, signed, sigBytes);
|
||||
|
||||
final BdfList originalList = BdfList.of(COMMENT.getInt(), comment,
|
||||
BdfList originalList = BdfList.of(COMMENT.getInt(), comment,
|
||||
originalId, oldId, sigBytes);
|
||||
final byte[] originalBody = TestUtils.getRandomBytes(42);
|
||||
byte[] originalBody = TestUtils.getRandomBytes(42);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(groupFactory).createGroup(clientId, descriptor);
|
||||
@@ -268,7 +268,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
will(returnValue(message));
|
||||
}});
|
||||
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, m).getDictionary();
|
||||
|
||||
assertEquals(comment, result.getString(KEY_COMMENT));
|
||||
@@ -279,8 +279,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
private void expectCrypto(final Blog b, final String label,
|
||||
final BdfList signed, final byte[] sig)
|
||||
private void expectCrypto(Blog b, String label, BdfList signed, byte[] sig)
|
||||
throws IOException, GeneralSecurityException {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).parseBlog(group);
|
||||
|
||||
@@ -54,19 +54,19 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testSendingMessages() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final byte[] body = new byte[123];
|
||||
final Metadata groupMetadata = new Metadata();
|
||||
final Metadata messageMetadata = new Metadata();
|
||||
final Metadata groupMetadata1 = new Metadata();
|
||||
final byte[] queueState = new byte[123];
|
||||
Transaction txn = new Transaction(null, false);
|
||||
byte[] body = new byte[123];
|
||||
Metadata groupMetadata = new Metadata();
|
||||
Metadata messageMetadata = new Metadata();
|
||||
Metadata groupMetadata1 = new Metadata();
|
||||
byte[] queueState = new byte[123];
|
||||
groupMetadata1.put(QUEUE_STATE_KEY, queueState);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -123,21 +123,20 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testValidatorRejectsShortMessage() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
|
||||
final AtomicReference<MessageValidator> captured =
|
||||
new AtomicReference<>();
|
||||
final QueueMessageValidator queueMessageValidator =
|
||||
AtomicReference<MessageValidator> captured = new AtomicReference<>();
|
||||
QueueMessageValidator queueMessageValidator =
|
||||
context.mock(QueueMessageValidator.class);
|
||||
// The message is too short to be a valid queue message
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH - 1];
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH - 1];
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerMessageValidator(with(clientId),
|
||||
@@ -167,23 +166,22 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testValidatorRejectsNegativeQueuePosition() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
|
||||
final AtomicReference<MessageValidator> captured =
|
||||
new AtomicReference<>();
|
||||
final QueueMessageValidator queueMessageValidator =
|
||||
AtomicReference<MessageValidator> captured = new AtomicReference<>();
|
||||
QueueMessageValidator queueMessageValidator =
|
||||
context.mock(QueueMessageValidator.class);
|
||||
// The message has a negative queue position
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
for (int i = 0; i < 8; i++)
|
||||
raw[MESSAGE_HEADER_LENGTH + i] = (byte) 0xFF;
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerMessageValidator(with(clientId),
|
||||
@@ -213,24 +211,23 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testValidatorDelegatesValidMessage() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
|
||||
final AtomicReference<MessageValidator> captured =
|
||||
new AtomicReference<>();
|
||||
final QueueMessageValidator queueMessageValidator =
|
||||
AtomicReference<MessageValidator> captured = new AtomicReference<>();
|
||||
QueueMessageValidator queueMessageValidator =
|
||||
context.mock(QueueMessageValidator.class);
|
||||
final Metadata metadata = new Metadata();
|
||||
final MessageContext messageContext =
|
||||
Metadata metadata = new Metadata();
|
||||
MessageContext messageContext =
|
||||
new MessageContext(metadata);
|
||||
// The message is valid, with a queue position of zero
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerMessageValidator(with(clientId),
|
||||
@@ -261,25 +258,24 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingMessageHookDeletesDuplicateMessage()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
AtomicReference<IncomingMessageHook> captured = new AtomicReference<>();
|
||||
IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Metadata groupMetadata = new Metadata();
|
||||
final byte[] queueState = new byte[123];
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Metadata groupMetadata = new Metadata();
|
||||
byte[] queueState = new byte[123];
|
||||
groupMetadata.put(QUEUE_STATE_KEY, queueState);
|
||||
// The message has queue position 0
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
@@ -313,27 +309,26 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingMessageHookAddsOutOfOrderMessageToPendingList()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
AtomicReference<IncomingMessageHook> captured = new AtomicReference<>();
|
||||
IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Metadata groupMetadata = new Metadata();
|
||||
final byte[] queueState = new byte[123];
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Metadata groupMetadata = new Metadata();
|
||||
byte[] queueState = new byte[123];
|
||||
groupMetadata.put(QUEUE_STATE_KEY, queueState);
|
||||
// The message has queue position 1
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
ByteUtils.writeUint64(1L, raw, MESSAGE_HEADER_LENGTH);
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
final BdfList pending = BdfList.of(BdfList.of(1L, messageId));
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
BdfList pending = BdfList.of(BdfList.of(1L, messageId));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
@@ -369,26 +364,25 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingMessageHookDelegatesInOrderMessage()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
AtomicReference<IncomingMessageHook> captured = new AtomicReference<>();
|
||||
IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Metadata groupMetadata = new Metadata();
|
||||
final byte[] queueState = new byte[123];
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Metadata groupMetadata = new Metadata();
|
||||
byte[] queueState = new byte[123];
|
||||
groupMetadata.put(QUEUE_STATE_KEY, queueState);
|
||||
// The message has queue position 0
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
final Metadata messageMetadata = new Metadata();
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
Metadata messageMetadata = new Metadata();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
@@ -427,33 +421,32 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingMessageHookRetrievesPendingMessage()
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
final QueueMessageFactory queueMessageFactory =
|
||||
DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
QueueMessageFactory queueMessageFactory =
|
||||
context.mock(QueueMessageFactory.class);
|
||||
final ValidationManager validationManager =
|
||||
ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
AtomicReference<IncomingMessageHook> captured = new AtomicReference<>();
|
||||
IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Metadata groupMetadata = new Metadata();
|
||||
final byte[] queueState = new byte[123];
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Metadata groupMetadata = new Metadata();
|
||||
byte[] queueState = new byte[123];
|
||||
groupMetadata.put(QUEUE_STATE_KEY, queueState);
|
||||
// The message has queue position 0
|
||||
final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
final Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
final Metadata messageMetadata = new Metadata();
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
Message message = new Message(messageId, groupId, timestamp, raw);
|
||||
Metadata messageMetadata = new Metadata();
|
||||
// Queue position 1 is pending
|
||||
final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw1 = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
final QueueMessage message1 = new QueueMessage(messageId1, groupId,
|
||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
byte[] raw1 = new byte[QUEUE_MESSAGE_HEADER_LENGTH];
|
||||
QueueMessage message1 = new QueueMessage(messageId1, groupId,
|
||||
timestamp, 1L, raw1);
|
||||
final Metadata messageMetadata1 = new Metadata();
|
||||
final BdfList pending = BdfList.of(BdfList.of(1L, messageId1));
|
||||
Metadata messageMetadata1 = new Metadata();
|
||||
BdfList pending = BdfList.of(BdfList.of(1L, messageId1));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
|
||||
@@ -89,7 +89,7 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testFetchFeedIoException() throws Exception {
|
||||
final BdfDictionary feedDict= new BdfDictionary();
|
||||
BdfDictionary feedDict= new BdfDictionary();
|
||||
BdfList feedList = BdfList.of(feedDict);
|
||||
|
||||
expectGetFeeds(feedList);
|
||||
@@ -104,17 +104,16 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testPostFeedEntriesEmptyDate() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
List<SyndEntry> entries = new ArrayList<>();
|
||||
entries.add(new SyndEntryImpl());
|
||||
final SyndEntry entry = new SyndEntryImpl();
|
||||
SyndEntry entry = new SyndEntryImpl();
|
||||
entry.setUpdatedDate(new Date());
|
||||
entries.add(entry);
|
||||
final String body =
|
||||
"<p> (" + entry.getUpdatedDate().toString() + ")</p>";
|
||||
String body = "<p> (" + entry.getUpdatedDate().toString() + ")</p>";
|
||||
Message msg = new Message(new MessageId(getRandomId()), blogGroupId, 0,
|
||||
getRandomBytes(42));
|
||||
final BlogPost post = new BlogPost(msg, null, localAuthor);
|
||||
BlogPost post = new BlogPost(msg, null, localAuthor);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -139,9 +138,9 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectGetFeeds(final BdfList feedList) throws Exception {
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
final BdfDictionary feedsDict =
|
||||
private void expectGetFeeds(BdfList feedList) throws Exception {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
BdfDictionary feedsDict =
|
||||
BdfDictionary.of(new BdfEntry(KEY_FEEDS, feedList));
|
||||
expectGetLocalGroup();
|
||||
context.checking(new Expectations() {{
|
||||
@@ -158,8 +157,8 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectStoreFeed(final BdfList feedList) throws Exception {
|
||||
final BdfDictionary feedDict =
|
||||
private void expectStoreFeed(BdfList feedList) throws Exception {
|
||||
BdfDictionary feedDict =
|
||||
BdfDictionary.of(new BdfEntry(KEY_FEEDS, feedList));
|
||||
expectGetLocalGroup();
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -81,10 +81,10 @@ public class ForumManagerTest
|
||||
@Test
|
||||
public void testForumPost() throws Exception {
|
||||
assertEquals(1, forumManager0.getForums().size());
|
||||
final long ms1 = clock.currentTimeMillis() - 1000L;
|
||||
final String body1 = "some forum text";
|
||||
final long ms2 = clock.currentTimeMillis();
|
||||
final String body2 = "some other forum text";
|
||||
long ms1 = clock.currentTimeMillis() - 1000L;
|
||||
String body1 = "some forum text";
|
||||
long ms2 = clock.currentTimeMillis();
|
||||
String body2 = "some other forum text";
|
||||
ForumPost post1 =
|
||||
createForumPost(forum0.getGroup().getId(), null, body1, ms1);
|
||||
assertEquals(ms1, post1.getMessage().getTimestamp());
|
||||
@@ -109,7 +109,7 @@ public class ForumManagerTest
|
||||
forumManager0.getPostHeaders(forum0.getGroup().getId());
|
||||
assertEquals(2, headers.size());
|
||||
for (ForumPostHeader h : headers) {
|
||||
final String hBody = forumManager0.getPostBody(h.getId());
|
||||
String hBody = forumManager0.getPostBody(h.getId());
|
||||
|
||||
boolean isPost1 = h.getId().equals(post1.getMessage().getId());
|
||||
boolean isPost2 = h.getId().equals(post2.getMessage().getId());
|
||||
|
||||
@@ -166,12 +166,12 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
|
||||
@Test
|
||||
public void testAcceptsMinLengthAuthorName() throws Exception {
|
||||
final String shortAuthorName = StringUtils.getRandomString(1);
|
||||
String shortAuthorName = StringUtils.getRandomString(1);
|
||||
BdfList shortNameAuthorList =
|
||||
BdfList.of(shortAuthorName, authorPublicKey);
|
||||
final Author shortNameAuthor =
|
||||
Author shortNameAuthor =
|
||||
new Author(authorId, shortAuthorName, authorPublicKey);
|
||||
final BdfList signedWithShortNameAuthor = BdfList.of(groupId, timestamp,
|
||||
BdfList signedWithShortNameAuthor = BdfList.of(groupId, timestamp,
|
||||
parentId.getBytes(), shortNameAuthorList, content);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -259,7 +259,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
|
||||
@Test
|
||||
public void testAcceptsMinLengthContent() throws Exception {
|
||||
String shortContent = "";
|
||||
final BdfList signedWithShortContent = BdfList.of(groupId, timestamp,
|
||||
BdfList signedWithShortContent = BdfList.of(groupId, timestamp,
|
||||
parentId.getBytes(), authorList, shortContent);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -174,7 +174,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
public void testIncomingRequestMessage()
|
||||
throws DbException, FormatException {
|
||||
|
||||
final BdfDictionary msg = new BdfDictionary();
|
||||
BdfDictionary msg = new BdfDictionary();
|
||||
msg.put(TYPE, TYPE_REQUEST);
|
||||
msg.put(GROUP_ID, introductionGroup1.getId());
|
||||
msg.put(SESSION_ID, sessionId);
|
||||
@@ -183,7 +183,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
msg.put(NAME, introducee2.getAuthor().getName());
|
||||
msg.put(PUBLIC_KEY, introducee2.getAuthor().getPublicKey());
|
||||
|
||||
final BdfDictionary state =
|
||||
BdfDictionary state =
|
||||
initializeSessionState(txn, introductionGroup1.getId(), msg);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -201,7 +201,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
public void testIncomingResponseMessage()
|
||||
throws DbException, FormatException {
|
||||
|
||||
final BdfDictionary msg = new BdfDictionary();
|
||||
BdfDictionary msg = new BdfDictionary();
|
||||
msg.put(TYPE, TYPE_RESPONSE);
|
||||
msg.put(GROUP_ID, introductionGroup1.getId());
|
||||
msg.put(SESSION_ID, sessionId);
|
||||
@@ -210,7 +210,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
msg.put(NAME, introducee2.getAuthor().getName());
|
||||
msg.put(PUBLIC_KEY, introducee2.getAuthor().getPublicKey());
|
||||
|
||||
final BdfDictionary state =
|
||||
BdfDictionary state =
|
||||
initializeSessionState(txn, introductionGroup1.getId(), msg);
|
||||
state.put(STATE, IntroduceeProtocolState.AWAIT_RESPONSES.ordinal());
|
||||
|
||||
@@ -236,7 +236,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
throws DbException, FormatException, GeneralSecurityException {
|
||||
|
||||
// TODO MR !237 should use its new default initialization method here
|
||||
final BdfDictionary msg = new BdfDictionary();
|
||||
BdfDictionary msg = new BdfDictionary();
|
||||
msg.put(TYPE, TYPE_RESPONSE);
|
||||
msg.put(GROUP_ID, introductionGroup1.getId());
|
||||
msg.put(SESSION_ID, sessionId);
|
||||
@@ -244,19 +244,19 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
msg.put(MESSAGE_TIME, time);
|
||||
msg.put(NAME, introducee2.getAuthor().getName());
|
||||
msg.put(PUBLIC_KEY, introducee2.getAuthor().getPublicKey());
|
||||
final BdfDictionary state =
|
||||
BdfDictionary state =
|
||||
initializeSessionState(txn, introductionGroup1.getId(), msg);
|
||||
|
||||
// prepare state for incoming ACK
|
||||
state.put(STATE, IntroduceeProtocolState.AWAIT_ACK.ordinal());
|
||||
state.put(ADDED_CONTACT_ID, 2);
|
||||
final byte[] nonce = TestUtils.getRandomBytes(42);
|
||||
byte[] nonce = TestUtils.getRandomBytes(42);
|
||||
state.put(NONCE, nonce);
|
||||
state.put(PUBLIC_KEY, introducee2.getAuthor().getPublicKey());
|
||||
|
||||
// create incoming ACK message
|
||||
final byte[] mac = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
final byte[] sig = TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH);
|
||||
byte[] mac = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
byte[] sig = TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH);
|
||||
BdfDictionary ack = BdfDictionary.of(
|
||||
new BdfEntry(TYPE, TYPE_ACK),
|
||||
new BdfEntry(SESSION_ID, sessionId),
|
||||
@@ -286,9 +286,9 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
public void testSignatureVerification()
|
||||
throws FormatException, DbException, GeneralSecurityException {
|
||||
|
||||
final byte[] publicKeyBytes = introducee2.getAuthor().getPublicKey();
|
||||
final byte[] nonce = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
final byte[] sig = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
byte[] publicKeyBytes = introducee2.getAuthor().getPublicKey();
|
||||
byte[] nonce = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
byte[] sig = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
state.put(PUBLIC_KEY, publicKeyBytes);
|
||||
@@ -308,12 +308,12 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
public void testMacVerification()
|
||||
throws FormatException, DbException, GeneralSecurityException {
|
||||
|
||||
final byte[] publicKeyBytes = introducee2.getAuthor().getPublicKey();
|
||||
final BdfDictionary tp = BdfDictionary.of(new BdfEntry("fake", "fake"));
|
||||
final byte[] ePublicKeyBytes =
|
||||
byte[] publicKeyBytes = introducee2.getAuthor().getPublicKey();
|
||||
BdfDictionary tp = BdfDictionary.of(new BdfEntry("fake", "fake"));
|
||||
byte[] ePublicKeyBytes =
|
||||
TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
final byte[] mac = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
final SecretKey macKey = TestUtils.getSecretKey();
|
||||
byte[] mac = TestUtils.getRandomBytes(MAC_LENGTH);
|
||||
SecretKey macKey = TestUtils.getSecretKey();
|
||||
|
||||
// move state to where it would be after an ACK arrived
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
@@ -324,7 +324,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
state.put(MAC, mac);
|
||||
state.put(MAC_KEY, macKey.getBytes());
|
||||
|
||||
final byte[] signBytes = TestUtils.getRandomBytes(42);
|
||||
byte[] signBytes = TestUtils.getRandomBytes(42);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).toByteArray(
|
||||
BdfList.of(publicKeyBytes, ePublicKeyBytes, tp, time));
|
||||
@@ -356,17 +356,17 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
private BdfDictionary initializeSessionState(final Transaction txn,
|
||||
final GroupId groupId, final BdfDictionary msg)
|
||||
private BdfDictionary initializeSessionState(Transaction txn,
|
||||
GroupId groupId, BdfDictionary msg)
|
||||
throws DbException, FormatException {
|
||||
|
||||
final SecureRandom secureRandom = context.mock(SecureRandom.class);
|
||||
final Bytes salt = new Bytes(new byte[64]);
|
||||
final BdfDictionary groupMetadata = BdfDictionary.of(
|
||||
SecureRandom secureRandom = context.mock(SecureRandom.class);
|
||||
Bytes salt = new Bytes(new byte[64]);
|
||||
BdfDictionary groupMetadata = BdfDictionary.of(
|
||||
new BdfEntry(CONTACT, introducee1.getId().getInt())
|
||||
);
|
||||
final boolean contactExists = false;
|
||||
final BdfDictionary state = new BdfDictionary();
|
||||
boolean contactExists = false;
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
state.put(STORAGE_ID, localStateMessage.getId());
|
||||
state.put(STATE, AWAIT_REQUEST.getValue());
|
||||
state.put(ROLE, ROLE_INTRODUCEE);
|
||||
|
||||
@@ -108,14 +108,14 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testMakeIntroduction() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final long time = 42L;
|
||||
Transaction txn = new Transaction(null, false);
|
||||
long time = 42L;
|
||||
context.setImposteriser(ClassImposteriser.INSTANCE);
|
||||
final SecureRandom secureRandom = context.mock(SecureRandom.class);
|
||||
final Bytes salt = new Bytes(new byte[64]);
|
||||
final Message msg = new Message(new MessageId(TestUtils.getRandomId()),
|
||||
SecureRandom secureRandom = context.mock(SecureRandom.class);
|
||||
Bytes salt = new Bytes(new byte[64]);
|
||||
Message msg = new Message(new MessageId(TestUtils.getRandomId()),
|
||||
localGroup0.getId(), time, TestUtils.getRandomBytes(64));
|
||||
final BdfDictionary state = new BdfDictionary();
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
state.put(SESSION_ID, msg.getId());
|
||||
state.put(STORAGE_ID, msg.getId());
|
||||
state.put(STATE, PREPARE_REQUESTS.getValue());
|
||||
@@ -128,25 +128,25 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
state.put(CONTACT_ID_2, introducee2.getId().getInt());
|
||||
state.put(AUTHOR_ID_1, introducee1.getAuthor().getId());
|
||||
state.put(AUTHOR_ID_2, introducee2.getAuthor().getId());
|
||||
final BdfDictionary state2 = (BdfDictionary) state.clone();
|
||||
BdfDictionary state2 = (BdfDictionary) state.clone();
|
||||
state2.put(STATE, AWAIT_RESPONSES.getValue());
|
||||
|
||||
final BdfDictionary msg1 = new BdfDictionary();
|
||||
BdfDictionary msg1 = new BdfDictionary();
|
||||
msg1.put(TYPE, TYPE_REQUEST);
|
||||
msg1.put(SESSION_ID, state.getRaw(SESSION_ID));
|
||||
msg1.put(GROUP_ID, state.getRaw(GROUP_ID_1));
|
||||
msg1.put(NAME, state.getString(CONTACT_2));
|
||||
msg1.put(PUBLIC_KEY, introducee2.getAuthor().getPublicKey());
|
||||
final BdfDictionary msg1send = (BdfDictionary) msg1.clone();
|
||||
BdfDictionary msg1send = (BdfDictionary) msg1.clone();
|
||||
msg1send.put(MESSAGE_TIME, time);
|
||||
|
||||
final BdfDictionary msg2 = new BdfDictionary();
|
||||
BdfDictionary msg2 = new BdfDictionary();
|
||||
msg2.put(TYPE, TYPE_REQUEST);
|
||||
msg2.put(SESSION_ID, state.getRaw(SESSION_ID));
|
||||
msg2.put(GROUP_ID, state.getRaw(GROUP_ID_2));
|
||||
msg2.put(NAME, state.getString(CONTACT_1));
|
||||
msg2.put(PUBLIC_KEY, introducee1.getAuthor().getPublicKey());
|
||||
final BdfDictionary msg2send = (BdfDictionary) msg2.clone();
|
||||
BdfDictionary msg2send = (BdfDictionary) msg2.clone();
|
||||
msg2send.put(MESSAGE_TIME, time);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -146,7 +146,7 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testAcceptIntroduction() throws DbException, FormatException {
|
||||
final BdfDictionary state = BdfDictionary.of(
|
||||
BdfDictionary state = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_ID_1, introductionGroup1.getId()),
|
||||
new BdfEntry(GROUP_ID_2, introductionGroup2.getId())
|
||||
);
|
||||
@@ -177,7 +177,7 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testDeclineIntroduction() throws DbException, FormatException {
|
||||
final BdfDictionary state = BdfDictionary.of(
|
||||
BdfDictionary state = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_ID_1, introductionGroup1.getId()),
|
||||
new BdfEntry(GROUP_ID_2, introductionGroup2.getId())
|
||||
);
|
||||
@@ -210,8 +210,8 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
public void testGetIntroductionMessages()
|
||||
throws DbException, FormatException {
|
||||
|
||||
final Map<MessageId, BdfDictionary> metadata = Collections.emptyMap();
|
||||
final Collection<MessageStatus> statuses = Collections.emptyList();
|
||||
Map<MessageId, BdfDictionary> metadata = Collections.emptyMap();
|
||||
Collection<MessageStatus> statuses = Collections.emptyList();
|
||||
txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -240,10 +240,10 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingRequestMessage()
|
||||
throws DbException, FormatException {
|
||||
|
||||
final BdfDictionary msg = new BdfDictionary();
|
||||
BdfDictionary msg = new BdfDictionary();
|
||||
msg.put(TYPE, TYPE_REQUEST);
|
||||
|
||||
final BdfDictionary state = new BdfDictionary();
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -267,12 +267,12 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
public void testIncomingResponseMessage()
|
||||
throws DbException, FormatException {
|
||||
|
||||
final BdfDictionary msg = BdfDictionary.of(
|
||||
BdfDictionary msg = BdfDictionary.of(
|
||||
new BdfEntry(TYPE, TYPE_RESPONSE),
|
||||
new BdfEntry(SESSION_ID, sessionId)
|
||||
);
|
||||
|
||||
final BdfDictionary state = new BdfDictionary();
|
||||
BdfDictionary state = new BdfDictionary();
|
||||
state.put(ROLE, ROLE_INTRODUCER);
|
||||
state.put(GROUP_ID_1, introductionGroup1.getId());
|
||||
state.put(GROUP_ID_2, introductionGroup2.getId());
|
||||
|
||||
@@ -83,17 +83,17 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testValidateProperIntroductionRequest() throws IOException {
|
||||
final byte[] sessionId = TestUtils.getRandomId();
|
||||
final String name = StringUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
final byte[] publicKey =
|
||||
byte[] sessionId = TestUtils.getRandomId();
|
||||
String name = StringUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
byte[] publicKey =
|
||||
TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
final String text =
|
||||
String text =
|
||||
StringUtils.getRandomString(MAX_INTRODUCTION_MESSAGE_LENGTH);
|
||||
|
||||
BdfList body = BdfList.of(TYPE_REQUEST, sessionId,
|
||||
name, publicKey, text);
|
||||
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, body)
|
||||
.getDictionary();
|
||||
|
||||
@@ -192,7 +192,7 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
msg.getBoolean(ACCEPT), msg.getLong(TIME),
|
||||
msg.getRaw(E_PUBLIC_KEY), msg.getDictionary(TRANSPORT));
|
||||
|
||||
final BdfDictionary result =
|
||||
BdfDictionary result =
|
||||
validator.validateMessage(message, group, body).getDictionary();
|
||||
|
||||
assertEquals(Long.valueOf(TYPE_RESPONSE), result.getLong(TYPE));
|
||||
|
||||
@@ -58,26 +58,26 @@ public class MessageSenderTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testSendMessage() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Group privateGroup =
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Group privateGroup =
|
||||
new Group(new GroupId(TestUtils.getRandomId()),
|
||||
new ClientId(StringUtils.getRandomString(5)),
|
||||
new byte[0]);
|
||||
final SessionId sessionId = new SessionId(TestUtils.getRandomId());
|
||||
SessionId sessionId = new SessionId(TestUtils.getRandomId());
|
||||
byte[] mac = TestUtils.getRandomBytes(42);
|
||||
byte[] sig = TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH);
|
||||
final long time = 42L;
|
||||
final BdfDictionary msg = BdfDictionary.of(
|
||||
long time = 42L;
|
||||
BdfDictionary msg = BdfDictionary.of(
|
||||
new BdfEntry(TYPE, TYPE_ACK),
|
||||
new BdfEntry(GROUP_ID, privateGroup.getId()),
|
||||
new BdfEntry(SESSION_ID, sessionId),
|
||||
new BdfEntry(MAC, mac),
|
||||
new BdfEntry(SIGNATURE, sig)
|
||||
);
|
||||
final BdfList bodyList =
|
||||
BdfList bodyList =
|
||||
BdfList.of(TYPE_ACK, sessionId.getBytes(), mac, sig);
|
||||
final byte[] body = TestUtils.getRandomBytes(8);
|
||||
final Metadata metadata = new Metadata();
|
||||
byte[] body = TestUtils.getRandomBytes(8);
|
||||
Metadata metadata = new Metadata();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).toByteArray(bodyList);
|
||||
|
||||
@@ -330,7 +330,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
||||
}
|
||||
|
||||
private void expectCreateAuthor(final Author member) {
|
||||
private void expectCreateAuthor(Author member) {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(authorFactory).createAuthor(member.getName(),
|
||||
member.getPublicKey());
|
||||
@@ -345,10 +345,9 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectJoinMessage(final Author member, final BdfList invite,
|
||||
final boolean creatorSigValid, final boolean memberSigValid)
|
||||
throws Exception {
|
||||
final BdfList signed = BdfList.of(group.getId(), message.getTimestamp(),
|
||||
private void expectJoinMessage(Author member, BdfList invite,
|
||||
boolean creatorSigValid, boolean memberSigValid) throws Exception {
|
||||
BdfList signed = BdfList.of(group.getId(), message.getTimestamp(),
|
||||
JOIN.getInt(), member.getName(), member.getPublicKey(), invite);
|
||||
expectCreateAuthor(member);
|
||||
expectParsePrivateGroup();
|
||||
@@ -610,9 +609,9 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
messageContext.getDictionary().containsKey(KEY_PARENT_MSG_ID));
|
||||
}
|
||||
|
||||
private void expectPostMessage(final Author member,
|
||||
final MessageId parentId, final boolean sigValid) throws Exception {
|
||||
final BdfList signed = BdfList.of(group.getId(), message.getTimestamp(),
|
||||
private void expectPostMessage(Author member, MessageId parentId,
|
||||
boolean sigValid) throws Exception {
|
||||
BdfList signed = BdfList.of(group.getId(), message.getTimestamp(),
|
||||
POST.getInt(), member.getName(), member.getPublicKey(),
|
||||
parentId == null ? null : parentId.getBytes(),
|
||||
previousMsgId.getBytes(), postContent);
|
||||
|
||||
@@ -112,14 +112,14 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
assertEquals(inviteTimestamp, s.getInviteTimestamp());
|
||||
}
|
||||
|
||||
protected void expectGetLocalTimestamp(final long time) {
|
||||
protected void expectGetLocalTimestamp(long time) {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(time));
|
||||
}});
|
||||
}
|
||||
|
||||
protected void expectSendInviteMessage(final String msg)
|
||||
protected void expectSendInviteMessage(String msg)
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder)
|
||||
@@ -131,7 +131,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
expectSendMessage(INVITE, true);
|
||||
}
|
||||
|
||||
protected void expectSendJoinMessage(final JoinMessage m, boolean visible)
|
||||
protected void expectSendJoinMessage(JoinMessage m, boolean visible)
|
||||
throws Exception {
|
||||
expectGetLocalTimestamp(messageTimestamp);
|
||||
context.checking(new Expectations() {{
|
||||
@@ -165,8 +165,8 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
expectSendMessage(ABORT, false);
|
||||
}
|
||||
|
||||
private void expectSendMessage(final MessageType type,
|
||||
final boolean visible) throws Exception {
|
||||
private void expectSendMessage(MessageType type, boolean visible)
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeMetadata(type, privateGroupId,
|
||||
message.getTimestamp(), true, true, visible, false, false);
|
||||
@@ -175,7 +175,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
protected void expectSetPrivateGroupVisibility(final Group.Visibility v)
|
||||
protected void expectSetPrivateGroupVisibility(Group.Visibility v)
|
||||
throws Exception {
|
||||
expectGetContactId();
|
||||
context.checking(new Expectations() {{
|
||||
@@ -184,7 +184,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
protected void expectGetContactId() throws Exception {
|
||||
final BdfDictionary groupMeta = BdfDictionary
|
||||
BdfDictionary groupMeta = BdfDictionary
|
||||
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper)
|
||||
@@ -211,10 +211,9 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
protected void expectMarkMessageVisibleInUi(final MessageId m,
|
||||
final boolean visible)
|
||||
protected void expectMarkMessageVisibleInUi(MessageId m, boolean visible)
|
||||
throws Exception {
|
||||
final BdfDictionary d = new BdfDictionary();
|
||||
BdfDictionary d = new BdfDictionary();
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).setVisibleInUi(d, visible);
|
||||
oneOf(clientHelper).mergeMessageMetadata(txn, m, d);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
assertSessionConstantsUnchanged(session, newSession);
|
||||
}
|
||||
|
||||
private void expectOnLocalInvite(final String msg) throws Exception {
|
||||
private void expectOnLocalInvite(String msg) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getGroup(txn, privateGroupId);
|
||||
will(returnValue(privateGroupGroup));
|
||||
|
||||
@@ -159,8 +159,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
groupInvitationManager.createLocalState(txn);
|
||||
}
|
||||
|
||||
private void expectAddingContact(final Contact c,
|
||||
final boolean contactExists) throws Exception {
|
||||
private void expectAddingContact(Contact c, boolean contactExists)
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, c);
|
||||
will(returnValue(contactGroup));
|
||||
@@ -169,7 +169,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
if (contactExists) return;
|
||||
|
||||
final BdfDictionary meta = BdfDictionary
|
||||
BdfDictionary meta = BdfDictionary
|
||||
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, c.getId().getInt()));
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
@@ -186,8 +186,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
expectAddingMember(privateGroup.getId(), c);
|
||||
}
|
||||
|
||||
private void expectAddingMember(final GroupId g, final Contact c)
|
||||
throws Exception {
|
||||
private void expectAddingMember(GroupId g, Contact c) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, c);
|
||||
will(returnValue(contactGroup));
|
||||
@@ -214,8 +213,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectStoreSession(final Session session,
|
||||
final MessageId storageId) throws Exception {
|
||||
private void expectStoreSession(Session session, MessageId storageId)
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(sessionEncoder).encodeSession(session);
|
||||
will(returnValue(meta));
|
||||
@@ -223,10 +222,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void expectGetSession(final Map<MessageId, BdfDictionary> results,
|
||||
final SessionId sessionId, final GroupId contactGroupId)
|
||||
throws Exception {
|
||||
final BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
private void expectGetSession(Map<MessageId, BdfDictionary> results,
|
||||
SessionId sessionId, GroupId contactGroupId) throws Exception {
|
||||
BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(sessionParser).getSessionQuery(sessionId);
|
||||
will(returnValue(query));
|
||||
@@ -327,9 +325,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
expectIncomingMessageWithSession(role, type, bdfSession);
|
||||
}
|
||||
|
||||
private void expectIncomingMessageWithSession(final Role role,
|
||||
final MessageType type, final BdfDictionary bdfSession)
|
||||
throws Exception {
|
||||
private void expectIncomingMessageWithSession(Role role, MessageType type,
|
||||
BdfDictionary bdfSession) throws Exception {
|
||||
expectParseMessageMetadata();
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
Session session = expectHandleMessage(role, messageMetadata, bdfSession,
|
||||
@@ -339,7 +336,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Nullable
|
||||
private Session expectHandleFirstMessage(Role role,
|
||||
final MessageMetadata messageMetadata, final MessageType type)
|
||||
MessageMetadata messageMetadata, MessageType type)
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageMetadata).getPrivateGroupId();
|
||||
@@ -367,9 +364,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Session expectHandleMessage(final Role role,
|
||||
final MessageMetadata messageMetadata, final BdfDictionary state,
|
||||
final MessageType type) throws Exception {
|
||||
private Session expectHandleMessage(Role role,
|
||||
MessageMetadata messageMetadata, BdfDictionary state,
|
||||
MessageType type) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageMetadata).getMessageType();
|
||||
will(returnValue(type));
|
||||
@@ -405,11 +402,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private <S extends Session> void expectIndividualMessage(
|
||||
final MessageType type, final ProtocolEngine<S> engine,
|
||||
final S session) throws Exception {
|
||||
private <S extends Session> void expectIndividualMessage(MessageType type,
|
||||
ProtocolEngine<S> engine, S session) throws Exception {
|
||||
if (type == INVITE) {
|
||||
final InviteMessage msg = context.mock(InviteMessage.class);
|
||||
InviteMessage msg = context.mock(InviteMessage.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser).parseInviteMessage(message, body);
|
||||
will(returnValue(msg));
|
||||
@@ -418,7 +414,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(session));
|
||||
}});
|
||||
} else if (type == JOIN) {
|
||||
final JoinMessage msg = context.mock(JoinMessage.class);
|
||||
JoinMessage msg = context.mock(JoinMessage.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser).parseJoinMessage(message, body);
|
||||
will(returnValue(msg));
|
||||
@@ -427,7 +423,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(session));
|
||||
}});
|
||||
} else if (type == LEAVE) {
|
||||
final LeaveMessage msg = context.mock(LeaveMessage.class);
|
||||
LeaveMessage msg = context.mock(LeaveMessage.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser).parseLeaveMessage(message, body);
|
||||
will(returnValue(msg));
|
||||
@@ -436,7 +432,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(session));
|
||||
}});
|
||||
} else if (type == ABORT) {
|
||||
final AbortMessage msg = context.mock(AbortMessage.class);
|
||||
AbortMessage msg = context.mock(AbortMessage.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser).parseAbortMessage(message, body);
|
||||
will(returnValue(msg));
|
||||
@@ -451,9 +447,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testSendFirstInvitation() throws Exception {
|
||||
final String msg = "Invitation text for first invitation";
|
||||
final long time = 42L;
|
||||
final byte[] signature = getRandomBytes(42);
|
||||
String msg = "Invitation text for first invitation";
|
||||
long time = 42L;
|
||||
byte[] signature = getRandomBytes(42);
|
||||
|
||||
expectGetSession(noResults, sessionId, contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
@@ -482,9 +478,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testSendSubsequentInvitation() throws Exception {
|
||||
final String msg = "Invitation text for subsequent invitation";
|
||||
final long time = 43L;
|
||||
final byte[] signature = getRandomBytes(43);
|
||||
String msg = "Invitation text for subsequent invitation";
|
||||
long time = 43L;
|
||||
byte[] signature = getRandomBytes(43);
|
||||
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
@@ -513,7 +509,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testRespondToInvitationWithoutSession() throws Exception {
|
||||
final SessionId sessionId = new SessionId(getRandomId());
|
||||
SessionId sessionId = new SessionId(getRandomId());
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -563,8 +559,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
groupInvitationManager.respondToInvitation(contactId, pg, false);
|
||||
}
|
||||
|
||||
private void expectRespondToInvitation(final SessionId sessionId,
|
||||
final boolean accept) throws Exception {
|
||||
private void expectRespondToInvitation(SessionId sessionId, boolean accept)
|
||||
throws Exception {
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -628,24 +624,24 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetInvitationMessages() throws Exception {
|
||||
final BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
final BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
|
||||
final Map<MessageId, BdfDictionary> results = new HashMap<>();
|
||||
BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
|
||||
Map<MessageId, BdfDictionary> results = new HashMap<>();
|
||||
results.put(message.getId(), meta);
|
||||
results.put(messageId2, meta2);
|
||||
final long time1 = 1L, time2 = 2L;
|
||||
final MessageMetadata messageMetadata1 =
|
||||
long time1 = 1L, time2 = 2L;
|
||||
MessageMetadata messageMetadata1 =
|
||||
new MessageMetadata(INVITE, privateGroup.getId(), time1, true,
|
||||
true, true, false, true);
|
||||
final MessageMetadata messageMetadata2 =
|
||||
MessageMetadata messageMetadata2 =
|
||||
new MessageMetadata(JOIN, privateGroup.getId(), time2, true,
|
||||
true, true, true, false);
|
||||
final InviteMessage invite =
|
||||
InviteMessage invite =
|
||||
new InviteMessage(message.getId(), contactGroup.getId(),
|
||||
privateGroup.getId(), time1, "name", author,
|
||||
new byte[0], null, new byte[0]);
|
||||
final PrivateGroup pg =
|
||||
PrivateGroup pg =
|
||||
new PrivateGroup(privateGroup, invite.getGroupName(),
|
||||
invite.getCreator(), invite.getSalt());
|
||||
|
||||
@@ -701,28 +697,27 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetInvitations() throws Exception {
|
||||
final BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
final BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
|
||||
final Map<MessageId, BdfDictionary> results = new HashMap<>();
|
||||
BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
|
||||
Map<MessageId, BdfDictionary> results = new HashMap<>();
|
||||
results.put(message.getId(), meta);
|
||||
results.put(messageId2, meta2);
|
||||
final Message message2 = new Message(messageId2, contactGroup.getId(),
|
||||
Message message2 = new Message(messageId2, contactGroup.getId(),
|
||||
0L, getRandomBytes(MESSAGE_HEADER_LENGTH + 1));
|
||||
long time1 = 1L, time2 = 2L;
|
||||
final String groupName = getRandomString(MAX_GROUP_NAME_LENGTH);
|
||||
final byte[] salt = getRandomBytes(GROUP_SALT_LENGTH);
|
||||
final InviteMessage inviteMessage1 =
|
||||
String groupName = getRandomString(MAX_GROUP_NAME_LENGTH);
|
||||
byte[] salt = getRandomBytes(GROUP_SALT_LENGTH);
|
||||
InviteMessage inviteMessage1 =
|
||||
new InviteMessage(message.getId(), contactGroup.getId(),
|
||||
privateGroup.getId(), time1, groupName, author, salt,
|
||||
null, getRandomBytes(5));
|
||||
final InviteMessage inviteMessage2 =
|
||||
new InviteMessage(message.getId(), contactGroup.getId(),
|
||||
InviteMessage inviteMessage2 =
|
||||
new InviteMessage(message2.getId(), contactGroup.getId(),
|
||||
privateGroup.getId(), time2, groupName, author, salt,
|
||||
null, getRandomBytes(5));
|
||||
final PrivateGroup pg = new PrivateGroup(privateGroup, groupName,
|
||||
PrivateGroup pg = new PrivateGroup(privateGroup, groupName,
|
||||
author, salt);
|
||||
final BdfList body2 = BdfList.of("body2");
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser).getInvitesAvailableToAnswerQuery();
|
||||
@@ -794,7 +789,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
.isInvitationAllowed(contact, privateGroup.getId()));
|
||||
}
|
||||
|
||||
private void expectIsInvitationAllowed(final CreatorState state)
|
||||
private void expectIsInvitationAllowed(CreatorState state)
|
||||
throws Exception {
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
@@ -824,23 +819,23 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemovingGroupEndsSessions() throws Exception {
|
||||
final Contact contact2 = new Contact(new ContactId(2), author,
|
||||
Contact contact2 = new Contact(new ContactId(2), author,
|
||||
author.getId(), true, true);
|
||||
final Contact contact3 = new Contact(new ContactId(3), author,
|
||||
Contact contact3 = new Contact(new ContactId(3), author,
|
||||
author.getId(), true, true);
|
||||
final Collection<Contact> contacts =
|
||||
Collection<Contact> contacts =
|
||||
Arrays.asList(contact, contact2, contact3);
|
||||
|
||||
final Group contactGroup2 = new Group(new GroupId(getRandomId()),
|
||||
Group contactGroup2 = new Group(new GroupId(getRandomId()),
|
||||
CLIENT_ID, getRandomBytes(5));
|
||||
final Group contactGroup3 = new Group(new GroupId(getRandomId()),
|
||||
Group contactGroup3 = new Group(new GroupId(getRandomId()),
|
||||
CLIENT_ID, getRandomBytes(5));
|
||||
|
||||
final MessageId storageId2 = new MessageId(getRandomId());
|
||||
final MessageId storageId3 = new MessageId(getRandomId());
|
||||
final BdfDictionary bdfSession2 =
|
||||
MessageId storageId2 = new MessageId(getRandomId());
|
||||
MessageId storageId3 = new MessageId(getRandomId());
|
||||
BdfDictionary bdfSession2 =
|
||||
BdfDictionary.of(new BdfEntry("f2", "o"));
|
||||
final BdfDictionary bdfSession3 =
|
||||
BdfDictionary bdfSession3 =
|
||||
BdfDictionary.of(new BdfEntry("f3", "o"));
|
||||
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
|
||||
@@ -295,8 +295,8 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
|
||||
assertEquals(meta, messageContext.getDictionary());
|
||||
}
|
||||
|
||||
private void expectInviteMessage(final boolean exception) throws Exception {
|
||||
final BdfList signed = BdfList.of(message.getTimestamp(),
|
||||
private void expectInviteMessage(boolean exception) throws Exception {
|
||||
BdfList signed = BdfList.of(message.getTimestamp(),
|
||||
message.getGroupId(), privateGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(authorFactory).createAuthor(creatorName, creatorKey);
|
||||
|
||||
@@ -127,13 +127,13 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
|
||||
@Test
|
||||
public void testOnJoinActionFromInvited() throws Exception {
|
||||
final JoinMessage properJoinMessage =
|
||||
JoinMessage properJoinMessage =
|
||||
new JoinMessage(messageId, contactGroupId, privateGroupId,
|
||||
messageTimestamp, lastRemoteMessageId);
|
||||
final long timestamp = 0L;
|
||||
final GroupMessage joinGroupMessage =
|
||||
long timestamp = 0L;
|
||||
GroupMessage joinGroupMessage =
|
||||
new GroupMessage(message, null, localAuthor);
|
||||
final BdfDictionary meta = new BdfDictionary();
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
|
||||
expectMarkMessageAvailableToAnswer(lastRemoteMessageId, false);
|
||||
context.checking(new Expectations() {{
|
||||
@@ -327,7 +327,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
Author notCreator =
|
||||
new Author(new AuthorId(getRandomId()), "Not Creator",
|
||||
getRandomBytes(5));
|
||||
final Contact notCreatorContact =
|
||||
Contact notCreatorContact =
|
||||
new Contact(contactId, notCreator, localAuthor.getId(), true,
|
||||
true);
|
||||
|
||||
@@ -346,7 +346,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
@Test
|
||||
public void testOnInviteMessageFromStart() throws Exception {
|
||||
InviteeSession session = getDefaultSession(START);
|
||||
final InviteMessage properInviteMessage =
|
||||
InviteMessage properInviteMessage =
|
||||
new InviteMessage(new MessageId(getRandomId()), contactGroupId,
|
||||
privateGroupId, session.getInviteTimestamp() + 1,
|
||||
privateGroup.getName(), privateGroup.getCreator(),
|
||||
@@ -717,9 +717,9 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
|
||||
// helper methods
|
||||
|
||||
private void expectMarkMessageAvailableToAnswer(final MessageId id,
|
||||
final boolean available) throws Exception {
|
||||
final BdfDictionary meta = new BdfDictionary();
|
||||
private void expectMarkMessageAvailableToAnswer(MessageId id,
|
||||
boolean available) throws Exception {
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder)
|
||||
.setAvailableToAnswer(meta, available);
|
||||
@@ -748,9 +748,9 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
}
|
||||
|
||||
private void expectMarkInvitesUnavailableToAnswer() throws Exception {
|
||||
final BdfDictionary query = BdfDictionary.of(new BdfEntry("query", ""));
|
||||
final BdfDictionary meta = BdfDictionary.of(new BdfEntry("meta", ""));
|
||||
final Map<MessageId, BdfDictionary> invites =
|
||||
BdfDictionary query = BdfDictionary.of(new BdfEntry("query", ""));
|
||||
BdfDictionary meta = BdfDictionary.of(new BdfEntry("meta", ""));
|
||||
Map<MessageId, BdfDictionary> invites =
|
||||
Collections.singletonMap(lastRemoteMessageId, meta);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageParser)
|
||||
|
||||
@@ -660,7 +660,7 @@ public class PeerProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
|
||||
// helper methods
|
||||
|
||||
private void expectRelationshipRevealed(final boolean byContact)
|
||||
private void expectRelationshipRevealed(boolean byContact)
|
||||
throws Exception {
|
||||
expectGetContactId();
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -134,20 +134,20 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
testRemovingBlog(sessions);
|
||||
}
|
||||
|
||||
private void testAddingContact(final Map<MessageId, BdfDictionary> sessions)
|
||||
private void testAddingContact(Map<MessageId, BdfDictionary> sessions)
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final LocalAuthor localAuthor =
|
||||
Transaction txn = new Transaction(null, false);
|
||||
LocalAuthor localAuthor =
|
||||
new LocalAuthor(localAuthorId, "Local Author",
|
||||
getRandomBytes(MAX_PUBLIC_KEY_LENGTH),
|
||||
getRandomBytes(MAX_PUBLIC_KEY_LENGTH),
|
||||
System.currentTimeMillis());
|
||||
final BdfDictionary meta = BdfDictionary
|
||||
BdfDictionary meta = BdfDictionary
|
||||
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
|
||||
final Group localBlogGroup =
|
||||
Group localBlogGroup =
|
||||
new Group(new GroupId(getRandomId()), BlogManager.CLIENT_ID,
|
||||
getRandomBytes(42));
|
||||
final Blog localBlog = new Blog(localBlogGroup, localAuthor, false);
|
||||
Blog localBlog = new Blog(localBlogGroup, localAuthor, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getContacts(txn);
|
||||
@@ -174,14 +174,14 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
blogSharingManager.createLocalState(txn);
|
||||
}
|
||||
|
||||
private void expectPreShareShareable(final Transaction txn,
|
||||
final Contact contact, final Blog blog,
|
||||
final Map<MessageId, BdfDictionary> sessions) throws Exception {
|
||||
final Group contactGroup =
|
||||
private void expectPreShareShareable(Transaction txn, Contact contact,
|
||||
Blog blog, Map<MessageId, BdfDictionary> sessions)
|
||||
throws Exception {
|
||||
Group contactGroup =
|
||||
new Group(new GroupId(getRandomId()), CLIENT_ID,
|
||||
getRandomBytes(42));
|
||||
final BdfDictionary sessionDict = new BdfDictionary();
|
||||
final Message message =
|
||||
BdfDictionary sessionDict = new BdfDictionary();
|
||||
Message message =
|
||||
new Message(new MessageId(getRandomId()), contactGroup.getId(),
|
||||
42L, getRandomBytes(1337));
|
||||
context.checking(new Expectations() {{
|
||||
@@ -211,11 +211,11 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
private void testRemovingBlog(final Map<MessageId, BdfDictionary> sessions)
|
||||
private void testRemovingBlog(Map<MessageId, BdfDictionary> sessions)
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final BdfDictionary sessionDict = new BdfDictionary();
|
||||
final Session session = new Session(contactGroup.getId(), blog.getId());
|
||||
Transaction txn = new Transaction(null, false);
|
||||
BdfDictionary sessionDict = new BdfDictionary();
|
||||
Session session = new Session(contactGroup.getId(), blog.getId());
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getContacts(txn);
|
||||
|
||||
@@ -175,7 +175,7 @@ public class BlogSharingValidatorTest extends SharingValidatorTest {
|
||||
invalidContent));
|
||||
}
|
||||
|
||||
private void expectCreateBlog(final String name, final byte[] key) {
|
||||
private void expectCreateBlog(String name, byte[] key) {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(authorFactory).createAuthor(name, key);
|
||||
will(returnValue(author));
|
||||
|
||||
@@ -165,7 +165,7 @@ public class ForumSharingValidatorTest extends SharingValidatorTest {
|
||||
invalidContent));
|
||||
}
|
||||
|
||||
private void expectCreateForum(final String name) {
|
||||
private void expectCreateForum(String name) {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(forumFactory).createForum(name, salt);
|
||||
will(returnValue(forum));
|
||||
|
||||
@@ -143,7 +143,7 @@ public abstract class SharingValidatorTest extends ValidatorTestCase {
|
||||
BdfList.of(ABORT.getValue(), groupId, previousMsgId, 123));
|
||||
}
|
||||
|
||||
protected void expectEncodeMetadata(final MessageType type) {
|
||||
protected void expectEncodeMetadata(MessageType type) {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder)
|
||||
.encodeMetadata(type, groupId, timestamp, false, false,
|
||||
|
||||
Reference in New Issue
Block a user