Assert that expected event is broadcasted

This commit is contained in:
Daniel Lublin
2021-03-09 13:50:35 +01:00
parent 144bd7bf1d
commit 647467a51a
3 changed files with 25 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
package org.briarproject.briar.sharing; package org.briarproject.briar.sharing;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.autodelete.event.ConversationMessagesDeletedEvent;
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
import org.briarproject.briar.api.sharing.InvitationResponse; import org.briarproject.briar.api.sharing.InvitationResponse;
import org.briarproject.briar.api.sharing.Shareable; import org.briarproject.briar.api.sharing.Shareable;
import org.briarproject.briar.api.sharing.SharingManager; import org.briarproject.briar.api.sharing.SharingManager;
@@ -8,6 +10,7 @@ import org.briarproject.briar.autodelete.AbstractAutoDeleteTest;
import static org.briarproject.bramble.api.cleanup.CleanupManager.BATCH_DELAY_MS; import static org.briarproject.bramble.api.cleanup.CleanupManager.BATCH_DELAY_MS;
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS; import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
import static org.briarproject.briar.test.TestEventListener.assertEvent;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
@@ -18,6 +21,8 @@ public abstract class AbstractAutoDeleteIntegrationTest
protected SharingManager<? extends Shareable> sharingManager0; protected SharingManager<? extends Shareable> sharingManager0;
protected Shareable shareable; protected Shareable shareable;
protected Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>>
responseReceivedEventClass;
protected void testAutoDeclinedSharing( protected void testAutoDeclinedSharing(
SharingManager<? extends Shareable> sharingManager0, SharingManager<? extends Shareable> sharingManager0,
@@ -64,8 +69,14 @@ public abstract class AbstractAutoDeleteIntegrationTest
// When 0's timer has elapsed, the message should be deleted from 0's // When 0's timer has elapsed, the message should be deleted from 0's
// view of the conversation but 1 should still see the message // view of the conversation but 1 should still see the message
c0.getTimeTravel().addCurrentTimeMillis(1); ConversationMessagesDeletedEvent event =
assertEvent(c0, ConversationMessagesDeletedEvent.class,
() -> c0.getTimeTravel().addCurrentTimeMillis(1)
);
c1.getTimeTravel().addCurrentTimeMillis(1); c1.getTimeTravel().addCurrentTimeMillis(1);
// assert that the proper event got broadcast
assertEquals(contactId1From0, event.getContactId());
assertGroupCount(c0, contactId1From0, 0, 0); assertGroupCount(c0, contactId1From0, 0, 0);
assertEquals(0, getMessageHeaders(c0, contactId1From0).size()); assertEquals(0, getMessageHeaders(c0, contactId1From0).size());
assertGroupCount(c1, contactId0From1, 1, 1); assertGroupCount(c1, contactId0From1, 1, 1);
@@ -88,7 +99,13 @@ public abstract class AbstractAutoDeleteIntegrationTest
// When 1's timer has elapsed, the message should be deleted from 1's // When 1's timer has elapsed, the message should be deleted from 1's
// view of the conversation and the invitation auto-declined // view of the conversation and the invitation auto-declined
c0.getTimeTravel().addCurrentTimeMillis(1); c0.getTimeTravel().addCurrentTimeMillis(1);
c1.getTimeTravel().addCurrentTimeMillis(1); ConversationMessageReceivedEvent<? extends InvitationResponse> e =
assertEvent(c1, responseReceivedEventClass,
() -> c1.getTimeTravel().addCurrentTimeMillis(1)
);
// assert that the proper event got broadcast
assertEquals(contactId0From1, e.getContactId());
assertGroupCount(c0, contactId1From0, 0, 0); assertGroupCount(c0, contactId1From0, 0, 0);
assertEquals(0, getMessageHeaders(c0, contactId1From0).size()); assertEquals(0, getMessageHeaders(c0, contactId1From0).size());
assertGroupCount(c1, contactId0From1, 1, 0); assertGroupCount(c1, contactId0From1, 1, 0);
@@ -96,6 +113,7 @@ public abstract class AbstractAutoDeleteIntegrationTest
// The only message is not the same as before, but declined response // The only message is not the same as before, but declined response
assertNotEquals(messageId0, h.getId()); assertNotEquals(messageId0, h.getId());
assertTrue(h instanceof InvitationResponse); assertTrue(h instanceof InvitationResponse);
assertEquals(h.getId(), e.getMessageHeader().getId());
assertFalse(((InvitationResponse) h).wasAccepted()); assertFalse(((InvitationResponse) h).wasAccepted());
assertTrue(((InvitationResponse) h).isAutoDecline()); assertTrue(((InvitationResponse) h).isAutoDecline());
// The auto-decline message should have the expected timer // The auto-decline message should have the expected timer

View File

@@ -1,5 +1,6 @@
package org.briarproject.briar.sharing; package org.briarproject.briar.sharing;
import org.briarproject.briar.api.blog.event.BlogInvitationResponseReceivedEvent;
import org.briarproject.briar.api.conversation.ConversationManager; import org.briarproject.briar.api.conversation.ConversationManager;
import org.briarproject.briar.test.BriarIntegrationTestComponent; import org.briarproject.briar.test.BriarIntegrationTestComponent;
import org.junit.Before; import org.junit.Before;
@@ -16,6 +17,7 @@ public class AutoDeleteBlogIntegrationTest
shareable = c0.getBlogManager().getPersonalBlog(author2); shareable = c0.getBlogManager().getPersonalBlog(author2);
sharingManager0 = c0.getBlogSharingManager(); sharingManager0 = c0.getBlogSharingManager();
addContacts1And2(); addContacts1And2();
responseReceivedEventClass = BlogInvitationResponseReceivedEvent.class;
} }
@Override @Override

View File

@@ -1,7 +1,7 @@
package org.briarproject.briar.sharing; package org.briarproject.briar.sharing;
import org.briarproject.briar.api.conversation.ConversationManager; import org.briarproject.briar.api.conversation.ConversationManager;
import org.briarproject.briar.api.forum.ForumManager; import org.briarproject.briar.api.forum.event.ForumInvitationResponseReceivedEvent;
import org.briarproject.briar.test.BriarIntegrationTestComponent; import org.briarproject.briar.test.BriarIntegrationTestComponent;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -13,10 +13,10 @@ public class AutoDeleteForumIntegrationTest
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
ForumManager forumManager0 = c0.getForumManager(); shareable = c0.getForumManager().addForum("Test Forum");
shareable = forumManager0.addForum("Test Forum");
sharingManager0 = c0.getForumSharingManager(); sharingManager0 = c0.getForumSharingManager();
addContacts1And2(); addContacts1And2();
responseReceivedEventClass = ForumInvitationResponseReceivedEvent.class;
} }
@Override @Override