mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9153 Add unit tests for the new discussions hot topics CQ and service method
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30028 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -36,7 +36,6 @@ import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.discussion.cannedqueries.GetDiscussionTopcisWithPostsCannedQuery;
|
||||
import org.alfresco.repo.discussion.cannedqueries.GetDiscussionTopcisWithPostsCannedQueryFactory;
|
||||
import org.alfresco.repo.discussion.cannedqueries.NodeWithChildrenEntity;
|
||||
import org.alfresco.repo.discussion.cannedqueries.NodeWithChildrenEntity.NameAndCreatedAt;
|
||||
import org.alfresco.repo.domain.node.NodeDAO;
|
||||
import org.alfresco.repo.node.getchildren.GetChildrenAuditableCannedQuery;
|
||||
import org.alfresco.repo.node.getchildren.GetChildrenAuditableCannedQueryFactory;
|
||||
@@ -678,7 +677,7 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
// Do the query
|
||||
GetDiscussionTopcisWithPostsCannedQueryFactory getCQFactory = (GetDiscussionTopcisWithPostsCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_TOPICS_WITH_POSTS);
|
||||
GetDiscussionTopcisWithPostsCannedQuery cq = (GetDiscussionTopcisWithPostsCannedQuery)getCQFactory.getCannedQuery(
|
||||
nodeRef, null, since, null, paging);
|
||||
nodeRef, null, since, true, null, paging);
|
||||
|
||||
// Execute the canned query
|
||||
CannedQueryResults<NodeWithChildrenEntity> results = cq.execute();
|
||||
@@ -1088,18 +1087,9 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
{
|
||||
NodeRef nodeRef = node.getNodeRef();
|
||||
String name = node.getName();
|
||||
TopicInfo topic = buildTopic(nodeRef, container, name);
|
||||
|
||||
int count = node.getChildren().size();
|
||||
for(NameAndCreatedAt c : node.getChildren())
|
||||
{
|
||||
if(c.getName().equals(name))
|
||||
{
|
||||
// Primary post
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
TopicInfo topic = buildTopic(nodeRef, container, name);
|
||||
topics.add(new Pair<TopicInfo,Integer>(topic, count));
|
||||
}
|
||||
return topics;
|
||||
|
@@ -1223,9 +1223,167 @@ public class DiscussionServiceImplTest
|
||||
|
||||
|
||||
// Add a few replies, topics will begin showing up
|
||||
PostInfo replySA1 = DISCUSSION_SERVICE.createReply(postSA, "Reply SA 1");
|
||||
PostInfo replySB1 = DISCUSSION_SERVICE.createReply(postSB, "Reply SB 1");
|
||||
PostInfo replySB2 = DISCUSSION_SERVICE.createReply(postSB, "Reply SB 2");
|
||||
PostInfo replySB3 = DISCUSSION_SERVICE.createReply(postSB, "Reply SB 3");
|
||||
PostInfo replyNA1 = DISCUSSION_SERVICE.createReply(postNA, "Reply NA 1");
|
||||
PostInfo replyNB1 = DISCUSSION_SERVICE.createReply(postNB, "Reply NB 1");
|
||||
PostInfo replyNB2 = DISCUSSION_SERVICE.createReply(postNB, "Reply NB 2");
|
||||
PostInfo replyNB3 = DISCUSSION_SERVICE.createReply(postNB, "Reply NB 3");
|
||||
PostInfo replyNB4 = DISCUSSION_SERVICE.createReply(postNB, "Reply NB 4");
|
||||
|
||||
// Check we now see things as expected, ordered by count
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, paging);
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals(topicSB.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(3, topics.getPage().get(0).getSecond().intValue());
|
||||
assertEquals(topicSA.getTitle(), topics.getPage().get(1).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(1).getSecond().intValue());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(FORUM_NODE, fourDaysAgo, paging);
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals(topicNB.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(4, topics.getPage().get(0).getSecond().intValue());
|
||||
assertEquals(topicNA.getTitle(), topics.getPage().get(1).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(1).getSecond().intValue());
|
||||
|
||||
|
||||
// TODO
|
||||
// Add reply to reply, counts go up
|
||||
PostInfo replySA1_1 = DISCUSSION_SERVICE.createReply(replySA1, "Reply to a reply");
|
||||
PostInfo replyNA1_1 = DISCUSSION_SERVICE.createReply(replyNA1, "Reply to a reply");
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, paging);
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals(topicSB.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(3, topics.getPage().get(0).getSecond().intValue());
|
||||
assertEquals(topicSA.getTitle(), topics.getPage().get(1).getFirst().getTitle());
|
||||
assertEquals(2, topics.getPage().get(1).getSecond().intValue());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(FORUM_NODE, fourDaysAgo, paging);
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals(topicNB.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(4, topics.getPage().get(0).getSecond().intValue());
|
||||
assertEquals(topicNA.getTitle(), topics.getPage().get(1).getFirst().getTitle());
|
||||
assertEquals(2, topics.getPage().get(1).getSecond().intValue());
|
||||
|
||||
|
||||
// Changing the date of the primary post or the topic makes no difference
|
||||
pushAuditableDatesBack(topicSA, 11, 1);
|
||||
pushAuditableDatesBack(topicSB, 12, 2);
|
||||
pushAuditableDatesBack(topicNA, 13, 3);
|
||||
pushAuditableDatesBack(topicNB, 14, 4);
|
||||
pushAuditableDatesBack(postSA, 3, 3);
|
||||
pushAuditableDatesBack(postNA, 3, 3);
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, paging);
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals(topicSB.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(3, topics.getPage().get(0).getSecond().intValue());
|
||||
assertEquals(topicSA.getTitle(), topics.getPage().get(1).getFirst().getTitle());
|
||||
assertEquals(2, topics.getPage().get(1).getSecond().intValue());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(FORUM_NODE, fourDaysAgo, paging);
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals(topicNB.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(4, topics.getPage().get(0).getSecond().intValue());
|
||||
assertEquals(topicNA.getTitle(), topics.getPage().get(1).getFirst().getTitle());
|
||||
assertEquals(2, topics.getPage().get(1).getSecond().intValue());
|
||||
|
||||
|
||||
// Push some replies into the past, counts go down
|
||||
pushAuditableDatesBack(replySA1, 6, 6);
|
||||
pushAuditableDatesBack(replyNA1, 6, 6);
|
||||
pushAuditableDatesBack(replySB1, 1, 1); // Not enough to affect it
|
||||
pushAuditableDatesBack(replyNB1, 1, 1); // Not enough to affect it
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, paging);
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals(topicSB.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(3, topics.getPage().get(0).getSecond().intValue());
|
||||
assertEquals(topicSA.getTitle(), topics.getPage().get(1).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(1).getSecond().intValue());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(FORUM_NODE, fourDaysAgo, paging);
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals(topicNB.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(4, topics.getPage().get(0).getSecond().intValue());
|
||||
assertEquals(topicNA.getTitle(), topics.getPage().get(1).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(1).getSecond().intValue());
|
||||
|
||||
|
||||
// Push most replies into the past, still shows, created date ordering matters here
|
||||
pushAuditableDatesBack(replySB2, 10, 10);
|
||||
pushAuditableDatesBack(replySB3, 10, 10);
|
||||
pushAuditableDatesBack(replyNB2, 10, 10);
|
||||
pushAuditableDatesBack(replyNB3, 10, 10);
|
||||
pushAuditableDatesBack(replyNB4, 10, 10);
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, paging);
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals(topicSA.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(0).getSecond().intValue());
|
||||
assertEquals(topicSB.getTitle(), topics.getPage().get(1).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(1).getSecond().intValue());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(FORUM_NODE, fourDaysAgo, paging);
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals(topicNA.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(0).getSecond().intValue());
|
||||
assertEquals(topicNB.getTitle(), topics.getPage().get(1).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(1).getSecond().intValue());
|
||||
|
||||
|
||||
// Delete the few recent replies, topics will then vanish
|
||||
DISCUSSION_SERVICE.deletePost(replySB1);
|
||||
DISCUSSION_SERVICE.deletePost(replyNB1);
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, paging);
|
||||
assertEquals(1, topics.getPage().size());
|
||||
assertEquals(topicSA.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(0).getSecond().intValue());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(FORUM_NODE, fourDaysAgo, paging);
|
||||
assertEquals(1, topics.getPage().size());
|
||||
assertEquals(topicNA.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(0).getSecond().intValue());
|
||||
|
||||
|
||||
// Exact date matching check
|
||||
pushAuditableDatesBack(replySA1_1, 1, 1);
|
||||
pushAuditableDatesBack(replyNA1_1, 1, 1);
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, paging);
|
||||
assertEquals(1, topics.getPage().size());
|
||||
assertEquals(topicSA.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(0).getSecond().intValue());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(FORUM_NODE, fourDaysAgo, paging);
|
||||
assertEquals(1, topics.getPage().size());
|
||||
assertEquals(topicNA.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(0).getSecond().intValue());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(DISCUSSION_SITE.getShortName(), yesterday, paging);
|
||||
assertEquals(1, topics.getPage().size());
|
||||
assertEquals(topicSA.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(0).getSecond().intValue());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(FORUM_NODE, yesterday, paging);
|
||||
assertEquals(1, topics.getPage().size());
|
||||
assertEquals(topicNA.getTitle(), topics.getPage().get(0).getFirst().getTitle());
|
||||
assertEquals(1, topics.getPage().get(0).getSecond().intValue());
|
||||
|
||||
|
||||
// If we ask for a date in the future, we don't get anything though
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(DISCUSSION_SITE.getShortName(), tomorrow, paging);
|
||||
assertEquals(0, topics.getPage().size());
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(FORUM_NODE, tomorrow, paging);
|
||||
assertEquals(0, topics.getPage().size());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(DISCUSSION_SITE.getShortName(), future, paging);
|
||||
assertEquals(0, topics.getPage().size());
|
||||
topics = DISCUSSION_SERVICE.listHotTopics(FORUM_NODE, future, paging);
|
||||
assertEquals(0, topics.getPage().size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -111,11 +111,29 @@ public class GetDiscussionTopcisWithPostsCannedQuery extends AbstractCannedQuery
|
||||
result.setChildren(wantedPosts);
|
||||
}
|
||||
|
||||
// Ignore any topic with no replies
|
||||
// (As topics have a primary post, that means any with less than 2 children)
|
||||
if(result.getChildren().size() <= 1)
|
||||
// If required, filter out the primary post
|
||||
if(paramBean.getExcludePrimaryPost())
|
||||
{
|
||||
// No posts at all, or only the primary one
|
||||
List<NameAndCreatedAt> wantedPosts = new ArrayList<NameAndCreatedAt>();
|
||||
for(NameAndCreatedAt post : result.getChildren())
|
||||
{
|
||||
if(post.getName().equals( result.getName() ))
|
||||
{
|
||||
// Primary post, skip
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
wantedPosts.add(post);
|
||||
}
|
||||
}
|
||||
result.setChildren(wantedPosts);
|
||||
}
|
||||
|
||||
// Ignore any topic with no posts
|
||||
if(result.getChildren().size() == 0)
|
||||
{
|
||||
// No valid posts
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@@ -58,7 +58,7 @@ public class GetDiscussionTopcisWithPostsCannedQueryFactory extends AbstractQNam
|
||||
}
|
||||
|
||||
public CannedQuery<NodeWithChildrenEntity> getCannedQuery(NodeRef parentNodeRef,
|
||||
Date topicCreatedFrom, Date postCreatedFrom,
|
||||
Date topicCreatedFrom, Date postCreatedFrom, boolean excludePrimaryPosts,
|
||||
CannedQuerySortDetails sortDetails, PagingRequest pagingReq)
|
||||
{
|
||||
ParameterCheck.mandatory("parentNodeRef", parentNodeRef);
|
||||
@@ -72,7 +72,8 @@ public class GetDiscussionTopcisWithPostsCannedQueryFactory extends AbstractQNam
|
||||
getQNameId(ContentModel.PROP_NAME),
|
||||
getQNameId(ForumModel.TYPE_TOPIC),
|
||||
getQNameId(ForumModel.TYPE_POST),
|
||||
topicCreatedFrom, postCreatedFrom
|
||||
topicCreatedFrom, postCreatedFrom,
|
||||
excludePrimaryPosts
|
||||
);
|
||||
|
||||
CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
|
||||
|
@@ -28,18 +28,21 @@ import java.util.Date;
|
||||
*/
|
||||
public class GetDiscussionTopcisWithPostsCannedQueryParams extends NodeWithChildrenEntity
|
||||
{
|
||||
private Date topicCreatedAfter;
|
||||
private Date postCreatedAfter;
|
||||
private boolean excludePrimaryPost;
|
||||
private Date topicCreatedAfter;
|
||||
private Date postCreatedAfter;
|
||||
|
||||
public GetDiscussionTopcisWithPostsCannedQueryParams(Long parentNodeId,
|
||||
Long nameQNameId,
|
||||
Long contentTypeQNameId,
|
||||
Long childrenTypeId,
|
||||
Date topicCreatedAfter,
|
||||
Date postCreatedAfter)
|
||||
Date postCreatedAfter,
|
||||
boolean excludePrimaryPost)
|
||||
|
||||
{
|
||||
super(parentNodeId, nameQNameId, contentTypeQNameId, childrenTypeId);
|
||||
this.excludePrimaryPost = excludePrimaryPost;
|
||||
this.topicCreatedAfter = topicCreatedAfter;
|
||||
this.postCreatedAfter = postCreatedAfter;
|
||||
}
|
||||
@@ -53,4 +56,9 @@ public class GetDiscussionTopcisWithPostsCannedQueryParams extends NodeWithChild
|
||||
{
|
||||
return postCreatedAfter;
|
||||
}
|
||||
|
||||
public boolean getExcludePrimaryPost()
|
||||
{
|
||||
return excludePrimaryPost;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user