diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/BroadcastDispositionActionDefinitionUpdateAction.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/BroadcastDispositionActionDefinitionUpdateAction.java index d4de92dd51..cf262d2ca3 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/BroadcastDispositionActionDefinitionUpdateAction.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/BroadcastDispositionActionDefinitionUpdateAction.java @@ -237,7 +237,7 @@ public class BroadcastDispositionActionDefinitionUpdateAction extends RMActionEx * @param dispositionActionDef The disposition action definition node * @param nextAction The next disposition action */ - private void persistPeriodChanges(NodeRef dispositionActionDef, DispositionAction nextAction) + protected void persistPeriodChanges(NodeRef dispositionActionDef, DispositionAction nextAction) { NodeRef dispositionedNode = getNodeService().getPrimaryParent(nextAction.getNodeRef()).getParentRef(); DispositionActionDefinition definition = nextAction.getDispositionActionDefinition(); diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/action/impl/BroadcastDispositionActionDefinitionUpdateActionUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/action/impl/BroadcastDispositionActionDefinitionUpdateActionUnitTest.java new file mode 100644 index 0000000000..2a4f2df23b --- /dev/null +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/action/impl/BroadcastDispositionActionDefinitionUpdateActionUnitTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2005-2016 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.action.impl; + +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.PROP_DISPOSITION_AS_OF; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Date; + +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link BroadcastDispositionActionDefinitionUpdateAction}. + * + * @author Tom Page + * @since 2.3.1 + */ +public class BroadcastDispositionActionDefinitionUpdateActionUnitTest +{ + /** The node under the category containing information about the definition of the action. */ + private static final NodeRef DISPOSITION_ACTION_DEF_NODE = new NodeRef("disposition://Action/Def"); + /** The node containing the details of the next disposition step for the content. */ + private static final NodeRef NEXT_ACTION_NODE_REF = new NodeRef("next://Step/"); + /** The node being subject to the disposition step. */ + private static final NodeRef CONTENT_NODE_REF = new NodeRef("content://Node/Ref"); + + /** The class under test. */ + private BroadcastDispositionActionDefinitionUpdateAction action = new BroadcastDispositionActionDefinitionUpdateAction(); + + private NodeService mockNodeService = mock(NodeService.class); + private DispositionService mockDispositionService = mock(DispositionService.class); + + /** Inject the mock services into the class under test and link the content and next action nodes. */ + @Before + public void setUp() + { + action.setNodeService(mockNodeService); + action.setDispositionService(mockDispositionService); + + ChildAssociationRef mockAssocRef = mock(ChildAssociationRef.class); + when(mockNodeService.getPrimaryParent(NEXT_ACTION_NODE_REF)).thenReturn(mockAssocRef); + when(mockAssocRef.getParentRef()).thenReturn(CONTENT_NODE_REF); + } + + /** + * Check that the disposition service is used to determine the "disposition as of" date when changes are made to the + * disposition period. + */ + @Test + public void testPersistPeriodChanges() + { + // Set up the data associated with the next disposition action. + DispositionAction mockAction = mock(DispositionAction.class); + when(mockAction.getNodeRef()).thenReturn(NEXT_ACTION_NODE_REF); + DispositionActionDefinition mockDispositionActionDefinition = mock(DispositionActionDefinition.class); + when(mockAction.getDispositionActionDefinition()).thenReturn(mockDispositionActionDefinition); + when(mockAction.getName()).thenReturn("mockAction"); + // Set up the disposition service to return a known "disposition as of" date. + Date asOfDate = new Date(); + when(mockDispositionService.calculateAsOfDate(CONTENT_NODE_REF, mockDispositionActionDefinition, false)) + .thenReturn(asOfDate); + + // Call the method under test. + action.persistPeriodChanges(DISPOSITION_ACTION_DEF_NODE, mockAction); + + // Check that the "disposition as of" date has been set on the next action. + verify(mockNodeService).setProperty(NEXT_ACTION_NODE_REF, PROP_DISPOSITION_AS_OF, asOfDate); + } +} diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionServiceImplUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionServiceImplUnitTest.java new file mode 100644 index 0000000000..8fb7ccbbb7 --- /dev/null +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionServiceImplUnitTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2005-2016 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.disposition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Date; + +import org.alfresco.model.ContentModel; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.Period; +import org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link DispositionServiceImpl}. + * + * @author Tom Page + * @since 2.3.1 + */ +public class DispositionServiceImplUnitTest +{ + /** The node being subject to the disposition step. */ + NodeRef CONTENT_NODE_REF = new NodeRef("content://node/"); + + /** The class under test. */ + private DispositionServiceImpl dispositionService = new DispositionServiceImpl(); + + private NodeService mockNodeService = mock(NodeService.class); + + @Before + public void setUp() + { + dispositionService.setNodeService(mockNodeService); + } + + /** + * Check that the relevant information is retrieved from the DispositionActionDefinition in order to determine the + * "disposition as of" date. + */ + @Test + public void testCalculateAsOfDate() + { + // Set up a mock for the disposition action definition. + DispositionActionDefinition mockDispositionActionDefinition = mock(DispositionActionDefinition.class); + Period mockPeriod = mock(Period.class); + when(mockDispositionActionDefinition.getPeriod()).thenReturn(mockPeriod); + when(mockDispositionActionDefinition.getPeriodProperty()).thenReturn(ContentModel.PROP_CREATED); + // Set up a created date and another date that is some Period later. + Date createdDate = new Date(1234567890); + when(mockNodeService.getProperty(CONTENT_NODE_REF, ContentModel.PROP_CREATED)).thenReturn(createdDate); + Date nextDate = new Date(1240000000); + when(mockPeriod.getNextDate(createdDate)).thenReturn(nextDate); + + // Call the method under test. + Date asOfDate = dispositionService.calculateAsOfDate(CONTENT_NODE_REF, mockDispositionActionDefinition, true); + + assertEquals("Unexpected calculation for 'as of' date", nextDate, asOfDate); + } + + /** Check that the calculated "disposition as of" date is null if a null period is given. */ + @Test + public void testCalculateAsOfDate_nullPeriod() + { + DispositionActionDefinition mockDispositionActionDefinition = mock(DispositionActionDefinition.class); + when(mockDispositionActionDefinition.getPeriod()).thenReturn(null); + + // Call the method under test. + Date asOfDate = dispositionService.calculateAsOfDate(CONTENT_NODE_REF, mockDispositionActionDefinition, true); + + assertNull("It should not be possible to determine the 'as of' date.", asOfDate); + } +}