diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/IntegrationTestSuite.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/IntegrationTestSuite.java index e1ff74ced6..9fa35377a8 100755 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/IntegrationTestSuite.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/IntegrationTestSuite.java @@ -22,6 +22,7 @@ import org.alfresco.module.org_alfresco_module_rm.test.integration.disposition.D import org.alfresco.module.org_alfresco_module_rm.test.integration.dod.DoD5015TestSuite; import org.alfresco.module.org_alfresco_module_rm.test.integration.event.EventTestSuite; import org.alfresco.module.org_alfresco_module_rm.test.integration.issue.IssueTestSuite; +import org.alfresco.module.org_alfresco_module_rm.test.integration.job.JobTestSuite; import org.alfresco.module.org_alfresco_module_rm.test.integration.record.RecordTestSuite; import org.alfresco.module.org_alfresco_module_rm.test.integration.recordfolder.RecordFolderTestSuite; import org.alfresco.module.org_alfresco_module_rm.test.integration.report.ReportTestSuite; @@ -45,7 +46,8 @@ import org.junit.runners.Suite.SuiteClasses; ReportTestSuite.class, DispositionTestSuite.class, RecordTestSuite.class, - RecordFolderTestSuite.class + RecordFolderTestSuite.class, + JobTestSuite.class }) public class IntegrationTestSuite { diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/event/CompleteEventsTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/event/CompleteEventsTest.java index 80620326f7..8be49d0b3e 100755 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/event/CompleteEventsTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/event/CompleteEventsTest.java @@ -72,7 +72,7 @@ public class CompleteEventsTest extends BaseRMTestCase // file record record = utils.createRecord(recordFolder, GUID.generate(), "title"); - utils.declareRecord(record); + utils.completeRecord(record); } public void when() @@ -128,7 +128,7 @@ public class CompleteEventsTest extends BaseRMTestCase // file record NodeRef record = utils.createRecord(recordFolder, GUID.generate(), "title"); - utils.declareRecord(record); + utils.completeRecord(record); } @@ -194,7 +194,7 @@ public class CompleteEventsTest extends BaseRMTestCase // file record NodeRef record = utils.createRecord(recordFolder, GUID.generate(), "title"); - utils.declareRecord(record); + utils.completeRecord(record); } public void when() @@ -267,7 +267,7 @@ public class CompleteEventsTest extends BaseRMTestCase // file record NodeRef record = utils.createRecord(recordFolder, GUID.generate(), "title"); - utils.declareRecord(record); + utils.completeRecord(record); } public void when() @@ -338,7 +338,7 @@ public class CompleteEventsTest extends BaseRMTestCase // file record NodeRef record = utils.createRecord(recordFolder, GUID.generate(), "title"); - utils.declareRecord(record); + utils.completeRecord(record); } public void when() @@ -409,7 +409,7 @@ public class CompleteEventsTest extends BaseRMTestCase // file record String recordName = GUID.generate(); record = utils.createRecord(recordFolder, recordName, "title"); - utils.declareRecord(record); + utils.completeRecord(record); // link record to second record folder nodeService.addChild(recordFolder2, record, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, recordName)); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/job/AutomaticDispositionTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/job/AutomaticDispositionTest.java new file mode 100644 index 0000000000..b36e258e35 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/job/AutomaticDispositionTest.java @@ -0,0 +1,105 @@ +/* + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.test.integration.job; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.module.org_alfresco_module_rm.action.impl.CutOffAction; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; +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.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; +import org.springframework.extensions.webscripts.GUID; + +/** + * Test automatic disposition via scheduled job. + * + * @author Roy Wetherall + * @since 2.2 + */ +public class AutomaticDispositionTest extends BaseRMTestCase +{ + /** additional job context to override job frequency */ + protected String[] getConfigLocations() + { + return new String[] + { + "classpath:alfresco/application-context.xml", + "classpath:test-context.xml", + "classpath:test-job-context.xml" + }; + } + + /** + * Given there is a complete record eligible for cut off, when the correct frequency of time passes, then + * the record will be automatically cut off + */ + public void testAutomaticCutOff() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + NodeRef sourceCategory; + NodeRef sourceRecordFolder; + NodeRef record; + + public void given() + { + // create test data + sourceCategory = filePlanService.createRecordCategory(filePlan, GUID.generate()); + DispositionSchedule dis = utils.createBasicDispositionSchedule(sourceCategory, GUID.generate(), GUID.generate(), true, false); + Map adParams = new HashMap(3); + adParams.put(PROP_DISPOSITION_ACTION_NAME, CutOffAction.NAME); + adParams.put(PROP_DISPOSITION_DESCRIPTION, GUID.generate()); + adParams.put(PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_IMMEDIATELY); + dispositionService.addDispositionActionDefinition(dis, adParams); + sourceRecordFolder = recordFolderService.createRecordFolder(sourceCategory, GUID.generate()); + + // create and complete record + record = utils.createRecord(sourceRecordFolder, GUID.generate()); + utils.completeRecord(record); + + // check the disposition action details + DispositionAction dispositionAction = dispositionService.getNextDispositionAction(record); + assertNotNull(dispositionAction); + assertNotNull(CutOffAction.NAME, dispositionAction.getName()); + assertTrue(dispositionService.isNextDispositionActionEligible(record)); + } + + public void when() throws Exception + { + // sleep .. allowing the job time to execute + Thread.sleep(30000); + } + + public void then() + { + // record should now be cut off + assertTrue(dispositionService.isDisposableItemCutoff(record)); + } + }); + } + + // TODO automatic retain + + // TODO automatic destroy +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/job/JobTestSuite.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/job/JobTestSuite.java new file mode 100644 index 0000000000..12022f2cf2 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/job/JobTestSuite.java @@ -0,0 +1,38 @@ +/* + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.test.integration.job; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +/** + * Job integration test suite + * + * @author Roy Wetherall + * @since 2.2 + */ +@RunWith(Suite.class) +@SuiteClasses( +{ + AutomaticDispositionTest.class +}) +public class JobTestSuite +{ +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/capabilities/CompositeCapabilityTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/capabilities/CompositeCapabilityTest.java index f00308cfd2..34678071b9 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/capabilities/CompositeCapabilityTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/capabilities/CompositeCapabilityTest.java @@ -64,7 +64,7 @@ public class CompositeCapabilityTest extends BaseRMTestCase { AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - utils.declareRecord(declaredRecord); + utils.completeRecord(declaredRecord); return null; } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/capabilities/DeclarativeCapabilityTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/capabilities/DeclarativeCapabilityTest.java index 1a922cbea0..6581d3a800 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/capabilities/DeclarativeCapabilityTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/capabilities/DeclarativeCapabilityTest.java @@ -106,9 +106,9 @@ public class DeclarativeCapabilityTest extends BaseRMTestCase { AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - utils.declareRecord(declaredRecord); - utils.declareRecord(frozenRecord); - utils.declareRecord(frozenRecord2); + utils.completeRecord(declaredRecord); + utils.completeRecord(frozenRecord); + utils.completeRecord(frozenRecord2); hold = holdService.createHold(filePlan, GUID.generate(), "reason", "description"); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAdminServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAdminServiceImplTest.java index 30602da5b3..fe6c63716a 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAdminServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementAdminServiceImplTest.java @@ -563,8 +563,8 @@ public class RecordsManagementAdminServiceImplTest extends BaseRMTestCase { public QName execute() throws Throwable { - utils.declareRecord(testRecord1); - utils.declareRecord(testRecord2); + utils.completeRecord(testRecord1); + utils.completeRecord(testRecord2); Map params = new HashMap(); params.put("referenceType", refType.toString()); @@ -755,8 +755,8 @@ public class RecordsManagementAdminServiceImplTest extends BaseRMTestCase { public Void execute() throws Throwable { - utils.declareRecord(testRecord1); - utils.declareRecord(testRecord2); + utils.completeRecord(testRecord1); + utils.completeRecord(testRecord2); policyComponent.bindClassBehaviour( RecordsManagementPolicies.BEFORE_CREATE_REFERENCE, diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java index 454a2f3deb..fc80f82ff6 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java @@ -89,11 +89,15 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase implements RecordsManagementModel, ContentModel, RMPermissionModel { /** Application context */ - protected static final String[] CONFIG_LOCATIONS = new String[] + protected String[] getConfigLocations() { - "classpath:alfresco/application-context.xml", - "classpath:test-context.xml" - }; + return new String[] + { + "classpath:alfresco/application-context.xml", + "classpath:test-context.xml", + "classpath:test-job-context.xml" + }; + } protected ApplicationContext applicationContext; /** test model constants */ @@ -310,7 +314,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase protected void setUp() throws Exception { // Get the application context - applicationContext = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS); + applicationContext = ApplicationContextHelper.getApplicationContext(getConfigLocations()); utils = new CommonRMTestUtils(applicationContext); // Initialise the service beans @@ -484,8 +488,8 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase if (isRecordTest()) { // declare a record - utils.declareRecord(recordDeclaredOne); - utils.declareRecord(recordDeclaredTwo); + utils.completeRecord(recordDeclaredOne); + utils.completeRecord(recordDeclaredTwo); } // unfiled container diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java index 65c67165b2..51d8f9dfa8 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java @@ -227,7 +227,10 @@ public class CommonRMTestUtils implements RecordsManagementModel return recordOne; } - public void declareRecord(final NodeRef record) + /** + * Helper method to complete record. + */ + public void completeRecord(final NodeRef record) { AuthenticationUtil.runAs(new RunAsWork() { diff --git a/rm-server/test/resources/test-job-context.xml b/rm-server/test/resources/test-job-context.xml new file mode 100644 index 0000000000..2cfee8877d --- /dev/null +++ b/rm-server/test/resources/test-job-context.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + 0/30 * * * * ? + + + + \ No newline at end of file