mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Unit tests to catch a noobish JDBC error.
This commit is contained in:
@@ -1387,15 +1387,16 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
// Get the local and remote authors
|
||||
String sql = "SELECT l.authorId, l.name, l.publicKey,"
|
||||
+ " r.authorId, r.name, r.publicKey"
|
||||
+ " FROM localAuthors AS l"
|
||||
+ " JOIN contacts AS r"
|
||||
+ " ON l.authorId = r.localAuthorId"
|
||||
String sql = "SELECT la.authorId, la.name, la.publicKey,"
|
||||
+ " c.authorId, c.name, c.publicKey"
|
||||
+ " FROM localAuthors AS la"
|
||||
+ " JOIN contacts AS c"
|
||||
+ " ON la.authorId = c.localAuthorId"
|
||||
+ " WHERE contactId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
rs = ps.executeQuery();
|
||||
if(!rs.next()) throw new DbException();
|
||||
AuthorId localId = new AuthorId(rs.getBytes(1));
|
||||
String localName = rs.getString(2);
|
||||
byte[] localKey = rs.getBytes(3);
|
||||
@@ -1404,6 +1405,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
String remoteName = rs.getString(5);
|
||||
byte[] remoteKey = rs.getBytes(6);
|
||||
Author remoteAuthor = new Author(remoteId, remoteName, remoteKey);
|
||||
if(rs.next()) throw new DbException();
|
||||
// Get the message headers
|
||||
sql = "SELECT messageId, parentId, m.groupId, contentType,"
|
||||
+ " timestamp, incoming, read"
|
||||
@@ -1412,7 +1414,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " ON m.groupId = g.groupId"
|
||||
+ " JOIN groupVisibilities AS gv"
|
||||
+ " ON m.groupId = gv.groupId"
|
||||
+ " WHERE gv.contactId = ?"
|
||||
+ " WHERE contactId = ?"
|
||||
+ " AND inbox = TRUE";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
|
||||
@@ -1628,6 +1628,39 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInboxMessageHeaders() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and an inbox group - no headers should be returned
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
Group inbox = new Group(groupId, "Group", new byte[GROUP_SALT_LENGTH],
|
||||
true);
|
||||
db.addGroup(txn, inbox);
|
||||
db.setInboxGroup(txn, contactId, inbox);
|
||||
assertEquals(Collections.emptyList(),
|
||||
db.getInboxMessageHeaders(txn, contactId));
|
||||
|
||||
// Add a message to the inbox group - the header should be returned
|
||||
db.addMessage(txn, message, false);
|
||||
Collection<MessageHeader> headers =
|
||||
db.getInboxMessageHeaders(txn, contactId);
|
||||
assertEquals(1, headers.size());
|
||||
MessageHeader header = headers.iterator().next();
|
||||
assertEquals(messageId, header.getId());
|
||||
assertNull(header.getParent());
|
||||
assertEquals(groupId, header.getGroupId());
|
||||
assertEquals(localAuthor, header.getAuthor());
|
||||
assertEquals(contentType, header.getContentType());
|
||||
assertEquals(timestamp, header.getTimestamp());
|
||||
assertFalse(header.isRead());
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionHandling() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
|
||||
Reference in New Issue
Block a user