mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-3132 (Update license headers)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
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.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Integration test for RM-1887
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.3
|
||||
*/
|
||||
public class RM1887Test extends BaseRMTestCase
|
||||
{
|
||||
@Override
|
||||
protected boolean isRecordTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a record is unfiled
|
||||
* And an unfiled folder has been created
|
||||
* When I move the unfiled record into the unfiled folder
|
||||
* Then the filed date of the unfiled record remains unset
|
||||
*/
|
||||
public void testMoveUnfiledRecord() throws Exception
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private NodeRef unfiledRecordFolder;
|
||||
private NodeRef unfiledRecord;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create unfiled folder
|
||||
unfiledRecordFolder = fileFolderService.create(filePlanService.getUnfiledContainer(filePlan), "my test folder", TYPE_UNFILED_RECORD_FOLDER).getNodeRef();
|
||||
|
||||
// crate unfiled record
|
||||
unfiledRecord = recordService.createRecordFromContent(filePlan, "test.txt", TYPE_CONTENT, null, null);
|
||||
|
||||
// check the record
|
||||
assertTrue(recordService.isRecord(unfiledRecord));
|
||||
assertFalse(recordService.isFiled(unfiledRecord));
|
||||
}
|
||||
|
||||
public void when() throws Exception
|
||||
{
|
||||
// move the record into the unfiled folder
|
||||
fileFolderService.move(unfiledRecord, unfiledRecordFolder, null);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// check the record
|
||||
assertTrue(recordService.isRecord(unfiledRecord));
|
||||
assertFalse(recordService.isFiled(unfiledRecord));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
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.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Integration test for RM-1887
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.3
|
||||
*/
|
||||
public class RM1887Test extends BaseRMTestCase
|
||||
{
|
||||
@Override
|
||||
protected boolean isRecordTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a record is unfiled
|
||||
* And an unfiled folder has been created
|
||||
* When I move the unfiled record into the unfiled folder
|
||||
* Then the filed date of the unfiled record remains unset
|
||||
*/
|
||||
public void testMoveUnfiledRecord() throws Exception
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private NodeRef unfiledRecordFolder;
|
||||
private NodeRef unfiledRecord;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create unfiled folder
|
||||
unfiledRecordFolder = fileFolderService.create(filePlanService.getUnfiledContainer(filePlan), "my test folder", TYPE_UNFILED_RECORD_FOLDER).getNodeRef();
|
||||
|
||||
// crate unfiled record
|
||||
unfiledRecord = recordService.createRecordFromContent(filePlan, "test.txt", TYPE_CONTENT, null, null);
|
||||
|
||||
// check the record
|
||||
assertTrue(recordService.isRecord(unfiledRecord));
|
||||
assertFalse(recordService.isFiled(unfiledRecord));
|
||||
}
|
||||
|
||||
public void when() throws Exception
|
||||
{
|
||||
// move the record into the unfiled folder
|
||||
fileFolderService.move(unfiledRecord, unfiledRecordFolder, null);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// check the record
|
||||
assertTrue(recordService.isRecord(unfiledRecord));
|
||||
assertFalse(recordService.isFiled(unfiledRecord));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
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.impl.FileToAction;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.rule.Rule;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.service.cmr.rule.RuleType;
|
||||
|
||||
/**
|
||||
* System test for RM-2072: Concurrency exceptions and deadlocks on Records Management "File to" rule
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2.1.1
|
||||
*/
|
||||
public class RM2072Test extends BaseRMTestCase
|
||||
{
|
||||
private static final int NUMBER_OF_BATCHES = 1;
|
||||
private static final int NUMBER_IN_BATCH = 500;
|
||||
|
||||
private RuleService ruleService;
|
||||
private NodeRef ruleFolder;
|
||||
|
||||
@Override
|
||||
protected void initServices()
|
||||
{
|
||||
super.initServices();
|
||||
|
||||
ruleService = (RuleService)applicationContext.getBean("RuleService");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCollaborationSiteTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRecordTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* When I add lots of documents in the same transaction
|
||||
* Then the rules should fire
|
||||
* And the documents should be filed in the new record folder
|
||||
*/
|
||||
public void testAutoDeclareAutoFileCreateRecordFolderOnly() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
// create the folder
|
||||
ruleFolder = fileFolderService.create(documentLibrary, "mytestfolder", ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
|
||||
// create record category
|
||||
NodeRef nodeRefA = filePlanService.createRecordCategory(filePlan, "A");
|
||||
NodeRef nodeRefB = filePlanService.createRecordCategory(nodeRefA, "B");
|
||||
filePlanService.createRecordCategory(nodeRefB, "C");
|
||||
|
||||
Action action = actionService.createAction(CreateRecordAction.NAME);
|
||||
action.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan);
|
||||
|
||||
Rule rule = new Rule();
|
||||
rule.setRuleType(RuleType.INBOUND);
|
||||
rule.setTitle("my rule");
|
||||
rule.setAction(action);
|
||||
rule.setExecuteAsynchronously(true);
|
||||
ruleService.saveRule(ruleFolder, rule);
|
||||
|
||||
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_CREATE_RECORD_PATH, true);
|
||||
|
||||
Rule fileRule = new Rule();
|
||||
fileRule.setRuleType(RuleType.INBOUND);
|
||||
fileRule.setTitle("my rule");
|
||||
fileRule.setAction(fileAction);
|
||||
fileRule.setExecuteAsynchronously(true);
|
||||
ruleService.saveRule(filePlanService.getUnfiledContainer(filePlan), fileRule);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test(Void result) throws Exception
|
||||
{
|
||||
assertFalse(ruleService.getRules(ruleFolder).isEmpty());
|
||||
}
|
||||
});
|
||||
|
||||
List<NodeRef> records = new ArrayList<NodeRef>(NUMBER_OF_BATCHES*NUMBER_IN_BATCH);
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_BATCHES; i++)
|
||||
{
|
||||
final int finali = i;
|
||||
records.addAll(doTestInTransaction(new Test<List<NodeRef>>()
|
||||
{
|
||||
@Override
|
||||
public List<NodeRef> run() throws Exception
|
||||
{
|
||||
List<NodeRef> records = new ArrayList<NodeRef>(NUMBER_IN_BATCH);
|
||||
for (int j = 0; j < NUMBER_IN_BATCH; j++)
|
||||
{
|
||||
int count = (finali+1)*(j+1);
|
||||
String name = "content" + count + ".txt";
|
||||
System.out.println(name + " - creating");
|
||||
|
||||
NodeRef record = fileFolderService.create(ruleFolder, name, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
records.add(record);
|
||||
}
|
||||
return records;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
while(!records.isEmpty())
|
||||
{
|
||||
Thread.sleep(1000);
|
||||
|
||||
final Iterator<NodeRef> temp = records.iterator();
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
while (temp.hasNext())
|
||||
{
|
||||
NodeRef record = temp.next();
|
||||
if (nodeService.hasAspect(record, ASPECT_RECORD) && recordService.isFiled(record))
|
||||
{
|
||||
String name = (String) nodeService.getProperty(record, ContentModel.PROP_NAME);
|
||||
System.out.println(name + " - complete");
|
||||
temp.remove();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
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.impl.FileToAction;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.rule.Rule;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.service.cmr.rule.RuleType;
|
||||
|
||||
/**
|
||||
* System test for RM-2072: Concurrency exceptions and deadlocks on Records Management "File to" rule
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2.1.1
|
||||
*/
|
||||
public class RM2072Test extends BaseRMTestCase
|
||||
{
|
||||
private static final int NUMBER_OF_BATCHES = 1;
|
||||
private static final int NUMBER_IN_BATCH = 500;
|
||||
|
||||
private RuleService ruleService;
|
||||
private NodeRef ruleFolder;
|
||||
|
||||
@Override
|
||||
protected void initServices()
|
||||
{
|
||||
super.initServices();
|
||||
|
||||
ruleService = (RuleService)applicationContext.getBean("RuleService");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCollaborationSiteTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRecordTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* When I add lots of documents in the same transaction
|
||||
* Then the rules should fire
|
||||
* And the documents should be filed in the new record folder
|
||||
*/
|
||||
public void testAutoDeclareAutoFileCreateRecordFolderOnly() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
// create the folder
|
||||
ruleFolder = fileFolderService.create(documentLibrary, "mytestfolder", ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
|
||||
// create record category
|
||||
NodeRef nodeRefA = filePlanService.createRecordCategory(filePlan, "A");
|
||||
NodeRef nodeRefB = filePlanService.createRecordCategory(nodeRefA, "B");
|
||||
filePlanService.createRecordCategory(nodeRefB, "C");
|
||||
|
||||
Action action = actionService.createAction(CreateRecordAction.NAME);
|
||||
action.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan);
|
||||
|
||||
Rule rule = new Rule();
|
||||
rule.setRuleType(RuleType.INBOUND);
|
||||
rule.setTitle("my rule");
|
||||
rule.setAction(action);
|
||||
rule.setExecuteAsynchronously(true);
|
||||
ruleService.saveRule(ruleFolder, rule);
|
||||
|
||||
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_CREATE_RECORD_PATH, true);
|
||||
|
||||
Rule fileRule = new Rule();
|
||||
fileRule.setRuleType(RuleType.INBOUND);
|
||||
fileRule.setTitle("my rule");
|
||||
fileRule.setAction(fileAction);
|
||||
fileRule.setExecuteAsynchronously(true);
|
||||
ruleService.saveRule(filePlanService.getUnfiledContainer(filePlan), fileRule);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test(Void result) throws Exception
|
||||
{
|
||||
assertFalse(ruleService.getRules(ruleFolder).isEmpty());
|
||||
}
|
||||
});
|
||||
|
||||
List<NodeRef> records = new ArrayList<NodeRef>(NUMBER_OF_BATCHES*NUMBER_IN_BATCH);
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_BATCHES; i++)
|
||||
{
|
||||
final int finali = i;
|
||||
records.addAll(doTestInTransaction(new Test<List<NodeRef>>()
|
||||
{
|
||||
@Override
|
||||
public List<NodeRef> run() throws Exception
|
||||
{
|
||||
List<NodeRef> records = new ArrayList<NodeRef>(NUMBER_IN_BATCH);
|
||||
for (int j = 0; j < NUMBER_IN_BATCH; j++)
|
||||
{
|
||||
int count = (finali+1)*(j+1);
|
||||
String name = "content" + count + ".txt";
|
||||
System.out.println(name + " - creating");
|
||||
|
||||
NodeRef record = fileFolderService.create(ruleFolder, name, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
records.add(record);
|
||||
}
|
||||
return records;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
while(!records.isEmpty())
|
||||
{
|
||||
Thread.sleep(1000);
|
||||
|
||||
final Iterator<NodeRef> temp = records.iterator();
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
while (temp.hasNext())
|
||||
{
|
||||
NodeRef record = temp.next();
|
||||
if (nodeService.hasAspect(record, ASPECT_RECORD) && recordService.isFiled(record))
|
||||
{
|
||||
String name = (String) nodeService.getProperty(record, ContentModel.PROP_NAME);
|
||||
System.out.println(name + " - complete");
|
||||
temp.remove();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
|
||||
|
||||
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.TestService;
|
||||
|
||||
/**
|
||||
* System test for RM-452
|
||||
*
|
||||
* See alfresco.extension.rm-method-security.properties
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class RM452Test extends BaseRMTestCase
|
||||
{
|
||||
private TestService testService;
|
||||
|
||||
@Override
|
||||
protected void initServices()
|
||||
{
|
||||
super.initServices();
|
||||
|
||||
testService = (TestService)applicationContext.getBean("TestService");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCollaborationSiteTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRecordTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void testRM452() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertNotNull(folder);
|
||||
assertNotNull(recordOne);
|
||||
assertFalse(filePlanService.isFilePlanComponent(folder));
|
||||
assertTrue(filePlanService.isFilePlanComponent(recordOne));
|
||||
|
||||
// call methodOne with non-RM artifact .. expect success
|
||||
testService.testMethodOne(folder);
|
||||
|
||||
// call methodTwo with non-RM artifact .. expect success
|
||||
testService.testMethodTwo(folder);
|
||||
|
||||
// call methodOne with an RM artifact .. expect success
|
||||
testService.testMethodOne(recordOne);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
doTestInTransaction(new FailureTest
|
||||
(
|
||||
"Shouldn't be able to call testMethodTwo on TestService, because override RM security for method is not configred.",
|
||||
AlfrescoRuntimeException.class
|
||||
)
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run() throws Exception
|
||||
{
|
||||
// call methodTwo with an RM artifact .. expect failure
|
||||
testService.testMethodTwo(recordOne);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
|
||||
|
||||
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.TestService;
|
||||
|
||||
/**
|
||||
* System test for RM-452
|
||||
*
|
||||
* See alfresco.extension.rm-method-security.properties
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class RM452Test extends BaseRMTestCase
|
||||
{
|
||||
private TestService testService;
|
||||
|
||||
@Override
|
||||
protected void initServices()
|
||||
{
|
||||
super.initServices();
|
||||
|
||||
testService = (TestService)applicationContext.getBean("TestService");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCollaborationSiteTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRecordTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void testRM452() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertNotNull(folder);
|
||||
assertNotNull(recordOne);
|
||||
assertFalse(filePlanService.isFilePlanComponent(folder));
|
||||
assertTrue(filePlanService.isFilePlanComponent(recordOne));
|
||||
|
||||
// call methodOne with non-RM artifact .. expect success
|
||||
testService.testMethodOne(folder);
|
||||
|
||||
// call methodTwo with non-RM artifact .. expect success
|
||||
testService.testMethodTwo(folder);
|
||||
|
||||
// call methodOne with an RM artifact .. expect success
|
||||
testService.testMethodOne(recordOne);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
doTestInTransaction(new FailureTest
|
||||
(
|
||||
"Shouldn't be able to call testMethodTwo on TestService, because override RM security for method is not configred.",
|
||||
AlfrescoRuntimeException.class
|
||||
)
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run() throws Exception
|
||||
{
|
||||
// call methodTwo with an RM artifact .. expect failure
|
||||
testService.testMethodTwo(recordOne);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.site.SiteRole;
|
||||
|
||||
/**
|
||||
* Unit test for RM-804 .. site managers are able to delete file plans
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class RM804Test extends BaseRMTestCase
|
||||
{
|
||||
@Override
|
||||
protected void initServices()
|
||||
{
|
||||
super.initServices();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCollaborationSiteTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isUserTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void testUsersHaveDeletePermissionsOnFilePlan() throws Exception
|
||||
{
|
||||
// as rmuser
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, ADMIN_USER);
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, ADMIN_USER);
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, ADMIN_USER);
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, rmUserName);
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, userName);
|
||||
}
|
||||
|
||||
public void testTryAndDeleteSiteAsSiteManagerOnly()
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
siteService.setMembership(siteId, userName, SiteRole.SiteManager.toString());
|
||||
|
||||
return null;
|
||||
}
|
||||
}, "admin");
|
||||
|
||||
doTestInTransaction(new FailureTest
|
||||
(
|
||||
"Should not be able to delete site as a site manager only.",
|
||||
AlfrescoRuntimeException.class
|
||||
)
|
||||
{
|
||||
@Override
|
||||
public void run() throws Exception
|
||||
{
|
||||
siteService.deleteSite(siteId);
|
||||
|
||||
}
|
||||
}, userName);
|
||||
|
||||
// give the user a RM role (but not sufficient to delete the file plan node ref)
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_USER, userName);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, "admin");
|
||||
|
||||
doTestInTransaction(new FailureTest
|
||||
(
|
||||
"Should not be able to delete site as a site manager with an RM role that doesn't have the capability.",
|
||||
AlfrescoRuntimeException.class
|
||||
)
|
||||
{
|
||||
@Override
|
||||
public void run() throws Exception
|
||||
{
|
||||
siteService.deleteSite(siteId);
|
||||
|
||||
}
|
||||
}, userName);
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_ADMIN, userName);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, "admin");
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
siteService.deleteSite(siteId);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, userName);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.site.SiteRole;
|
||||
|
||||
/**
|
||||
* Unit test for RM-804 .. site managers are able to delete file plans
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class RM804Test extends BaseRMTestCase
|
||||
{
|
||||
@Override
|
||||
protected void initServices()
|
||||
{
|
||||
super.initServices();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCollaborationSiteTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isUserTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void testUsersHaveDeletePermissionsOnFilePlan() throws Exception
|
||||
{
|
||||
// as rmuser
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, ADMIN_USER);
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, ADMIN_USER);
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertEquals(AccessStatus.ALLOWED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, ADMIN_USER);
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, rmUserName);
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertEquals(AccessStatus.DENIED, capabilityService.getCapabilityAccessState(filePlan, "Delete"));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, userName);
|
||||
}
|
||||
|
||||
public void testTryAndDeleteSiteAsSiteManagerOnly()
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
siteService.setMembership(siteId, userName, SiteRole.SiteManager.toString());
|
||||
|
||||
return null;
|
||||
}
|
||||
}, "admin");
|
||||
|
||||
doTestInTransaction(new FailureTest
|
||||
(
|
||||
"Should not be able to delete site as a site manager only.",
|
||||
AlfrescoRuntimeException.class
|
||||
)
|
||||
{
|
||||
@Override
|
||||
public void run() throws Exception
|
||||
{
|
||||
siteService.deleteSite(siteId);
|
||||
|
||||
}
|
||||
}, userName);
|
||||
|
||||
// give the user a RM role (but not sufficient to delete the file plan node ref)
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_USER, userName);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, "admin");
|
||||
|
||||
doTestInTransaction(new FailureTest
|
||||
(
|
||||
"Should not be able to delete site as a site manager with an RM role that doesn't have the capability.",
|
||||
AlfrescoRuntimeException.class
|
||||
)
|
||||
{
|
||||
@Override
|
||||
public void run() throws Exception
|
||||
{
|
||||
siteService.deleteSite(siteId);
|
||||
|
||||
}
|
||||
}, userName);
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_ADMIN, userName);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, "admin");
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
siteService.deleteSite(siteId);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, userName);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
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.vital.VitalRecordDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.Period;
|
||||
|
||||
/**
|
||||
* System test for RM-994
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class RM994Test extends BaseRMTestCase
|
||||
{
|
||||
@Override
|
||||
protected void initServices()
|
||||
{
|
||||
super.initServices();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCollaborationSiteTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRecordTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void testRM944() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
checkVitalRecordNotSet(rmContainer);
|
||||
checkVitalRecordNotSet(rmFolder);
|
||||
checkVitalRecordNotSet(recordOne);
|
||||
assertNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF));
|
||||
|
||||
vitalRecordService.setVitalRecordDefintion(rmContainer, true, new Period("month|1"));
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
checkVitalRecordSet(rmContainer);
|
||||
checkVitalRecordSet(rmFolder);
|
||||
checkVitalRecordSet(recordOne);
|
||||
assertNotNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF));
|
||||
|
||||
recordService.createRecord(filePlan, dmDocument, true);
|
||||
|
||||
assertTrue(recordService.isRecord(dmDocument));
|
||||
checkVitalRecordNotSet(dmDocument);
|
||||
|
||||
fileFolderService.move(dmDocument, rmFolder, null);
|
||||
|
||||
checkVitalRecordSet(dmDocument);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, "admin");
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
checkVitalRecordSet(dmDocument);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void checkVitalRecordSet(NodeRef nodeRef)
|
||||
{
|
||||
VitalRecordDefinition def = vitalRecordService.getVitalRecordDefinition(nodeRef);
|
||||
assertNotNull(def);
|
||||
assertTrue(def.isEnabled());
|
||||
assertEquals("month", def.getReviewPeriod().getPeriodType());
|
||||
assertEquals("1", def.getReviewPeriod().getExpression());
|
||||
}
|
||||
|
||||
private void checkVitalRecordNotSet(NodeRef nodeRef)
|
||||
{
|
||||
VitalRecordDefinition recordDef = vitalRecordService.getVitalRecordDefinition(nodeRef);
|
||||
if (recordDef != null)
|
||||
{
|
||||
assertFalse(recordDef.isEnabled());
|
||||
assertEquals("none", recordDef.getReviewPeriod().getPeriodType());
|
||||
assertNull(recordDef.getNextReviewDate());
|
||||
}
|
||||
}
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
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.vital.VitalRecordDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.Period;
|
||||
|
||||
/**
|
||||
* System test for RM-994
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class RM994Test extends BaseRMTestCase
|
||||
{
|
||||
@Override
|
||||
protected void initServices()
|
||||
{
|
||||
super.initServices();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCollaborationSiteTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRecordTest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void testRM944() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
checkVitalRecordNotSet(rmContainer);
|
||||
checkVitalRecordNotSet(rmFolder);
|
||||
checkVitalRecordNotSet(recordOne);
|
||||
assertNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF));
|
||||
|
||||
vitalRecordService.setVitalRecordDefintion(rmContainer, true, new Period("month|1"));
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
checkVitalRecordSet(rmContainer);
|
||||
checkVitalRecordSet(rmFolder);
|
||||
checkVitalRecordSet(recordOne);
|
||||
assertNotNull(nodeService.getProperty(recordOne, PROP_REVIEW_AS_OF));
|
||||
|
||||
recordService.createRecord(filePlan, dmDocument, true);
|
||||
|
||||
assertTrue(recordService.isRecord(dmDocument));
|
||||
checkVitalRecordNotSet(dmDocument);
|
||||
|
||||
fileFolderService.move(dmDocument, rmFolder, null);
|
||||
|
||||
checkVitalRecordSet(dmDocument);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, "admin");
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
checkVitalRecordSet(dmDocument);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void checkVitalRecordSet(NodeRef nodeRef)
|
||||
{
|
||||
VitalRecordDefinition def = vitalRecordService.getVitalRecordDefinition(nodeRef);
|
||||
assertNotNull(def);
|
||||
assertTrue(def.isEnabled());
|
||||
assertEquals("month", def.getReviewPeriod().getPeriodType());
|
||||
assertEquals("1", def.getReviewPeriod().getExpression());
|
||||
}
|
||||
|
||||
private void checkVitalRecordNotSet(NodeRef nodeRef)
|
||||
{
|
||||
VitalRecordDefinition recordDef = vitalRecordService.getVitalRecordDefinition(nodeRef);
|
||||
if (recordDef != null)
|
||||
{
|
||||
assertFalse(recordDef.isEnabled());
|
||||
assertEquals("none", recordDef.getReviewPeriod().getPeriodType());
|
||||
assertNull(recordDef.getNextReviewDate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.version;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.version.ExtendedVersionableAspect;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
/**
|
||||
* Test recorded version histories when interacting with cm:versionable aspect
|
||||
* and the auto-version behvaiour.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.3.1
|
||||
*/
|
||||
public class AutoVersionTest extends RecordableVersionsBaseTest
|
||||
{
|
||||
/**
|
||||
* Given a versionable document
|
||||
* When I specialise the type of the document
|
||||
* Then the version history has only one initial version
|
||||
* And it does not represent the current type of the document
|
||||
*/
|
||||
public void testSpecialisedNodeInitialVersionCreated()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// specialise document
|
||||
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef();
|
||||
assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState));
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a versionable document with initial version turned off
|
||||
* When I specialise the type of the document
|
||||
* Then the version history remains empty
|
||||
*/
|
||||
public void testSpecialisedNodeInitialVersionNotCreated()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
|
||||
props.put(ContentModel.PROP_INITIAL_VERSION, false);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// specialise document
|
||||
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNull(versionHistory);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a versionable document with initial version turned off
|
||||
* And auto version on type change is set on
|
||||
* When I specialise the type of the document
|
||||
* Then the version history contains the initial version
|
||||
*/
|
||||
public void testSpecialisedNodeInitialVersionNotCreatedOnTypeChangeOn()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private ExtendedVersionableAspect extendedVersionableAspect;
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// turn auto version on type change on
|
||||
extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect");
|
||||
assertNotNull(extendedVersionableAspect);
|
||||
extendedVersionableAspect.setAutoVersionOnTypeChange(true);
|
||||
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
|
||||
props.put(ContentModel.PROP_INITIAL_VERSION, false);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// specialise document
|
||||
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef();
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState));
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
|
||||
}
|
||||
|
||||
public void after() throws Exception
|
||||
{
|
||||
// reset auto version on type to default off
|
||||
extendedVersionableAspect.setAutoVersionOnTypeChange(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a versionable document with initial version turned on
|
||||
* And auto version on type change is set on
|
||||
* When I specialise the type of the document
|
||||
* Then the version history contains the initial version
|
||||
*/
|
||||
public void testSpecialisedNodeInitialVersionCreatedOnTypeChangeOn()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private ExtendedVersionableAspect extendedVersionableAspect;
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// turn auto version on type change on
|
||||
extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect");
|
||||
assertNotNull(extendedVersionableAspect);
|
||||
extendedVersionableAspect.setAutoVersionOnTypeChange(true);
|
||||
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
|
||||
props.put(ContentModel.PROP_INITIAL_VERSION, true);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// specialise document
|
||||
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(2, versionHistory.getAllVersions().size());
|
||||
|
||||
NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef();
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState));
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
|
||||
|
||||
frozenState = versionHistory.getVersion("1.0").getFrozenStateNodeRef();
|
||||
assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState));
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
|
||||
}
|
||||
|
||||
public void after() throws Exception
|
||||
{
|
||||
// reset auto version on type to default off
|
||||
extendedVersionableAspect.setAutoVersionOnTypeChange(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.version;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.version.ExtendedVersionableAspect;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
/**
|
||||
* Test recorded version histories when interacting with cm:versionable aspect
|
||||
* and the auto-version behvaiour.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.3.1
|
||||
*/
|
||||
public class AutoVersionTest extends RecordableVersionsBaseTest
|
||||
{
|
||||
/**
|
||||
* Given a versionable document
|
||||
* When I specialise the type of the document
|
||||
* Then the version history has only one initial version
|
||||
* And it does not represent the current type of the document
|
||||
*/
|
||||
public void testSpecialisedNodeInitialVersionCreated()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// specialise document
|
||||
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef();
|
||||
assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState));
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a versionable document with initial version turned off
|
||||
* When I specialise the type of the document
|
||||
* Then the version history remains empty
|
||||
*/
|
||||
public void testSpecialisedNodeInitialVersionNotCreated()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
|
||||
props.put(ContentModel.PROP_INITIAL_VERSION, false);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// specialise document
|
||||
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNull(versionHistory);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a versionable document with initial version turned off
|
||||
* And auto version on type change is set on
|
||||
* When I specialise the type of the document
|
||||
* Then the version history contains the initial version
|
||||
*/
|
||||
public void testSpecialisedNodeInitialVersionNotCreatedOnTypeChangeOn()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private ExtendedVersionableAspect extendedVersionableAspect;
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// turn auto version on type change on
|
||||
extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect");
|
||||
assertNotNull(extendedVersionableAspect);
|
||||
extendedVersionableAspect.setAutoVersionOnTypeChange(true);
|
||||
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
|
||||
props.put(ContentModel.PROP_INITIAL_VERSION, false);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// specialise document
|
||||
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef();
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState));
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
|
||||
}
|
||||
|
||||
public void after() throws Exception
|
||||
{
|
||||
// reset auto version on type to default off
|
||||
extendedVersionableAspect.setAutoVersionOnTypeChange(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a versionable document with initial version turned on
|
||||
* And auto version on type change is set on
|
||||
* When I specialise the type of the document
|
||||
* Then the version history contains the initial version
|
||||
*/
|
||||
public void testSpecialisedNodeInitialVersionCreatedOnTypeChangeOn()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(dmCollaborator)
|
||||
{
|
||||
private ExtendedVersionableAspect extendedVersionableAspect;
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// turn auto version on type change on
|
||||
extendedVersionableAspect = (ExtendedVersionableAspect)applicationContext.getBean("rm.extendedVersionableAspect");
|
||||
assertNotNull(extendedVersionableAspect);
|
||||
extendedVersionableAspect.setAutoVersionOnTypeChange(true);
|
||||
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
|
||||
props.put(ContentModel.PROP_INITIAL_VERSION, true);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, props);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// specialise document
|
||||
nodeService.setType(myDocument, TYPE_CUSTOM_TYPE);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(2, versionHistory.getAllVersions().size());
|
||||
|
||||
NodeRef frozenState = versionHistory.getHeadVersion().getFrozenStateNodeRef();
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(frozenState));
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
|
||||
|
||||
frozenState = versionHistory.getVersion("1.0").getFrozenStateNodeRef();
|
||||
assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(frozenState));
|
||||
assertEquals(TYPE_CUSTOM_TYPE, nodeService.getType(myDocument));
|
||||
}
|
||||
|
||||
public void after() throws Exception
|
||||
{
|
||||
// reset auto version on type to default off
|
||||
extendedVersionableAspect.setAutoVersionOnTypeChange(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.version;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
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.CutOffAction;
|
||||
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.RelationshipService;
|
||||
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.RecordableVersionPolicy;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
/**
|
||||
* Recordable version history integration tests.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.3.1
|
||||
*/
|
||||
public class DeleteRecordVersionTest extends RecordableVersionsBaseTest
|
||||
{
|
||||
/**
|
||||
* Given that a document is created
|
||||
* And the initial version is record
|
||||
* When I delete the version record
|
||||
* Then the version is deleted
|
||||
* And the version history is not deleted
|
||||
*
|
||||
* @see https://issues.alfresco.com/jira/browse/RM-2562
|
||||
*/
|
||||
public void testDeleteFirstRecordedVersion()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
|
||||
props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL);
|
||||
props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan);
|
||||
nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// check the initial version label
|
||||
assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL));
|
||||
|
||||
// check that the version history contains a single version that is recorded
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
// check the recorded version is not marked as destroyed
|
||||
Version head = versionHistory.getHeadVersion();
|
||||
assertNotNull(head);
|
||||
assertFalse(recordableVersionService.isRecordedVersionDestroyed(head));
|
||||
|
||||
// check the version record
|
||||
NodeRef record = recordableVersionService.getVersionRecord(head);
|
||||
assertTrue(recordService.isRecord(record));
|
||||
|
||||
// record should not have a version history because it is immutable
|
||||
assertFalse(nodeService.hasAspect(record, ContentModel.ASPECT_VERSIONABLE));
|
||||
VersionHistory recordVersionHistory = versionService.getVersionHistory(record);
|
||||
assertNull(recordVersionHistory);
|
||||
|
||||
// destroy record
|
||||
nodeService.deleteNode(record);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// document is still versionable
|
||||
assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE));
|
||||
|
||||
// check the initial version label
|
||||
assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL));
|
||||
|
||||
// still has a version history, but the version is marked as destroyed
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
// check the recorded version is marked as destroyed and the record version is not longer available
|
||||
Version version = versionHistory.getHeadVersion();
|
||||
assertNotNull(version);
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version));
|
||||
assertNull(recordableVersionService.getVersionRecord(version));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a document is created
|
||||
* And the initial version is record
|
||||
* And the associated version record is deleted
|
||||
* When a new version 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)
|
||||
*
|
||||
* @see https://issues.alfresco.com/jira/browse/RM-2562
|
||||
*/
|
||||
public void testDeleteFirstRecordedVersionAndCreateNewVersion()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
ContentWriter writer = fileFolderService.getWriter(myDocument);
|
||||
writer.setEncoding("UTF-8");
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
writer.putContent(GUID.generate());
|
||||
|
||||
// make versionable
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
|
||||
props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL);
|
||||
props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan);
|
||||
nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// get the created version record
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
Version head = versionHistory.getHeadVersion();
|
||||
NodeRef record = recordableVersionService.getVersionRecord(head);
|
||||
|
||||
// destroy record
|
||||
nodeService.deleteNode(record);
|
||||
|
||||
// update the content to create a new version (and version record)
|
||||
ContentWriter writer = fileFolderService.getWriter(myDocument);
|
||||
writer.putContent(GUID.generate());
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// document is still versionable
|
||||
assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE));
|
||||
|
||||
// check the version number has been incremented
|
||||
assertEquals("1.1", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL));
|
||||
|
||||
// still has a version history, with 2 enties
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(2, versionHistory.getAllVersions().size());
|
||||
|
||||
// latest version is current
|
||||
Version head = versionHistory.getHeadVersion();
|
||||
assertFalse(recordableVersionService.isRecordedVersionDestroyed(head));
|
||||
assertNotNull(recordableVersionService.getVersionRecord(head));
|
||||
|
||||
// first version is destroyed
|
||||
Version destroyed = versionHistory.getPredecessor(head);
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(destroyed));
|
||||
assertNull(recordableVersionService.getVersionRecord(destroyed));
|
||||
|
||||
// get the version record for the current version
|
||||
NodeRef versionRecord = recordableVersionService.getVersionRecord(head);
|
||||
assertNotNull(versionRecord);
|
||||
assertTrue(nodeService.exists(versionRecord));
|
||||
|
||||
Set<Relationship> from = relationshipService.getRelationshipsFrom(versionRecord);
|
||||
assertTrue(from.isEmpty());
|
||||
|
||||
Set<Relationship> to = relationshipService.getRelationshipsTo(versionRecord);
|
||||
assertTrue(to.isEmpty());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a chain of version records (1.0, 1.1, 1.2) which are all related
|
||||
* When I delete version record 1.0
|
||||
* Then 1.1 is the oldest version
|
||||
*/
|
||||
public void testDeleteOldestVersion()
|
||||
{
|
||||
final NodeRef myDocument = createDocumentWithRecordVersions();
|
||||
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private VersionHistory versionHistory;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// get version history
|
||||
versionHistory = versionService.getVersionHistory(myDocument);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
Version version10 = versionHistory.getVersion("1.0");
|
||||
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
|
||||
|
||||
// delete record version 1.0
|
||||
nodeService.deleteNode(recordVersion10);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// check the deleted version
|
||||
Version version10 = versionHistory.getVersion("1.0");
|
||||
assertNotNull(version10);
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version10));
|
||||
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
|
||||
assertNull(recordVersion10);
|
||||
|
||||
// verify 1.2 setup as expected
|
||||
Version version12 = versionHistory.getHeadVersion();
|
||||
assertEquals("1.2", version12.getVersionLabel());
|
||||
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
|
||||
assertNotNull(recordVersion12);
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
|
||||
Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, from12.size());
|
||||
|
||||
// verify 1.1 setup as expected
|
||||
Version version11 = versionHistory.getPredecessor(version12);
|
||||
assertEquals("1.1", version11.getVersionLabel());
|
||||
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
|
||||
assertNotNull(recordVersion11);
|
||||
|
||||
Set<Relationship> to11 = relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, to11.size());
|
||||
assertEquals(recordVersion12, to11.iterator().next().getSource());
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a chain of version records (1.0, 1.1, 1.2) which are all related
|
||||
* When I delete version record 1.1
|
||||
* Then 1.2 now 'versions' 1.0
|
||||
*/
|
||||
public void testDeleteMiddleVersion()
|
||||
{
|
||||
final NodeRef myDocument = createDocumentWithRecordVersions();
|
||||
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private VersionHistory versionHistory;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// get version history
|
||||
versionHistory = versionService.getVersionHistory(myDocument);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
Version version11 = versionHistory.getVersion("1.1");
|
||||
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
|
||||
|
||||
// delete record version 1.1
|
||||
nodeService.deleteNode(recordVersion11);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// check the deleted version
|
||||
Version version11 = versionHistory.getVersion("1.1");
|
||||
assertNotNull(version11);
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11));
|
||||
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
|
||||
assertNull(recordVersion11);
|
||||
|
||||
// verify 1.2 setup as expected
|
||||
Version version12 = versionHistory.getHeadVersion();
|
||||
assertEquals("1.2", version12.getVersionLabel());
|
||||
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
|
||||
assertNotNull(recordVersion12);
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
|
||||
Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, from12.size());
|
||||
|
||||
// verify 1.0 setup as expected
|
||||
Version version10 = versionHistory.getVersion("1.0");
|
||||
assertEquals("1.0", version10.getVersionLabel());
|
||||
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
|
||||
assertNotNull(recordVersion10);
|
||||
|
||||
Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, to10.size());
|
||||
assertEquals(recordVersion12, to10.iterator().next().getSource());
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a chain of version records (1.0, 1.1, 1.2) which are all related
|
||||
* When I delete version record 1.2
|
||||
* Then 1.1 is the most recent version
|
||||
*/
|
||||
public void testDeleteCurrentVersion()
|
||||
{
|
||||
final NodeRef myDocument = createDocumentWithRecordVersions();
|
||||
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private VersionHistory versionHistory;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// get version history
|
||||
versionHistory = versionService.getVersionHistory(myDocument);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
Version version12 = versionHistory.getVersion("1.2");
|
||||
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
|
||||
|
||||
// delete record version 1.2
|
||||
nodeService.deleteNode(recordVersion12);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// check 1.2
|
||||
Version version12 = versionHistory.getVersion("1.2");
|
||||
assertNotNull(version12);
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version12));
|
||||
assertNull(recordableVersionService.getVersionRecord(version12));
|
||||
|
||||
// verify 1.1
|
||||
Version version11 = versionHistory.getVersion("1.1");
|
||||
assertNotNull(version11);
|
||||
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
|
||||
assertNotNull(recordVersion11);
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
|
||||
Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, from11.size());
|
||||
|
||||
// verify 1.0
|
||||
Version version10 = versionHistory.getVersion("1.0");
|
||||
assertNotNull(version10);
|
||||
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
|
||||
assertNotNull(recordVersion10);
|
||||
|
||||
Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, to10.size());
|
||||
assertEquals(recordVersion11, to10.iterator().next().getSource());
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a version record
|
||||
* When the version record is destroyed whilst retaining the meta data
|
||||
* Then the version is marked as destroyed in the collab version history
|
||||
*/
|
||||
public void testDestroyVersionRecordWithMetadata()
|
||||
{
|
||||
final NodeRef myDocument = createDocumentWithRecordVersions();
|
||||
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private VersionHistory versionHistory;
|
||||
private NodeRef recordVersion11;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create file plan structure
|
||||
NodeRef myCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
|
||||
utils.createBasicDispositionSchedule(myCategory, GUID.generate(), GUID.generate(), true, true);
|
||||
|
||||
NodeRef myRecordFolder = recordFolderService.createRecordFolder(myCategory, GUID.generate());
|
||||
|
||||
// get version history
|
||||
versionHistory = versionService.getVersionHistory(myDocument);
|
||||
|
||||
// file and complete all the version records into my record folder
|
||||
for (Version version : versionHistory.getAllVersions())
|
||||
{
|
||||
NodeRef record = recordableVersionService.getVersionRecord(version);
|
||||
fileFolderService.move(record, myRecordFolder, null);
|
||||
utils.completeRecord(record);
|
||||
}
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
Version version11 = versionHistory.getVersion("1.1");
|
||||
recordVersion11 = recordableVersionService.getVersionRecord(version11);
|
||||
|
||||
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
|
||||
params.put(CompleteEventAction.PARAM_EVENT_NAME, CommonRMTestUtils.DEFAULT_EVENT_NAME);
|
||||
rmActionService.executeRecordsManagementAction(recordVersion11, CompleteEventAction.NAME, params);
|
||||
|
||||
rmActionService.executeRecordsManagementAction(recordVersion11, CutOffAction.NAME);
|
||||
|
||||
rmActionService.executeRecordsManagementAction(recordVersion11, DestroyAction.NAME);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// verify that the version history looks as expected
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
Collection<Version> versions = versionHistory.getAllVersions();
|
||||
assertEquals(3, versions.size());
|
||||
|
||||
// verify 1.2 setup as expected
|
||||
Version version12 = versionHistory.getHeadVersion();
|
||||
assertEquals("1.2", version12.getVersionLabel());
|
||||
assertFalse(recordableVersionService.isRecordedVersionDestroyed(version12));
|
||||
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
|
||||
assertNotNull(recordVersion12);
|
||||
assertFalse(recordService.isMetadataStub(recordVersion12));
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsTo(recordVersion12, "versions").isEmpty());
|
||||
|
||||
Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, "versions");
|
||||
assertEquals(1, from12.size());
|
||||
|
||||
// verify 1.1 setup as expected
|
||||
Version version11 = versionHistory.getPredecessor(version12);
|
||||
assertEquals("1.1", version11.getVersionLabel());
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11));
|
||||
assertNotNull(recordVersion11);
|
||||
assertTrue(recordService.isMetadataStub(recordVersion11));
|
||||
|
||||
Set<Relationship> to11 = relationshipService.getRelationshipsTo(recordVersion11, "versions");
|
||||
assertEquals(1, to11.size());
|
||||
assertEquals(recordVersion12, to11.iterator().next().getSource());
|
||||
|
||||
Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, "versions");
|
||||
assertEquals(1, from11.size());
|
||||
|
||||
// verify 1.0 setup as expected
|
||||
Version version10 = versionHistory.getPredecessor(version11);
|
||||
assertEquals("1.0", version10.getVersionLabel());
|
||||
assertFalse(recordableVersionService.isRecordedVersionDestroyed(version10));
|
||||
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
|
||||
assertNotNull(recordVersion10);
|
||||
assertFalse(recordService.isMetadataStub(recordVersion10));
|
||||
|
||||
Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, "versions");
|
||||
assertEquals(1, to10.size());
|
||||
assertEquals(recordVersion11, to10.iterator().next().getSource());
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, "versions").isEmpty());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.integration.version;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
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.CutOffAction;
|
||||
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.RelationshipService;
|
||||
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.RecordableVersionPolicy;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
/**
|
||||
* Recordable version history integration tests.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.3.1
|
||||
*/
|
||||
public class DeleteRecordVersionTest extends RecordableVersionsBaseTest
|
||||
{
|
||||
/**
|
||||
* Given that a document is created
|
||||
* And the initial version is record
|
||||
* When I delete the version record
|
||||
* Then the version is deleted
|
||||
* And the version history is not deleted
|
||||
*
|
||||
* @see https://issues.alfresco.com/jira/browse/RM-2562
|
||||
*/
|
||||
public void testDeleteFirstRecordedVersion()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// make versionable
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
|
||||
props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL);
|
||||
props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan);
|
||||
nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// check the initial version label
|
||||
assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL));
|
||||
|
||||
// check that the version history contains a single version that is recorded
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
// check the recorded version is not marked as destroyed
|
||||
Version head = versionHistory.getHeadVersion();
|
||||
assertNotNull(head);
|
||||
assertFalse(recordableVersionService.isRecordedVersionDestroyed(head));
|
||||
|
||||
// check the version record
|
||||
NodeRef record = recordableVersionService.getVersionRecord(head);
|
||||
assertTrue(recordService.isRecord(record));
|
||||
|
||||
// record should not have a version history because it is immutable
|
||||
assertFalse(nodeService.hasAspect(record, ContentModel.ASPECT_VERSIONABLE));
|
||||
VersionHistory recordVersionHistory = versionService.getVersionHistory(record);
|
||||
assertNull(recordVersionHistory);
|
||||
|
||||
// destroy record
|
||||
nodeService.deleteNode(record);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// document is still versionable
|
||||
assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE));
|
||||
|
||||
// check the initial version label
|
||||
assertEquals("1.0", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL));
|
||||
|
||||
// still has a version history, but the version is marked as destroyed
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(1, versionHistory.getAllVersions().size());
|
||||
|
||||
// check the recorded version is marked as destroyed and the record version is not longer available
|
||||
Version version = versionHistory.getHeadVersion();
|
||||
assertNotNull(version);
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version));
|
||||
assertNull(recordableVersionService.getVersionRecord(version));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a document is created
|
||||
* And the initial version is record
|
||||
* And the associated version record is deleted
|
||||
* When a new version 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)
|
||||
*
|
||||
* @see https://issues.alfresco.com/jira/browse/RM-2562
|
||||
*/
|
||||
public void testDeleteFirstRecordedVersionAndCreateNewVersion()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private NodeRef myDocument;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a document
|
||||
myDocument = fileFolderService.create(dmFolder, GUID.generate(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
ContentWriter writer = fileFolderService.getWriter(myDocument);
|
||||
writer.setEncoding("UTF-8");
|
||||
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
writer.putContent(GUID.generate());
|
||||
|
||||
// make versionable
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
|
||||
props.put(RecordableVersionModel.PROP_RECORDABLE_VERSION_POLICY, RecordableVersionPolicy.ALL);
|
||||
props.put(RecordableVersionModel.PROP_FILE_PLAN, filePlan);
|
||||
nodeService.addAspect(myDocument, RecordableVersionModel.ASPECT_VERSIONABLE, props);
|
||||
nodeService.addAspect(myDocument, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
// get the created version record
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
Version head = versionHistory.getHeadVersion();
|
||||
NodeRef record = recordableVersionService.getVersionRecord(head);
|
||||
|
||||
// destroy record
|
||||
nodeService.deleteNode(record);
|
||||
|
||||
// update the content to create a new version (and version record)
|
||||
ContentWriter writer = fileFolderService.getWriter(myDocument);
|
||||
writer.putContent(GUID.generate());
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// document is still versionable
|
||||
assertTrue(nodeService.hasAspect(myDocument, ContentModel.ASPECT_VERSIONABLE));
|
||||
|
||||
// check the version number has been incremented
|
||||
assertEquals("1.1", nodeService.getProperty(myDocument, ContentModel.PROP_VERSION_LABEL));
|
||||
|
||||
// still has a version history, with 2 enties
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
assertEquals(2, versionHistory.getAllVersions().size());
|
||||
|
||||
// latest version is current
|
||||
Version head = versionHistory.getHeadVersion();
|
||||
assertFalse(recordableVersionService.isRecordedVersionDestroyed(head));
|
||||
assertNotNull(recordableVersionService.getVersionRecord(head));
|
||||
|
||||
// first version is destroyed
|
||||
Version destroyed = versionHistory.getPredecessor(head);
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(destroyed));
|
||||
assertNull(recordableVersionService.getVersionRecord(destroyed));
|
||||
|
||||
// get the version record for the current version
|
||||
NodeRef versionRecord = recordableVersionService.getVersionRecord(head);
|
||||
assertNotNull(versionRecord);
|
||||
assertTrue(nodeService.exists(versionRecord));
|
||||
|
||||
Set<Relationship> from = relationshipService.getRelationshipsFrom(versionRecord);
|
||||
assertTrue(from.isEmpty());
|
||||
|
||||
Set<Relationship> to = relationshipService.getRelationshipsTo(versionRecord);
|
||||
assertTrue(to.isEmpty());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a chain of version records (1.0, 1.1, 1.2) which are all related
|
||||
* When I delete version record 1.0
|
||||
* Then 1.1 is the oldest version
|
||||
*/
|
||||
public void testDeleteOldestVersion()
|
||||
{
|
||||
final NodeRef myDocument = createDocumentWithRecordVersions();
|
||||
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private VersionHistory versionHistory;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// get version history
|
||||
versionHistory = versionService.getVersionHistory(myDocument);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
Version version10 = versionHistory.getVersion("1.0");
|
||||
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
|
||||
|
||||
// delete record version 1.0
|
||||
nodeService.deleteNode(recordVersion10);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// check the deleted version
|
||||
Version version10 = versionHistory.getVersion("1.0");
|
||||
assertNotNull(version10);
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version10));
|
||||
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
|
||||
assertNull(recordVersion10);
|
||||
|
||||
// verify 1.2 setup as expected
|
||||
Version version12 = versionHistory.getHeadVersion();
|
||||
assertEquals("1.2", version12.getVersionLabel());
|
||||
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
|
||||
assertNotNull(recordVersion12);
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
|
||||
Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, from12.size());
|
||||
|
||||
// verify 1.1 setup as expected
|
||||
Version version11 = versionHistory.getPredecessor(version12);
|
||||
assertEquals("1.1", version11.getVersionLabel());
|
||||
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
|
||||
assertNotNull(recordVersion11);
|
||||
|
||||
Set<Relationship> to11 = relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, to11.size());
|
||||
assertEquals(recordVersion12, to11.iterator().next().getSource());
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a chain of version records (1.0, 1.1, 1.2) which are all related
|
||||
* When I delete version record 1.1
|
||||
* Then 1.2 now 'versions' 1.0
|
||||
*/
|
||||
public void testDeleteMiddleVersion()
|
||||
{
|
||||
final NodeRef myDocument = createDocumentWithRecordVersions();
|
||||
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private VersionHistory versionHistory;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// get version history
|
||||
versionHistory = versionService.getVersionHistory(myDocument);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
Version version11 = versionHistory.getVersion("1.1");
|
||||
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
|
||||
|
||||
// delete record version 1.1
|
||||
nodeService.deleteNode(recordVersion11);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// check the deleted version
|
||||
Version version11 = versionHistory.getVersion("1.1");
|
||||
assertNotNull(version11);
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11));
|
||||
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
|
||||
assertNull(recordVersion11);
|
||||
|
||||
// verify 1.2 setup as expected
|
||||
Version version12 = versionHistory.getHeadVersion();
|
||||
assertEquals("1.2", version12.getVersionLabel());
|
||||
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
|
||||
assertNotNull(recordVersion12);
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
|
||||
Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, from12.size());
|
||||
|
||||
// verify 1.0 setup as expected
|
||||
Version version10 = versionHistory.getVersion("1.0");
|
||||
assertEquals("1.0", version10.getVersionLabel());
|
||||
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
|
||||
assertNotNull(recordVersion10);
|
||||
|
||||
Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, to10.size());
|
||||
assertEquals(recordVersion12, to10.iterator().next().getSource());
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a chain of version records (1.0, 1.1, 1.2) which are all related
|
||||
* When I delete version record 1.2
|
||||
* Then 1.1 is the most recent version
|
||||
*/
|
||||
public void testDeleteCurrentVersion()
|
||||
{
|
||||
final NodeRef myDocument = createDocumentWithRecordVersions();
|
||||
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private VersionHistory versionHistory;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// get version history
|
||||
versionHistory = versionService.getVersionHistory(myDocument);
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
Version version12 = versionHistory.getVersion("1.2");
|
||||
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
|
||||
|
||||
// delete record version 1.2
|
||||
nodeService.deleteNode(recordVersion12);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// check 1.2
|
||||
Version version12 = versionHistory.getVersion("1.2");
|
||||
assertNotNull(version12);
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version12));
|
||||
assertNull(recordableVersionService.getVersionRecord(version12));
|
||||
|
||||
// verify 1.1
|
||||
Version version11 = versionHistory.getVersion("1.1");
|
||||
assertNotNull(version11);
|
||||
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
|
||||
assertNotNull(recordVersion11);
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
|
||||
Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, from11.size());
|
||||
|
||||
// verify 1.0
|
||||
Version version10 = versionHistory.getVersion("1.0");
|
||||
assertNotNull(version10);
|
||||
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
|
||||
assertNotNull(recordVersion10);
|
||||
|
||||
Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS);
|
||||
assertEquals(1, to10.size());
|
||||
assertEquals(recordVersion11, to10.iterator().next().getSource());
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a version record
|
||||
* When the version record is destroyed whilst retaining the meta data
|
||||
* Then the version is marked as destroyed in the collab version history
|
||||
*/
|
||||
public void testDestroyVersionRecordWithMetadata()
|
||||
{
|
||||
final NodeRef myDocument = createDocumentWithRecordVersions();
|
||||
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
private VersionHistory versionHistory;
|
||||
private NodeRef recordVersion11;
|
||||
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create file plan structure
|
||||
NodeRef myCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
|
||||
utils.createBasicDispositionSchedule(myCategory, GUID.generate(), GUID.generate(), true, true);
|
||||
|
||||
NodeRef myRecordFolder = recordFolderService.createRecordFolder(myCategory, GUID.generate());
|
||||
|
||||
// get version history
|
||||
versionHistory = versionService.getVersionHistory(myDocument);
|
||||
|
||||
// file and complete all the version records into my record folder
|
||||
for (Version version : versionHistory.getAllVersions())
|
||||
{
|
||||
NodeRef record = recordableVersionService.getVersionRecord(version);
|
||||
fileFolderService.move(record, myRecordFolder, null);
|
||||
utils.completeRecord(record);
|
||||
}
|
||||
}
|
||||
|
||||
public void when()
|
||||
{
|
||||
Version version11 = versionHistory.getVersion("1.1");
|
||||
recordVersion11 = recordableVersionService.getVersionRecord(version11);
|
||||
|
||||
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
|
||||
params.put(CompleteEventAction.PARAM_EVENT_NAME, CommonRMTestUtils.DEFAULT_EVENT_NAME);
|
||||
rmActionService.executeRecordsManagementAction(recordVersion11, CompleteEventAction.NAME, params);
|
||||
|
||||
rmActionService.executeRecordsManagementAction(recordVersion11, CutOffAction.NAME);
|
||||
|
||||
rmActionService.executeRecordsManagementAction(recordVersion11, DestroyAction.NAME);
|
||||
}
|
||||
|
||||
public void then()
|
||||
{
|
||||
// verify that the version history looks as expected
|
||||
VersionHistory versionHistory = versionService.getVersionHistory(myDocument);
|
||||
assertNotNull(versionHistory);
|
||||
Collection<Version> versions = versionHistory.getAllVersions();
|
||||
assertEquals(3, versions.size());
|
||||
|
||||
// verify 1.2 setup as expected
|
||||
Version version12 = versionHistory.getHeadVersion();
|
||||
assertEquals("1.2", version12.getVersionLabel());
|
||||
assertFalse(recordableVersionService.isRecordedVersionDestroyed(version12));
|
||||
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
|
||||
assertNotNull(recordVersion12);
|
||||
assertFalse(recordService.isMetadataStub(recordVersion12));
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsTo(recordVersion12, "versions").isEmpty());
|
||||
|
||||
Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, "versions");
|
||||
assertEquals(1, from12.size());
|
||||
|
||||
// verify 1.1 setup as expected
|
||||
Version version11 = versionHistory.getPredecessor(version12);
|
||||
assertEquals("1.1", version11.getVersionLabel());
|
||||
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11));
|
||||
assertNotNull(recordVersion11);
|
||||
assertTrue(recordService.isMetadataStub(recordVersion11));
|
||||
|
||||
Set<Relationship> to11 = relationshipService.getRelationshipsTo(recordVersion11, "versions");
|
||||
assertEquals(1, to11.size());
|
||||
assertEquals(recordVersion12, to11.iterator().next().getSource());
|
||||
|
||||
Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, "versions");
|
||||
assertEquals(1, from11.size());
|
||||
|
||||
// verify 1.0 setup as expected
|
||||
Version version10 = versionHistory.getPredecessor(version11);
|
||||
assertEquals("1.0", version10.getVersionLabel());
|
||||
assertFalse(recordableVersionService.isRecordedVersionDestroyed(version10));
|
||||
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
|
||||
assertNotNull(recordVersion10);
|
||||
assertFalse(recordService.isMetadataStub(recordVersion10));
|
||||
|
||||
Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, "versions");
|
||||
assertEquals(1, to10.size());
|
||||
assertEquals(recordVersion11, to10.iterator().next().getSource());
|
||||
|
||||
assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, "versions").isEmpty());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
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 java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
|
||||
public class AuditRestApiTest extends BaseRMWebScriptTestCase
|
||||
{
|
||||
/** URL for the REST APIs */
|
||||
protected static final String GET_NODE_AUDITLOG_URL_FORMAT = "/api/node/{0}/rmauditlog";
|
||||
|
||||
private static final String USER_WITHOUT_AUDIT_CAPABILITY = GUID.generate();
|
||||
|
||||
private NodeRef record;
|
||||
|
||||
public void testAuditAccessCapability() throws IOException
|
||||
{
|
||||
|
||||
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_FORBIDDEN, USER_WITHOUT_AUDIT_CAPABILITY );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupTestData()
|
||||
{
|
||||
super.setupTestData();
|
||||
|
||||
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
|
||||
{
|
||||
@Override
|
||||
public Object execute() throws Throwable
|
||||
{
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil
|
||||
.getSystemUserName());
|
||||
|
||||
createUser(USER_WITHOUT_AUDIT_CAPABILITY);
|
||||
|
||||
record = utils.createRecord(recordFolder, GUID.generate());
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDownImpl()
|
||||
{
|
||||
super.tearDownImpl();
|
||||
|
||||
deleteUser(USER_WITHOUT_AUDIT_CAPABILITY);
|
||||
}
|
||||
|
||||
protected String getRMSiteId()
|
||||
{
|
||||
return DEFAULT_RM_SITE_ID;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
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 java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
|
||||
public class AuditRestApiTest extends BaseRMWebScriptTestCase
|
||||
{
|
||||
/** URL for the REST APIs */
|
||||
protected static final String GET_NODE_AUDITLOG_URL_FORMAT = "/api/node/{0}/rmauditlog";
|
||||
|
||||
private static final String USER_WITHOUT_AUDIT_CAPABILITY = GUID.generate();
|
||||
|
||||
private NodeRef record;
|
||||
|
||||
public void testAuditAccessCapability() throws IOException
|
||||
{
|
||||
|
||||
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_FORBIDDEN, USER_WITHOUT_AUDIT_CAPABILITY );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupTestData()
|
||||
{
|
||||
super.setupTestData();
|
||||
|
||||
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
|
||||
{
|
||||
@Override
|
||||
public Object execute() throws Throwable
|
||||
{
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil
|
||||
.getSystemUserName());
|
||||
|
||||
createUser(USER_WITHOUT_AUDIT_CAPABILITY);
|
||||
|
||||
record = utils.createRecord(recordFolder, GUID.generate());
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDownImpl()
|
||||
{
|
||||
super.tearDownImpl();
|
||||
|
||||
deleteUser(USER_WITHOUT_AUDIT_CAPABILITY);
|
||||
}
|
||||
|
||||
protected String getRMSiteId()
|
||||
{
|
||||
return DEFAULT_RM_SITE_ID;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.system;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.test.util.BaseRMTestCase;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
|
||||
/**
|
||||
* Notification helper (system) test
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class NotificationServiceHelperSystemTest extends BaseRMTestCase
|
||||
{
|
||||
private static final String NOTIFICATION_ROLE = "RecordsManager";
|
||||
private static final String EMAIL_ADDRESS = "roy.wetherall@alfreso.com";
|
||||
|
||||
/** Services */
|
||||
private RecordsManagementNotificationHelper notificationHelper;
|
||||
|
||||
/** Test data */
|
||||
private NodeRef record;
|
||||
private List<NodeRef> records;
|
||||
private String userName;
|
||||
private NodeRef person;
|
||||
|
||||
@Override
|
||||
protected void initServices()
|
||||
{
|
||||
super.initServices();
|
||||
|
||||
// Get the notification helper
|
||||
notificationHelper = (RecordsManagementNotificationHelper)applicationContext.getBean("recordsManagementNotificationHelper");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupTestData()
|
||||
{
|
||||
super.setupTestData();
|
||||
|
||||
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
|
||||
{
|
||||
@Override
|
||||
public Object execute() throws Throwable
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
// Create a user
|
||||
userName = GUID.generate();
|
||||
authenticationService.createAuthentication(userName, "".toCharArray());
|
||||
PropertyMap props = new PropertyMap();
|
||||
props.put(PROP_USERNAME, userName);
|
||||
props.put(PROP_FIRSTNAME, "Test");
|
||||
props.put(PROP_LASTNAME, "User");
|
||||
props.put(PROP_EMAIL, EMAIL_ADDRESS);
|
||||
person = personService.createPerson(props);
|
||||
|
||||
// Find the authority for the given role
|
||||
Role role = filePlanRoleService.getRole(filePlan, NOTIFICATION_ROLE);
|
||||
assertNotNull("Notification role could not be retrieved", role);
|
||||
String roleGroup = role.getRoleGroupName();
|
||||
assertNotNull("Notification role group can not be null.", roleGroup);
|
||||
|
||||
// Add user to notification role group
|
||||
authorityService.addAuthority(roleGroup, userName);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupTestDataImpl()
|
||||
{
|
||||
super.setupTestDataImpl();
|
||||
|
||||
// Create a few test records
|
||||
record = utils.createRecord(rmFolder, "recordOne");
|
||||
NodeRef record2 = utils.createRecord(rmFolder, "recordTwo");
|
||||
NodeRef record3 = utils.createRecord(rmFolder, "recordThree");
|
||||
|
||||
records = new ArrayList<NodeRef>(3);
|
||||
records.add(record);
|
||||
records.add(record2);
|
||||
records.add(record3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDownImpl()
|
||||
{
|
||||
super.tearDownImpl();
|
||||
|
||||
// Delete the person and user
|
||||
personService.deletePerson(person);
|
||||
}
|
||||
|
||||
public void testSendDueForReviewNotification()
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
notificationHelper.recordsDueForReviewEmailNotification(records);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testSendSupersededNotification()
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
notificationHelper.recordSupersededEmailNotification(record);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.system;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.test.util.BaseRMTestCase;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
|
||||
/**
|
||||
* Notification helper (system) test
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class NotificationServiceHelperSystemTest extends BaseRMTestCase
|
||||
{
|
||||
private static final String NOTIFICATION_ROLE = "RecordsManager";
|
||||
private static final String EMAIL_ADDRESS = "roy.wetherall@alfreso.com";
|
||||
|
||||
/** Services */
|
||||
private RecordsManagementNotificationHelper notificationHelper;
|
||||
|
||||
/** Test data */
|
||||
private NodeRef record;
|
||||
private List<NodeRef> records;
|
||||
private String userName;
|
||||
private NodeRef person;
|
||||
|
||||
@Override
|
||||
protected void initServices()
|
||||
{
|
||||
super.initServices();
|
||||
|
||||
// Get the notification helper
|
||||
notificationHelper = (RecordsManagementNotificationHelper)applicationContext.getBean("recordsManagementNotificationHelper");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupTestData()
|
||||
{
|
||||
super.setupTestData();
|
||||
|
||||
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
|
||||
{
|
||||
@Override
|
||||
public Object execute() throws Throwable
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
// Create a user
|
||||
userName = GUID.generate();
|
||||
authenticationService.createAuthentication(userName, "".toCharArray());
|
||||
PropertyMap props = new PropertyMap();
|
||||
props.put(PROP_USERNAME, userName);
|
||||
props.put(PROP_FIRSTNAME, "Test");
|
||||
props.put(PROP_LASTNAME, "User");
|
||||
props.put(PROP_EMAIL, EMAIL_ADDRESS);
|
||||
person = personService.createPerson(props);
|
||||
|
||||
// Find the authority for the given role
|
||||
Role role = filePlanRoleService.getRole(filePlan, NOTIFICATION_ROLE);
|
||||
assertNotNull("Notification role could not be retrieved", role);
|
||||
String roleGroup = role.getRoleGroupName();
|
||||
assertNotNull("Notification role group can not be null.", roleGroup);
|
||||
|
||||
// Add user to notification role group
|
||||
authorityService.addAuthority(roleGroup, userName);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupTestDataImpl()
|
||||
{
|
||||
super.setupTestDataImpl();
|
||||
|
||||
// Create a few test records
|
||||
record = utils.createRecord(rmFolder, "recordOne");
|
||||
NodeRef record2 = utils.createRecord(rmFolder, "recordTwo");
|
||||
NodeRef record3 = utils.createRecord(rmFolder, "recordThree");
|
||||
|
||||
records = new ArrayList<NodeRef>(3);
|
||||
records.add(record);
|
||||
records.add(record2);
|
||||
records.add(record3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDownImpl()
|
||||
{
|
||||
super.tearDownImpl();
|
||||
|
||||
// Delete the person and user
|
||||
personService.deletePerson(person);
|
||||
}
|
||||
|
||||
public void testSendDueForReviewNotification()
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
notificationHelper.recordsDueForReviewEmailNotification(records);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testSendSupersededNotification()
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
notificationHelper.recordSupersededEmailNotification(record);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.util;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.Group;
|
||||
|
||||
/**
|
||||
* Utility test case to generate a report of the capabilities in the system.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class GenerateCapabilityReport extends BaseRMTestCase
|
||||
{
|
||||
public void testGetCapability() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
FileWriter writer = new FileWriter("c:\\mywork\\capabilityReport.csv");
|
||||
BufferedWriter out = new BufferedWriter(writer);
|
||||
try
|
||||
{
|
||||
Set<Capability> capabilities = capabilityService.getCapabilities(true);
|
||||
for (Capability capability : capabilities)
|
||||
{
|
||||
Group group = capability.getGroup();
|
||||
String groupId = "none";
|
||||
if (group != null)
|
||||
{
|
||||
groupId = group.getId();
|
||||
}
|
||||
|
||||
out.write(groupId);
|
||||
out.write(",");
|
||||
out.write(capability.getName());
|
||||
out.write(",");
|
||||
out.write(Boolean.toString(capability.isPrivate()));
|
||||
out.write("\n");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.util;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.Group;
|
||||
|
||||
/**
|
||||
* Utility test case to generate a report of the capabilities in the system.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class GenerateCapabilityReport extends BaseRMTestCase
|
||||
{
|
||||
public void testGetCapability() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
FileWriter writer = new FileWriter("c:\\mywork\\capabilityReport.csv");
|
||||
BufferedWriter out = new BufferedWriter(writer);
|
||||
try
|
||||
{
|
||||
Set<Capability> capabilities = capabilityService.getCapabilities(true);
|
||||
for (Capability capability : capabilities)
|
||||
{
|
||||
Group group = capability.getGroup();
|
||||
String groupId = "none";
|
||||
if (group != null)
|
||||
{
|
||||
groupId = group.getId();
|
||||
}
|
||||
|
||||
out.write(groupId);
|
||||
out.write(",");
|
||||
out.write(capability.getName());
|
||||
out.write(",");
|
||||
out.write(Boolean.toString(capability.isPrivate()));
|
||||
out.write("\n");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer;
|
||||
|
||||
/**
|
||||
* Stand-alone Web Script Test Server
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class TestWebScriptRepoServer extends TestWebScriptServer
|
||||
{
|
||||
/**
|
||||
* Main entry point.
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
TestWebScriptServer testServer = getTestServer();
|
||||
AuthenticationUtil.setRunAsUserSystem();
|
||||
testServer.rep();
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
StringWriter strWriter = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(strWriter);
|
||||
e.printStackTrace(printWriter);
|
||||
System.out.println(strWriter.toString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
private final static String[] CONFIG_LOCATIONS = new String[]
|
||||
{
|
||||
"classpath:alfresco/application-context.xml",
|
||||
"classpath:alfresco/web-scripts-application-context.xml",
|
||||
"classpath:alfresco/web-scripts-application-context-test.xml"
|
||||
};
|
||||
|
||||
/** A static reference to the application context being used */
|
||||
private static ClassPathXmlApplicationContext ctx;
|
||||
private static String appendedTestConfiguration;
|
||||
|
||||
private RetryingTransactionHelper retryingTransactionHelper;
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
|
||||
/**
|
||||
* Sets helper that provides transaction callbacks
|
||||
*/
|
||||
public void setTransactionHelper(RetryingTransactionHelper retryingTransactionHelper)
|
||||
{
|
||||
this.retryingTransactionHelper = retryingTransactionHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authenticationService
|
||||
*/
|
||||
public void setAuthenticationService(AuthenticationService authenticationService)
|
||||
{
|
||||
this.authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default user name
|
||||
*/
|
||||
protected String getDefaultUserName()
|
||||
{
|
||||
return AuthenticationUtil.getAdminUserName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc #getTestServer(String)}
|
||||
*/
|
||||
public static TestWebScriptServer getTestServer()
|
||||
{
|
||||
return getTestServer(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start up a context and get the server bean.
|
||||
* <p>
|
||||
* This method will close and restart the application context only if the configuration has
|
||||
* changed.
|
||||
*
|
||||
* @param appendTestConfigLocation additional context file to include in the application context
|
||||
* @return Test Server
|
||||
*/
|
||||
public static synchronized TestWebScriptServer getTestServer(String appendTestConfigLocation)
|
||||
{
|
||||
if (TestWebScriptRepoServer.ctx != null)
|
||||
{
|
||||
boolean configChanged = !EqualsHelper.nullSafeEquals(
|
||||
appendTestConfigLocation,
|
||||
TestWebScriptRepoServer.appendedTestConfiguration);
|
||||
if (configChanged)
|
||||
{
|
||||
// The config changed, so close the context (it'll be restarted later)
|
||||
try
|
||||
{
|
||||
ctx.close();
|
||||
ctx = null;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throw new RuntimeException("Failed to shut down existing application context", e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// There is already a context with the required configuration
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we need to start/restart the context
|
||||
if (TestWebScriptRepoServer.ctx == null)
|
||||
{
|
||||
// Restart it
|
||||
final String[] configLocations;
|
||||
if (appendTestConfigLocation == null)
|
||||
{
|
||||
configLocations = CONFIG_LOCATIONS;
|
||||
}
|
||||
else
|
||||
{
|
||||
configLocations = new String[CONFIG_LOCATIONS.length+1];
|
||||
System.arraycopy(CONFIG_LOCATIONS, 0, configLocations, 0, CONFIG_LOCATIONS.length);
|
||||
configLocations[CONFIG_LOCATIONS.length] = appendTestConfigLocation;
|
||||
}
|
||||
TestWebScriptRepoServer.ctx = new ClassPathXmlApplicationContext(configLocations);
|
||||
TestWebScriptRepoServer.appendedTestConfiguration = appendTestConfigLocation;
|
||||
}
|
||||
|
||||
// Get the bean
|
||||
TestWebScriptServer testServer = (org.alfresco.repo.web.scripts.TestWebScriptRepoServer)TestWebScriptRepoServer.ctx.getBean("webscripts.test");
|
||||
return testServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpret a single command using the BufferedReader passed in for any data needed.
|
||||
*
|
||||
* @param line The unparsed command
|
||||
* @return The textual output of the command.
|
||||
*/
|
||||
@Override
|
||||
protected String interpretCommand(final String line)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (username.startsWith("TICKET_"))
|
||||
{
|
||||
try
|
||||
{
|
||||
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
|
||||
{
|
||||
public Object execute() throws Exception
|
||||
{
|
||||
authenticationService.validate(username);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return executeCommand(line);
|
||||
}
|
||||
finally
|
||||
{
|
||||
authenticationService.clearCurrentSecurityContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(AuthenticationException e)
|
||||
{
|
||||
executeCommand("user " + getDefaultUserName());
|
||||
}
|
||||
|
||||
// execute command in context of currently selected user
|
||||
return AuthenticationUtil.runAs(new RunAsWork<String>()
|
||||
{
|
||||
@SuppressWarnings("synthetic-access")
|
||||
public String doWork() throws Exception
|
||||
{
|
||||
return executeCommand(line);
|
||||
}
|
||||
}, username);
|
||||
}
|
||||
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer;
|
||||
|
||||
/**
|
||||
* Stand-alone Web Script Test Server
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class TestWebScriptRepoServer extends TestWebScriptServer
|
||||
{
|
||||
/**
|
||||
* Main entry point.
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
TestWebScriptServer testServer = getTestServer();
|
||||
AuthenticationUtil.setRunAsUserSystem();
|
||||
testServer.rep();
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
StringWriter strWriter = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(strWriter);
|
||||
e.printStackTrace(printWriter);
|
||||
System.out.println(strWriter.toString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
private final static String[] CONFIG_LOCATIONS = new String[]
|
||||
{
|
||||
"classpath:alfresco/application-context.xml",
|
||||
"classpath:alfresco/web-scripts-application-context.xml",
|
||||
"classpath:alfresco/web-scripts-application-context-test.xml"
|
||||
};
|
||||
|
||||
/** A static reference to the application context being used */
|
||||
private static ClassPathXmlApplicationContext ctx;
|
||||
private static String appendedTestConfiguration;
|
||||
|
||||
private RetryingTransactionHelper retryingTransactionHelper;
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
|
||||
/**
|
||||
* Sets helper that provides transaction callbacks
|
||||
*/
|
||||
public void setTransactionHelper(RetryingTransactionHelper retryingTransactionHelper)
|
||||
{
|
||||
this.retryingTransactionHelper = retryingTransactionHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authenticationService
|
||||
*/
|
||||
public void setAuthenticationService(AuthenticationService authenticationService)
|
||||
{
|
||||
this.authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default user name
|
||||
*/
|
||||
protected String getDefaultUserName()
|
||||
{
|
||||
return AuthenticationUtil.getAdminUserName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc #getTestServer(String)}
|
||||
*/
|
||||
public static TestWebScriptServer getTestServer()
|
||||
{
|
||||
return getTestServer(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start up a context and get the server bean.
|
||||
* <p>
|
||||
* This method will close and restart the application context only if the configuration has
|
||||
* changed.
|
||||
*
|
||||
* @param appendTestConfigLocation additional context file to include in the application context
|
||||
* @return Test Server
|
||||
*/
|
||||
public static synchronized TestWebScriptServer getTestServer(String appendTestConfigLocation)
|
||||
{
|
||||
if (TestWebScriptRepoServer.ctx != null)
|
||||
{
|
||||
boolean configChanged = !EqualsHelper.nullSafeEquals(
|
||||
appendTestConfigLocation,
|
||||
TestWebScriptRepoServer.appendedTestConfiguration);
|
||||
if (configChanged)
|
||||
{
|
||||
// The config changed, so close the context (it'll be restarted later)
|
||||
try
|
||||
{
|
||||
ctx.close();
|
||||
ctx = null;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throw new RuntimeException("Failed to shut down existing application context", e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// There is already a context with the required configuration
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we need to start/restart the context
|
||||
if (TestWebScriptRepoServer.ctx == null)
|
||||
{
|
||||
// Restart it
|
||||
final String[] configLocations;
|
||||
if (appendTestConfigLocation == null)
|
||||
{
|
||||
configLocations = CONFIG_LOCATIONS;
|
||||
}
|
||||
else
|
||||
{
|
||||
configLocations = new String[CONFIG_LOCATIONS.length+1];
|
||||
System.arraycopy(CONFIG_LOCATIONS, 0, configLocations, 0, CONFIG_LOCATIONS.length);
|
||||
configLocations[CONFIG_LOCATIONS.length] = appendTestConfigLocation;
|
||||
}
|
||||
TestWebScriptRepoServer.ctx = new ClassPathXmlApplicationContext(configLocations);
|
||||
TestWebScriptRepoServer.appendedTestConfiguration = appendTestConfigLocation;
|
||||
}
|
||||
|
||||
// Get the bean
|
||||
TestWebScriptServer testServer = (org.alfresco.repo.web.scripts.TestWebScriptRepoServer)TestWebScriptRepoServer.ctx.getBean("webscripts.test");
|
||||
return testServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpret a single command using the BufferedReader passed in for any data needed.
|
||||
*
|
||||
* @param line The unparsed command
|
||||
* @return The textual output of the command.
|
||||
*/
|
||||
@Override
|
||||
protected String interpretCommand(final String line)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (username.startsWith("TICKET_"))
|
||||
{
|
||||
try
|
||||
{
|
||||
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
|
||||
{
|
||||
public Object execute() throws Exception
|
||||
{
|
||||
authenticationService.validate(username);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return executeCommand(line);
|
||||
}
|
||||
finally
|
||||
{
|
||||
authenticationService.clearCurrentSecurityContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(AuthenticationException e)
|
||||
{
|
||||
executeCommand("user " + getDefaultUserName());
|
||||
}
|
||||
|
||||
// execute command in context of currently selected user
|
||||
return AuthenticationUtil.runAs(new RunAsWork<String>()
|
||||
{
|
||||
@SuppressWarnings("synthetic-access")
|
||||
public String doWork() throws Exception
|
||||
{
|
||||
return executeCommand(line);
|
||||
}
|
||||
}, username);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
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.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
/**
|
||||
* Hold service implementation unit test
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
public class HoldServiceImplUnitTest extends BaseUnitTest
|
||||
{
|
||||
/** test values */
|
||||
private static final String HOLD_NAME = "holdname";
|
||||
private static final String HOLD_REASON = "holdreason";
|
||||
private static final String HOLD_DESCRIPTION = "holddescription";
|
||||
|
||||
protected NodeRef holdContainer;
|
||||
protected NodeRef hold;
|
||||
protected NodeRef hold2;
|
||||
|
||||
@Spy @InjectMocks HoldServiceImpl holdService;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void before() throws Exception
|
||||
{
|
||||
super.before();
|
||||
|
||||
// setup objects used in mock interactions
|
||||
holdContainer = generateNodeRef(TYPE_HOLD_CONTAINER);
|
||||
hold = generateNodeRef(TYPE_HOLD);
|
||||
hold2 = generateNodeRef(TYPE_HOLD);
|
||||
|
||||
// setup interactions
|
||||
doReturn(holdContainer).when(mockedFilePlanService).getHoldContainer(filePlan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isHold()
|
||||
{
|
||||
assertTrue(holdService.isHold(hold));
|
||||
assertFalse(holdService.isHold(recordFolder));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heldByMultipleResults()
|
||||
{
|
||||
// setup record folder in multiple holds
|
||||
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, hold2, ASSOC_FROZEN_RECORDS, recordFolder, true, 2));
|
||||
doReturn(holds).when(mockedNodeService).getParentAssocs(recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
|
||||
|
||||
// check that both holds are found for record folder
|
||||
List<NodeRef> heldByHolds = holdService.heldBy(recordFolder, true);
|
||||
assertNotNull(heldByHolds);
|
||||
assertEquals(2, heldByHolds.size());
|
||||
assertTrue(holdService.heldBy(recordFolder, false).isEmpty());
|
||||
|
||||
// check that both holds are found for record (even thou they are one level deep)
|
||||
heldByHolds = holdService.heldBy(record, true);
|
||||
assertNotNull(heldByHolds);
|
||||
assertEquals(2, heldByHolds.size());
|
||||
assertTrue(holdService.heldBy(record, false).isEmpty());
|
||||
}
|
||||
|
||||
@Test (expected=AlfrescoRuntimeException.class)
|
||||
public void getHold()
|
||||
{
|
||||
// setup node service interactions
|
||||
when(mockedNodeService.getChildByName(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), anyString())).thenReturn(null)
|
||||
.thenReturn(hold)
|
||||
.thenReturn(recordFolder);
|
||||
|
||||
// no hold
|
||||
NodeRef noHold = holdService.getHold(filePlan, "notAHold");
|
||||
assertNull(noHold);
|
||||
|
||||
// found hold
|
||||
NodeRef someHold = holdService.getHold(filePlan, "someHold");
|
||||
assertNotNull(someHold);
|
||||
assertEquals(TYPE_HOLD, mockedNodeService.getType(someHold));
|
||||
|
||||
// ensure runtime exception is thrown
|
||||
holdService.getHold(filePlan, "notHold");
|
||||
}
|
||||
|
||||
@Test (expected=RuntimeException.class)
|
||||
public void getHeldNotAHold()
|
||||
{
|
||||
holdService.getHeld(recordFolder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHeldNoResults()
|
||||
{
|
||||
assertTrue(holdService.getHeld(hold).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHeldWithResults()
|
||||
{
|
||||
// setup record folder in hold
|
||||
List<ChildAssociationRef> holds = new ArrayList<ChildAssociationRef>(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);
|
||||
|
||||
List<NodeRef> list = holdService.getHeld(hold);
|
||||
assertEquals(1, list.size());
|
||||
assertEquals(recordFolder, list.get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void createHold()
|
||||
{
|
||||
// setup node service interactions
|
||||
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));
|
||||
|
||||
// create hold
|
||||
NodeRef newHold = holdService.createHold(filePlan, HOLD_NAME, HOLD_REASON, HOLD_DESCRIPTION);
|
||||
assertNotNull(newHold);
|
||||
assertEquals(TYPE_HOLD, mockedNodeService.getType(newHold));
|
||||
assertEquals(hold, newHold);
|
||||
|
||||
// check the node service interactions
|
||||
ArgumentCaptor<Map> propertyMapCaptor = ArgumentCaptor.forClass(Map.class);
|
||||
ArgumentCaptor<QName> assocNameCaptor = ArgumentCaptor.forClass(QName.class);
|
||||
verify(mockedNodeService).createNode(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), assocNameCaptor.capture() , eq(TYPE_HOLD), propertyMapCaptor.capture());
|
||||
|
||||
// check property map
|
||||
Map<QName, Serializable> propertyMap = (Map<QName, Serializable>)propertyMapCaptor.getValue();
|
||||
assertNotNull(propertyMap);
|
||||
assertEquals(3, propertyMap.size());
|
||||
assertTrue(propertyMap.containsKey(ContentModel.PROP_NAME));
|
||||
assertEquals(HOLD_NAME, propertyMap.get(ContentModel.PROP_NAME));
|
||||
assertTrue(propertyMap.containsKey(ContentModel.PROP_DESCRIPTION));
|
||||
assertEquals(HOLD_DESCRIPTION, propertyMap.get(ContentModel.PROP_DESCRIPTION));
|
||||
assertTrue(propertyMap.containsKey(PROP_HOLD_REASON));
|
||||
assertEquals(HOLD_REASON, propertyMap.get(PROP_HOLD_REASON));
|
||||
|
||||
// check assoc name
|
||||
assertNotNull(assocNameCaptor.getValue());
|
||||
assertEquals(NamespaceService.CONTENT_MODEL_1_0_URI, assocNameCaptor.getValue().getNamespaceURI());
|
||||
assertEquals(HOLD_NAME, assocNameCaptor.getValue().getLocalName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHoldReason()
|
||||
{
|
||||
// setup node service interactions
|
||||
when(mockedNodeService.exists(hold))
|
||||
.thenReturn(false)
|
||||
.thenReturn(true)
|
||||
.thenReturn(true)
|
||||
.thenReturn(true);
|
||||
when(mockedNodeService.getProperty(eq(hold), eq(PROP_HOLD_REASON)))
|
||||
.thenReturn(null)
|
||||
.thenReturn(HOLD_REASON);
|
||||
|
||||
// node does not exist
|
||||
assertNull(holdService.getHoldReason(hold));
|
||||
|
||||
// node isn't a hold
|
||||
assertNull(holdService.getHoldReason(recordFolder));
|
||||
|
||||
// hold reason isn't set
|
||||
assertNull(holdService.getHoldReason(hold));
|
||||
|
||||
// hold reason set
|
||||
assertEquals(HOLD_REASON, holdService.getHoldReason(hold));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHoldReason()
|
||||
{
|
||||
// setup node service interactions
|
||||
when(mockedNodeService.exists(hold))
|
||||
.thenReturn(false)
|
||||
.thenReturn(true)
|
||||
.thenReturn(true);
|
||||
|
||||
// node does not exist
|
||||
holdService.setHoldReason(hold, HOLD_REASON);
|
||||
verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON);
|
||||
|
||||
// node isn't a hold
|
||||
holdService.setHoldReason(recordFolder, HOLD_REASON);
|
||||
verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON);
|
||||
|
||||
// set hold reason
|
||||
holdService.setHoldReason(hold, HOLD_REASON);
|
||||
verify(mockedNodeService).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON);
|
||||
}
|
||||
|
||||
@Test (expected=AlfrescoRuntimeException.class)
|
||||
public void deleteHoldNotAHold()
|
||||
{
|
||||
holdService.deleteHold(recordFolder);
|
||||
verify(mockedNodeService, never()).deleteNode(hold);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteHold()
|
||||
{
|
||||
// delete hold
|
||||
holdService.deleteHold(hold);
|
||||
verify(mockedNodeService).deleteNode(hold);
|
||||
|
||||
// TODO check interactions with policy component!!!
|
||||
}
|
||||
|
||||
@Test (expected=AlfrescoRuntimeException.class)
|
||||
public void addToHoldNotAHold()
|
||||
{
|
||||
holdService.addToHold(recordFolder, recordFolder);
|
||||
}
|
||||
|
||||
@Test (expected=AlfrescoRuntimeException.class)
|
||||
public void addToHoldNotARecordFolderOrRecord()
|
||||
{
|
||||
NodeRef anotherThing = generateNodeRef(TYPE_RECORD_CATEGORY);
|
||||
holdService.addToHold(hold, anotherThing);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void addToHoldNotInHold()
|
||||
{
|
||||
holdService.addToHold(hold, recordFolder);
|
||||
|
||||
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(record), eq(ASPECT_FROZEN), any(Map.class));
|
||||
verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString());
|
||||
|
||||
holdService.addToHold(hold, record);
|
||||
verify(mockedNodeService).addChild(hold, record, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
|
||||
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(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(record), anyString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void addToHoldAlreadyInHold()
|
||||
{
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
|
||||
|
||||
holdService.addToHold(hold, recordFolder);
|
||||
|
||||
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(record), eq(ASPECT_FROZEN), any(Map.class));
|
||||
verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void addToHoldAldeadyFrozen()
|
||||
{
|
||||
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
|
||||
|
||||
holdService.addToHold(hold, recordFolder);
|
||||
|
||||
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(record), eq(ASPECT_FROZEN), any(Map.class));
|
||||
verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void addToHolds()
|
||||
{
|
||||
// ensure the interaction indicates that a node has the frozen aspect applied if it has
|
||||
doAnswer(new Answer<Void>()
|
||||
{
|
||||
public Void answer(InvocationOnMock invocation)
|
||||
{
|
||||
NodeRef nodeRef = (NodeRef)invocation.getArguments()[0];
|
||||
doReturn(true).when(mockedNodeService).hasAspect(nodeRef, ASPECT_FROZEN);
|
||||
return null;
|
||||
}
|
||||
|
||||
}).when(mockedNodeService).addAspect(any(NodeRef.class), eq(ASPECT_FROZEN), any(Map.class));
|
||||
|
||||
// build a list of holds
|
||||
List<NodeRef> holds = new ArrayList<NodeRef>(2);
|
||||
holds.add(hold);
|
||||
holds.add(hold2);
|
||||
|
||||
// add the record folder to both holds
|
||||
holdService.addToHolds(holds, recordFolder);
|
||||
|
||||
// verify the interactions
|
||||
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)).addAspect(eq(recordFolder), 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());
|
||||
}
|
||||
|
||||
@Test (expected=AlfrescoRuntimeException.class)
|
||||
public void removeFromHoldNotAHold()
|
||||
{
|
||||
holdService.removeFromHold(recordFolder, recordFolder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeFromHoldNotInHold()
|
||||
{
|
||||
holdService.removeFromHold(hold, recordFolder);
|
||||
|
||||
verify(mockedNodeService, never()).removeChild(hold, recordFolder);
|
||||
verify(mockedNodeService, never()).removeAspect(recordFolder, ASPECT_FROZEN);
|
||||
verify(mockedNodeService, never()).removeAspect(record, ASPECT_FROZEN);
|
||||
verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeFromHold()
|
||||
{
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
|
||||
|
||||
holdService.removeFromHold(hold, recordFolder);
|
||||
|
||||
verify(mockedNodeService, times(1)).removeChild(hold, recordFolder);
|
||||
verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN);
|
||||
verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN);
|
||||
verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeFromHolds()
|
||||
{
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
|
||||
|
||||
// build a list of holds
|
||||
List<NodeRef> holds = new ArrayList<NodeRef>(2);
|
||||
holds.add(hold);
|
||||
holds.add(hold2);
|
||||
|
||||
holdService.removeFromHolds(holds, recordFolder);
|
||||
|
||||
verify(mockedNodeService, times(1)).removeChild(hold, recordFolder);
|
||||
verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder);
|
||||
verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN);
|
||||
verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN);
|
||||
verify(mockedRecordsManagementAuditService, times(2)).auditEvent(any(NodeRef.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeFromAllHolds()
|
||||
{
|
||||
// build a list of holds
|
||||
List<NodeRef> holds = new ArrayList<NodeRef>(2);
|
||||
holds.add(hold);
|
||||
holds.add(hold2);
|
||||
|
||||
doAnswer(new Answer<Void>()
|
||||
{
|
||||
public Void answer(InvocationOnMock invocation)
|
||||
{
|
||||
doReturn(Collections.singletonList(hold2)).when(holdService).heldBy(recordFolder, true);
|
||||
return null;
|
||||
}
|
||||
|
||||
}).when(mockedNodeService).removeChild(hold, recordFolder);
|
||||
|
||||
doAnswer(new Answer<Void>()
|
||||
{
|
||||
public Void answer(InvocationOnMock invocation)
|
||||
{
|
||||
doReturn(new ArrayList<NodeRef>()).when(holdService).heldBy(recordFolder, true);
|
||||
return null;
|
||||
}
|
||||
|
||||
}).when(mockedNodeService).removeChild(hold2, recordFolder);
|
||||
|
||||
// define interactions
|
||||
doReturn(holds).when(holdService).heldBy(recordFolder, true);
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
|
||||
|
||||
// remove record folder from all holds
|
||||
holdService.removeFromAllHolds(recordFolder);
|
||||
|
||||
// verify interactions
|
||||
verify(mockedNodeService, times(1)).removeChild(hold, recordFolder);
|
||||
verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder);
|
||||
verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN);
|
||||
verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN);
|
||||
}
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
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.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
/**
|
||||
* Hold service implementation unit test
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
public class HoldServiceImplUnitTest extends BaseUnitTest
|
||||
{
|
||||
/** test values */
|
||||
private static final String HOLD_NAME = "holdname";
|
||||
private static final String HOLD_REASON = "holdreason";
|
||||
private static final String HOLD_DESCRIPTION = "holddescription";
|
||||
|
||||
protected NodeRef holdContainer;
|
||||
protected NodeRef hold;
|
||||
protected NodeRef hold2;
|
||||
|
||||
@Spy @InjectMocks HoldServiceImpl holdService;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void before() throws Exception
|
||||
{
|
||||
super.before();
|
||||
|
||||
// setup objects used in mock interactions
|
||||
holdContainer = generateNodeRef(TYPE_HOLD_CONTAINER);
|
||||
hold = generateNodeRef(TYPE_HOLD);
|
||||
hold2 = generateNodeRef(TYPE_HOLD);
|
||||
|
||||
// setup interactions
|
||||
doReturn(holdContainer).when(mockedFilePlanService).getHoldContainer(filePlan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isHold()
|
||||
{
|
||||
assertTrue(holdService.isHold(hold));
|
||||
assertFalse(holdService.isHold(recordFolder));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heldByMultipleResults()
|
||||
{
|
||||
// setup record folder in multiple holds
|
||||
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, hold2, ASSOC_FROZEN_RECORDS, recordFolder, true, 2));
|
||||
doReturn(holds).when(mockedNodeService).getParentAssocs(recordFolder, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
|
||||
|
||||
// check that both holds are found for record folder
|
||||
List<NodeRef> heldByHolds = holdService.heldBy(recordFolder, true);
|
||||
assertNotNull(heldByHolds);
|
||||
assertEquals(2, heldByHolds.size());
|
||||
assertTrue(holdService.heldBy(recordFolder, false).isEmpty());
|
||||
|
||||
// check that both holds are found for record (even thou they are one level deep)
|
||||
heldByHolds = holdService.heldBy(record, true);
|
||||
assertNotNull(heldByHolds);
|
||||
assertEquals(2, heldByHolds.size());
|
||||
assertTrue(holdService.heldBy(record, false).isEmpty());
|
||||
}
|
||||
|
||||
@Test (expected=AlfrescoRuntimeException.class)
|
||||
public void getHold()
|
||||
{
|
||||
// setup node service interactions
|
||||
when(mockedNodeService.getChildByName(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), anyString())).thenReturn(null)
|
||||
.thenReturn(hold)
|
||||
.thenReturn(recordFolder);
|
||||
|
||||
// no hold
|
||||
NodeRef noHold = holdService.getHold(filePlan, "notAHold");
|
||||
assertNull(noHold);
|
||||
|
||||
// found hold
|
||||
NodeRef someHold = holdService.getHold(filePlan, "someHold");
|
||||
assertNotNull(someHold);
|
||||
assertEquals(TYPE_HOLD, mockedNodeService.getType(someHold));
|
||||
|
||||
// ensure runtime exception is thrown
|
||||
holdService.getHold(filePlan, "notHold");
|
||||
}
|
||||
|
||||
@Test (expected=RuntimeException.class)
|
||||
public void getHeldNotAHold()
|
||||
{
|
||||
holdService.getHeld(recordFolder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHeldNoResults()
|
||||
{
|
||||
assertTrue(holdService.getHeld(hold).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHeldWithResults()
|
||||
{
|
||||
// setup record folder in hold
|
||||
List<ChildAssociationRef> holds = new ArrayList<ChildAssociationRef>(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);
|
||||
|
||||
List<NodeRef> list = holdService.getHeld(hold);
|
||||
assertEquals(1, list.size());
|
||||
assertEquals(recordFolder, list.get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void createHold()
|
||||
{
|
||||
// setup node service interactions
|
||||
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));
|
||||
|
||||
// create hold
|
||||
NodeRef newHold = holdService.createHold(filePlan, HOLD_NAME, HOLD_REASON, HOLD_DESCRIPTION);
|
||||
assertNotNull(newHold);
|
||||
assertEquals(TYPE_HOLD, mockedNodeService.getType(newHold));
|
||||
assertEquals(hold, newHold);
|
||||
|
||||
// check the node service interactions
|
||||
ArgumentCaptor<Map> propertyMapCaptor = ArgumentCaptor.forClass(Map.class);
|
||||
ArgumentCaptor<QName> assocNameCaptor = ArgumentCaptor.forClass(QName.class);
|
||||
verify(mockedNodeService).createNode(eq(holdContainer), eq(ContentModel.ASSOC_CONTAINS), assocNameCaptor.capture() , eq(TYPE_HOLD), propertyMapCaptor.capture());
|
||||
|
||||
// check property map
|
||||
Map<QName, Serializable> propertyMap = (Map<QName, Serializable>)propertyMapCaptor.getValue();
|
||||
assertNotNull(propertyMap);
|
||||
assertEquals(3, propertyMap.size());
|
||||
assertTrue(propertyMap.containsKey(ContentModel.PROP_NAME));
|
||||
assertEquals(HOLD_NAME, propertyMap.get(ContentModel.PROP_NAME));
|
||||
assertTrue(propertyMap.containsKey(ContentModel.PROP_DESCRIPTION));
|
||||
assertEquals(HOLD_DESCRIPTION, propertyMap.get(ContentModel.PROP_DESCRIPTION));
|
||||
assertTrue(propertyMap.containsKey(PROP_HOLD_REASON));
|
||||
assertEquals(HOLD_REASON, propertyMap.get(PROP_HOLD_REASON));
|
||||
|
||||
// check assoc name
|
||||
assertNotNull(assocNameCaptor.getValue());
|
||||
assertEquals(NamespaceService.CONTENT_MODEL_1_0_URI, assocNameCaptor.getValue().getNamespaceURI());
|
||||
assertEquals(HOLD_NAME, assocNameCaptor.getValue().getLocalName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHoldReason()
|
||||
{
|
||||
// setup node service interactions
|
||||
when(mockedNodeService.exists(hold))
|
||||
.thenReturn(false)
|
||||
.thenReturn(true)
|
||||
.thenReturn(true)
|
||||
.thenReturn(true);
|
||||
when(mockedNodeService.getProperty(eq(hold), eq(PROP_HOLD_REASON)))
|
||||
.thenReturn(null)
|
||||
.thenReturn(HOLD_REASON);
|
||||
|
||||
// node does not exist
|
||||
assertNull(holdService.getHoldReason(hold));
|
||||
|
||||
// node isn't a hold
|
||||
assertNull(holdService.getHoldReason(recordFolder));
|
||||
|
||||
// hold reason isn't set
|
||||
assertNull(holdService.getHoldReason(hold));
|
||||
|
||||
// hold reason set
|
||||
assertEquals(HOLD_REASON, holdService.getHoldReason(hold));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHoldReason()
|
||||
{
|
||||
// setup node service interactions
|
||||
when(mockedNodeService.exists(hold))
|
||||
.thenReturn(false)
|
||||
.thenReturn(true)
|
||||
.thenReturn(true);
|
||||
|
||||
// node does not exist
|
||||
holdService.setHoldReason(hold, HOLD_REASON);
|
||||
verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON);
|
||||
|
||||
// node isn't a hold
|
||||
holdService.setHoldReason(recordFolder, HOLD_REASON);
|
||||
verify(mockedNodeService, never()).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON);
|
||||
|
||||
// set hold reason
|
||||
holdService.setHoldReason(hold, HOLD_REASON);
|
||||
verify(mockedNodeService).setProperty(hold, PROP_HOLD_REASON, HOLD_REASON);
|
||||
}
|
||||
|
||||
@Test (expected=AlfrescoRuntimeException.class)
|
||||
public void deleteHoldNotAHold()
|
||||
{
|
||||
holdService.deleteHold(recordFolder);
|
||||
verify(mockedNodeService, never()).deleteNode(hold);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteHold()
|
||||
{
|
||||
// delete hold
|
||||
holdService.deleteHold(hold);
|
||||
verify(mockedNodeService).deleteNode(hold);
|
||||
|
||||
// TODO check interactions with policy component!!!
|
||||
}
|
||||
|
||||
@Test (expected=AlfrescoRuntimeException.class)
|
||||
public void addToHoldNotAHold()
|
||||
{
|
||||
holdService.addToHold(recordFolder, recordFolder);
|
||||
}
|
||||
|
||||
@Test (expected=AlfrescoRuntimeException.class)
|
||||
public void addToHoldNotARecordFolderOrRecord()
|
||||
{
|
||||
NodeRef anotherThing = generateNodeRef(TYPE_RECORD_CATEGORY);
|
||||
holdService.addToHold(hold, anotherThing);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void addToHoldNotInHold()
|
||||
{
|
||||
holdService.addToHold(hold, recordFolder);
|
||||
|
||||
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(record), eq(ASPECT_FROZEN), any(Map.class));
|
||||
verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString());
|
||||
|
||||
holdService.addToHold(hold, record);
|
||||
verify(mockedNodeService).addChild(hold, record, ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_RECORDS);
|
||||
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(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(record), anyString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void addToHoldAlreadyInHold()
|
||||
{
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
|
||||
|
||||
holdService.addToHold(hold, recordFolder);
|
||||
|
||||
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(record), eq(ASPECT_FROZEN), any(Map.class));
|
||||
verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void addToHoldAldeadyFrozen()
|
||||
{
|
||||
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
|
||||
|
||||
holdService.addToHold(hold, recordFolder);
|
||||
|
||||
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(record), eq(ASPECT_FROZEN), any(Map.class));
|
||||
verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void addToHolds()
|
||||
{
|
||||
// ensure the interaction indicates that a node has the frozen aspect applied if it has
|
||||
doAnswer(new Answer<Void>()
|
||||
{
|
||||
public Void answer(InvocationOnMock invocation)
|
||||
{
|
||||
NodeRef nodeRef = (NodeRef)invocation.getArguments()[0];
|
||||
doReturn(true).when(mockedNodeService).hasAspect(nodeRef, ASPECT_FROZEN);
|
||||
return null;
|
||||
}
|
||||
|
||||
}).when(mockedNodeService).addAspect(any(NodeRef.class), eq(ASPECT_FROZEN), any(Map.class));
|
||||
|
||||
// build a list of holds
|
||||
List<NodeRef> holds = new ArrayList<NodeRef>(2);
|
||||
holds.add(hold);
|
||||
holds.add(hold2);
|
||||
|
||||
// add the record folder to both holds
|
||||
holdService.addToHolds(holds, recordFolder);
|
||||
|
||||
// verify the interactions
|
||||
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)).addAspect(eq(recordFolder), 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());
|
||||
}
|
||||
|
||||
@Test (expected=AlfrescoRuntimeException.class)
|
||||
public void removeFromHoldNotAHold()
|
||||
{
|
||||
holdService.removeFromHold(recordFolder, recordFolder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeFromHoldNotInHold()
|
||||
{
|
||||
holdService.removeFromHold(hold, recordFolder);
|
||||
|
||||
verify(mockedNodeService, never()).removeChild(hold, recordFolder);
|
||||
verify(mockedNodeService, never()).removeAspect(recordFolder, ASPECT_FROZEN);
|
||||
verify(mockedNodeService, never()).removeAspect(record, ASPECT_FROZEN);
|
||||
verify(mockedRecordsManagementAuditService, never()).auditEvent(eq(recordFolder), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeFromHold()
|
||||
{
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
|
||||
|
||||
holdService.removeFromHold(hold, recordFolder);
|
||||
|
||||
verify(mockedNodeService, times(1)).removeChild(hold, recordFolder);
|
||||
verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN);
|
||||
verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN);
|
||||
verify(mockedRecordsManagementAuditService, times(1)).auditEvent(eq(recordFolder), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeFromHolds()
|
||||
{
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
|
||||
|
||||
// build a list of holds
|
||||
List<NodeRef> holds = new ArrayList<NodeRef>(2);
|
||||
holds.add(hold);
|
||||
holds.add(hold2);
|
||||
|
||||
holdService.removeFromHolds(holds, recordFolder);
|
||||
|
||||
verify(mockedNodeService, times(1)).removeChild(hold, recordFolder);
|
||||
verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder);
|
||||
verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN);
|
||||
verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN);
|
||||
verify(mockedRecordsManagementAuditService, times(2)).auditEvent(any(NodeRef.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeFromAllHolds()
|
||||
{
|
||||
// build a list of holds
|
||||
List<NodeRef> holds = new ArrayList<NodeRef>(2);
|
||||
holds.add(hold);
|
||||
holds.add(hold2);
|
||||
|
||||
doAnswer(new Answer<Void>()
|
||||
{
|
||||
public Void answer(InvocationOnMock invocation)
|
||||
{
|
||||
doReturn(Collections.singletonList(hold2)).when(holdService).heldBy(recordFolder, true);
|
||||
return null;
|
||||
}
|
||||
|
||||
}).when(mockedNodeService).removeChild(hold, recordFolder);
|
||||
|
||||
doAnswer(new Answer<Void>()
|
||||
{
|
||||
public Void answer(InvocationOnMock invocation)
|
||||
{
|
||||
doReturn(new ArrayList<NodeRef>()).when(holdService).heldBy(recordFolder, true);
|
||||
return null;
|
||||
}
|
||||
|
||||
}).when(mockedNodeService).removeChild(hold2, recordFolder);
|
||||
|
||||
// define interactions
|
||||
doReturn(holds).when(holdService).heldBy(recordFolder, true);
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold);
|
||||
doReturn(Collections.singletonList(recordFolder)).when(holdService).getHeld(hold2);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(recordFolder, ASPECT_FROZEN);
|
||||
doReturn(true).when(mockedNodeService).hasAspect(record, ASPECT_FROZEN);
|
||||
|
||||
// remove record folder from all holds
|
||||
holdService.removeFromAllHolds(recordFolder);
|
||||
|
||||
// verify interactions
|
||||
verify(mockedNodeService, times(1)).removeChild(hold, recordFolder);
|
||||
verify(mockedNodeService, times(1)).removeChild(hold2, recordFolder);
|
||||
verify(mockedNodeService, times(1)).removeAspect(recordFolder, ASPECT_FROZEN);
|
||||
verify(mockedNodeService, times(1)).removeAspect(record, ASPECT_FROZEN);
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.model.compatibility;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
|
||||
/**
|
||||
* Dictionary bootstrap post processor unit test.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
public class DictionaryBootstrapPostProcessorUnitTest extends BaseUnitTest
|
||||
{
|
||||
/** bean id's */
|
||||
private static final String BEAN_SITESERVICE_BOOTSTRAP = "siteService_dictionaryBootstrap";
|
||||
private static final String BEAN_RM_DICTIONARY_BOOTSTRAP = "org_alfresco_module_rm_dictionaryBootstrap";
|
||||
|
||||
@Mock private ConfigurableListableBeanFactory mockedBeanFactory;
|
||||
@Mock private BeanDefinition mockedBeanDefinition;
|
||||
|
||||
@InjectMocks private DictionaryBootstrapPostProcessor postProcessor;
|
||||
|
||||
/**
|
||||
* given the bean factory does not contain the site service bootstrap bean then ensure that it is
|
||||
* not added as a dependency
|
||||
*/
|
||||
@Test
|
||||
public void noSiteServiceBootstrapBeanAvailable()
|
||||
{
|
||||
// === given ====
|
||||
doReturn(false).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||
|
||||
// === when ===
|
||||
postProcessor.postProcessBeanFactory(mockedBeanFactory);
|
||||
|
||||
// === then ===
|
||||
verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||
verifyNoMoreInteractions(mockedBeanFactory);
|
||||
verifyZeroInteractions(mockedBeanDefinition);
|
||||
}
|
||||
|
||||
/**
|
||||
* given that the site service bootstrap bean is contained within the bean factory, ensure that
|
||||
* it is added as a dependency
|
||||
*/
|
||||
@Test
|
||||
public void siteServiceBootstrapBeanAvailable()
|
||||
{
|
||||
// === given ====
|
||||
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||
doReturn(mockedBeanDefinition).when(mockedBeanFactory).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||
|
||||
// === when ===
|
||||
postProcessor.postProcessBeanFactory(mockedBeanFactory);
|
||||
|
||||
// === then ===
|
||||
verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||
verify(mockedBeanFactory, times(1)).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||
|
||||
verify(mockedBeanFactory, times(1)).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||
verify(mockedBeanDefinition, times(1)).setDependsOn(new String[]{BEAN_SITESERVICE_BOOTSTRAP});
|
||||
|
||||
verifyNoMoreInteractions(mockedBeanFactory, mockedBeanDefinition);
|
||||
|
||||
}
|
||||
}
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.model.compatibility;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
|
||||
/**
|
||||
* Dictionary bootstrap post processor unit test.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
public class DictionaryBootstrapPostProcessorUnitTest extends BaseUnitTest
|
||||
{
|
||||
/** bean id's */
|
||||
private static final String BEAN_SITESERVICE_BOOTSTRAP = "siteService_dictionaryBootstrap";
|
||||
private static final String BEAN_RM_DICTIONARY_BOOTSTRAP = "org_alfresco_module_rm_dictionaryBootstrap";
|
||||
|
||||
@Mock private ConfigurableListableBeanFactory mockedBeanFactory;
|
||||
@Mock private BeanDefinition mockedBeanDefinition;
|
||||
|
||||
@InjectMocks private DictionaryBootstrapPostProcessor postProcessor;
|
||||
|
||||
/**
|
||||
* given the bean factory does not contain the site service bootstrap bean then ensure that it is
|
||||
* not added as a dependency
|
||||
*/
|
||||
@Test
|
||||
public void noSiteServiceBootstrapBeanAvailable()
|
||||
{
|
||||
// === given ====
|
||||
doReturn(false).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||
|
||||
// === when ===
|
||||
postProcessor.postProcessBeanFactory(mockedBeanFactory);
|
||||
|
||||
// === then ===
|
||||
verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||
verifyNoMoreInteractions(mockedBeanFactory);
|
||||
verifyZeroInteractions(mockedBeanDefinition);
|
||||
}
|
||||
|
||||
/**
|
||||
* given that the site service bootstrap bean is contained within the bean factory, ensure that
|
||||
* it is added as a dependency
|
||||
*/
|
||||
@Test
|
||||
public void siteServiceBootstrapBeanAvailable()
|
||||
{
|
||||
// === given ====
|
||||
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||
doReturn(true).when(mockedBeanFactory).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||
doReturn(mockedBeanDefinition).when(mockedBeanFactory).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||
|
||||
// === when ===
|
||||
postProcessor.postProcessBeanFactory(mockedBeanFactory);
|
||||
|
||||
// === then ===
|
||||
verify(mockedBeanFactory, times(1)).containsBean(BEAN_SITESERVICE_BOOTSTRAP);
|
||||
verify(mockedBeanFactory, times(1)).containsBean(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||
|
||||
verify(mockedBeanFactory, times(1)).getBeanDefinition(BEAN_RM_DICTIONARY_BOOTSTRAP);
|
||||
verify(mockedBeanDefinition, times(1)).setDependsOn(new String[]{BEAN_SITESERVICE_BOOTSTRAP});
|
||||
|
||||
verifyNoMoreInteractions(mockedBeanFactory, mockedBeanDefinition);
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user