mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Unify all private message responses in one PrivateResponse class
This also adds `Shareable`s to invitation response which is a precondition for #561
This commit is contained in:
@@ -159,7 +159,7 @@ public class IntroductionIntegrationTest
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.response1Received);
|
||||
assertEquals(introducee2.getAuthor().getName(),
|
||||
listener0.getResponse().getName());
|
||||
listener0.getResponse().getObject().getName());
|
||||
assertGroupCount(messageTracker0, g1.getId(), 2, 1);
|
||||
|
||||
// sync second ACCEPT message
|
||||
@@ -167,7 +167,7 @@ public class IntroductionIntegrationTest
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.response2Received);
|
||||
assertEquals(introducee1.getAuthor().getName(),
|
||||
listener0.getResponse().getName());
|
||||
listener0.getResponse().getObject().getName());
|
||||
assertGroupCount(messageTracker0, g2.getId(), 2, 1);
|
||||
|
||||
// sync forwarded ACCEPT messages to introducees
|
||||
@@ -265,7 +265,7 @@ public class IntroductionIntegrationTest
|
||||
|
||||
// assert that the name on the decline event is correct
|
||||
assertEquals(introducee2.getAuthor().getName(),
|
||||
listener0.getResponse().getName());
|
||||
listener0.getResponse().getObject().getName());
|
||||
|
||||
// sync second response
|
||||
sync2To0(1, true);
|
||||
@@ -282,7 +282,7 @@ public class IntroductionIntegrationTest
|
||||
// assert that the name on the decline event is correct
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertEquals(introducee1.getAuthor().getName(),
|
||||
listener2.getResponse().getName());
|
||||
listener2.getResponse().getObject().getName());
|
||||
|
||||
// note how the introducer does not forward the second response,
|
||||
// because after the first decline the protocol finished
|
||||
@@ -351,7 +351,7 @@ public class IntroductionIntegrationTest
|
||||
// assert that the name on the decline event is correct
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertEquals(contact2From0.getAuthor().getName(),
|
||||
listener1.getResponse().getName());
|
||||
listener1.getResponse().getObject().getName());
|
||||
|
||||
assertFalse(contactManager1
|
||||
.contactExists(author2.getId(), author1.getId()));
|
||||
@@ -475,7 +475,7 @@ public class IntroductionIntegrationTest
|
||||
// assert that the name on the decline event is correct
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertEquals(introducee1.getAuthor().getName(),
|
||||
listener2.getResponse().getName());
|
||||
listener2.getResponse().getObject().getName());
|
||||
|
||||
// assert that introducee2 is in correct state
|
||||
introduceeSession = getIntroduceeSession(c2);
|
||||
|
||||
@@ -310,6 +310,8 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
oneOf(messageTracker)
|
||||
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
|
||||
false);
|
||||
oneOf(privateGroupManager).getPrivateGroup(txn, privateGroupId);
|
||||
will(returnValue(privateGroup));
|
||||
}});
|
||||
expectGetContactId();
|
||||
expectSetPrivateGroupVisibility(SHARED);
|
||||
@@ -399,6 +401,8 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
oneOf(messageTracker)
|
||||
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
|
||||
false);
|
||||
oneOf(privateGroupManager).getPrivateGroup(txn, privateGroupId);
|
||||
will(returnValue(privateGroup));
|
||||
}});
|
||||
expectGetContactId();
|
||||
CreatorSession newSession =
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject.briar.privategroup.invitation;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
@@ -12,7 +13,6 @@ import org.briarproject.briar.api.privategroup.invitation.GroupInvitationItem;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
import org.briarproject.briar.test.BriarIntegrationTest;
|
||||
import org.briarproject.briar.test.BriarIntegrationTestComponent;
|
||||
import org.briarproject.briar.test.DaggerBriarIntegrationTestComponent;
|
||||
@@ -124,7 +124,8 @@ public class GroupInvitationIntegrationTest
|
||||
for (PrivateMessageHeader m : messages) {
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
InvitationResponse response = (GroupInvitationResponse) m;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertEquals(privateGroup0, response.getObject());
|
||||
assertTrue(response.isLocal());
|
||||
assertFalse(response.wasAccepted());
|
||||
}
|
||||
@@ -140,7 +141,8 @@ public class GroupInvitationIntegrationTest
|
||||
for (PrivateMessageHeader m : messages) {
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
InvitationResponse response = (GroupInvitationResponse) m;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertEquals(privateGroup0, response.getObject());
|
||||
assertFalse(response.isLocal());
|
||||
assertFalse(response.wasAccepted());
|
||||
}
|
||||
@@ -171,24 +173,27 @@ public class GroupInvitationIntegrationTest
|
||||
for (PrivateMessageHeader m : messages) {
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
InvitationResponse response = (GroupInvitationResponse) m;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertEquals(privateGroup0, response.getObject());
|
||||
assertTrue(response.wasAccepted());
|
||||
} else {
|
||||
assertTrue(((GroupInvitationRequest) m).doesExist());
|
||||
GroupInvitationRequest request = (GroupInvitationRequest) m;
|
||||
assertEquals(privateGroup0, request.getObject());
|
||||
assertTrue(request.doesExist());
|
||||
}
|
||||
}
|
||||
assertTrue(foundResponse);
|
||||
|
||||
sync1To0(1, true);
|
||||
|
||||
messages =
|
||||
groupInvitationManager0.getMessages(contactId1From0);
|
||||
messages = groupInvitationManager0.getMessages(contactId1From0);
|
||||
assertEquals(2, messages.size());
|
||||
foundResponse = false;
|
||||
for (PrivateMessageHeader m : messages) {
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
InvitationResponse response = (GroupInvitationResponse) m;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertEquals(privateGroup0, response.getObject());
|
||||
assertTrue(response.wasAccepted());
|
||||
}
|
||||
}
|
||||
@@ -432,6 +437,36 @@ public class GroupInvitationIntegrationTest
|
||||
sync1To0(1, true);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testDeleteOnlyInvitationFails() throws Exception {
|
||||
// send invitation
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sync0To1(1, true);
|
||||
|
||||
// save MessageId of invitation
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
groupInvitationManager1.getMessages(contactId0From1);
|
||||
assertEquals(1, messages.size());
|
||||
MessageId inviteId = messages.iterator().next().getId();
|
||||
|
||||
// decline invitation
|
||||
groupInvitationManager1
|
||||
.respondToInvitation(contactId0From1, privateGroup0, false);
|
||||
|
||||
// we should have an invitation and a decline message
|
||||
messages = groupInvitationManager1.getMessages(contactId0From1);
|
||||
assertEquals(2, messages.size());
|
||||
|
||||
// delete only invitation
|
||||
withinTransaction(db1, txn -> {
|
||||
db1.deleteMessage(txn, inviteId);
|
||||
db1.deleteMessageMetadata(txn, inviteId);
|
||||
});
|
||||
|
||||
// This should fail
|
||||
groupInvitationManager1.getMessages(contactId0From1);
|
||||
}
|
||||
|
||||
private void sendInvitation(long timestamp, @Nullable String msg) throws
|
||||
DbException {
|
||||
byte[] signature = groupInvitationFactory.signInvitation(contact1From0,
|
||||
|
||||
@@ -682,6 +682,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
contactGroup.getId(), query);
|
||||
will(returnValue(results));
|
||||
// first message
|
||||
oneOf(messageParser).parseMetadata(meta2);
|
||||
will(returnValue(messageMetadata2));
|
||||
oneOf(messageParser).parseMetadata(meta);
|
||||
will(returnValue(messageMetadata1));
|
||||
oneOf(db).getMessageStatus(txn, contactId, message.getId());
|
||||
@@ -695,6 +697,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
// second message
|
||||
oneOf(messageParser).parseMetadata(meta2);
|
||||
will(returnValue(messageMetadata2));
|
||||
oneOf(messageParser).parseMetadata(meta);
|
||||
will(returnValue(messageMetadata1));
|
||||
oneOf(db).getMessageStatus(txn, contactId, messageId2);
|
||||
// end transaction
|
||||
oneOf(db).commitTransaction(txn);
|
||||
@@ -709,9 +713,11 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
if (m.getId().equals(message.getId())) {
|
||||
assertTrue(m instanceof GroupInvitationRequest);
|
||||
assertEquals(time1, m.getTimestamp());
|
||||
assertEquals(pg, ((GroupInvitationRequest) m).getObject());
|
||||
} else if (m.getId().equals(messageId2)) {
|
||||
assertTrue(m instanceof GroupInvitationResponse);
|
||||
assertEquals(time2, m.getTimestamp());
|
||||
assertEquals(pg, ((GroupInvitationResponse) m).getObject());
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@@ -154,6 +154,7 @@ public class BlogSharingIntegrationTest
|
||||
for (PrivateMessageHeader m : list) {
|
||||
if (m instanceof BlogInvitationRequest) {
|
||||
BlogInvitationRequest invitation = (BlogInvitationRequest) m;
|
||||
assertEquals(blog2, invitation.getObject());
|
||||
assertFalse(invitation.wasAnswered());
|
||||
assertEquals(blog2.getAuthor().getName(),
|
||||
invitation.getName());
|
||||
@@ -161,6 +162,7 @@ public class BlogSharingIntegrationTest
|
||||
assertEquals("Hi!", invitation.getMessage());
|
||||
} else {
|
||||
BlogInvitationResponse response = (BlogInvitationResponse) m;
|
||||
assertEquals(blog2, response.getObject());
|
||||
assertTrue(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
@@ -225,6 +227,7 @@ public class BlogSharingIntegrationTest
|
||||
for (PrivateMessageHeader m : list) {
|
||||
if (m instanceof BlogInvitationRequest) {
|
||||
BlogInvitationRequest invitation = (BlogInvitationRequest) m;
|
||||
assertEquals(rssBlog, invitation.getObject());
|
||||
assertFalse(invitation.wasAnswered());
|
||||
assertEquals(rssBlog.getAuthor().getName(),
|
||||
invitation.getName());
|
||||
@@ -232,6 +235,7 @@ public class BlogSharingIntegrationTest
|
||||
assertEquals("Hi!", invitation.getMessage());
|
||||
} else {
|
||||
BlogInvitationResponse response = (BlogInvitationResponse) m;
|
||||
assertEquals(rssBlog, response.getObject());
|
||||
assertTrue(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
@@ -284,12 +288,14 @@ public class BlogSharingIntegrationTest
|
||||
for (PrivateMessageHeader m : list) {
|
||||
if (m instanceof BlogInvitationRequest) {
|
||||
BlogInvitationRequest invitation = (BlogInvitationRequest) m;
|
||||
assertEquals(blog2, invitation.getObject());
|
||||
assertFalse(invitation.wasAnswered());
|
||||
assertEquals(blog2.getAuthor().getName(),
|
||||
invitation.getName());
|
||||
assertEquals(null, invitation.getMessage());
|
||||
} else {
|
||||
BlogInvitationResponse response = (BlogInvitationResponse) m;
|
||||
assertEquals(blog2, response.getObject());
|
||||
assertFalse(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
@@ -612,7 +618,7 @@ public class BlogSharingIntegrationTest
|
||||
}
|
||||
}
|
||||
|
||||
private void listenToEvents(boolean accept) throws DbException {
|
||||
private void listenToEvents(boolean accept) {
|
||||
listener0 = new SharerListener();
|
||||
c0.getEventBus().addListener(listener0);
|
||||
listener1 = new InviteeListener(accept);
|
||||
|
||||
@@ -137,15 +137,15 @@ public class ForumSharingIntegrationTest
|
||||
// check other things are alright with the forum message
|
||||
for (PrivateMessageHeader m : list) {
|
||||
if (m instanceof ForumInvitationRequest) {
|
||||
ForumInvitationRequest invitation =
|
||||
(ForumInvitationRequest) m;
|
||||
ForumInvitationRequest invitation = (ForumInvitationRequest) m;
|
||||
assertFalse(invitation.wasAnswered());
|
||||
assertEquals(forum0.getName(), invitation.getName());
|
||||
assertEquals(forum0, invitation.getObject());
|
||||
assertEquals("Hi!", invitation.getMessage());
|
||||
assertTrue(invitation.doesExist());
|
||||
} else {
|
||||
ForumInvitationResponse response =
|
||||
(ForumInvitationResponse) m;
|
||||
ForumInvitationResponse response = (ForumInvitationResponse) m;
|
||||
assertEquals(forum0, response.getObject());
|
||||
assertTrue(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
@@ -195,12 +195,14 @@ public class ForumSharingIntegrationTest
|
||||
for (PrivateMessageHeader m : list) {
|
||||
if (m instanceof ForumInvitationRequest) {
|
||||
ForumInvitationRequest invitation = (ForumInvitationRequest) m;
|
||||
assertEquals(forum0, invitation.getObject());
|
||||
assertFalse(invitation.wasAnswered());
|
||||
assertEquals(forum0.getName(), invitation.getName());
|
||||
assertEquals(null, invitation.getMessage());
|
||||
assertFalse(invitation.doesExist());
|
||||
} else {
|
||||
ForumInvitationResponse response = (ForumInvitationResponse) m;
|
||||
assertEquals(forum0, response.getObject());
|
||||
assertFalse(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.briarproject.bramble.api.contact.ContactManager;
|
||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||
@@ -376,4 +377,21 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
||||
assertNotNull(contactId1From2);
|
||||
contactManager2.removeContact(contactId1From2);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface TransactionScope {
|
||||
void execute(Transaction txn) throws DbException;
|
||||
}
|
||||
|
||||
protected void withinTransaction(DatabaseComponent db, TransactionScope scope)
|
||||
throws DbException {
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
scope.execute(txn);
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user