mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Return default message status if group is invisible.
This commit is contained in:
@@ -30,6 +30,7 @@ import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.sync.MessageStatus;
|
||||
import org.briarproject.bramble.api.sync.Offer;
|
||||
import org.briarproject.bramble.api.sync.Request;
|
||||
import org.briarproject.bramble.api.sync.event.GroupAddedEvent;
|
||||
@@ -77,6 +78,7 @@ import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
@@ -1319,6 +1321,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
TransportKeys transportKeys = createTransportKeys();
|
||||
KeySet ks = new KeySet(keySetId, contactId, transportKeys);
|
||||
Collection<KeySet> keys = singletonList(ks);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// startTransaction()
|
||||
oneOf(database).startTransaction();
|
||||
@@ -1348,6 +1351,114 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMessageStatusByGroupId() throws Exception {
|
||||
MessageStatus status =
|
||||
new MessageStatus(messageId, contactId, true, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// startTransaction()
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
// getMessageStatus()
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).containsGroup(txn, groupId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getGroupVisibility(txn, contactId, groupId);
|
||||
will(returnValue(VISIBLE));
|
||||
oneOf(database).getMessageStatus(txn, contactId, groupId);
|
||||
will(returnValue(singletonList(status)));
|
||||
// getMessageStatus() again
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).containsGroup(txn, groupId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getGroupVisibility(txn, contactId, groupId);
|
||||
will(returnValue(INVISIBLE));
|
||||
oneOf(database).getMessageIds(txn, groupId);
|
||||
will(returnValue(singletonList(messageId)));
|
||||
// endTransaction()
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||
shutdown);
|
||||
|
||||
Transaction transaction = db.startTransaction(true);
|
||||
try {
|
||||
// With visible group - return stored status
|
||||
Collection<MessageStatus> statuses =
|
||||
db.getMessageStatus(transaction, contactId, groupId);
|
||||
assertEquals(1, statuses.size());
|
||||
MessageStatus s = statuses.iterator().next();
|
||||
assertEquals(messageId, s.getMessageId());
|
||||
assertEquals(contactId, s.getContactId());
|
||||
assertTrue(s.isSent());
|
||||
assertTrue(s.isSeen());
|
||||
// With invisible group - return default status
|
||||
statuses = db.getMessageStatus(transaction, contactId, groupId);
|
||||
assertEquals(1, statuses.size());
|
||||
s = statuses.iterator().next();
|
||||
assertEquals(messageId, s.getMessageId());
|
||||
assertEquals(contactId, s.getContactId());
|
||||
assertFalse(s.isSent());
|
||||
assertFalse(s.isSeen());
|
||||
db.commitTransaction(transaction);
|
||||
} finally {
|
||||
db.endTransaction(transaction);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMessageStatusByMessageId() throws Exception {
|
||||
MessageStatus status =
|
||||
new MessageStatus(messageId, contactId, true, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// startTransaction()
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
// getMessageStatus()
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).containsMessage(txn, messageId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getMessageStatus(txn, contactId, messageId);
|
||||
will(returnValue(status));
|
||||
// getMessageStatus() again
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).containsMessage(txn, messageId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getMessageStatus(txn, contactId, messageId);
|
||||
will(returnValue(null));
|
||||
// endTransaction()
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||
shutdown);
|
||||
|
||||
Transaction transaction = db.startTransaction(true);
|
||||
try {
|
||||
// With visible group - return stored status
|
||||
MessageStatus s =
|
||||
db.getMessageStatus(transaction, contactId, messageId);
|
||||
assertEquals(messageId, s.getMessageId());
|
||||
assertEquals(contactId, s.getContactId());
|
||||
assertTrue(s.isSent());
|
||||
assertTrue(s.isSeen());
|
||||
// With invisible group - return default status
|
||||
s = db.getMessageStatus(transaction, contactId, messageId);
|
||||
assertEquals(messageId, s.getMessageId());
|
||||
assertEquals(contactId, s.getContactId());
|
||||
assertFalse(s.isSent());
|
||||
assertFalse(s.isSeen());
|
||||
db.commitTransaction(transaction);
|
||||
} finally {
|
||||
db.endTransaction(transaction);
|
||||
}
|
||||
}
|
||||
|
||||
private TransportKeys createTransportKeys() {
|
||||
SecretKey inPrevTagKey = getSecretKey();
|
||||
SecretKey inPrevHeaderKey = getSecretKey();
|
||||
|
||||
@@ -1596,6 +1596,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
|
||||
// The message should not be sent or seen
|
||||
MessageStatus status = db.getMessageStatus(txn, contactId, messageId);
|
||||
assertNotNull(status);
|
||||
assertEquals(messageId, status.getMessageId());
|
||||
assertEquals(contactId, status.getContactId());
|
||||
assertFalse(status.isSent());
|
||||
@@ -1616,6 +1617,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
|
||||
// The message should be sent but not seen
|
||||
status = db.getMessageStatus(txn, contactId, messageId);
|
||||
assertNotNull(status);
|
||||
assertEquals(messageId, status.getMessageId());
|
||||
assertEquals(contactId, status.getContactId());
|
||||
assertTrue(status.isSent());
|
||||
@@ -1635,6 +1637,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
|
||||
// The message should be sent and seen
|
||||
status = db.getMessageStatus(txn, contactId, messageId);
|
||||
assertNotNull(status);
|
||||
assertEquals(messageId, status.getMessageId());
|
||||
assertEquals(contactId, status.getContactId());
|
||||
assertTrue(status.isSent());
|
||||
@@ -1649,6 +1652,36 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
assertTrue(status.isSent());
|
||||
assertTrue(status.isSeen());
|
||||
|
||||
// Make the group invisible to the contact
|
||||
db.removeGroupVisibility(txn, contactId, groupId);
|
||||
|
||||
// Null should be returned when querying by message
|
||||
assertNull(db.getMessageStatus(txn, contactId, messageId));
|
||||
|
||||
// No statuses should be returned when querying by group
|
||||
statuses = db.getMessageStatus(txn, contactId, groupId);
|
||||
assertEquals(0, statuses.size());
|
||||
|
||||
// Make the group visible to the contact again
|
||||
db.addGroupVisibility(txn, contactId, groupId, false);
|
||||
|
||||
// The default status should be returned when querying by message
|
||||
status = db.getMessageStatus(txn, contactId, messageId);
|
||||
assertNotNull(status);
|
||||
assertEquals(messageId, status.getMessageId());
|
||||
assertEquals(contactId, status.getContactId());
|
||||
assertFalse(status.isSent());
|
||||
assertFalse(status.isSeen());
|
||||
|
||||
// The default status should be returned when querying by group
|
||||
statuses = db.getMessageStatus(txn, contactId, groupId);
|
||||
assertEquals(1, statuses.size());
|
||||
status = statuses.iterator().next();
|
||||
assertEquals(messageId, status.getMessageId());
|
||||
assertEquals(contactId, status.getContactId());
|
||||
assertFalse(status.isSent());
|
||||
assertFalse(status.isSeen());
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user