mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Addressed review comments.
This commit is contained in:
@@ -31,6 +31,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.briarproject.TestUtils.assertGroupCount;
|
||||
import static org.briarproject.api.blogs.BlogSharingManager.CLIENT_ID;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -46,6 +47,7 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ 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.GroupCount;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
@@ -29,7 +28,6 @@ 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.GroupId;
|
||||
import org.briarproject.api.sync.SyncSession;
|
||||
import org.briarproject.api.sync.SyncSessionFactory;
|
||||
import org.briarproject.api.system.Clock;
|
||||
@@ -58,12 +56,12 @@ 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.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -304,15 +302,15 @@ public abstract class BriarIntegrationTest extends BriarTestCase {
|
||||
|
||||
protected void sync2To1(int num, boolean valid)
|
||||
throws IOException, TimeoutException {
|
||||
assertTrue(contactId2From1 != null);
|
||||
assertTrue(contactId1From2 != null);
|
||||
assertNotNull(contactId2From1);
|
||||
assertNotNull(contactId1From2);
|
||||
syncMessage(sync2, contactId2From1, sync1, contactId1From2, num, valid);
|
||||
}
|
||||
|
||||
protected void sync1To2(int num, boolean valid)
|
||||
throws IOException, TimeoutException {
|
||||
assertTrue(contactId2From1 != null);
|
||||
assertTrue(contactId1From2 != null);
|
||||
assertNotNull(contactId2From1);
|
||||
assertNotNull(contactId1From2);
|
||||
syncMessage(sync1, contactId1From2, sync2, contactId2From1, num, valid);
|
||||
}
|
||||
|
||||
@@ -359,23 +357,4 @@ public abstract class BriarIntegrationTest extends BriarTestCase {
|
||||
contactManager2.removeContact(contactId0From2);
|
||||
contactManager2.removeContact(contactId1From2);
|
||||
}
|
||||
|
||||
protected static void assertGroupCount(MessageTracker tracker, GroupId g,
|
||||
long msgCount, long unreadCount, long latestMsg)
|
||||
throws DbException {
|
||||
|
||||
GroupCount groupCount = tracker.getGroupCount(g);
|
||||
assertEquals(msgCount, groupCount.getMsgCount());
|
||||
assertEquals(unreadCount, groupCount.getUnreadCount());
|
||||
assertEquals(latestMsg, groupCount.getLatestMsgTime());
|
||||
}
|
||||
|
||||
protected 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.Collection;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.briarproject.TestUtils.assertGroupCount;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ForumManagerTest extends BriarIntegrationTest {
|
||||
@@ -24,9 +25,10 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
||||
private ForumManager forumManager0, forumManager1;
|
||||
private ForumSharingManager forumSharingManager0, forumSharingManager1;
|
||||
private Forum forum0;
|
||||
private GroupId g;
|
||||
private GroupId groupId0;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
@@ -37,9 +39,9 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
||||
|
||||
|
||||
forum0 = forumManager0.addForum("Test Forum");
|
||||
g = forum0.getId();
|
||||
groupId0 = forum0.getId();
|
||||
// share forum
|
||||
forumSharingManager0.sendInvitation(g, contactId1From0, null);
|
||||
forumSharingManager0.sendInvitation(groupId0, contactId1From0, null);
|
||||
sync0To1(1, true);
|
||||
forumSharingManager1.respondToInvitation(forum0, contact0From1, true);
|
||||
sync1To0(1, true);
|
||||
@@ -93,8 +95,7 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
||||
assertEquals(body1, hBody);
|
||||
assertNull(h.getParentId());
|
||||
assertTrue(h.isRead());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
assertEquals(h.getTimestamp(), ms2);
|
||||
assertEquals(body2, hBody);
|
||||
assertEquals(h.getParentId(), post2.getParent());
|
||||
@@ -109,55 +110,55 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
||||
public void testForumPostDelivery() throws Exception {
|
||||
// add one forum post
|
||||
long time = clock.currentTimeMillis();
|
||||
ForumPost post1 = createForumPost(g, null, "a", time);
|
||||
ForumPost post1 = createForumPost(groupId0, null, "a", time);
|
||||
forumManager0.addLocalPost(post1);
|
||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
||||
assertGroupCount(messageTracker0, g, 1, 0, time);
|
||||
assertGroupCount(messageTracker1, g, 0, 0, 0);
|
||||
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||
assertGroupCount(messageTracker0, groupId0, 1, 0, time);
|
||||
assertGroupCount(messageTracker1, groupId0, 0, 0, 0);
|
||||
|
||||
// send post to 1
|
||||
sync0To1(1, true);
|
||||
assertEquals(1, forumManager1.getPostHeaders(g).size());
|
||||
assertGroupCount(messageTracker1, g, 1, 1, time);
|
||||
assertEquals(1, forumManager1.getPostHeaders(groupId0).size());
|
||||
assertGroupCount(messageTracker1, groupId0, 1, 1, time);
|
||||
|
||||
// add another forum post
|
||||
long time2 = clock.currentTimeMillis();
|
||||
ForumPost post2 = createForumPost(g, null, "b", time2);
|
||||
ForumPost post2 = createForumPost(groupId0, null, "b", time2);
|
||||
forumManager1.addLocalPost(post2);
|
||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
||||
assertEquals(2, forumManager1.getPostHeaders(g).size());
|
||||
assertGroupCount(messageTracker0, g, 1, 0, time);
|
||||
assertGroupCount(messageTracker1, g, 2, 1, time2);
|
||||
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||
assertEquals(2, forumManager1.getPostHeaders(groupId0).size());
|
||||
assertGroupCount(messageTracker0, groupId0, 1, 0, time);
|
||||
assertGroupCount(messageTracker1, groupId0, 2, 1, time2);
|
||||
|
||||
// send post to 0
|
||||
sync1To0(1, true);
|
||||
assertEquals(2, forumManager1.getPostHeaders(g).size());
|
||||
assertGroupCount(messageTracker0, g, 2, 1, time2);
|
||||
assertEquals(2, forumManager1.getPostHeaders(groupId0).size());
|
||||
assertGroupCount(messageTracker0, groupId0, 2, 1, time2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForumPostDeliveredAfterParent() throws Exception {
|
||||
// add one forum post without the parent
|
||||
long time = clock.currentTimeMillis();
|
||||
ForumPost post1 = createForumPost(g, null, "a", time);
|
||||
ForumPost post2 = createForumPost(g, post1, "a", time);
|
||||
ForumPost post1 = createForumPost(groupId0, null, "a", time);
|
||||
ForumPost post2 = createForumPost(groupId0, post1, "a", time);
|
||||
forumManager0.addLocalPost(post2);
|
||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
||||
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||
|
||||
// send post to 1 without waiting for message delivery
|
||||
sync0To1(1, false);
|
||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||
|
||||
// now add the parent post as well
|
||||
forumManager0.addLocalPost(post1);
|
||||
assertEquals(2, forumManager0.getPostHeaders(g).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
||||
assertEquals(2, forumManager0.getPostHeaders(groupId0).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||
|
||||
// and send it over to 1 and wait for a second message to be delivered
|
||||
sync0To1(2, true);
|
||||
assertEquals(2, forumManager1.getPostHeaders(g).size());
|
||||
assertEquals(2, forumManager1.getPostHeaders(groupId0).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,15 +174,15 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
||||
// add one forum post with a parent in another forum
|
||||
long time = clock.currentTimeMillis();
|
||||
ForumPost post1 = createForumPost(g1, null, "a", time);
|
||||
ForumPost post = createForumPost(g, post1, "b", time);
|
||||
ForumPost post = createForumPost(groupId0, post1, "b", time);
|
||||
forumManager0.addLocalPost(post);
|
||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
||||
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||
|
||||
// send the child post to 1
|
||||
sync0To1(1, false);
|
||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
||||
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(groupId0).size());
|
||||
|
||||
// now also add the parent post which is in another group
|
||||
forumManager0.addLocalPost(post1);
|
||||
@@ -190,10 +191,10 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
||||
|
||||
// send posts to 1
|
||||
sync0To1(1, true);
|
||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
||||
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||
assertEquals(1, forumManager0.getPostHeaders(g1).size());
|
||||
// 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());
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ public class ForumSharingIntegrationTest extends BriarIntegrationTest {
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.briarproject.TestPluginsModule.TRANSPORT_ID;
|
||||
import static org.briarproject.TestUtils.assertGroupCount;
|
||||
import static org.briarproject.api.clients.MessageQueueManager.QUEUE_STATE_KEY;
|
||||
import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.E_PUBLIC_KEY;
|
||||
@@ -88,6 +89,7 @@ public class IntroductionIntegrationTest extends BriarIntegrationTest {
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
package org.briarproject;
|
||||
|
||||
import org.briarproject.api.clients.MessageTracker;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public abstract class BriarTestCase {
|
||||
@@ -14,6 +9,7 @@ public abstract class BriarTestCase {
|
||||
public BriarTestCase() {
|
||||
// Ensure exceptions thrown on worker threads cause tests to fail
|
||||
UncaughtExceptionHandler fail = new UncaughtExceptionHandler() {
|
||||
@Override
|
||||
public void uncaughtException(Thread thread, Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
fail();
|
||||
@@ -21,22 +17,4 @@ public abstract class BriarTestCase {
|
||||
};
|
||||
Thread.setDefaultUncaughtExceptionHandler(fail);
|
||||
}
|
||||
|
||||
protected static void assertGroupCount(MessageTracker tracker, GroupId g,
|
||||
long msgCount, long unreadCount, long latestMsg)
|
||||
throws DbException {
|
||||
|
||||
MessageTracker.GroupCount groupCount = tracker.getGroupCount(g);
|
||||
assertEquals(msgCount, groupCount.getMsgCount());
|
||||
assertEquals(unreadCount, groupCount.getUnreadCount());
|
||||
assertEquals(latestMsg, groupCount.getLatestMsgTime());
|
||||
}
|
||||
|
||||
protected static void assertGroupCount(MessageTracker tracker, GroupId g,
|
||||
long msgCount, long unreadCount) throws DbException {
|
||||
|
||||
MessageTracker.GroupCount c1 = tracker.getGroupCount(g);
|
||||
assertEquals(msgCount, c1.getMsgCount());
|
||||
assertEquals(unreadCount, c1.getUnreadCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
package org.briarproject;
|
||||
|
||||
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.db.DbException;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.util.IoUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
private static final AtomicInteger nextTestDir =
|
||||
@@ -44,4 +50,20 @@ public class TestUtils {
|
||||
public static SecretKey getSecretKey() {
|
||||
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