Rating Service checkpoint.

Added some of the REST API for the rating service. (Work in progress)
    GET ratingdefinitions url=/api/rating/schemedefinitions
    GET ratings url=/api/node/{store_type}/{store_id}/{id}/ratings


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21068 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2010-07-12 08:41:01 +00:00
parent 0465e9b101
commit 43654cd646
2 changed files with 23 additions and 58 deletions

View File

@@ -1,40 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.rating;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* This class is a holder for the various test classes associated with the Rating Service.
* It is not (at the time of writing) intended to be incorporated into the automatic build
* which will find the various test classes and run them individually.
*
* @author Neil McErlean
* @since 3.4
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
RatingNodePropertiesTest.class,
RatingServiceIntegrationTest.class
})
public class AllRatingTests
{
// Intentionally empty
}

View File

@@ -33,6 +33,7 @@ import org.alfresco.service.cmr.rating.RatingScheme;
import org.alfresco.service.cmr.rating.RatingService; import org.alfresco.service.cmr.rating.RatingService;
import org.alfresco.service.cmr.rating.RatingServiceException; import org.alfresco.service.cmr.rating.RatingServiceException;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
@@ -47,8 +48,9 @@ import org.alfresco.util.PropertyMap;
*/ */
public class RatingServiceIntegrationTest extends BaseAlfrescoSpringTest public class RatingServiceIntegrationTest extends BaseAlfrescoSpringTest
{ {
private static final String USER_ERNIE = "Ernie"; private static final String USER_ONE = "UserOne";
private static final String USER_ERIC = "Eric"; private static final String USER_USERTWO = "UserTwo";
private CopyService copyService;
private PersonService personService; private PersonService personService;
private RatingService ratingService; private RatingService ratingService;
private Repository repositoryHelper; private Repository repositoryHelper;
@@ -56,9 +58,10 @@ public class RatingServiceIntegrationTest extends BaseAlfrescoSpringTest
// These NodeRefs are used by the test methods. // These NodeRefs are used by the test methods.
private NodeRef testFolder; private NodeRef testFolder;
private NodeRef testFolderCopyDest;
private NodeRef testDoc_Admin; private NodeRef testDoc_Admin;
private NodeRef testDoc_Eric; private NodeRef testDoc_UserOne;
private NodeRef testDoc_Ernie; private NodeRef testDoc_UserTwo;
// The out of the box scheme names. // The out of the box scheme names.
private static final String LIKES_SCHEME_NAME = "likesRatingScheme"; private static final String LIKES_SCHEME_NAME = "likesRatingScheme";
@@ -68,6 +71,7 @@ public class RatingServiceIntegrationTest extends BaseAlfrescoSpringTest
protected void onSetUpInTransaction() throws Exception protected void onSetUpInTransaction() throws Exception
{ {
super.onSetUpInTransaction(); super.onSetUpInTransaction();
this.copyService = (CopyService)this.applicationContext.getBean("CopyService");
this.personService = (PersonService)this.applicationContext.getBean("PersonService"); this.personService = (PersonService)this.applicationContext.getBean("PersonService");
this.ratingService = (RatingService) this.applicationContext.getBean("ratingService"); this.ratingService = (RatingService) this.applicationContext.getBean("ratingService");
this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper"); this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
@@ -79,15 +83,16 @@ public class RatingServiceIntegrationTest extends BaseAlfrescoSpringTest
//TODO These could be created @BeforeClass //TODO These could be created @BeforeClass
testFolder = createNode(companyHome, "testFolder", ContentModel.TYPE_FOLDER); testFolder = createNode(companyHome, "testFolder", ContentModel.TYPE_FOLDER);
testFolderCopyDest = createNode(companyHome, "testFolderCopyDest", ContentModel.TYPE_FOLDER);
testDoc_Admin = createNode(testFolder, "testDocInFolder", ContentModel.TYPE_CONTENT); testDoc_Admin = createNode(testFolder, "testDocInFolder", ContentModel.TYPE_CONTENT);
createUser(USER_ERIC); createUser(USER_USERTWO);
createUser(USER_ERNIE); createUser(USER_ONE);
AuthenticationUtil.setFullyAuthenticatedUser(USER_ERIC); AuthenticationUtil.setFullyAuthenticatedUser(USER_USERTWO);
testDoc_Eric = createNode(testFolder, "ericsDoc", ContentModel.TYPE_CONTENT); testDoc_UserOne = createNode(testFolder, "userOnesDoc", ContentModel.TYPE_CONTENT);
AuthenticationUtil.setFullyAuthenticatedUser(USER_ERNIE); AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
testDoc_Ernie = createNode(testFolder, "erniesDoc", ContentModel.TYPE_CONTENT); testDoc_UserTwo = createNode(testFolder, "userTwosDoc", ContentModel.TYPE_CONTENT);
// And back to admin // And back to admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
@@ -97,8 +102,8 @@ public class RatingServiceIntegrationTest extends BaseAlfrescoSpringTest
protected void onTearDownInTransaction() throws Exception protected void onTearDownInTransaction() throws Exception
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
deleteUser(USER_ERIC); deleteUser(USER_USERTWO);
deleteUser(USER_ERNIE); deleteUser(USER_ONE);
} }
private NodeRef createNode(NodeRef parentNode, String name, QName type) private NodeRef createNode(NodeRef parentNode, String name, QName type)
@@ -167,8 +172,8 @@ public class RatingServiceIntegrationTest extends BaseAlfrescoSpringTest
public void testApplyUpdateDeleteRatings_SingleUserMultipleSchemes() throws Exception public void testApplyUpdateDeleteRatings_SingleUserMultipleSchemes() throws Exception
{ {
// We'll do all this as user 'eric'. // We'll do all this as user 'UserOne'.
AuthenticationUtil.setFullyAuthenticatedUser(USER_ERIC); AuthenticationUtil.setFullyAuthenticatedUser(USER_USERTWO);
//Before we start, let's ensure the read behaviour on a pristine node is correct. //Before we start, let's ensure the read behaviour on a pristine node is correct.
Rating nullRating = ratingService.getRatingByCurrentUser(testDoc_Admin, LIKES_SCHEME_NAME); Rating nullRating = ratingService.getRatingByCurrentUser(testDoc_Admin, LIKES_SCHEME_NAME);
@@ -282,10 +287,10 @@ public class RatingServiceIntegrationTest extends BaseAlfrescoSpringTest
public void testApplyRating_MultipleUsers() throws Exception public void testApplyRating_MultipleUsers() throws Exception
{ {
// 2 different users rating the same piece of content in the same rating scheme // 2 different users rating the same piece of content in the same rating scheme
AuthenticationUtil.setFullyAuthenticatedUser(USER_ERNIE); AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
ratingService.applyRating(testDoc_Admin, 4, FIVE_STAR_SCHEME_NAME); ratingService.applyRating(testDoc_Admin, 4, FIVE_STAR_SCHEME_NAME);
AuthenticationUtil.setFullyAuthenticatedUser(USER_ERIC); AuthenticationUtil.setFullyAuthenticatedUser(USER_USERTWO);
ratingService.applyRating(testDoc_Admin, 2, FIVE_STAR_SCHEME_NAME); ratingService.applyRating(testDoc_Admin, 2, FIVE_STAR_SCHEME_NAME);
float meanRating = ratingService.getAverageRating(testDoc_Admin, FIVE_STAR_SCHEME_NAME); float meanRating = ratingService.getAverageRating(testDoc_Admin, FIVE_STAR_SCHEME_NAME);
@@ -302,8 +307,8 @@ public class RatingServiceIntegrationTest extends BaseAlfrescoSpringTest
{ {
try try
{ {
AuthenticationUtil.setFullyAuthenticatedUser(USER_ERNIE); AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
ratingService.applyRating(testDoc_Ernie, 4, FIVE_STAR_SCHEME_NAME); ratingService.applyRating(testDoc_UserTwo, 4, FIVE_STAR_SCHEME_NAME);
} catch (RatingServiceException expected) } catch (RatingServiceException expected)
{ {
return; return;