mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Merge branch '727-refactor-integration-tests' into 'master'
Refactor Integration Tests This is quite a massive MR (currently 1763 additions and 3482 deletions). However, there's not so much happening. The only thing I did was moving redundant code from the various protocol integration tests to the `BriarIntegrationTest` class. All integration tests are still passing. Closes #727 See merge request !433
This commit is contained in:
@@ -1,147 +1,58 @@
|
|||||||
package org.briarproject;
|
package org.briarproject;
|
||||||
|
|
||||||
import net.jodah.concurrentunit.Waiter;
|
|
||||||
|
|
||||||
import org.briarproject.api.blogs.Blog;
|
import org.briarproject.api.blogs.Blog;
|
||||||
import org.briarproject.api.blogs.BlogCommentHeader;
|
import org.briarproject.api.blogs.BlogCommentHeader;
|
||||||
import org.briarproject.api.blogs.BlogFactory;
|
|
||||||
import org.briarproject.api.blogs.BlogManager;
|
import org.briarproject.api.blogs.BlogManager;
|
||||||
import org.briarproject.api.blogs.BlogPost;
|
import org.briarproject.api.blogs.BlogPost;
|
||||||
import org.briarproject.api.blogs.BlogPostFactory;
|
|
||||||
import org.briarproject.api.blogs.BlogPostHeader;
|
import org.briarproject.api.blogs.BlogPostHeader;
|
||||||
import org.briarproject.api.contact.ContactId;
|
|
||||||
import org.briarproject.api.contact.ContactManager;
|
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.event.Event;
|
|
||||||
import org.briarproject.api.event.EventListener;
|
|
||||||
import org.briarproject.api.event.MessageStateChangedEvent;
|
|
||||||
import org.briarproject.api.identity.AuthorFactory;
|
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.api.sync.SyncSession;
|
|
||||||
import org.briarproject.api.sync.SyncSessionFactory;
|
|
||||||
import org.briarproject.api.system.Clock;
|
|
||||||
import org.briarproject.blogs.BlogsModule;
|
|
||||||
import org.briarproject.contact.ContactModule;
|
|
||||||
import org.briarproject.crypto.CryptoModule;
|
|
||||||
import org.briarproject.lifecycle.LifecycleModule;
|
|
||||||
import org.briarproject.properties.PropertiesModule;
|
|
||||||
import org.briarproject.sync.SyncModule;
|
|
||||||
import org.briarproject.transport.TransportModule;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertFalse;
|
import static junit.framework.Assert.assertFalse;
|
||||||
import static org.briarproject.TestPluginsModule.MAX_LATENCY;
|
|
||||||
import static org.briarproject.api.blogs.MessageType.COMMENT;
|
import static org.briarproject.api.blogs.MessageType.COMMENT;
|
||||||
import static org.briarproject.api.blogs.MessageType.POST;
|
import static org.briarproject.api.blogs.MessageType.POST;
|
||||||
import static org.briarproject.api.blogs.MessageType.WRAPPED_COMMENT;
|
import static org.briarproject.api.blogs.MessageType.WRAPPED_COMMENT;
|
||||||
import static org.briarproject.api.blogs.MessageType.WRAPPED_POST;
|
import static org.briarproject.api.blogs.MessageType.WRAPPED_POST;
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.DELIVERED;
|
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.INVALID;
|
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.PENDING;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class BlogManagerTest extends BriarIntegrationTest {
|
public class BlogManagerTest extends BriarIntegrationTest {
|
||||||
|
|
||||||
private LifecycleManager lifecycleManager0, lifecycleManager1;
|
|
||||||
private SyncSessionFactory sync0, sync1;
|
|
||||||
private BlogManager blogManager0, blogManager1;
|
private BlogManager blogManager0, blogManager1;
|
||||||
private ContactManager contactManager0, contactManager1;
|
|
||||||
private ContactId contactId0,contactId1;
|
|
||||||
private IdentityManager identityManager0, identityManager1;
|
|
||||||
private LocalAuthor author0, author1;
|
|
||||||
private Blog blog0, blog1;
|
private Blog blog0, blog1;
|
||||||
|
|
||||||
@Inject
|
|
||||||
Clock clock;
|
|
||||||
@Inject
|
|
||||||
AuthorFactory authorFactory;
|
|
||||||
@Inject
|
|
||||||
CryptoComponent crypto;
|
|
||||||
@Inject
|
|
||||||
BlogFactory blogFactory;
|
|
||||||
@Inject
|
|
||||||
BlogPostFactory blogPostFactory;
|
|
||||||
|
|
||||||
// objects accessed from background threads need to be volatile
|
|
||||||
private volatile Waiter validationWaiter;
|
|
||||||
private volatile Waiter deliveryWaiter;
|
|
||||||
|
|
||||||
private final File testDir = TestUtils.getTestDirectory();
|
|
||||||
private final SecretKey master = TestUtils.getSecretKey();
|
|
||||||
private final int TIMEOUT = 15000;
|
|
||||||
private final String AUTHOR1 = "Author 1";
|
|
||||||
private final String AUTHOR2 = "Author 2";
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
Logger.getLogger(BlogManagerTest.class.getName());
|
|
||||||
|
|
||||||
private BlogManagerTestComponent t0, t1;
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
public ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
BlogManagerTestComponent component =
|
super.setUp();
|
||||||
DaggerBlogManagerTestComponent.builder().build();
|
|
||||||
component.inject(this);
|
|
||||||
injectEagerSingletons(component);
|
|
||||||
|
|
||||||
assertTrue(testDir.mkdirs());
|
author0 = identityManager0.getLocalAuthor();
|
||||||
File t0Dir = new File(testDir, AUTHOR1);
|
author1 = identityManager1.getLocalAuthor();
|
||||||
t0 = DaggerBlogManagerTestComponent.builder()
|
|
||||||
.testDatabaseModule(new TestDatabaseModule(t0Dir)).build();
|
|
||||||
injectEagerSingletons(t0);
|
|
||||||
File t1Dir = new File(testDir, AUTHOR2);
|
|
||||||
t1 = DaggerBlogManagerTestComponent.builder()
|
|
||||||
.testDatabaseModule(new TestDatabaseModule(t1Dir)).build();
|
|
||||||
injectEagerSingletons(t1);
|
|
||||||
|
|
||||||
identityManager0 = t0.getIdentityManager();
|
blogManager0 = c0.getBlogManager();
|
||||||
identityManager1 = t1.getIdentityManager();
|
blogManager1 = c1.getBlogManager();
|
||||||
contactManager0 = t0.getContactManager();
|
|
||||||
contactManager1 = t1.getContactManager();
|
|
||||||
blogManager0 = t0.getBlogManager();
|
|
||||||
blogManager1 = t1.getBlogManager();
|
|
||||||
sync0 = t0.getSyncSessionFactory();
|
|
||||||
sync1 = t1.getSyncSessionFactory();
|
|
||||||
|
|
||||||
// initialize waiters fresh for each test
|
blog0 = blogFactory.createBlog(author0);
|
||||||
validationWaiter = new Waiter();
|
blog1 = blogFactory.createBlog(author1);
|
||||||
deliveryWaiter = new Waiter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersonalBlogInitialisation() throws Exception {
|
public void testPersonalBlogInitialisation() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
|
|
||||||
defaultInit();
|
|
||||||
|
|
||||||
Collection<Blog> blogs0 = blogManager0.getBlogs();
|
Collection<Blog> blogs0 = blogManager0.getBlogs();
|
||||||
assertEquals(2, blogs0.size());
|
assertEquals(3, blogs0.size());
|
||||||
Iterator<Blog> i0 = blogs0.iterator();
|
Iterator<Blog> i0 = blogs0.iterator();
|
||||||
assertEquals(author0, i0.next().getAuthor());
|
assertEquals(author0, i0.next().getAuthor());
|
||||||
assertEquals(author1, i0.next().getAuthor());
|
assertEquals(author1, i0.next().getAuthor());
|
||||||
|
assertEquals(author2, i0.next().getAuthor());
|
||||||
|
|
||||||
Collection<Blog> blogs1 = blogManager1.getBlogs();
|
Collection<Blog> blogs1 = blogManager1.getBlogs();
|
||||||
assertEquals(2, blogs1.size());
|
assertEquals(2, blogs1.size());
|
||||||
@@ -163,15 +74,10 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
assertEquals(1, blogManager1.getBlogs(author0).size());
|
assertEquals(1, blogManager1.getBlogs(author0).size());
|
||||||
assertEquals(1, blogManager0.getBlogs(author1).size());
|
assertEquals(1, blogManager0.getBlogs(author1).size());
|
||||||
assertEquals(1, blogManager1.getBlogs(author1).size());
|
assertEquals(1, blogManager1.getBlogs(author1).size());
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlogPost() throws Exception {
|
public void testBlogPost() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
defaultInit();
|
|
||||||
|
|
||||||
// check that blog0 has no posts
|
// check that blog0 has no posts
|
||||||
final String body = TestUtils.getRandomString(42);
|
final String body = TestUtils.getRandomString(42);
|
||||||
Collection<BlogPostHeader> headers0 =
|
Collection<BlogPostHeader> headers0 =
|
||||||
@@ -197,8 +103,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
assertEquals(0, headers1.size());
|
assertEquals(0, headers1.size());
|
||||||
|
|
||||||
// sync the post over
|
// sync the post over
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// make sure post arrived
|
// make sure post arrived
|
||||||
headers1 = blogManager1.getPostHeaders(blog0.getId());
|
headers1 = blogManager1.getPostHeaders(blog0.getId());
|
||||||
@@ -207,15 +112,10 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
// check that body is there
|
// check that body is there
|
||||||
assertEquals(body, blogManager1.getPostBody(p.getMessage().getId()));
|
assertEquals(body, blogManager1.getPostBody(p.getMessage().getId()));
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlogPostInWrongBlog() throws Exception {
|
public void testBlogPostInWrongBlog() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
defaultInit();
|
|
||||||
|
|
||||||
// add a post to blog1
|
// add a post to blog1
|
||||||
final String body = TestUtils.getRandomString(42);
|
final String body = TestUtils.getRandomString(42);
|
||||||
BlogPost p = blogPostFactory
|
BlogPost p = blogPostFactory
|
||||||
@@ -229,22 +129,16 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
assertEquals(1, headers0.size());
|
assertEquals(1, headers0.size());
|
||||||
|
|
||||||
// sync the post over
|
// sync the post over
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// make sure post did not arrive, because of wrong signature
|
// make sure post did not arrive, because of wrong signature
|
||||||
Collection<BlogPostHeader> headers1 =
|
Collection<BlogPostHeader> headers1 =
|
||||||
blogManager1.getPostHeaders(blog1.getId());
|
blogManager1.getPostHeaders(blog1.getId());
|
||||||
assertEquals(0, headers1.size());
|
assertEquals(0, headers1.size());
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCanNotRemoveContactsPersonalBlog() throws Exception {
|
public void testCanNotRemoveContactsPersonalBlog() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
defaultInit();
|
|
||||||
|
|
||||||
assertFalse(blogManager0.canBeRemoved(blog1.getId()));
|
assertFalse(blogManager0.canBeRemoved(blog1.getId()));
|
||||||
assertFalse(blogManager1.canBeRemoved(blog0.getId()));
|
assertFalse(blogManager1.canBeRemoved(blog0.getId()));
|
||||||
|
|
||||||
@@ -257,15 +151,10 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
// blogs have not been removed
|
// blogs have not been removed
|
||||||
assertEquals(2, blogManager0.getBlogs().size());
|
assertEquals(2, blogManager0.getBlogs().size());
|
||||||
assertEquals(2, blogManager1.getBlogs().size());
|
assertEquals(2, blogManager1.getBlogs().size());
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlogComment() throws Exception {
|
public void testBlogComment() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
defaultInit();
|
|
||||||
|
|
||||||
// add a post to blog0
|
// add a post to blog0
|
||||||
final String body = TestUtils.getRandomString(42);
|
final String body = TestUtils.getRandomString(42);
|
||||||
BlogPost p = blogPostFactory
|
BlogPost p = blogPostFactory
|
||||||
@@ -274,8 +163,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
blogManager0.addLocalPost(p);
|
blogManager0.addLocalPost(p);
|
||||||
|
|
||||||
// sync the post over
|
// sync the post over
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// make sure post arrived
|
// make sure post arrived
|
||||||
Collection<BlogPostHeader> headers1 =
|
Collection<BlogPostHeader> headers1 =
|
||||||
@@ -290,8 +178,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
headers1.iterator().next());
|
headers1.iterator().next());
|
||||||
|
|
||||||
// sync comment over
|
// sync comment over
|
||||||
sync1To0();
|
sync1To0(2, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 2);
|
|
||||||
|
|
||||||
// make sure comment and wrapped post arrived
|
// make sure comment and wrapped post arrived
|
||||||
Collection<BlogPostHeader> headers0 =
|
Collection<BlogPostHeader> headers0 =
|
||||||
@@ -307,15 +194,10 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
// 1 has only their own comment in their blog
|
// 1 has only their own comment in their blog
|
||||||
headers1 = blogManager1.getPostHeaders(blog1.getId());
|
headers1 = blogManager1.getPostHeaders(blog1.getId());
|
||||||
assertEquals(1, headers1.size());
|
assertEquals(1, headers1.size());
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlogCommentOnOwnPost() throws Exception {
|
public void testBlogCommentOnOwnPost() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
defaultInit();
|
|
||||||
|
|
||||||
// add a post to blog0
|
// add a post to blog0
|
||||||
final String body = TestUtils.getRandomString(42);
|
final String body = TestUtils.getRandomString(42);
|
||||||
BlogPost p = blogPostFactory
|
BlogPost p = blogPostFactory
|
||||||
@@ -335,8 +217,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
.addLocalComment(author0, blog0.getId(), comment, header);
|
.addLocalComment(author0, blog0.getId(), comment, header);
|
||||||
|
|
||||||
// sync the post and comment over
|
// sync the post and comment over
|
||||||
sync0To1();
|
sync0To1(2, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 2);
|
|
||||||
|
|
||||||
// make sure post arrived
|
// make sure post arrived
|
||||||
Collection<BlogPostHeader> headers1 =
|
Collection<BlogPostHeader> headers1 =
|
||||||
@@ -349,15 +230,10 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
assertEquals(comment, ((BlogCommentHeader)h).getComment());
|
assertEquals(comment, ((BlogCommentHeader)h).getComment());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCommentOnComment() throws Exception {
|
public void testCommentOnComment() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
defaultInit();
|
|
||||||
|
|
||||||
// add a post to blog0
|
// add a post to blog0
|
||||||
final String body = TestUtils.getRandomString(42);
|
final String body = TestUtils.getRandomString(42);
|
||||||
BlogPost p = blogPostFactory
|
BlogPost p = blogPostFactory
|
||||||
@@ -366,8 +242,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
blogManager0.addLocalPost(p);
|
blogManager0.addLocalPost(p);
|
||||||
|
|
||||||
// sync the post over
|
// sync the post over
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// make sure post arrived
|
// make sure post arrived
|
||||||
Collection<BlogPostHeader> headers1 =
|
Collection<BlogPostHeader> headers1 =
|
||||||
@@ -381,8 +256,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
headers1.iterator().next());
|
headers1.iterator().next());
|
||||||
|
|
||||||
// sync comment over
|
// sync comment over
|
||||||
sync1To0();
|
sync1To0(2, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 2);
|
|
||||||
|
|
||||||
// make sure comment and wrapped post arrived
|
// make sure comment and wrapped post arrived
|
||||||
Collection<BlogPostHeader> headers0 =
|
Collection<BlogPostHeader> headers0 =
|
||||||
@@ -399,8 +273,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
.addLocalComment(author0, blog0.getId(), comment, cHeader);
|
.addLocalComment(author0, blog0.getId(), comment, cHeader);
|
||||||
|
|
||||||
// sync comment over
|
// sync comment over
|
||||||
sync0To1();
|
sync0To1(3, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 3);
|
|
||||||
|
|
||||||
// check that comment arrived
|
// check that comment arrived
|
||||||
headers1 =
|
headers1 =
|
||||||
@@ -421,8 +294,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
blogManager1.addLocalComment(author1, blog1.getId(), comment2, cHeader);
|
blogManager1.addLocalComment(author1, blog1.getId(), comment2, cHeader);
|
||||||
|
|
||||||
// sync comment over
|
// sync comment over
|
||||||
sync1To0();
|
sync1To0(4, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 4);
|
|
||||||
|
|
||||||
// make sure new comment arrived
|
// make sure new comment arrived
|
||||||
headers0 =
|
headers0 =
|
||||||
@@ -448,16 +320,10 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue(satisfied);
|
assertTrue(satisfied);
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCommentOnOwnComment() throws Exception {
|
public void testCommentOnOwnComment() throws Exception {
|
||||||
|
|
||||||
startLifecycles();
|
|
||||||
defaultInit();
|
|
||||||
|
|
||||||
// add a post to blog0
|
// add a post to blog0
|
||||||
final String body = TestUtils.getRandomString(42);
|
final String body = TestUtils.getRandomString(42);
|
||||||
BlogPost p = blogPostFactory
|
BlogPost p = blogPostFactory
|
||||||
@@ -466,8 +332,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
blogManager0.addLocalPost(p);
|
blogManager0.addLocalPost(p);
|
||||||
|
|
||||||
// sync the post over
|
// sync the post over
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// make sure post arrived
|
// make sure post arrived
|
||||||
Collection<BlogPostHeader> headers1 =
|
Collection<BlogPostHeader> headers1 =
|
||||||
@@ -492,128 +357,12 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
|||||||
blogManager1.addLocalComment(author1, blog1.getId(), comment, ch);
|
blogManager1.addLocalComment(author1, blog1.getId(), comment, ch);
|
||||||
|
|
||||||
// sync both comments over (2 comments + 1 wrapped post)
|
// sync both comments over (2 comments + 1 wrapped post)
|
||||||
sync1To0();
|
sync1To0(3, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 3);
|
|
||||||
|
|
||||||
// make sure both comments arrived
|
// make sure both comments arrived
|
||||||
Collection<BlogPostHeader> headers0 =
|
Collection<BlogPostHeader> headers0 =
|
||||||
blogManager0.getPostHeaders(blog1.getId());
|
blogManager0.getPostHeaders(blog1.getId());
|
||||||
assertEquals(2, headers0.size());
|
assertEquals(2, headers0.size());
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
TestUtils.deleteTestDirectory(testDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements EventListener {
|
|
||||||
@Override
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (e instanceof MessageStateChangedEvent) {
|
|
||||||
MessageStateChangedEvent event = (MessageStateChangedEvent) e;
|
|
||||||
if (!event.isLocal()) {
|
|
||||||
if (event.getState() == DELIVERED) {
|
|
||||||
deliveryWaiter.resume();
|
|
||||||
} else if (event.getState() == INVALID ||
|
|
||||||
event.getState() == PENDING) {
|
|
||||||
validationWaiter.resume();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void defaultInit() throws DbException {
|
|
||||||
getDefaultIdentities();
|
|
||||||
addDefaultContacts();
|
|
||||||
listenToEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getDefaultIdentities() throws DbException {
|
|
||||||
author0 = identityManager0.getLocalAuthor();
|
|
||||||
author1 = identityManager1.getLocalAuthor();
|
|
||||||
blog0 = blogFactory.createBlog(author0);
|
|
||||||
blog1 = blogFactory.createBlog(author1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addDefaultContacts() throws DbException {
|
|
||||||
// sharer adds invitee as contact
|
|
||||||
contactId1 = contactManager0.addContact(author1,
|
|
||||||
author0.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
// invitee adds sharer back
|
|
||||||
contactId0 = contactManager1.addContact(author0,
|
|
||||||
author1.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void listenToEvents() {
|
|
||||||
Listener listener0 = new Listener();
|
|
||||||
t0.getEventBus().addListener(listener0);
|
|
||||||
Listener listener1 = new Listener();
|
|
||||||
t1.getEventBus().addListener(listener1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sync0To1() throws IOException, TimeoutException {
|
|
||||||
deliverMessage(sync0, contactId0, sync1, contactId1, "0 to 1");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sync1To0() throws IOException, TimeoutException {
|
|
||||||
deliverMessage(sync1, contactId1, sync0, contactId0, "1 to 0");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deliverMessage(SyncSessionFactory fromSync, ContactId fromId,
|
|
||||||
SyncSessionFactory toSync, ContactId toId, String debug)
|
|
||||||
throws IOException, TimeoutException {
|
|
||||||
|
|
||||||
if (debug != null) LOG.info("TEST: Sending message from " + debug);
|
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
// Create an outgoing sync session
|
|
||||||
SyncSession sessionFrom =
|
|
||||||
fromSync.createSimplexOutgoingSession(toId, MAX_LATENCY, out);
|
|
||||||
// Write whatever needs to be written
|
|
||||||
sessionFrom.run();
|
|
||||||
out.close();
|
|
||||||
|
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
||||||
// Create an incoming sync session
|
|
||||||
SyncSession sessionTo = toSync.createIncomingSession(fromId, in);
|
|
||||||
// Read whatever needs to be read
|
|
||||||
sessionTo.run();
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startLifecycles() throws InterruptedException {
|
|
||||||
// Start the lifecycle manager and wait for it to finish
|
|
||||||
lifecycleManager0 = t0.getLifecycleManager();
|
|
||||||
lifecycleManager1 = t1.getLifecycleManager();
|
|
||||||
lifecycleManager0.startServices(AUTHOR1);
|
|
||||||
lifecycleManager1.startServices(AUTHOR2);
|
|
||||||
lifecycleManager0.waitForStartup();
|
|
||||||
lifecycleManager1.waitForStartup();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopLifecycles() throws InterruptedException {
|
|
||||||
// Clean up
|
|
||||||
lifecycleManager0.stopServices();
|
|
||||||
lifecycleManager1.stopServices();
|
|
||||||
lifecycleManager0.waitForShutdown();
|
|
||||||
lifecycleManager1.waitForShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void injectEagerSingletons(BlogManagerTestComponent component) {
|
|
||||||
component.inject(new LifecycleModule.EagerSingletons());
|
|
||||||
component.inject(new BlogsModule.EagerSingletons());
|
|
||||||
component.inject(new CryptoModule.EagerSingletons());
|
|
||||||
component.inject(new ContactModule.EagerSingletons());
|
|
||||||
component.inject(new TransportModule.EagerSingletons());
|
|
||||||
component.inject(new SyncModule.EagerSingletons());
|
|
||||||
component.inject(new PropertiesModule.EagerSingletons());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,78 +0,0 @@
|
|||||||
package org.briarproject;
|
|
||||||
|
|
||||||
import org.briarproject.api.blogs.BlogManager;
|
|
||||||
import org.briarproject.api.contact.ContactManager;
|
|
||||||
import org.briarproject.api.event.EventBus;
|
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.api.sync.SyncSessionFactory;
|
|
||||||
import org.briarproject.blogs.BlogsModule;
|
|
||||||
import org.briarproject.clients.ClientsModule;
|
|
||||||
import org.briarproject.contact.ContactModule;
|
|
||||||
import org.briarproject.crypto.CryptoModule;
|
|
||||||
import org.briarproject.data.DataModule;
|
|
||||||
import org.briarproject.db.DatabaseModule;
|
|
||||||
import org.briarproject.event.EventModule;
|
|
||||||
import org.briarproject.identity.IdentityModule;
|
|
||||||
import org.briarproject.lifecycle.LifecycleModule;
|
|
||||||
import org.briarproject.properties.PropertiesModule;
|
|
||||||
import org.briarproject.sharing.SharingModule;
|
|
||||||
import org.briarproject.sync.SyncModule;
|
|
||||||
import org.briarproject.system.SystemModule;
|
|
||||||
import org.briarproject.transport.TransportModule;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Component;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Component(modules = {
|
|
||||||
TestDatabaseModule.class,
|
|
||||||
TestPluginsModule.class,
|
|
||||||
TestSeedProviderModule.class,
|
|
||||||
ClientsModule.class,
|
|
||||||
ContactModule.class,
|
|
||||||
CryptoModule.class,
|
|
||||||
DataModule.class,
|
|
||||||
DatabaseModule.class,
|
|
||||||
EventModule.class,
|
|
||||||
BlogsModule.class,
|
|
||||||
IdentityModule.class,
|
|
||||||
LifecycleModule.class,
|
|
||||||
PropertiesModule.class,
|
|
||||||
SharingModule.class,
|
|
||||||
SyncModule.class,
|
|
||||||
SystemModule.class,
|
|
||||||
TransportModule.class
|
|
||||||
})
|
|
||||||
interface BlogManagerTestComponent {
|
|
||||||
|
|
||||||
void inject(BlogManagerTest testCase);
|
|
||||||
|
|
||||||
void inject(ContactModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(CryptoModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(BlogsModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(LifecycleModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(PropertiesModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(SyncModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(TransportModule.EagerSingletons init);
|
|
||||||
|
|
||||||
LifecycleManager getLifecycleManager();
|
|
||||||
|
|
||||||
EventBus getEventBus();
|
|
||||||
|
|
||||||
IdentityManager getIdentityManager();
|
|
||||||
|
|
||||||
ContactManager getContactManager();
|
|
||||||
|
|
||||||
BlogManager getBlogManager();
|
|
||||||
|
|
||||||
SyncSessionFactory getSyncSessionFactory();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -6,206 +6,114 @@ import org.briarproject.api.blogs.Blog;
|
|||||||
import org.briarproject.api.blogs.BlogInvitationRequest;
|
import org.briarproject.api.blogs.BlogInvitationRequest;
|
||||||
import org.briarproject.api.blogs.BlogInvitationResponse;
|
import org.briarproject.api.blogs.BlogInvitationResponse;
|
||||||
import org.briarproject.api.blogs.BlogManager;
|
import org.briarproject.api.blogs.BlogManager;
|
||||||
import org.briarproject.api.blogs.BlogPostFactory;
|
|
||||||
import org.briarproject.api.blogs.BlogSharingManager;
|
import org.briarproject.api.blogs.BlogSharingManager;
|
||||||
import org.briarproject.api.clients.ContactGroupFactory;
|
|
||||||
import org.briarproject.api.clients.MessageTracker;
|
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.api.contact.Contact;
|
||||||
import org.briarproject.api.contact.ContactId;
|
|
||||||
import org.briarproject.api.contact.ContactManager;
|
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.event.BlogInvitationReceivedEvent;
|
import org.briarproject.api.event.BlogInvitationReceivedEvent;
|
||||||
import org.briarproject.api.event.BlogInvitationResponseReceivedEvent;
|
import org.briarproject.api.event.BlogInvitationResponseReceivedEvent;
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.api.event.Event;
|
||||||
import org.briarproject.api.event.EventListener;
|
import org.briarproject.api.event.EventListener;
|
||||||
import org.briarproject.api.event.MessageStateChangedEvent;
|
|
||||||
import org.briarproject.api.identity.AuthorFactory;
|
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.api.sharing.InvitationMessage;
|
import org.briarproject.api.sharing.InvitationMessage;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.SyncSession;
|
|
||||||
import org.briarproject.api.sync.SyncSessionFactory;
|
|
||||||
import org.briarproject.api.sync.ValidationManager.State;
|
|
||||||
import org.briarproject.api.system.Clock;
|
|
||||||
import org.briarproject.blogs.BlogsModule;
|
|
||||||
import org.briarproject.contact.ContactModule;
|
|
||||||
import org.briarproject.crypto.CryptoModule;
|
|
||||||
import org.briarproject.lifecycle.LifecycleModule;
|
|
||||||
import org.briarproject.properties.PropertiesModule;
|
|
||||||
import org.briarproject.sharing.SharingModule;
|
|
||||||
import org.briarproject.sync.SyncModule;
|
|
||||||
import org.briarproject.transport.TransportModule;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import static org.briarproject.TestUtils.assertGroupCount;
|
||||||
|
|
||||||
import static org.briarproject.TestPluginsModule.MAX_LATENCY;
|
|
||||||
import static org.briarproject.api.blogs.BlogSharingManager.CLIENT_ID;
|
import static org.briarproject.api.blogs.BlogSharingManager.CLIENT_ID;
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.DELIVERED;
|
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.INVALID;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
||||||
|
|
||||||
private LifecycleManager lifecycleManager0, lifecycleManager1,
|
private BlogManager blogManager1;
|
||||||
lifecycleManager2;
|
|
||||||
private SyncSessionFactory sync0, sync1;
|
|
||||||
private BlogManager blogManager0, blogManager1;
|
|
||||||
private MessageTracker messageTracker0, messageTracker1;
|
|
||||||
private ContactManager contactManager0, contactManager1, contactManager2;
|
|
||||||
private Contact contact1, contact2, contact01, contact02;
|
|
||||||
private ContactId contactId1, contactId01;
|
|
||||||
private IdentityManager identityManager0, identityManager1,
|
|
||||||
identityManager2;
|
|
||||||
private LocalAuthor author0, author1, author2;
|
|
||||||
private Blog blog0, blog1, blog2;
|
private Blog blog0, blog1, blog2;
|
||||||
private SharerListener listener0;
|
private SharerListener listener0;
|
||||||
private InviteeListener listener1;
|
private InviteeListener listener1;
|
||||||
|
|
||||||
@Inject
|
|
||||||
Clock clock;
|
|
||||||
@Inject
|
|
||||||
AuthorFactory authorFactory;
|
|
||||||
@Inject
|
|
||||||
ContactGroupFactory contactGroupFactory;
|
|
||||||
@Inject
|
|
||||||
BlogPostFactory blogPostFactory;
|
|
||||||
@Inject
|
|
||||||
CryptoComponent cryptoComponent;
|
|
||||||
|
|
||||||
// objects accessed from background threads need to be volatile
|
// objects accessed from background threads need to be volatile
|
||||||
private volatile BlogSharingManager blogSharingManager0;
|
private volatile BlogSharingManager blogSharingManager0;
|
||||||
private volatile BlogSharingManager blogSharingManager1;
|
private volatile BlogSharingManager blogSharingManager1;
|
||||||
private volatile BlogSharingManager blogSharingManager2;
|
private volatile BlogSharingManager blogSharingManager2;
|
||||||
private volatile Waiter eventWaiter;
|
private volatile Waiter eventWaiter;
|
||||||
private volatile Waiter msgWaiter;
|
|
||||||
|
|
||||||
private final File testDir = TestUtils.getTestDirectory();
|
|
||||||
private final SecretKey master = TestUtils.getSecretKey();
|
|
||||||
private final int TIMEOUT = 15000;
|
|
||||||
private final String SHARER = "Sharer";
|
|
||||||
private final String INVITEE = "Invitee";
|
|
||||||
private final String CONTACT2 = "Contact2";
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
Logger.getLogger(BlogSharingIntegrationTest.class.getName());
|
|
||||||
|
|
||||||
private BlogSharingIntegrationTestComponent t0, t1, t2;
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
public ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
@Override
|
||||||
BlogSharingIntegrationTestComponent component =
|
public void setUp() throws Exception {
|
||||||
DaggerBlogSharingIntegrationTestComponent.builder().build();
|
super.setUp();
|
||||||
component.inject(this);
|
|
||||||
injectEagerSingletons(component);
|
|
||||||
|
|
||||||
assertTrue(testDir.mkdirs());
|
BlogManager blogManager0 = c0.getBlogManager();
|
||||||
File t0Dir = new File(testDir, SHARER);
|
blogManager1 = c1.getBlogManager();
|
||||||
t0 = DaggerBlogSharingIntegrationTestComponent.builder()
|
blogSharingManager0 = c0.getBlogSharingManager();
|
||||||
.testDatabaseModule(new TestDatabaseModule(t0Dir)).build();
|
blogSharingManager1 = c1.getBlogSharingManager();
|
||||||
injectEagerSingletons(t0);
|
blogSharingManager2 = c2.getBlogSharingManager();
|
||||||
File t1Dir = new File(testDir, INVITEE);
|
|
||||||
t1 = DaggerBlogSharingIntegrationTestComponent.builder()
|
|
||||||
.testDatabaseModule(new TestDatabaseModule(t1Dir)).build();
|
|
||||||
injectEagerSingletons(t1);
|
|
||||||
File t2Dir = new File(testDir, CONTACT2);
|
|
||||||
t2 = DaggerBlogSharingIntegrationTestComponent.builder()
|
|
||||||
.testDatabaseModule(new TestDatabaseModule(t2Dir)).build();
|
|
||||||
injectEagerSingletons(t2);
|
|
||||||
|
|
||||||
identityManager0 = t0.getIdentityManager();
|
blog0 = blogManager0.getPersonalBlog(author0);
|
||||||
identityManager1 = t1.getIdentityManager();
|
blog1 = blogManager0.getPersonalBlog(author1);
|
||||||
identityManager2 = t2.getIdentityManager();
|
blog2 = blogManager0.getPersonalBlog(author2);
|
||||||
contactManager0 = t0.getContactManager();
|
|
||||||
contactManager1 = t1.getContactManager();
|
|
||||||
contactManager2 = t2.getContactManager();
|
|
||||||
blogManager0 = t0.getBlogManager();
|
|
||||||
blogManager1 = t1.getBlogManager();
|
|
||||||
messageTracker0 = t0.getMessageTracker();
|
|
||||||
messageTracker1 = t1.getMessageTracker();
|
|
||||||
blogSharingManager0 = t0.getBlogSharingManager();
|
|
||||||
blogSharingManager1 = t1.getBlogSharingManager();
|
|
||||||
blogSharingManager2 = t2.getBlogSharingManager();
|
|
||||||
sync0 = t0.getSyncSessionFactory();
|
|
||||||
sync1 = t1.getSyncSessionFactory();
|
|
||||||
|
|
||||||
// initialize waiters fresh for each test
|
// initialize waiters fresh for each test
|
||||||
eventWaiter = new Waiter();
|
eventWaiter = new Waiter();
|
||||||
msgWaiter = new Waiter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersonalBlogCannotBeSharedWithOwner() throws Exception {
|
public void testPersonalBlogCannotBeSharedWithOwner() throws Exception {
|
||||||
startLifecycles();
|
listenToEvents(true);
|
||||||
defaultInit(true);
|
|
||||||
|
|
||||||
assertFalse(blogSharingManager0.canBeShared(blog1.getId(), contact1));
|
assertFalse(blogSharingManager0.canBeShared(blog1.getId(),
|
||||||
assertFalse(blogSharingManager0.canBeShared(blog2.getId(), contact2));
|
contact1From0));
|
||||||
assertFalse(blogSharingManager1.canBeShared(blog0.getId(), contact01));
|
assertFalse(blogSharingManager0.canBeShared(blog2.getId(),
|
||||||
assertFalse(blogSharingManager2.canBeShared(blog0.getId(), contact02));
|
contact2From0));
|
||||||
|
assertFalse(blogSharingManager1.canBeShared(blog0.getId(),
|
||||||
|
contact0From1));
|
||||||
|
assertFalse(blogSharingManager2.canBeShared(blog0.getId(),
|
||||||
|
contact0From2));
|
||||||
|
|
||||||
// create invitation
|
// create invitation
|
||||||
blogSharingManager0
|
blogSharingManager0
|
||||||
.sendInvitation(blog1.getId(), contactId1, "Hi!");
|
.sendInvitation(blog1.getId(), contactId1From0, "Hi!");
|
||||||
|
|
||||||
// sync invitation
|
// sync invitation
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
// make sure the invitee ignored the request for their own blog
|
// make sure the invitee ignored the request for their own blog
|
||||||
assertFalse(listener1.requestReceived);
|
assertFalse(listener1.requestReceived);
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccessfulSharing() throws Exception {
|
public void testSuccessfulSharing() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
|
|
||||||
// initialize and let invitee accept all requests
|
// initialize and let invitee accept all requests
|
||||||
defaultInit(true);
|
listenToEvents(true);
|
||||||
|
|
||||||
// send invitation
|
// send invitation
|
||||||
blogSharingManager0
|
blogSharingManager0
|
||||||
.sendInvitation(blog2.getId(), contactId1, "Hi!");
|
.sendInvitation(blog2.getId(), contactId1From0, "Hi!");
|
||||||
|
|
||||||
// invitee has own blog and that of the sharer
|
// invitee has own blog and that of the sharer
|
||||||
assertEquals(2, blogManager1.getBlogs().size());
|
assertEquals(2, blogManager1.getBlogs().size());
|
||||||
|
|
||||||
// get sharing group and assert group message count
|
// get sharing group and assert group message count
|
||||||
GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID, contact1)
|
GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||||
|
contact1From0)
|
||||||
.getId();
|
.getId();
|
||||||
assertGroupCount(messageTracker0, g, 1, 0);
|
assertGroupCount(messageTracker0, g, 1, 0);
|
||||||
|
|
||||||
// sync first request message
|
// sync first request message
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener1.requestReceived);
|
assertTrue(listener1.requestReceived);
|
||||||
assertGroupCount(messageTracker1, g, 2, 1);
|
assertGroupCount(messageTracker1, g, 2, 1);
|
||||||
|
|
||||||
// sync response back
|
// sync response back
|
||||||
sync1To0();
|
sync1To0(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener0.responseReceived);
|
assertTrue(listener0.responseReceived);
|
||||||
assertGroupCount(messageTracker0, g, 2, 1);
|
assertGroupCount(messageTracker0, g, 2, 1);
|
||||||
@@ -217,7 +125,7 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
// invitee has one invitation message from sharer
|
// invitee has one invitation message from sharer
|
||||||
List<InvitationMessage> list =
|
List<InvitationMessage> list =
|
||||||
new ArrayList<>(blogSharingManager1
|
new ArrayList<>(blogSharingManager1
|
||||||
.getInvitationMessages(contactId01));
|
.getInvitationMessages(contactId0From1));
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
// check other things are alright with the message
|
// check other things are alright with the message
|
||||||
for (InvitationMessage m : list) {
|
for (InvitationMessage m : list) {
|
||||||
@@ -227,49 +135,47 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
assertFalse(invitation.isAvailable());
|
assertFalse(invitation.isAvailable());
|
||||||
assertEquals(blog2.getAuthor().getName(),
|
assertEquals(blog2.getAuthor().getName(),
|
||||||
invitation.getBlogAuthorName());
|
invitation.getBlogAuthorName());
|
||||||
assertEquals(contactId1, invitation.getContactId());
|
assertEquals(contactId1From0, invitation.getContactId());
|
||||||
assertEquals("Hi!", invitation.getMessage());
|
assertEquals("Hi!", invitation.getMessage());
|
||||||
} else {
|
} else {
|
||||||
BlogInvitationResponse response =
|
BlogInvitationResponse response =
|
||||||
(BlogInvitationResponse) m;
|
(BlogInvitationResponse) m;
|
||||||
assertEquals(contactId01, response.getContactId());
|
assertEquals(contactId0From1, response.getContactId());
|
||||||
assertTrue(response.wasAccepted());
|
assertTrue(response.wasAccepted());
|
||||||
assertTrue(response.isLocal());
|
assertTrue(response.isLocal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sharer has own invitation message and response
|
// sharer has own invitation message and response
|
||||||
assertEquals(2,
|
assertEquals(2,
|
||||||
blogSharingManager0.getInvitationMessages(contactId1)
|
blogSharingManager0.getInvitationMessages(contactId1From0)
|
||||||
.size());
|
.size());
|
||||||
// blog can not be shared again
|
// blog can not be shared again
|
||||||
assertFalse(blogSharingManager0.canBeShared(blog2.getId(), contact1));
|
assertFalse(blogSharingManager0.canBeShared(blog2.getId(),
|
||||||
assertFalse(blogSharingManager1.canBeShared(blog2.getId(), contact01));
|
contact1From0));
|
||||||
|
assertFalse(blogSharingManager1.canBeShared(blog2.getId(),
|
||||||
|
contact0From1));
|
||||||
|
|
||||||
// group message count is still correct
|
// group message count is still correct
|
||||||
assertGroupCount(messageTracker0, g, 2, 1);
|
assertGroupCount(messageTracker0, g, 2, 1);
|
||||||
assertGroupCount(messageTracker1, g, 2, 1);
|
assertGroupCount(messageTracker1, g, 2, 1);
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeclinedSharing() throws Exception {
|
public void testDeclinedSharing() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
|
|
||||||
// initialize and let invitee deny all requests
|
// initialize and let invitee deny all requests
|
||||||
defaultInit(false);
|
listenToEvents(false);
|
||||||
|
|
||||||
// send invitation
|
// send invitation
|
||||||
blogSharingManager0
|
blogSharingManager0
|
||||||
.sendInvitation(blog2.getId(), contactId1, null);
|
.sendInvitation(blog2.getId(), contactId1From0, null);
|
||||||
|
|
||||||
// sync first request message
|
// sync first request message
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener1.requestReceived);
|
assertTrue(listener1.requestReceived);
|
||||||
|
|
||||||
// sync response back
|
// sync response back
|
||||||
sync1To0();
|
sync1To0(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener0.responseReceived);
|
assertTrue(listener0.responseReceived);
|
||||||
|
|
||||||
@@ -282,7 +188,7 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
// invitee has one invitation message from sharer and one response
|
// invitee has one invitation message from sharer and one response
|
||||||
List<InvitationMessage> list =
|
List<InvitationMessage> list =
|
||||||
new ArrayList<>(blogSharingManager1
|
new ArrayList<>(blogSharingManager1
|
||||||
.getInvitationMessages(contactId01));
|
.getInvitationMessages(contactId0From1));
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
// check things are alright with the message
|
// check things are alright with the message
|
||||||
for (InvitationMessage m : list) {
|
for (InvitationMessage m : list) {
|
||||||
@@ -292,44 +198,40 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
assertFalse(invitation.isAvailable());
|
assertFalse(invitation.isAvailable());
|
||||||
assertEquals(blog2.getAuthor().getName(),
|
assertEquals(blog2.getAuthor().getName(),
|
||||||
invitation.getBlogAuthorName());
|
invitation.getBlogAuthorName());
|
||||||
assertEquals(contactId1, invitation.getContactId());
|
assertEquals(contactId1From0, invitation.getContactId());
|
||||||
assertEquals(null, invitation.getMessage());
|
assertEquals(null, invitation.getMessage());
|
||||||
} else {
|
} else {
|
||||||
BlogInvitationResponse response =
|
BlogInvitationResponse response =
|
||||||
(BlogInvitationResponse) m;
|
(BlogInvitationResponse) m;
|
||||||
assertEquals(contactId01, response.getContactId());
|
assertEquals(contactId0From1, response.getContactId());
|
||||||
assertFalse(response.wasAccepted());
|
assertFalse(response.wasAccepted());
|
||||||
assertTrue(response.isLocal());
|
assertTrue(response.isLocal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sharer has own invitation message and response
|
// sharer has own invitation message and response
|
||||||
assertEquals(2,
|
assertEquals(2,
|
||||||
blogSharingManager0.getInvitationMessages(contactId1)
|
blogSharingManager0.getInvitationMessages(contactId1From0)
|
||||||
.size());
|
.size());
|
||||||
// blog can be shared again
|
// blog can be shared again
|
||||||
assertTrue(blogSharingManager0.canBeShared(blog2.getId(), contact1));
|
assertTrue(blogSharingManager0.canBeShared(blog2.getId(), contact1From0));
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInviteeLeavesAfterFinished() throws Exception {
|
public void testInviteeLeavesAfterFinished() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
|
|
||||||
// initialize and let invitee accept all requests
|
// initialize and let invitee accept all requests
|
||||||
defaultInit(true);
|
listenToEvents(true);
|
||||||
|
|
||||||
// send invitation
|
// send invitation
|
||||||
blogSharingManager0
|
blogSharingManager0
|
||||||
.sendInvitation(blog2.getId(), contactId1, "Hi!");
|
.sendInvitation(blog2.getId(), contactId1From0, "Hi!");
|
||||||
|
|
||||||
// sync first request message
|
// sync first request message
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener1.requestReceived);
|
assertTrue(listener1.requestReceived);
|
||||||
|
|
||||||
// sync response back
|
// sync response back
|
||||||
sync1To0();
|
sync1To0(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener0.responseReceived);
|
assertTrue(listener0.responseReceived);
|
||||||
|
|
||||||
@@ -340,16 +242,16 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
// sharer shares blog with invitee
|
// sharer shares blog with invitee
|
||||||
assertTrue(blogSharingManager0.getSharedWith(blog2.getId())
|
assertTrue(blogSharingManager0.getSharedWith(blog2.getId())
|
||||||
.contains(contact1));
|
.contains(contact1From0));
|
||||||
// invitee gets blog shared by sharer
|
// invitee gets blog shared by sharer
|
||||||
assertTrue(blogSharingManager1.getSharedBy(blog2.getId())
|
assertTrue(blogSharingManager1.getSharedBy(blog2.getId())
|
||||||
.contains(contact01));
|
.contains(contact0From1));
|
||||||
|
|
||||||
// invitee un-subscribes from blog
|
// invitee un-subscribes from blog
|
||||||
blogManager1.removeBlog(blog2);
|
blogManager1.removeBlog(blog2);
|
||||||
|
|
||||||
// send leave message to sharer
|
// send leave message to sharer
|
||||||
sync1To0();
|
sync1To0(1, true);
|
||||||
|
|
||||||
// blog is gone
|
// blog is gone
|
||||||
assertEquals(0, blogSharingManager0.getInvitations().size());
|
assertEquals(0, blogSharingManager0.getInvitations().size());
|
||||||
@@ -357,41 +259,30 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
// sharer no longer shares blog with invitee
|
// sharer no longer shares blog with invitee
|
||||||
assertFalse(blogSharingManager0.getSharedWith(blog2.getId())
|
assertFalse(blogSharingManager0.getSharedWith(blog2.getId())
|
||||||
.contains(contact1));
|
.contains(contact1From0));
|
||||||
// invitee no longer gets blog shared by sharer
|
// invitee no longer gets blog shared by sharer
|
||||||
assertFalse(blogSharingManager1.getSharedBy(blog2.getId())
|
assertFalse(blogSharingManager1.getSharedBy(blog2.getId())
|
||||||
.contains(contact01));
|
.contains(contact0From1));
|
||||||
// blog can be shared again
|
// blog can be shared again
|
||||||
assertTrue(blogSharingManager0.canBeShared(blog2.getId(), contact1));
|
assertTrue(blogSharingManager0.canBeShared(blog2.getId(), contact1From0));
|
||||||
assertTrue(blogSharingManager1.canBeShared(blog2.getId(), contact01));
|
assertTrue(blogSharingManager1.canBeShared(blog2.getId(), contact0From1));
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvitationForExistingBlog() throws Exception {
|
public void testInvitationForExistingBlog() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
|
|
||||||
// initialize and let invitee accept all requests
|
// initialize and let invitee accept all requests
|
||||||
defaultInit(true);
|
listenToEvents(true);
|
||||||
|
|
||||||
// 1 and 2 are adding each other
|
// 1 and 2 are adding each other
|
||||||
contactManager1.addContact(author2,
|
addContacts1And2();
|
||||||
author1.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
contactManager2.addContact(author1,
|
|
||||||
author2.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
assertEquals(3, blogManager1.getBlogs().size());
|
assertEquals(3, blogManager1.getBlogs().size());
|
||||||
|
|
||||||
// sharer sends invitation for 2's blog to 1
|
// sharer sends invitation for 2's blog to 1
|
||||||
blogSharingManager0
|
blogSharingManager0
|
||||||
.sendInvitation(blog2.getId(), contactId1, "Hi!");
|
.sendInvitation(blog2.getId(), contactId1From0, "Hi!");
|
||||||
|
|
||||||
// sync first request message
|
// sync first request message
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener1.requestReceived);
|
assertTrue(listener1.requestReceived);
|
||||||
|
|
||||||
@@ -399,44 +290,40 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
Collection<Contact> contacts =
|
Collection<Contact> contacts =
|
||||||
blogSharingManager1.getSharedBy(blog2.getId());
|
blogSharingManager1.getSharedBy(blog2.getId());
|
||||||
assertEquals(1, contacts.size());
|
assertEquals(1, contacts.size());
|
||||||
assertTrue(contacts.contains(contact01));
|
assertTrue(contacts.contains(contact0From1));
|
||||||
|
|
||||||
// make sure 1 knows that they have blog2 already
|
// make sure 1 knows that they have blog2 already
|
||||||
Collection<InvitationMessage> messages =
|
Collection<InvitationMessage> messages =
|
||||||
blogSharingManager1.getInvitationMessages(contactId01);
|
blogSharingManager1.getInvitationMessages(contactId0From1);
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
assertEquals(blog2, blogManager1.getBlog(blog2.getId()));
|
assertEquals(blog2, blogManager1.getBlog(blog2.getId()));
|
||||||
|
|
||||||
// sync response back
|
// sync response back
|
||||||
sync1To0();
|
sync1To0(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener0.responseReceived);
|
assertTrue(listener0.responseReceived);
|
||||||
|
|
||||||
// blog was not added, because it was there already
|
// blog was not added, because it was there already
|
||||||
assertEquals(0, blogSharingManager0.getInvitations().size());
|
assertEquals(0, blogSharingManager0.getInvitations().size());
|
||||||
assertEquals(3, blogManager1.getBlogs().size());
|
assertEquals(3, blogManager1.getBlogs().size());
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemovingSharedBlog() throws Exception {
|
public void testRemovingSharedBlog() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
|
|
||||||
// initialize and let invitee accept all requests
|
// initialize and let invitee accept all requests
|
||||||
defaultInit(true);
|
listenToEvents(true);
|
||||||
|
|
||||||
// send invitation
|
// send invitation
|
||||||
blogSharingManager0
|
blogSharingManager0
|
||||||
.sendInvitation(blog2.getId(), contactId1, "Hi!");
|
.sendInvitation(blog2.getId(), contactId1From0, "Hi!");
|
||||||
|
|
||||||
// sync first request message
|
// sync first request message
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener1.requestReceived);
|
assertTrue(listener1.requestReceived);
|
||||||
|
|
||||||
// sync response back
|
// sync response back
|
||||||
sync1To0();
|
sync1To0(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener0.responseReceived);
|
assertTrue(listener0.responseReceived);
|
||||||
|
|
||||||
@@ -445,11 +332,11 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
Collection<Contact> sharedWith =
|
Collection<Contact> sharedWith =
|
||||||
blogSharingManager0.getSharedWith(blog2.getId());
|
blogSharingManager0.getSharedWith(blog2.getId());
|
||||||
assertEquals(1, sharedWith.size());
|
assertEquals(1, sharedWith.size());
|
||||||
assertEquals(contact1, sharedWith.iterator().next());
|
assertEquals(contact1From0, sharedWith.iterator().next());
|
||||||
Collection<Contact> sharedBy =
|
Collection<Contact> sharedBy =
|
||||||
blogSharingManager1.getSharedBy(blog2.getId());
|
blogSharingManager1.getSharedBy(blog2.getId());
|
||||||
assertEquals(1, sharedBy.size());
|
assertEquals(1, sharedBy.size());
|
||||||
assertEquals(contact01, sharedBy.iterator().next());
|
assertEquals(contact0From1, sharedBy.iterator().next());
|
||||||
|
|
||||||
// shared blog can be removed
|
// shared blog can be removed
|
||||||
assertTrue(blogManager1.canBeRemoved(blog2.getId()));
|
assertTrue(blogManager1.canBeRemoved(blog2.getId()));
|
||||||
@@ -458,32 +345,28 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
blogManager1.removeBlog(blog2);
|
blogManager1.removeBlog(blog2);
|
||||||
|
|
||||||
// sync LEAVE message
|
// sync LEAVE message
|
||||||
sync1To0();
|
sync1To0(1, true);
|
||||||
|
|
||||||
// sharer does not share this blog anymore with invitee
|
// sharer does not share this blog anymore with invitee
|
||||||
sharedWith =
|
sharedWith =
|
||||||
blogSharingManager0.getSharedWith(blog2.getId());
|
blogSharingManager0.getSharedWith(blog2.getId());
|
||||||
assertEquals(0, sharedWith.size());
|
assertEquals(0, sharedWith.size());
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharedBlogBecomesPermanent() throws Exception {
|
public void testSharedBlogBecomesPermanent() throws Exception {
|
||||||
startLifecycles();
|
// let invitee accept all requests
|
||||||
|
listenToEvents(true);
|
||||||
// initialize and let invitee accept all requests
|
|
||||||
defaultInit(true);
|
|
||||||
|
|
||||||
// invitee only sees two blogs
|
// invitee only sees two blogs
|
||||||
assertEquals(2, blogManager1.getBlogs().size());
|
assertEquals(2, blogManager1.getBlogs().size());
|
||||||
|
|
||||||
// sharer sends invitation for 2's blog to 1
|
// sharer sends invitation for 2's blog to 1
|
||||||
blogSharingManager0
|
blogSharingManager0
|
||||||
.sendInvitation(blog2.getId(), contactId1, "Hi!");
|
.sendInvitation(blog2.getId(), contactId1From0, "Hi!");
|
||||||
|
|
||||||
// sync first request message
|
// sync first request message
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener1.requestReceived);
|
assertTrue(listener1.requestReceived);
|
||||||
|
|
||||||
@@ -491,10 +374,10 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
Collection<Contact> contacts =
|
Collection<Contact> contacts =
|
||||||
blogSharingManager1.getSharedBy(blog2.getId());
|
blogSharingManager1.getSharedBy(blog2.getId());
|
||||||
assertEquals(1, contacts.size());
|
assertEquals(1, contacts.size());
|
||||||
assertTrue(contacts.contains(contact01));
|
assertTrue(contacts.contains(contact0From1));
|
||||||
|
|
||||||
// sync response back
|
// sync response back
|
||||||
sync1To0();
|
sync1To0(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener0.responseReceived);
|
assertTrue(listener0.responseReceived);
|
||||||
|
|
||||||
@@ -503,26 +386,11 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
assertTrue(blogManager1.canBeRemoved(blog2.getId()));
|
assertTrue(blogManager1.canBeRemoved(blog2.getId()));
|
||||||
|
|
||||||
// 1 and 2 are adding each other
|
// 1 and 2 are adding each other
|
||||||
contactManager1.addContact(author2,
|
addContacts1And2();
|
||||||
author1.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
contactManager2.addContact(author1,
|
|
||||||
author2.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
assertEquals(3, blogManager1.getBlogs().size());
|
assertEquals(3, blogManager1.getBlogs().size());
|
||||||
|
|
||||||
// now blog can not be removed anymore
|
// now blog can not be removed anymore
|
||||||
assertFalse(blogManager1.canBeRemoved(blog2.getId()));
|
assertFalse(blogManager1.canBeRemoved(blog2.getId()));
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws InterruptedException {
|
|
||||||
TestUtils.deleteTestDirectory(testDir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SharerListener implements EventListener {
|
private class SharerListener implements EventListener {
|
||||||
@@ -531,17 +399,10 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eventOccurred(Event e) {
|
public void eventOccurred(Event e) {
|
||||||
if (e instanceof MessageStateChangedEvent) {
|
if (e instanceof BlogInvitationResponseReceivedEvent) {
|
||||||
MessageStateChangedEvent event = (MessageStateChangedEvent) e;
|
|
||||||
State s = event.getState();
|
|
||||||
if ((s == DELIVERED || s == INVALID) && !event.isLocal()) {
|
|
||||||
LOG.info("TEST: Sharer received message");
|
|
||||||
msgWaiter.resume();
|
|
||||||
}
|
|
||||||
} else if (e instanceof BlogInvitationResponseReceivedEvent) {
|
|
||||||
BlogInvitationResponseReceivedEvent event =
|
BlogInvitationResponseReceivedEvent event =
|
||||||
(BlogInvitationResponseReceivedEvent) e;
|
(BlogInvitationResponseReceivedEvent) e;
|
||||||
eventWaiter.assertEquals(contactId1, event.getContactId());
|
eventWaiter.assertEquals(contactId1From0, event.getContactId());
|
||||||
responseReceived = true;
|
responseReceived = true;
|
||||||
eventWaiter.resume();
|
eventWaiter.resume();
|
||||||
}
|
}
|
||||||
@@ -549,10 +410,10 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
else if (e instanceof BlogInvitationReceivedEvent) {
|
else if (e instanceof BlogInvitationReceivedEvent) {
|
||||||
BlogInvitationReceivedEvent event =
|
BlogInvitationReceivedEvent event =
|
||||||
(BlogInvitationReceivedEvent) e;
|
(BlogInvitationReceivedEvent) e;
|
||||||
eventWaiter.assertEquals(contactId1, event.getContactId());
|
eventWaiter.assertEquals(contactId1From0, event.getContactId());
|
||||||
Blog b = event.getShareable();
|
Blog b = event.getShareable();
|
||||||
try {
|
try {
|
||||||
Contact c = contactManager0.getContact(contactId1);
|
Contact c = contactManager0.getContact(contactId1From0);
|
||||||
blogSharingManager0.respondToInvitation(b, c, true);
|
blogSharingManager0.respondToInvitation(b, c, true);
|
||||||
} catch (DbException ex) {
|
} catch (DbException ex) {
|
||||||
eventWaiter.rethrow(ex);
|
eventWaiter.rethrow(ex);
|
||||||
@@ -580,14 +441,7 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eventOccurred(Event e) {
|
public void eventOccurred(Event e) {
|
||||||
if (e instanceof MessageStateChangedEvent) {
|
if (e instanceof BlogInvitationReceivedEvent) {
|
||||||
MessageStateChangedEvent event = (MessageStateChangedEvent) e;
|
|
||||||
State s = event.getState();
|
|
||||||
if ((s == DELIVERED || s == INVALID) && !event.isLocal()) {
|
|
||||||
LOG.info("TEST: Invitee received message");
|
|
||||||
msgWaiter.resume();
|
|
||||||
}
|
|
||||||
} else if (e instanceof BlogInvitationReceivedEvent) {
|
|
||||||
BlogInvitationReceivedEvent event =
|
BlogInvitationReceivedEvent event =
|
||||||
(BlogInvitationReceivedEvent) e;
|
(BlogInvitationReceivedEvent) e;
|
||||||
requestReceived = true;
|
requestReceived = true;
|
||||||
@@ -609,135 +463,19 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
|||||||
else if (e instanceof BlogInvitationResponseReceivedEvent) {
|
else if (e instanceof BlogInvitationResponseReceivedEvent) {
|
||||||
BlogInvitationResponseReceivedEvent event =
|
BlogInvitationResponseReceivedEvent event =
|
||||||
(BlogInvitationResponseReceivedEvent) e;
|
(BlogInvitationResponseReceivedEvent) e;
|
||||||
eventWaiter.assertEquals(contactId01, event.getContactId());
|
eventWaiter.assertEquals(contactId0From1, event.getContactId());
|
||||||
eventWaiter.resume();
|
eventWaiter.resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startLifecycles() throws InterruptedException {
|
private void listenToEvents(boolean accept) throws DbException {
|
||||||
// Start the lifecycle manager and wait for it to finish
|
|
||||||
lifecycleManager0 = t0.getLifecycleManager();
|
|
||||||
lifecycleManager1 = t1.getLifecycleManager();
|
|
||||||
lifecycleManager2 = t2.getLifecycleManager();
|
|
||||||
lifecycleManager0.startServices(SHARER);
|
|
||||||
lifecycleManager1.startServices(INVITEE);
|
|
||||||
lifecycleManager2.startServices(CONTACT2);
|
|
||||||
lifecycleManager0.waitForStartup();
|
|
||||||
lifecycleManager1.waitForStartup();
|
|
||||||
lifecycleManager2.waitForStartup();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopLifecycles() throws InterruptedException {
|
|
||||||
// Clean up
|
|
||||||
lifecycleManager0.stopServices();
|
|
||||||
lifecycleManager1.stopServices();
|
|
||||||
lifecycleManager2.stopServices();
|
|
||||||
lifecycleManager0.waitForShutdown();
|
|
||||||
lifecycleManager1.waitForShutdown();
|
|
||||||
lifecycleManager2.waitForShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void defaultInit(boolean accept) throws DbException {
|
|
||||||
getDefaultIdentities();
|
|
||||||
addDefaultContacts();
|
|
||||||
getPersonalBlogOfSharer();
|
|
||||||
listenToEvents(accept);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getDefaultIdentities() throws DbException {
|
|
||||||
author0 = identityManager0.getLocalAuthor();
|
|
||||||
author1 = identityManager1.getLocalAuthor();
|
|
||||||
author2 = identityManager2.getLocalAuthor();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addDefaultContacts() throws DbException {
|
|
||||||
// sharer adds invitee as contact
|
|
||||||
contactId1 = contactManager0.addContact(author1,
|
|
||||||
author0.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
contact1 = contactManager0.getContact(contactId1);
|
|
||||||
// sharer adds second contact
|
|
||||||
ContactId contactId2 = contactManager0.addContact(author2,
|
|
||||||
author0.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
contact2 = contactManager0.getContact(contactId2);
|
|
||||||
// contacts add sharer back
|
|
||||||
contactId01 = contactManager1.addContact(author0,
|
|
||||||
author1.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
contact01 = contactManager1.getContact(contactId01);
|
|
||||||
ContactId contactId02 = contactManager2.addContact(author0,
|
|
||||||
author2.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
contact02 = contactManager2.getContact(contactId02);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getPersonalBlogOfSharer() throws DbException {
|
|
||||||
blog0 = blogManager0.getPersonalBlog(author0);
|
|
||||||
blog1 = blogManager0.getPersonalBlog(author1);
|
|
||||||
blog2 = blogManager0.getPersonalBlog(author2);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void listenToEvents(boolean accept) {
|
|
||||||
listener0 = new SharerListener();
|
listener0 = new SharerListener();
|
||||||
t0.getEventBus().addListener(listener0);
|
c0.getEventBus().addListener(listener0);
|
||||||
listener1 = new InviteeListener(accept);
|
listener1 = new InviteeListener(accept);
|
||||||
t1.getEventBus().addListener(listener1);
|
c1.getEventBus().addListener(listener1);
|
||||||
SharerListener listener2 = new SharerListener();
|
SharerListener listener2 = new SharerListener();
|
||||||
t2.getEventBus().addListener(listener2);
|
c2.getEventBus().addListener(listener2);
|
||||||
}
|
|
||||||
|
|
||||||
private void sync0To1() throws IOException, TimeoutException {
|
|
||||||
deliverMessage(sync0, contactId01, sync1, contactId1,
|
|
||||||
"Sharer to Invitee");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sync1To0() throws IOException, TimeoutException {
|
|
||||||
deliverMessage(sync1, contactId1, sync0, contactId01,
|
|
||||||
"Invitee to Sharer");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deliverMessage(SyncSessionFactory fromSync, ContactId fromId,
|
|
||||||
SyncSessionFactory toSync, ContactId toId, String debug)
|
|
||||||
throws IOException, TimeoutException {
|
|
||||||
|
|
||||||
if (debug != null) LOG.info("TEST: Sending message from " + debug);
|
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
// Create an outgoing sync session
|
|
||||||
SyncSession sessionFrom =
|
|
||||||
fromSync.createSimplexOutgoingSession(toId, MAX_LATENCY, out);
|
|
||||||
// Write whatever needs to be written
|
|
||||||
sessionFrom.run();
|
|
||||||
out.close();
|
|
||||||
|
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
||||||
// Create an incoming sync session
|
|
||||||
SyncSession sessionTo = toSync.createIncomingSession(fromId, in);
|
|
||||||
// Read whatever needs to be read
|
|
||||||
sessionTo.run();
|
|
||||||
in.close();
|
|
||||||
|
|
||||||
// wait for message to actually arrive
|
|
||||||
msgWaiter.await(TIMEOUT, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void injectEagerSingletons(
|
|
||||||
BlogSharingIntegrationTestComponent component) {
|
|
||||||
|
|
||||||
component.inject(new LifecycleModule.EagerSingletons());
|
|
||||||
component.inject(new BlogsModule.EagerSingletons());
|
|
||||||
component.inject(new CryptoModule.EagerSingletons());
|
|
||||||
component.inject(new ContactModule.EagerSingletons());
|
|
||||||
component.inject(new TransportModule.EagerSingletons());
|
|
||||||
component.inject(new SharingModule.EagerSingletons());
|
|
||||||
component.inject(new SyncModule.EagerSingletons());
|
|
||||||
component.inject(new PropertiesModule.EagerSingletons());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
package org.briarproject;
|
|
||||||
|
|
||||||
import org.briarproject.api.blogs.BlogManager;
|
|
||||||
import org.briarproject.api.blogs.BlogSharingManager;
|
|
||||||
import org.briarproject.api.clients.MessageTracker;
|
|
||||||
import org.briarproject.api.contact.ContactManager;
|
|
||||||
import org.briarproject.api.event.EventBus;
|
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.api.sync.SyncSessionFactory;
|
|
||||||
import org.briarproject.blogs.BlogsModule;
|
|
||||||
import org.briarproject.clients.ClientsModule;
|
|
||||||
import org.briarproject.contact.ContactModule;
|
|
||||||
import org.briarproject.crypto.CryptoModule;
|
|
||||||
import org.briarproject.data.DataModule;
|
|
||||||
import org.briarproject.db.DatabaseModule;
|
|
||||||
import org.briarproject.event.EventModule;
|
|
||||||
import org.briarproject.forum.ForumModule;
|
|
||||||
import org.briarproject.identity.IdentityModule;
|
|
||||||
import org.briarproject.lifecycle.LifecycleModule;
|
|
||||||
import org.briarproject.messaging.MessagingModule;
|
|
||||||
import org.briarproject.properties.PropertiesModule;
|
|
||||||
import org.briarproject.sharing.SharingModule;
|
|
||||||
import org.briarproject.sync.SyncModule;
|
|
||||||
import org.briarproject.system.SystemModule;
|
|
||||||
import org.briarproject.transport.TransportModule;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Component;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Component(modules = {
|
|
||||||
TestDatabaseModule.class,
|
|
||||||
TestPluginsModule.class,
|
|
||||||
TestSeedProviderModule.class,
|
|
||||||
ClientsModule.class,
|
|
||||||
ContactModule.class,
|
|
||||||
CryptoModule.class,
|
|
||||||
DataModule.class,
|
|
||||||
DatabaseModule.class,
|
|
||||||
EventModule.class,
|
|
||||||
BlogsModule.class,
|
|
||||||
ForumModule.class,
|
|
||||||
IdentityModule.class,
|
|
||||||
LifecycleModule.class,
|
|
||||||
PropertiesModule.class,
|
|
||||||
SharingModule.class,
|
|
||||||
SyncModule.class,
|
|
||||||
SystemModule.class,
|
|
||||||
TransportModule.class,
|
|
||||||
MessagingModule.class
|
|
||||||
})
|
|
||||||
interface BlogSharingIntegrationTestComponent {
|
|
||||||
|
|
||||||
void inject(BlogSharingIntegrationTest testCase);
|
|
||||||
|
|
||||||
void inject(ContactModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(CryptoModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(BlogsModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(LifecycleModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(PropertiesModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(SharingModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(SyncModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(TransportModule.EagerSingletons init);
|
|
||||||
|
|
||||||
LifecycleManager getLifecycleManager();
|
|
||||||
|
|
||||||
EventBus getEventBus();
|
|
||||||
|
|
||||||
IdentityManager getIdentityManager();
|
|
||||||
|
|
||||||
ContactManager getContactManager();
|
|
||||||
|
|
||||||
BlogSharingManager getBlogSharingManager();
|
|
||||||
|
|
||||||
BlogManager getBlogManager();
|
|
||||||
|
|
||||||
MessageTracker getMessageTracker();
|
|
||||||
|
|
||||||
SyncSessionFactory getSyncSessionFactory();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +1,360 @@
|
|||||||
package org.briarproject;
|
package org.briarproject;
|
||||||
|
|
||||||
|
import android.support.annotation.CallSuper;
|
||||||
|
|
||||||
|
import net.jodah.concurrentunit.Waiter;
|
||||||
|
|
||||||
|
import org.briarproject.api.blogs.BlogFactory;
|
||||||
|
import org.briarproject.api.blogs.BlogPostFactory;
|
||||||
|
import org.briarproject.api.clients.ClientHelper;
|
||||||
|
import org.briarproject.api.clients.ContactGroupFactory;
|
||||||
import org.briarproject.api.clients.MessageTracker;
|
import org.briarproject.api.clients.MessageTracker;
|
||||||
import org.briarproject.api.clients.MessageTracker.GroupCount;
|
import org.briarproject.api.contact.Contact;
|
||||||
|
import org.briarproject.api.contact.ContactId;
|
||||||
|
import org.briarproject.api.contact.ContactManager;
|
||||||
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
|
import org.briarproject.api.db.DatabaseComponent;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.event.Event;
|
||||||
|
import org.briarproject.api.event.EventListener;
|
||||||
|
import org.briarproject.api.event.MessageStateChangedEvent;
|
||||||
|
import org.briarproject.api.forum.ForumPostFactory;
|
||||||
|
import org.briarproject.api.identity.AuthorFactory;
|
||||||
|
import org.briarproject.api.identity.IdentityManager;
|
||||||
|
import org.briarproject.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.api.privategroup.GroupMessageFactory;
|
||||||
|
import org.briarproject.api.privategroup.PrivateGroupFactory;
|
||||||
|
import org.briarproject.api.privategroup.invitation.GroupInvitationFactory;
|
||||||
|
import org.briarproject.api.sync.SyncSession;
|
||||||
|
import org.briarproject.api.sync.SyncSessionFactory;
|
||||||
|
import org.briarproject.api.system.Clock;
|
||||||
|
import org.briarproject.blogs.BlogsModule;
|
||||||
|
import org.briarproject.contact.ContactModule;
|
||||||
|
import org.briarproject.crypto.CryptoModule;
|
||||||
|
import org.briarproject.forum.ForumModule;
|
||||||
|
import org.briarproject.introduction.IntroductionGroupFactory;
|
||||||
|
import org.briarproject.introduction.IntroductionModule;
|
||||||
|
import org.briarproject.lifecycle.LifecycleModule;
|
||||||
|
import org.briarproject.privategroup.PrivateGroupModule;
|
||||||
|
import org.briarproject.properties.PropertiesModule;
|
||||||
|
import org.briarproject.sharing.SharingModule;
|
||||||
|
import org.briarproject.sync.SyncModule;
|
||||||
|
import org.briarproject.transport.TransportModule;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertNotNull;
|
||||||
|
import static org.briarproject.TestPluginsModule.MAX_LATENCY;
|
||||||
|
import static org.briarproject.TestUtils.getSecretKey;
|
||||||
|
import static org.briarproject.api.sync.ValidationManager.State.DELIVERED;
|
||||||
|
import static org.briarproject.api.sync.ValidationManager.State.INVALID;
|
||||||
|
import static org.briarproject.api.sync.ValidationManager.State.PENDING;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
public abstract class BriarIntegrationTest extends BriarTestCase {
|
public abstract class BriarIntegrationTest extends BriarTestCase {
|
||||||
|
|
||||||
protected static void assertGroupCount(MessageTracker tracker, GroupId g,
|
private static final Logger LOG =
|
||||||
long msgCount, long unreadCount, long latestMsg)
|
Logger.getLogger(BriarIntegrationTest.class.getName());
|
||||||
throws DbException {
|
|
||||||
|
|
||||||
GroupCount groupCount = tracker.getGroupCount(g);
|
@Nullable
|
||||||
assertEquals(msgCount, groupCount.getMsgCount());
|
protected ContactId contactId1From2, contactId2From1;
|
||||||
assertEquals(unreadCount, groupCount.getUnreadCount());
|
protected ContactId contactId0From1, contactId0From2, contactId1From0,
|
||||||
assertEquals(latestMsg, groupCount.getLatestMsgTime());
|
contactId2From0;
|
||||||
|
protected Contact contact0From1, contact0From2, contact1From0,
|
||||||
|
contact2From0;
|
||||||
|
protected LocalAuthor author0, author1, author2;
|
||||||
|
protected ContactManager contactManager0, contactManager1, contactManager2;
|
||||||
|
protected IdentityManager identityManager0, identityManager1,
|
||||||
|
identityManager2;
|
||||||
|
protected DatabaseComponent db0, db1, db2;
|
||||||
|
protected MessageTracker messageTracker0, messageTracker1, messageTracker2;
|
||||||
|
|
||||||
|
private LifecycleManager lifecycleManager0, lifecycleManager1,
|
||||||
|
lifecycleManager2;
|
||||||
|
private SyncSessionFactory sync0, sync1, sync2;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected Clock clock;
|
||||||
|
@Inject
|
||||||
|
protected CryptoComponent crypto;
|
||||||
|
@Inject
|
||||||
|
protected ClientHelper clientHelper;
|
||||||
|
@Inject
|
||||||
|
protected AuthorFactory authorFactory;
|
||||||
|
@Inject
|
||||||
|
protected IntroductionGroupFactory introductionGroupFactory;
|
||||||
|
@Inject
|
||||||
|
ContactGroupFactory contactGroupFactory;
|
||||||
|
@Inject
|
||||||
|
PrivateGroupFactory privateGroupFactory;
|
||||||
|
@Inject
|
||||||
|
GroupMessageFactory groupMessageFactory;
|
||||||
|
@Inject
|
||||||
|
GroupInvitationFactory groupInvitationFactory;
|
||||||
|
@Inject
|
||||||
|
BlogFactory blogFactory;
|
||||||
|
@Inject
|
||||||
|
BlogPostFactory blogPostFactory;
|
||||||
|
@Inject
|
||||||
|
ForumPostFactory forumPostFactory;
|
||||||
|
|
||||||
|
// objects accessed from background threads need to be volatile
|
||||||
|
private volatile Waiter validationWaiter;
|
||||||
|
private volatile Waiter deliveryWaiter;
|
||||||
|
|
||||||
|
protected final static int TIMEOUT = 15000;
|
||||||
|
protected BriarIntegrationTestComponent c0, c1, c2;
|
||||||
|
|
||||||
|
private final File testDir = TestUtils.getTestDirectory();
|
||||||
|
private final String AUTHOR0 = "Author 0";
|
||||||
|
private final String AUTHOR1 = "Author 1";
|
||||||
|
private final String AUTHOR2 = "Author 2";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
@CallSuper
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
BriarIntegrationTestComponent component =
|
||||||
|
DaggerBriarIntegrationTestComponent.builder().build();
|
||||||
|
component.inject(this);
|
||||||
|
|
||||||
|
assertTrue(testDir.mkdirs());
|
||||||
|
File t0Dir = new File(testDir, AUTHOR0);
|
||||||
|
c0 = DaggerBriarIntegrationTestComponent.builder()
|
||||||
|
.testDatabaseModule(new TestDatabaseModule(t0Dir)).build();
|
||||||
|
injectEagerSingletons(c0);
|
||||||
|
File t1Dir = new File(testDir, AUTHOR1);
|
||||||
|
c1 = DaggerBriarIntegrationTestComponent.builder()
|
||||||
|
.testDatabaseModule(new TestDatabaseModule(t1Dir)).build();
|
||||||
|
injectEagerSingletons(c1);
|
||||||
|
File t2Dir = new File(testDir, AUTHOR2);
|
||||||
|
c2 = DaggerBriarIntegrationTestComponent.builder()
|
||||||
|
.testDatabaseModule(new TestDatabaseModule(t2Dir)).build();
|
||||||
|
injectEagerSingletons(c2);
|
||||||
|
|
||||||
|
identityManager0 = c0.getIdentityManager();
|
||||||
|
identityManager1 = c1.getIdentityManager();
|
||||||
|
identityManager2 = c2.getIdentityManager();
|
||||||
|
contactManager0 = c0.getContactManager();
|
||||||
|
contactManager1 = c1.getContactManager();
|
||||||
|
contactManager2 = c2.getContactManager();
|
||||||
|
messageTracker0 = c0.getMessageTracker();
|
||||||
|
messageTracker1 = c1.getMessageTracker();
|
||||||
|
messageTracker2 = c2.getMessageTracker();
|
||||||
|
db0 = c0.getDatabaseComponent();
|
||||||
|
db1 = c1.getDatabaseComponent();
|
||||||
|
db2 = c2.getDatabaseComponent();
|
||||||
|
sync0 = c0.getSyncSessionFactory();
|
||||||
|
sync1 = c1.getSyncSessionFactory();
|
||||||
|
sync2 = c2.getSyncSessionFactory();
|
||||||
|
|
||||||
|
// initialize waiters fresh for each test
|
||||||
|
validationWaiter = new Waiter();
|
||||||
|
deliveryWaiter = new Waiter();
|
||||||
|
|
||||||
|
startLifecycles();
|
||||||
|
|
||||||
|
getDefaultIdentities();
|
||||||
|
addDefaultContacts();
|
||||||
|
listenToEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void assertGroupCount(MessageTracker tracker, GroupId g,
|
private void injectEagerSingletons(
|
||||||
long msgCount, long unreadCount) throws DbException {
|
BriarIntegrationTestComponent component) {
|
||||||
|
component.inject(new LifecycleModule.EagerSingletons());
|
||||||
GroupCount c1 = tracker.getGroupCount(g);
|
component.inject(new BlogsModule.EagerSingletons());
|
||||||
assertEquals(msgCount, c1.getMsgCount());
|
component.inject(new CryptoModule.EagerSingletons());
|
||||||
assertEquals(unreadCount, c1.getUnreadCount());
|
component.inject(new ContactModule.EagerSingletons());
|
||||||
|
component.inject(new ForumModule.EagerSingletons());
|
||||||
|
component.inject(new IntroductionModule.EagerSingletons());
|
||||||
|
component.inject(new PropertiesModule.EagerSingletons());
|
||||||
|
component.inject(new PrivateGroupModule.EagerSingletons());
|
||||||
|
component.inject(new SyncModule.EagerSingletons());
|
||||||
|
component.inject(new SharingModule.EagerSingletons());
|
||||||
|
component.inject(new TransportModule.EagerSingletons());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startLifecycles() throws InterruptedException {
|
||||||
|
// Start the lifecycle manager and wait for it to finish
|
||||||
|
lifecycleManager0 = c0.getLifecycleManager();
|
||||||
|
lifecycleManager1 = c1.getLifecycleManager();
|
||||||
|
lifecycleManager2 = c2.getLifecycleManager();
|
||||||
|
lifecycleManager0.startServices(AUTHOR0);
|
||||||
|
lifecycleManager1.startServices(AUTHOR1);
|
||||||
|
lifecycleManager2.startServices(AUTHOR2);
|
||||||
|
lifecycleManager0.waitForStartup();
|
||||||
|
lifecycleManager1.waitForStartup();
|
||||||
|
lifecycleManager2.waitForStartup();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listenToEvents() {
|
||||||
|
Listener listener0 = new Listener();
|
||||||
|
c0.getEventBus().addListener(listener0);
|
||||||
|
Listener listener1 = new Listener();
|
||||||
|
c1.getEventBus().addListener(listener1);
|
||||||
|
Listener listener2 = new Listener();
|
||||||
|
c2.getEventBus().addListener(listener2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Listener implements EventListener {
|
||||||
|
@Override
|
||||||
|
public void eventOccurred(Event e) {
|
||||||
|
if (e instanceof MessageStateChangedEvent) {
|
||||||
|
MessageStateChangedEvent event = (MessageStateChangedEvent) e;
|
||||||
|
if (!event.isLocal()) {
|
||||||
|
if (event.getState() == DELIVERED) {
|
||||||
|
LOG.info("Delivered new message");
|
||||||
|
deliveryWaiter.resume();
|
||||||
|
} else if (event.getState() == INVALID ||
|
||||||
|
event.getState() == PENDING) {
|
||||||
|
LOG.info("Validated new " + event.getState().name() +
|
||||||
|
" message");
|
||||||
|
validationWaiter.resume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getDefaultIdentities() throws DbException {
|
||||||
|
author0 = identityManager0.getLocalAuthor();
|
||||||
|
author1 = identityManager1.getLocalAuthor();
|
||||||
|
author2 = identityManager2.getLocalAuthor();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addDefaultContacts() throws DbException {
|
||||||
|
contactId1From0 = contactManager0
|
||||||
|
.addContact(author1, author0.getId(), getSecretKey(),
|
||||||
|
clock.currentTimeMillis(), true, true, true);
|
||||||
|
contact1From0 = contactManager0.getContact(contactId1From0);
|
||||||
|
contactId0From1 = contactManager1
|
||||||
|
.addContact(author0, author1.getId(), getSecretKey(),
|
||||||
|
clock.currentTimeMillis(), true, true, true);
|
||||||
|
contact0From1 = contactManager1.getContact(contactId0From1);
|
||||||
|
contactId2From0 = contactManager0
|
||||||
|
.addContact(author2, author0.getId(), getSecretKey(),
|
||||||
|
clock.currentTimeMillis(), true, true, true);
|
||||||
|
contact2From0 = contactManager0.getContact(contactId2From0);
|
||||||
|
contactId0From2 = contactManager2
|
||||||
|
.addContact(author0, author2.getId(), getSecretKey(),
|
||||||
|
clock.currentTimeMillis(), true, true, true);
|
||||||
|
contact0From2 = contactManager2.getContact(contactId0From2);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addContacts1And2() throws DbException {
|
||||||
|
contactId2From1 = contactManager1
|
||||||
|
.addContact(author2, author1.getId(), getSecretKey(),
|
||||||
|
clock.currentTimeMillis(), true, true, true);
|
||||||
|
contactId1From2 = contactManager2
|
||||||
|
.addContact(author1, author2.getId(), getSecretKey(),
|
||||||
|
clock.currentTimeMillis(), true, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
stopLifecycles();
|
||||||
|
TestUtils.deleteTestDirectory(testDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopLifecycles() throws InterruptedException {
|
||||||
|
// Clean up
|
||||||
|
lifecycleManager0.stopServices();
|
||||||
|
lifecycleManager1.stopServices();
|
||||||
|
lifecycleManager2.stopServices();
|
||||||
|
lifecycleManager0.waitForShutdown();
|
||||||
|
lifecycleManager1.waitForShutdown();
|
||||||
|
lifecycleManager2.waitForShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sync0To1(int num, boolean valid)
|
||||||
|
throws IOException, TimeoutException {
|
||||||
|
syncMessage(sync0, contactId0From1, sync1, contactId1From0, num, valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sync0To2(int num, boolean valid)
|
||||||
|
throws IOException, TimeoutException {
|
||||||
|
syncMessage(sync0, contactId0From2, sync2, contactId2From0, num, valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sync1To0(int num, boolean valid)
|
||||||
|
throws IOException, TimeoutException {
|
||||||
|
syncMessage(sync1, contactId1From0, sync0, contactId0From1, num, valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sync2To0(int num, boolean valid)
|
||||||
|
throws IOException, TimeoutException {
|
||||||
|
syncMessage(sync2, contactId2From0, sync0, contactId0From2, num, valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sync2To1(int num, boolean valid)
|
||||||
|
throws IOException, TimeoutException {
|
||||||
|
assertNotNull(contactId2From1);
|
||||||
|
assertNotNull(contactId1From2);
|
||||||
|
syncMessage(sync2, contactId2From1, sync1, contactId1From2, num, valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sync1To2(int num, boolean valid)
|
||||||
|
throws IOException, TimeoutException {
|
||||||
|
assertNotNull(contactId2From1);
|
||||||
|
assertNotNull(contactId1From2);
|
||||||
|
syncMessage(sync1, contactId1From2, sync2, contactId2From1, num, valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncMessage(SyncSessionFactory fromSync, ContactId fromId,
|
||||||
|
SyncSessionFactory toSync, ContactId toId, int num, boolean valid)
|
||||||
|
throws IOException, TimeoutException {
|
||||||
|
|
||||||
|
// Debug output
|
||||||
|
String from = "0";
|
||||||
|
if (fromSync == sync1) from = "1";
|
||||||
|
else if (fromSync == sync2) from = "2";
|
||||||
|
String to = "0";
|
||||||
|
if (toSync == sync1) to = "1";
|
||||||
|
else if (toSync == sync2) to = "2";
|
||||||
|
LOG.info("TEST: Sending message from " + from + " to " + to);
|
||||||
|
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
// Create an outgoing sync session
|
||||||
|
SyncSession sessionFrom =
|
||||||
|
fromSync.createSimplexOutgoingSession(toId, MAX_LATENCY, out);
|
||||||
|
// Write whatever needs to be written
|
||||||
|
sessionFrom.run();
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
|
// Create an incoming sync session
|
||||||
|
SyncSession sessionTo = toSync.createIncomingSession(fromId, in);
|
||||||
|
// Read whatever needs to be read
|
||||||
|
sessionTo.run();
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
if (valid) {
|
||||||
|
deliveryWaiter.await(TIMEOUT, num);
|
||||||
|
} else {
|
||||||
|
validationWaiter.await(TIMEOUT, num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeAllContacts() throws DbException {
|
||||||
|
contactManager0.removeContact(contactId1From0);
|
||||||
|
contactManager0.removeContact(contactId2From0);
|
||||||
|
contactManager1.removeContact(contactId0From1);
|
||||||
|
contactManager1.removeContact(contactId2From1);
|
||||||
|
contactManager2.removeContact(contactId0From2);
|
||||||
|
contactManager2.removeContact(contactId1From2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
package org.briarproject;
|
package org.briarproject;
|
||||||
|
|
||||||
|
import org.briarproject.api.blogs.BlogManager;
|
||||||
|
import org.briarproject.api.blogs.BlogSharingManager;
|
||||||
import org.briarproject.api.clients.ClientHelper;
|
import org.briarproject.api.clients.ClientHelper;
|
||||||
import org.briarproject.api.clients.MessageQueueManager;
|
import org.briarproject.api.clients.MessageQueueManager;
|
||||||
import org.briarproject.api.clients.ContactGroupFactory;
|
import org.briarproject.api.clients.MessageTracker;
|
||||||
import org.briarproject.api.contact.ContactManager;
|
import org.briarproject.api.contact.ContactManager;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
import org.briarproject.api.db.DatabaseComponent;
|
||||||
import org.briarproject.api.event.EventBus;
|
import org.briarproject.api.event.EventBus;
|
||||||
import org.briarproject.api.forum.ForumManager;
|
import org.briarproject.api.forum.ForumManager;
|
||||||
import org.briarproject.api.forum.ForumSharingManager;
|
import org.briarproject.api.forum.ForumSharingManager;
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
import org.briarproject.api.identity.IdentityManager;
|
||||||
|
import org.briarproject.api.introduction.IntroductionManager;
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.api.privategroup.PrivateGroupManager;
|
||||||
|
import org.briarproject.api.properties.TransportPropertyManager;
|
||||||
import org.briarproject.api.sync.SyncSessionFactory;
|
import org.briarproject.api.sync.SyncSessionFactory;
|
||||||
import org.briarproject.blogs.BlogsModule;
|
import org.briarproject.blogs.BlogsModule;
|
||||||
import org.briarproject.clients.ClientsModule;
|
import org.briarproject.clients.ClientsModule;
|
||||||
@@ -20,8 +25,12 @@ import org.briarproject.db.DatabaseModule;
|
|||||||
import org.briarproject.event.EventModule;
|
import org.briarproject.event.EventModule;
|
||||||
import org.briarproject.forum.ForumModule;
|
import org.briarproject.forum.ForumModule;
|
||||||
import org.briarproject.identity.IdentityModule;
|
import org.briarproject.identity.IdentityModule;
|
||||||
|
import org.briarproject.introduction.IntroductionModule;
|
||||||
|
import org.briarproject.introduction.MessageSender;
|
||||||
import org.briarproject.lifecycle.LifecycleModule;
|
import org.briarproject.lifecycle.LifecycleModule;
|
||||||
import org.briarproject.messaging.MessagingModule;
|
import org.briarproject.messaging.MessagingModule;
|
||||||
|
import org.briarproject.privategroup.PrivateGroupModule;
|
||||||
|
import org.briarproject.privategroup.invitation.GroupInvitationModule;
|
||||||
import org.briarproject.properties.PropertiesModule;
|
import org.briarproject.properties.PropertiesModule;
|
||||||
import org.briarproject.sharing.SharingModule;
|
import org.briarproject.sharing.SharingModule;
|
||||||
import org.briarproject.sync.SyncModule;
|
import org.briarproject.sync.SyncModule;
|
||||||
@@ -40,23 +49,28 @@ import dagger.Component;
|
|||||||
ClientsModule.class,
|
ClientsModule.class,
|
||||||
ContactModule.class,
|
ContactModule.class,
|
||||||
CryptoModule.class,
|
CryptoModule.class,
|
||||||
|
BlogsModule.class,
|
||||||
DataModule.class,
|
DataModule.class,
|
||||||
DatabaseModule.class,
|
DatabaseModule.class,
|
||||||
EventModule.class,
|
EventModule.class,
|
||||||
ForumModule.class,
|
ForumModule.class,
|
||||||
BlogsModule.class,
|
GroupInvitationModule.class,
|
||||||
|
MessagingModule.class,
|
||||||
IdentityModule.class,
|
IdentityModule.class,
|
||||||
|
IntroductionModule.class,
|
||||||
LifecycleModule.class,
|
LifecycleModule.class,
|
||||||
|
PrivateGroupModule.class,
|
||||||
PropertiesModule.class,
|
PropertiesModule.class,
|
||||||
SharingModule.class,
|
SharingModule.class,
|
||||||
SyncModule.class,
|
SyncModule.class,
|
||||||
SystemModule.class,
|
SystemModule.class,
|
||||||
TransportModule.class,
|
TransportModule.class
|
||||||
MessagingModule.class
|
|
||||||
})
|
})
|
||||||
interface ForumSharingIntegrationTestComponent {
|
public interface BriarIntegrationTestComponent {
|
||||||
|
|
||||||
void inject(ForumSharingIntegrationTest testCase);
|
void inject(BriarIntegrationTest init);
|
||||||
|
|
||||||
|
void inject(BlogsModule.EagerSingletons init);
|
||||||
|
|
||||||
void inject(ContactModule.EagerSingletons init);
|
void inject(ContactModule.EagerSingletons init);
|
||||||
|
|
||||||
@@ -64,8 +78,12 @@ interface ForumSharingIntegrationTestComponent {
|
|||||||
|
|
||||||
void inject(ForumModule.EagerSingletons init);
|
void inject(ForumModule.EagerSingletons init);
|
||||||
|
|
||||||
|
void inject(IntroductionModule.EagerSingletons init);
|
||||||
|
|
||||||
void inject(LifecycleModule.EagerSingletons init);
|
void inject(LifecycleModule.EagerSingletons init);
|
||||||
|
|
||||||
|
void inject(PrivateGroupModule.EagerSingletons init);
|
||||||
|
|
||||||
void inject(PropertiesModule.EagerSingletons init);
|
void inject(PropertiesModule.EagerSingletons init);
|
||||||
|
|
||||||
void inject(SharingModule.EagerSingletons init);
|
void inject(SharingModule.EagerSingletons init);
|
||||||
@@ -80,22 +98,32 @@ interface ForumSharingIntegrationTestComponent {
|
|||||||
|
|
||||||
IdentityManager getIdentityManager();
|
IdentityManager getIdentityManager();
|
||||||
|
|
||||||
|
ClientHelper getClientHelper();
|
||||||
|
|
||||||
ContactManager getContactManager();
|
ContactManager getContactManager();
|
||||||
|
|
||||||
|
SyncSessionFactory getSyncSessionFactory();
|
||||||
|
|
||||||
|
DatabaseComponent getDatabaseComponent();
|
||||||
|
|
||||||
|
BlogManager getBlogManager();
|
||||||
|
|
||||||
|
BlogSharingManager getBlogSharingManager();
|
||||||
|
|
||||||
ForumSharingManager getForumSharingManager();
|
ForumSharingManager getForumSharingManager();
|
||||||
|
|
||||||
ForumManager getForumManager();
|
ForumManager getForumManager();
|
||||||
|
|
||||||
SyncSessionFactory getSyncSessionFactory();
|
IntroductionManager getIntroductionManager();
|
||||||
|
|
||||||
/* the following methods are only needed to manually construct messages */
|
MessageTracker getMessageTracker();
|
||||||
|
|
||||||
DatabaseComponent getDatabaseComponent();
|
MessageSender getMessageSender();
|
||||||
|
|
||||||
ContactGroupFactory getContactGroupFactory();
|
|
||||||
|
|
||||||
ClientHelper getClientHelper();
|
|
||||||
|
|
||||||
MessageQueueManager getMessageQueueManager();
|
MessageQueueManager getMessageQueueManager();
|
||||||
|
|
||||||
|
PrivateGroupManager getPrivateGroupManager();
|
||||||
|
|
||||||
|
TransportPropertyManager getTransportPropertyManager();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,135 +2,49 @@ package org.briarproject;
|
|||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import net.jodah.concurrentunit.Waiter;
|
|
||||||
|
|
||||||
import org.briarproject.api.clients.MessageTracker;
|
|
||||||
import org.briarproject.api.contact.Contact;
|
|
||||||
import org.briarproject.api.contact.ContactId;
|
|
||||||
import org.briarproject.api.contact.ContactManager;
|
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
|
||||||
import org.briarproject.api.db.DbException;
|
|
||||||
import org.briarproject.api.event.Event;
|
|
||||||
import org.briarproject.api.event.EventListener;
|
|
||||||
import org.briarproject.api.event.MessageStateChangedEvent;
|
|
||||||
import org.briarproject.api.forum.Forum;
|
import org.briarproject.api.forum.Forum;
|
||||||
import org.briarproject.api.forum.ForumManager;
|
import org.briarproject.api.forum.ForumManager;
|
||||||
import org.briarproject.api.forum.ForumPost;
|
import org.briarproject.api.forum.ForumPost;
|
||||||
import org.briarproject.api.forum.ForumPostFactory;
|
|
||||||
import org.briarproject.api.forum.ForumPostHeader;
|
import org.briarproject.api.forum.ForumPostHeader;
|
||||||
import org.briarproject.api.forum.ForumSharingManager;
|
import org.briarproject.api.forum.ForumSharingManager;
|
||||||
import org.briarproject.api.identity.AuthorFactory;
|
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.SyncSession;
|
|
||||||
import org.briarproject.api.sync.SyncSessionFactory;
|
|
||||||
import org.briarproject.api.system.Clock;
|
|
||||||
import org.briarproject.contact.ContactModule;
|
|
||||||
import org.briarproject.crypto.CryptoModule;
|
|
||||||
import org.briarproject.forum.ForumModule;
|
|
||||||
import org.briarproject.lifecycle.LifecycleModule;
|
|
||||||
import org.briarproject.properties.PropertiesModule;
|
|
||||||
import org.briarproject.sharing.SharingModule;
|
|
||||||
import org.briarproject.sync.SyncModule;
|
|
||||||
import org.briarproject.transport.TransportModule;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
import static junit.framework.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.assertNull;
|
import static junit.framework.Assert.assertNull;
|
||||||
import static junit.framework.TestCase.assertFalse;
|
import static junit.framework.TestCase.assertFalse;
|
||||||
import static org.briarproject.TestPluginsModule.MAX_LATENCY;
|
import static org.briarproject.TestUtils.assertGroupCount;
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.DELIVERED;
|
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.INVALID;
|
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.PENDING;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class ForumManagerTest extends BriarIntegrationTest {
|
public class ForumManagerTest extends BriarIntegrationTest {
|
||||||
|
|
||||||
private LifecycleManager lifecycleManager0, lifecycleManager1;
|
|
||||||
private SyncSessionFactory sync0, sync1;
|
|
||||||
private ForumManager forumManager0, forumManager1;
|
private ForumManager forumManager0, forumManager1;
|
||||||
private ContactManager contactManager0, contactManager1;
|
private ForumSharingManager forumSharingManager0, forumSharingManager1;
|
||||||
private MessageTracker messageTracker0, messageTracker1;
|
|
||||||
private ContactId contactId0,contactId1;
|
|
||||||
private IdentityManager identityManager0, identityManager1;
|
|
||||||
private LocalAuthor author0, author1;
|
|
||||||
private Forum forum0;
|
private Forum forum0;
|
||||||
|
private GroupId groupId0;
|
||||||
@Inject
|
|
||||||
Clock clock;
|
|
||||||
@Inject
|
|
||||||
AuthorFactory authorFactory;
|
|
||||||
@Inject
|
|
||||||
CryptoComponent crypto;
|
|
||||||
@Inject
|
|
||||||
ForumPostFactory forumPostFactory;
|
|
||||||
|
|
||||||
// objects accessed from background threads need to be volatile
|
|
||||||
private volatile ForumSharingManager forumSharingManager0;
|
|
||||||
private volatile ForumSharingManager forumSharingManager1;
|
|
||||||
private volatile Waiter validationWaiter;
|
|
||||||
private volatile Waiter deliveryWaiter;
|
|
||||||
|
|
||||||
private final File testDir = TestUtils.getTestDirectory();
|
|
||||||
private final SecretKey master = TestUtils.getSecretKey();
|
|
||||||
private final int TIMEOUT = 15000;
|
|
||||||
private final String SHARER = "Sharer";
|
|
||||||
private final String INVITEE = "Invitee";
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
Logger.getLogger(ForumSharingIntegrationTest.class.getName());
|
|
||||||
|
|
||||||
private ForumManagerTestComponent t0, t1;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
ForumManagerTestComponent component =
|
super.setUp();
|
||||||
DaggerForumManagerTestComponent.builder().build();
|
|
||||||
component.inject(this);
|
|
||||||
injectEagerSingletons(component);
|
|
||||||
|
|
||||||
assertTrue(testDir.mkdirs());
|
forumManager0 = c0.getForumManager();
|
||||||
File t0Dir = new File(testDir, SHARER);
|
forumManager1 = c1.getForumManager();
|
||||||
t0 = DaggerForumManagerTestComponent.builder()
|
forumSharingManager0 = c0.getForumSharingManager();
|
||||||
.testDatabaseModule(new TestDatabaseModule(t0Dir)).build();
|
forumSharingManager1 = c1.getForumSharingManager();
|
||||||
injectEagerSingletons(t0);
|
|
||||||
File t1Dir = new File(testDir, INVITEE);
|
|
||||||
t1 = DaggerForumManagerTestComponent.builder()
|
|
||||||
.testDatabaseModule(new TestDatabaseModule(t1Dir)).build();
|
|
||||||
injectEagerSingletons(t1);
|
|
||||||
|
|
||||||
identityManager0 = t0.getIdentityManager();
|
|
||||||
identityManager1 = t1.getIdentityManager();
|
|
||||||
contactManager0 = t0.getContactManager();
|
|
||||||
contactManager1 = t1.getContactManager();
|
|
||||||
messageTracker0 = t0.getMessageTracker();
|
|
||||||
messageTracker1 = t1.getMessageTracker();
|
|
||||||
forumManager0 = t0.getForumManager();
|
|
||||||
forumManager1 = t1.getForumManager();
|
|
||||||
forumSharingManager0 = t0.getForumSharingManager();
|
|
||||||
forumSharingManager1 = t1.getForumSharingManager();
|
|
||||||
sync0 = t0.getSyncSessionFactory();
|
|
||||||
sync1 = t1.getSyncSessionFactory();
|
|
||||||
|
|
||||||
// initialize waiters fresh for each test
|
forum0 = forumManager0.addForum("Test Forum");
|
||||||
validationWaiter = new Waiter();
|
groupId0 = forum0.getId();
|
||||||
deliveryWaiter = new Waiter();
|
// share forum
|
||||||
|
forumSharingManager0.sendInvitation(groupId0, contactId1From0, null);
|
||||||
|
sync0To1(1, true);
|
||||||
|
forumSharingManager1.respondToInvitation(forum0, contact0From1, true);
|
||||||
|
sync1To0(1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ForumPost createForumPost(GroupId groupId,
|
private ForumPost createForumPost(GroupId groupId,
|
||||||
@@ -142,36 +56,33 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForumPost() throws Exception {
|
public void testForumPost() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
getDefaultIdentities();
|
|
||||||
Forum forum = forumManager0.addForum("TestForum");
|
|
||||||
assertEquals(1, forumManager0.getForums().size());
|
assertEquals(1, forumManager0.getForums().size());
|
||||||
final long ms1 = clock.currentTimeMillis() - 1000L;
|
final long ms1 = clock.currentTimeMillis() - 1000L;
|
||||||
final String body1 = "some forum text";
|
final String body1 = "some forum text";
|
||||||
final long ms2 = clock.currentTimeMillis();
|
final long ms2 = clock.currentTimeMillis();
|
||||||
final String body2 = "some other forum text";
|
final String body2 = "some other forum text";
|
||||||
ForumPost post1 =
|
ForumPost post1 =
|
||||||
createForumPost(forum.getGroup().getId(), null, body1, ms1);
|
createForumPost(forum0.getGroup().getId(), null, body1, ms1);
|
||||||
assertEquals(ms1, post1.getMessage().getTimestamp());
|
assertEquals(ms1, post1.getMessage().getTimestamp());
|
||||||
ForumPost post2 =
|
ForumPost post2 =
|
||||||
createForumPost(forum.getGroup().getId(), post1, body2, ms2);
|
createForumPost(forum0.getGroup().getId(), post1, body2, ms2);
|
||||||
assertEquals(ms2, post2.getMessage().getTimestamp());
|
assertEquals(ms2, post2.getMessage().getTimestamp());
|
||||||
forumManager0.addLocalPost(post1);
|
forumManager0.addLocalPost(post1);
|
||||||
forumManager0.setReadFlag(forum.getGroup().getId(),
|
forumManager0.setReadFlag(forum0.getGroup().getId(),
|
||||||
post1.getMessage().getId(), true);
|
post1.getMessage().getId(), true);
|
||||||
assertGroupCount(messageTracker0, forum.getGroup().getId(), 1, 0,
|
assertGroupCount(messageTracker0, forum0.getGroup().getId(), 1, 0,
|
||||||
post1.getMessage().getTimestamp());
|
post1.getMessage().getTimestamp());
|
||||||
forumManager0.addLocalPost(post2);
|
forumManager0.addLocalPost(post2);
|
||||||
forumManager0.setReadFlag(forum.getGroup().getId(),
|
forumManager0.setReadFlag(forum0.getGroup().getId(),
|
||||||
post2.getMessage().getId(), false);
|
post2.getMessage().getId(), false);
|
||||||
assertGroupCount(messageTracker0, forum.getGroup().getId(), 2, 1,
|
assertGroupCount(messageTracker0, forum0.getGroup().getId(), 2, 1,
|
||||||
post2.getMessage().getTimestamp());
|
post2.getMessage().getTimestamp());
|
||||||
forumManager0.setReadFlag(forum.getGroup().getId(),
|
forumManager0.setReadFlag(forum0.getGroup().getId(),
|
||||||
post2.getMessage().getId(), false);
|
post2.getMessage().getId(), false);
|
||||||
assertGroupCount(messageTracker0, forum.getGroup().getId(), 2, 1,
|
assertGroupCount(messageTracker0, forum0.getGroup().getId(), 2, 1,
|
||||||
post2.getMessage().getTimestamp());
|
post2.getMessage().getTimestamp());
|
||||||
Collection<ForumPostHeader> headers =
|
Collection<ForumPostHeader> headers =
|
||||||
forumManager0.getPostHeaders(forum.getGroup().getId());
|
forumManager0.getPostHeaders(forum0.getGroup().getId());
|
||||||
assertEquals(2, headers.size());
|
assertEquals(2, headers.size());
|
||||||
for (ForumPostHeader h : headers) {
|
for (ForumPostHeader h : headers) {
|
||||||
final String hBody = forumManager0.getPostBody(h.getId());
|
final String hBody = forumManager0.getPostBody(h.getId());
|
||||||
@@ -184,146 +95,94 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
|||||||
assertEquals(body1, hBody);
|
assertEquals(body1, hBody);
|
||||||
assertNull(h.getParentId());
|
assertNull(h.getParentId());
|
||||||
assertTrue(h.isRead());
|
assertTrue(h.isRead());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
assertEquals(h.getTimestamp(), ms2);
|
assertEquals(h.getTimestamp(), ms2);
|
||||||
assertEquals(body2, hBody);
|
assertEquals(body2, hBody);
|
||||||
assertEquals(h.getParentId(), post2.getParent());
|
assertEquals(h.getParentId(), post2.getParent());
|
||||||
assertFalse(h.isRead());
|
assertFalse(h.isRead());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
forumManager0.removeForum(forum);
|
forumManager0.removeForum(forum0);
|
||||||
assertEquals(0, forumManager0.getForums().size());
|
assertEquals(0, forumManager0.getForums().size());
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForumPostDelivery() throws Exception {
|
public void testForumPostDelivery() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
defaultInit();
|
|
||||||
|
|
||||||
// share forum
|
|
||||||
GroupId g = forum0.getId();
|
|
||||||
forumSharingManager0.sendInvitation(g, contactId1, null);
|
|
||||||
sync0To1();
|
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
Contact c0 = contactManager1.getContact(contactId0);
|
|
||||||
forumSharingManager1.respondToInvitation(forum0, c0, true);
|
|
||||||
sync1To0();
|
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// add one forum post
|
// add one forum post
|
||||||
long time = clock.currentTimeMillis();
|
long time = clock.currentTimeMillis();
|
||||||
ForumPost post1 = createForumPost(g, null, "a", time);
|
ForumPost post1 = createForumPost(groupId0, null, "a", time);
|
||||||
forumManager0.addLocalPost(post1);
|
forumManager0.addLocalPost(post1);
|
||||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||||
assertGroupCount(messageTracker0, g, 1, 0, time);
|
assertGroupCount(messageTracker0, groupId0, 1, 0, time);
|
||||||
assertGroupCount(messageTracker1, g, 0, 0, 0);
|
assertGroupCount(messageTracker1, groupId0, 0, 0, 0);
|
||||||
|
|
||||||
// send post to 1
|
// send post to 1
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
assertEquals(1, forumManager1.getPostHeaders(groupId0).size());
|
||||||
assertEquals(1, forumManager1.getPostHeaders(g).size());
|
assertGroupCount(messageTracker1, groupId0, 1, 1, time);
|
||||||
assertGroupCount(messageTracker1, g, 1, 1, time);
|
|
||||||
|
|
||||||
// add another forum post
|
// add another forum post
|
||||||
long time2 = clock.currentTimeMillis();
|
long time2 = clock.currentTimeMillis();
|
||||||
ForumPost post2 = createForumPost(g, null, "b", time2);
|
ForumPost post2 = createForumPost(groupId0, null, "b", time2);
|
||||||
forumManager1.addLocalPost(post2);
|
forumManager1.addLocalPost(post2);
|
||||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||||
assertEquals(2, forumManager1.getPostHeaders(g).size());
|
assertEquals(2, forumManager1.getPostHeaders(groupId0).size());
|
||||||
assertGroupCount(messageTracker0, g, 1, 0, time);
|
assertGroupCount(messageTracker0, groupId0, 1, 0, time);
|
||||||
assertGroupCount(messageTracker1, g, 2, 1, time2);
|
assertGroupCount(messageTracker1, groupId0, 2, 1, time2);
|
||||||
|
|
||||||
// send post to 0
|
// send post to 0
|
||||||
sync1To0();
|
sync1To0(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
assertEquals(2, forumManager1.getPostHeaders(groupId0).size());
|
||||||
assertEquals(2, forumManager1.getPostHeaders(g).size());
|
assertGroupCount(messageTracker0, groupId0, 2, 1, time2);
|
||||||
assertGroupCount(messageTracker0, g, 2, 1, time2);
|
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForumPostDeliveredAfterParent() throws Exception {
|
public void testForumPostDeliveredAfterParent() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
defaultInit();
|
|
||||||
|
|
||||||
// share forum
|
|
||||||
GroupId g = forum0.getId();
|
|
||||||
forumSharingManager0.sendInvitation(g, contactId1, null);
|
|
||||||
sync0To1();
|
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
Contact c0 = contactManager1.getContact(contactId0);
|
|
||||||
forumSharingManager1.respondToInvitation(forum0, c0, true);
|
|
||||||
sync1To0();
|
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// add one forum post without the parent
|
// add one forum post without the parent
|
||||||
long time = clock.currentTimeMillis();
|
long time = clock.currentTimeMillis();
|
||||||
ForumPost post1 = createForumPost(g, null, "a", time);
|
ForumPost post1 = createForumPost(groupId0, null, "a", time);
|
||||||
ForumPost post2 = createForumPost(g, post1, "a", time);
|
ForumPost post2 = createForumPost(groupId0, post1, "a", time);
|
||||||
forumManager0.addLocalPost(post2);
|
forumManager0.addLocalPost(post2);
|
||||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||||
|
|
||||||
// send post to 1 without waiting for message delivery
|
// send post to 1 without waiting for message delivery
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
|
||||||
|
|
||||||
// now add the parent post as well
|
// now add the parent post as well
|
||||||
forumManager0.addLocalPost(post1);
|
forumManager0.addLocalPost(post1);
|
||||||
assertEquals(2, forumManager0.getPostHeaders(g).size());
|
assertEquals(2, forumManager0.getPostHeaders(groupId0).size());
|
||||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||||
|
|
||||||
// and send it over to 1 and wait for a second message to be delivered
|
// and send it over to 1 and wait for a second message to be delivered
|
||||||
sync0To1();
|
sync0To1(2, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 2);
|
assertEquals(2, forumManager1.getPostHeaders(groupId0).size());
|
||||||
assertEquals(2, forumManager1.getPostHeaders(g).size());
|
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForumPostWithParentInOtherGroup() throws Exception {
|
public void testForumPostWithParentInOtherGroup() throws Exception {
|
||||||
startLifecycles();
|
|
||||||
defaultInit();
|
|
||||||
|
|
||||||
// share forum
|
|
||||||
GroupId g = forum0.getId();
|
|
||||||
forumSharingManager0.sendInvitation(g, contactId1, null);
|
|
||||||
sync0To1();
|
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
Contact c0 = contactManager1.getContact(contactId0);
|
|
||||||
forumSharingManager1.respondToInvitation(forum0, c0, true);
|
|
||||||
sync1To0();
|
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// share a second forum
|
// share a second forum
|
||||||
Forum forum1 = forumManager0.addForum("Test Forum1");
|
Forum forum1 = forumManager0.addForum("Test Forum1");
|
||||||
GroupId g1 = forum1.getId();
|
GroupId g1 = forum1.getId();
|
||||||
forumSharingManager0.sendInvitation(g1, contactId1, null);
|
forumSharingManager0.sendInvitation(g1, contactId1From0, null);
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
forumSharingManager1.respondToInvitation(forum1, contact0From1, true);
|
||||||
forumSharingManager1.respondToInvitation(forum1, c0, true);
|
sync1To0(1, true);
|
||||||
sync1To0();
|
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// add one forum post with a parent in another forum
|
// add one forum post with a parent in another forum
|
||||||
long time = clock.currentTimeMillis();
|
long time = clock.currentTimeMillis();
|
||||||
ForumPost post1 = createForumPost(g1, null, "a", time);
|
ForumPost post1 = createForumPost(g1, null, "a", time);
|
||||||
ForumPost post = createForumPost(g, post1, "b", time);
|
ForumPost post = createForumPost(groupId0, post1, "b", time);
|
||||||
forumManager0.addLocalPost(post);
|
forumManager0.addLocalPost(post);
|
||||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||||
|
|
||||||
// send the child post to 1
|
// send the child post to 1
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
|
||||||
|
|
||||||
// now also add the parent post which is in another group
|
// now also add the parent post which is in another group
|
||||||
forumManager0.addLocalPost(post1);
|
forumManager0.addLocalPost(post1);
|
||||||
@@ -331,132 +190,12 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
|||||||
assertEquals(0, forumManager1.getPostHeaders(g1).size());
|
assertEquals(0, forumManager1.getPostHeaders(g1).size());
|
||||||
|
|
||||||
// send posts to 1
|
// send posts to 1
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
|
||||||
assertEquals(1, forumManager0.getPostHeaders(g1).size());
|
assertEquals(1, forumManager0.getPostHeaders(g1).size());
|
||||||
// the next line is critical, makes sure post doesn't show up
|
// the next line is critical, makes sure post doesn't show up
|
||||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||||
assertEquals(1, forumManager1.getPostHeaders(g1).size());
|
assertEquals(1, forumManager1.getPostHeaders(g1).size());
|
||||||
|
|
||||||
stopLifecycles();
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
TestUtils.deleteTestDirectory(testDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements EventListener {
|
|
||||||
@Override
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (e instanceof MessageStateChangedEvent) {
|
|
||||||
MessageStateChangedEvent event = (MessageStateChangedEvent) e;
|
|
||||||
if (!event.isLocal()) {
|
|
||||||
if (event.getState() == DELIVERED) {
|
|
||||||
deliveryWaiter.resume();
|
|
||||||
} else if (event.getState() == INVALID ||
|
|
||||||
event.getState() == PENDING) {
|
|
||||||
validationWaiter.resume();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void defaultInit() throws DbException {
|
|
||||||
getDefaultIdentities();
|
|
||||||
addDefaultContacts();
|
|
||||||
addForum();
|
|
||||||
listenToEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getDefaultIdentities() throws DbException {
|
|
||||||
author0 = identityManager0.getLocalAuthor();
|
|
||||||
author1 = identityManager1.getLocalAuthor();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addDefaultContacts() throws DbException {
|
|
||||||
// sharer adds invitee as contact
|
|
||||||
contactId1 = contactManager0.addContact(author1,
|
|
||||||
author0.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
// invitee adds sharer back
|
|
||||||
contactId0 = contactManager1.addContact(author0,
|
|
||||||
author1.getId(), master, clock.currentTimeMillis(), true,
|
|
||||||
true, true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addForum() throws DbException {
|
|
||||||
forum0 = forumManager0.addForum("Test Forum");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void listenToEvents() {
|
|
||||||
Listener listener0 = new Listener();
|
|
||||||
t0.getEventBus().addListener(listener0);
|
|
||||||
Listener listener1 = new Listener();
|
|
||||||
t1.getEventBus().addListener(listener1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sync0To1() throws IOException, TimeoutException {
|
|
||||||
deliverMessage(sync0, contactId0, sync1, contactId1, "0 to 1");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sync1To0() throws IOException, TimeoutException {
|
|
||||||
deliverMessage(sync1, contactId1, sync0, contactId0, "1 to 0");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deliverMessage(SyncSessionFactory fromSync, ContactId fromId,
|
|
||||||
SyncSessionFactory toSync, ContactId toId, String debug)
|
|
||||||
throws IOException, TimeoutException {
|
|
||||||
|
|
||||||
if (debug != null) LOG.info("TEST: Sending message from " + debug);
|
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
// Create an outgoing sync session
|
|
||||||
SyncSession sessionFrom =
|
|
||||||
fromSync.createSimplexOutgoingSession(toId, MAX_LATENCY, out);
|
|
||||||
// Write whatever needs to be written
|
|
||||||
sessionFrom.run();
|
|
||||||
out.close();
|
|
||||||
|
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
||||||
// Create an incoming sync session
|
|
||||||
SyncSession sessionTo = toSync.createIncomingSession(fromId, in);
|
|
||||||
// Read whatever needs to be read
|
|
||||||
sessionTo.run();
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startLifecycles() throws InterruptedException {
|
|
||||||
// Start the lifecycle manager and wait for it to finish
|
|
||||||
lifecycleManager0 = t0.getLifecycleManager();
|
|
||||||
lifecycleManager1 = t1.getLifecycleManager();
|
|
||||||
lifecycleManager0.startServices(SHARER);
|
|
||||||
lifecycleManager1.startServices(INVITEE);
|
|
||||||
lifecycleManager0.waitForStartup();
|
|
||||||
lifecycleManager1.waitForStartup();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopLifecycles() throws InterruptedException {
|
|
||||||
// Clean up
|
|
||||||
lifecycleManager0.stopServices();
|
|
||||||
lifecycleManager1.stopServices();
|
|
||||||
lifecycleManager0.waitForShutdown();
|
|
||||||
lifecycleManager1.waitForShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void injectEagerSingletons(ForumManagerTestComponent component) {
|
|
||||||
component.inject(new LifecycleModule.EagerSingletons());
|
|
||||||
component.inject(new ForumModule.EagerSingletons());
|
|
||||||
component.inject(new CryptoModule.EagerSingletons());
|
|
||||||
component.inject(new ContactModule.EagerSingletons());
|
|
||||||
component.inject(new TransportModule.EagerSingletons());
|
|
||||||
component.inject(new SharingModule.EagerSingletons());
|
|
||||||
component.inject(new SyncModule.EagerSingletons());
|
|
||||||
component.inject(new PropertiesModule.EagerSingletons());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
package org.briarproject;
|
|
||||||
|
|
||||||
import org.briarproject.api.clients.MessageTracker;
|
|
||||||
import org.briarproject.api.contact.ContactManager;
|
|
||||||
import org.briarproject.api.event.EventBus;
|
|
||||||
import org.briarproject.api.forum.ForumManager;
|
|
||||||
import org.briarproject.api.forum.ForumSharingManager;
|
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.api.sync.SyncSessionFactory;
|
|
||||||
import org.briarproject.blogs.BlogsModule;
|
|
||||||
import org.briarproject.clients.ClientsModule;
|
|
||||||
import org.briarproject.contact.ContactModule;
|
|
||||||
import org.briarproject.crypto.CryptoModule;
|
|
||||||
import org.briarproject.data.DataModule;
|
|
||||||
import org.briarproject.db.DatabaseModule;
|
|
||||||
import org.briarproject.event.EventModule;
|
|
||||||
import org.briarproject.forum.ForumModule;
|
|
||||||
import org.briarproject.identity.IdentityModule;
|
|
||||||
import org.briarproject.lifecycle.LifecycleModule;
|
|
||||||
import org.briarproject.messaging.MessagingModule;
|
|
||||||
import org.briarproject.properties.PropertiesModule;
|
|
||||||
import org.briarproject.sharing.SharingModule;
|
|
||||||
import org.briarproject.sync.SyncModule;
|
|
||||||
import org.briarproject.system.SystemModule;
|
|
||||||
import org.briarproject.transport.TransportModule;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Component;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Component(modules = {
|
|
||||||
TestDatabaseModule.class,
|
|
||||||
TestPluginsModule.class,
|
|
||||||
TestSeedProviderModule.class,
|
|
||||||
ClientsModule.class,
|
|
||||||
ContactModule.class,
|
|
||||||
CryptoModule.class,
|
|
||||||
DataModule.class,
|
|
||||||
DatabaseModule.class,
|
|
||||||
EventModule.class,
|
|
||||||
ForumModule.class,
|
|
||||||
BlogsModule.class,
|
|
||||||
IdentityModule.class,
|
|
||||||
LifecycleModule.class,
|
|
||||||
PropertiesModule.class,
|
|
||||||
SharingModule.class,
|
|
||||||
SyncModule.class,
|
|
||||||
SystemModule.class,
|
|
||||||
TransportModule.class,
|
|
||||||
MessagingModule.class
|
|
||||||
})
|
|
||||||
interface ForumManagerTestComponent {
|
|
||||||
|
|
||||||
void inject(ForumManagerTest testCase);
|
|
||||||
|
|
||||||
void inject(ContactModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(CryptoModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(ForumModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(LifecycleModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(PropertiesModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(SharingModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(SyncModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(TransportModule.EagerSingletons init);
|
|
||||||
|
|
||||||
LifecycleManager getLifecycleManager();
|
|
||||||
|
|
||||||
EventBus getEventBus();
|
|
||||||
|
|
||||||
IdentityManager getIdentityManager();
|
|
||||||
|
|
||||||
ContactManager getContactManager();
|
|
||||||
|
|
||||||
MessageTracker getMessageTracker();
|
|
||||||
|
|
||||||
ForumSharingManager getForumSharingManager();
|
|
||||||
|
|
||||||
ForumManager getForumManager();
|
|
||||||
|
|
||||||
SyncSessionFactory getSyncSessionFactory();
|
|
||||||
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,65 +1,22 @@
|
|||||||
package org.briarproject;
|
package org.briarproject;
|
||||||
|
|
||||||
import net.jodah.concurrentunit.Waiter;
|
|
||||||
|
|
||||||
import org.briarproject.api.clients.ClientHelper;
|
|
||||||
import org.briarproject.api.clients.ContactGroupFactory;
|
|
||||||
import org.briarproject.api.clients.MessageTracker.GroupCount;
|
import org.briarproject.api.clients.MessageTracker.GroupCount;
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.api.contact.Contact;
|
||||||
import org.briarproject.api.contact.ContactId;
|
|
||||||
import org.briarproject.api.contact.ContactManager;
|
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
|
||||||
import org.briarproject.api.crypto.KeyPair;
|
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
|
||||||
import org.briarproject.api.data.BdfList;
|
import org.briarproject.api.data.BdfList;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.api.db.DbException;
|
|
||||||
import org.briarproject.api.db.Transaction;
|
import org.briarproject.api.db.Transaction;
|
||||||
import org.briarproject.api.event.Event;
|
|
||||||
import org.briarproject.api.event.EventListener;
|
|
||||||
import org.briarproject.api.event.MessageStateChangedEvent;
|
|
||||||
import org.briarproject.api.identity.AuthorFactory;
|
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.api.privategroup.GroupMember;
|
import org.briarproject.api.privategroup.GroupMember;
|
||||||
import org.briarproject.api.privategroup.GroupMessage;
|
import org.briarproject.api.privategroup.GroupMessage;
|
||||||
import org.briarproject.api.privategroup.GroupMessageFactory;
|
|
||||||
import org.briarproject.api.privategroup.GroupMessageHeader;
|
import org.briarproject.api.privategroup.GroupMessageHeader;
|
||||||
import org.briarproject.api.privategroup.JoinMessageHeader;
|
import org.briarproject.api.privategroup.JoinMessageHeader;
|
||||||
import org.briarproject.api.privategroup.PrivateGroup;
|
import org.briarproject.api.privategroup.PrivateGroup;
|
||||||
import org.briarproject.api.privategroup.PrivateGroupFactory;
|
|
||||||
import org.briarproject.api.privategroup.PrivateGroupManager;
|
import org.briarproject.api.privategroup.PrivateGroupManager;
|
||||||
import org.briarproject.api.privategroup.invitation.GroupInvitationFactory;
|
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.api.sync.MessageId;
|
||||||
import org.briarproject.api.sync.SyncSession;
|
|
||||||
import org.briarproject.api.sync.SyncSessionFactory;
|
|
||||||
import org.briarproject.api.system.Clock;
|
|
||||||
import org.briarproject.contact.ContactModule;
|
|
||||||
import org.briarproject.crypto.CryptoModule;
|
|
||||||
import org.briarproject.lifecycle.LifecycleModule;
|
|
||||||
import org.briarproject.privategroup.PrivateGroupModule;
|
|
||||||
import org.briarproject.properties.PropertiesModule;
|
|
||||||
import org.briarproject.sync.SyncModule;
|
|
||||||
import org.briarproject.transport.TransportModule;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static org.briarproject.TestPluginsModule.MAX_LATENCY;
|
|
||||||
import static org.briarproject.TestUtils.getRandomBytes;
|
import static org.briarproject.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.api.identity.Author.Status.VERIFIED;
|
import static org.briarproject.api.identity.Author.Status.VERIFIED;
|
||||||
import static org.briarproject.api.privategroup.Visibility.INVISIBLE;
|
import static org.briarproject.api.privategroup.Visibility.INVISIBLE;
|
||||||
@@ -68,110 +25,32 @@ import static org.briarproject.api.privategroup.Visibility.REVEALED_BY_US;
|
|||||||
import static org.briarproject.api.privategroup.Visibility.VISIBLE;
|
import static org.briarproject.api.privategroup.Visibility.VISIBLE;
|
||||||
import static org.briarproject.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
|
import static org.briarproject.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
|
||||||
import static org.briarproject.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.api.sync.Group.Visibility.SHARED;
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.DELIVERED;
|
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.INVALID;
|
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.PENDING;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||||
|
|
||||||
private LifecycleManager lifecycleManager0, lifecycleManager1,
|
|
||||||
lifecycleManager2;
|
|
||||||
private SyncSessionFactory sync0, sync1, sync2;
|
|
||||||
private PrivateGroupManager groupManager0, groupManager1, groupManager2;
|
|
||||||
private ContactManager contactManager0, contactManager1, contactManager2;
|
|
||||||
private ContactId contactId01, contactId02, contactId1, contactId2;
|
|
||||||
private IdentityManager identityManager0, identityManager1,
|
|
||||||
identityManager2;
|
|
||||||
private LocalAuthor author0, author1, author2;
|
|
||||||
private DatabaseComponent db0, db1, db2;
|
|
||||||
private PrivateGroup privateGroup0;
|
private PrivateGroup privateGroup0;
|
||||||
private GroupId groupId0;
|
private GroupId groupId0;
|
||||||
|
private PrivateGroupManager groupManager0, groupManager1, groupManager2;
|
||||||
@Inject
|
|
||||||
Clock clock;
|
|
||||||
@Inject
|
|
||||||
AuthorFactory authorFactory;
|
|
||||||
@Inject
|
|
||||||
ClientHelper clientHelper;
|
|
||||||
@Inject
|
|
||||||
CryptoComponent crypto;
|
|
||||||
@Inject
|
|
||||||
ContactGroupFactory contactGroupFactory;
|
|
||||||
@Inject
|
|
||||||
PrivateGroupFactory privateGroupFactory;
|
|
||||||
@Inject
|
|
||||||
GroupMessageFactory groupMessageFactory;
|
|
||||||
@Inject
|
|
||||||
GroupInvitationFactory groupInvitationFactory;
|
|
||||||
|
|
||||||
// objects accessed from background threads need to be volatile
|
|
||||||
private volatile Waiter validationWaiter;
|
|
||||||
private volatile Waiter deliveryWaiter;
|
|
||||||
|
|
||||||
private final File testDir = TestUtils.getTestDirectory();
|
|
||||||
private final SecretKey master = TestUtils.getSecretKey();
|
|
||||||
private final int TIMEOUT = 15000;
|
|
||||||
private final String AUTHOR0 = "Author 0";
|
|
||||||
private final String AUTHOR1 = "Author 1";
|
|
||||||
private final String AUTHOR2 = "Author 2";
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
Logger.getLogger(PrivateGroupManagerTest.class.getName());
|
|
||||||
|
|
||||||
private PrivateGroupManagerTestComponent t0, t1, t2;
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
PrivateGroupManagerTestComponent component =
|
super.setUp();
|
||||||
DaggerPrivateGroupManagerTestComponent.builder().build();
|
|
||||||
component.inject(this);
|
|
||||||
|
|
||||||
assertTrue(testDir.mkdirs());
|
groupManager0 = c0.getPrivateGroupManager();
|
||||||
File t0Dir = new File(testDir, AUTHOR0);
|
groupManager1 = c1.getPrivateGroupManager();
|
||||||
t0 = DaggerPrivateGroupManagerTestComponent.builder()
|
groupManager2 = c2.getPrivateGroupManager();
|
||||||
.testDatabaseModule(new TestDatabaseModule(t0Dir)).build();
|
|
||||||
injectEagerSingletons(t0);
|
|
||||||
File t1Dir = new File(testDir, AUTHOR1);
|
|
||||||
t1 = DaggerPrivateGroupManagerTestComponent.builder()
|
|
||||||
.testDatabaseModule(new TestDatabaseModule(t1Dir)).build();
|
|
||||||
injectEagerSingletons(t1);
|
|
||||||
File t2Dir = new File(testDir, AUTHOR2);
|
|
||||||
t2 = DaggerPrivateGroupManagerTestComponent.builder()
|
|
||||||
.testDatabaseModule(new TestDatabaseModule(t2Dir)).build();
|
|
||||||
injectEagerSingletons(t2);
|
|
||||||
|
|
||||||
identityManager0 = t0.getIdentityManager();
|
privateGroup0 =
|
||||||
identityManager1 = t1.getIdentityManager();
|
privateGroupFactory.createPrivateGroup("Testgroup", author0);
|
||||||
identityManager2 = t2.getIdentityManager();
|
groupId0 = privateGroup0.getId();
|
||||||
contactManager0 = t0.getContactManager();
|
|
||||||
contactManager1 = t1.getContactManager();
|
|
||||||
contactManager2 = t2.getContactManager();
|
|
||||||
db0 = t0.getDatabaseComponent();
|
|
||||||
db1 = t1.getDatabaseComponent();
|
|
||||||
db2 = t2.getDatabaseComponent();
|
|
||||||
groupManager0 = t0.getPrivateGroupManager();
|
|
||||||
groupManager1 = t1.getPrivateGroupManager();
|
|
||||||
groupManager2 = t2.getPrivateGroupManager();
|
|
||||||
sync0 = t0.getSyncSessionFactory();
|
|
||||||
sync1 = t1.getSyncSessionFactory();
|
|
||||||
sync2 = t2.getSyncSessionFactory();
|
|
||||||
|
|
||||||
// initialize waiters fresh for each test
|
|
||||||
validationWaiter = new Waiter();
|
|
||||||
deliveryWaiter = new Waiter();
|
|
||||||
|
|
||||||
startLifecycles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendingMessage() throws Exception {
|
public void testSendingMessage() throws Exception {
|
||||||
defaultInit();
|
addGroup();
|
||||||
|
|
||||||
// create and add test message
|
// create and add test message
|
||||||
long time = clock.currentTimeMillis();
|
long time = clock.currentTimeMillis();
|
||||||
@@ -186,8 +65,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
groupManager0.getPreviousMsgId(groupId0));
|
groupManager0.getPreviousMsgId(groupId0));
|
||||||
|
|
||||||
// sync test message
|
// sync test message
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that message arrived as expected
|
// assert that message arrived as expected
|
||||||
Collection<GroupMessageHeader> headers =
|
Collection<GroupMessageHeader> headers =
|
||||||
@@ -213,7 +91,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMessageWithWrongPreviousMsgId() throws Exception {
|
public void testMessageWithWrongPreviousMsgId() throws Exception {
|
||||||
defaultInit();
|
addGroup();
|
||||||
|
|
||||||
// create and add test message with no previousMsgId
|
// create and add test message with no previousMsgId
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
@@ -223,8 +101,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
groupManager0.addLocalMessage(msg);
|
groupManager0.addLocalMessage(msg);
|
||||||
|
|
||||||
// sync test message
|
// sync test message
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that message did not arrive
|
// assert that message did not arrive
|
||||||
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
||||||
@@ -237,8 +114,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
groupManager0.addLocalMessage(msg);
|
groupManager0.addLocalMessage(msg);
|
||||||
|
|
||||||
// sync test message
|
// sync test message
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that message did not arrive
|
// assert that message did not arrive
|
||||||
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
||||||
@@ -251,8 +127,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
groupManager0.addLocalMessage(msg);
|
groupManager0.addLocalMessage(msg);
|
||||||
|
|
||||||
// sync test message
|
// sync test message
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that message did not arrive
|
// assert that message did not arrive
|
||||||
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
||||||
@@ -260,7 +135,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMessageWithWrongParentMsgId() throws Exception {
|
public void testMessageWithWrongParentMsgId() throws Exception {
|
||||||
defaultInit();
|
addGroup();
|
||||||
|
|
||||||
// create and add test message with random parentMsgId
|
// create and add test message with random parentMsgId
|
||||||
MessageId parentMsgId = new MessageId(TestUtils.getRandomId());
|
MessageId parentMsgId = new MessageId(TestUtils.getRandomId());
|
||||||
@@ -271,8 +146,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
groupManager0.addLocalMessage(msg);
|
groupManager0.addLocalMessage(msg);
|
||||||
|
|
||||||
// sync test message
|
// sync test message
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that message did not arrive
|
// assert that message did not arrive
|
||||||
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
||||||
@@ -285,8 +159,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
groupManager0.addLocalMessage(msg);
|
groupManager0.addLocalMessage(msg);
|
||||||
|
|
||||||
// sync test message
|
// sync test message
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that message did not arrive
|
// assert that message did not arrive
|
||||||
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
||||||
@@ -294,7 +167,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMessageWithWrongTimestamp() throws Exception {
|
public void testMessageWithWrongTimestamp() throws Exception {
|
||||||
defaultInit();
|
addGroup();
|
||||||
|
|
||||||
// create and add test message with wrong timestamp
|
// create and add test message with wrong timestamp
|
||||||
MessageId previousMsgId = groupManager0.getPreviousMsgId(groupId0);
|
MessageId previousMsgId = groupManager0.getPreviousMsgId(groupId0);
|
||||||
@@ -304,8 +177,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
groupManager0.addLocalMessage(msg);
|
groupManager0.addLocalMessage(msg);
|
||||||
|
|
||||||
// sync test message
|
// sync test message
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that message did not arrive
|
// assert that message did not arrive
|
||||||
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
||||||
@@ -318,8 +190,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
groupManager0.addLocalMessage(msg);
|
groupManager0.addLocalMessage(msg);
|
||||||
|
|
||||||
// sync test message
|
// sync test message
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
assertEquals(3, groupManager1.getHeaders(groupId0).size());
|
assertEquals(3, groupManager1.getHeaders(groupId0).size());
|
||||||
|
|
||||||
// create and add test message with same timestamp as previous message
|
// create and add test message with same timestamp as previous message
|
||||||
@@ -330,8 +201,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
groupManager0.addLocalMessage(msg);
|
groupManager0.addLocalMessage(msg);
|
||||||
|
|
||||||
// sync test message
|
// sync test message
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that message did not arrive
|
// assert that message did not arrive
|
||||||
assertEquals(3, groupManager1.getHeaders(groupId0).size());
|
assertEquals(3, groupManager1.getHeaders(groupId0).size());
|
||||||
@@ -339,10 +209,6 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrongJoinMessages1() throws Exception {
|
public void testWrongJoinMessages1() throws Exception {
|
||||||
addDefaultIdentities();
|
|
||||||
addDefaultContacts();
|
|
||||||
listenToEvents();
|
|
||||||
|
|
||||||
// author0 joins privateGroup0 with wrong join message
|
// author0 joins privateGroup0 with wrong join message
|
||||||
long joinTime = clock.currentTimeMillis();
|
long joinTime = clock.currentTimeMillis();
|
||||||
GroupMessage joinMsg0 = groupMessageFactory
|
GroupMessage joinMsg0 = groupMessageFactory
|
||||||
@@ -354,14 +220,14 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
// share the group with 1
|
// share the group with 1
|
||||||
Transaction txn0 = db0.startTransaction(false);
|
Transaction txn0 = db0.startTransaction(false);
|
||||||
db0.setGroupVisibility(txn0, contactId1, privateGroup0.getId(), SHARED);
|
db0.setGroupVisibility(txn0, contactId1From0, privateGroup0.getId(), SHARED);
|
||||||
db0.commitTransaction(txn0);
|
db0.commitTransaction(txn0);
|
||||||
db0.endTransaction(txn0);
|
db0.endTransaction(txn0);
|
||||||
|
|
||||||
// author1 joins privateGroup0 with wrong timestamp
|
// author1 joins privateGroup0 with wrong timestamp
|
||||||
joinTime = clock.currentTimeMillis();
|
joinTime = clock.currentTimeMillis();
|
||||||
long inviteTime = joinTime;
|
long inviteTime = joinTime;
|
||||||
Contact c1 = contactManager0.getContact(contactId1);
|
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||||
byte[] creatorSignature = groupInvitationFactory
|
byte[] creatorSignature = groupInvitationFactory
|
||||||
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
||||||
author0.getPrivateKey());
|
author0.getPrivateKey());
|
||||||
@@ -374,20 +240,18 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
// share the group with 0
|
// share the group with 0
|
||||||
Transaction txn1 = db1.startTransaction(false);
|
Transaction txn1 = db1.startTransaction(false);
|
||||||
db1.setGroupVisibility(txn1, contactId01, privateGroup0.getId(),
|
db1.setGroupVisibility(txn1, contactId0From1, privateGroup0.getId(),
|
||||||
SHARED);
|
SHARED);
|
||||||
db1.commitTransaction(txn1);
|
db1.commitTransaction(txn1);
|
||||||
db1.endTransaction(txn1);
|
db1.endTransaction(txn1);
|
||||||
|
|
||||||
// sync join messages
|
// sync join messages
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that 0 never joined the group from 1's perspective
|
// assert that 0 never joined the group from 1's perspective
|
||||||
assertEquals(1, groupManager1.getHeaders(groupId0).size());
|
assertEquals(1, groupManager1.getHeaders(groupId0).size());
|
||||||
|
|
||||||
sync1To0();
|
sync1To0(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that 1 never joined the group from 0's perspective
|
// assert that 1 never joined the group from 0's perspective
|
||||||
assertEquals(1, groupManager0.getHeaders(groupId0).size());
|
assertEquals(1, groupManager0.getHeaders(groupId0).size());
|
||||||
@@ -395,10 +259,6 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrongJoinMessages2() throws Exception {
|
public void testWrongJoinMessages2() throws Exception {
|
||||||
addDefaultIdentities();
|
|
||||||
addDefaultContacts();
|
|
||||||
listenToEvents();
|
|
||||||
|
|
||||||
// author0 joins privateGroup0 with wrong member's join message
|
// author0 joins privateGroup0 with wrong member's join message
|
||||||
long joinTime = clock.currentTimeMillis();
|
long joinTime = clock.currentTimeMillis();
|
||||||
long inviteTime = joinTime - 1;
|
long inviteTime = joinTime - 1;
|
||||||
@@ -417,7 +277,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
// share the group with 1
|
// share the group with 1
|
||||||
Transaction txn0 = db0.startTransaction(false);
|
Transaction txn0 = db0.startTransaction(false);
|
||||||
db0.setGroupVisibility(txn0, contactId1, privateGroup0.getId(), SHARED);
|
db0.setGroupVisibility(txn0, contactId1From0, privateGroup0.getId(), SHARED);
|
||||||
db0.commitTransaction(txn0);
|
db0.commitTransaction(txn0);
|
||||||
db0.endTransaction(txn0);
|
db0.endTransaction(txn0);
|
||||||
|
|
||||||
@@ -425,7 +285,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
joinTime = clock.currentTimeMillis();
|
joinTime = clock.currentTimeMillis();
|
||||||
inviteTime = joinTime - 1;
|
inviteTime = joinTime - 1;
|
||||||
// signature uses joiner's key, not creator's key
|
// signature uses joiner's key, not creator's key
|
||||||
Contact c1 = contactManager0.getContact(contactId1);
|
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||||
creatorSignature = groupInvitationFactory
|
creatorSignature = groupInvitationFactory
|
||||||
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
||||||
author1.getPrivateKey());
|
author1.getPrivateKey());
|
||||||
@@ -438,19 +298,17 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
// share the group with 0
|
// share the group with 0
|
||||||
Transaction txn1 = db1.startTransaction(false);
|
Transaction txn1 = db1.startTransaction(false);
|
||||||
db1.setGroupVisibility(txn1, contactId01, privateGroup0.getId(), SHARED);
|
db1.setGroupVisibility(txn1, contactId0From1, privateGroup0.getId(), SHARED);
|
||||||
db1.commitTransaction(txn1);
|
db1.commitTransaction(txn1);
|
||||||
db1.endTransaction(txn1);
|
db1.endTransaction(txn1);
|
||||||
|
|
||||||
// sync join messages
|
// sync join messages
|
||||||
sync0To1();
|
sync0To1(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that 0 never joined the group from 1's perspective
|
// assert that 0 never joined the group from 1's perspective
|
||||||
assertEquals(1, groupManager1.getHeaders(groupId0).size());
|
assertEquals(1, groupManager1.getHeaders(groupId0).size());
|
||||||
|
|
||||||
sync1To0();
|
sync1To0(1, false);
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// assert that 1 never joined the group from 0's perspective
|
// assert that 1 never joined the group from 0's perspective
|
||||||
assertEquals(1, groupManager0.getHeaders(groupId0).size());
|
assertEquals(1, groupManager0.getHeaders(groupId0).size());
|
||||||
@@ -458,7 +316,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetMembers() throws Exception {
|
public void testGetMembers() throws Exception {
|
||||||
defaultInit();
|
addGroup();
|
||||||
|
|
||||||
Collection<GroupMember> members0 = groupManager0.getMembers(groupId0);
|
Collection<GroupMember> members0 = groupManager0.getMembers(groupId0);
|
||||||
assertEquals(2, members0.size());
|
assertEquals(2, members0.size());
|
||||||
@@ -485,7 +343,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJoinMessages() throws Exception {
|
public void testJoinMessages() throws Exception {
|
||||||
defaultInit();
|
addGroup();
|
||||||
|
|
||||||
Collection<GroupMessageHeader> headers0 =
|
Collection<GroupMessageHeader> headers0 =
|
||||||
groupManager0.getHeaders(groupId0);
|
groupManager0.getHeaders(groupId0);
|
||||||
@@ -514,18 +372,18 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRevealingRelationships() throws Exception {
|
public void testRevealingRelationships() throws Exception {
|
||||||
defaultInit();
|
addGroup();
|
||||||
|
|
||||||
// share the group with 2
|
// share the group with 2
|
||||||
Transaction txn0 = db0.startTransaction(false);
|
Transaction txn0 = db0.startTransaction(false);
|
||||||
db0.setGroupVisibility(txn0, contactId2, privateGroup0.getId(), SHARED);
|
db0.setGroupVisibility(txn0, contactId2From0, privateGroup0.getId(), SHARED);
|
||||||
db0.commitTransaction(txn0);
|
db0.commitTransaction(txn0);
|
||||||
db0.endTransaction(txn0);
|
db0.endTransaction(txn0);
|
||||||
|
|
||||||
// author2 joins privateGroup0
|
// author2 joins privateGroup0
|
||||||
long joinTime = clock.currentTimeMillis();
|
long joinTime = clock.currentTimeMillis();
|
||||||
long inviteTime = joinTime - 1;
|
long inviteTime = joinTime - 1;
|
||||||
Contact c2 = contactManager0.getContact(contactId2);
|
Contact c2 = contactManager0.getContact(contactId2From0);
|
||||||
byte[] creatorSignature = groupInvitationFactory
|
byte[] creatorSignature = groupInvitationFactory
|
||||||
.signInvitation(c2, privateGroup0.getId(), inviteTime,
|
.signInvitation(c2, privateGroup0.getId(), inviteTime,
|
||||||
author0.getPrivateKey());
|
author0.getPrivateKey());
|
||||||
@@ -536,18 +394,15 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
groupManager2.addPrivateGroup(txn2, privateGroup0, joinMsg2, false);
|
groupManager2.addPrivateGroup(txn2, privateGroup0, joinMsg2, false);
|
||||||
|
|
||||||
// share the group with 0
|
// share the group with 0
|
||||||
db2.setGroupVisibility(txn2, contactId01, privateGroup0.getId(),
|
db2.setGroupVisibility(txn2, contactId0From1, privateGroup0.getId(),
|
||||||
SHARED);
|
SHARED);
|
||||||
db2.commitTransaction(txn2);
|
db2.commitTransaction(txn2);
|
||||||
db2.endTransaction(txn2);
|
db2.endTransaction(txn2);
|
||||||
|
|
||||||
// sync join messages
|
// sync join messages
|
||||||
deliverMessage(sync2, contactId2, sync0, contactId02, "2 to 0");
|
sync2To0(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
sync0To2(2, true);
|
||||||
deliverMessage(sync0, contactId02, sync2, contactId2, "0 to 2");
|
sync0To1(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 2);
|
|
||||||
sync0To1();
|
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
|
|
||||||
// check that everybody sees everybody else as joined
|
// check that everybody sees everybody else as joined
|
||||||
Collection<GroupMember> members0 = groupManager0.getMembers(groupId0);
|
Collection<GroupMember> members0 = groupManager0.getMembers(groupId0);
|
||||||
@@ -626,7 +481,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDissolveGroup() throws Exception {
|
public void testDissolveGroup() throws Exception {
|
||||||
defaultInit();
|
addGroup();
|
||||||
|
|
||||||
// group is not dissolved initially
|
// group is not dissolved initially
|
||||||
assertFalse(groupManager1.isDissolved(groupId0));
|
assertFalse(groupManager1.isDissolved(groupId0));
|
||||||
@@ -641,93 +496,6 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
assertTrue(groupManager1.isDissolved(groupId0));
|
assertTrue(groupManager1.isDissolved(groupId0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
stopLifecycles();
|
|
||||||
TestUtils.deleteTestDirectory(testDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener implements EventListener {
|
|
||||||
@Override
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (e instanceof MessageStateChangedEvent) {
|
|
||||||
MessageStateChangedEvent event = (MessageStateChangedEvent) e;
|
|
||||||
if (!event.isLocal()) {
|
|
||||||
if (event.getState() == DELIVERED) {
|
|
||||||
LOG.info("Delivered new message");
|
|
||||||
deliveryWaiter.resume();
|
|
||||||
} else if (event.getState() == INVALID ||
|
|
||||||
event.getState() == PENDING) {
|
|
||||||
LOG.info("Validated new " + event.getState().name() +
|
|
||||||
" message");
|
|
||||||
validationWaiter.resume();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void defaultInit() throws Exception {
|
|
||||||
addDefaultIdentities();
|
|
||||||
addDefaultContacts();
|
|
||||||
listenToEvents();
|
|
||||||
addGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addDefaultIdentities() throws DbException {
|
|
||||||
KeyPair keyPair0 = crypto.generateSignatureKeyPair();
|
|
||||||
byte[] publicKey0 = keyPair0.getPublic().getEncoded();
|
|
||||||
byte[] privateKey0 = keyPair0.getPrivate().getEncoded();
|
|
||||||
author0 = authorFactory
|
|
||||||
.createLocalAuthor(AUTHOR0, publicKey0, privateKey0);
|
|
||||||
identityManager0.registerLocalAuthor(author0);
|
|
||||||
privateGroup0 =
|
|
||||||
privateGroupFactory.createPrivateGroup("Testgroup", author0);
|
|
||||||
groupId0 = privateGroup0.getId();
|
|
||||||
|
|
||||||
KeyPair keyPair1 = crypto.generateSignatureKeyPair();
|
|
||||||
byte[] publicKey1 = keyPair1.getPublic().getEncoded();
|
|
||||||
byte[] privateKey1 = keyPair1.getPrivate().getEncoded();
|
|
||||||
author1 = authorFactory
|
|
||||||
.createLocalAuthor(AUTHOR1, publicKey1, privateKey1);
|
|
||||||
identityManager1.registerLocalAuthor(author1);
|
|
||||||
|
|
||||||
KeyPair keyPair2 = crypto.generateSignatureKeyPair();
|
|
||||||
byte[] publicKey2 = keyPair2.getPublic().getEncoded();
|
|
||||||
byte[] privateKey2 = keyPair2.getPrivate().getEncoded();
|
|
||||||
author2 = authorFactory
|
|
||||||
.createLocalAuthor(AUTHOR2, publicKey2, privateKey2);
|
|
||||||
identityManager2.registerLocalAuthor(author2);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addDefaultContacts() throws DbException {
|
|
||||||
// creator adds invitee as contact
|
|
||||||
contactId1 = contactManager0
|
|
||||||
.addContact(author1, author0.getId(), master,
|
|
||||||
clock.currentTimeMillis(), true, true, true);
|
|
||||||
// invitee adds creator back
|
|
||||||
contactId01 = contactManager1
|
|
||||||
.addContact(author0, author1.getId(), master,
|
|
||||||
clock.currentTimeMillis(), true, true, true);
|
|
||||||
// creator adds invitee as contact
|
|
||||||
contactId2 = contactManager0
|
|
||||||
.addContact(author2, author0.getId(), master,
|
|
||||||
clock.currentTimeMillis(), true, true, true);
|
|
||||||
// invitee adds creator back
|
|
||||||
contactId02 = contactManager2
|
|
||||||
.addContact(author0, author2.getId(), master,
|
|
||||||
clock.currentTimeMillis(), true, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void listenToEvents() {
|
|
||||||
Listener listener0 = new Listener();
|
|
||||||
t0.getEventBus().addListener(listener0);
|
|
||||||
Listener listener1 = new Listener();
|
|
||||||
t1.getEventBus().addListener(listener1);
|
|
||||||
Listener listener2 = new Listener();
|
|
||||||
t2.getEventBus().addListener(listener2);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addGroup() throws Exception {
|
private void addGroup() throws Exception {
|
||||||
// author0 joins privateGroup0
|
// author0 joins privateGroup0
|
||||||
long joinTime = clock.currentTimeMillis();
|
long joinTime = clock.currentTimeMillis();
|
||||||
@@ -739,14 +507,14 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
// share the group with 1
|
// share the group with 1
|
||||||
Transaction txn0 = db0.startTransaction(false);
|
Transaction txn0 = db0.startTransaction(false);
|
||||||
db0.setGroupVisibility(txn0, contactId1, privateGroup0.getId(), SHARED);
|
db0.setGroupVisibility(txn0, contactId1From0, privateGroup0.getId(), SHARED);
|
||||||
db0.commitTransaction(txn0);
|
db0.commitTransaction(txn0);
|
||||||
db0.endTransaction(txn0);
|
db0.endTransaction(txn0);
|
||||||
|
|
||||||
// author1 joins privateGroup0
|
// author1 joins privateGroup0
|
||||||
joinTime = clock.currentTimeMillis();
|
joinTime = clock.currentTimeMillis();
|
||||||
long inviteTime = joinTime - 1;
|
long inviteTime = joinTime - 1;
|
||||||
Contact c1 = contactManager0.getContact(contactId1);
|
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||||
byte[] creatorSignature = groupInvitationFactory
|
byte[] creatorSignature = groupInvitationFactory
|
||||||
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
||||||
author0.getPrivateKey());
|
author0.getPrivateKey());
|
||||||
@@ -757,7 +525,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
|
|
||||||
// share the group with 0
|
// share the group with 0
|
||||||
Transaction txn1 = db1.startTransaction(false);
|
Transaction txn1 = db1.startTransaction(false);
|
||||||
db1.setGroupVisibility(txn1, contactId01, privateGroup0.getId(),
|
db1.setGroupVisibility(txn1, contactId0From1, privateGroup0.getId(),
|
||||||
SHARED);
|
SHARED);
|
||||||
db1.commitTransaction(txn1);
|
db1.commitTransaction(txn1);
|
||||||
db1.endTransaction(txn1);
|
db1.endTransaction(txn1);
|
||||||
@@ -765,74 +533,8 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
groupManager1.getPreviousMsgId(groupId0));
|
groupManager1.getPreviousMsgId(groupId0));
|
||||||
|
|
||||||
// sync join messages
|
// sync join messages
|
||||||
sync0To1();
|
sync0To1(1, true);
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
sync1To0(1, true);
|
||||||
sync1To0();
|
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sync0To1() throws IOException, TimeoutException {
|
|
||||||
deliverMessage(sync0, contactId01, sync1, contactId1, "0 to 1");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sync1To0() throws IOException, TimeoutException {
|
|
||||||
deliverMessage(sync1, contactId1, sync0, contactId01, "1 to 0");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deliverMessage(SyncSessionFactory fromSync, ContactId fromId,
|
|
||||||
SyncSessionFactory toSync, ContactId toId, String debug)
|
|
||||||
throws IOException, TimeoutException {
|
|
||||||
|
|
||||||
if (debug != null) LOG.info("TEST: Sending message from " + debug);
|
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
// Create an outgoing sync session
|
|
||||||
SyncSession sessionFrom =
|
|
||||||
fromSync.createSimplexOutgoingSession(toId, MAX_LATENCY, out);
|
|
||||||
// Write whatever needs to be written
|
|
||||||
sessionFrom.run();
|
|
||||||
out.close();
|
|
||||||
|
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
||||||
// Create an incoming sync session
|
|
||||||
SyncSession sessionTo = toSync.createIncomingSession(fromId, in);
|
|
||||||
// Read whatever needs to be read
|
|
||||||
sessionTo.run();
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startLifecycles() throws InterruptedException {
|
|
||||||
// Start the lifecycle manager and wait for it to finish
|
|
||||||
lifecycleManager0 = t0.getLifecycleManager();
|
|
||||||
lifecycleManager1 = t1.getLifecycleManager();
|
|
||||||
lifecycleManager2 = t2.getLifecycleManager();
|
|
||||||
lifecycleManager0.startServices(AUTHOR0);
|
|
||||||
lifecycleManager1.startServices(AUTHOR1);
|
|
||||||
lifecycleManager2.startServices(AUTHOR2);
|
|
||||||
lifecycleManager0.waitForStartup();
|
|
||||||
lifecycleManager1.waitForStartup();
|
|
||||||
lifecycleManager2.waitForStartup();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopLifecycles() throws InterruptedException {
|
|
||||||
// Clean up
|
|
||||||
lifecycleManager0.stopServices();
|
|
||||||
lifecycleManager1.stopServices();
|
|
||||||
lifecycleManager2.stopServices();
|
|
||||||
lifecycleManager0.waitForShutdown();
|
|
||||||
lifecycleManager1.waitForShutdown();
|
|
||||||
lifecycleManager2.waitForShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void injectEagerSingletons(
|
|
||||||
PrivateGroupManagerTestComponent component) {
|
|
||||||
component.inject(new LifecycleModule.EagerSingletons());
|
|
||||||
component.inject(new PrivateGroupModule.EagerSingletons());
|
|
||||||
component.inject(new CryptoModule.EagerSingletons());
|
|
||||||
component.inject(new ContactModule.EagerSingletons());
|
|
||||||
component.inject(new TransportModule.EagerSingletons());
|
|
||||||
component.inject(new SyncModule.EagerSingletons());
|
|
||||||
component.inject(new PropertiesModule.EagerSingletons());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
package org.briarproject;
|
|
||||||
|
|
||||||
import org.briarproject.api.contact.ContactManager;
|
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.api.event.EventBus;
|
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.api.privategroup.PrivateGroupManager;
|
|
||||||
import org.briarproject.api.sync.SyncSessionFactory;
|
|
||||||
import org.briarproject.clients.ClientsModule;
|
|
||||||
import org.briarproject.contact.ContactModule;
|
|
||||||
import org.briarproject.crypto.CryptoModule;
|
|
||||||
import org.briarproject.data.DataModule;
|
|
||||||
import org.briarproject.db.DatabaseModule;
|
|
||||||
import org.briarproject.event.EventModule;
|
|
||||||
import org.briarproject.identity.IdentityModule;
|
|
||||||
import org.briarproject.lifecycle.LifecycleModule;
|
|
||||||
import org.briarproject.messaging.MessagingModule;
|
|
||||||
import org.briarproject.privategroup.PrivateGroupModule;
|
|
||||||
import org.briarproject.privategroup.invitation.GroupInvitationModule;
|
|
||||||
import org.briarproject.properties.PropertiesModule;
|
|
||||||
import org.briarproject.sharing.SharingModule;
|
|
||||||
import org.briarproject.sync.SyncModule;
|
|
||||||
import org.briarproject.system.SystemModule;
|
|
||||||
import org.briarproject.transport.TransportModule;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Component;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Component(modules = {
|
|
||||||
TestDatabaseModule.class,
|
|
||||||
TestPluginsModule.class,
|
|
||||||
TestSeedProviderModule.class,
|
|
||||||
ClientsModule.class,
|
|
||||||
ContactModule.class,
|
|
||||||
CryptoModule.class,
|
|
||||||
DataModule.class,
|
|
||||||
DatabaseModule.class,
|
|
||||||
EventModule.class,
|
|
||||||
MessagingModule.class,
|
|
||||||
PrivateGroupModule.class,
|
|
||||||
GroupInvitationModule.class,
|
|
||||||
IdentityModule.class,
|
|
||||||
LifecycleModule.class,
|
|
||||||
PropertiesModule.class,
|
|
||||||
SharingModule.class,
|
|
||||||
SyncModule.class,
|
|
||||||
SystemModule.class,
|
|
||||||
TransportModule.class
|
|
||||||
})
|
|
||||||
interface PrivateGroupManagerTestComponent {
|
|
||||||
|
|
||||||
void inject(PrivateGroupManagerTest testCase);
|
|
||||||
|
|
||||||
void inject(ContactModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(CryptoModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(PrivateGroupModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(LifecycleModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(PropertiesModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(SyncModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(TransportModule.EagerSingletons init);
|
|
||||||
|
|
||||||
LifecycleManager getLifecycleManager();
|
|
||||||
|
|
||||||
EventBus getEventBus();
|
|
||||||
|
|
||||||
IdentityManager getIdentityManager();
|
|
||||||
|
|
||||||
ContactManager getContactManager();
|
|
||||||
|
|
||||||
PrivateGroupManager getPrivateGroupManager();
|
|
||||||
|
|
||||||
SyncSessionFactory getSyncSessionFactory();
|
|
||||||
|
|
||||||
DatabaseComponent getDatabaseComponent();
|
|
||||||
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,99 +0,0 @@
|
|||||||
package org.briarproject.introduction;
|
|
||||||
|
|
||||||
import org.briarproject.TestDatabaseModule;
|
|
||||||
import org.briarproject.TestPluginsModule;
|
|
||||||
import org.briarproject.TestSeedProviderModule;
|
|
||||||
import org.briarproject.api.clients.ClientHelper;
|
|
||||||
import org.briarproject.api.clients.MessageTracker;
|
|
||||||
import org.briarproject.api.contact.ContactManager;
|
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.api.event.EventBus;
|
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.api.introduction.IntroductionManager;
|
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.api.properties.TransportPropertyManager;
|
|
||||||
import org.briarproject.api.sync.SyncSessionFactory;
|
|
||||||
import org.briarproject.clients.ClientsModule;
|
|
||||||
import org.briarproject.contact.ContactModule;
|
|
||||||
import org.briarproject.crypto.CryptoModule;
|
|
||||||
import org.briarproject.data.DataModule;
|
|
||||||
import org.briarproject.db.DatabaseModule;
|
|
||||||
import org.briarproject.event.EventModule;
|
|
||||||
import org.briarproject.identity.IdentityModule;
|
|
||||||
import org.briarproject.lifecycle.LifecycleModule;
|
|
||||||
import org.briarproject.messaging.MessagingModule;
|
|
||||||
import org.briarproject.properties.PropertiesModule;
|
|
||||||
import org.briarproject.sync.SyncModule;
|
|
||||||
import org.briarproject.system.SystemModule;
|
|
||||||
import org.briarproject.transport.TransportModule;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Component;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Component(modules = {
|
|
||||||
TestDatabaseModule.class,
|
|
||||||
TestPluginsModule.class,
|
|
||||||
TestSeedProviderModule.class,
|
|
||||||
LifecycleModule.class,
|
|
||||||
IntroductionModule.class,
|
|
||||||
DatabaseModule.class,
|
|
||||||
CryptoModule.class,
|
|
||||||
EventModule.class,
|
|
||||||
ContactModule.class,
|
|
||||||
IdentityModule.class,
|
|
||||||
TransportModule.class,
|
|
||||||
ClientsModule.class,
|
|
||||||
SyncModule.class,
|
|
||||||
SystemModule.class,
|
|
||||||
DataModule.class,
|
|
||||||
PropertiesModule.class,
|
|
||||||
MessagingModule.class
|
|
||||||
})
|
|
||||||
interface IntroductionIntegrationTestComponent {
|
|
||||||
|
|
||||||
void inject(IntroductionIntegrationTest testCase);
|
|
||||||
|
|
||||||
void inject(ContactModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(CryptoModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(IntroductionModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(LifecycleModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(PropertiesModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(SyncModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(SystemModule.EagerSingletons init);
|
|
||||||
|
|
||||||
void inject(TransportModule.EagerSingletons init);
|
|
||||||
|
|
||||||
LifecycleManager getLifecycleManager();
|
|
||||||
|
|
||||||
EventBus getEventBus();
|
|
||||||
|
|
||||||
IdentityManager getIdentityManager();
|
|
||||||
|
|
||||||
ContactManager getContactManager();
|
|
||||||
|
|
||||||
IntroductionManager getIntroductionManager();
|
|
||||||
|
|
||||||
TransportPropertyManager getTransportPropertyManager();
|
|
||||||
|
|
||||||
MessageTracker getMessageTracker();
|
|
||||||
|
|
||||||
SyncSessionFactory getSyncSessionFactory();
|
|
||||||
|
|
||||||
/* the following methods are only needed to manually construct messages */
|
|
||||||
|
|
||||||
DatabaseComponent getDatabaseComponent();
|
|
||||||
|
|
||||||
ClientHelper getClientHelper();
|
|
||||||
|
|
||||||
MessageSender getMessageSender();
|
|
||||||
|
|
||||||
IntroductionGroupFactory getIntroductionGroupFactory();
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,7 @@ import org.briarproject.api.db.DbException;
|
|||||||
import org.briarproject.api.messaging.ConversationManager.ConversationClient;
|
import org.briarproject.api.messaging.ConversationManager.ConversationClient;
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.sync.ClientId;
|
import org.briarproject.api.sync.ClientId;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ public interface IntroductionManager extends ConversationClient {
|
|||||||
/**
|
/**
|
||||||
* sends two initial introduction messages
|
* sends two initial introduction messages
|
||||||
*/
|
*/
|
||||||
void makeIntroduction(Contact c1, Contact c2, String msg,
|
void makeIntroduction(Contact c1, Contact c2, @Nullable String msg,
|
||||||
final long timestamp)
|
final long timestamp)
|
||||||
throws DbException, FormatException;
|
throws DbException, FormatException;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.briarproject.api.db.DbException;
|
|||||||
import org.briarproject.api.messaging.ConversationManager.ConversationClient;
|
import org.briarproject.api.messaging.ConversationManager.ConversationClient;
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ public interface SharingManager<S extends Shareable>
|
|||||||
* and sends an optional message along with it.
|
* and sends an optional message along with it.
|
||||||
*/
|
*/
|
||||||
void sendInvitation(GroupId groupId, ContactId contactId,
|
void sendInvitation(GroupId groupId, ContactId contactId,
|
||||||
String message) throws DbException;
|
@Nullable String message) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responds to a pending group invitation
|
* Responds to a pending group invitation
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ public abstract class BriarTestCase {
|
|||||||
public BriarTestCase() {
|
public BriarTestCase() {
|
||||||
// Ensure exceptions thrown on worker threads cause tests to fail
|
// Ensure exceptions thrown on worker threads cause tests to fail
|
||||||
UncaughtExceptionHandler fail = new UncaughtExceptionHandler() {
|
UncaughtExceptionHandler fail = new UncaughtExceptionHandler() {
|
||||||
|
@Override
|
||||||
public void uncaughtException(Thread thread, Throwable throwable) {
|
public void uncaughtException(Thread thread, Throwable throwable) {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
fail();
|
fail();
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
package org.briarproject;
|
package org.briarproject;
|
||||||
|
|
||||||
import org.briarproject.api.UniqueId;
|
import org.briarproject.api.UniqueId;
|
||||||
|
import org.briarproject.api.clients.MessageTracker;
|
||||||
|
import org.briarproject.api.clients.MessageTracker.GroupCount;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.api.db.DbException;
|
||||||
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.util.IoUtils;
|
import org.briarproject.util.IoUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class TestUtils {
|
public class TestUtils {
|
||||||
|
|
||||||
private static final AtomicInteger nextTestDir =
|
private static final AtomicInteger nextTestDir =
|
||||||
@@ -44,4 +50,20 @@ public class TestUtils {
|
|||||||
public static SecretKey getSecretKey() {
|
public static SecretKey getSecretKey() {
|
||||||
return new SecretKey(getRandomBytes(SecretKey.LENGTH));
|
return new SecretKey(getRandomBytes(SecretKey.LENGTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void assertGroupCount(MessageTracker tracker, GroupId g,
|
||||||
|
long msgCount, long unreadCount, long latestMsgTime)
|
||||||
|
throws DbException {
|
||||||
|
GroupCount groupCount = tracker.getGroupCount(g);
|
||||||
|
assertEquals(msgCount, groupCount.getMsgCount());
|
||||||
|
assertEquals(unreadCount, groupCount.getUnreadCount());
|
||||||
|
assertEquals(latestMsgTime, groupCount.getLatestMsgTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertGroupCount(MessageTracker tracker, GroupId g,
|
||||||
|
long msgCount, long unreadCount) throws DbException {
|
||||||
|
GroupCount c1 = tracker.getGroupCount(g);
|
||||||
|
assertEquals(msgCount, c1.getMsgCount());
|
||||||
|
assertEquals(unreadCount, c1.getUnreadCount());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user