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

@@ -73,37 +73,37 @@ import org.springframework.context.ApplicationContext;
/**
* Base test case class to use for RM unit tests.
*
*
* @author Roy Wetherall
*/
public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
implements RecordsManagementModel, ContentModel, RMPermissionModel
{
{
/** Application context */
protected static final String[] CONFIG_LOCATIONS = new String[]
{
protected static final String[] CONFIG_LOCATIONS = new String[]
{
"classpath:alfresco/application-context.xml",
"classpath:test-context.xml"
};
protected ApplicationContext applicationContext;
/** test model constants */
protected String URI = "http://www.alfresco.org/model/rmtest/1.0";
protected String PREFIX = "rmt";
protected QName TYPE_CUSTOM_TYPE = QName.createQName(URI, "customType");
protected QName ASPECT_CUSTOM_ASPECT = QName.createQName(URI, "customAspect");
protected QName ASPECT_RECORD_META_DATA = QName.createQName(URI, "recordMetaData");
/** site id's */
protected static final String SITE_ID = "mySite";
protected static final String COLLABORATION_SITE_ID = "collab-site-id";
/** Common test utils */
protected CommonRMTestUtils utils;
/** RM Admin user name */
protected String rmAdminUserName;
/** Services */
protected NodeService nodeService;
protected ContentService contentService;
@@ -120,12 +120,12 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
protected FileFolderService fileFolderService;
protected PermissionService permissionService;
protected TaggingService taggingService;
/** RM Services */
protected RecordsManagementService rmService;
protected DispositionService dispositionService;
protected RecordsManagementEventService eventService;
protected RecordsManagementAdminService adminService;
protected RecordsManagementAdminService adminService;
protected RecordsManagementActionService actionService;
protected RecordsManagementSearchService rmSearchService;
protected FilePlanRoleService filePlanRoleService;
@@ -137,10 +137,10 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
protected RecordService recordService;
protected FilePlanService filePlanService;
protected FilePlanAuthenticationService filePlanAuthenticationService;
/** test data */
protected StoreRef storeRef;
protected NodeRef rootNodeRef;
protected NodeRef rootNodeRef;
protected SiteInfo siteInfo;
protected NodeRef folder;
protected NodeRef filePlan;
@@ -148,8 +148,8 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
protected DispositionSchedule dispositionSchedule;
protected NodeRef rmFolder;
protected NodeRef unfiledContainer;
/** multi-hierarchy test data
/** multi-hierarchy test data
*
* |--rmRootContainer
* |
@@ -160,7 +160,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
* | |--mhContainer-2-1
* | |
* | |--mhContainer-3-1
* |
* |
* |--mhContainer-1-2 (has schedule - folder level)
* |
* |--mhContainer-2-2
@@ -168,26 +168,26 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
* | |--mhContainer-3-2
* | |
* | |--mhContainer-3-3 (has schedule - record level)
* |
* |
* |--mhContainer-2-3 (has schedule - folder level)
* |
* |--mhContainer-3-4
* |
* |--mhContainer-3-5 (has schedule- record level)
* |
* |--mhContainer-3-5 (has schedule- record level)
*/
protected NodeRef mhContainer;
protected NodeRef mhContainer11;
protected DispositionSchedule mhDispositionSchedule11;
protected NodeRef mhContainer12;
protected DispositionSchedule mhDispositionSchedule12;
protected NodeRef mhContainer21;
protected NodeRef mhContainer22;
protected NodeRef mhContainer23;
protected DispositionSchedule mhDispositionSchedule23;
protected NodeRef mhContainer31;
protected NodeRef mhContainer32;
protected NodeRef mhContainer33;
@@ -195,22 +195,22 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
protected NodeRef mhContainer34;
protected NodeRef mhContainer35;
protected DispositionSchedule mhDispositionSchedule35;
protected NodeRef mhRecordFolder41;
protected NodeRef mhRecordFolder42;
protected NodeRef mhRecordFolder43;
protected NodeRef mhRecordFolder44;
protected NodeRef mhRecordFolder45;
/** test user names */
protected String[] testUsers;
protected String userName;
protected String userName;
protected String rmUserName;
protected String powerUserName;
protected String securityOfficerName;
protected String recordsManagerName;
protected String rmAdminName;
/** test people */
protected NodeRef userPerson;
protected NodeRef rmUserPerson;
@@ -218,7 +218,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
protected NodeRef securityOfficerPerson;
protected NodeRef recordsManagerPerson;
protected NodeRef rmAdminPerson;
/** test records */
protected NodeRef recordOne;
protected NodeRef recordTwo;
@@ -227,7 +227,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
protected NodeRef recordFive;
protected NodeRef recordDeclaredOne;
protected NodeRef recordDeclaredTwo;
/** collaboration site artifacts */
protected SiteInfo collaborationSite;
protected NodeRef documentLibrary;
@@ -239,7 +239,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
protected NodeRef dmConsumerNodeRef;
protected String dmCollaborator;
protected NodeRef dmCollaboratorNodeRef;
/**
* Indicates whether this is a multi-hierarchy test or not. If it is then the multi-hierarchy record
* taxonomy test data is loaded.
@@ -248,7 +248,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
{
return false;
}
/**
* Indicates whether the test users should be created or not.
*/
@@ -256,7 +256,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
{
return false;
}
/**
* Indicates whether the test records should be created or not.
*/
@@ -264,7 +264,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
{
return false;
}
/**
* Indicates whether the test users should have filling on the file plan structure
* by default or not.
@@ -273,7 +273,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
{
return false;
}
/**
* Indicates whether the test collaboration site should be created
* or not.
@@ -282,7 +282,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
{
return false;
}
/**
* @see junit.framework.TestCase#setUp()
*/
@@ -292,10 +292,10 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
// Get the application context
applicationContext = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS);
utils = new CommonRMTestUtils(applicationContext);
// Initialise the service beans
initServices();
// grab the rmadmin user name
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
{
@@ -305,26 +305,26 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
// As system user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
rmAdminUserName = filePlanAuthenticationService.getRmAdminUserName();
return null;
}
});
// Setup test data
setupTestData();
setupTestData();
// Create multi hierarchy data
if (isMultiHierarchyTest() == true)
{
setupMultiHierarchyTestData();
}
}
// Create collaboration data
if (isCollaborationSiteTest() == true)
{
setupCollaborationSiteTestData();
}
// Create the users here
if (isUserTest() == true)
{
@@ -343,7 +343,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
retryingTransactionHelper = (RetryingTransactionHelper)applicationContext.getBean("retryingTransactionHelper");
namespaceService = (NamespaceService)this.applicationContext.getBean("NamespaceService");
searchService = (SearchService)this.applicationContext.getBean("SearchService");
policyComponent = (PolicyComponent)this.applicationContext.getBean("policyComponent");
policyComponent = (PolicyComponent)this.applicationContext.getBean("policyComponent");
dictionaryService = (DictionaryService)this.applicationContext.getBean("DictionaryService");
siteService = (SiteService)this.applicationContext.getBean("SiteService");
authorityService = (AuthorityService)this.applicationContext.getBean("AuthorityService");
@@ -353,7 +353,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
fileFolderService = (FileFolderService)applicationContext.getBean("FileFolderService");
permissionService = (PermissionService)applicationContext.getBean("PermissionService");
taggingService = (TaggingService)applicationContext.getBean("TaggingService");
// Get RM services
rmService = (RecordsManagementService)applicationContext.getBean("RecordsManagementService");
dispositionService = (DispositionService)applicationContext.getBean("DispositionService");
@@ -371,7 +371,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
filePlanService = (FilePlanService) applicationContext.getBean("FilePlanService");
filePlanAuthenticationService = (FilePlanAuthenticationService) applicationContext.getBean("FilePlanAuthenticationService");
}
/**
* @see junit.framework.TestCase#tearDown()
*/
@@ -385,33 +385,33 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
{
// As system user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Do the tear down
// Do the tear down
tearDownImpl();
return null;
}
});
});
}
/**
* Tear down implementation
*/
protected void tearDownImpl()
protected void tearDownImpl()
{
// Delete the folder
nodeService.deleteNode(folder);
// Delete the site
siteService.deleteSite(SITE_ID);
// delete the collaboration site (if required)
if (isCollaborationSiteTest() == true)
{
siteService.deleteSite(COLLABORATION_SITE_ID);
}
}
/**
* @see org.alfresco.util.RetryingTransactionHelperTestCase#getRetryingTransactionHelper()
*/
@@ -420,7 +420,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
{
return retryingTransactionHelper;
}
/**
* Setup test data for tests
*/
@@ -431,15 +431,15 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
public Void run()
{
setupTestDataImpl();
if (isRecordTest() == true)
{
setupTestRecords();
}
return null;
}
@Override
public void test(Void result) throws Exception
{
@@ -454,10 +454,10 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
unfiledContainer = filePlanService.getUnfiledContainer(filePlan);
assertNotNull(unfiledContainer);
}
},
AuthenticationUtil.getAdminUserName());
},
AuthenticationUtil.getAdminUserName());
}
/**
* Impl of test data setup
*/
@@ -465,36 +465,36 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
{
storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
rootNodeRef = nodeService.getRootNode(storeRef);
// Create folder
String containerName = "RM2_" + System.currentTimeMillis();
Map<QName, Serializable> containerProps = new HashMap<QName, Serializable>(1);
containerProps.put(ContentModel.PROP_NAME, containerName);
folder = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, containerName),
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, containerName),
ContentModel.TYPE_FOLDER,
containerProps).getChildRef();
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);
// Create RM container
rmContainer = rmService.createRecordCategory(filePlan, "rmContainer");
assertNotNull("Could not create rm container", rmContainer);
// Create disposition schedule
dispositionSchedule = utils.createBasicDispositionSchedule(rmContainer);
// Create RM folder
rmFolder = rmService.createRecordFolder(rmContainer, "rmFolder");
assertNotNull("Could not create rm folder", rmFolder);
}
protected void setupTestRecords()
{
recordOne = utils.createRecord(rmFolder, "one.txt");
@@ -505,7 +505,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
recordDeclaredOne = utils.createRecord(rmFolder, "declaredOne.txt");
recordDeclaredTwo = utils.createRecord(rmFolder, "declaredTwo.txt");
}
protected void setupTestUsers(final NodeRef filePlan)
{
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
@@ -519,46 +519,46 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
}
});
}
/**
*
*
* @param filePlan
*/
protected void setupTestUsersImpl(NodeRef filePlan)
{
userName = GUID.generate();
userPerson = createPerson(userName);
rmUserName = GUID.generate();
rmUserPerson = createPerson(rmUserName);
filePlanRoleService.assignRoleToAuthority(filePlan, "User", rmUserName);
powerUserName = GUID.generate();
powerUserPerson = createPerson(powerUserName);
filePlanRoleService.assignRoleToAuthority(filePlan, "PowerUser", powerUserName);
securityOfficerName = GUID.generate();
securityOfficerPerson = createPerson(securityOfficerName);
filePlanRoleService.assignRoleToAuthority(filePlan, "SecurityOfficer", securityOfficerName);
recordsManagerName = GUID.generate();
recordsManagerPerson = createPerson(recordsManagerName);
filePlanRoleService.assignRoleToAuthority(filePlan, "RecordsManager", recordsManagerName);
rmAdminName = GUID.generate();
rmAdminPerson = createPerson(rmAdminName);
filePlanRoleService.assignRoleToAuthority(filePlan, "Administrator", rmAdminName);
filePlanRoleService.assignRoleToAuthority(filePlan, "Administrator", rmAdminName);
testUsers = new String[]
{
userName,
rmUserName,
powerUserName,
securityOfficerName,
recordsManagerName,
rmUserName,
powerUserName,
securityOfficerName,
recordsManagerName,
rmAdminName
};
if (isFillingForAllUsers() == true)
{
// Give all the users file permission objects
@@ -567,13 +567,13 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
filePlanPermissionService.setPermission(filePlan, user, FILING);
filePlanPermissionService.setPermission(rmContainer, user, FILING);
filePlanPermissionService.setPermission(unfiledContainer, user, FILING);
}
}
}
}
/**
* Util method to create a person.
* @param userName user name
* @param userName user name
* @return NodeRef user node reference
*/
protected NodeRef createPerson(String userName)
@@ -583,7 +583,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
properties.put(ContentModel.PROP_USERNAME, userName);
return personService.createPerson(properties);
}
/**
* Setup multi hierarchy test data
*/
@@ -596,29 +596,29 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
{
// As system user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Do setup
setupMultiHierarchyTestDataImpl();
return null;
}
});
}
/**
* Impl of multi hierarchy test data
*/
protected void setupMultiHierarchyTestDataImpl()
{
// Create root mh container
mhContainer = rmService.createRecordCategory(filePlan, "mhContainer");
mhContainer = rmService.createRecordCategory(filePlan, "mhContainer");
// Level 1
mhContainer11 = rmService.createRecordCategory(mhContainer, "mhContainer11");
mhDispositionSchedule11 = utils.createBasicDispositionSchedule(mhContainer11, "ds11", CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, false, true);
mhContainer12 = rmService.createRecordCategory(mhContainer, "mhContainer12");
mhDispositionSchedule12 = utils.createBasicDispositionSchedule(mhContainer12, "ds12", CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, false, true);
// Level 2
mhContainer21 = rmService.createRecordCategory(mhContainer11, "mhContainer21");
mhContainer22 = rmService.createRecordCategory(mhContainer12, "mhContainer22");
@@ -633,15 +633,15 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
mhContainer34 = rmService.createRecordCategory(mhContainer23, "mhContainer34");
mhContainer35 = rmService.createRecordCategory(mhContainer23, "mhContainer35");
mhDispositionSchedule35 = utils.createBasicDispositionSchedule(mhContainer35, "ds35", CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, true, true);
// Record folders
mhRecordFolder41 = rmService.createRecordFolder(mhContainer31, "mhFolder41");
mhRecordFolder42 = rmService.createRecordFolder(mhContainer32, "mhFolder42");
mhRecordFolder43 = rmService.createRecordFolder(mhContainer33, "mhFolder43");
mhRecordFolder44 = rmService.createRecordFolder(mhContainer34, "mhFolder44");
mhRecordFolder45 = rmService.createRecordFolder(mhContainer35, "mhFolder45");
mhRecordFolder45 = rmService.createRecordFolder(mhContainer35, "mhFolder45");
}
protected void setupCollaborationSiteTestData()
{
doTestInTransaction(new Test<Void>()
@@ -653,17 +653,17 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
}
}, AuthenticationUtil.getAdminUserName());
}
protected void setupCollaborationSiteTestDataImpl()
{
// create collaboration site
collaborationSite = siteService.createSite("preset", COLLABORATION_SITE_ID, "title", "description", SiteVisibility.PRIVATE);
documentLibrary = SiteServiceImpl.getSiteContainer(
COLLABORATION_SITE_ID,
SiteService.DOCUMENT_LIBRARY,
COLLABORATION_SITE_ID,
SiteService.DOCUMENT_LIBRARY,
true,
siteService,
transactionService,
siteService,
transactionService,
taggingService);
assertNotNull("Collaboration site document library component was not successfully created.", documentLibrary);
@@ -671,35 +671,35 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
// create a folder and documents
dmFolder = fileFolderService.create(documentLibrary, "collabFolder", ContentModel.TYPE_FOLDER).getNodeRef();
dmDocument = fileFolderService.create(dmFolder, "collabDocument.txt", ContentModel.TYPE_CONTENT).getNodeRef();
dmConsumer = GUID.generate();
dmConsumerNodeRef = createPerson(dmConsumer);
siteService.setMembership(COLLABORATION_SITE_ID, dmConsumer, SiteModel.SITE_CONSUMER);
dmCollaborator = GUID.generate();
dmCollaboratorNodeRef = createPerson(dmCollaborator);
siteService.setMembership(COLLABORATION_SITE_ID, dmCollaborator, SiteModel.SITE_COLLABORATOR);
}
/**
* Override to ensure the tests are run as the 'rmadmin' user by default.
*/
@Override
protected <A> A doTestInTransaction(Test<A> test)
{
return super.doTestInTransaction(test, rmAdminUserName);
}
@Override
protected void doTestInTransaction(FailureTest test)
{
super.doTestInTransaction(test, rmAdminUserName);
}
/**
* Helper class to try and simplify {@link Void} tests.
*
*
* @author Roy Wetherall
* @since 2.1
*/
@@ -711,20 +711,20 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
runImpl();
return null;
}
public abstract void runImpl() throws Exception;
@Override
public void test(Void result) throws Exception
{
testImpl();
}
public void testImpl() throws Exception
{
// empty implementation
}
}
}

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,12 +90,14 @@ 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;
protected DispositionService dispositionService;
protected RecordsManagementEventService eventService;
protected RecordsManagementAdminService adminService;
protected RecordsManagementAdminService adminService;
protected RecordsManagementActionService actionService;
protected RecordsManagementSearchService rmSearchService;
protected FilePlanRoleService filePlanRoleService;
@@ -95,10 +105,10 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
protected RecordsManagementAuditService auditService;
protected CapabilityService capabilityService;
protected VitalRecordService vitalRecordService;
/** test data */
protected StoreRef storeRef;
protected NodeRef rootNodeRef;
protected NodeRef rootNodeRef;
protected SiteInfo siteInfo;
protected NodeRef folder;
protected NodeRef filePlan;
@@ -107,42 +117,53 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
protected DispositionSchedule dispositionSchedule;
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
{
super.setUp();
// Initialise the service beans
initServices();
initServices();
// Setup test data
setupTestData();
}
/**
* Initialise the service beans.
*/
protected void initServices()
{
ApplicationContext applicationContext = getServer().getApplicationContext();
applicationContext = getServer().getApplicationContext();
// Common test utils
utils = new CommonRMTestUtils(applicationContext);
// Get services
nodeService = (NodeService)applicationContext.getBean("NodeService");
contentService = (ContentService)applicationContext.getBean("ContentService");
retryingTransactionHelper = (RetryingTransactionHelper)applicationContext.getBean("retryingTransactionHelper");
namespaceService = (NamespaceService)applicationContext.getBean("NamespaceService");
searchService = (SearchService)applicationContext.getBean("SearchService");
policyComponent = (PolicyComponent)applicationContext.getBean("policyComponent");
policyComponent = (PolicyComponent)applicationContext.getBean("policyComponent");
dictionaryService = (DictionaryService)applicationContext.getBean("DictionaryService");
siteService = (SiteService)applicationContext.getBean("SiteService");
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");
dispositionService = (DispositionService)applicationContext.getBean("DispositionService");
@@ -156,7 +177,7 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
capabilityService = (CapabilityService)applicationContext.getBean("CapabilityService");
vitalRecordService = (VitalRecordService)applicationContext.getBean("VitalRecordService");
}
/**
* @see junit.framework.TestCase#tearDown()
*/
@@ -170,27 +191,33 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
{
// As system user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Do the tear down
// Do the tear down
tearDownImpl();
return null;
}
});
});
}
/**
* Tear down implementation
*/
protected void tearDownImpl()
protected void tearDownImpl()
{
// Delete the folder
nodeService.deleteNode(folder);
// Delete the site
siteService.deleteSite(SITE_ID);
// Delete the collaboration site (if required)
if (isCollaborationSiteTest() == true)
{
siteService.deleteSite(COLLAB_SITE_ID);
}
}
/**
* Setup test data for tests
*/
@@ -207,7 +234,7 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
}
});
}
/**
* Impl of test data setup
*/
@@ -215,40 +242,78 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
{
storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
rootNodeRef = nodeService.getRootNode(storeRef);
// Create folder
String containerName = "RM2_" + System.currentTimeMillis();
Map<QName, Serializable> containerProps = new HashMap<QName, Serializable>(1);
containerProps.put(ContentModel.PROP_NAME, containerName);
folder = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, containerName),
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, containerName),
ContentModel.TYPE_FOLDER,
containerProps).getChildRef();
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);
recordSeries = rmService.createRecordCategory(filePlan, "recordSeries");
assertNotNull("Could not create record category with no disposition schedule", recordSeries);
recordCategory = rmService.createRecordCategory(recordSeries, "rmContainer");
assertNotNull("Could not create record category", recordCategory);
// Make vital record
vitalRecordService.setVitalRecordDefintion(recordCategory, true, new Period("week|1"));
// Create disposition schedule
dispositionSchedule = utils.createBasicDispositionSchedule(recordCategory);
// Create RM folder
recordFolder = rmService.createRecordFolder(recordCategory, "rmFolder");
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"
});
}
}