mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Start working on integration test
This commit is contained in:
@@ -2,7 +2,6 @@ package org.briarproject.briar.socialbackup;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.bramble.api.Pair;
|
import org.briarproject.bramble.api.Pair;
|
||||||
import org.briarproject.bramble.api.client.BdfIncomingMessageHook;
|
|
||||||
import org.briarproject.bramble.api.client.ClientHelper;
|
import org.briarproject.bramble.api.client.ClientHelper;
|
||||||
import org.briarproject.bramble.api.client.ContactGroupFactory;
|
import org.briarproject.bramble.api.client.ContactGroupFactory;
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
@@ -277,6 +276,7 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Group getContactGroup(Contact c) {
|
public Group getContactGroup(Contact c) {
|
||||||
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||||
MAJOR_VERSION, c);
|
MAJOR_VERSION, c);
|
||||||
@@ -294,11 +294,18 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
for (Entry<MessageId, BdfDictionary> messageEntry : messages
|
for (Entry<MessageId, BdfDictionary> messageEntry : messages
|
||||||
.entrySet()) {
|
.entrySet()) {
|
||||||
BdfDictionary message = messageEntry.getValue();
|
BdfDictionary meta = messageEntry.getValue();
|
||||||
if (message.getLong(MSG_KEY_MESSAGE_TYPE).intValue() ==
|
if (meta.getLong(MSG_KEY_MESSAGE_TYPE).intValue() ==
|
||||||
SHARD.getValue()) {
|
SHARD.getValue()) {
|
||||||
long timestamp = message.getLong(MSG_KEY_TIMESTAMP);
|
boolean isLocal = meta.getBoolean(MSG_KEY_LOCAL);
|
||||||
boolean isLocal = message.getBoolean(MSG_KEY_LOCAL);
|
long timestamp;
|
||||||
|
if (isLocal) {
|
||||||
|
timestamp = meta.getLong(MSG_KEY_TIMESTAMP);
|
||||||
|
} else {
|
||||||
|
Message message = clientHelper
|
||||||
|
.getMessage(txn, messageEntry.getKey());
|
||||||
|
timestamp = message.getTimestamp();
|
||||||
|
}
|
||||||
List<AttachmentHeader> attachmentHeaders =
|
List<AttachmentHeader> attachmentHeaders =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
ShardMessageHeader shardHeader = new ShardMessageHeader(
|
ShardMessageHeader shardHeader = new ShardMessageHeader(
|
||||||
@@ -420,6 +427,7 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
BdfDictionary meta = BdfDictionary.of(
|
BdfDictionary meta = BdfDictionary.of(
|
||||||
new BdfEntry(MSG_KEY_MESSAGE_TYPE, BACKUP.getValue()),
|
new BdfEntry(MSG_KEY_MESSAGE_TYPE, BACKUP.getValue()),
|
||||||
new BdfEntry(MSG_KEY_LOCAL, true),
|
new BdfEntry(MSG_KEY_LOCAL, true),
|
||||||
|
new BdfEntry(MSG_KEY_TIMESTAMP, timestamp),
|
||||||
new BdfEntry(MSG_KEY_VERSION, version));
|
new BdfEntry(MSG_KEY_VERSION, version));
|
||||||
clientHelper.addLocalMessage(txn, m, meta, true, false);
|
clientHelper.addLocalMessage(txn, m, meta, true, false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package org.briarproject.briar.socialbackup;
|
package org.briarproject.briar.socialbackup;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.test.TestDatabaseConfigModule;
|
import org.briarproject.bramble.test.TestDatabaseConfigModule;
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
|
||||||
import org.briarproject.briar.api.socialbackup.BackupMetadata;
|
import org.briarproject.briar.api.socialbackup.BackupMetadata;
|
||||||
|
import org.briarproject.briar.api.socialbackup.ShardMessageHeader;
|
||||||
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
|
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
|
||||||
import org.briarproject.briar.test.BriarIntegrationTest;
|
import org.briarproject.briar.test.BriarIntegrationTest;
|
||||||
import org.briarproject.briar.test.BriarIntegrationTestComponent;
|
import org.briarproject.briar.test.BriarIntegrationTestComponent;
|
||||||
@@ -10,25 +13,30 @@ import org.briarproject.briar.test.DaggerBriarIntegrationTestComponent;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import dagger.Provides;
|
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class SocialBackupIntegrationTest
|
public class SocialBackupIntegrationTest
|
||||||
extends BriarIntegrationTest<BriarIntegrationTestComponent> {
|
extends BriarIntegrationTest<BriarIntegrationTestComponent> {
|
||||||
|
|
||||||
private SocialBackupManager socialBackupManager0;
|
private SocialBackupManager socialBackupManager0;
|
||||||
|
private SocialBackupManager socialBackupManager1;
|
||||||
|
private SocialBackupManager socialBackupManager2;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
socialBackupManager0 = c0.getSocialBackupManager();
|
socialBackupManager0 = c0.getSocialBackupManager();
|
||||||
|
socialBackupManager1 = c1.getSocialBackupManager();
|
||||||
|
socialBackupManager2 = c2.getSocialBackupManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,5 +81,68 @@ public class SocialBackupIntegrationTest
|
|||||||
// Sync the shard and backup messages to the contacts
|
// Sync the shard and backup messages to the contacts
|
||||||
sync0To1(2, true);
|
sync0To1(2, true);
|
||||||
sync0To2(2, true);
|
sync0To2(2, true);
|
||||||
|
|
||||||
|
Collection<ConversationMessageHeader> messages1At0 =
|
||||||
|
getMessages1At0();
|
||||||
|
assertEquals(1, messages1At0.size());
|
||||||
|
for (ConversationMessageHeader h : messages1At0) {
|
||||||
|
assertTrue(h instanceof ShardMessageHeader);
|
||||||
|
ShardMessageHeader s = (ShardMessageHeader) h;
|
||||||
|
assertTrue(s.isLocal());
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<ConversationMessageHeader> messages2At0 =
|
||||||
|
getMessages2At0();
|
||||||
|
assertEquals(1, messages2At0.size());
|
||||||
|
for (ConversationMessageHeader h : messages2At0) {
|
||||||
|
assertTrue(h instanceof ShardMessageHeader);
|
||||||
|
ShardMessageHeader s = (ShardMessageHeader) h;
|
||||||
|
assertTrue(s.isLocal());
|
||||||
|
}
|
||||||
|
|
||||||
|
// the shard message from 0 should have arrived at 1
|
||||||
|
Collection<ConversationMessageHeader> messages0At1 =
|
||||||
|
getMessages0At1();
|
||||||
|
assertEquals(1, messages0At1.size());
|
||||||
|
for (ConversationMessageHeader h : messages0At1) {
|
||||||
|
assertTrue(h instanceof ShardMessageHeader);
|
||||||
|
ShardMessageHeader s = (ShardMessageHeader) h;
|
||||||
|
assertFalse(s.isLocal());
|
||||||
|
}
|
||||||
|
|
||||||
|
// the shard message from 0 should have arrived at 2
|
||||||
|
Collection<ConversationMessageHeader> messages0At2 =
|
||||||
|
getMessages0At2();
|
||||||
|
assertEquals(1, messages0At2.size());
|
||||||
|
for (ConversationMessageHeader h : messages0At2) {
|
||||||
|
assertTrue(h instanceof ShardMessageHeader);
|
||||||
|
ShardMessageHeader s = (ShardMessageHeader) h;
|
||||||
|
assertFalse(s.isLocal());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Collection<ConversationMessageHeader> getMessages1At0()
|
||||||
|
throws DbException {
|
||||||
|
return db0.transactionWithResult(true, txn -> socialBackupManager0
|
||||||
|
.getMessageHeaders(txn, contactId1From0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collection<ConversationMessageHeader> getMessages2At0()
|
||||||
|
throws DbException {
|
||||||
|
return db0.transactionWithResult(true, txn -> socialBackupManager0
|
||||||
|
.getMessageHeaders(txn, contactId2From0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collection<ConversationMessageHeader> getMessages0At1()
|
||||||
|
throws DbException {
|
||||||
|
return db1.transactionWithResult(true, txn -> socialBackupManager1
|
||||||
|
.getMessageHeaders(txn, contactId0From1));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collection<ConversationMessageHeader> getMessages0At2()
|
||||||
|
throws DbException {
|
||||||
|
return db1.transactionWithResult(true, txn -> socialBackupManager2
|
||||||
|
.getMessageHeaders(txn, contactId0From2));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user