Merge remote-tracking branch 'remotes/origin/release/V2.7' into merge-3.0/RM-6787_VersionWhenClassifyFileWithCopies

# Conflicts:
#	rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java
#	rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspectUnitTest.java
#	rm-enterprise/rm-enterprise-repo/src/main/java/org/alfresco/module/org_alfresco_module_rm/model/AbstractSecureItem.java
#	rm-enterprise/rm-enterprise-repo/src/main/java/org/alfresco/module/org_alfresco_module_rm/model/clf/aspect/ClassifiedAspect.java
#	rm-enterprise/rm-enterprise-repo/src/main/java/org/alfresco/module/org_alfresco_module_rm/model/secured/aspect/SecuredAspect.java
#	rm-enterprise/rm-enterprise-repo/src/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/clf/aspect/ClassifiedAspectUnitTest.java
#	rm-enterprise/rm-enterprise-repo/src/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/secured/aspect/SecuredAspectUnitTest.java
#	rm-enterprise/rm-enterprise-repo/src/unit-test/java/org/alfresco/module/org_alfresco_module_rm/securitymarks/SecurityMarkingServiceImplUnitTest.java
This commit is contained in:
Rodica Sutu
2019-04-09 10:51:44 +03:00
10 changed files with 320 additions and 138 deletions

View File

@@ -31,8 +31,6 @@ import static java.util.Collections.emptyList;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_ARCHIVED;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_RECORD;
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;
@@ -40,11 +38,8 @@ import static org.mockito.MockitoAnnotations.initMocks;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.junit.Before;
@@ -71,15 +66,9 @@ public class RecordAspectUnitTest
@Mock
private NodeService mockNodeService;
@Mock
private BehaviourFilter mockBehaviorFilter;
@Mock
private ContentService mockContentService;
@Mock
private ContentReader mockContentReader;
@Mock
private ContentWriter mockContentWriter;
@Mock
private ExtendedSecurityService mockExtendedSecurityService;
@Mock
private ContentBinDuplicationUtility mockContentBinDuplicationUtility;
@Before
public void setUp()
@@ -92,12 +81,10 @@ public class RecordAspectUnitTest
public void testDuplicateBinBeforeAddingAspectForFileWithCopy()
{
when(mockNodeService.getSourceAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(SOURCE_ASSOC_REF));
when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader);
when(mockContentService.getWriter(NODE_REF, ContentModel.PROP_CONTENT, true)).thenReturn(mockContentWriter);
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
verifyBeforeAddAspectMethodsInvocations(1);
verify(mockContentBinDuplicationUtility, times(1)).duplicate(NODE_REF);
}
/** Check that the bin is duplicated before adding the aspect if the file is a copy. */
@@ -105,29 +92,10 @@ public class RecordAspectUnitTest
public void testDuplicateBinBeforeAddingAspectForCopy()
{
when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(TARGET_ASSOC_REF));
when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader);
when(mockContentService.getWriter(NODE_REF, ContentModel.PROP_CONTENT, true)).thenReturn(mockContentWriter);
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
verifyBeforeAddAspectMethodsInvocations(1);
}
/** Check that no content bin is created if the file does not have content. */
@Test
public void testBeforeAddAspectOnFileWithNoContent()
{
when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(TARGET_ASSOC_REF));
when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(null);
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
verify(mockBehaviorFilter, times(1)).disableBehaviour(eq(ContentModel.ASPECT_AUDITABLE));
verify(mockBehaviorFilter, times(1)).disableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE));
verify(mockContentService, times(1)).getReader(NODE_REF, ContentModel.PROP_CONTENT);
verify(mockContentService, never()).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true);
verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE));
verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE));
verify(mockContentBinDuplicationUtility, times(1)).duplicate(NODE_REF);
}
/** Check that the bin is not duplicated before adding the aspect if the node has no copies. */
@@ -139,7 +107,7 @@ public class RecordAspectUnitTest
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
verifyBeforeAddAspectMethodsInvocations(0);
verify(mockContentBinDuplicationUtility, times(0)).duplicate(NODE_REF);
}
/** Check that the bin is duplicated when copying a record. */
@@ -148,47 +116,12 @@ public class RecordAspectUnitTest
{
when(mockNodeService.exists(COPY_REF)).thenReturn(true);
when(mockNodeService.hasAspect(COPY_REF, ASPECT_RECORD)).thenReturn(true);
when(mockContentService.getReader(COPY_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader);
when(mockContentService.getWriter(COPY_REF, ContentModel.PROP_CONTENT, true)).thenReturn(mockContentWriter);
recordAspect.onCopyComplete(null, NODE_REF, COPY_REF, true, null);
verify(mockExtendedSecurityService, times(1)).remove(COPY_REF);
verify(mockContentService, times(1)).getReader(COPY_REF, ContentModel.PROP_CONTENT);
verify(mockContentService, times(1)).getWriter(COPY_REF, ContentModel.PROP_CONTENT, true);
verify(mockContentWriter, times(1)).putContent(mockContentReader);
verify(mockContentBinDuplicationUtility, times(1)).duplicate(COPY_REF);
}
/**
* This is testing the fix for RM-6788 where archived content couldn't be declared as a record
* This was caused by attempting to copy the bin file and updating the content url of the
* archived piece of content which failed as this is a protected property. This is done if
* the node is/has a copy but the same duplication already happens during archive.
*/
@Test
public void testBinFileNotDuplicatedForArchivedContent()
{
when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(TARGET_ASSOC_REF));
when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(null);
when(mockNodeService.hasAspect(NODE_REF, ASPECT_ARCHIVED)).thenReturn(true);
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
verifyBeforeAddAspectMethodsInvocations(0);
}
/**
* Helper to verify beforeAddAspect methods invocations
*
* @param wantedNumberOfInvocations wanted number of invocations for each method
*/
private void verifyBeforeAddAspectMethodsInvocations(int wantedNumberOfInvocations)
{
verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).disableBehaviour(eq(ContentModel.ASPECT_AUDITABLE));
verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).disableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE));
verify(mockContentService, times(wantedNumberOfInvocations)).getReader(NODE_REF, ContentModel.PROP_CONTENT);
verify(mockContentService, times(wantedNumberOfInvocations)).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true);
verify(mockContentWriter, times(wantedNumberOfInvocations)).putContent(mockContentReader);
verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE));
verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE));
}
}

View File

@@ -0,0 +1,130 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2019 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 <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.module.org_alfresco_module_rm.util;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_ARCHIVED;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Test class for the ContentBinDuplicationUtility
* @author Ross Gale
* @since 2.7.2
*/
public class ContentBinDuplicationUtilityUnitTest
{
@Mock
private ContentService mockContentService;
@Mock
private BehaviourFilter mockBehaviourFilter;
@Mock
private ContentReader mockContentReader;
@Mock
private ContentWriter mockContentWriter;
@Mock
private NodeService mockNodeService;
@InjectMocks
private ContentBinDuplicationUtility contentBinDuplicationUtility;
@Before
public void setUp()
{
MockitoAnnotations.initMocks(this);
}
/**
* Tests that the requests are made to disable and re-enable the audit and versioning and to update the content bin
*/
@Test
public void testContentUrlIsUpdated()
{
NodeRef nodeRef = new NodeRef("some://test/noderef");
when(mockContentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader);
when(mockContentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true)).thenReturn(mockContentWriter);
contentBinDuplicationUtility.duplicate(nodeRef);
verify(mockContentWriter, times(1)).putContent(mockContentReader);
checkBehaviours(1);
}
/**
* Test content duplication doesn't happen when node has no content
*/
@Test
public void testDuplicationDoesntHappenWithNoContent()
{
NodeRef nodeRef = new NodeRef("some://test/noderef");
when(mockContentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(null);
contentBinDuplicationUtility.duplicate(nodeRef);
verify(mockContentWriter, times(0)).putContent(mockContentReader);
checkBehaviours(1);
}
/**
* This is testing the fix for RM-6788 where archived content couldn't be declared as a record
* This was caused by attempting to copy the bin file and updating the content url of the
* archived piece of content which failed as this is a protected property. This is done if
* the node is/has a copy but the same duplication already happens during archive.
*/
@Test
public void testBinFileNotDuplicatedForArchivedContent()
{
NodeRef nodeRef = new NodeRef("some://test/noderef");
when(mockNodeService.hasAspect(nodeRef, ASPECT_ARCHIVED)).thenReturn(true);
contentBinDuplicationUtility.duplicate(nodeRef);
verify(mockContentReader, times(0)).getReader();
checkBehaviours(0);
}
/**
* Check that the behaviours are disabled and re-enabled the correct number of times
* @param times the times the behaviours should be called
*/
private void checkBehaviours(int times)
{
verify(mockBehaviourFilter, times(times)).disableBehaviour();
verify(mockBehaviourFilter, times(times)).enableBehaviour();
}
}