use of org.alfresco.service.cmr.blog.BlogPostInfo in project alfresco-repository by Alfresco.
the class BlogServiceImplTest method assertSortingIsCorrect.
private void assertSortingIsCorrect(List<BlogPostInfo> blogPosts) {
// Sometimes you just have to see the data...
for (BlogPostInfo bpi : blogPosts) {
System.out.println(" -----");
Date published = (Date) NODE_SERVICE.getProperty(bpi.getNodeRef(), ContentModel.PROP_PUBLISHED);
Date created = (Date) NODE_SERVICE.getProperty(bpi.getNodeRef(), ContentModel.PROP_CREATED);
System.out.print(" published: " + (published == null ? " " : published.getTime()));
System.out.println(" created : " + created.getTime());
}
for (// We only want to iterate to the second-last item
int i = 0; // We only want to iterate to the second-last item
i < blogPosts.size() - 1; // We only want to iterate to the second-last item
i++) {
BlogPostInfo nextBPI = blogPosts.get(i);
BlogPostInfo followingBPI = blogPosts.get(i + 1);
Date nextPublishedDate = (Date) NODE_SERVICE.getProperty(nextBPI.getNodeRef(), ContentModel.PROP_PUBLISHED);
Date followingPublishedDate = (Date) NODE_SERVICE.getProperty(followingBPI.getNodeRef(), ContentModel.PROP_PUBLISHED);
Date nextCreatedDate = (Date) NODE_SERVICE.getProperty(nextBPI.getNodeRef(), ContentModel.PROP_CREATED);
Date followingCreatedDate = (Date) NODE_SERVICE.getProperty(followingBPI.getNodeRef(), ContentModel.PROP_CREATED);
// published must precede draft
if (nextPublishedDate == null && followingPublishedDate != null) {
fail("Published posts must precede draft posts");
} else if (nextPublishedDate != null && followingPublishedDate != null) {
assertTrue("Error in BlogPostInfo sorting. Published dates in wrong order.", !nextPublishedDate.before(followingPublishedDate));
} else if (nextPublishedDate == null && followingPublishedDate == null) {
assertTrue("Error in BlogPostInfo sorting. Created dates in wrong order.", !nextCreatedDate.before(followingCreatedDate));
}
}
}
Aggregations