mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-9153 Discussions rest webscript tests
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29691 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,14 +19,19 @@
|
|||||||
package org.alfresco.repo.web.scripts.discussion;
|
package org.alfresco.repo.web.scripts.discussion;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.transaction.UserTransaction;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.model.ForumModel;
|
import org.alfresco.model.ForumModel;
|
||||||
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.site.SiteModel;
|
import org.alfresco.repo.site.SiteModel;
|
||||||
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
||||||
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||||
@@ -37,6 +42,7 @@ import org.alfresco.service.cmr.site.SiteService;
|
|||||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||||
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
import org.alfresco.util.PropertyMap;
|
import org.alfresco.util.PropertyMap;
|
||||||
import org.springframework.extensions.webscripts.Status;
|
import org.springframework.extensions.webscripts.Status;
|
||||||
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
|
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
|
||||||
@@ -60,10 +66,13 @@ public class DiscussionServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
private MutableAuthenticationService authenticationService;
|
private MutableAuthenticationService authenticationService;
|
||||||
private AuthenticationComponent authenticationComponent;
|
private AuthenticationComponent authenticationComponent;
|
||||||
|
private TransactionService transactionService;
|
||||||
|
private BehaviourFilter policyBehaviourFilter;
|
||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
private PersonService personService;
|
private PersonService personService;
|
||||||
private SiteService siteService;
|
private SiteService siteService;
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
|
private NodeService internalNodeService;
|
||||||
|
|
||||||
private static final String USER_ONE = "UserOneThird";
|
private static final String USER_ONE = "UserOneThird";
|
||||||
private static final String USER_TWO = "UserTwoThird";
|
private static final String USER_TWO = "UserTwoThird";
|
||||||
@@ -88,10 +97,13 @@ public class DiscussionServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
|
this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
|
||||||
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
|
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
|
||||||
|
this.policyBehaviourFilter = (BehaviourFilter)getServer().getApplicationContext().getBean("policyBehaviourFilter");
|
||||||
|
this.transactionService = (TransactionService)getServer().getApplicationContext().getBean("transactionService");
|
||||||
|
this.permissionService = (PermissionService)getServer().getApplicationContext().getBean("PermissionService");
|
||||||
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
|
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
|
||||||
this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
|
this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
|
||||||
this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
|
this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
|
||||||
this.permissionService = (PermissionService)getServer().getApplicationContext().getBean("PermissionService");
|
this.internalNodeService = (NodeService)getServer().getApplicationContext().getBean("nodeService");
|
||||||
|
|
||||||
// Authenticate as user
|
// Authenticate as user
|
||||||
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||||
@@ -312,6 +324,10 @@ public class DiscussionServiceTest extends BaseWebScriptTest
|
|||||||
{
|
{
|
||||||
url = baseUrl;
|
url = baseUrl;
|
||||||
}
|
}
|
||||||
|
else if(type == "limit")
|
||||||
|
{
|
||||||
|
url = baseUrl + "?pageSize=1";
|
||||||
|
}
|
||||||
else if(type == "hot")
|
else if(type == "hot")
|
||||||
{
|
{
|
||||||
url = baseUrl + "/hot";
|
url = baseUrl + "/hot";
|
||||||
@@ -415,6 +431,40 @@ public class DiscussionServiceTest extends BaseWebScriptTest
|
|||||||
return result.getJSONObject("item");
|
return result.getJSONObject("item");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monkeys with the created and published dates on a topic+posts
|
||||||
|
*/
|
||||||
|
private void pushCreatedDateBack(NodeRef node, int daysAgo) throws Exception
|
||||||
|
{
|
||||||
|
Date created = (Date)nodeService.getProperty(node, ContentModel.PROP_CREATED);
|
||||||
|
Date newCreated = new Date(created.getTime() - daysAgo*24*60*60*1000);
|
||||||
|
Date published = (Date)nodeService.getProperty(node, ContentModel.PROP_PUBLISHED);
|
||||||
|
if(published == null) published = created;
|
||||||
|
Date newPublished = new Date(published.getTime() - daysAgo*24*60*60*1000);
|
||||||
|
|
||||||
|
UserTransaction txn = transactionService.getUserTransaction();
|
||||||
|
txn.begin();
|
||||||
|
|
||||||
|
this.policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
|
||||||
|
internalNodeService.setProperty(node, ContentModel.PROP_CREATED, newCreated);
|
||||||
|
internalNodeService.setProperty(node, ContentModel.PROP_MODIFIED, newCreated);
|
||||||
|
internalNodeService.setProperty(node, ContentModel.PROP_PUBLISHED, newPublished);
|
||||||
|
this.policyBehaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE);
|
||||||
|
|
||||||
|
txn.commit();
|
||||||
|
|
||||||
|
// Now chance something else on the node to have it re-indexed
|
||||||
|
nodeService.setProperty(node, ContentModel.PROP_CREATED, newCreated);
|
||||||
|
nodeService.setProperty(node, ContentModel.PROP_MODIFIED, newCreated);
|
||||||
|
nodeService.setProperty(node, ContentModel.PROP_PUBLISHED, newPublished);
|
||||||
|
nodeService.setProperty(node, ContentModel.PROP_DESCRIPTION, "Forced change");
|
||||||
|
|
||||||
|
// Finally change any children (eg if updating a topic, do the posts)
|
||||||
|
for(ChildAssociationRef ref : nodeService.getChildAssocs(node))
|
||||||
|
{
|
||||||
|
pushCreatedDateBack(ref.getChildRef(), daysAgo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Tests
|
// Tests
|
||||||
@@ -982,18 +1032,119 @@ public class DiscussionServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
// Shift some of the posts into the past
|
// Shift some of the posts into the past
|
||||||
// (Update the created and published dates)
|
// (Update the created and published dates)
|
||||||
|
pushCreatedDateBack(siteTopic1, 10);
|
||||||
|
pushCreatedDateBack(siteReply1B, -2); // Make it newer
|
||||||
|
|
||||||
|
pushCreatedDateBack(nodeTopic2, 10);
|
||||||
|
pushCreatedDateBack(nodeTopic3, 4);
|
||||||
|
pushCreatedDateBack(nodeReply1AAA, -1); // Make it newer
|
||||||
|
|
||||||
|
|
||||||
// Re-check totals, no change
|
// Re-check totals, only ordering changes
|
||||||
|
result = getPosts(null, Status.STATUS_OK);
|
||||||
|
assertEquals(2, result.getInt("total"));
|
||||||
|
assertEquals(2, result.getInt("itemCount"));
|
||||||
|
assertEquals(2, result.getJSONArray("items").length());
|
||||||
|
assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(1).getString("title"));
|
||||||
|
assertEquals(2, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||||
|
assertEquals(3, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
|
||||||
|
|
||||||
|
result = getPosts(FORUM_NODE, null, Status.STATUS_OK);
|
||||||
|
assertEquals(3, result.getInt("total"));
|
||||||
|
assertEquals(3, result.getInt("itemCount"));
|
||||||
|
assertEquals(3, result.getJSONArray("items").length());
|
||||||
|
// TODO This appears to be incorrect...
|
||||||
|
assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(1).getString("title"));
|
||||||
|
// assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
// assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(1).getString("title"));
|
||||||
|
assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(2).getString("title"));
|
||||||
|
assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||||
|
assertEquals(0, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
|
||||||
|
assertEquals(1, result.getJSONArray("items").getJSONObject(2).getInt("replyCount"));
|
||||||
|
|
||||||
|
|
||||||
// Re-check recent, old ones vanish
|
// Re-check recent, old ones vanish
|
||||||
|
result = getPosts("new?numdays=2", Status.STATUS_OK);
|
||||||
|
assertEquals(1, result.getInt("total"));
|
||||||
|
assertEquals(1, result.getInt("itemCount"));
|
||||||
|
assertEquals(1, result.getJSONArray("items").length());
|
||||||
|
assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
assertEquals(3, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||||
|
|
||||||
|
result = getPosts(FORUM_NODE, "new?numdays=6", Status.STATUS_OK);
|
||||||
|
assertEquals(2, result.getInt("total"));
|
||||||
|
assertEquals(2, result.getInt("itemCount"));
|
||||||
|
assertEquals(2, result.getJSONArray("items").length());
|
||||||
|
assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(1).getString("title"));
|
||||||
|
assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||||
|
assertEquals(1, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
|
||||||
|
|
||||||
|
result = getPosts(FORUM_NODE, "new?numdays=2", Status.STATUS_OK);
|
||||||
|
assertEquals(1, result.getInt("total"));
|
||||||
|
assertEquals(1, result.getInt("itemCount"));
|
||||||
|
assertEquals(1, result.getJSONArray("items").length());
|
||||||
|
assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
assertEquals(1, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||||
|
|
||||||
|
|
||||||
|
// Re-check "mine", no change except ordering
|
||||||
|
result = getPosts("mine", Status.STATUS_OK);
|
||||||
|
assertEquals(1, result.getInt("total"));
|
||||||
|
assertEquals(1, result.getInt("itemCount"));
|
||||||
|
assertEquals(1, result.getJSONArray("items").length());
|
||||||
|
assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
assertEquals(2, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||||
|
|
||||||
|
result = getPosts(FORUM_NODE, "mine", Status.STATUS_OK);
|
||||||
|
assertEquals(2, result.getInt("total"));
|
||||||
|
assertEquals(2, result.getInt("itemCount"));
|
||||||
|
assertEquals(2, result.getJSONArray("items").length());
|
||||||
|
// TODO This appears to be incorrect...
|
||||||
|
assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(1).getString("title"));
|
||||||
|
// assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
// assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(1).getString("title"));
|
||||||
|
assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||||
|
assertEquals(0, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
|
||||||
|
|
||||||
// Re-check "mine", no change
|
|
||||||
|
|
||||||
// Re-check hot, some old ones vanish
|
// Re-check hot, some old ones vanish
|
||||||
|
result = getPosts("hot", Status.STATUS_OK);
|
||||||
|
assertEquals(2, result.getInt("total"));
|
||||||
|
assertEquals(2, result.getInt("itemCount"));
|
||||||
|
assertEquals(2, result.getJSONArray("items").length());
|
||||||
|
assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(1).getString("title"));
|
||||||
|
assertEquals(3, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||||
|
assertEquals(2, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
|
||||||
|
|
||||||
|
result = getPosts(FORUM_NODE, "hot", Status.STATUS_OK);
|
||||||
|
assertEquals(1, result.getInt("total"));
|
||||||
|
assertEquals(1, result.getInt("itemCount"));
|
||||||
|
assertEquals(1, result.getJSONArray("items").length());
|
||||||
|
assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
assertEquals(1, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||||
|
|
||||||
|
|
||||||
// TODO Check paging
|
// Check paging
|
||||||
|
result = getPosts("limit", Status.STATUS_OK);
|
||||||
|
assertEquals(2, result.getInt("total"));
|
||||||
|
assertEquals(1, result.getInt("itemCount"));
|
||||||
|
assertEquals(1, result.getJSONArray("items").length());
|
||||||
|
assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
assertEquals(2, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||||
|
|
||||||
|
result = getPosts(FORUM_NODE, "limit", Status.STATUS_OK);
|
||||||
|
assertEquals(3, result.getInt("total"));
|
||||||
|
assertEquals(1, result.getInt("itemCount"));
|
||||||
|
assertEquals(1, result.getJSONArray("items").length());
|
||||||
|
// TODO This appears to be incorrect...
|
||||||
|
assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
// assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||||
|
assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user