Skip to content

Commit f5a0e20

Browse files
committed
Add tests + code for retrieving node item count for parent only
1 parent c0299de commit f5a0e20

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

src/main/java/org/buddycloud/channelserver/db/jdbc/JDBCNodeStore.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,15 @@ public int countNodeItems(String nodeId, boolean parentOnly) throws NodeStoreExc
13161316
PreparedStatement selectStatement = null;
13171317

13181318
try {
1319-
selectStatement = conn.prepareStatement(dialect.countItemsForNode());
1319+
String query = dialect.countItemsForNode();
1320+
String parentOnlySubstitution = "";
1321+
if (parentOnly) {
1322+
parentOnlySubstitution = "AND \"in_reply_to\" IS NULL";
1323+
}
1324+
System.out.println("\n\n\n\n\n" + query.replace("%parentOnly%", parentOnlySubstitution) + " " + parentOnly);
1325+
selectStatement = conn.prepareStatement(
1326+
query.replace("%parentOnly%", parentOnlySubstitution)
1327+
);
13201328
selectStatement.setString(1, nodeId);
13211329

13221330
java.sql.ResultSet rs = selectStatement.executeQuery();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public class Sql92NodeStoreDialect implements NodeStoreSQLDialect {
130130
private static final String SELECT_COUNT_RECENT_ITEM_PARTS = "" + "(SELECT COUNT(\"id\") " + "FROM \"items\" " + "WHERE \"node\" = ? "
131131
+ "AND \"updated\" > ? " + "%parentOnly% " + "LIMIT ?)";
132132

133-
private static final String COUNT_ITEMS_FOR_NODE = "SELECT COUNT(*)" + " FROM \"items\" WHERE \"node\" = ?";
133+
private static final String COUNT_ITEMS_FOR_NODE = "SELECT COUNT(*)" + " FROM \"items\" WHERE \"node\" = ? %parentOnly%;";
134134

135135
private static final String SELECT_ITEM_REPLIES = "" + "SELECT \"id\", \"node\", \"xml\", \"updated\", \"in_reply_to\", \"created\" "
136136
+ "FROM \"items\" WHERE \"node\" = ? AND \"in_reply_to\" LIKE ? " + "AND \"updated\" > ? ORDER BY \"updated\" DESC";

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ public void testCountNodeItems() throws Exception {
259259

260260
assertEquals("Incorrect item count", 5, result);
261261
}
262+
263+
@Test
264+
public void countNodeItemsWithNoReplies() throws Exception {
265+
dbTester.loadData("node_1");
266+
dbTester.loadData("node_4");
267+
268+
int result = store.countNodeItems(TEST_SERVER1_NODE1_ID, true);
269+
270+
assertEquals("Incorrect item count", 6, result);
271+
}
262272

263273
@Test
264274
public void testGetNewNodeItemsForUserBetweenDates() throws Exception {

src/test/resources/org/buddycloud/channelserver/testing/jdbc/scripts/node_1.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ INSERT INTO "items" ("node", "id", "updated", "xml") VALUES ('users/node1@server
111111
<activity:object-type>note</activity:object-type>
112112
</activity:object>
113113
</entry>');
114-
114+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
INSERT INTO "items" ("node", "id", "updated", "xml", "in_reply_to") VALUES ('users/node1@server1/posts', 'a6', TIMESTAMP '2010-01-08 11:45:12', '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
2+
<published>2010-01-08T11:45:12Z</published>
3+
<author>
4+
<name>user2@server1</name>
5+
<jid xmlns="http://buddycloud.com/atom-elements-0">user2@server1</jid>
6+
</author>
7+
<content type="text">Test 5</content>
8+
<geoloc xmlns="http://jabber.org/protocol/geoloc">
9+
<text>London, England</text>
10+
<locality>London</locality>
11+
<country>England</country>
12+
</geoloc>
13+
14+
<activity:verb>post</activity:verb>
15+
<activity:object>
16+
<activity:object-type>note</activity:object-type>
17+
</activity:object>
18+
</entry>', 'a1');
19+
20+
INSERT INTO "items" ("node", "id", "updated", "xml", "in_reply_to") VALUES ('users/node1@server1/posts', 'a7', TIMESTAMP '2010-01-06 22:32:12', '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
21+
<published>2010-01-06T22:32:12Z</published>
22+
<author>
23+
<name>user1@server1</name>
24+
<jid xmlns="http://buddycloud.com/atom-elements-0">user1@server1</jid>
25+
</author>
26+
<content type="text">Test 2</content>
27+
<geoloc xmlns="http://jabber.org/protocol/geoloc">
28+
<text>Paris, France</text>
29+
<locality>Paris</locality>
30+
<country>France</country>
31+
</geoloc>
32+
33+
<activity:verb>post</activity:verb>
34+
<activity:object>
35+
<activity:object-type>note</activity:object-type>
36+
</activity:object>
37+
</entry>', 'a1');
38+
39+
INSERT INTO "items" ("node", "id", "updated", "xml", "in_reply_to") VALUES ('users/node1@server1/posts', 'a8', TIMESTAMP '2010-01-06 22:32:12', '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
40+
<published>2010-01-06T22:32:12Z</published>
41+
<author>
42+
<name>user1@server1</name>
43+
<jid xmlns="http://buddycloud.com/atom-elements-0">user1@server1</jid>
44+
</author>
45+
<content type="text">Test 2</content>
46+
<geoloc xmlns="http://jabber.org/protocol/geoloc">
47+
<text>Paris, France</text>
48+
<locality>Paris</locality>
49+
<country>France</country>
50+
</geoloc>
51+
52+
<activity:verb>post</activity:verb>
53+
<activity:object>
54+
<activity:object-type>note</activity:object-type>
55+
</activity:object>
56+
</entry>', NULL);

0 commit comments

Comments
 (0)