mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
Replaced Database.getParent() with getGroupMessageParent().
The new method checks whether the parent is present in the database and belongs to the same group, so separate methods for those checks have been removed.
This commit is contained in:
@@ -105,9 +105,7 @@ public class DatabaseComponentImplTest extends DatabaseComponentTest {
|
||||
will(returnValue(Collections.singleton(messageId)));
|
||||
oneOf(database).getSendability(txn, messageId);
|
||||
will(returnValue(1));
|
||||
oneOf(database).getGroup(txn, messageId);
|
||||
will(returnValue(groupId));
|
||||
oneOf(database).getParent(txn, messageId);
|
||||
oneOf(database).getGroupMessageParent(txn, messageId);
|
||||
will(returnValue(null));
|
||||
oneOf(database).removeMessage(txn, messageId);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
|
||||
@@ -200,117 +200,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
will(returnValue(0));
|
||||
oneOf(database).setSendability(txn, messageId, 1);
|
||||
// Backward inclusion stops when the message has no parent
|
||||
oneOf(database).getGroup(txn, messageId);
|
||||
will(returnValue(groupId));
|
||||
oneOf(database).getParent(txn, messageId);
|
||||
will(returnValue(null));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||
|
||||
db.setRating(authorId, Rating.GOOD);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingParentStopsBackwardInclusion() throws DbException {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
context.checking(new Expectations() {{
|
||||
// setRating(Rating.GOOD)
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).setRating(txn, authorId, Rating.GOOD);
|
||||
// The sendability of the author's messages should be incremented
|
||||
oneOf(database).getMessagesByAuthor(txn, authorId);
|
||||
will(returnValue(Collections.singletonList(messageId)));
|
||||
oneOf(database).getSendability(txn, messageId);
|
||||
will(returnValue(0));
|
||||
oneOf(database).setSendability(txn, messageId, 1);
|
||||
// The parent exists
|
||||
oneOf(database).getGroup(txn, messageId);
|
||||
will(returnValue(groupId));
|
||||
oneOf(database).getParent(txn, messageId);
|
||||
will(returnValue(parentId));
|
||||
// The parent isn't in the DB
|
||||
oneOf(database).containsMessage(txn, parentId);
|
||||
will(returnValue(false));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||
|
||||
db.setRating(authorId, Rating.GOOD);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParentInAnotherGroupStopsBackwardInclusion()
|
||||
throws DbException {
|
||||
final GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
context.checking(new Expectations() {{
|
||||
// setRating(Rating.GOOD)
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).setRating(txn, authorId, Rating.GOOD);
|
||||
// The sendability of the author's messages should be incremented
|
||||
oneOf(database).getMessagesByAuthor(txn, authorId);
|
||||
will(returnValue(Collections.singletonList(messageId)));
|
||||
oneOf(database).getSendability(txn, messageId);
|
||||
will(returnValue(0));
|
||||
oneOf(database).setSendability(txn, messageId, 1);
|
||||
// The parent exists and is in the database
|
||||
oneOf(database).getGroup(txn, messageId);
|
||||
will(returnValue(groupId));
|
||||
oneOf(database).getParent(txn, messageId);
|
||||
will(returnValue(parentId));
|
||||
oneOf(database).containsMessage(txn, parentId);
|
||||
will(returnValue(true));
|
||||
// The parent is in a different group
|
||||
oneOf(database).getGroup(txn, parentId);
|
||||
will(returnValue(groupId1));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||
|
||||
db.setRating(authorId, Rating.GOOD);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrivateParentStopsBackwardInclusion() throws DbException {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
context.checking(new Expectations() {{
|
||||
// setRating(Rating.GOOD)
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).setRating(txn, authorId, Rating.GOOD);
|
||||
// The sendability of the author's messages should be incremented
|
||||
oneOf(database).getMessagesByAuthor(txn, authorId);
|
||||
will(returnValue(Collections.singletonList(messageId)));
|
||||
oneOf(database).getSendability(txn, messageId);
|
||||
will(returnValue(0));
|
||||
oneOf(database).setSendability(txn, messageId, 1);
|
||||
// The parent exists and is in the database
|
||||
oneOf(database).getGroup(txn, messageId);
|
||||
will(returnValue(groupId));
|
||||
oneOf(database).getParent(txn, messageId);
|
||||
will(returnValue(parentId));
|
||||
oneOf(database).containsMessage(txn, parentId);
|
||||
will(returnValue(true));
|
||||
// The parent is a private message
|
||||
oneOf(database).getGroup(txn, parentId);
|
||||
oneOf(database).getGroupMessageParent(txn, messageId);
|
||||
will(returnValue(null));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
@@ -340,14 +230,8 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
will(returnValue(0));
|
||||
oneOf(database).setSendability(txn, messageId, 1);
|
||||
// The parent exists, is in the DB, and is in the same group
|
||||
oneOf(database).getGroup(txn, messageId);
|
||||
will(returnValue(groupId));
|
||||
oneOf(database).getParent(txn, messageId);
|
||||
oneOf(database).getGroupMessageParent(txn, messageId);
|
||||
will(returnValue(parentId));
|
||||
oneOf(database).containsMessage(txn, parentId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getGroup(txn, parentId);
|
||||
will(returnValue(groupId));
|
||||
// The parent is already sendable
|
||||
oneOf(database).getSendability(txn, parentId);
|
||||
will(returnValue(1));
|
||||
@@ -380,19 +264,14 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
will(returnValue(0));
|
||||
oneOf(database).setSendability(txn, messageId, 1);
|
||||
// The parent exists, is in the DB, and is in the same group
|
||||
oneOf(database).getGroup(txn, messageId);
|
||||
will(returnValue(groupId));
|
||||
oneOf(database).getParent(txn, messageId);
|
||||
oneOf(database).getGroupMessageParent(txn, messageId);
|
||||
will(returnValue(parentId));
|
||||
oneOf(database).containsMessage(txn, parentId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getGroup(txn, parentId);
|
||||
will(returnValue(groupId));
|
||||
// The parent is not already sendable
|
||||
oneOf(database).getSendability(txn, parentId);
|
||||
will(returnValue(0));
|
||||
oneOf(database).setSendability(txn, parentId, 1);
|
||||
oneOf(database).getParent(txn, parentId);
|
||||
// The parent has no parent
|
||||
oneOf(database).getGroupMessageParent(txn, parentId);
|
||||
will(returnValue(null));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
@@ -505,9 +384,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
will(returnValue(2));
|
||||
oneOf(database).setSendability(txn, messageId, 3);
|
||||
// The sendability of the message's ancestors should be updated
|
||||
oneOf(database).getGroup(txn, messageId);
|
||||
will(returnValue(groupId));
|
||||
oneOf(database).getParent(txn, messageId);
|
||||
oneOf(database).getGroupMessageParent(txn, messageId);
|
||||
will(returnValue(null));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
@@ -1155,9 +1032,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
oneOf(database).getNumberOfSendableChildren(txn, messageId);
|
||||
will(returnValue(1));
|
||||
oneOf(database).setSendability(txn, messageId, 2);
|
||||
oneOf(database).getGroup(txn, messageId);
|
||||
will(returnValue(groupId));
|
||||
oneOf(database).getParent(txn, messageId);
|
||||
oneOf(database).getGroupMessageParent(txn, messageId);
|
||||
will(returnValue(null));
|
||||
// The batch needs to be acknowledged
|
||||
oneOf(batch).getId();
|
||||
|
||||
@@ -1430,6 +1430,127 @@ public class H2DatabaseTest extends TestCase {
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupMessageParentWithNoParent() throws DbException {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Subscribe to a group
|
||||
db.addSubscription(txn, group);
|
||||
|
||||
// A message with no parent should return null
|
||||
MessageId childId = new MessageId(TestUtils.getRandomId());
|
||||
Message child = new TestMessage(childId, null, groupId, null,
|
||||
timestamp, raw);
|
||||
db.addGroupMessage(txn, child);
|
||||
assertTrue(db.containsMessage(txn, childId));
|
||||
assertNull(db.getGroupMessageParent(txn, childId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupMessageParentWithAbsentParent() throws DbException {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Subscribe to a group
|
||||
db.addSubscription(txn, group);
|
||||
|
||||
// A message with an absent parent should return null
|
||||
MessageId childId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId parentId = new MessageId(TestUtils.getRandomId());
|
||||
Message child = new TestMessage(childId, parentId, groupId, null,
|
||||
timestamp, raw);
|
||||
db.addGroupMessage(txn, child);
|
||||
assertTrue(db.containsMessage(txn, childId));
|
||||
assertFalse(db.containsMessage(txn, parentId));
|
||||
assertNull(db.getGroupMessageParent(txn, childId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupMessageParentWithParentInAnotherGroup()
|
||||
throws DbException {
|
||||
GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
||||
Group group1 = groupFactory.createGroup(groupId1, "Group name", null);
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Subscribe to two groups
|
||||
db.addSubscription(txn, group);
|
||||
db.addSubscription(txn, group1);
|
||||
|
||||
// A message with a parent in another group should return null
|
||||
MessageId childId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId parentId = new MessageId(TestUtils.getRandomId());
|
||||
Message child = new TestMessage(childId, parentId, groupId, null,
|
||||
timestamp, raw);
|
||||
Message parent = new TestMessage(parentId, null, groupId1, null,
|
||||
timestamp, raw);
|
||||
db.addGroupMessage(txn, child);
|
||||
db.addGroupMessage(txn, parent);
|
||||
assertTrue(db.containsMessage(txn, childId));
|
||||
assertTrue(db.containsMessage(txn, parentId));
|
||||
assertNull(db.getGroupMessageParent(txn, childId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupMessageParentWithPrivateParent()
|
||||
throws DbException {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
assertEquals(contactId, db.addContact(txn, transports, secret));
|
||||
db.addSubscription(txn, group);
|
||||
|
||||
// A message with a private parent should return null
|
||||
MessageId childId = new MessageId(TestUtils.getRandomId());
|
||||
Message child = new TestMessage(childId, privateMessageId, groupId, null,
|
||||
timestamp, raw);
|
||||
db.addGroupMessage(txn, child);
|
||||
db.addPrivateMessage(txn, privateMessage, contactId);
|
||||
assertTrue(db.containsMessage(txn, childId));
|
||||
assertTrue(db.containsMessage(txn, privateMessageId));
|
||||
assertNull(db.getGroupMessageParent(txn, childId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupMessageParentWithParentInSameGroup()
|
||||
throws DbException {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Subscribe to a group
|
||||
db.addSubscription(txn, group);
|
||||
|
||||
// A message with a parent in the same group should return the parent
|
||||
MessageId childId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId parentId = new MessageId(TestUtils.getRandomId());
|
||||
Message child = new TestMessage(childId, parentId, groupId, null,
|
||||
timestamp, raw);
|
||||
Message parent = new TestMessage(parentId, null, groupId, null,
|
||||
timestamp, raw);
|
||||
db.addGroupMessage(txn, child);
|
||||
db.addGroupMessage(txn, parent);
|
||||
assertTrue(db.containsMessage(txn, childId));
|
||||
assertTrue(db.containsMessage(txn, parentId));
|
||||
assertEquals(parentId, db.getGroupMessageParent(txn, childId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionHandling() throws DbException {
|
||||
Database<Connection> db = open(false);
|
||||
|
||||
Reference in New Issue
Block a user