Remove code from TestDataCreator that breaks encapsulation

parent ae81eb37
...@@ -2,7 +2,6 @@ package org.briarproject.briar.test; ...@@ -2,7 +2,6 @@ package org.briarproject.briar.test;
import org.briarproject.bramble.api.FormatException; import org.briarproject.bramble.api.FormatException;
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.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager; import org.briarproject.bramble.api.contact.ContactManager;
...@@ -25,7 +24,6 @@ import org.briarproject.bramble.api.plugin.TorConstants; ...@@ -25,7 +24,6 @@ import org.briarproject.bramble.api.plugin.TorConstants;
import org.briarproject.bramble.api.plugin.TransportId; import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.properties.TransportProperties; import org.briarproject.bramble.api.properties.TransportProperties;
import org.briarproject.bramble.api.properties.TransportPropertyManager; import org.briarproject.bramble.api.properties.TransportPropertyManager;
import org.briarproject.bramble.api.sync.ClientId;
import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
...@@ -34,12 +32,10 @@ import org.briarproject.briar.api.blog.Blog; ...@@ -34,12 +32,10 @@ import org.briarproject.briar.api.blog.Blog;
import org.briarproject.briar.api.blog.BlogManager; import org.briarproject.briar.api.blog.BlogManager;
import org.briarproject.briar.api.blog.BlogPost; import org.briarproject.briar.api.blog.BlogPost;
import org.briarproject.briar.api.blog.BlogPostFactory; import org.briarproject.briar.api.blog.BlogPostFactory;
import org.briarproject.briar.api.blog.BlogSharingManager;
import org.briarproject.briar.api.client.MessageTracker; import org.briarproject.briar.api.client.MessageTracker;
import org.briarproject.briar.api.forum.Forum; import org.briarproject.briar.api.forum.Forum;
import org.briarproject.briar.api.forum.ForumManager; import org.briarproject.briar.api.forum.ForumManager;
import org.briarproject.briar.api.forum.ForumPost; import org.briarproject.briar.api.forum.ForumPost;
import org.briarproject.briar.api.forum.ForumSharingManager;
import org.briarproject.briar.api.messaging.MessagingManager; import org.briarproject.briar.api.messaging.MessagingManager;
import org.briarproject.briar.api.messaging.PrivateMessage; import org.briarproject.briar.api.messaging.PrivateMessage;
import org.briarproject.briar.api.messaging.PrivateMessageFactory; import org.briarproject.briar.api.messaging.PrivateMessageFactory;
...@@ -82,7 +78,6 @@ public class TestDataCreatorImpl implements TestDataCreator { ...@@ -82,7 +78,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
private final DatabaseComponent db; private final DatabaseComponent db;
private final IdentityManager identityManager; private final IdentityManager identityManager;
private final ContactManager contactManager; private final ContactManager contactManager;
private final ContactGroupFactory contactGroupFactory;
private final TransportPropertyManager transportPropertyManager; private final TransportPropertyManager transportPropertyManager;
private final MessagingManager messagingManager; private final MessagingManager messagingManager;
private final BlogManager blogManager; private final BlogManager blogManager;
...@@ -101,7 +96,6 @@ public class TestDataCreatorImpl implements TestDataCreator { ...@@ -101,7 +96,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
BlogPostFactory blogPostFactory, CryptoComponent cryptoComponent, BlogPostFactory blogPostFactory, CryptoComponent cryptoComponent,
DatabaseComponent db, IdentityManager identityManager, DatabaseComponent db, IdentityManager identityManager,
ContactManager contactManager, ContactManager contactManager,
ContactGroupFactory contactGroupFactory,
TransportPropertyManager transportPropertyManager, TransportPropertyManager transportPropertyManager,
MessagingManager messagingManager, BlogManager blogManager, MessagingManager messagingManager, BlogManager blogManager,
ForumManager forumManager, @IoExecutor Executor ioExecutor) { ForumManager forumManager, @IoExecutor Executor ioExecutor) {
...@@ -115,7 +109,6 @@ public class TestDataCreatorImpl implements TestDataCreator { ...@@ -115,7 +109,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
this.db = db; this.db = db;
this.identityManager = identityManager; this.identityManager = identityManager;
this.contactManager = contactManager; this.contactManager = contactManager;
this.contactGroupFactory = contactGroupFactory;
this.transportPropertyManager = transportPropertyManager; this.transportPropertyManager = transportPropertyManager;
this.messagingManager = messagingManager; this.messagingManager = messagingManager;
this.blogManager = blogManager; this.blogManager = blogManager;
...@@ -183,7 +176,6 @@ public class TestDataCreatorImpl implements TestDataCreator { ...@@ -183,7 +176,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
timestamp, true, verified, true); timestamp, true, verified, true);
transportPropertyManager.addRemoteProperties(txn, contactId, props); transportPropertyManager.addRemoteProperties(txn, contactId, props);
contact = db.getContact(txn, contactId); contact = db.getContact(txn, contactId);
fakeClientVisibilities(txn, contact);
db.commitTransaction(txn); db.commitTransaction(txn);
} finally { } finally {
db.endTransaction(txn); db.endTransaction(txn);
...@@ -199,11 +191,7 @@ public class TestDataCreatorImpl implements TestDataCreator { ...@@ -199,11 +191,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
@Override @Override
public Contact addContact(String name) throws DbException { public Contact addContact(String name) throws DbException {
// load localAuthor from DB, because cache doesn't get refreshed LocalAuthor localAuthor = identityManager.getLocalAuthor();
// when Espresso tests run within one lifecycle
Transaction txn = db.startTransaction(false);
LocalAuthor localAuthor = db.getLocalAuthors(txn).iterator().next();
db.endTransaction(txn);
return addContact(localAuthor.getId(), getAuthor(name)); return addContact(localAuthor.getId(), getAuthor(name));
} }
...@@ -309,8 +297,7 @@ public class TestDataCreatorImpl implements TestDataCreator { ...@@ -309,8 +297,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
Group group = messagingManager.getContactGroup(contact); Group group = messagingManager.getContactGroup(contact);
for (int i = 0; i < numPrivateMsgs; i++) { for (int i = 0; i < numPrivateMsgs; i++) {
try { try {
createRandomPrivateMessage(contact.getId(), group.getId(), createRandomPrivateMessage(group.getId(), i);
i);
} catch (FormatException e) { } catch (FormatException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -322,30 +309,27 @@ public class TestDataCreatorImpl implements TestDataCreator { ...@@ -322,30 +309,27 @@ public class TestDataCreatorImpl implements TestDataCreator {
} }
} }
private void createRandomPrivateMessage(ContactId contactId, private void createRandomPrivateMessage(GroupId groupId, int num)
GroupId groupId, int num) throws DbException, FormatException { throws DbException, FormatException {
long timestamp = clock.currentTimeMillis() - num * 60 * 1000; long timestamp = clock.currentTimeMillis() - num * 60 * 1000;
String body = getRandomText(); String body = getRandomText();
boolean local = random.nextBoolean(); boolean local = random.nextBoolean();
createPrivateMessage(contactId, groupId, body, timestamp, local); createPrivateMessage(groupId, body, timestamp, local);
} }
private void createPrivateMessage(ContactId contactId, GroupId groupId, private void createPrivateMessage(GroupId groupId, String body,
String body, long timestamp, boolean local) long timestamp, boolean local) throws DbException, FormatException {
throws DbException, FormatException {
PrivateMessage m = privateMessageFactory PrivateMessage m = privateMessageFactory
.createPrivateMessage(groupId, timestamp, body); .createPrivateMessage(groupId, timestamp, body);
BdfDictionary meta = new BdfDictionary(); BdfDictionary meta = new BdfDictionary();
meta.put("timestamp", timestamp); meta.put("timestamp", timestamp);
meta.put("local", local); meta.put("local", local);
meta.put("read", local); // all local messages are read meta.put("read", local); // all local messages are read
Transaction txn = db.startTransaction(false); Transaction txn = db.startTransaction(false);
try { try {
clientHelper.addLocalMessage(txn, m.getMessage(), meta, true); clientHelper.addLocalMessage(txn, m.getMessage(), meta, true);
if (local) { if (local) messageTracker.trackOutgoingMessage(txn, m.getMessage());
messageTracker.trackOutgoingMessage(txn, m.getMessage());
db.receiveMessage(txn, contactId, m.getMessage());
}
else messageTracker.trackIncomingMessage(txn, m.getMessage()); else messageTracker.trackIncomingMessage(txn, m.getMessage());
db.commitTransaction(txn); db.commitTransaction(txn);
} finally { } finally {
...@@ -357,8 +341,7 @@ public class TestDataCreatorImpl implements TestDataCreator { ...@@ -357,8 +341,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
public void addPrivateMessage(Contact contact, String body, long time, public void addPrivateMessage(Contact contact, String body, long time,
boolean local) throws DbException, FormatException { boolean local) throws DbException, FormatException {
Group group = messagingManager.getContactGroup(contact); Group group = messagingManager.getContactGroup(contact);
createPrivateMessage(contact.getId(), group.getId(), body, time, createPrivateMessage(group.getId(), body, time, local);
local);
} }
private void createBlogPosts(List<Contact> contacts, int numBlogPosts) private void createBlogPosts(List<Contact> contacts, int numBlogPosts)
...@@ -439,23 +422,6 @@ public class TestDataCreatorImpl implements TestDataCreator { ...@@ -439,23 +422,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
} }
} }
private void fakeClientVisibilities(Transaction txn, Contact contact)
throws DbException {
fakeClientVisibilities(txn, contact, MessagingManager.CLIENT_ID,
MessagingManager.MAJOR_VERSION);
fakeClientVisibilities(txn, contact, ForumSharingManager.CLIENT_ID,
ForumSharingManager.MAJOR_VERSION);
fakeClientVisibilities(txn, contact, BlogSharingManager.CLIENT_ID,
BlogSharingManager.MAJOR_VERSION);
}
private void fakeClientVisibilities(Transaction txn, Contact contact,
ClientId clientId, int majorVersion) throws DbException {
Group group = contactGroupFactory
.createContactGroup(clientId, majorVersion, contact);
db.setGroupVisibility(txn, contact.getId(), group.getId(), SHARED);
}
private String getRandomText() { private String getRandomText() {
int minLength = 3 + random.nextInt(500); int minLength = 3 + random.nextInt(500);
int maxWordLength = 15; int maxWordLength = 15;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment