mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
RM-3386 Integration test to check that updating the disposition period works.
This test is the scenario given in the bug report. Create a record that has a next disposition step in a year. Update the step to be three years, and check that the record's 'disposition as of' date is updated accordingly.
This commit is contained in:
@@ -31,7 +31,8 @@ import org.junit.runners.Suite.SuiteClasses;
|
|||||||
@RunWith(Suite.class)
|
@RunWith(Suite.class)
|
||||||
@SuiteClasses(
|
@SuiteClasses(
|
||||||
{
|
{
|
||||||
CutOffTest.class
|
CutOffTest.class,
|
||||||
|
UpdateDispositionScheduleTest.class
|
||||||
})
|
})
|
||||||
public class DispositionTestSuite
|
public class DispositionTestSuite
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1,164 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.module.org_alfresco_module_rm.test.integration.disposition;
|
||||||
|
|
||||||
|
import static org.alfresco.module.org_alfresco_module_rm.test.util.bdt.BehaviourTest.test;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
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.disposition.DispositionActionDefinition;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.job.publish.DispositionActionDefinitionPublishExecutor;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.test.util.bdt.BehaviourTest;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.alfresco.util.ApplicationContextHelper;
|
||||||
|
import org.springframework.extensions.webscripts.GUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration tests for updating the disposition schedule.
|
||||||
|
*
|
||||||
|
* @author Tom Page
|
||||||
|
* @since 2.3.1
|
||||||
|
*/
|
||||||
|
public class UpdateDispositionScheduleTest extends BaseRMTestCase
|
||||||
|
{
|
||||||
|
/** A unique prefix for the constants in this test. */
|
||||||
|
protected static final String TEST_PREFIX = UpdateDispositionScheduleTest.class.getName() + GUID.generate() + "_";
|
||||||
|
/** The name to use for the category. */
|
||||||
|
protected static final String CATEGORY_NAME = TEST_PREFIX + "Category";
|
||||||
|
/** The name to use for the folder. */
|
||||||
|
protected static final String FOLDER_NAME = TEST_PREFIX + "Folder";
|
||||||
|
/** The name to use for the record. */
|
||||||
|
protected static final String RECORD_NAME = TEST_PREFIX + "Record";
|
||||||
|
|
||||||
|
/** The executor for the disposition update job. */
|
||||||
|
private DispositionActionDefinitionPublishExecutor dispositionActionDefinitionPublishExecutor;
|
||||||
|
/** The internal disposition service is used to avoid permissions issues when updating the record. */
|
||||||
|
private DispositionService internalDispositionService;
|
||||||
|
|
||||||
|
/** The category node. */
|
||||||
|
private NodeRef category;
|
||||||
|
/** The folder node. */
|
||||||
|
private NodeRef folder;
|
||||||
|
/** The record node. */
|
||||||
|
private NodeRef record;
|
||||||
|
/** The 'disposition as of' date from before the 'when' step. */
|
||||||
|
private Date originalAsOfDate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
BehaviourTest.initBehaviourTests(retryingTransactionHelper);
|
||||||
|
|
||||||
|
// Get the application context
|
||||||
|
applicationContext = ApplicationContextHelper.getApplicationContext(getConfigLocations());
|
||||||
|
dispositionActionDefinitionPublishExecutor = applicationContext.getBean(DispositionActionDefinitionPublishExecutor.class);
|
||||||
|
internalDispositionService = (DispositionService) applicationContext.getBean("dispositionService");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <a href="https://issues.alfresco.com/jira/browse/RM-3386">RM-3386</a>
|
||||||
|
* <p><pre>
|
||||||
|
* Given a record subject to a disposition schedule
|
||||||
|
* And the next step is due to run at some period after the date the content was created
|
||||||
|
* When I update the period of the next step (and wait for this to be processed)
|
||||||
|
* Then the "as of" date is updated to be at the new period after the creation date.
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public void testUpdatePeriod()
|
||||||
|
{
|
||||||
|
test()
|
||||||
|
.given(() -> {
|
||||||
|
// Create a category.
|
||||||
|
category = filePlanService.createRecordCategory(filePlan, CATEGORY_NAME);
|
||||||
|
// Create a disposition schedule for the category (Cut off immediately, then Destroy 1 year after the creation date).
|
||||||
|
DispositionSchedule dispSched = utils.createBasicDispositionSchedule(category, "instructions", "authority", true, false);
|
||||||
|
Map<QName, Serializable> cutOffParams = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, CutOffAction.NAME,
|
||||||
|
PROP_DISPOSITION_DESCRIPTION, "description",
|
||||||
|
PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_IMMEDIATELY);
|
||||||
|
dispositionService.addDispositionActionDefinition(dispSched, cutOffParams);
|
||||||
|
Map<QName, Serializable> destroyParams = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, DestroyAction.NAME,
|
||||||
|
PROP_DISPOSITION_DESCRIPTION, "description",
|
||||||
|
PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_ONE_YEAR,
|
||||||
|
PROP_DISPOSITION_PERIOD_PROPERTY, ContentModel.PROP_CREATED);
|
||||||
|
dispositionService.addDispositionActionDefinition(dispSched, destroyParams);
|
||||||
|
// Create a folder containing a record within the category.
|
||||||
|
folder = recordFolderService.createRecordFolder(category, FOLDER_NAME);
|
||||||
|
record = fileFolderService.create(folder, RECORD_NAME, ContentModel.TYPE_CONTENT).getNodeRef();
|
||||||
|
|
||||||
|
dispositionService.cutoffDisposableItem(record);
|
||||||
|
// Ensure the update has been applied to the record.
|
||||||
|
internalDispositionService.updateNextDispositionAction(record);
|
||||||
|
|
||||||
|
originalAsOfDate = dispositionService.getNextDispositionAction(record).getAsOfDate();
|
||||||
|
})
|
||||||
|
.when(() -> {
|
||||||
|
// Update the Destroy step to be 3 years after the creation date.
|
||||||
|
DispositionSchedule dispSched = dispositionService.getDispositionSchedule(category);
|
||||||
|
DispositionActionDefinition destroy = dispSched.getDispositionActionDefinitionByName(DestroyAction.NAME);
|
||||||
|
Map<QName, Serializable> destroyParams = ImmutableMap.of(PROP_DISPOSITION_ACTION_NAME, DestroyAction.NAME,
|
||||||
|
PROP_DISPOSITION_DESCRIPTION, "description",
|
||||||
|
PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_THREE_YEARS,
|
||||||
|
PROP_DISPOSITION_PERIOD_PROPERTY, ContentModel.PROP_CREATED);
|
||||||
|
dispositionService.updateDispositionActionDefinition(destroy, destroyParams);
|
||||||
|
|
||||||
|
// Make the disposition action definition update job run.
|
||||||
|
dispositionActionDefinitionPublishExecutor.publish(destroy.getNodeRef());
|
||||||
|
})
|
||||||
|
.then()
|
||||||
|
.expect(true)
|
||||||
|
.from(() -> aboutTwoYearsApart(originalAsOfDate, dispositionService.getNextDispositionAction(record).getAsOfDate()))
|
||||||
|
.because("Increasing the destroy period by two years should increase the 'as of' date by two years.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the two given dates are approximately two years apart.
|
||||||
|
* <p>
|
||||||
|
* This actually just checks that they're more than one and less than three years apart, because leap years make
|
||||||
|
* things hard to calculate.
|
||||||
|
*
|
||||||
|
* @return true if the two dates are about two years apart.
|
||||||
|
*/
|
||||||
|
private boolean aboutTwoYearsApart(Date start, Date end)
|
||||||
|
{
|
||||||
|
long days = daysBetween(start, end);
|
||||||
|
long yearInDays = 365;
|
||||||
|
return (yearInDays < days) && (days < 3 * yearInDays);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Find the number of days between the two dates. */
|
||||||
|
private long daysBetween(Date start, Date end)
|
||||||
|
{
|
||||||
|
return TimeUnit.MILLISECONDS.toDays(end.getTime() - start.getTime());
|
||||||
|
}
|
||||||
|
}
|
@@ -56,7 +56,7 @@ import org.springframework.context.ApplicationContext;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Common RM test utility methods.
|
* Common RM test utility methods.
|
||||||
*
|
*
|
||||||
* @author Roy Wetherall
|
* @author Roy Wetherall
|
||||||
*/
|
*/
|
||||||
public class CommonRMTestUtils implements RecordsManagementModel
|
public class CommonRMTestUtils implements RecordsManagementModel
|
||||||
@@ -76,10 +76,12 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
public static final String DEFAULT_EVENT_NAME = "case_closed";
|
public static final String DEFAULT_EVENT_NAME = "case_closed";
|
||||||
public static final String PERIOD_NONE = "none|0";
|
public static final String PERIOD_NONE = "none|0";
|
||||||
public static final String PERIOD_IMMEDIATELY = "immediately|0";
|
public static final String PERIOD_IMMEDIATELY = "immediately|0";
|
||||||
|
public static final String PERIOD_ONE_YEAR = "year|1";
|
||||||
|
public static final String PERIOD_THREE_YEARS = "year|3";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param applicationContext application context
|
* @param applicationContext application context
|
||||||
*/
|
*/
|
||||||
public CommonRMTestUtils(ApplicationContext applicationContext)
|
public CommonRMTestUtils(ApplicationContext applicationContext)
|
||||||
@@ -95,7 +97,7 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a disposition schedule
|
* Create a disposition schedule
|
||||||
*
|
*
|
||||||
* @param container record category
|
* @param container record category
|
||||||
* @return {@link DispositionSchedule} created disposition schedule node reference
|
* @return {@link DispositionSchedule} created disposition schedule node reference
|
||||||
*/
|
*/
|
||||||
@@ -129,15 +131,15 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
boolean extendedDispositionSchedule)
|
boolean extendedDispositionSchedule)
|
||||||
{
|
{
|
||||||
return createDispositionSchedule(
|
return createDispositionSchedule(
|
||||||
container,
|
container,
|
||||||
dispositionInstructions,
|
dispositionInstructions,
|
||||||
dispositionAuthority,
|
dispositionAuthority,
|
||||||
isRecordLevel,
|
isRecordLevel,
|
||||||
defaultDispositionActions,
|
defaultDispositionActions,
|
||||||
extendedDispositionSchedule,
|
extendedDispositionSchedule,
|
||||||
DEFAULT_EVENT_NAME);
|
DEFAULT_EVENT_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create test disposition schedule
|
* Create test disposition schedule
|
||||||
*/
|
*/
|
||||||
@@ -241,8 +243,8 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
modelSecurityService.setEnabled(false);
|
modelSecurityService.setEnabled(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_FILED, new Date());
|
nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_FILED, new Date());
|
||||||
nodeService.setProperty(record, ContentModel.PROP_TITLE, "titleValue");
|
nodeService.setProperty(record, ContentModel.PROP_TITLE, "titleValue");
|
||||||
actionService.executeRecordsManagementAction(record, "declareRecord");
|
actionService.executeRecordsManagementAction(record, "declareRecord");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -255,7 +257,7 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
|
|
||||||
}, AuthenticationUtil.getAdminUserName());
|
}, AuthenticationUtil.getAdminUserName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeFolder(final NodeRef recordFolder)
|
public void closeFolder(final NodeRef recordFolder)
|
||||||
{
|
{
|
||||||
@@ -293,10 +295,10 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
|
|
||||||
return filePlanRoleService.createRole(filePlan, roleName, roleName, capabilities);
|
return filePlanRoleService.createRole(filePlan, roleName, roleName, capabilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to complete event on disposable item
|
* Helper method to complete event on disposable item
|
||||||
*
|
*
|
||||||
* @param disposableItem disposable item (record or record folder)
|
* @param disposableItem disposable item (record or record folder)
|
||||||
* @param eventName event name
|
* @param eventName event name
|
||||||
*/
|
*/
|
||||||
@@ -305,8 +307,8 @@ public class CommonRMTestUtils implements RecordsManagementModel
|
|||||||
// build action properties
|
// build action properties
|
||||||
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
|
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
|
||||||
params.put(CompleteEventAction.PARAM_EVENT_NAME, eventName);
|
params.put(CompleteEventAction.PARAM_EVENT_NAME, eventName);
|
||||||
|
|
||||||
// complete event
|
// complete event
|
||||||
actionService.executeRecordsManagementAction(disposableItem, CompleteEventAction.NAME, params);
|
actionService.executeRecordsManagementAction(disposableItem, CompleteEventAction.NAME, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user