Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)

51903 to 54309 


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Samuel Langlois
2013-08-20 17:17:31 +00:00
parent 0a36e2af67
commit ab4ca7177f
1576 changed files with 36419 additions and 8603 deletions

View File

@@ -60,7 +60,6 @@ import org.json.JSONObject;
*/
public class PreferenceServiceImpl implements PreferenceService
{
private static final String SHARE_SITES_PREFERENCE_KEY = "org.alfresco.share.sites.favourites.";
private static final int SHARE_SITES_PREFERENCE_KEY_LEN = SHARE_SITES_PREFERENCE_KEY.length();
private static final String EXT_SITES_PREFERENCE_KEY = "org.alfresco.ext.sites.favourites.";
@@ -70,6 +69,8 @@ public class PreferenceServiceImpl implements PreferenceService
private ContentService contentService;
private PersonService personService;
private PermissionService permissionService;
/** Authentication Service */
private AuthenticationContext authenticationContext;
private AuthorityService authorityService;
@@ -87,7 +88,7 @@ public class PreferenceServiceImpl implements PreferenceService
{
this.contentService = contentService;
}
/**
* Set the person service
*
@@ -505,7 +506,7 @@ public class PreferenceServiceImpl implements PreferenceService
// Remove the prefs that match the filter
List<String> removeKeys = new ArrayList<String>(10);
@SuppressWarnings("unchecked")
Iterator<String> keys = jsonPrefs.keys();
Iterator<String> keys = jsonPrefs.keys();
while (keys.hasNext())
{
final String key = (String) keys.next();
@@ -548,7 +549,7 @@ public class PreferenceServiceImpl implements PreferenceService
+ " does not have sufficient permissions to update the preferences of the user " + userName);
}
}
/**
* Helper to encapsulate the test for whether the currently authenticated user can write to the
* preferences objects for the given username and person node reference.

View File

@@ -1,205 +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.preference;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.jscript.ClasspathScriptLocation;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.cmr.preference.PreferenceService;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.ScriptLocation;
import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.util.BaseAlfrescoSpringTest;
import org.alfresco.util.TestWithUserUtils;
/**
* Thumbnail service implementation unit test
*
* @author Roy Wetherall
*/
public class PreferenceServiceImplTest extends BaseAlfrescoSpringTest
{
private static final String USER_ONE = "userOne";
private static final String USER_BAD = "userBad";
private ScriptService scriptService;
private NodeService nodeService;
private AuthenticationComponent authenticationComponent;
private PreferenceService preferenceService;
private PersonService personService;
private ContentService contentService;
/**
* Called during the transaction setup
*/
protected void onSetUpInTransaction() throws Exception
{
super.onSetUpInTransaction();
// Get the required services
this.scriptService = (ScriptService) this.applicationContext.getBean("ScriptService");
this.nodeService = (NodeService) this.applicationContext.getBean("NodeService");
this.authenticationComponent = (AuthenticationComponent) this.applicationContext
.getBean("authenticationComponent");
this.preferenceService = (PreferenceService) this.applicationContext.getBean("PreferenceService");
this.personService = (PersonService) this.applicationContext.getBean("PersonService");
this.contentService = (ContentService) this.applicationContext.getBean("ContentService");
// Do the test's as userOne
TestWithUserUtils.authenticateUser(USER_ONE, "PWD", this.authenticationService, this.authenticationComponent);
}
public void testPreferences() throws Exception
{
// assertEquals(USER_ONE, AuthenticationUtil.getCurrentUserName());
// Try and get preferences before they have been set
Map<String, Serializable> prefs = this.preferenceService.getPreferences(USER_ONE);
assertNotNull(prefs);
assertEquals(0, prefs.size());
// assertEquals(USER_ONE, AuthenticationUtil.getCurrentUserName());
// Lets set some preferences for the user
prefs = new HashMap<String, Serializable>(5);
prefs.put("alfresco.one.alpha", "string");
prefs.put("alfresco.one.beta", 100);
prefs.put("alfresco.two.alpha", 3.142);
prefs.put("alfresco.two.beta", this.rootNodeRef);
prefs.put("alfresco.two.gamma", new Date());
prefs.put("atTheRoot", "thisIsAtTheRoot");
this.preferenceService.setPreferences(USER_ONE, prefs);
// assertEquals(USER_ONE, AuthenticationUtil.getCurrentUserName());
NodeRef personNodeRef = this.personService.getPerson(USER_ONE);
ContentReader reader = this.contentService.getReader(personNodeRef, ContentModel.PROP_PREFERENCE_VALUES);
System.out.println("JSON: " + reader.getContentString());
// Try and get all the preferences
prefs = this.preferenceService.getPreferences(USER_ONE, null);
assertNotNull(prefs);
assertEquals(6, prefs.size());
// Try and get some of the preferences
prefs = this.preferenceService.getPreferences(USER_ONE, "alfresco.two");
assertNotNull(prefs);
assertEquals(3, prefs.size());
// assertEquals(USER_ONE, AuthenticationUtil.getCurrentUserName());
// Clear some of the preferences
this.preferenceService.clearPreferences(USER_ONE, "alfresco.two");
prefs = this.preferenceService.getPreferences(USER_ONE, null);
assertNotNull(prefs);
assertEquals(3, prefs.size());
// assertEquals(USER_ONE, AuthenticationUtil.getCurrentUserName());
// Clear all the preferences
this.preferenceService.clearPreferences(USER_ONE);
prefs = this.preferenceService.getPreferences(USER_ONE);
assertNotNull(prefs);
assertEquals(0, prefs.size());
// assertEquals(USER_ONE, AuthenticationUtil.getCurrentUserName());
}
public void xtestBadUser()
{
assertEquals(USER_ONE, authenticationComponent.getCurrentUserName());
try
{
// Lets set some preferences for the user
Map<String, Serializable> prefs = new HashMap<String, Serializable>(5);
prefs.put("alfresco.one.alpha", "string");
prefs.put("alfresco.one.beta", 100);
prefs.put("alfresco.two.alpha", 3.142);
prefs.put("alfresco.two.beta", this.rootNodeRef);
prefs.put("alfresco.two.gamma", new Date());
prefs.put("atTheRoot", "thisIsAtTheRoot");
this.preferenceService.setPreferences(USER_BAD, prefs);
fail("This should have raised an exception since we are trying to update preferences that are not our own!");
}
catch (Exception exception)
{
// this is OK :)
}
}
public void testGetOtherUserPreferences()
{
assertEquals(USER_ONE, authenticationComponent.getCurrentUserName());
// Lets set some preferences for the user one
Map<String, Serializable> prefs = new HashMap<String, Serializable>(5);
prefs.put("alfresco.one.alpha", "string");
prefs.put("alfresco.one.beta", 100);
this.preferenceService.setPreferences(USER_ONE, prefs);
Map<String, Serializable> userOnePrefs = this.preferenceService.getPreferences(USER_ONE);
assertNotNull(userOnePrefs);
assertEquals(2, prefs.size());
// login as USER_BAD
TestWithUserUtils.authenticateUser(USER_BAD, "PWD", this.authenticationService, this.authenticationComponent);
assertEquals(USER_BAD, authenticationComponent.getCurrentUserName());
try
{
// Lets USER_BAD tries and get USER_ONE's preferences
@SuppressWarnings("unused")
Map<String, Serializable> badUserPrefs = this.preferenceService.getPreferences(USER_ONE);
fail("This should have raised an exception since we are trying to get preferences that are not our own!");
}
catch (Exception exception)
{
// this is OK
}
}
// == Test the JavaScript API ==
public void testJSAPI() throws Exception
{
// assertEquals(USER_ONE, authenticationComponent.getCurrentUserName());
ScriptLocation location = new ClasspathScriptLocation(
"org/alfresco/repo/preference/script/test_preferenceService.js");
this.scriptService.executeScript(location, new HashMap<String, Object>(0));
}
}

View File

@@ -25,6 +25,7 @@ import java.util.Map;
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.preference.PreferenceService;
import org.alfresco.service.transaction.TransactionService;
import org.mozilla.javascript.NativeObject;
/**
@@ -38,6 +39,13 @@ public class ScriptPreferenceService extends BaseScopableProcessorExtension
/** Preference Service */
private PreferenceService preferenceService;
private TransactionService transactionService;
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
public void setServiceRegistry(ServiceRegistry services)
{
this.services = services;
@@ -48,6 +56,11 @@ public class ScriptPreferenceService extends BaseScopableProcessorExtension
this.preferenceService = preferenceService;
}
public boolean getAllowWrite()
{
return transactionService.getAllowWrite();
}
public NativeObject getPreferences(String userName)
{
return getPreferences(userName, null);

View File

@@ -1,56 +0,0 @@
function testPreferences()
{
var preferences = new Object();
preferences.myValue = "myValue";
preferences.comp1 = new Object();
preferences.comp1.value1 = "value1";
preferences.comp1.value2 = 12;
preferenceService.setPreferences("userOne", preferences);
var result = preferenceService.getPreferences("userOne");
test.assertNotNull(result);
test.assertEquals("myValue", result.myValue);
test.assertEquals("value1", result.comp1.value1);
test.assertEquals(12, result.comp1.value2);
preferences = new Object();
preferences.comp2 = new Object();
preferences.comp2.value1 = "value1";
preferences.comp2.value2 = 3.142;
preferences.comp1 = new Object();
preferences.comp1.value1 = "changed";
preferences.comp1.value2 = 1001;
preferenceService.setPreferences("userOne", preferences);
result = preferenceService.getPreferences("userOne");
test.assertNotNull(result);
test.assertEquals("myValue", result.myValue);
test.assertEquals("changed", result.comp1.value1);
test.assertEquals(1001, result.comp1.value2);
test.assertEquals("value1", result.comp2.value1);
test.assertEquals(3.142, result.comp2.value2);
preferenceService.clearPreferences("userOne", "comp1");
result = preferenceService.getPreferences("userOne");
test.assertNotNull(result);
test.assertEquals("myValue", result.myValue);
test.assertEquals("undefined", result.comp1);
test.assertEquals("value1", result.comp2.value1);
test.assertEquals(3.142, result.comp2.value2);
preferenceService.clearPreferences("userOne");
result = preferenceService.getPreferences("userOne");
test.assertNotNull(result);
test.assertEquals("undefined", result.myValue);
test.assertEquals("undefined", result.comp1);
test.assertEquals("undefined", result.comp2);
}
// Execute test's
testPreferences();