Unit tests for RM-592 and RM-595

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@47478 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2013-03-03 15:09:55 +00:00
parent 772ff8aaac
commit 5bbb3757e1
6 changed files with 672 additions and 156 deletions

View File

@@ -21,11 +21,17 @@ package org.alfresco.module.org_alfresco_module_rm.test;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.ActionDefinitionsRestApiTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.CapabilitiesRestApiTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.DataSetRestApiTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.DispositionRestApiTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.EmailMapKeysRestApiTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.EmailMapScriptTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.EventRestApiTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RMCaveatConfigScriptTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RMConstraintScriptTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RmClassesRestApiTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RmPropertiesRestApiTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RmRestApiTest;
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RoleRestApiTest;
@@ -52,6 +58,12 @@ public class WebScriptTestSuite extends TestSuite
suite.addTestSuite(RmRestApiTest.class);
suite.addTestSuite(RoleRestApiTest.class);
suite.addTestSuite(DataSetRestApiTest.class);
suite.addTestSuite(EmailMapScriptTest.class);
suite.addTestSuite(EmailMapKeysRestApiTest.class);
suite.addTestSuite(CapabilitiesRestApiTest.class);
suite.addTestSuite(ActionDefinitionsRestApiTest.class);
suite.addTestSuite(RmClassesRestApiTest.class);
suite.addTestSuite(RmPropertiesRestApiTest.class);
return suite;
}
}

View File

@@ -479,7 +479,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
assertNotNull("Could not create base folder", folder);
// Create the site
siteInfo = siteService.createSite("preset", SITE_ID, "title", "descrition", SiteVisibility.PUBLIC, RecordsManagementModel.TYPE_RM_SITE);
siteInfo = siteService.createSite("rm-site-dashboard", SITE_ID, "title", "descrition", SiteVisibility.PUBLIC, RecordsManagementModel.TYPE_RM_SITE);
filePlan = siteService.getContainer(SITE_ID, RmSiteType.COMPONENT_DOCUMENT_LIBRARY);
assertNotNull("Site document library container was not created successfully.", filePlan);

View File

@@ -39,6 +39,7 @@ import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionSer
import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordService;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.site.SiteServiceImpl;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
@@ -55,8 +56,10 @@ import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.springframework.context.ApplicationContext;
/**
@@ -66,10 +69,15 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
{
/** Site id */
protected static final String SITE_ID = "mySite";
/** Collab site id */
protected static final String COLLAB_SITE_ID = "myCollabSite";
/** Common test utils */
protected CommonRMTestUtils utils;
/** Application context */
protected ApplicationContext applicationContext;
/** Services */
protected NodeService nodeService;
protected ContentService contentService;
@@ -82,6 +90,8 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
protected MutableAuthenticationService authenticationService;
protected AuthorityService authorityService;
protected PersonService personService;
protected TransactionService transactionService;
protected TaggingService taggingService;
/** RM Services */
protected RecordsManagementService rmService;
@@ -108,6 +118,15 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
protected NodeRef recordFolder;
protected NodeRef recordFolder2;
/**
* Indicates whether the test collaboration site should be created
* or not.
*/
protected boolean isCollaborationSiteTest()
{
return false;
}
@Override
protected void setUp() throws Exception
{
@@ -125,7 +144,7 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
*/
protected void initServices()
{
ApplicationContext applicationContext = getServer().getApplicationContext();
applicationContext = getServer().getApplicationContext();
// Common test utils
utils = new CommonRMTestUtils(applicationContext);
@@ -142,6 +161,8 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
authorityService = (AuthorityService)applicationContext.getBean("AuthorityService");
authenticationService = (MutableAuthenticationService)applicationContext.getBean("AuthenticationService");
personService = (PersonService)applicationContext.getBean("PersonService");
transactionService = (TransactionService)applicationContext.getBean("TransactionService");
taggingService = (TaggingService)applicationContext.getBean("TaggingService");
// Get RM services
rmService = (RecordsManagementService)applicationContext.getBean("RecordsManagementService");
@@ -189,6 +210,12 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
// Delete the site
siteService.deleteSite(SITE_ID);
// Delete the collaboration site (if required)
if (isCollaborationSiteTest() == true)
{
siteService.deleteSite(COLLAB_SITE_ID);
}
}
/**
@@ -229,7 +256,7 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
assertNotNull("Could not create base folder", folder);
// Create the site
siteInfo = siteService.createSite("preset", SITE_ID, "title", "descrition", SiteVisibility.PUBLIC, RecordsManagementModel.TYPE_RM_SITE);
siteInfo = siteService.createSite("rm-site-dashboard", SITE_ID, "title", "descrition", SiteVisibility.PUBLIC, RecordsManagementModel.TYPE_RM_SITE);
filePlan = siteService.getContainer(SITE_ID, RmSiteType.COMPONENT_DOCUMENT_LIBRARY);
assertNotNull("Site document library container was not created successfully.", filePlan);
@@ -250,5 +277,43 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
assertNotNull("Could not create rm folder", recordFolder);
recordFolder2 = rmService.createRecordFolder(recordCategory, "rmFolder2");
assertNotNull("Could not create rm folder 2", recordFolder2);
// Create collaboration data
if (isCollaborationSiteTest() == true)
{
setupCollaborationSiteTestData();
}
}
protected void setupCollaborationSiteTestData()
{
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
{
@Override
public Object execute() throws Throwable
{
// As system user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
setupCollaborationSiteTestDataImpl();
return null;
}
});
}
protected void setupCollaborationSiteTestDataImpl()
{
// create collaboration site
siteService.createSite("preset", COLLAB_SITE_ID, "title", "description", SiteVisibility.PRIVATE);
NodeRef documentLibrary = SiteServiceImpl.getSiteContainer(
COLLAB_SITE_ID,
SiteService.DOCUMENT_LIBRARY,
true,
siteService,
transactionService,
taggingService);
assertNotNull("Collaboration site document library component was not successfully created.", documentLibrary);
}
}

View File

@@ -0,0 +1,147 @@
/*
* Copyright (C) 2005-2013 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.module.org_alfresco_module_rm.test.webscript;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
/**
* REST API Tests for Action Definitions
*
* @author Tuna Aksoy
* @since 2.1
*/
public class ActionDefinitionsRestApiTest extends BaseRMWebScriptTestCase
{
/** URL for the REST APIs */
private static final String RM_ACTIONDEFINITIONS_URL = "/api/rm/rm-actiondefinitions";
private static final String DM_ACTIONDEFINITIONS_URL = "/api/rm/dm-actiondefinitions";
/**
* Test the REST API to retrieve the list of rm action definitions
*
* @throws IOException
* @throws JSONException
*/
public void testRmGetActionDefinitions() throws IOException, JSONException
{
// Send request
Response response = sendRequest(new GetRequest(RM_ACTIONDEFINITIONS_URL), Status.STATUS_OK);
// Check the content from the response
String contentAsString = response.getContentAsString();
assertNotNull(contentAsString);
// Convert the response to json and check the data
JSONObject contentAsJson = new JSONObject(contentAsString);
JSONArray data = contentAsJson.getJSONArray("data");
assertNotNull(data);
// Get a (sub)list of available dm action definitions
List<String> dmActionDefinitions = getDmActionDefinitions();
// Get the list of rm action definitions from the response and check it
List<String> rmActionDefinitions = new ArrayList<String>();
for (int i = 0; i < data.length(); i++)
{
String name = data.getJSONObject(i).getString("name");
assertNotNull(name);
rmActionDefinitions.add(name);
assertFalse(dmActionDefinitions.contains(name));
}
assertTrue(rmActionDefinitions.containsAll(getRmActionDefinitions()));
}
/**
* Test the REST API to retrieve the list of dm action definitions
*
* @throws IOException
* @throws JSONException
*/
public void testDmGetActionDefinitions() throws IOException, JSONException
{
// Send request
Response response = sendRequest(new GetRequest(DM_ACTIONDEFINITIONS_URL), Status.STATUS_OK);
// Check the content from the response
String contentAsString = response.getContentAsString();
assertNotNull(contentAsString);
// Convert the response to json and check the data
JSONObject contentAsJson = new JSONObject(contentAsString);
JSONArray data = contentAsJson.getJSONArray("data");
assertNotNull(data);
// Get a (sub)list of available rm action definitions
List<String> rmActionDefinitions = getRmActionDefinitions();
// Get the list of dm action definitions from the response and check it
List<String> dmActionDefinitions = new ArrayList<String>();
for (int i = 0; i < data.length(); i++)
{
String name = data.getJSONObject(i).getString("name");
assertNotNull(name);
dmActionDefinitions.add(name);
assertFalse(rmActionDefinitions.contains(name));
}
assertTrue(dmActionDefinitions.containsAll(getDmActionDefinitions()));
}
/**
* Returns a (sub)list of rm action definitions
*
* @return A (sub)list of rm action definitions
*/
private List<String> getRmActionDefinitions()
{
return Arrays.asList(new String[]
{
"reject",
"fileTo",
"declareRecord"
});
}
/**
* Returns a (sub)list of dm action definitions
*
* @return A (sub)list of dm action definitions
*/
private List<String> getDmActionDefinitions()
{
return Arrays.asList(new String[]
{
"check-in",
"check-out",
"mail",
"move",
"transform"
});
}
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright (C) 2005-2013 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.module.org_alfresco_module_rm.test.webscript;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
import org.json.JSONArray;
import org.json.JSONException;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
/**
* REST API Tests for Class Definitions
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmClassesRestApiTest extends BaseRMWebScriptTestCase
{
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase#isCollaborationSiteTest()
*/
@Override
protected boolean isCollaborationSiteTest()
{
return true;
}
/** URL for the REST APIs */
private static final String RM_ASPECTS_URL = "/api/rm/classes?cf=%s&siteId=%s";
/**
* Test the REST API to retrieve the list of rm aspects
*
* @throws IOException
* @throws JSONException
*/
public void testRmGetAspectDefinitions() throws IOException, JSONException
{
// Format url and send request
String url = String.format(RM_ASPECTS_URL, "aspect", SITE_ID);
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
// Check the content from the response
String contentAsString = response.getContentAsString();
assertNotNull(contentAsString);
// Convert the response to json array
JSONArray contentAsJson = new JSONArray(contentAsString);
assertNotNull(contentAsJson);
// Get a (sub)list of available dm/rm aspects
List<String> dmAspects = getDmAspects();
List<String> rmAspects = getRmAspects();
// Get the list of rm aspects from the response and check it
List<String> rmAspectList = new ArrayList<String>();
for (int i = 0; i < contentAsJson.length(); i++)
{
String name = contentAsJson.getJSONObject(i).getString("name");
assertNotNull(name);
rmAspectList.add(name);
assertFalse(dmAspects.contains(name));
}
assertTrue(rmAspectList.containsAll(rmAspects));
// Get the list of dm aspects and check them. It also contains rm related aspects.
// Format url and send request
url = String.format(RM_ASPECTS_URL, "aspect", COLLAB_SITE_ID);
response = sendRequest(new GetRequest(url), Status.STATUS_OK);
// Check the content from the response
contentAsString = response.getContentAsString();
assertNotNull(contentAsString);
// Convert the response to json array
contentAsJson = new JSONArray(contentAsString);
assertNotNull(contentAsJson);
// Get the list of dm aspects from the response and check it
List<String> dmAspectList = new ArrayList<String>();
for (int i = 0; i < contentAsJson.length(); i++)
{
String name = contentAsJson.getJSONObject(i).getString("name");
assertNotNull(name);
dmAspectList.add(name);
}
assertTrue(dmAspectList.containsAll(dmAspects));
// the list of dm aspescts contains also rm aspects
assertTrue(dmAspectList.containsAll(rmAspects));
}
/**
* Returns a (sub)list of rm aspects
*
* @return A (sub)list of rm aspects
*/
private List<String> getRmAspects()
{
return Arrays.asList(new String[]
{
"rma:ascended",
"rma:recordMetaData",
"rma:vitalRecordDefinition"
});
}
/**
* Returns a (sub)list of dm aspects
*
* @return A (sub)list of dm aspects
*/
private List<String> getDmAspects()
{
return Arrays.asList(new String[]
{
"emailserver:attached",
"bpm:assignees",
"cm:likesRatingSchemeRollups",
"wcmwf:submission",
"gd:googleEditable"
});
}
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright (C) 2005-2013 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.module.org_alfresco_module_rm.test.webscript;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
import org.json.JSONArray;
import org.json.JSONException;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
/**
* REST API Tests for Properties Definitions
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmPropertiesRestApiTest extends BaseRMWebScriptTestCase
{
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase#isCollaborationSiteTest()
*/
@Override
protected boolean isCollaborationSiteTest()
{
return true;
}
/** URL for the REST APIs */
private static final String RM_TYPES_URL = "/api/rm/classes?cf=%s&siteId=%s";
/**
* Test the REST API to retrieve the list of rm types
*
* @throws IOException
* @throws JSONException
*/
public void testRmGetTypeDefinitions() throws IOException, JSONException
{
// Format url and send request
String url = String.format(RM_TYPES_URL, "type", SITE_ID);
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
// Check the content from the response
String contentAsString = response.getContentAsString();
assertNotNull(contentAsString);
// Convert the response to json array
JSONArray contentAsJson = new JSONArray(contentAsString);
assertNotNull(contentAsJson);
// Get a (sub)list of available dm/rm types
List<String> dmTypes = getDmTypes();
List<String> rmTypes = getRmTypes();
// Get the list of rm types from the response and check it
List<String> rmTypeList = new ArrayList<String>();
for (int i = 0; i < contentAsJson.length(); i++)
{
String name = contentAsJson.getJSONObject(i).getString("name");
assertNotNull(name);
rmTypeList.add(name);
assertFalse(dmTypes.contains(name));
}
assertTrue(rmTypeList.containsAll(rmTypes));
// Get the list of dm types and check them. It also contains rm related types.
// Format url and send request
url = String.format(RM_TYPES_URL, "type", COLLAB_SITE_ID);
response = sendRequest(new GetRequest(url), Status.STATUS_OK);
// Check the content from the response
contentAsString = response.getContentAsString();
assertNotNull(contentAsString);
// Convert the response to json array
contentAsJson = new JSONArray(contentAsString);
assertNotNull(contentAsJson);
// Get the list of dm types from the response and check it
List<String> dmTypeList = new ArrayList<String>();
for (int i = 0; i < contentAsJson.length(); i++)
{
String name = contentAsJson.getJSONObject(i).getString("name");
assertNotNull(name);
dmTypeList.add(name);
}
assertTrue(dmTypeList.containsAll(dmTypes));
// the list of dm type contains also rm types
assertTrue(dmTypeList.containsAll(rmTypes));
}
/**
* Returns a (sub)list of rm types
*
* @return A (sub)list of rm types
*/
private List<String> getRmTypes()
{
return Arrays.asList(new String[]
{
"rma:eventExecution",
"rma:nonElectronicDocument",
"rma:transfer"
});
}
/**
* Returns a (sub)list of dm types
*
* @return A (sub)list of dm types
*/
private List<String> getDmTypes()
{
return Arrays.asList(new String[]
{
"cm:authority",
"sys:descriptor",
"app:folderlink",
"wcmwf:parallelReviewTask",
"wca:deploymentserver"
});
}
}