Search in sources :

Example 16 with BlogPostInfo

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));
        }
    }
}
Also used : BlogPostInfo(org.alfresco.service.cmr.blog.BlogPostInfo) Date(java.util.Date)

Aggregations

BlogPostInfo (org.alfresco.service.cmr.blog.BlogPostInfo)16 ArrayList (java.util.ArrayList)10 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 PagingRequest (org.alfresco.query.PagingRequest)8 PagingResults (org.alfresco.query.PagingResults)8 List (java.util.List)7 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)7 BaseSpringTest (org.alfresco.util.BaseSpringTest)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)5 Date (java.util.Date)4 JSONObject (org.json.simple.JSONObject)4 RangedDateProperty (org.alfresco.service.cmr.blog.BlogService.RangedDateProperty)3 Pair (org.alfresco.util.Pair)3 Category (org.junit.experimental.categories.Category)3 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 IOException (java.io.IOException)1