Moved subscription updates to the client layer.

This commit is contained in:
akwizgran
2016-02-01 15:13:36 +00:00
parent 54272c8836
commit 18db17bf5b
30 changed files with 1286 additions and 646 deletions

View File

@@ -20,6 +20,7 @@ import org.briarproject.api.event.GroupRemovedEvent;
import org.briarproject.api.event.GroupVisibilityUpdatedEvent;
import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.event.MessageRequestedEvent;
import org.briarproject.api.event.MessageSharedEvent;
import org.briarproject.api.event.MessageToAckEvent;
import org.briarproject.api.event.MessageToRequestEvent;
import org.briarproject.api.event.MessageValidatedEvent;
@@ -246,6 +247,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
// The message was added, so the listeners should be called
oneOf(eventBus).broadcast(with(any(MessageAddedEvent.class)));
oneOf(eventBus).broadcast(with(any(MessageValidatedEvent.class)));
oneOf(eventBus).broadcast(with(any(MessageSharedEvent.class)));
}});
DatabaseComponent db = createDatabaseComponent(database, eventBus,
shutdown);
@@ -265,11 +267,11 @@ public class DatabaseComponentImplTest extends BriarTestCase {
final EventBus eventBus = context.mock(EventBus.class);
context.checking(new Expectations() {{
// Check whether the contact is in the DB (which it's not)
exactly(15).of(database).startTransaction();
exactly(17).of(database).startTransaction();
will(returnValue(txn));
exactly(15).of(database).containsContact(txn, contactId);
exactly(17).of(database).containsContact(txn, contactId);
will(returnValue(false));
exactly(15).of(database).abortTransaction(txn);
exactly(17).of(database).abortTransaction(txn);
}});
DatabaseComponent db = createDatabaseComponent(database, eventBus,
shutdown);
@@ -337,6 +339,13 @@ public class DatabaseComponentImplTest extends BriarTestCase {
// Expected
}
try {
db.isVisibleToContact(contactId, groupId);
fail();
} catch (NoSuchContactException expected) {
// Expected
}
try {
Ack a = new Ack(Collections.singletonList(messageId));
db.receiveAck(contactId, a);
@@ -382,6 +391,13 @@ public class DatabaseComponentImplTest extends BriarTestCase {
// Expected
}
try {
db.setVisibleToContact(contactId, groupId, true);
fail();
} catch (NoSuchContactException expected) {
// Expected
}
context.assertIsSatisfied();
}
@@ -438,13 +454,14 @@ public class DatabaseComponentImplTest extends BriarTestCase {
final EventBus eventBus = context.mock(EventBus.class);
context.checking(new Expectations() {{
// Check whether the group is in the DB (which it's not)
exactly(7).of(database).startTransaction();
exactly(9).of(database).startTransaction();
will(returnValue(txn));
exactly(7).of(database).containsGroup(txn, groupId);
exactly(9).of(database).containsGroup(txn, groupId);
will(returnValue(false));
exactly(7).of(database).abortTransaction(txn);
// This is needed for getMessageStatus() to proceed
exactly(1).of(database).containsContact(txn, contactId);
exactly(9).of(database).abortTransaction(txn);
// This is needed for getMessageStatus(), isVisibleToContact(), and
// setVisibleToContact() to proceed
exactly(3).of(database).containsContact(txn, contactId);
will(returnValue(true));
}});
DatabaseComponent db = createDatabaseComponent(database, eventBus,
@@ -478,6 +495,13 @@ public class DatabaseComponentImplTest extends BriarTestCase {
// Expected
}
try {
db.isVisibleToContact(contactId, groupId);
fail();
} catch (NoSuchGroupException expected) {
// Expected
}
try {
db.mergeGroupMetadata(groupId, metadata);
fail();
@@ -499,6 +523,13 @@ public class DatabaseComponentImplTest extends BriarTestCase {
// Expected
}
try {
db.setVisibleToContact(contactId, groupId, true);
fail();
} catch (NoSuchGroupException expected) {
// Expected
}
context.assertIsSatisfied();
}
@@ -847,7 +878,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
will(returnValue(false));
oneOf(database).containsVisibleGroup(txn, contactId, groupId);
will(returnValue(true));
oneOf(database).addMessage(txn, message, UNKNOWN, true);
oneOf(database).addMessage(txn, message, UNKNOWN, false);
oneOf(database).getVisibility(txn, groupId);
will(returnValue(Collections.singletonList(contactId)));
oneOf(database).getContactIds(txn);
@@ -1019,7 +1050,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
oneOf(database).getContactIds(txn);
will(returnValue(both));
oneOf(database).removeVisibility(txn, contactId1, groupId);
oneOf(database).setVisibleToAll(txn, groupId, false);
oneOf(database).commitTransaction(txn);
oneOf(eventBus).broadcast(with(any(
GroupVisibilityUpdatedEvent.class)));
@@ -1051,7 +1081,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
will(returnValue(both));
oneOf(database).getContactIds(txn);
will(returnValue(both));
oneOf(database).setVisibleToAll(txn, groupId, false);
oneOf(database).commitTransaction(txn);
}});
DatabaseComponent db = createDatabaseComponent(database, eventBus,
@@ -1062,55 +1091,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
context.assertIsSatisfied();
}
@Test
public void testSettingVisibleToAllAffectsCurrentContacts()
throws Exception {
final ContactId contactId1 = new ContactId(123);
final Collection<ContactId> both = Arrays.asList(contactId, contactId1);
Mockery context = new Mockery();
@SuppressWarnings("unchecked")
final Database<Object> database = context.mock(Database.class);
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
final EventBus eventBus = context.mock(EventBus.class);
context.checking(new Expectations() {{
// setVisibility()
oneOf(database).startTransaction();
will(returnValue(txn));
oneOf(database).containsGroup(txn, groupId);
will(returnValue(true));
oneOf(database).getVisibility(txn, groupId);
will(returnValue(Collections.emptyList()));
oneOf(database).getContactIds(txn);
will(returnValue(both));
oneOf(database).addVisibility(txn, contactId, groupId);
oneOf(database).setVisibleToAll(txn, groupId, false);
oneOf(database).commitTransaction(txn);
oneOf(eventBus).broadcast(with(any(
GroupVisibilityUpdatedEvent.class)));
// setVisibleToAll()
oneOf(database).startTransaction();
will(returnValue(txn));
oneOf(database).containsGroup(txn, groupId);
will(returnValue(true));
oneOf(database).setVisibleToAll(txn, groupId, true);
oneOf(database).getVisibility(txn, groupId);
will(returnValue(Collections.singletonList(contactId)));
oneOf(database).getContactIds(txn);
will(returnValue(both));
oneOf(database).addVisibility(txn, contactId1, groupId);
oneOf(database).commitTransaction(txn);
oneOf(eventBus).broadcast(with(any(
GroupVisibilityUpdatedEvent.class)));
}});
DatabaseComponent db = createDatabaseComponent(database, eventBus,
shutdown);
db.setVisibility(groupId, Collections.singletonList(contactId));
db.setVisibleToAll(groupId, true);
context.assertIsSatisfied();
}
@Test
public void testTransportKeys() throws Exception {
final TransportKeys keys = createTransportKeys();

View File

@@ -205,7 +205,7 @@ public class H2DatabaseTest extends BriarTestCase {
Database<Connection> db = open(false);
Connection txn = db.startTransaction();
// Add a contact, subscribe to a group and store an unvalidated message
// Add a contact, a group and an unvalidated message
db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
db.addGroup(txn, group);
@@ -243,7 +243,7 @@ public class H2DatabaseTest extends BriarTestCase {
Database<Connection> db = open(false);
Connection txn = db.startTransaction();
// Add a contact, subscribe to a group and store an unshared message
// Add a contact, a group and an unshared message
db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
db.addGroup(txn, group);
@@ -329,7 +329,7 @@ public class H2DatabaseTest extends BriarTestCase {
ids = db.getMessagesToOffer(txn, contactId, 100);
assertEquals(Collections.singletonList(messageId), ids);
// Making the subscription invisible should make the message unsendable
// Making the group invisible should make the message unsendable
db.removeVisibility(txn, contactId, groupId);
ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE);
assertTrue(ids.isEmpty());
@@ -1017,6 +1017,31 @@ public class H2DatabaseTest extends BriarTestCase {
db.close();
}
@Test
public void testGroupsVisibleToContacts() throws Exception {
Database<Connection> db = open(false);
Connection txn = db.startTransaction();
// Add a contact and a group
db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
db.addGroup(txn, group);
// The group should not be visible to the contact
assertFalse(db.containsVisibleGroup(txn, contactId, groupId));
// Make the group visible to the contact
db.addVisibility(txn, contactId, groupId);
assertTrue(db.containsVisibleGroup(txn, contactId, groupId));
// Make the group invisible to the contact
db.removeVisibility(txn, contactId, groupId);
assertFalse(db.containsVisibleGroup(txn, contactId, groupId));
db.commitTransaction(txn);
db.close();
}
@Test
public void testDifferentLocalPseudonymsCanHaveTheSameContact()
throws Exception {

View File

@@ -0,0 +1,14 @@
package org.briarproject.forum;
import org.briarproject.BriarTestCase;
import org.junit.Test;
import static org.junit.Assert.fail;
public class ForumListValidatorTest extends BriarTestCase {
@Test
public void testUnitTestsExist() {
fail(); // FIXME: Write tests
}
}

View File

@@ -0,0 +1,14 @@
package org.briarproject.forum;
import org.briarproject.BriarTestCase;
import org.junit.Test;
import static org.junit.Assert.fail;
public class ForumSharingManagerImplTest extends BriarTestCase {
@Test
public void testUnitTestsExist() {
fail(); // FIXME: Write tests
}
}