mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-1956: Create record capability allows user to edit metadata and copy category/folder /record
* fixes issue relating to filing records with only CreateRecord capability git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.3@97945 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.capability.impl;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.sf.acegisecurity.vote.AccessDecisionVoter;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImpl;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
|
||||
/**
|
||||
* Edit non records metadata capability unit test
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.3
|
||||
*/
|
||||
public class EditNonRecordsMetadataCapabilityUnitTest extends BaseUnitTest
|
||||
{
|
||||
/** mocked set */
|
||||
@Mock private Set<Object> mockedSet;
|
||||
|
||||
/** test capability */
|
||||
@InjectMocks private EditNonRecordMetadataCapability capability;
|
||||
|
||||
/**
|
||||
* Given that the evaluated node is held in the transaction cache as new
|
||||
* When evaluated
|
||||
* Then access is granted
|
||||
*/
|
||||
@Test
|
||||
public void newRecord()
|
||||
{
|
||||
NodeRef nodeRef = generateNodeRef();
|
||||
when(mockedTransactionalResourceHelper.getSet(RecordServiceImpl.KEY_NEW_RECORDS))
|
||||
.thenReturn(mockedSet);
|
||||
when(mockedSet.contains(nodeRef))
|
||||
.thenReturn(true);
|
||||
|
||||
Assert.assertEquals(AccessDecisionVoter.ACCESS_GRANTED, capability.evaluate(nodeRef));
|
||||
}
|
||||
}
|
@@ -21,17 +21,22 @@ package org.alfresco.module.org_alfresco_module_rm.record;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
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.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -39,6 +44,7 @@ import org.apache.commons.collections.CollectionUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Spy;
|
||||
|
||||
/**
|
||||
* Unit test for RecordServiceImpl
|
||||
@@ -54,7 +60,7 @@ public class RecordServiceImplUnitTest extends BaseUnitTest
|
||||
private static QName TYPE_MY_FILE_PLAN = generateQName();
|
||||
private static QName ASPECT_FOR_FILE_PLAN = generateQName();
|
||||
|
||||
@InjectMocks private RecordServiceImpl recordService;
|
||||
@Spy @InjectMocks private RecordServiceImpl recordService;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
@@ -239,5 +245,65 @@ public class RecordServiceImplUnitTest extends BaseUnitTest
|
||||
|
||||
// verify link was created
|
||||
verify(mockedNodeService, times(1)).removeChild(recordFolder, record);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that a new record is being created
|
||||
* When the behaviour is triggered
|
||||
* Then the record is stored for later reference in the transaction
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void onCreateChildAssociationNewRecord()
|
||||
{
|
||||
// standard content node
|
||||
NodeRef nodeRef = generateCmContent("test.txt");
|
||||
ChildAssociationRef assoc = generateChildAssociationRef(generateNodeRef(), nodeRef);
|
||||
|
||||
doNothing().when(recordService).file(nodeRef);
|
||||
|
||||
// doesn't have no content aspect
|
||||
when(mockedNodeService.hasAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT))
|
||||
.thenReturn(false);
|
||||
|
||||
Set<Object> values = mock(HashSet.class);
|
||||
when(mockedTransactionalResourceHelper.getSet(RecordServiceImpl.KEY_NEW_RECORDS))
|
||||
.thenReturn(values);
|
||||
|
||||
// trigger behaviour
|
||||
recordService.onCreateChildAssociation(assoc, true);
|
||||
|
||||
// verify
|
||||
verify(values, times(1)).add(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that an existing record is linked
|
||||
* When the behaviour is triggered
|
||||
* Then the record is not stored for later reference in the transaction
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void onCreateChildAssociationExistingRecord()
|
||||
{
|
||||
// standard content node
|
||||
NodeRef nodeRef = generateCmContent("test.txt");
|
||||
ChildAssociationRef assoc = generateChildAssociationRef(generateNodeRef(), nodeRef);
|
||||
|
||||
doNothing().when(recordService).file(nodeRef);
|
||||
|
||||
// doesn't have no content aspect
|
||||
when(mockedNodeService.hasAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT))
|
||||
.thenReturn(false);
|
||||
|
||||
Set<Object> values = mock(HashSet.class);
|
||||
when(mockedTransactionalResourceHelper.getSet(RecordServiceImpl.KEY_NEW_RECORDS))
|
||||
.thenReturn(values);
|
||||
|
||||
// trigger behaviour
|
||||
recordService.onCreateChildAssociation(assoc, false);
|
||||
|
||||
// verify
|
||||
verify(values, never()).add(nodeRef);
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ import org.alfresco.module.org_alfresco_module_rm.bootstrap.BootstrapImporterMod
|
||||
import org.alfresco.module.org_alfresco_module_rm.bootstrap.RecordContributorsGroupBootstrapComponentUnitTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMEntryVoterUnitTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.declarative.condition.CapabilityDeclarativeConditionSuite;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.impl.EditNonRecordsMetadataCapabilityUnitTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.forms.RecordsManagementTypeFormFilterUnitTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.hold.HoldServiceImplUnitTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.job.DispositionLifecycleJobExecuterUnitTest;
|
||||
@@ -70,6 +71,9 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
// evaluators
|
||||
TransferEvaluatorUnitTest.class,
|
||||
FrozenEvaluatorUnitTest.class,
|
||||
|
||||
// capabilities
|
||||
EditNonRecordsMetadataCapabilityUnitTest.class,
|
||||
|
||||
// web scripts
|
||||
HoldsGetUnitTest.class,
|
||||
|
Reference in New Issue
Block a user