Skip to content

Commit d9a549b

Browse files
committed
SQL tests on NodeThreadsGet.
1 parent 6c9a852 commit d9a549b

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

src/main/java/org/buddycloud/channelserver/db/jdbc/dialect/Sql92NodeStoreDialect.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,21 @@ public class Sql92NodeStoreDialect implements NodeStoreSQLDialect {
223223
private static final String DELETE_USER_SUBSCRIPTIONS = "DELETE FROM \"subscriptions\" WHERE \"user\" = ?";
224224

225225
private static final String SELECT_NODE_THREADS =
226-
"SELECT \"items.node\", \"items.id\", \"items.updated\", \"items.xml\", \"items.in_reply_to\", " +
227-
"\"threads.thread_id\", \"threads.thread_updated\" FROM items," +
228-
"(SELECT MAX(updated) AS thread_updated, thread_id FROM " +
229-
"(SELECT node, updated, (CASE WHEN (in_reply_to IS NULL) THEN id ELSE in_reply_to END) AS thread_id FROM items) AS _items" +
230-
"WHERE node = ? " +
231-
"GROUP BY thread_id " +
232-
"HAVING MAX(updated) < ? " +
233-
"ORDER BY thread_updated DESC LIMIT ?) AS threads " +
234-
"WHERE items.in_reply_to = threads.thread_id OR items.id = threads.thread_id " +
235-
"ORDER BY threads.thread_updated DESC, items.updated;";
236-
237-
private static final String COUNT_NODE_THREADS = "SELECT COUNT(DISTINCT _items.thread_id) " +
238-
"FROM (SELECT node, (CASE WHEN (in_reply_to IS NULL) THEN id ELSE in_reply_to END) AS thread_id " +
239-
"FROM items WHERE node = ?) AS _items;";
226+
"SELECT \"node\", \"id\", \"updated\", \"xml\", \"in_reply_to\", " +
227+
"\"thread_id\", \"thread_updated\" FROM \"items\"," +
228+
"(SELECT MAX(\"updated\") AS \"thread_updated\", \"thread_id\" FROM " +
229+
"(SELECT \"updated\", " +
230+
"(CASE WHEN (\"in_reply_to\" IS NULL) THEN \"id\" ELSE \"in_reply_to\" END) AS \"thread_id\" " +
231+
"FROM \"items\" WHERE \"node\" = ?) AS \"_items\" " +
232+
"GROUP BY \"thread_id\" " +
233+
"HAVING MAX(\"updated\") < ? " +
234+
"ORDER BY \"thread_updated\" DESC LIMIT ?) AS \"threads\" " +
235+
"WHERE \"in_reply_to\" = \"thread_id\" OR \"id\" = \"thread_id\" " +
236+
"ORDER BY \"thread_updated\" DESC, \"updated\"";
237+
238+
private static final String COUNT_NODE_THREADS = "SELECT COUNT(DISTINCT \"thread_id\") " +
239+
"FROM (SELECT \"node\", (CASE WHEN (\"in_reply_to\" IS NULL) THEN \"id\" ELSE \"in_reply_to\" END) AS \"thread_id\" " +
240+
"FROM \"items\" WHERE \"node\" = ?) AS \"_items\"";
240241

241242
@Override
242243
public String insertNode() {

src/test/java/org/buddycloud/channelserver/db/jdbc/JDBCNodeStoreTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.buddycloud.channelserver.db.jdbc;
22

3-
import static org.junit.Assert.*;
3+
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertFalse;
55
import static org.junit.Assert.assertNotNull;
66
import static org.junit.Assert.assertNull;
@@ -43,8 +43,8 @@
4343
import org.buddycloud.channelserver.pubsub.subscription.Subscriptions;
4444
import org.junit.After;
4545
import org.junit.Before;
46-
import org.junit.Test;
4746
import org.junit.Ignore;
47+
import org.junit.Test;
4848
import org.mockito.InOrder;
4949
import org.mockito.Mockito;
5050
import org.xmpp.packet.JID;
@@ -2319,4 +2319,16 @@ private void assertSameNodeItem(NodeItem actual, NodeItem expected) {
23192319
assertEquals(expected.getPayload(), actual.getPayload());
23202320
assertEquals(expected.getInReplyTo(), actual.getInReplyTo());
23212321
}
2322+
2323+
@Test
2324+
public void testSelectNodeThreads() throws Exception {
2325+
dbTester.loadData("node_1");
2326+
assertEquals(5, store.getNodeThreads(TEST_SERVER1_NODE1_ID, null, 10).size());
2327+
}
2328+
2329+
@Test
2330+
public void testCountNodeThreads() throws Exception {
2331+
dbTester.loadData("node_1");
2332+
assertEquals(5, store.countNodeThreads(TEST_SERVER1_NODE1_ID));
2333+
}
23222334
}

0 commit comments

Comments
 (0)