RM-3132 (Update license headers)

This commit is contained in:
Tuna Aksoy
2016-03-15 14:53:01 +00:00
parent b1a71b654f
commit d2870081bb
14 changed files with 2996 additions and 2996 deletions

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,70 +21,70 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
/** /**
* Integration test for RM-1887 * Integration test for RM-1887
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.3 * @since 2.3
*/ */
public class RM1887Test extends BaseRMTestCase public class RM1887Test extends BaseRMTestCase
{ {
@Override @Override
protected boolean isRecordTest() protected boolean isRecordTest()
{ {
return true; return true;
} }
/** /**
* Given that a record is unfiled * Given that a record is unfiled
* And an unfiled folder has been created * And an unfiled folder has been created
* When I move the unfiled record into the unfiled folder * When I move the unfiled record into the unfiled folder
* Then the filed date of the unfiled record remains unset * Then the filed date of the unfiled record remains unset
*/ */
public void testMoveUnfiledRecord() throws Exception public void testMoveUnfiledRecord() throws Exception
{ {
doBehaviourDrivenTest(new BehaviourDrivenTest() doBehaviourDrivenTest(new BehaviourDrivenTest()
{ {
private NodeRef unfiledRecordFolder; private NodeRef unfiledRecordFolder;
private NodeRef unfiledRecord; private NodeRef unfiledRecord;
public void given() throws Exception public void given() throws Exception
{ {
// create unfiled folder // create unfiled folder
unfiledRecordFolder = fileFolderService.create(filePlanService.getUnfiledContainer(filePlan), "my test folder", TYPE_UNFILED_RECORD_FOLDER).getNodeRef(); unfiledRecordFolder = fileFolderService.create(filePlanService.getUnfiledContainer(filePlan), "my test folder", TYPE_UNFILED_RECORD_FOLDER).getNodeRef();
// crate unfiled record // crate unfiled record
unfiledRecord = recordService.createRecordFromContent(filePlan, "test.txt", TYPE_CONTENT, null, null); unfiledRecord = recordService.createRecordFromContent(filePlan, "test.txt", TYPE_CONTENT, null, null);
// check the record // check the record
assertTrue(recordService.isRecord(unfiledRecord)); assertTrue(recordService.isRecord(unfiledRecord));
assertFalse(recordService.isFiled(unfiledRecord)); assertFalse(recordService.isFiled(unfiledRecord));
} }
public void when() throws Exception public void when() throws Exception
{ {
// move the record into the unfiled folder // move the record into the unfiled folder
fileFolderService.move(unfiledRecord, unfiledRecordFolder, null); fileFolderService.move(unfiledRecord, unfiledRecordFolder, null);
} }
public void then() public void then()
{ {
// check the record // check the record
assertTrue(recordService.isRecord(unfiledRecord)); assertTrue(recordService.isRecord(unfiledRecord));
assertFalse(recordService.isFiled(unfiledRecord)); assertFalse(recordService.isFiled(unfiledRecord));
} }
}); });
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,170 +21,170 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction; import org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction;
import org.alfresco.module.org_alfresco_module_rm.action.impl.FileToAction; import org.alfresco.module.org_alfresco_module_rm.action.impl.FileToAction;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.Rule; import org.alfresco.service.cmr.rule.Rule;
import org.alfresco.service.cmr.rule.RuleService; import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.service.cmr.rule.RuleType; import org.alfresco.service.cmr.rule.RuleType;
/** /**
* System test for RM-2072: Concurrency exceptions and deadlocks on Records Management "File to" rule * System test for RM-2072: Concurrency exceptions and deadlocks on Records Management "File to" rule
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.2.1.1 * @since 2.2.1.1
*/ */
public class RM2072Test extends BaseRMTestCase public class RM2072Test extends BaseRMTestCase
{ {
private static final int NUMBER_OF_BATCHES = 1; private static final int NUMBER_OF_BATCHES = 1;
private static final int NUMBER_IN_BATCH = 500; private static final int NUMBER_IN_BATCH = 500;
private RuleService ruleService; private RuleService ruleService;
private NodeRef ruleFolder; private NodeRef ruleFolder;
@Override @Override
protected void initServices() protected void initServices()
{ {
super.initServices(); super.initServices();
ruleService = (RuleService)applicationContext.getBean("RuleService"); ruleService = (RuleService)applicationContext.getBean("RuleService");
} }
@Override @Override
protected boolean isCollaborationSiteTest() protected boolean isCollaborationSiteTest()
{ {
return true; return true;
} }
@Override @Override
protected boolean isRecordTest() protected boolean isRecordTest()
{ {
return true; return true;
} }
/** /**
* Given that I have auto declare configured * Given that I have auto declare configured
* And that I have auto file configured to a path where only the record folder needs to be created * And that I have auto file configured to a path where only the record folder needs to be created
* When I add lots of documents in the same transaction * When I add lots of documents in the same transaction
* Then the rules should fire * Then the rules should fire
* And the documents should be filed in the new record folder * And the documents should be filed in the new record folder
*/ */
public void testAutoDeclareAutoFileCreateRecordFolderOnly() throws Exception public void testAutoDeclareAutoFileCreateRecordFolderOnly() throws Exception
{ {
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
// create the folder // create the folder
ruleFolder = fileFolderService.create(documentLibrary, "mytestfolder", ContentModel.TYPE_FOLDER).getNodeRef(); ruleFolder = fileFolderService.create(documentLibrary, "mytestfolder", ContentModel.TYPE_FOLDER).getNodeRef();
// create record category // create record category
NodeRef nodeRefA = filePlanService.createRecordCategory(filePlan, "A"); NodeRef nodeRefA = filePlanService.createRecordCategory(filePlan, "A");
NodeRef nodeRefB = filePlanService.createRecordCategory(nodeRefA, "B"); NodeRef nodeRefB = filePlanService.createRecordCategory(nodeRefA, "B");
filePlanService.createRecordCategory(nodeRefB, "C"); filePlanService.createRecordCategory(nodeRefB, "C");
Action action = actionService.createAction(CreateRecordAction.NAME); Action action = actionService.createAction(CreateRecordAction.NAME);
action.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan); action.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan);
Rule rule = new Rule(); Rule rule = new Rule();
rule.setRuleType(RuleType.INBOUND); rule.setRuleType(RuleType.INBOUND);
rule.setTitle("my rule"); rule.setTitle("my rule");
rule.setAction(action); rule.setAction(action);
rule.setExecuteAsynchronously(true); rule.setExecuteAsynchronously(true);
ruleService.saveRule(ruleFolder, rule); ruleService.saveRule(ruleFolder, rule);
Action fileAction = actionService.createAction(FileToAction.NAME); Action fileAction = actionService.createAction(FileToAction.NAME);
fileAction.setParameterValue(FileToAction.PARAM_PATH, "/A/B/C/{date.year.long}/{date.month.long}/{date.day.month}"); fileAction.setParameterValue(FileToAction.PARAM_PATH, "/A/B/C/{date.year.long}/{date.month.long}/{date.day.month}");
fileAction.setParameterValue(FileToAction.PARAM_CREATE_RECORD_PATH, true); fileAction.setParameterValue(FileToAction.PARAM_CREATE_RECORD_PATH, true);
Rule fileRule = new Rule(); Rule fileRule = new Rule();
fileRule.setRuleType(RuleType.INBOUND); fileRule.setRuleType(RuleType.INBOUND);
fileRule.setTitle("my rule"); fileRule.setTitle("my rule");
fileRule.setAction(fileAction); fileRule.setAction(fileAction);
fileRule.setExecuteAsynchronously(true); fileRule.setExecuteAsynchronously(true);
ruleService.saveRule(filePlanService.getUnfiledContainer(filePlan), fileRule); ruleService.saveRule(filePlanService.getUnfiledContainer(filePlan), fileRule);
return null; return null;
} }
@Override @Override
public void test(Void result) throws Exception public void test(Void result) throws Exception
{ {
assertFalse(ruleService.getRules(ruleFolder).isEmpty()); assertFalse(ruleService.getRules(ruleFolder).isEmpty());
} }
}); });
List<NodeRef> records = new ArrayList<NodeRef>(NUMBER_OF_BATCHES*NUMBER_IN_BATCH); List<NodeRef> records = new ArrayList<NodeRef>(NUMBER_OF_BATCHES*NUMBER_IN_BATCH);
for (int i = 0; i < NUMBER_OF_BATCHES; i++) for (int i = 0; i < NUMBER_OF_BATCHES; i++)
{ {
final int finali = i; final int finali = i;
records.addAll(doTestInTransaction(new Test<List<NodeRef>>() records.addAll(doTestInTransaction(new Test<List<NodeRef>>()
{ {
@Override @Override
public List<NodeRef> run() throws Exception public List<NodeRef> run() throws Exception
{ {
List<NodeRef> records = new ArrayList<NodeRef>(NUMBER_IN_BATCH); List<NodeRef> records = new ArrayList<NodeRef>(NUMBER_IN_BATCH);
for (int j = 0; j < NUMBER_IN_BATCH; j++) for (int j = 0; j < NUMBER_IN_BATCH; j++)
{ {
int count = (finali+1)*(j+1); int count = (finali+1)*(j+1);
String name = "content" + count + ".txt"; String name = "content" + count + ".txt";
System.out.println(name + " - creating"); System.out.println(name + " - creating");
NodeRef record = fileFolderService.create(ruleFolder, name, ContentModel.TYPE_CONTENT).getNodeRef(); NodeRef record = fileFolderService.create(ruleFolder, name, ContentModel.TYPE_CONTENT).getNodeRef();
records.add(record); records.add(record);
} }
return records; return records;
} }
})); }));
} }
try try
{ {
while(!records.isEmpty()) while(!records.isEmpty())
{ {
Thread.sleep(1000); Thread.sleep(1000);
final Iterator<NodeRef> temp = records.iterator(); final Iterator<NodeRef> temp = records.iterator();
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() throws Exception public Void run() throws Exception
{ {
while (temp.hasNext()) while (temp.hasNext())
{ {
NodeRef record = temp.next(); NodeRef record = temp.next();
if (nodeService.hasAspect(record, ASPECT_RECORD) && recordService.isFiled(record)) if (nodeService.hasAspect(record, ASPECT_RECORD) && recordService.isFiled(record))
{ {
String name = (String) nodeService.getProperty(record, ContentModel.PROP_NAME); String name = (String) nodeService.getProperty(record, ContentModel.PROP_NAME);
System.out.println(name + " - complete"); System.out.println(name + " - complete");
temp.remove(); temp.remove();
} }
} }
return null; return null;
} }
}); });
} }
} }
catch (Exception exception) catch (Exception exception)
{ {
exception.printStackTrace(); exception.printStackTrace();
throw exception; throw exception;
} }
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,86 +21,86 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.module.org_alfresco_module_rm.test.util.TestService; import org.alfresco.module.org_alfresco_module_rm.test.util.TestService;
/** /**
* System test for RM-452 * System test for RM-452
* *
* See alfresco.extension.rm-method-security.properties * See alfresco.extension.rm-method-security.properties
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.1 * @since 2.1
*/ */
public class RM452Test extends BaseRMTestCase public class RM452Test extends BaseRMTestCase
{ {
private TestService testService; private TestService testService;
@Override @Override
protected void initServices() protected void initServices()
{ {
super.initServices(); super.initServices();
testService = (TestService)applicationContext.getBean("TestService"); testService = (TestService)applicationContext.getBean("TestService");
} }
@Override @Override
protected boolean isCollaborationSiteTest() protected boolean isCollaborationSiteTest()
{ {
return true; return true;
} }
@Override @Override
protected boolean isRecordTest() protected boolean isRecordTest()
{ {
return true; return true;
} }
public void testRM452() throws Exception public void testRM452() throws Exception
{ {
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
assertNotNull(folder); assertNotNull(folder);
assertNotNull(recordOne); assertNotNull(recordOne);
assertFalse(filePlanService.isFilePlanComponent(folder)); assertFalse(filePlanService.isFilePlanComponent(folder));
assertTrue(filePlanService.isFilePlanComponent(recordOne)); assertTrue(filePlanService.isFilePlanComponent(recordOne));
// call methodOne with non-RM artifact .. expect success // call methodOne with non-RM artifact .. expect success
testService.testMethodOne(folder); testService.testMethodOne(folder);
// call methodTwo with non-RM artifact .. expect success // call methodTwo with non-RM artifact .. expect success
testService.testMethodTwo(folder); testService.testMethodTwo(folder);
// call methodOne with an RM artifact .. expect success // call methodOne with an RM artifact .. expect success
testService.testMethodOne(recordOne); testService.testMethodOne(recordOne);
return null; return null;
} }
}); });
doTestInTransaction(new FailureTest doTestInTransaction(new FailureTest
( (
"Shouldn't be able to call testMethodTwo on TestService, because override RM security for method is not configred.", "Shouldn't be able to call testMethodTwo on TestService, because override RM security for method is not configred.",
AlfrescoRuntimeException.class AlfrescoRuntimeException.class
) )
{ {
@Override @Override
public void run() throws Exception public void run() throws Exception
{ {
// call methodTwo with an RM artifact .. expect failure // call methodTwo with an RM artifact .. expect failure
testService.testMethodTwo(recordOne); testService.testMethodTwo(recordOne);
} }
}); });
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,178 +21,178 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.site.SiteRole; import org.alfresco.service.cmr.site.SiteRole;
/** /**
* Unit test for RM-804 .. site managers are able to delete file plans * Unit test for RM-804 .. site managers are able to delete file plans
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.1 * @since 2.1
*/ */
public class RM804Test extends BaseRMTestCase public class RM804Test extends BaseRMTestCase
{ {
@Override @Override
protected void initServices() protected void initServices()
{ {
super.initServices(); super.initServices();
} }
@Override @Override
protected boolean isCollaborationSiteTest() protected boolean isCollaborationSiteTest()
{ {
return true; return true;
} }
@Override @Override
protected boolean isUserTest() protected boolean isUserTest()
{ {
return true; return true;
} }
public void testUsersHaveDeletePermissionsOnFilePlan() throws Exception public void testUsersHaveDeletePermissionsOnFilePlan() throws Exception
{ {
// as rmuser // as rmuser
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
return null; return null;
} }
}, ADMIN_USER); }, ADMIN_USER);
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
return null; return null;
} }
}, ADMIN_USER); }, ADMIN_USER);
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
return null; return null;
} }
}, ADMIN_USER); }, ADMIN_USER);
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
return null; return null;
} }
}, rmUserName); }, rmUserName);
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete")); assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
return null; return null;
} }
}, userName); }, userName);
} }
public void testTryAndDeleteSiteAsSiteManagerOnly() public void testTryAndDeleteSiteAsSiteManagerOnly()
{ {
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
siteService.setMembership(siteId, userName, SiteRole.SiteManager.toString()); siteService.setMembership(siteId, userName, SiteRole.SiteManager.toString());
return null; return null;
} }
}, "admin"); }, "admin");
doTestInTransaction(new FailureTest doTestInTransaction(new FailureTest
( (
"Should not be able to delete site as a site manager only.", "Should not be able to delete site as a site manager only.",
AlfrescoRuntimeException.class AlfrescoRuntimeException.class
) )
{ {
@Override @Override
public void run() throws Exception public void run() throws Exception
{ {
siteService.deleteSite(siteId); siteService.deleteSite(siteId);
} }
}, userName); }, userName);
// give the user a RM role (but not sufficient to delete the file plan node ref) // give the user a RM role (but not sufficient to delete the file plan node ref)
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_USER, userName); filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_USER, userName);
return null; return null;
} }
}, "admin"); }, "admin");
doTestInTransaction(new FailureTest doTestInTransaction(new FailureTest
( (
"Should not be able to delete site as a site manager with an RM role that doesn't have the capability.", "Should not be able to delete site as a site manager with an RM role that doesn't have the capability.",
AlfrescoRuntimeException.class AlfrescoRuntimeException.class
) )
{ {
@Override @Override
public void run() throws Exception public void run() throws Exception
{ {
siteService.deleteSite(siteId); siteService.deleteSite(siteId);
} }
}, userName); }, userName);
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_ADMIN, userName); filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_ADMIN, userName);
return null; return null;
} }
}, "admin"); }, "admin");
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
siteService.deleteSite(siteId); siteService.deleteSite(siteId);
return null; return null;
} }
}, userName); }, userName);
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,114 +21,114 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordDefinition; import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordDefinition;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.Period; import org.alfresco.service.cmr.repository.Period;
/** /**
* System test for RM-994 * System test for RM-994
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.1 * @since 2.1
*/ */
public class RM994Test extends BaseRMTestCase public class RM994Test extends BaseRMTestCase
{ {
@Override @Override
protected void initServices() protected void initServices()
{ {
super.initServices(); super.initServices();
} }
@Override @Override
protected boolean isCollaborationSiteTest() protected boolean isCollaborationSiteTest()
{ {
return true; return true;
} }
@Override @Override
protected boolean isRecordTest() protected boolean isRecordTest()
{ {
return true; return true;
} }
public void testRM944() throws Exception public void testRM944() throws Exception
{ {
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
checkVitalRecordNotSet(rmContainer); checkVitalRecordNotSet(rmContainer);
checkVitalRecordNotSet(rmFolder); checkVitalRecordNotSet(rmFolder);
checkVitalRecordNotSet(recordOne); checkVitalRecordNotSet(recordOne);
assertNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF)); assertNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF));
vitalRecordService.setVitalRecordDefintion(rmContainer, true, new Period("month|1")); vitalRecordService.setVitalRecordDefintion(rmContainer, true, new Period("month|1"));
return null; return null;
} }
}); });
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() throws Exception public Void run() throws Exception
{ {
checkVitalRecordSet(rmContainer); checkVitalRecordSet(rmContainer);
checkVitalRecordSet(rmFolder); checkVitalRecordSet(rmFolder);
checkVitalRecordSet(recordOne); checkVitalRecordSet(recordOne);
assertNotNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF)); assertNotNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF));
recordService.createRecord(filePlan, dmDocument, true); recordService.createRecord(filePlan, dmDocument, true);
assertTrue(recordService.isRecord(dmDocument)); assertTrue(recordService.isRecord(dmDocument));
checkVitalRecordNotSet(dmDocument); checkVitalRecordNotSet(dmDocument);
fileFolderService.move(dmDocument, rmFolder, null); fileFolderService.move(dmDocument, rmFolder, null);
checkVitalRecordSet(dmDocument); checkVitalRecordSet(dmDocument);
return null; return null;
} }
}, "admin"); }, "admin");
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() throws Exception public Void run() throws Exception
{ {
checkVitalRecordSet(dmDocument); checkVitalRecordSet(dmDocument);
return null; return null;
} }
}); });
} }
private void checkVitalRecordSet(NodeRef nodeRef) private void checkVitalRecordSet(NodeRef nodeRef)
{ {
VitalRecordDefinition def = vitalRecordService.getVitalRecordDefinition(nodeRef); VitalRecordDefinition def = vitalRecordService.getVitalRecordDefinition(nodeRef);
assertNotNull(def); assertNotNull(def);
assertTrue(def.isEnabled()); assertTrue(def.isEnabled());
assertEquals("month", def.getReviewPeriod().getPeriodType()); assertEquals("month", def.getReviewPeriod().getPeriodType());
assertEquals("1", def.getReviewPeriod().getExpression()); assertEquals("1", def.getReviewPeriod().getExpression());
} }
private void checkVitalRecordNotSet(NodeRef nodeRef) private void checkVitalRecordNotSet(NodeRef nodeRef)
{ {
VitalRecordDefinition recordDef = vitalRecordService.getVitalRecordDefinition(nodeRef); VitalRecordDefinition recordDef = vitalRecordService.getVitalRecordDefinition(nodeRef);
if (recordDef != null) if (recordDef != null)
{ {
assertFalse(recordDef.isEnabled()); assertFalse(recordDef.isEnabled());
assertEquals("none", recordDef.getReviewPeriod().getPeriodType()); assertEquals("none", recordDef.getReviewPeriod().getPeriodType());
assertNull(recordDef.getNextReviewDate()); assertNull(recordDef.getNextReviewDate());
} }
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,220 +21,220 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.integration.version; package org.alfresco.module.org_alfresco_module_rm.test.integration.version;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.version.ExtendedVersionableAspect; import org.alfresco.module.org_alfresco_module_rm.version.ExtendedVersionableAspect;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.VersionHistory; import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
/** /**
* Test recorded version histories when interacting with cm:versionable aspect * Test recorded version histories when interacting with cm:versionable aspect
* and the auto-version behvaiour. * and the auto-version behvaiour.
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.3.1 * @since 2.3.1
*/ */
public class AutoVersionTest extends RecordableVersionsBaseTest public class AutoVersionTest extends RecordableVersionsBaseTest
{ {
/** /**
* Given a versionable document * Given a versionable document
* When I specialise the type of the document * When I specialise the type of the document
* Then the version history has only one initial version * Then the version history has only one initial version
* And it does not represent the current type of the document * And it does not represent the current type of the document
*/ */
public void testSpecialisedNodeInitialVersionCreated() public void testSpecialisedNodeInitialVersionCreated()
{ {
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
{ {
private NodeRef myDocument; private NodeRef myDocument;
public void given() throws Exception public void given() throws Exception
{ {
// create a document // create a document
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
// make versionable // make versionable
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null); nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null);
} }
public void when() public void when()
{ {
// specialise document // specialise document
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
} }
public void then() public void then()
{ {
VersionHistory versionHistory = versionService.getVersionHistory(myDocument); VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
assertNotNull(versionHistory); assertNotNull(versionHistory);
assertEquals(1, versionHistory.getAllVersions().size()); assertEquals(1, versionHistory.getAllVersions().size());
NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef(); NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef();
assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState)); assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState));
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
} }
}); });
} }
/** /**
* Given a versionable document with initial version turned off * Given a versionable document with initial version turned off
* When I specialise the type of the document * When I specialise the type of the document
* Then the version history remains empty * Then the version history remains empty
*/ */
public void testSpecialisedNodeInitialVersionNotCreated() public void testSpecialisedNodeInitialVersionNotCreated()
{ {
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
{ {
private NodeRef myDocument; private NodeRef myDocument;
public void given() throws Exception public void given() throws Exception
{ {
// create a document // create a document
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
// make versionable // make versionable
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1); Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_INITIAL_VERSION, false); props.put(ContentModel.PROP_INITIAL_VERSION, false);
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props); nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props);
} }
public void when() public void when()
{ {
// specialise document // specialise document
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
} }
public void then() public void then()
{ {
VersionHistory versionHistory = versionService.getVersionHistory(myDocument); VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
assertNull(versionHistory); assertNull(versionHistory);
} }
}); });
} }
/** /**
* Given a versionable document with initial version turned off * Given a versionable document with initial version turned off
* And auto version on type change is set on * And auto version on type change is set on
* When I specialise the type of the document * When I specialise the type of the document
* Then the version history contains the initial version * Then the version history contains the initial version
*/ */
public void testSpecialisedNodeInitialVersionNotCreatedOnTypeChangeOn() public void testSpecialisedNodeInitialVersionNotCreatedOnTypeChangeOn()
{ {
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
{ {
private ExtendedVersionableAspect extendedVersionableAspect; private ExtendedVersionableAspect extendedVersionableAspect;
private NodeRef myDocument; private NodeRef myDocument;
public void given() throws Exception public void given() throws Exception
{ {
// turn auto version on type change on // turn auto version on type change on
extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect"); extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect");
assertNotNull(extendedVersionableAspect); assertNotNull(extendedVersionableAspect);
extendedVersionableAspect.setAutoVersionOnTypeChange(true); extendedVersionableAspect.setAutoVersionOnTypeChange(true);
// create a document // create a document
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
// make versionable // make versionable
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1); Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_INITIAL_VERSION, false); props.put(ContentModel.PROP_INITIAL_VERSION, false);
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props); nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props);
} }
public void when() public void when()
{ {
// specialise document // specialise document
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
} }
public void then() public void then()
{ {
VersionHistory versionHistory = versionService.getVersionHistory(myDocument); VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
assertNotNull(versionHistory); assertNotNull(versionHistory);
assertEquals(1, versionHistory.getAllVersions().size()); assertEquals(1, versionHistory.getAllVersions().size());
NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef(); NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef();
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState)); assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState));
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
} }
public void after() throws Exception public void after() throws Exception
{ {
// reset auto version on type to default off // reset auto version on type to default off
extendedVersionableAspect.setAutoVersionOnTypeChange(false); extendedVersionableAspect.setAutoVersionOnTypeChange(false);
} }
}); });
} }
/** /**
* Given a versionable document with initial version turned on * Given a versionable document with initial version turned on
* And auto version on type change is set on * And auto version on type change is set on
* When I specialise the type of the document * When I specialise the type of the document
* Then the version history contains the initial version * Then the version history contains the initial version
*/ */
public void testSpecialisedNodeInitialVersionCreatedOnTypeChangeOn() public void testSpecialisedNodeInitialVersionCreatedOnTypeChangeOn()
{ {
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator) doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
{ {
private ExtendedVersionableAspect extendedVersionableAspect; private ExtendedVersionableAspect extendedVersionableAspect;
private NodeRef myDocument; private NodeRef myDocument;
public void given() throws Exception public void given() throws Exception
{ {
// turn auto version on type change on // turn auto version on type change on
extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect"); extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect");
assertNotNull(extendedVersionableAspect); assertNotNull(extendedVersionableAspect);
extendedVersionableAspect.setAutoVersionOnTypeChange(true); extendedVersionableAspect.setAutoVersionOnTypeChange(true);
// create a document // create a document
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
// make versionable // make versionable
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1); Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_INITIAL_VERSION, true); props.put(ContentModel.PROP_INITIAL_VERSION, true);
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props); nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props);
} }
public void when() public void when()
{ {
// specialise document // specialise document
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE); nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
} }
public void then() public void then()
{ {
VersionHistory versionHistory = versionService.getVersionHistory(myDocument); VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
assertNotNull(versionHistory); assertNotNull(versionHistory);
assertEquals(2, versionHistory.getAllVersions().size()); assertEquals(2, versionHistory.getAllVersions().size());
NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef(); NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef();
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState)); assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState));
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
frozenState = versionHistory.getVersion("1.0").getFrozenStateNodeRef(); frozenState = versionHistory.getVersion("1.0").getFrozenStateNodeRef();
assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState)); assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState));
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument)); assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
} }
public void after() throws Exception public void after() throws Exception
{ {
// reset auto version on type to default off // reset auto version on type to default off
extendedVersionableAspect.setAutoVersionOnTypeChange(false); extendedVersionableAspect.setAutoVersionOnTypeChange(false);
} }
}); });
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,493 +21,493 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.integration.version; package org.alfresco.module.org_alfresco_module_rm.test.integration.version;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.action.impl.CompleteEventAction; import org.alfresco.module.org_alfresco_module_rm.action.impl.CompleteEventAction;
import org.alfresco.module.org_alfresco_module_rm.action.impl.CutOffAction; import org.alfresco.module.org_alfresco_module_rm.action.impl.CutOffAction;
import org.alfresco.module.org_alfresco_module_rm.action.impl.DestroyAction; import org.alfresco.module.org_alfresco_module_rm.action.impl.DestroyAction;
import org.alfresco.module.org_alfresco_module_rm.relationship.Relationship; import org.alfresco.module.org_alfresco_module_rm.relationship.Relationship;
import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService; import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService;
import org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils; import org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils;
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel; import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel;
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy; import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy;
import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.Version; import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory; import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
/** /**
* Recordable version history integration tests. * Recordable version history integration tests.
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.3.1 * @since 2.3.1
*/ */
public class DeleteRecordVersionTest extends RecordableVersionsBaseTest public class DeleteRecordVersionTest extends RecordableVersionsBaseTest
{ {
/** /**
* Given that a document is created * Given that a document is created
* And the initial version is record * And the initial version is record
* When I delete the version record * When I delete the version record
* Then the version is deleted * Then the version is deleted
* And the version history is not deleted * And the version history is not deleted
* *
* @see https://issues.alfresco.com/jira/browse/RM-2562 * @see https://issues.alfresco.com/jira/browse/RM-2562
*/ */
public void testDeleteFirstRecordedVersion() public void testDeleteFirstRecordedVersion()
{ {
doBehaviourDrivenTest(new BehaviourDrivenTest() doBehaviourDrivenTest(new BehaviourDrivenTest()
{ {
private NodeRef myDocument; private NodeRef myDocument;
public void given() throws Exception public void given() throws Exception
{ {
// create a document // create a document
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
// make versionable // make versionable
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2); Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL); props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL);
props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan); props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan);
nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props); nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props);
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null); nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null);
} }
public void when() public void when()
{ {
// check the initial version label // check the initial version label
assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL)); assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL));
// check that the version history contains a single version that is recorded // check that the version history contains a single version that is recorded
VersionHistory versionHistory = versionService.getVersionHistory(myDocument); VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
assertNotNull(versionHistory); assertNotNull(versionHistory);
assertEquals(1, versionHistory.getAllVersions().size()); assertEquals(1, versionHistory.getAllVersions().size());
// check the recorded version is not marked as destroyed // check the recorded version is not marked as destroyed
Version head = versionHistory.getHeadVersion(); Version head = versionHistory.getHeadVersion();
assertNotNull(head); assertNotNull(head);
assertFalse(recordableVersionService.isRecordedVersionDestroyed(head)); assertFalse(recordableVersionService.isRecordedVersionDestroyed(head));
// check the version record // check the version record
NodeRef record = recordableVersionService.getVersionRecord(head); NodeRef record = recordableVersionService.getVersionRecord(head);
assertTrue(recordService.isRecord(record)); assertTrue(recordService.isRecord(record));
// record should not have a version history because it is immutable // record should not have a version history because it is immutable
assertFalse(nodeService.hasAspect(record, ContentModel.ASPECT_VERSIONABLE)); assertFalse(nodeService.hasAspect(record, ContentModel.ASPECT_VERSIONABLE));
VersionHistory recordVersionHistory = versionService.getVersionHistory(record); VersionHistory recordVersionHistory = versionService.getVersionHistory(record);
assertNull(recordVersionHistory); assertNull(recordVersionHistory);
// destroy record // destroy record
nodeService.deleteNode(record); nodeService.deleteNode(record);
} }
public void then() public void then()
{ {
// document is still versionable // document is still versionable
assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE)); assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE));
// check the initial version label // check the initial version label
assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL)); assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL));
// still has a version history, but the version is marked as destroyed // still has a version history, but the version is marked as destroyed
VersionHistory versionHistory = versionService.getVersionHistory(myDocument); VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
assertNotNull(versionHistory); assertNotNull(versionHistory);
assertEquals(1, versionHistory.getAllVersions().size()); assertEquals(1, versionHistory.getAllVersions().size());
// check the recorded version is marked as destroyed and the record version is not longer available // check the recorded version is marked as destroyed and the record version is not longer available
Version version = versionHistory.getHeadVersion(); Version version = versionHistory.getHeadVersion();
assertNotNull(version); assertNotNull(version);
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version)); assertTrue(recordableVersionService.isRecordedVersionDestroyed(version));
assertNull(recordableVersionService.getVersionRecord(version)); assertNull(recordableVersionService.getVersionRecord(version));
} }
}); });
} }
/** /**
* Given that a document is created * Given that a document is created
* And the initial version is record * And the initial version is record
* And the associated version record is deleted * And the associated version record is deleted
* When a new version is created * When a new version is created
* Then a new associated version record is created * Then a new associated version record is created
* And the version is 1.1 (not 1.0 since this was deleted, but the version history maintained) * And the version is 1.1 (not 1.0 since this was deleted, but the version history maintained)
* *
* @see https://issues.alfresco.com/jira/browse/RM-2562 * @see https://issues.alfresco.com/jira/browse/RM-2562
*/ */
public void testDeleteFirstRecordedVersionAndCreateNewVersion() public void testDeleteFirstRecordedVersionAndCreateNewVersion()
{ {
doBehaviourDrivenTest(new BehaviourDrivenTest() doBehaviourDrivenTest(new BehaviourDrivenTest()
{ {
private NodeRef myDocument; private NodeRef myDocument;
public void given() throws Exception public void given() throws Exception
{ {
// create a document // create a document
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef(); myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
ContentWriter writer = fileFolderService.getWriter(myDocument); ContentWriter writer = fileFolderService.getWriter(myDocument);
writer.setEncoding("UTF-8"); writer.setEncoding("UTF-8");
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.putContent(GUID.generate()); writer.putContent(GUID.generate());
// make versionable // make versionable
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2); Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL); props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL);
props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan); props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan);
nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props); nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props);
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null); nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null);
} }
public void when() public void when()
{ {
// get the created version record // get the created version record
VersionHistory versionHistory = versionService.getVersionHistory(myDocument); VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
Version head = versionHistory.getHeadVersion(); Version head = versionHistory.getHeadVersion();
NodeRef record = recordableVersionService.getVersionRecord(head); NodeRef record = recordableVersionService.getVersionRecord(head);
// destroy record // destroy record
nodeService.deleteNode(record); nodeService.deleteNode(record);
// update the content to create a new version (and version record) // update the content to create a new version (and version record)
ContentWriter writer = fileFolderService.getWriter(myDocument); ContentWriter writer = fileFolderService.getWriter(myDocument);
writer.putContent(GUID.generate()); writer.putContent(GUID.generate());
} }
public void then() public void then()
{ {
// document is still versionable // document is still versionable
assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE)); assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE));
// check the version number has been incremented // check the version number has been incremented
assertEquals("1.1", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL)); assertEquals("1.1", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL));
// still has a version history, with 2 enties // still has a version history, with 2 enties
VersionHistory versionHistory = versionService.getVersionHistory(myDocument); VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
assertNotNull(versionHistory); assertNotNull(versionHistory);
assertEquals(2, versionHistory.getAllVersions().size()); assertEquals(2, versionHistory.getAllVersions().size());
// latest version is current // latest version is current
Version head = versionHistory.getHeadVersion(); Version head = versionHistory.getHeadVersion();
assertFalse(recordableVersionService.isRecordedVersionDestroyed(head)); assertFalse(recordableVersionService.isRecordedVersionDestroyed(head));
assertNotNull(recordableVersionService.getVersionRecord(head)); assertNotNull(recordableVersionService.getVersionRecord(head));
// first version is destroyed // first version is destroyed
Version destroyed = versionHistory.getPredecessor(head); Version destroyed = versionHistory.getPredecessor(head);
assertTrue(recordableVersionService.isRecordedVersionDestroyed(destroyed)); assertTrue(recordableVersionService.isRecordedVersionDestroyed(destroyed));
assertNull(recordableVersionService.getVersionRecord(destroyed)); assertNull(recordableVersionService.getVersionRecord(destroyed));
// get the version record for the current version // get the version record for the current version
NodeRef versionRecord = recordableVersionService.getVersionRecord(head); NodeRef versionRecord = recordableVersionService.getVersionRecord(head);
assertNotNull(versionRecord); assertNotNull(versionRecord);
assertTrue(nodeService.exists(versionRecord)); assertTrue(nodeService.exists(versionRecord));
Set<Relationship> from = relationshipService.getRelationshipsFrom(versionRecord); Set<Relationship> from = relationshipService.getRelationshipsFrom(versionRecord);
assertTrue(from.isEmpty()); assertTrue(from.isEmpty());
Set<Relationship> to = relationshipService.getRelationshipsTo(versionRecord); Set<Relationship> to = relationshipService.getRelationshipsTo(versionRecord);
assertTrue(to.isEmpty()); assertTrue(to.isEmpty());
} }
}); });
} }
/** /**
* Given a chain of version records (1.0, 1.1, 1.2) which are all related * Given a chain of version records (1.0, 1.1, 1.2) which are all related
* When I delete version record 1.0 * When I delete version record 1.0
* Then 1.1 is the oldest version * Then 1.1 is the oldest version
*/ */
public void testDeleteOldestVersion() public void testDeleteOldestVersion()
{ {
final NodeRef myDocument = createDocumentWithRecordVersions(); final NodeRef myDocument = createDocumentWithRecordVersions();
doBehaviourDrivenTest(new BehaviourDrivenTest() doBehaviourDrivenTest(new BehaviourDrivenTest()
{ {
private VersionHistory versionHistory; private VersionHistory versionHistory;
public void given() throws Exception public void given() throws Exception
{ {
// get version history // get version history
versionHistory = versionService.getVersionHistory(myDocument); versionHistory = versionService.getVersionHistory(myDocument);
} }
public void when() public void when()
{ {
Version version10 = versionHistory.getVersion("1.0"); Version version10 = versionHistory.getVersion("1.0");
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
// delete record version 1.0 // delete record version 1.0
nodeService.deleteNode(recordVersion10); nodeService.deleteNode(recordVersion10);
} }
public void then() public void then()
{ {
// check the deleted version // check the deleted version
Version version10 = versionHistory.getVersion("1.0"); Version version10 = versionHistory.getVersion("1.0");
assertNotNull(version10); assertNotNull(version10);
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version10)); assertTrue(recordableVersionService.isRecordedVersionDestroyed(version10));
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
assertNull(recordVersion10); assertNull(recordVersion10);
// verify 1.2 setup as expected // verify 1.2 setup as expected
Version version12 = versionHistory.getHeadVersion(); Version version12 = versionHistory.getHeadVersion();
assertEquals("1.2", version12.getVersionLabel()); assertEquals("1.2", version12.getVersionLabel());
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
assertNotNull(recordVersion12); assertNotNull(recordVersion12);
assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS); Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS);
assertEquals(1, from12.size()); assertEquals(1, from12.size());
// verify 1.1 setup as expected // verify 1.1 setup as expected
Version version11 = versionHistory.getPredecessor(version12); Version version11 = versionHistory.getPredecessor(version12);
assertEquals("1.1", version11.getVersionLabel()); assertEquals("1.1", version11.getVersionLabel());
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
assertNotNull(recordVersion11); assertNotNull(recordVersion11);
Set<Relationship> to11 = relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS); Set<Relationship> to11 = relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS);
assertEquals(1, to11.size()); assertEquals(1, to11.size());
assertEquals(recordVersion12, to11.iterator().next().getSource()); assertEquals(recordVersion12, to11.iterator().next().getSource());
assertTrue(relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); assertTrue(relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
} }
}); });
} }
/** /**
* Given a chain of version records (1.0, 1.1, 1.2) which are all related * Given a chain of version records (1.0, 1.1, 1.2) which are all related
* When I delete version record 1.1 * When I delete version record 1.1
* Then 1.2 now 'versions' 1.0 * Then 1.2 now 'versions' 1.0
*/ */
public void testDeleteMiddleVersion() public void testDeleteMiddleVersion()
{ {
final NodeRef myDocument = createDocumentWithRecordVersions(); final NodeRef myDocument = createDocumentWithRecordVersions();
doBehaviourDrivenTest(new BehaviourDrivenTest() doBehaviourDrivenTest(new BehaviourDrivenTest()
{ {
private VersionHistory versionHistory; private VersionHistory versionHistory;
public void given() throws Exception public void given() throws Exception
{ {
// get version history // get version history
versionHistory = versionService.getVersionHistory(myDocument); versionHistory = versionService.getVersionHistory(myDocument);
} }
public void when() public void when()
{ {
Version version11 = versionHistory.getVersion("1.1"); Version version11 = versionHistory.getVersion("1.1");
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
// delete record version 1.1 // delete record version 1.1
nodeService.deleteNode(recordVersion11); nodeService.deleteNode(recordVersion11);
} }
public void then() public void then()
{ {
// check the deleted version // check the deleted version
Version version11 = versionHistory.getVersion("1.1"); Version version11 = versionHistory.getVersion("1.1");
assertNotNull(version11); assertNotNull(version11);
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11)); assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11));
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
assertNull(recordVersion11); assertNull(recordVersion11);
// verify 1.2 setup as expected // verify 1.2 setup as expected
Version version12 = versionHistory.getHeadVersion(); Version version12 = versionHistory.getHeadVersion();
assertEquals("1.2", version12.getVersionLabel()); assertEquals("1.2", version12.getVersionLabel());
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
assertNotNull(recordVersion12); assertNotNull(recordVersion12);
assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS); Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS);
assertEquals(1, from12.size()); assertEquals(1, from12.size());
// verify 1.0 setup as expected // verify 1.0 setup as expected
Version version10 = versionHistory.getVersion("1.0"); Version version10 = versionHistory.getVersion("1.0");
assertEquals("1.0", version10.getVersionLabel()); assertEquals("1.0", version10.getVersionLabel());
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
assertNotNull(recordVersion10); assertNotNull(recordVersion10);
Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS); Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS);
assertEquals(1, to10.size()); assertEquals(1, to10.size());
assertEquals(recordVersion12, to10.iterator().next().getSource()); assertEquals(recordVersion12, to10.iterator().next().getSource());
assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
} }
}); });
} }
/** /**
* Given a chain of version records (1.0, 1.1, 1.2) which are all related * Given a chain of version records (1.0, 1.1, 1.2) which are all related
* When I delete version record 1.2 * When I delete version record 1.2
* Then 1.1 is the most recent version * Then 1.1 is the most recent version
*/ */
public void testDeleteCurrentVersion() public void testDeleteCurrentVersion()
{ {
final NodeRef myDocument = createDocumentWithRecordVersions(); final NodeRef myDocument = createDocumentWithRecordVersions();
doBehaviourDrivenTest(new BehaviourDrivenTest() doBehaviourDrivenTest(new BehaviourDrivenTest()
{ {
private VersionHistory versionHistory; private VersionHistory versionHistory;
public void given() throws Exception public void given() throws Exception
{ {
// get version history // get version history
versionHistory = versionService.getVersionHistory(myDocument); versionHistory = versionService.getVersionHistory(myDocument);
} }
public void when() public void when()
{ {
Version version12 = versionHistory.getVersion("1.2"); Version version12 = versionHistory.getVersion("1.2");
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
// delete record version 1.2 // delete record version 1.2
nodeService.deleteNode(recordVersion12); nodeService.deleteNode(recordVersion12);
} }
public void then() public void then()
{ {
// check 1.2 // check 1.2
Version version12 = versionHistory.getVersion("1.2"); Version version12 = versionHistory.getVersion("1.2");
assertNotNull(version12); assertNotNull(version12);
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version12)); assertTrue(recordableVersionService.isRecordedVersionDestroyed(version12));
assertNull(recordableVersionService.getVersionRecord(version12)); assertNull(recordableVersionService.getVersionRecord(version12));
// verify 1.1 // verify 1.1
Version version11 = versionHistory.getVersion("1.1"); Version version11 = versionHistory.getVersion("1.1");
assertNotNull(version11); assertNotNull(version11);
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11); NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
assertNotNull(recordVersion11); assertNotNull(recordVersion11);
assertTrue(relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); assertTrue(relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS); Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS);
assertEquals(1, from11.size()); assertEquals(1, from11.size());
// verify 1.0 // verify 1.0
Version version10 = versionHistory.getVersion("1.0"); Version version10 = versionHistory.getVersion("1.0");
assertNotNull(version10); assertNotNull(version10);
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
assertNotNull(recordVersion10); assertNotNull(recordVersion10);
Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS); Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS);
assertEquals(1, to10.size()); assertEquals(1, to10.size());
assertEquals(recordVersion11, to10.iterator().next().getSource()); assertEquals(recordVersion11, to10.iterator().next().getSource());
assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty()); assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
} }
}); });
} }
/** /**
* Given that a version record * Given that a version record
* When the version record is destroyed whilst retaining the meta data * When the version record is destroyed whilst retaining the meta data
* Then the version is marked as destroyed in the collab version history * Then the version is marked as destroyed in the collab version history
*/ */
public void testDestroyVersionRecordWithMetadata() public void testDestroyVersionRecordWithMetadata()
{ {
final NodeRef myDocument = createDocumentWithRecordVersions(); final NodeRef myDocument = createDocumentWithRecordVersions();
doBehaviourDrivenTest(new BehaviourDrivenTest() doBehaviourDrivenTest(new BehaviourDrivenTest()
{ {
private VersionHistory versionHistory; private VersionHistory versionHistory;
private NodeRef recordVersion11; private NodeRef recordVersion11;
public void given() throws Exception public void given() throws Exception
{ {
// create file plan structure // create file plan structure
NodeRef myCategory = filePlanService.createRecordCategory(filePlan, GUID.generate()); NodeRef myCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
utils.createBasicDispositionSchedule(myCategory, GUID.generate(), GUID.generate(), true, true); utils.createBasicDispositionSchedule(myCategory, GUID.generate(), GUID.generate(), true, true);
NodeRef myRecordFolder = recordFolderService.createRecordFolder(myCategory, GUID.generate()); NodeRef myRecordFolder = recordFolderService.createRecordFolder(myCategory, GUID.generate());
// get version history // get version history
versionHistory = versionService.getVersionHistory(myDocument); versionHistory = versionService.getVersionHistory(myDocument);
// file and complete all the version records into my record folder // file and complete all the version records into my record folder
for (Version version : versionHistory.getAllVersions()) for (Version version : versionHistory.getAllVersions())
{ {
NodeRef record = recordableVersionService.getVersionRecord(version); NodeRef record = recordableVersionService.getVersionRecord(version);
fileFolderService.move(record, myRecordFolder, null); fileFolderService.move(record, myRecordFolder, null);
utils.completeRecord(record); utils.completeRecord(record);
} }
} }
public void when() public void when()
{ {
Version version11 = versionHistory.getVersion("1.1"); Version version11 = versionHistory.getVersion("1.1");
recordVersion11 = recordableVersionService.getVersionRecord(version11); recordVersion11 = recordableVersionService.getVersionRecord(version11);
Map<String, Serializable> params = new HashMap<String, Serializable>(1); Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(CompleteEventAction.PARAM_EVENT_NAME, CommonRMTestUtils.DEFAULT_EVENT_NAME); params.put(CompleteEventAction.PARAM_EVENT_NAME, CommonRMTestUtils.DEFAULT_EVENT_NAME);
rmActionService.executeRecordsManagementAction(recordVersion11, CompleteEventAction.NAME, params); rmActionService.executeRecordsManagementAction(recordVersion11, CompleteEventAction.NAME, params);
rmActionService.executeRecordsManagementAction(recordVersion11, CutOffAction.NAME); rmActionService.executeRecordsManagementAction(recordVersion11, CutOffAction.NAME);
rmActionService.executeRecordsManagementAction(recordVersion11, DestroyAction.NAME); rmActionService.executeRecordsManagementAction(recordVersion11, DestroyAction.NAME);
} }
public void then() public void then()
{ {
// verify that the version history looks as expected // verify that the version history looks as expected
VersionHistory versionHistory = versionService.getVersionHistory(myDocument); VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
assertNotNull(versionHistory); assertNotNull(versionHistory);
Collection<Version> versions = versionHistory.getAllVersions(); Collection<Version> versions = versionHistory.getAllVersions();
assertEquals(3, versions.size()); assertEquals(3, versions.size());
// verify 1.2 setup as expected // verify 1.2 setup as expected
Version version12 = versionHistory.getHeadVersion(); Version version12 = versionHistory.getHeadVersion();
assertEquals("1.2", version12.getVersionLabel()); assertEquals("1.2", version12.getVersionLabel());
assertFalse(recordableVersionService.isRecordedVersionDestroyed(version12)); assertFalse(recordableVersionService.isRecordedVersionDestroyed(version12));
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12); NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
assertNotNull(recordVersion12); assertNotNull(recordVersion12);
assertFalse(recordService.isMetadataStub(recordVersion12)); assertFalse(recordService.isMetadataStub(recordVersion12));
assertTrue(relationshipService.getRelationshipsTo(recordVersion12, "versions").isEmpty()); assertTrue(relationshipService.getRelationshipsTo(recordVersion12, "versions").isEmpty());
Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, "versions"); Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, "versions");
assertEquals(1, from12.size()); assertEquals(1, from12.size());
// verify 1.1 setup as expected // verify 1.1 setup as expected
Version version11 = versionHistory.getPredecessor(version12); Version version11 = versionHistory.getPredecessor(version12);
assertEquals("1.1", version11.getVersionLabel()); assertEquals("1.1", version11.getVersionLabel());
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11)); assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11));
assertNotNull(recordVersion11); assertNotNull(recordVersion11);
assertTrue(recordService.isMetadataStub(recordVersion11)); assertTrue(recordService.isMetadataStub(recordVersion11));
Set<Relationship> to11 = relationshipService.getRelationshipsTo(recordVersion11, "versions"); Set<Relationship> to11 = relationshipService.getRelationshipsTo(recordVersion11, "versions");
assertEquals(1, to11.size()); assertEquals(1, to11.size());
assertEquals(recordVersion12, to11.iterator().next().getSource()); assertEquals(recordVersion12, to11.iterator().next().getSource());
Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, "versions"); Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, "versions");
assertEquals(1, from11.size()); assertEquals(1, from11.size());
// verify 1.0 setup as expected // verify 1.0 setup as expected
Version version10 = versionHistory.getPredecessor(version11); Version version10 = versionHistory.getPredecessor(version11);
assertEquals("1.0", version10.getVersionLabel()); assertEquals("1.0", version10.getVersionLabel());
assertFalse(recordableVersionService.isRecordedVersionDestroyed(version10)); assertFalse(recordableVersionService.isRecordedVersionDestroyed(version10));
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10); NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
assertNotNull(recordVersion10); assertNotNull(recordVersion10);
assertFalse(recordService.isMetadataStub(recordVersion10)); assertFalse(recordService.isMetadataStub(recordVersion10));
Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, "versions"); Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, "versions");
assertEquals(1, to10.size()); assertEquals(1, to10.size());
assertEquals(recordVersion11, to10.iterator().next().getSource()); assertEquals(recordVersion11, to10.iterator().next().getSource());
assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, "versions").isEmpty()); assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, "versions").isEmpty());
} }
}); });
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,80 +21,80 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.legacy.webscript; package org.alfresco.module.org_alfresco_module_rm.test.legacy.webscript;
import static org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService.DEFAULT_RM_SITE_ID; import static org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService.DEFAULT_RM_SITE_ID;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
public class AuditRestApiTest extends BaseRMWebScriptTestCase public class AuditRestApiTest extends BaseRMWebScriptTestCase
{ {
/** URL for the REST APIs */ /** URL for the REST APIs */
protected static final String GET_NODE_AUDITLOG_URL_FORMAT = "/api/node/{0}/rmauditlog"; protected static final String GET_NODE_AUDITLOG_URL_FORMAT = "/api/node/{0}/rmauditlog";
private static final String USER_WITHOUT_AUDIT_CAPABILITY = GUID.generate(); private static final String USER_WITHOUT_AUDIT_CAPABILITY = GUID.generate();
private NodeRef record; private NodeRef record;
public void testAuditAccessCapability() throws IOException public void testAuditAccessCapability() throws IOException
{ {
String recordAuditUrl = MessageFormat.format(GET_NODE_AUDITLOG_URL_FORMAT,record.toString().replace("://", "/")); String recordAuditUrl = MessageFormat.format(GET_NODE_AUDITLOG_URL_FORMAT,record.toString().replace("://", "/"));
sendRequest(new GetRequest(recordAuditUrl), Status.STATUS_OK, AuthenticationUtil.getAdminUserName() ); sendRequest(new GetRequest(recordAuditUrl), Status.STATUS_OK, AuthenticationUtil.getAdminUserName() );
sendRequest(new GetRequest(recordAuditUrl), Status.STATUS_FORBIDDEN, USER_WITHOUT_AUDIT_CAPABILITY ); sendRequest(new GetRequest(recordAuditUrl), Status.STATUS_FORBIDDEN, USER_WITHOUT_AUDIT_CAPABILITY );
} }
@Override @Override
protected void setupTestData() protected void setupTestData()
{ {
super.setupTestData(); super.setupTestData();
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>() retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
{ {
@Override @Override
public Object execute() throws Throwable public Object execute() throws Throwable
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil
.getSystemUserName()); .getSystemUserName());
createUser(USER_WITHOUT_AUDIT_CAPABILITY); createUser(USER_WITHOUT_AUDIT_CAPABILITY);
record = utils.createRecord(recordFolder, GUID.generate()); record = utils.createRecord(recordFolder, GUID.generate());
return null; return null;
} }
}); });
} }
@Override @Override
protected void tearDownImpl() protected void tearDownImpl()
{ {
super.tearDownImpl(); super.tearDownImpl();
deleteUser(USER_WITHOUT_AUDIT_CAPABILITY); deleteUser(USER_WITHOUT_AUDIT_CAPABILITY);
} }
protected String getRMSiteId() protected String getRMSiteId()
{ {
return DEFAULT_RM_SITE_ID; return DEFAULT_RM_SITE_ID;
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,136 +21,136 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.system; package org.alfresco.module.org_alfresco_module_rm.test.system;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.notification.RecordsManagementNotificationHelper; import org.alfresco.module.org_alfresco_module_rm.notification.RecordsManagementNotificationHelper;
import org.alfresco.module.org_alfresco_module_rm.role.Role; import org.alfresco.module.org_alfresco_module_rm.role.Role;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
import org.alfresco.util.PropertyMap; import org.alfresco.util.PropertyMap;
/** /**
* Notification helper (system) test * Notification helper (system) test
* *
* @author Roy Wetherall * @author Roy Wetherall
*/ */
public class NotificationServiceHelperSystemTest extends BaseRMTestCase public class NotificationServiceHelperSystemTest extends BaseRMTestCase
{ {
private static final String NOTIFICATION_ROLE = "RecordsManager"; private static final String NOTIFICATION_ROLE = "RecordsManager";
private static final String EMAIL_ADDRESS = "roy.wetherall@alfreso.com"; private static final String EMAIL_ADDRESS = "roy.wetherall@alfreso.com";
/** Services */ /** Services */
private RecordsManagementNotificationHelper notificationHelper; private RecordsManagementNotificationHelper notificationHelper;
/** Test data */ /** Test data */
private NodeRef record; private NodeRef record;
private List<NodeRef> records; private List<NodeRef> records;
private String userName; private String userName;
private NodeRef person; private NodeRef person;
@Override @Override
protected void initServices() protected void initServices()
{ {
super.initServices(); super.initServices();
// Get the notification helper // Get the notification helper
notificationHelper = (RecordsManagementNotificationHelper)applicationContext.getBean("recordsManagementNotificationHelper"); notificationHelper = (RecordsManagementNotificationHelper)applicationContext.getBean("recordsManagementNotificationHelper");
} }
@Override @Override
protected void setupTestData() protected void setupTestData()
{ {
super.setupTestData(); super.setupTestData();
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>() retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
{ {
@Override @Override
public Object execute() throws Throwable public Object execute() throws Throwable
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
// Create a user // Create a user
userName = GUID.generate(); userName = GUID.generate();
authenticationService.createAuthentication(userName, "".toCharArray()); authenticationService.createAuthentication(userName, "".toCharArray());
PropertyMap props = new PropertyMap(); PropertyMap props = new PropertyMap();
props.put(PROP_USERNAME, userName); props.put(PROP_USERNAME, userName);
props.put(PROP_FIRSTNAME, "Test"); props.put(PROP_FIRSTNAME, "Test");
props.put(PROP_LASTNAME, "User"); props.put(PROP_LASTNAME, "User");
props.put(PROP_EMAIL, EMAIL_ADDRESS); props.put(PROP_EMAIL, EMAIL_ADDRESS);
person = personService.createPerson(props); person = personService.createPerson(props);
// Find the authority for the given role // Find the authority for the given role
Role role = filePlanRoleService.getRole(filePlan, NOTIFICATION_ROLE); Role role = filePlanRoleService.getRole(filePlan, NOTIFICATION_ROLE);
assertNotNull("Notification role could not be retrieved", role); assertNotNull("Notification role could not be retrieved", role);
String roleGroup = role.getRoleGroupName(); String roleGroup = role.getRoleGroupName();
assertNotNull("Notification role group can not be null.", roleGroup); assertNotNull("Notification role group can not be null.", roleGroup);
// Add user to notification role group // Add user to notification role group
authorityService.addAuthority(roleGroup, userName); authorityService.addAuthority(roleGroup, userName);
return null; return null;
} }
}); });
} }
@Override @Override
protected void setupTestDataImpl() protected void setupTestDataImpl()
{ {
super.setupTestDataImpl(); super.setupTestDataImpl();
// Create a few test records // Create a few test records
record = utils.createRecord(rmFolder, "recordOne"); record = utils.createRecord(rmFolder, "recordOne");
NodeRef record2 = utils.createRecord(rmFolder, "recordTwo"); NodeRef record2 = utils.createRecord(rmFolder, "recordTwo");
NodeRef record3 = utils.createRecord(rmFolder, "recordThree"); NodeRef record3 = utils.createRecord(rmFolder, "recordThree");
records = new ArrayList<NodeRef>(3); records = new ArrayList<NodeRef>(3);
records.add(record); records.add(record);
records.add(record2); records.add(record2);
records.add(record3); records.add(record3);
} }
@Override @Override
protected void tearDownImpl() protected void tearDownImpl()
{ {
super.tearDownImpl(); super.tearDownImpl();
// Delete the person and user // Delete the person and user
personService.deletePerson(person); personService.deletePerson(person);
} }
public void testSendDueForReviewNotification() public void testSendDueForReviewNotification()
{ {
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
notificationHelper.recordsDueForReviewEmailNotification(records); notificationHelper.recordsDueForReviewEmailNotification(records);
return null; return null;
} }
}); });
} }
public void testSendSupersededNotification() public void testSendSupersededNotification()
{ {
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() public Void run()
{ {
notificationHelper.recordSupersededEmailNotification(record); notificationHelper.recordSupersededEmailNotification(record);
return null; return null;
} }
}); });
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,63 +21,63 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.util; package org.alfresco.module.org_alfresco_module_rm.test.util;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.FileWriter; import java.io.FileWriter;
import java.util.Set; import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.capability.Capability; import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
import org.alfresco.module.org_alfresco_module_rm.capability.Group; import org.alfresco.module.org_alfresco_module_rm.capability.Group;
/** /**
* Utility test case to generate a report of the capabilities in the system. * Utility test case to generate a report of the capabilities in the system.
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.1 * @since 2.1
*/ */
public class GenerateCapabilityReport extends BaseRMTestCase public class GenerateCapabilityReport extends BaseRMTestCase
{ {
public void testGetCapability() throws Exception public void testGetCapability() throws Exception
{ {
doTestInTransaction(new Test<Void>() doTestInTransaction(new Test<Void>()
{ {
@Override @Override
public Void run() throws Exception public Void run() throws Exception
{ {
FileWriter writer = new FileWriter("c:\\mywork\\capabilityReport.csv"); FileWriter writer = new FileWriter("c:\\mywork\\capabilityReport.csv");
BufferedWriter out = new BufferedWriter(writer); BufferedWriter out = new BufferedWriter(writer);
try try
{ {
Set<Capability> capabilities = capabilityService.getCapabilities(true); Set<Capability> capabilities = capabilityService.getCapabilities(true);
for (Capability capability : capabilities) for (Capability capability : capabilities)
{ {
Group group = capability.getGroup(); Group group = capability.getGroup();
String groupId = "none"; String groupId = "none";
if (group != null) if (group != null)
{ {
groupId = group.getId(); groupId = group.getId();
} }
out.write(groupId); out.write(groupId);
out.write(","); out.write(",");
out.write(capability.getName()); out.write(capability.getName());
out.write(","); out.write(",");
out.write(Boolean.toString(capability.isPrivate())); out.write(Boolean.toString(capability.isPrivate()));
out.write("\n"); out.write("\n");
} }
} }
finally finally
{ {
out.close(); out.close();
} }
return null; return null;
} }
}); });
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,209 +21,209 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.util; package org.alfresco.module.org_alfresco_module_rm.test.util;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import org.alfresco.repo.security.authentication.AuthenticationException; import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.util.EqualsHelper; import org.alfresco.util.EqualsHelper;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.extensions.webscripts.TestWebScriptServer; import org.springframework.extensions.webscripts.TestWebScriptServer;
/** /**
* Stand-alone Web Script Test Server * Stand-alone Web Script Test Server
* *
* @author davidc * @author davidc
*/ */
public class TestWebScriptRepoServer extends TestWebScriptServer public class TestWebScriptRepoServer extends TestWebScriptServer
{ {
/** /**
* Main entry point. * Main entry point.
*/ */
public static void main(String[] args) public static void main(String[] args)
{ {
try try
{ {
TestWebScriptServer testServer = getTestServer(); TestWebScriptServer testServer = getTestServer();
AuthenticationUtil.setRunAsUserSystem(); AuthenticationUtil.setRunAsUserSystem();
testServer.rep(); testServer.rep();
} }
catch(Throwable e) catch(Throwable e)
{ {
StringWriter strWriter = new StringWriter(); StringWriter strWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(strWriter); PrintWriter printWriter = new PrintWriter(strWriter);
e.printStackTrace(printWriter); e.printStackTrace(printWriter);
System.out.println(strWriter.toString()); System.out.println(strWriter.toString());
} }
finally finally
{ {
System.exit(0); System.exit(0);
} }
} }
private final static String[] CONFIG_LOCATIONS = new String[] private final static String[] CONFIG_LOCATIONS = new String[]
{ {
"classpath:alfresco/application-context.xml", "classpath:alfresco/application-context.xml",
"classpath:alfresco/web-scripts-application-context.xml", "classpath:alfresco/web-scripts-application-context.xml",
"classpath:alfresco/web-scripts-application-context-test.xml" "classpath:alfresco/web-scripts-application-context-test.xml"
}; };
/** A static reference to the application context being used */ /** A static reference to the application context being used */
private static ClassPathXmlApplicationContext ctx; private static ClassPathXmlApplicationContext ctx;
private static String appendedTestConfiguration; private static String appendedTestConfiguration;
private RetryingTransactionHelper retryingTransactionHelper; private RetryingTransactionHelper retryingTransactionHelper;
private AuthenticationService authenticationService; private AuthenticationService authenticationService;
/** /**
* Sets helper that provides transaction callbacks * Sets helper that provides transaction callbacks
*/ */
public void setTransactionHelper(RetryingTransactionHelper retryingTransactionHelper) public void setTransactionHelper(RetryingTransactionHelper retryingTransactionHelper)
{ {
this.retryingTransactionHelper = retryingTransactionHelper; this.retryingTransactionHelper = retryingTransactionHelper;
} }
/** /**
* @param authenticationService * @param authenticationService
*/ */
public void setAuthenticationService(AuthenticationService authenticationService) public void setAuthenticationService(AuthenticationService authenticationService)
{ {
this.authenticationService = authenticationService; this.authenticationService = authenticationService;
} }
/** /**
* Get default user name * Get default user name
*/ */
protected String getDefaultUserName() protected String getDefaultUserName()
{ {
return AuthenticationUtil.getAdminUserName(); return AuthenticationUtil.getAdminUserName();
} }
/** /**
* {@inheritDoc #getTestServer(String)} * {@inheritDoc #getTestServer(String)}
*/ */
public static TestWebScriptServer getTestServer() public static TestWebScriptServer getTestServer()
{ {
return getTestServer(null); return getTestServer(null);
} }
/** /**
* Start up a context and get the server bean. * Start up a context and get the server bean.
* <p> * <p>
* This method will close and restart the application context only if the configuration has * This method will close and restart the application context only if the configuration has
* changed. * changed.
* *
* @param appendTestConfigLocation additional context file to include in the application context * @param appendTestConfigLocation additional context file to include in the application context
* @return Test Server * @return Test Server
*/ */
public static synchronized TestWebScriptServer getTestServer(String appendTestConfigLocation) public static synchronized TestWebScriptServer getTestServer(String appendTestConfigLocation)
{ {
if (TestWebScriptRepoServer.ctx != null) if (TestWebScriptRepoServer.ctx != null)
{ {
boolean configChanged = !EqualsHelper.nullSafeEquals( boolean configChanged = !EqualsHelper.nullSafeEquals(
appendTestConfigLocation, appendTestConfigLocation,
TestWebScriptRepoServer.appendedTestConfiguration); TestWebScriptRepoServer.appendedTestConfiguration);
if (configChanged) if (configChanged)
{ {
// The config changed, so close the context (it'll be restarted later) // The config changed, so close the context (it'll be restarted later)
try try
{ {
ctx.close(); ctx.close();
ctx = null; ctx = null;
} }
catch (Throwable e) catch (Throwable e)
{ {
throw new RuntimeException("Failed to shut down existing application context", e); throw new RuntimeException("Failed to shut down existing application context", e);
} }
} }
else else
{ {
// There is already a context with the required configuration // There is already a context with the required configuration
} }
} }
// Check if we need to start/restart the context // Check if we need to start/restart the context
if (TestWebScriptRepoServer.ctx == null) if (TestWebScriptRepoServer.ctx == null)
{ {
// Restart it // Restart it
final String[] configLocations; final String[] configLocations;
if (appendTestConfigLocation == null) if (appendTestConfigLocation == null)
{ {
configLocations = CONFIG_LOCATIONS; configLocations = CONFIG_LOCATIONS;
} }
else else
{ {
configLocations = new String[CONFIG_LOCATIONS.length+1]; configLocations = new String[CONFIG_LOCATIONS.length+1];
System.arraycopy(CONFIG_LOCATIONS, 0, configLocations, 0, CONFIG_LOCATIONS.length); System.arraycopy(CONFIG_LOCATIONS, 0, configLocations, 0, CONFIG_LOCATIONS.length);
configLocations[CONFIG_LOCATIONS.length] = appendTestConfigLocation; configLocations[CONFIG_LOCATIONS.length] = appendTestConfigLocation;
} }
TestWebScriptRepoServer.ctx = new ClassPathXmlApplicationContext(configLocations); TestWebScriptRepoServer.ctx = new ClassPathXmlApplicationContext(configLocations);
TestWebScriptRepoServer.appendedTestConfiguration = appendTestConfigLocation; TestWebScriptRepoServer.appendedTestConfiguration = appendTestConfigLocation;
} }
// Get the bean // Get the bean
TestWebScriptServer testServer = (org.alfresco.repo.web.scripts.TestWebScriptRepoServer)TestWebScriptRepoServer.ctx.getBean("webscripts.test"); TestWebScriptServer testServer = (org.alfresco.repo.web.scripts.TestWebScriptRepoServer)TestWebScriptRepoServer.ctx.getBean("webscripts.test");
return testServer; return testServer;
} }
/** /**
* Interpret a single command using the BufferedReader passed in for any data needed. * Interpret a single command using the BufferedReader passed in for any data needed.
* *
* @param line The unparsed command * @param line The unparsed command
* @return The textual output of the command. * @return The textual output of the command.
*/ */
@Override @Override
protected String interpretCommand(final String line) protected String interpretCommand(final String line)
throws IOException throws IOException
{ {
try try
{ {
if (username.startsWith("TICKET_")) if (username.startsWith("TICKET_"))
{ {
try try
{ {
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>() retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
{ {
public Object execute() throws Exception public Object execute() throws Exception
{ {
authenticationService.validate(username); authenticationService.validate(username);
return null; return null;
} }
}); });
return executeCommand(line); return executeCommand(line);
} }
finally finally
{ {
authenticationService.clearCurrentSecurityContext(); authenticationService.clearCurrentSecurityContext();
} }
} }
} }
catch(AuthenticationException e) catch(AuthenticationException e)
{ {
executeCommand("user " + getDefaultUserName()); executeCommand("user " + getDefaultUserName());
} }
// execute command in context of currently selected user // execute command in context of currently selected user
return AuthenticationUtil.runAs(new RunAsWork<String>() return AuthenticationUtil.runAs(new RunAsWork<String>()
{ {
@SuppressWarnings("synthetic-access") @SuppressWarnings("synthetic-access")
public String doWork() throws Exception public String doWork() throws Exception
{ {
return executeCommand(line); return executeCommand(line);
} }
}, username); }, username);
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,448 +21,448 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.hold; package org.alfresco.module.org_alfresco_module_rm.hold;
import static org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateQName; import static org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateQName;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.service.namespace.RegexQNamePattern;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Spy; import org.mockito.Spy;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
/** /**
* Hold service implementation unit test * Hold service implementation unit test
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.2 * @since 2.2
*/ */
public class HoldServiceImplUnitTest extends BaseUnitTest public class HoldServiceImplUnitTest extends BaseUnitTest
{ {
/** test values */ /** test values */
private static final String HOLD_NAME = "holdname"; private static final String HOLD_NAME = "holdname";
private static final String HOLD_REASON = "holdreason"; private static final String HOLD_REASON = "holdreason";
private static final String HOLD_DESCRIPTION = "holddescription"; private static final String HOLD_DESCRIPTION = "holddescription";
protected NodeRef holdContainer; protected NodeRef holdContainer;
protected NodeRef hold; protected NodeRef hold;
protected NodeRef hold2; protected NodeRef hold2;
@Spy @InjectMocks HoldServiceImpl holdService; @Spy @InjectMocks HoldServiceImpl holdService;
@Before @Before
@Override @Override
public void before() throws Exception public void before() throws Exception
{ {
super.before(); super.before();
// setup objects used in mock interactions // setup objects used in mock interactions
holdContainer = generateNodeRef(TYPE_HOLD_CONTAINER); holdContainer = generateNodeRef(TYPE_HOLD_CONTAINER);
hold = generateNodeRef(TYPE_HOLD); hold = generateNodeRef(TYPE_HOLD);
hold2 = generateNodeRef(TYPE_HOLD); hold2 = generateNodeRef(TYPE_HOLD);
// setup interactions // setup interactions
doReturn(holdContainer).when(mockedFilePlanService).getHoldContainer(filePlan); doReturn(holdContainer).when(mockedFilePlanService).getHoldContainer(filePlan);
} }
@Test @Test
public void isHold() public void isHold()
{ {
assertTrue(holdService.isHold(hold)); assertTrue(holdService.isHold(hold));
assertFalse(holdService.isHold(recordFolder)); assertFalse(holdService.isHold(recordFolder));
} }
@Test @Test
public void heldByMultipleResults() public void heldByMultipleResults()
{ {
// setup record folder in multiple holds // setup record folder in multiple holds
List<ChildAssociationRef> holds = new ArrayList<ChildAssociationRef>(2); List<ChildAssociationRef> holds = new ArrayList<ChildAssociationRef>(2);
holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold, ASSOC_FROZEN_RECORDS, recordFolder, true, 1)); holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold, ASSOC_FROZEN_RECORDS, recordFolder, true, 1));
holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold2, ASSOC_FROZEN_RECORDS, recordFolder, true, 2)); holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold2, ASSOC_FROZEN_RECORDS, recordFolder, true, 2));
doReturn(holds).when(mockedNodeService).getParentAssocs(recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); doReturn(holds).when(mockedNodeService).getParentAssocs(recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
// check that both holds are found for record folder // check that both holds are found for record folder
List<NodeRef> heldByHolds = holdService.heldBy(recordFolder, true); List<NodeRef> heldByHolds = holdService.heldBy(recordFolder, true);
assertNotNull(heldByHolds); assertNotNull(heldByHolds);
assertEquals(2, heldByHolds.size()); assertEquals(2, heldByHolds.size());
assertTrue(holdService.heldBy(recordFolder, false).isEmpty()); assertTrue(holdService.heldBy(recordFolder, false).isEmpty());
// check that both holds are found for record (even thou they are one level deep) // check that both holds are found for record (even thou they are one level deep)
heldByHolds = holdService.heldBy(record, true); heldByHolds = holdService.heldBy(record, true);
assertNotNull(heldByHolds); assertNotNull(heldByHolds);
assertEquals(2, heldByHolds.size()); assertEquals(2, heldByHolds.size());
assertTrue(holdService.heldBy(record, false).isEmpty()); assertTrue(holdService.heldBy(record, false).isEmpty());
} }
@Test (expected=AlfrescoRuntimeException.class) @Test (expected=AlfrescoRuntimeException.class)
public void getHold() public void getHold()
{ {
// setup node service interactions // setup node service interactions
when(mockedNodeService.getChildByName(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), anyString())).thenReturn(null) when(mockedNodeService.getChildByName(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), anyString())).thenReturn(null)
.thenReturn(hold) .thenReturn(hold)
.thenReturn(recordFolder); .thenReturn(recordFolder);
// no hold // no hold
NodeRef noHold = holdService.getHold(filePlan, "notAHold"); NodeRef noHold = holdService.getHold(filePlan, "notAHold");
assertNull(noHold); assertNull(noHold);
// found hold // found hold
NodeRef someHold = holdService.getHold(filePlan, "someHold"); NodeRef someHold = holdService.getHold(filePlan, "someHold");
assertNotNull(someHold); assertNotNull(someHold);
assertEquals(TYPE_HOLD, mockedNodeService.getType(someHold)); assertEquals(TYPE_HOLD, mockedNodeService.getType(someHold));
// ensure runtime exception is thrown // ensure runtime exception is thrown
holdService.getHold(filePlan, "notHold"); holdService.getHold(filePlan, "notHold");
} }
@Test (expected=RuntimeException.class) @Test (expected=RuntimeException.class)
public void getHeldNotAHold() public void getHeldNotAHold()
{ {
holdService.getHeld(recordFolder); holdService.getHeld(recordFolder);
} }
@Test @Test
public void getHeldNoResults() public void getHeldNoResults()
{ {
assertTrue(holdService.getHeld(hold).isEmpty()); assertTrue(holdService.getHeld(hold).isEmpty());
} }
@Test @Test
public void getHeldWithResults() public void getHeldWithResults()
{ {
// setup record folder in hold // setup record folder in hold
List<ChildAssociationRef> holds = new ArrayList<ChildAssociationRef>(1); List<ChildAssociationRef> holds = new ArrayList<ChildAssociationRef>(1);
holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold, ASSOC_FROZEN_RECORDS, recordFolder, true, 1)); holds.add(new ChildAssociationRef(ASSOC_FROZEN_RECORDS, hold, ASSOC_FROZEN_RECORDS, recordFolder, true, 1));
doReturn(holds).when(mockedNodeService).getChildAssocs(hold, ASSOC_FROZEN_RECORDS, RegexQNamePattern.MATCH_ALL); doReturn(holds).when(mockedNodeService).getChildAssocs(hold, ASSOC_FROZEN_RECORDS, RegexQNamePattern.MATCH_ALL);
List<NodeRef> list = holdService.getHeld(hold); List<NodeRef> list = holdService.getHeld(hold);
assertEquals(1, list.size()); assertEquals(1, list.size());
assertEquals(recordFolder, list.get(0)); assertEquals(recordFolder, list.get(0));
} }
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
public void createHold() public void createHold()
{ {
// setup node service interactions // setup node service interactions
when(mockedNodeService.createNode(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), any(QName.class) , eq(TYPE_HOLD), any(Map.class))) when(mockedNodeService.createNode(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), any(QName.class) , eq(TYPE_HOLD), any(Map.class)))
.thenReturn(new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, holdContainer, generateQName(), hold)); .thenReturn(new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, holdContainer, generateQName(), hold));
// create hold // create hold
NodeRef newHold = holdService.createHold(filePlan, HOLD_NAME, HOLD_REASON, HOLD_DESCRIPTION); NodeRef newHold = holdService.createHold(filePlan, HOLD_NAME, HOLD_REASON, HOLD_DESCRIPTION);
assertNotNull(newHold); assertNotNull(newHold);
assertEquals(TYPE_HOLD, mockedNodeService.getType(newHold)); assertEquals(TYPE_HOLD, mockedNodeService.getType(newHold));
assertEquals(hold, newHold); assertEquals(hold, newHold);
// check the node service interactions // check the node service interactions
ArgumentCaptor<Map> propertyMapCaptor = ArgumentCaptor.forClass(Map.class); ArgumentCaptor<Map> propertyMapCaptor = ArgumentCaptor.forClass(Map.class);
ArgumentCaptor<QName> assocNameCaptor = ArgumentCaptor.forClass(QName.class); ArgumentCaptor<QName> assocNameCaptor = ArgumentCaptor.forClass(QName.class);
verify(mockedNodeService).createNode(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), assocNameCaptor.capture() , eq(TYPE_HOLD), propertyMapCaptor.capture()); verify(mockedNodeService).createNode(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), assocNameCaptor.capture() , eq(TYPE_HOLD), propertyMapCaptor.capture());
// check property map // check property map
Map<QName, Serializable> propertyMap = (Map<QName, Serializable>)propertyMapCaptor.getValue(); Map<QName, Serializable> propertyMap = (Map<QName, Serializable>)propertyMapCaptor.getValue();
assertNotNull(propertyMap); assertNotNull(propertyMap);
assertEquals(3, propertyMap.size()); assertEquals(3, propertyMap.size());
assertTrue(propertyMap.containsKey(ContentModel.PROP_NAME)); assertTrue(propertyMap.containsKey(ContentModel.PROP_NAME));
assertEquals(HOLD_NAME, propertyMap.get(ContentModel.PROP_NAME)); assertEquals(HOLD_NAME, propertyMap.get(ContentModel.PROP_NAME));
assertTrue(propertyMap.containsKey(ContentModel.PROP_DESCRIPTION)); assertTrue(propertyMap.containsKey(ContentModel.PROP_DESCRIPTION));
assertEquals(HOLD_DESCRIPTION, propertyMap.get(ContentModel.PROP_DESCRIPTION)); assertEquals(HOLD_DESCRIPTION, propertyMap.get(ContentModel.PROP_DESCRIPTION));
assertTrue(propertyMap.containsKey(PROP_HOLD_REASON)); assertTrue(propertyMap.containsKey(PROP_HOLD_REASON));
assertEquals(HOLD_REASON, propertyMap.get(PROP_HOLD_REASON)); assertEquals(HOLD_REASON, propertyMap.get(PROP_HOLD_REASON));
// check assoc name // check assoc name
assertNotNull(assocNameCaptor.getValue()); assertNotNull(assocNameCaptor.getValue());
assertEquals(NamespaceService.CONTENT_MODEL_1_0_URI, assocNameCaptor.getValue().getNamespaceURI()); assertEquals(NamespaceService.CONTENT_MODEL_1_0_URI, assocNameCaptor.getValue().getNamespaceURI());
assertEquals(HOLD_NAME, assocNameCaptor.getValue().getLocalName()); assertEquals(HOLD_NAME, assocNameCaptor.getValue().getLocalName());
} }
@Test @Test
public void getHoldReason() public void getHoldReason()
{ {
// setup node service interactions // setup node service interactions
when(mockedNodeService.exists(hold)) when(mockedNodeService.exists(hold))
.thenReturn(false) .thenReturn(false)
.thenReturn(true) .thenReturn(true)
.thenReturn(true) .thenReturn(true)
.thenReturn(true); .thenReturn(true);
when(mockedNodeService.getProperty(eq(hold), eq(PROP_HOLD_REASON))) when(mockedNodeService.getProperty(eq(hold), eq(PROP_HOLD_REASON)))
.thenReturn(null) .thenReturn(null)
.thenReturn(HOLD_REASON); .thenReturn(HOLD_REASON);
// node does not exist // node does not exist
assertNull(holdService.getHoldReason(hold)); assertNull(holdService.getHoldReason(hold));
// node isn't a hold // node isn't a hold
assertNull(holdService.getHoldReason(recordFolder)); assertNull(holdService.getHoldReason(recordFolder));
// hold reason isn't set // hold reason isn't set
assertNull(holdService.getHoldReason(hold)); assertNull(holdService.getHoldReason(hold));
// hold reason set // hold reason set
assertEquals(HOLD_REASON, holdService.getHoldReason(hold)); assertEquals(HOLD_REASON, holdService.getHoldReason(hold));
} }
@Test @Test
public void setHoldReason() public void setHoldReason()
{ {
// setup node service interactions // setup node service interactions
when(mockedNodeService.exists(hold)) when(mockedNodeService.exists(hold))
.thenReturn(false) .thenReturn(false)
.thenReturn(true) .thenReturn(true)
.thenReturn(true); .thenReturn(true);
// node does not exist // node does not exist
holdService.setHoldReason(hold, HOLD_REASON); holdService.setHoldReason(hold, HOLD_REASON);
verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON); verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON);
// node isn't a hold // node isn't a hold
holdService.setHoldReason(recordFolder, HOLD_REASON); holdService.setHoldReason(recordFolder, HOLD_REASON);
verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON); verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON);
// set hold reason // set hold reason
holdService.setHoldReason(hold, HOLD_REASON); holdService.setHoldReason(hold, HOLD_REASON);
verify(mockedNodeService).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON); verify(mockedNodeService).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON);
} }
@Test (expected=AlfrescoRuntimeException.class) @Test (expected=AlfrescoRuntimeException.class)
public void deleteHoldNotAHold() public void deleteHoldNotAHold()
{ {
holdService.deleteHold(recordFolder); holdService.deleteHold(recordFolder);
verify(mockedNodeService, never()).deleteNode(hold); verify(mockedNodeService, never()).deleteNode(hold);
} }
@Test @Test
public void deleteHold() public void deleteHold()
{ {
// delete hold // delete hold
holdService.deleteHold(hold); holdService.deleteHold(hold);
verify(mockedNodeService).deleteNode(hold); verify(mockedNodeService).deleteNode(hold);
// TODO check interactions with policy component!!! // TODO check interactions with policy component!!!
} }
@Test (expected=AlfrescoRuntimeException.class) @Test (expected=AlfrescoRuntimeException.class)
public void addToHoldNotAHold() public void addToHoldNotAHold()
{ {
holdService.addToHold(recordFolder, recordFolder); holdService.addToHold(recordFolder, recordFolder);
} }
@Test (expected=AlfrescoRuntimeException.class) @Test (expected=AlfrescoRuntimeException.class)
public void addToHoldNotARecordFolderOrRecord() public void addToHoldNotARecordFolderOrRecord()
{ {
NodeRef anotherThing = generateNodeRef(TYPE_RECORD_CATEGORY); NodeRef anotherThing = generateNodeRef(TYPE_RECORD_CATEGORY);
holdService.addToHold(hold, anotherThing); holdService.addToHold(hold, anotherThing);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void addToHoldNotInHold() public void addToHoldNotInHold()
{ {
holdService.addToHold(hold, recordFolder); holdService.addToHold(hold, recordFolder);
verify(mockedNodeService).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); verify(mockedNodeService).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
verify(mockedNodeService).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); verify(mockedNodeService).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class));
verify(mockedNodeService).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); verify(mockedNodeService).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class));
verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString()); verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString());
holdService.addToHold(hold, record); holdService.addToHold(hold, record);
verify(mockedNodeService).addChild(hold, record, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); verify(mockedNodeService).addChild(hold, record, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
verify(mockedNodeService).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); verify(mockedNodeService).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class));
verify(mockedNodeService, times(2)).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); verify(mockedNodeService, times(2)).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class));
verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(record), anyString()); verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(record), anyString());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void addToHoldAlreadyInHold() public void addToHoldAlreadyInHold()
{ {
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
holdService.addToHold(hold, recordFolder); holdService.addToHold(hold, recordFolder);
verify(mockedNodeService, never()).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); verify(mockedNodeService, never()).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
verify(mockedNodeService, never()).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); verify(mockedNodeService, never()).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class));
verify(mockedNodeService, never()).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); verify(mockedNodeService, never()).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class));
verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString()); verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void addToHoldAldeadyFrozen() public void addToHoldAldeadyFrozen()
{ {
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
holdService.addToHold(hold, recordFolder); holdService.addToHold(hold, recordFolder);
verify(mockedNodeService, times(1)).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); verify(mockedNodeService, times(1)).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
verify(mockedNodeService, never()).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); verify(mockedNodeService, never()).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class));
verify(mockedNodeService, never()).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); verify(mockedNodeService, never()).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class));
verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString()); verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void addToHolds() public void addToHolds()
{ {
// ensure the interaction indicates that a node has the frozen aspect applied if it has // ensure the interaction indicates that a node has the frozen aspect applied if it has
doAnswer(new Answer<Void>() doAnswer(new Answer<Void>()
{ {
public Void answer(InvocationOnMock invocation) public Void answer(InvocationOnMock invocation)
{ {
NodeRef nodeRef = (NodeRef)invocation.getArguments()[0]; NodeRef nodeRef = (NodeRef)invocation.getArguments()[0];
doReturn(true).when(mockedNodeService).hasAspect(nodeRef, ASPECT_FROZEN); doReturn(true).when(mockedNodeService).hasAspect(nodeRef, ASPECT_FROZEN);
return null; return null;
} }
}).when(mockedNodeService).addAspect(any(NodeRef.class), eq(ASPECT_FROZEN), any(Map.class)); }).when(mockedNodeService).addAspect(any(NodeRef.class), eq(ASPECT_FROZEN), any(Map.class));
// build a list of holds // build a list of holds
List<NodeRef> holds = new ArrayList<NodeRef>(2); List<NodeRef> holds = new ArrayList<NodeRef>(2);
holds.add(hold); holds.add(hold);
holds.add(hold2); holds.add(hold2);
// add the record folder to both holds // add the record folder to both holds
holdService.addToHolds(holds, recordFolder); holdService.addToHolds(holds, recordFolder);
// verify the interactions // verify the interactions
verify(mockedNodeService, times(1)).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); verify(mockedNodeService, times(1)).addChild(hold, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
verify(mockedNodeService, times(1)).addChild(hold2, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS); verify(mockedNodeService, times(1)).addChild(hold2, recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
verify(mockedNodeService, times(1)).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class)); verify(mockedNodeService, times(1)).addAspect(eq(recordFolder), eq(ASPECT_FROZEN), any(Map.class));
verify(mockedNodeService, times(1)).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class)); verify(mockedNodeService, times(1)).addAspect(eq(record), eq(ASPECT_FROZEN), any(Map.class));
verify(mockedRecordsManagementAuditService, times(2)).auditEvent(eq(recordFolder), anyString()); verify(mockedRecordsManagementAuditService, times(2)).auditEvent(eq(recordFolder), anyString());
} }
@Test (expected=AlfrescoRuntimeException.class) @Test (expected=AlfrescoRuntimeException.class)
public void removeFromHoldNotAHold() public void removeFromHoldNotAHold()
{ {
holdService.removeFromHold(recordFolder, recordFolder); holdService.removeFromHold(recordFolder, recordFolder);
} }
@Test @Test
public void removeFromHoldNotInHold() public void removeFromHoldNotInHold()
{ {
holdService.removeFromHold(hold, recordFolder); holdService.removeFromHold(hold, recordFolder);
verify(mockedNodeService, never()).removeChild(hold, recordFolder); verify(mockedNodeService, never()).removeChild(hold, recordFolder);
verify(mockedNodeService, never()).removeAspect(recordFolder, ASPECT_FROZEN); verify(mockedNodeService, never()).removeAspect(recordFolder, ASPECT_FROZEN);
verify(mockedNodeService, never()).removeAspect(record, ASPECT_FROZEN); verify(mockedNodeService, never()).removeAspect(record, ASPECT_FROZEN);
verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString()); verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString());
} }
@Test @Test
public void removeFromHold() public void removeFromHold()
{ {
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
holdService.removeFromHold(hold, recordFolder); holdService.removeFromHold(hold, recordFolder);
verify(mockedNodeService, times(1)).removeChild(hold, recordFolder); verify(mockedNodeService, times(1)).removeChild(hold, recordFolder);
verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN); verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN);
verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN); verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN);
verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString()); verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString());
} }
@Test @Test
public void removeFromHolds() public void removeFromHolds()
{ {
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2); doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2);
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
// build a list of holds // build a list of holds
List<NodeRef> holds = new ArrayList<NodeRef>(2); List<NodeRef> holds = new ArrayList<NodeRef>(2);
holds.add(hold); holds.add(hold);
holds.add(hold2); holds.add(hold2);
holdService.removeFromHolds(holds, recordFolder); holdService.removeFromHolds(holds, recordFolder);
verify(mockedNodeService, times(1)).removeChild(hold, recordFolder); verify(mockedNodeService, times(1)).removeChild(hold, recordFolder);
verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder); verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder);
verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN); verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN);
verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN); verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN);
verify(mockedRecordsManagementAuditService, times(2)).auditEvent(any(NodeRef.class), anyString()); verify(mockedRecordsManagementAuditService, times(2)).auditEvent(any(NodeRef.class), anyString());
} }
@Test @Test
public void removeFromAllHolds() public void removeFromAllHolds()
{ {
// build a list of holds // build a list of holds
List<NodeRef> holds = new ArrayList<NodeRef>(2); List<NodeRef> holds = new ArrayList<NodeRef>(2);
holds.add(hold); holds.add(hold);
holds.add(hold2); holds.add(hold2);
doAnswer(new Answer<Void>() doAnswer(new Answer<Void>()
{ {
public Void answer(InvocationOnMock invocation) public Void answer(InvocationOnMock invocation)
{ {
doReturn(Collections.singletonList(hold2)).when(holdService).heldBy(recordFolder, true); doReturn(Collections.singletonList(hold2)).when(holdService).heldBy(recordFolder, true);
return null; return null;
} }
}).when(mockedNodeService).removeChild(hold, recordFolder); }).when(mockedNodeService).removeChild(hold, recordFolder);
doAnswer(new Answer<Void>() doAnswer(new Answer<Void>()
{ {
public Void answer(InvocationOnMock invocation) public Void answer(InvocationOnMock invocation)
{ {
doReturn(new ArrayList<NodeRef>()).when(holdService).heldBy(recordFolder, true); doReturn(new ArrayList<NodeRef>()).when(holdService).heldBy(recordFolder, true);
return null; return null;
} }
}).when(mockedNodeService).removeChild(hold2, recordFolder); }).when(mockedNodeService).removeChild(hold2, recordFolder);
// define interactions // define interactions
doReturn(holds).when(holdService).heldBy(recordFolder, true); doReturn(holds).when(holdService).heldBy(recordFolder, true);
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold); doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2); doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2);
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN); doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN); doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
// remove record folder from all holds // remove record folder from all holds
holdService.removeFromAllHolds(recordFolder); holdService.removeFromAllHolds(recordFolder);
// verify interactions // verify interactions
verify(mockedNodeService, times(1)).removeChild(hold, recordFolder); verify(mockedNodeService, times(1)).removeChild(hold, recordFolder);
verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder); verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder);
verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN); verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN);
verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN); verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN);
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* *
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -21,84 +21,84 @@
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.model.compatibility; package org.alfresco.module.org_alfresco_module_rm.model.compatibility;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.verifyZeroInteractions;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.junit.Test; import org.junit.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
/** /**
* Dictionary bootstrap post processor unit test. * Dictionary bootstrap post processor unit test.
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.2 * @since 2.2
*/ */
public class DictionaryBootstrapPostProcessorUnitTest extends BaseUnitTest public class DictionaryBootstrapPostProcessorUnitTest extends BaseUnitTest
{ {
/** bean id's */ /** bean id's */
private static final String BEAN_SITESERVICE_BOOTSTRAP = "siteService_dictionaryBootstrap"; private static final String BEAN_SITESERVICE_BOOTSTRAP = "siteService_dictionaryBootstrap";
private static final String BEAN_RM_DICTIONARY_BOOTSTRAP = "org_alfresco_module_rm_dictionaryBootstrap"; private static final String BEAN_RM_DICTIONARY_BOOTSTRAP = "org_alfresco_module_rm_dictionaryBootstrap";
@Mock private ConfigurableListableBeanFactory mockedBeanFactory; @Mock private ConfigurableListableBeanFactory mockedBeanFactory;
@Mock private BeanDefinition mockedBeanDefinition; @Mock private BeanDefinition mockedBeanDefinition;
@InjectMocks private DictionaryBootstrapPostProcessor postProcessor; @InjectMocks private DictionaryBootstrapPostProcessor postProcessor;
/** /**
* given the bean factory does not contain the site service bootstrap bean then ensure that it is * given the bean factory does not contain the site service bootstrap bean then ensure that it is
* not added as a dependency * not added as a dependency
*/ */
@Test @Test
public void noSiteServiceBootstrapBeanAvailable() public void noSiteServiceBootstrapBeanAvailable()
{ {
// === given ==== // === given ====
doReturn(false).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP); doReturn(false).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
// === when === // === when ===
postProcessor.postProcessBeanFactory(mockedBeanFactory); postProcessor.postProcessBeanFactory(mockedBeanFactory);
// === then === // === then ===
verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP); verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
verifyNoMoreInteractions(mockedBeanFactory); verifyNoMoreInteractions(mockedBeanFactory);
verifyZeroInteractions(mockedBeanDefinition); verifyZeroInteractions(mockedBeanDefinition);
} }
/** /**
* given that the site service bootstrap bean is contained within the bean factory, ensure that * given that the site service bootstrap bean is contained within the bean factory, ensure that
* it is added as a dependency * it is added as a dependency
*/ */
@Test @Test
public void siteServiceBootstrapBeanAvailable() public void siteServiceBootstrapBeanAvailable()
{ {
// === given ==== // === given ====
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP); doReturn(true).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP); doReturn(true).when(mockedBeanFactory).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP);
doReturn(mockedBeanDefinition).when(mockedBeanFactory).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP); doReturn(mockedBeanDefinition).when(mockedBeanFactory).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP);
// === when === // === when ===
postProcessor.postProcessBeanFactory(mockedBeanFactory); postProcessor.postProcessBeanFactory(mockedBeanFactory);
// === then === // === then ===
verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP); verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
verify(mockedBeanFactory, times(1)).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP); verify(mockedBeanFactory, times(1)).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP);
verify(mockedBeanFactory, times(1)).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP); verify(mockedBeanFactory, times(1)).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP);
verify(mockedBeanDefinition, times(1)).setDependsOn(new String[]{BEAN_SITESERVICE_BOOTSTRAP}); verify(mockedBeanDefinition, times(1)).setDependsOn(new String[]{BEAN_SITESERVICE_BOOTSTRAP});
verifyNoMoreInteractions(mockedBeanFactory, mockedBeanDefinition); verifyNoMoreInteractions(mockedBeanFactory, mockedBeanDefinition);
} }
} }