Merged V4.1-BUG-FIX to HEAD

41549: (RECORD ONLY) ALF-15908: Ensure custom actions work (latest Surf libs r1140)
   41551: Fixed the failing unit test for ALF-15687.
   41553: ALF-14201: sorted out sorting issue in historic task query
   41554: ALF-15930: Removed redundant duplicate condition checking when deploying a workflow


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@41555 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Dave Ward
2012-09-13 10:06:19 +00:00
parent 11ee3f8511
commit e7fefd8f6a

View File

@@ -25,12 +25,12 @@ import org.alfresco.repo.web.scripts.BaseWebScriptTest;
import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.util.PropertyMap; import org.alfresco.util.PropertyMap;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
/** /**
* Unit test to test preference Web Script API * Unit test to test preference Web Script API
@@ -38,148 +38,153 @@ import org.json.JSONObject;
* @author Roy Wetherall * @author Roy Wetherall
*/ */
public class PreferenceServiceTest extends BaseWebScriptTest public class PreferenceServiceTest extends BaseWebScriptTest
{ {
private MutableAuthenticationService authenticationService; private MutableAuthenticationService authenticationService;
private AuthenticationComponent authenticationComponent; private AuthenticationComponent authenticationComponent;
private PersonService personService; private PersonService personService;
private static final String USER_ONE = "PreferenceTestOne" + System.currentTimeMillis(); private static final String USER_ONE = "PreferenceTestOne" + System.currentTimeMillis();
private static final String USER_BAD = "PreferenceTestBad" + System.currentTimeMillis(); private static final String USER_BAD = "PreferenceTestBad" + System.currentTimeMillis();
private static final String URL = "/api/people/" + USER_ONE + "/preferences";; private static final String URL = "/api/people/" + USER_ONE + "/preferences";;
@Override @Override
protected void setUp() throws Exception protected void setUp() throws Exception
{ {
super.setUp(); super.setUp();
this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService"); this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean(
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent"); "AuthenticationService");
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService"); this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean(
"authenticationComponent");
this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
this.authenticationComponent.setSystemUserAsCurrentUser(); this.authenticationComponent.setSystemUserAsCurrentUser();
// Create users // Create users
createUser(USER_ONE); createUser(USER_ONE);
createUser(USER_BAD); createUser(USER_BAD);
// Do tests as user one // Do tests as user one
this.authenticationComponent.setCurrentUser(USER_ONE); this.authenticationComponent.setCurrentUser(USER_ONE);
} }
private void createUser(String userName) private void createUser(String userName)
{ {
if (this.authenticationService.authenticationExists(userName) == false) if (this.authenticationService.authenticationExists(userName) == false)
{ {
this.authenticationService.createAuthentication(userName, "PWD".toCharArray()); this.authenticationService.createAuthentication(userName, "PWD".toCharArray());
PropertyMap ppOne = new PropertyMap(4); PropertyMap ppOne = new PropertyMap(4);
ppOne.put(ContentModel.PROP_USERNAME, userName); ppOne.put(ContentModel.PROP_USERNAME, userName);
ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName"); ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
ppOne.put(ContentModel.PROP_LASTNAME, "lastName"); ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
ppOne.put(ContentModel.PROP_EMAIL, "email@email.com"); ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle"); ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
this.personService.createPerson(ppOne); this.personService.createPerson(ppOne);
} }
} }
@Override @Override
protected void tearDown() throws Exception protected void tearDown() throws Exception
{ {
super.tearDown(); super.tearDown();
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
} }
public void testPreferences() throws Exception public void testPreferences() throws Exception
{ {
// Get the preferences before they have been set // Get the preferences before they have been set
Response resp = sendRequest(new GetRequest(URL), 200); Response resp = sendRequest(new GetRequest(URL), 200);
JSONObject jsonResult = new JSONObject(resp.getContentAsString()); JSONObject jsonResult = new JSONObject(resp.getContentAsString());
assertNotNull(jsonResult); assertNotNull(jsonResult);
assertFalse(jsonResult.keys().hasNext()); assertFalse(jsonResult.keys().hasNext());
// Set some preferences // Set some preferences
JSONObject jsonObject = getPreferenceObj(); JSONObject jsonObject = getPreferenceObj();
jsonObject.put("comp1", getPreferenceObj()); jsonObject.put("comp1", getPreferenceObj());
resp = sendRequest(new PostRequest(URL, jsonObject.toString(), "application/json"), 200); resp = sendRequest(new PostRequest(URL, jsonObject.toString(), "application/json"), 200);
assertEquals(0, resp.getContentLength()); assertEquals(0, resp.getContentLength());
// Get the preferences // Get the preferences
resp = sendRequest(new GetRequest(URL), 200); resp = sendRequest(new GetRequest(URL), 200);
jsonResult = new JSONObject(resp.getContentAsString()); jsonResult = new JSONObject(resp.getContentAsString());
assertNotNull(jsonResult); assertNotNull(jsonResult);
assertTrue(jsonResult.keys().hasNext()); assertTrue(jsonResult.keys().hasNext());
checkJSONObject(jsonResult); checkJSONObject(jsonResult);
checkJSONObject(jsonResult.getJSONObject("comp1")); checkJSONObject(jsonResult.getJSONObject("comp1"));
// Update some of the preferences // Update some of the preferences
jsonObject.put("stringValue", "updated"); jsonObject.put("stringValue", "updated");
jsonObject.put("comp2", getPreferenceObj()); jsonObject.put("comp2", getPreferenceObj());
resp = sendRequest(new PostRequest(URL, jsonObject.toString(), "application/json"), 200); resp = sendRequest(new PostRequest(URL, jsonObject.toString(), "application/json"), 200);
assertEquals(0, resp.getContentLength()); assertEquals(0, resp.getContentLength());
// Get the preferences // Get the preferences
resp = sendRequest(new GetRequest(URL), 200); resp = sendRequest(new GetRequest(URL), 200);
jsonResult = new JSONObject(resp.getContentAsString()); jsonResult = new JSONObject(resp.getContentAsString());
assertNotNull(jsonResult); assertNotNull(jsonResult);
assertTrue(jsonResult.keys().hasNext()); assertTrue(jsonResult.keys().hasNext());
jsonObject.put("stringValue", "updated"); jsonObject.put("stringValue", "updated");
jsonObject.put("numberValue", 10); jsonObject.put("numberValue", 10);
jsonObject.put("numberValue2", 3.142); jsonObject.put("numberValue2", 3.142);
checkJSONObject(jsonResult.getJSONObject("comp1")); checkJSONObject(jsonResult.getJSONObject("comp1"));
checkJSONObject(jsonResult.getJSONObject("comp2")); checkJSONObject(jsonResult.getJSONObject("comp2"));
// Filter the preferences retrieved // Filter the preferences retrieved
resp = sendRequest(new GetRequest(URL + "?pf=comp2"), 200); resp = sendRequest(new GetRequest(URL + "?pf=comp2"), 200);
jsonResult = new JSONObject(resp.getContentAsString()); jsonResult = new JSONObject(resp.getContentAsString());
assertNotNull(jsonResult); assertNotNull(jsonResult);
assertTrue(jsonResult.keys().hasNext()); assertTrue(jsonResult.keys().hasNext());
checkJSONObject(jsonResult.getJSONObject("comp2")); checkJSONObject(jsonResult.getJSONObject("comp2"));
assertFalse(jsonResult.has("comp1")); assertFalse(jsonResult.has("comp1"));
assertFalse(jsonResult.has("stringValue")); assertFalse(jsonResult.has("stringValue"));
// Clear some of the preferences // Clear some of the preferences
sendRequest(new DeleteRequest(URL + "?pf=comp1"), 200); sendRequest(new DeleteRequest(URL + "?pf=comp1"), 200);
resp = sendRequest(new GetRequest(URL), 200); resp = sendRequest(new GetRequest(URL), 200);
jsonResult = new JSONObject(resp.getContentAsString()); jsonResult = new JSONObject(resp.getContentAsString());
assertNotNull(jsonResult); assertNotNull(jsonResult);
assertTrue(jsonResult.keys().hasNext()); assertTrue(jsonResult.keys().hasNext());
checkJSONObject(jsonResult.getJSONObject("comp2")); checkJSONObject(jsonResult.getJSONObject("comp2"));
assertFalse(jsonResult.has("comp1")); assertFalse(jsonResult.has("comp1"));
// Clear all the preferences // Clear all the preferences
sendRequest(new DeleteRequest(URL), 200); sendRequest(new DeleteRequest(URL), 200);
resp = sendRequest(new GetRequest(URL), 200); resp = sendRequest(new GetRequest(URL), 200);
jsonResult = new JSONObject(resp.getContentAsString()); jsonResult = new JSONObject(resp.getContentAsString());
assertNotNull(jsonResult); assertNotNull(jsonResult);
assertFalse(jsonResult.keys().hasNext()); assertFalse(jsonResult.keys().hasNext());
// Test trying to update another user's permissions // Test trying to update another user's permissions
sendRequest(new PostRequest("/api/people/" + USER_BAD + "/preferences", jsonObject.toString(), "application/json"), 500); sendRequest(new PostRequest("/api/people/" + USER_BAD + "/preferences", jsonObject.toString(),
"application/json"), 401);
// Test error conditions // Test error conditions
sendRequest(new GetRequest("/api/people/noExistUser/preferences"), 404); sendRequest(new GetRequest("/api/people/noExistUser/preferences"), 404);
} }
private JSONObject getPreferenceObj() private JSONObject getPreferenceObj() throws JSONException
throws JSONException
{ {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("stringValue", "value"); jsonObject.put("stringValue", "value");
@@ -187,9 +192,8 @@ public class PreferenceServiceTest extends BaseWebScriptTest
jsonObject.put("numberValue2", 3.142); jsonObject.put("numberValue2", 3.142);
return jsonObject; return jsonObject;
} }
private void checkJSONObject(JSONObject jsonObject) private void checkJSONObject(JSONObject jsonObject) throws JSONException
throws JSONException
{ {
assertEquals("value", jsonObject.get("stringValue")); assertEquals("value", jsonObject.get("stringValue"));
assertEquals(10, jsonObject.get("numberValue")); assertEquals(10, jsonObject.get("numberValue"));