mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 07:09:56 +01:00
Added names to contacts, created Contact class in API.
This commit is contained in:
31
briar-api/src/net/sf/briar/api/Contact.java
Normal file
31
briar-api/src/net/sf/briar/api/Contact.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package net.sf.briar.api;
|
||||||
|
|
||||||
|
public class Contact {
|
||||||
|
|
||||||
|
private final ContactId id;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public Contact(ContactId id, String name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return id.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if(o instanceof Contact) return id.equals(((Contact) o).id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import java.io.IOException;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.sf.briar.api.Contact;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
@@ -50,11 +51,12 @@ public interface DatabaseComponent {
|
|||||||
void removeListener(DatabaseListener d);
|
void removeListener(DatabaseListener d);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new contact to the database and returns an ID for the contact.
|
* Adds a contact with the given name to the database and returns an ID for
|
||||||
|
* the contact.
|
||||||
*/
|
*/
|
||||||
ContactId addContact() throws DbException;
|
ContactId addContact(String name) throws DbException;
|
||||||
|
|
||||||
/** Adds an endpoitn to the database. */
|
/** Adds an endpoint to the database. */
|
||||||
void addEndpoint(Endpoint ep) throws DbException;
|
void addEndpoint(Endpoint ep) throws DbException;
|
||||||
|
|
||||||
/** Adds a locally generated group message to the database. */
|
/** Adds a locally generated group message to the database. */
|
||||||
@@ -155,8 +157,8 @@ public interface DatabaseComponent {
|
|||||||
/** Returns the configuration for the given transport. */
|
/** Returns the configuration for the given transport. */
|
||||||
TransportConfig getConfig(TransportId t) throws DbException;
|
TransportConfig getConfig(TransportId t) throws DbException;
|
||||||
|
|
||||||
/** Returns the IDs of all contacts. */
|
/** Returns all contacts. */
|
||||||
Collection<ContactId> getContacts() throws DbException;
|
Collection<Contact> getContacts() throws DbException;
|
||||||
|
|
||||||
/** Returns the local transport properties for the given transport. */
|
/** Returns the local transport properties for the given transport. */
|
||||||
TransportProperties getLocalProperties(TransportId t) throws DbException;
|
TransportProperties getLocalProperties(TransportId t) throws DbException;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.io.IOException;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.sf.briar.api.Contact;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
@@ -77,11 +78,12 @@ interface Database<T> {
|
|||||||
void commitTransaction(T txn) throws DbException;
|
void commitTransaction(T txn) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new contact to the database and returns an ID for the contact.
|
* Adds a contact with the given name to the database and returns an ID for
|
||||||
|
* the contact.
|
||||||
* <p>
|
* <p>
|
||||||
* Locking: contact write, subscription write.
|
* Locking: contact write, subscription write.
|
||||||
*/
|
*/
|
||||||
ContactId addContact(T txn) throws DbException;
|
ContactId addContact(T txn, String name) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an endpoint to the database.
|
* Adds an endpoint to the database.
|
||||||
@@ -203,7 +205,14 @@ interface Database<T> {
|
|||||||
* <p>
|
* <p>
|
||||||
* Locking: contact read.
|
* Locking: contact read.
|
||||||
*/
|
*/
|
||||||
Collection<ContactId> getContacts(T txn) throws DbException;
|
Collection<ContactId> getContactIds(T txn) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all contacts.
|
||||||
|
* <p>
|
||||||
|
* Locking: contact read.
|
||||||
|
*/
|
||||||
|
Collection<Contact> getContacts(T txn) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all endpoints.
|
* Returns all endpoints.
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import net.sf.briar.api.Contact;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
@@ -171,7 +172,7 @@ DatabaseCleaner.Callback {
|
|||||||
listeners.remove(d);
|
listeners.remove(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContactId addContact() throws DbException {
|
public ContactId addContact(String name) throws DbException {
|
||||||
ContactId c;
|
ContactId c;
|
||||||
contactLock.writeLock().lock();
|
contactLock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
@@ -179,7 +180,7 @@ DatabaseCleaner.Callback {
|
|||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
c = db.addContact(txn);
|
c = db.addContact(txn, name);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
db.abortTransaction(txn);
|
db.abortTransaction(txn);
|
||||||
@@ -279,7 +280,7 @@ DatabaseCleaner.Callback {
|
|||||||
if(sender != null) db.addStatus(txn, sender, id, true);
|
if(sender != null) db.addStatus(txn, sender, id, true);
|
||||||
if(stored) {
|
if(stored) {
|
||||||
// Mark the message as unseen by other contacts
|
// Mark the message as unseen by other contacts
|
||||||
for(ContactId c : db.getContacts(txn)) {
|
for(ContactId c : db.getContactIds(txn)) {
|
||||||
if(!c.equals(sender)) db.addStatus(txn, c, id, false);
|
if(!c.equals(sender)) db.addStatus(txn, c, id, false);
|
||||||
}
|
}
|
||||||
// Calculate and store the message's sendability
|
// Calculate and store the message's sendability
|
||||||
@@ -801,12 +802,12 @@ DatabaseCleaner.Callback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<ContactId> getContacts() throws DbException {
|
public Collection<Contact> getContacts() throws DbException {
|
||||||
contactLock.readLock().lock();
|
contactLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
Collection<ContactId> contacts = db.getContacts(txn);
|
Collection<Contact> contacts = db.getContacts(txn);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
return contacts;
|
return contacts;
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
@@ -1691,7 +1692,7 @@ DatabaseCleaner.Callback {
|
|||||||
HashSet<ContactId> oldVisible =
|
HashSet<ContactId> oldVisible =
|
||||||
new HashSet<ContactId>(db.getVisibility(txn, g));
|
new HashSet<ContactId>(db.getVisibility(txn, g));
|
||||||
// Set the group's visibility for each current contact
|
// Set the group's visibility for each current contact
|
||||||
for(ContactId c : db.getContacts(txn)) {
|
for(ContactId c : db.getContactIds(txn)) {
|
||||||
boolean then = oldVisible.contains(c);
|
boolean then = oldVisible.contains(c);
|
||||||
boolean now = newVisible.contains(c);
|
boolean now = newVisible.contains(c);
|
||||||
if(!then && now) {
|
if(!then && now) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import net.sf.briar.api.Contact;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.Rating;
|
import net.sf.briar.api.Rating;
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
@@ -58,7 +59,10 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
|
|
||||||
// Locking: contact
|
// Locking: contact
|
||||||
private static final String CREATE_CONTACTS =
|
private static final String CREATE_CONTACTS =
|
||||||
"CREATE TABLE contacts (contactId COUNTER)";
|
"CREATE TABLE contacts "
|
||||||
|
+ " (contactId COUNTER,"
|
||||||
|
+ " name VARCHAR NOT NULL,"
|
||||||
|
+ " PRIMARY KEY (contactId))";
|
||||||
|
|
||||||
// Locking: subscription
|
// Locking: subscription
|
||||||
private static final String CREATE_GROUPS =
|
private static final String CREATE_GROUPS =
|
||||||
@@ -492,13 +496,15 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
if(interrupted) Thread.currentThread().interrupt();
|
if(interrupted) Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContactId addContact(Connection txn) throws DbException {
|
public ContactId addContact(Connection txn, String name)
|
||||||
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
// Create a contact row
|
// Create a contact row
|
||||||
String sql = "INSERT INTO contacts DEFAULT VALUES";
|
String sql = "INSERT INTO contacts (name) VALUES (?)";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setString(1, name);
|
||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if(affected != 1) throw new DbStateException();
|
if(affected != 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -1001,7 +1007,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<ContactId> getContacts(Connection txn)
|
public Collection<ContactId> getContactIds(Connection txn)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@@ -1021,6 +1027,30 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Contact> getContacts(Connection txn)
|
||||||
|
throws DbException {
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
String sql = "SELECT contactId, name FROM contacts";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
List<Contact> contacts = new ArrayList<Contact>();
|
||||||
|
while(rs.next()) {
|
||||||
|
ContactId id = new ContactId(rs.getInt(1));
|
||||||
|
String name = rs.getString(2);
|
||||||
|
contacts.add(new Contact(id, name));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
return Collections.unmodifiableList(contacts);
|
||||||
|
} catch(SQLException e) {
|
||||||
|
tryToClose(rs);
|
||||||
|
tryToClose(ps);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<Endpoint> getEndpoints(Connection txn)
|
public Collection<Endpoint> getEndpoints(Connection txn)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.util.Map;
|
|||||||
import net.sf.briar.BriarTestCase;
|
import net.sf.briar.BriarTestCase;
|
||||||
import net.sf.briar.TestMessage;
|
import net.sf.briar.TestMessage;
|
||||||
import net.sf.briar.TestUtils;
|
import net.sf.briar.TestUtils;
|
||||||
|
import net.sf.briar.api.Contact;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
@@ -56,10 +57,11 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
protected final ContactId contactId;
|
protected final ContactId contactId;
|
||||||
protected final GroupId groupId;
|
protected final GroupId groupId;
|
||||||
protected final MessageId messageId, messageId1;
|
protected final MessageId messageId, messageId1;
|
||||||
private final String subject;
|
private final String contactName, subject;
|
||||||
private final long timestamp;
|
private final long timestamp;
|
||||||
private final int size;
|
private final int size;
|
||||||
private final byte[] raw;
|
private final byte[] raw;
|
||||||
|
private final Contact contact;
|
||||||
private final Message message, privateMessage;
|
private final Message message, privateMessage;
|
||||||
private final Group group;
|
private final Group group;
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
@@ -74,10 +76,12 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
groupId = new GroupId(TestUtils.getRandomId());
|
groupId = new GroupId(TestUtils.getRandomId());
|
||||||
messageId = new MessageId(TestUtils.getRandomId());
|
messageId = new MessageId(TestUtils.getRandomId());
|
||||||
messageId1 = new MessageId(TestUtils.getRandomId());
|
messageId1 = new MessageId(TestUtils.getRandomId());
|
||||||
|
contactName = "Alice";
|
||||||
subject = "Foo";
|
subject = "Foo";
|
||||||
timestamp = System.currentTimeMillis();
|
timestamp = System.currentTimeMillis();
|
||||||
size = 1234;
|
size = 1234;
|
||||||
raw = new byte[size];
|
raw = new byte[size];
|
||||||
|
contact = new Contact(contactId, contactName);
|
||||||
message = new TestMessage(messageId, null, groupId, authorId, subject,
|
message = new TestMessage(messageId, null, groupId, authorId, subject,
|
||||||
timestamp, raw);
|
timestamp, raw);
|
||||||
privateMessage = new TestMessage(messageId, null, null, null, subject,
|
privateMessage = new TestMessage(messageId, null, null, null, subject,
|
||||||
@@ -127,13 +131,13 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
// setRating(authorId, GOOD) again
|
// setRating(authorId, GOOD) again
|
||||||
oneOf(database).setRating(txn, authorId, GOOD);
|
oneOf(database).setRating(txn, authorId, GOOD);
|
||||||
will(returnValue(GOOD));
|
will(returnValue(GOOD));
|
||||||
// addContact()
|
// addContact(contactName)
|
||||||
oneOf(database).addContact(txn);
|
oneOf(database).addContact(txn, contactName);
|
||||||
will(returnValue(contactId));
|
will(returnValue(contactId));
|
||||||
oneOf(listener).eventOccurred(with(any(ContactAddedEvent.class)));
|
oneOf(listener).eventOccurred(with(any(ContactAddedEvent.class)));
|
||||||
// getContacts()
|
// getContacts()
|
||||||
oneOf(database).getContacts(txn);
|
oneOf(database).getContacts(txn);
|
||||||
will(returnValue(Arrays.asList(contactId)));
|
will(returnValue(Arrays.asList(contact)));
|
||||||
// getRemoteProperties(transportId)
|
// getRemoteProperties(transportId)
|
||||||
oneOf(database).getRemoteProperties(txn, transportId);
|
oneOf(database).getRemoteProperties(txn, transportId);
|
||||||
will(returnValue(Collections.emptyMap()));
|
will(returnValue(Collections.emptyMap()));
|
||||||
@@ -178,8 +182,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
assertEquals(UNRATED, db.getRating(authorId));
|
assertEquals(UNRATED, db.getRating(authorId));
|
||||||
db.setRating(authorId, GOOD); // First time - listeners called
|
db.setRating(authorId, GOOD); // First time - listeners called
|
||||||
db.setRating(authorId, GOOD); // Second time - not called
|
db.setRating(authorId, GOOD); // Second time - not called
|
||||||
assertEquals(contactId, db.addContact());
|
assertEquals(contactId, db.addContact(contactName));
|
||||||
assertEquals(Arrays.asList(contactId), db.getContacts());
|
assertEquals(Arrays.asList(contact), db.getContacts());
|
||||||
assertEquals(Collections.emptyMap(),
|
assertEquals(Collections.emptyMap(),
|
||||||
db.getRemoteProperties(transportId));
|
db.getRemoteProperties(transportId));
|
||||||
db.subscribe(group); // First time - listeners called
|
db.subscribe(group); // First time - listeners called
|
||||||
@@ -366,7 +370,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).addGroupMessage(txn, message);
|
oneOf(database).addGroupMessage(txn, message);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).getContacts(txn);
|
oneOf(database).getContactIds(txn);
|
||||||
will(returnValue(Arrays.asList(contactId)));
|
will(returnValue(Arrays.asList(contactId)));
|
||||||
oneOf(database).addStatus(txn, contactId, messageId, false);
|
oneOf(database).addStatus(txn, contactId, messageId, false);
|
||||||
// The author is unrated and there are no sendable children
|
// The author is unrated and there are no sendable children
|
||||||
@@ -401,7 +405,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).addGroupMessage(txn, message);
|
oneOf(database).addGroupMessage(txn, message);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).getContacts(txn);
|
oneOf(database).getContactIds(txn);
|
||||||
will(returnValue(Arrays.asList(contactId)));
|
will(returnValue(Arrays.asList(contactId)));
|
||||||
oneOf(database).addStatus(txn, contactId, messageId, false);
|
oneOf(database).addStatus(txn, contactId, messageId, false);
|
||||||
// The author is rated GOOD and there are two sendable children
|
// The author is rated GOOD and there are two sendable children
|
||||||
@@ -653,7 +657,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
// addContact()
|
// addContact()
|
||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(database).addContact(txn);
|
oneOf(database).addContact(txn, contactName);
|
||||||
will(returnValue(contactId));
|
will(returnValue(contactId));
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
// Check whether the transport is in the DB (which it's not)
|
// Check whether the transport is in the DB (which it's not)
|
||||||
@@ -667,7 +671,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||||
shutdown);
|
shutdown);
|
||||||
assertEquals(contactId, db.addContact());
|
assertEquals(contactId, db.addContact(contactName));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.addEndpoint(endpoint);
|
db.addEndpoint(endpoint);
|
||||||
@@ -1182,7 +1186,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).addStatus(txn, contactId, messageId, true);
|
oneOf(database).addStatus(txn, contactId, messageId, true);
|
||||||
// Set the status to seen = true for all other contacts (none)
|
// Set the status to seen = true for all other contacts (none)
|
||||||
oneOf(database).getContacts(txn);
|
oneOf(database).getContactIds(txn);
|
||||||
will(returnValue(Arrays.asList(contactId)));
|
will(returnValue(Arrays.asList(contactId)));
|
||||||
// Calculate the sendability - zero, so ancestors aren't updated
|
// Calculate the sendability - zero, so ancestors aren't updated
|
||||||
oneOf(database).getRating(txn, authorId);
|
oneOf(database).getRating(txn, authorId);
|
||||||
@@ -1224,7 +1228,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).addStatus(txn, contactId, messageId, true);
|
oneOf(database).addStatus(txn, contactId, messageId, true);
|
||||||
// Set the status to seen = true for all other contacts (none)
|
// Set the status to seen = true for all other contacts (none)
|
||||||
oneOf(database).getContacts(txn);
|
oneOf(database).getContactIds(txn);
|
||||||
will(returnValue(Arrays.asList(contactId)));
|
will(returnValue(Arrays.asList(contactId)));
|
||||||
// Calculate the sendability - ancestors are updated
|
// Calculate the sendability - ancestors are updated
|
||||||
oneOf(database).getRating(txn, authorId);
|
oneOf(database).getRating(txn, authorId);
|
||||||
@@ -1424,7 +1428,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).addGroupMessage(txn, message);
|
oneOf(database).addGroupMessage(txn, message);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).getContacts(txn);
|
oneOf(database).getContactIds(txn);
|
||||||
will(returnValue(Arrays.asList(contactId)));
|
will(returnValue(Arrays.asList(contactId)));
|
||||||
oneOf(database).addStatus(txn, contactId, messageId, false);
|
oneOf(database).addStatus(txn, contactId, messageId, false);
|
||||||
oneOf(database).getRating(txn, authorId);
|
oneOf(database).getRating(txn, authorId);
|
||||||
@@ -1631,7 +1635,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).getVisibility(txn, groupId);
|
oneOf(database).getVisibility(txn, groupId);
|
||||||
will(returnValue(both));
|
will(returnValue(both));
|
||||||
oneOf(database).getContacts(txn);
|
oneOf(database).getContactIds(txn);
|
||||||
will(returnValue(both));
|
will(returnValue(both));
|
||||||
oneOf(database).removeVisibility(txn, contactId1, groupId);
|
oneOf(database).removeVisibility(txn, contactId1, groupId);
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
@@ -1665,7 +1669,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).getVisibility(txn, groupId);
|
oneOf(database).getVisibility(txn, groupId);
|
||||||
will(returnValue(both));
|
will(returnValue(both));
|
||||||
oneOf(database).getContacts(txn);
|
oneOf(database).getContactIds(txn);
|
||||||
will(returnValue(both));
|
will(returnValue(both));
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final GroupId groupId;
|
private final GroupId groupId;
|
||||||
private final MessageId messageId, messageId1;
|
private final MessageId messageId, messageId1;
|
||||||
private final String subject;
|
private final String contactName, subject;
|
||||||
private final long timestamp;
|
private final long timestamp;
|
||||||
private final int size;
|
private final int size;
|
||||||
private final byte[] raw;
|
private final byte[] raw;
|
||||||
@@ -70,6 +70,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
messageId = new MessageId(TestUtils.getRandomId());
|
messageId = new MessageId(TestUtils.getRandomId());
|
||||||
messageId1 = new MessageId(TestUtils.getRandomId());
|
messageId1 = new MessageId(TestUtils.getRandomId());
|
||||||
group = new Group(groupId, "Foo", null);
|
group = new Group(groupId, "Foo", null);
|
||||||
|
contactName = "Alice";
|
||||||
subject = "Foo";
|
subject = "Foo";
|
||||||
timestamp = System.currentTimeMillis();
|
timestamp = System.currentTimeMillis();
|
||||||
size = 1234;
|
size = 1234;
|
||||||
@@ -93,7 +94,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
assertFalse(db.containsContact(txn, contactId));
|
assertFalse(db.containsContact(txn, contactId));
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
assertTrue(db.containsContact(txn, contactId));
|
assertTrue(db.containsContact(txn, contactId));
|
||||||
assertFalse(db.containsSubscription(txn, groupId));
|
assertFalse(db.containsSubscription(txn, groupId));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
@@ -147,22 +148,22 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Create three contacts
|
// Create three contacts, all with the same name
|
||||||
assertFalse(db.containsContact(txn, contactId));
|
assertFalse(db.containsContact(txn, contactId));
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
assertTrue(db.containsContact(txn, contactId));
|
assertTrue(db.containsContact(txn, contactId));
|
||||||
assertFalse(db.containsContact(txn, contactId1));
|
assertFalse(db.containsContact(txn, contactId1));
|
||||||
assertEquals(contactId1, db.addContact(txn));
|
assertEquals(contactId1, db.addContact(txn, contactName));
|
||||||
assertTrue(db.containsContact(txn, contactId1));
|
assertTrue(db.containsContact(txn, contactId1));
|
||||||
assertFalse(db.containsContact(txn, contactId2));
|
assertFalse(db.containsContact(txn, contactId2));
|
||||||
assertEquals(contactId2, db.addContact(txn));
|
assertEquals(contactId2, db.addContact(txn, contactName));
|
||||||
assertTrue(db.containsContact(txn, contactId2));
|
assertTrue(db.containsContact(txn, contactId2));
|
||||||
// Delete the contact with the highest ID
|
// Delete the contact with the highest ID
|
||||||
db.removeContact(txn, contactId2);
|
db.removeContact(txn, contactId2);
|
||||||
assertFalse(db.containsContact(txn, contactId2));
|
assertFalse(db.containsContact(txn, contactId2));
|
||||||
// Add another contact - a new ID should be created
|
// Add another contact (same name again) - a new ID should be created
|
||||||
assertFalse(db.containsContact(txn, contactId3));
|
assertFalse(db.containsContact(txn, contactId3));
|
||||||
assertEquals(contactId3, db.addContact(txn));
|
assertEquals(contactId3, db.addContact(txn, contactName));
|
||||||
assertTrue(db.containsContact(txn, contactId3));
|
assertTrue(db.containsContact(txn, contactId3));
|
||||||
|
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
@@ -209,7 +210,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and store a private message
|
// Add a contact and store a private message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addPrivateMessage(txn, privateMessage, contactId);
|
db.addPrivateMessage(txn, privateMessage, contactId);
|
||||||
|
|
||||||
// Removing the contact should remove the message
|
// Removing the contact should remove the message
|
||||||
@@ -228,7 +229,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and store a private message
|
// Add a contact and store a private message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addPrivateMessage(txn, privateMessage, contactId);
|
db.addPrivateMessage(txn, privateMessage, contactId);
|
||||||
|
|
||||||
// The message has no status yet, so it should not be sendable
|
// The message has no status yet, so it should not be sendable
|
||||||
@@ -256,7 +257,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and store a private message
|
// Add a contact and store a private message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addPrivateMessage(txn, privateMessage, contactId);
|
db.addPrivateMessage(txn, privateMessage, contactId);
|
||||||
db.addStatus(txn, contactId, messageId1, false);
|
db.addStatus(txn, contactId, messageId1, false);
|
||||||
|
|
||||||
@@ -284,7 +285,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
@@ -322,7 +323,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
@@ -359,7 +360,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
@@ -396,7 +397,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
@@ -427,7 +428,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
@@ -459,7 +460,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and some messages to ack
|
// Add a contact and some messages to ack
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addMessageToAck(txn, contactId, messageId);
|
db.addMessageToAck(txn, contactId, messageId);
|
||||||
db.addMessageToAck(txn, contactId, messageId1);
|
db.addMessageToAck(txn, contactId, messageId1);
|
||||||
|
|
||||||
@@ -484,7 +485,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and receive the same message twice
|
// Add a contact and receive the same message twice
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addMessageToAck(txn, contactId, messageId);
|
db.addMessageToAck(txn, contactId, messageId);
|
||||||
db.addMessageToAck(txn, contactId, messageId);
|
db.addMessageToAck(txn, contactId, messageId);
|
||||||
|
|
||||||
@@ -509,7 +510,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
@@ -748,7 +749,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
// Add a contact with a transport
|
// Add a contact with a transport
|
||||||
TransportProperties p = new TransportProperties(
|
TransportProperties p = new TransportProperties(
|
||||||
Collections.singletonMap("foo", "bar"));
|
Collections.singletonMap("foo", "bar"));
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.setRemoteProperties(txn, contactId, transportId, p, 1);
|
db.setRemoteProperties(txn, contactId, transportId, p, 1);
|
||||||
assertEquals(Collections.singletonMap(contactId, p),
|
assertEquals(Collections.singletonMap(contactId, p),
|
||||||
db.getRemoteProperties(txn, transportId));
|
db.getRemoteProperties(txn, transportId));
|
||||||
@@ -838,7 +839,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
// Initialise the transport properties with version 1
|
// Initialise the transport properties with version 1
|
||||||
TransportProperties p = new TransportProperties(
|
TransportProperties p = new TransportProperties(
|
||||||
Collections.singletonMap("foo", "bar"));
|
Collections.singletonMap("foo", "bar"));
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.setRemoteProperties(txn, contactId, transportId, p, 1);
|
db.setRemoteProperties(txn, contactId, transportId, p, 1);
|
||||||
assertEquals(Collections.singletonMap(contactId, p),
|
assertEquals(Collections.singletonMap(contactId, p),
|
||||||
db.getRemoteProperties(txn, transportId));
|
db.getRemoteProperties(txn, transportId));
|
||||||
@@ -870,7 +871,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and subscribe to a group
|
// Add a contact and subscribe to a group
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
|
|
||||||
@@ -887,7 +888,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
@@ -910,7 +911,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
@@ -933,7 +934,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message -
|
// Add a contact, subscribe to a group and store a message -
|
||||||
// the message is older than the contact's retention time
|
// the message is older than the contact's retention time
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
@@ -957,7 +958,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
@@ -982,7 +983,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and subscribe to a group
|
// Add a contact and subscribe to a group
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
@@ -1001,7 +1002,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact with a subscription
|
// Add a contact with a subscription
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
|
|
||||||
// There's no local subscription for the group
|
// There's no local subscription for the group
|
||||||
@@ -1018,7 +1019,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
db.addStatus(txn, contactId, messageId, false);
|
db.addStatus(txn, contactId, messageId, false);
|
||||||
@@ -1037,7 +1038,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
@@ -1057,7 +1058,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
@@ -1079,7 +1080,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
@@ -1100,7 +1101,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and subscribe to a group
|
// Add a contact and subscribe to a group
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
// The group should not be visible to the contact
|
// The group should not be visible to the contact
|
||||||
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
|
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
|
||||||
@@ -1192,7 +1193,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and subscribe to a group
|
// Add a contact and subscribe to a group
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
|
|
||||||
// A message with a private parent should return null
|
// A message with a private parent should return null
|
||||||
@@ -1241,7 +1242,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and subscribe to a group
|
// Add a contact and subscribe to a group
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
|
|
||||||
// Store a couple of messages
|
// Store a couple of messages
|
||||||
@@ -1472,7 +1473,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
// Subscribe to the groups and add a contact
|
// Subscribe to the groups and add a contact
|
||||||
for(Group g : groups) db.addSubscription(txn, g);
|
for(Group g : groups) db.addSubscription(txn, g);
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
|
|
||||||
// Make the groups visible to the contact
|
// Make the groups visible to the contact
|
||||||
Collections.shuffle(groups);
|
Collections.shuffle(groups);
|
||||||
@@ -1528,7 +1529,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
// Add the contact, the transport, the endpoint and the first two
|
// Add the contact, the transport, the endpoint and the first two
|
||||||
// secrets (periods 0 and 1)
|
// secrets (periods 0 and 1)
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addTransport(txn, transportId);
|
db.addTransport(txn, transportId);
|
||||||
db.addEndpoint(txn, ep);
|
db.addEndpoint(txn, ep);
|
||||||
db.addSecrets(txn, Arrays.asList(s1, s2));
|
db.addSecrets(txn, Arrays.asList(s1, s2));
|
||||||
@@ -1622,7 +1623,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add the contact, the transport, the endpoint and the temporary secret
|
// Add the contact, the transport, the endpoint and the temporary secret
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addTransport(txn, transportId);
|
db.addTransport(txn, transportId);
|
||||||
db.addEndpoint(txn, ep);
|
db.addEndpoint(txn, ep);
|
||||||
db.addSecrets(txn, Arrays.asList(s));
|
db.addSecrets(txn, Arrays.asList(s));
|
||||||
@@ -1678,7 +1679,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add the contact, the transport, the endpoint and the temporary secret
|
// Add the contact, the transport, the endpoint and the temporary secret
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addTransport(txn, transportId);
|
db.addTransport(txn, transportId);
|
||||||
db.addEndpoint(txn, ep);
|
db.addEndpoint(txn, ep);
|
||||||
db.addSecrets(txn, Arrays.asList(s));
|
db.addSecrets(txn, Arrays.asList(s));
|
||||||
@@ -1749,7 +1750,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(Collections.emptyList(), db.getEndpoints(txn));
|
assertEquals(Collections.emptyList(), db.getEndpoints(txn));
|
||||||
|
|
||||||
// Add the contact, the transports and the endpoints
|
// Add the contact, the transports and the endpoints
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn, contactName));
|
||||||
db.addTransport(txn, transportId1);
|
db.addTransport(txn, transportId1);
|
||||||
db.addTransport(txn, transportId2);
|
db.addTransport(txn, transportId2);
|
||||||
db.addEndpoint(txn, ep1);
|
db.addEndpoint(txn, ep1);
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
KeyManager km = alice.getInstance(KeyManager.class);
|
KeyManager km = alice.getInstance(KeyManager.class);
|
||||||
km.start();
|
km.start();
|
||||||
// Add Bob as a contact
|
// Add Bob as a contact
|
||||||
ContactId contactId = db.addContact();
|
ContactId contactId = db.addContact("Bob");
|
||||||
Endpoint ep = new Endpoint(contactId, transportId, epoch,
|
Endpoint ep = new Endpoint(contactId, transportId, epoch,
|
||||||
CLOCK_DIFFERENCE, LATENCY, true);
|
CLOCK_DIFFERENCE, LATENCY, true);
|
||||||
// Add the transport and the endpoint
|
// Add the transport and the endpoint
|
||||||
@@ -151,7 +151,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
KeyManager km = bob.getInstance(KeyManager.class);
|
KeyManager km = bob.getInstance(KeyManager.class);
|
||||||
km.start();
|
km.start();
|
||||||
// Add Alice as a contact
|
// Add Alice as a contact
|
||||||
ContactId contactId = db.addContact();
|
ContactId contactId = db.addContact("Alice");
|
||||||
Endpoint ep = new Endpoint(contactId, transportId, epoch,
|
Endpoint ep = new Endpoint(contactId, transportId, epoch,
|
||||||
CLOCK_DIFFERENCE, LATENCY, false);
|
CLOCK_DIFFERENCE, LATENCY, false);
|
||||||
// Add the transport and the endpoint
|
// Add the transport and the endpoint
|
||||||
|
|||||||
Reference in New Issue
Block a user