configSystemRegistry.put("/test/comments/q1", comQuery);
Map<String, String> params = new HashMap<String, String>();
params.put("1", "%comment%");
params.put("2", "r1x");
Collection qResults = registry.executeQuery("/test/comments/q1", params);
String[] qPaths = (String[]) qResults.getContent();
assertEquals("Query result count should be 4", qPaths.length, 4);
// we can't expect the comment number to be 4 , 3, 2, 1 if already comments there in the
// database it will take different numbers
assertEquals("Comment query result is invalid",
((Comment) registry.get(qPaths[0])).getText(),
"a new test comment");
assertEquals("Comment query result is invalid",
((Comment) registry.get(qPaths[1])).getText(),
"commentXX3 on this resource :)");
assertEquals("Comment query result is invalid",
((Comment) registry.get(qPaths[2])).getText(),
"commentXX2 on this resource :)");
assertEquals("Comment query result is invalid",
((Comment) registry.get(qPaths[3])).getText(),
"commentXX1 on this resource :)");
Resource qResult = registry.get(qPaths[0]);
assertTrue("Comment query should return Comment objects as results",
qResult instanceof Comment);
Comment c1 = (Comment) qResult;
assertNotNull("Comment query result is invalid", c1.getText());
assertNotNull("Comment query result is invalid", c1.getUser());
assertNotNull("Comment query result is invalid", c1.getCreatedTime());
Resource r2 = registry.newResource();
r2.setContent("r2 content");
registry.put("/test/comments/r2", r2);
registry.addComment("/test/comments/r2", new Comment("commentXX1 on this resource :)"));
registry.addComment("/test/comments/r2", new Comment("commentXX2 on this resource :)"));
registry.addComment("/test/comments/r2", new Comment("commentXX3 on this resource :)"));
registry.addComment("/test/comments/r2", new Comment("a new test comment"));
comQuery = configSystemRegistry.newResource();
sql = "SELECT REG_COMMENT_ID FROM REG_COMMENT C, REG_RESOURCE_COMMENT RC " +
"WHERE C.REG_COMMENT_TEXT LIKE ? AND C.REG_ID=RC.REG_COMMENT_ID " +
"AND RC.REG_RESOURCE_NAME=? ORDER BY C.REG_COMMENTED_TIME LIMIT ?, ?";
comQuery.setContent(sql);
comQuery.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
comQuery.addProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME,
RegistryConstants.COMMENTS_RESULT_TYPE);
configSystemRegistry.put("/test/comments/q1", comQuery);
params = new HashMap<String, String>();
params.put("1", "%comment%");
params.put("2", "r2");
params.put("3", "1");
params.put("4", "4");
qResults = registry.executeQuery("/test/comments/q1", params);
qPaths = (String[]) qResults.getContent();
assertEquals("Query result count should be 3", qPaths.length, 3);
assertEquals("Comment query result is invalid",
((Comment) registry.get(qPaths[2])).getText(),
"a new test comment");