diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml index deebceb06e..96130f9e01 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml @@ -66,7 +66,8 @@ - + + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java index 6a28c62f0d..b9f608e612 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java @@ -27,7 +27,6 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type; -import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.record.RecordService; @@ -74,15 +73,13 @@ public class NonElectronicRecordType extends BaseBehaviourBean implements NodeSe final NodeRef child = nodeRef; if (nodeService.exists(child)) { - QName childType = nodeService.getType(child); NodeRef parentRef = nodeService.getPrimaryParent(child).getParentRef(); QName parentType = nodeService.getType(parentRef); - boolean isContentSubType = dictionaryService.isSubClass(childType, ContentModel.TYPE_CONTENT); boolean isUnfiledRecordContainer = parentType .equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER); boolean isUnfiledRecordFolder = parentType .equals(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER); - if (isContentSubType && (isUnfiledRecordContainer || isUnfiledRecordFolder)) + if (isUnfiledRecordContainer || isUnfiledRecordFolder) { if (!nodeService.hasAspect(child, ASPECT_FILE_PLAN_COMPONENT)) { diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java new file mode 100644 index 0000000000..cc417a7349 --- /dev/null +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java @@ -0,0 +1,103 @@ +/* + * #%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 + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * 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 . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.model.rma.type; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +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.util.Map; + +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; +import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper; +import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * @author silviudinuta + */ +public class NonElectronicRecordTypeUnitTest extends BaseUnitTest +{ + + @InjectMocks + NonElectronicRecordType nonElectronicRecordType; + @Mock + AuthenticationUtil mockAuthenticationUtil; + + @Before + public void setUp() + { + MockitoAnnotations.initMocks(this); + MockAuthenticationUtilHelper.setup(mockAuthenticationUtil); + } + + @SuppressWarnings("unchecked") + @Test + public void testOnUpdateWithAspectsAlreadyPresent() + { + NodeRef nodeRef = generateNodeRef(); + NodeRef parentNodeRef=generateNodeRef(); + ChildAssociationRef generateChildAssociationRef = generateChildAssociationRef(parentNodeRef, nodeRef); + when(mockedNodeService.getPrimaryParent(nodeRef)).thenReturn(generateChildAssociationRef); + when(mockedNodeService.getType(parentNodeRef)).thenReturn(TYPE_UNFILED_RECORD_FOLDER); + when(mockedNodeService.hasAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(true); + when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(true); + + nonElectronicRecordType.onUpdateNode(nodeRef); + + verify(mockedNodeService, never()).addAspect(eq(nodeRef), eq(ASPECT_FILE_PLAN_COMPONENT), any(Map.class)); + verify(mockedRecordService, never()).makeRecord(eq(nodeRef)); + } + + @SuppressWarnings("unchecked") + @Test + public void testOnUpdateWithoutTheAspects() + { + NodeRef nodeRef = generateNodeRef(); + NodeRef parentNodeRef=generateNodeRef(); + ChildAssociationRef generateChildAssociationRef = generateChildAssociationRef(parentNodeRef, nodeRef); + when(mockedNodeService.getPrimaryParent(nodeRef)).thenReturn(generateChildAssociationRef); + when(mockedNodeService.getType(parentNodeRef)).thenReturn(TYPE_UNFILED_RECORD_FOLDER); + when(mockedNodeService.hasAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false); + when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false); + + nonElectronicRecordType.onUpdateNode(nodeRef); + + verify(mockedNodeService, times(1)).addAspect(eq(nodeRef), eq(ASPECT_FILE_PLAN_COMPONENT), any(Map.class)); + verify(mockedRecordService, times(1)).makeRecord(eq(nodeRef)); + } +}