mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Merge branch 'master' into '941-store-correct-parent-id'
# Conflicts: # briar-core/src/test/java/org/briarproject/briar/blog/BlogManagerImplTest.java
This commit is contained in:
@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.contact.ContactManager;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
@@ -77,8 +76,6 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
private final IdentityManager identityManager =
|
||||
context.mock(IdentityManager.class);
|
||||
private final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
private final ContactManager contactManager =
|
||||
context.mock(ContactManager.class);
|
||||
private final BlogFactory blogFactory = context.mock(BlogFactory.class);
|
||||
private final BlogPostFactory blogPostFactory =
|
||||
context.mock(BlogPostFactory.class);
|
||||
@@ -94,7 +91,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
public BlogManagerImplTest() {
|
||||
MetadataParser metadataParser = context.mock(MetadataParser.class);
|
||||
blogManager = new BlogManagerImpl(db, identityManager, clientHelper,
|
||||
metadataParser, contactManager, blogFactory, blogPostFactory);
|
||||
metadataParser, blogFactory, blogPostFactory);
|
||||
|
||||
localAuthor1 = createLocalAuthor();
|
||||
localAuthor2 = createLocalAuthor();
|
||||
@@ -160,6 +157,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).createBlog(blog2.getAuthor());
|
||||
will(returnValue(blog2));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(blog1.getAuthor()));
|
||||
oneOf(db).removeGroup(txn, blog2.getGroup());
|
||||
}});
|
||||
|
||||
@@ -244,13 +243,11 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
public void testRemoveBlog() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
|
||||
checkGetBlogExpectations(txn, false, blog1);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
will(returnValue(txn));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(blog2.getAuthor()));
|
||||
oneOf(contactManager).contactExists(txn, localAuthor1.getId(),
|
||||
localAuthor2.getId());
|
||||
will(returnValue(false));
|
||||
oneOf(db).removeGroup(txn, blog1.getGroup());
|
||||
oneOf(db).commitTransaction(txn);
|
||||
oneOf(db).endTransaction(txn);
|
||||
@@ -800,57 +797,29 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
public void testBlogCanBeRemoved() throws Exception {
|
||||
// check that own personal blogs can not be removed
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
checkGetBlogExpectations(txn, true, blog1);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(blog1.getAuthor()));
|
||||
oneOf(db).commitTransaction(txn);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
assertFalse(blogManager.canBeRemoved(blog1.getId()));
|
||||
assertFalse(blogManager.canBeRemoved(blog1));
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// check that blogs of contacts can not be removed
|
||||
// check that blogs of contacts can be removed
|
||||
final Transaction txn2 = new Transaction(null, true);
|
||||
checkGetBlogExpectations(txn2, true, blog1);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn2));
|
||||
oneOf(identityManager).getLocalAuthor(txn2);
|
||||
will(returnValue(blog2.getAuthor()));
|
||||
oneOf(contactManager).contactExists(txn2, blog1.getAuthor().getId(),
|
||||
blog2.getAuthor().getId());
|
||||
will(returnValue(true));
|
||||
oneOf(db).commitTransaction(txn2);
|
||||
oneOf(db).endTransaction(txn2);
|
||||
}});
|
||||
assertFalse(blogManager.canBeRemoved(blog1.getId()));
|
||||
assertTrue(blogManager.canBeRemoved(blog1));
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// check that blogs can be removed if they don't belong to a contact
|
||||
final Transaction txn3 = new Transaction(null, true);
|
||||
checkGetBlogExpectations(txn3, true, blog1);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn3);
|
||||
will(returnValue(blog2.getAuthor()));
|
||||
oneOf(contactManager).contactExists(txn3, blog1.getAuthor().getId(),
|
||||
blog2.getAuthor().getId());
|
||||
will(returnValue(false));
|
||||
oneOf(db).commitTransaction(txn3);
|
||||
oneOf(db).endTransaction(txn3);
|
||||
}});
|
||||
assertTrue(blogManager.canBeRemoved(blog1.getId()));
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
private void checkGetBlogExpectations(final Transaction txn,
|
||||
final boolean readOnly, final Blog blog) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(readOnly);
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getGroup(txn, blog.getId());
|
||||
will(returnValue(blog.getGroup()));
|
||||
oneOf(blogFactory).parseBlog(blog.getGroup());
|
||||
will(returnValue(blog));
|
||||
}});
|
||||
}
|
||||
|
||||
private LocalAuthor createLocalAuthor() {
|
||||
@@ -874,4 +843,4 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import org.junit.rules.ExpectedException;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
@@ -185,19 +184,19 @@ public class BlogManagerIntegrationTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanNotRemoveContactsPersonalBlog() throws Exception {
|
||||
assertFalse(blogManager0.canBeRemoved(blog1.getId()));
|
||||
assertFalse(blogManager1.canBeRemoved(blog0.getId()));
|
||||
public void testCanRemoveContactsPersonalBlog() throws Exception {
|
||||
assertTrue(blogManager0.canBeRemoved(blog1));
|
||||
assertTrue(blogManager1.canBeRemoved(blog0));
|
||||
|
||||
// the following two calls should throw a DbException now
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
assertEquals(4, blogManager0.getBlogs().size());
|
||||
assertEquals(2, blogManager1.getBlogs().size());
|
||||
|
||||
blogManager0.removeBlog(blog1);
|
||||
blogManager1.removeBlog(blog0);
|
||||
|
||||
// blogs have not been removed
|
||||
assertEquals(2, blogManager0.getBlogs().size());
|
||||
assertEquals(2, blogManager1.getBlogs().size());
|
||||
// blogs have been removed
|
||||
assertEquals(3, blogManager0.getBlogs().size());
|
||||
assertEquals(1, blogManager1.getBlogs().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.briarproject.briar.client;
|
||||
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.briar.api.client.MessageTracker;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.briarproject.briar.client.MessageTrackerConstants.GROUP_KEY_STORED_MESSAGE_ID;
|
||||
|
||||
public class MessageTrackerTest extends BrambleMockTestCase {
|
||||
|
||||
protected final GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||
protected final ClientHelper clientHelper =
|
||||
context.mock(ClientHelper.class);
|
||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
private final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
private final MessageTracker messageTracker =
|
||||
new MessageTrackerImpl(db, clientHelper);
|
||||
private final BdfDictionary dictionary = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_STORED_MESSAGE_ID, messageId)
|
||||
);
|
||||
|
||||
@Test
|
||||
public void testMessageStore() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).mergeGroupMetadata(groupId, dictionary);
|
||||
}});
|
||||
messageTracker.storeMessageId(groupId, messageId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageLoad() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(groupId);
|
||||
will(returnValue(dictionary));
|
||||
}});
|
||||
MessageId loadedId = messageTracker.loadStoredMessageId(groupId);
|
||||
Assert.assertNotNull(loadedId);
|
||||
Assert.assertTrue(messageId.equals(loadedId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,7 +41,7 @@ import static org.junit.Assert.fail;
|
||||
public class BlogSharingIntegrationTest
|
||||
extends BriarIntegrationTest<BriarIntegrationTestComponent> {
|
||||
|
||||
private BlogManager blogManager1;
|
||||
private BlogManager blogManager0, blogManager1;
|
||||
private Blog blog0, blog1, blog2;
|
||||
private SharerListener listener0;
|
||||
private InviteeListener listener1;
|
||||
@@ -60,7 +60,7 @@ public class BlogSharingIntegrationTest
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
BlogManager blogManager0 = c0.getBlogManager();
|
||||
blogManager0 = c0.getBlogManager();
|
||||
blogManager1 = c1.getBlogManager();
|
||||
blogSharingManager0 = c0.getBlogSharingManager();
|
||||
blogSharingManager1 = c1.getBlogSharingManager();
|
||||
@@ -370,7 +370,7 @@ public class BlogSharingIntegrationTest
|
||||
assertEquals(contact0From1, sharedBy.iterator().next());
|
||||
|
||||
// shared blog can be removed
|
||||
assertTrue(blogManager1.canBeRemoved(blog2.getId()));
|
||||
assertTrue(blogManager1.canBeRemoved(blog2));
|
||||
|
||||
// invitee removes blog again
|
||||
blogManager1.removeBlog(blog2);
|
||||
@@ -386,44 +386,33 @@ public class BlogSharingIntegrationTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSharedBlogBecomesPermanent() throws Exception {
|
||||
public void testRemovePreSharedBlog() throws Exception {
|
||||
// let invitee accept all requests
|
||||
listenToEvents(true);
|
||||
|
||||
// invitee only sees two blogs
|
||||
assertEquals(2, blogManager1.getBlogs().size());
|
||||
// 0 and 1 are sharing blog 1 with each other
|
||||
assertTrue(blogSharingManager0.getSharedWith(blog1.getId())
|
||||
.contains(contact1From0));
|
||||
assertTrue(blogSharingManager1.getSharedWith(blog1.getId())
|
||||
.contains(contact0From1));
|
||||
|
||||
// sharer sends invitation for 2's blog to 1
|
||||
blogSharingManager0
|
||||
.sendInvitation(blog2.getId(), contactId1From0, "Hi!",
|
||||
clock.currentTimeMillis());
|
||||
// 0 removes blog 1
|
||||
assertTrue(blogManager0.getBlogs().contains(blog1));
|
||||
blogManager0.removeBlog(blog1);
|
||||
assertFalse(blogManager0.getBlogs().contains(blog1));
|
||||
|
||||
// sync first request message
|
||||
// sync leave message to 0
|
||||
sync0To1(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener1.requestReceived);
|
||||
|
||||
// make sure blog2 is shared by 0
|
||||
Collection<Contact> contacts =
|
||||
blogSharingManager1.getSharedWith(blog2.getId());
|
||||
assertEquals(1, contacts.size());
|
||||
assertTrue(contacts.contains(contact0From1));
|
||||
// 0 and 1 are no longer sharing blog 1 with each other
|
||||
assertFalse(blogSharingManager0.getSharedWith(blog1.getId())
|
||||
.contains(contact1From0));
|
||||
assertFalse(blogSharingManager1.getSharedWith(blog1.getId())
|
||||
.contains(contact0From1));
|
||||
|
||||
// sync response back
|
||||
sync1To0(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// blog was added and can be removed
|
||||
assertEquals(3, blogManager1.getBlogs().size());
|
||||
assertTrue(blogManager1.canBeRemoved(blog2.getId()));
|
||||
|
||||
// 1 and 2 are adding each other
|
||||
addContacts1And2();
|
||||
assertEquals(3, blogManager1.getBlogs().size());
|
||||
|
||||
// now blog can not be removed anymore
|
||||
assertFalse(blogManager1.canBeRemoved(blog2.getId()));
|
||||
// 1 can again share blog 1 with 0
|
||||
assertTrue(
|
||||
blogSharingManager1.canBeShared(blog1.getId(), contact0From1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user