mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-6928 adding check to allow specified properties on frozen nodes to be updated
This commit is contained in:
@@ -42,6 +42,7 @@ import java.util.Set;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.freeze.FreezeService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.NodeTypeUtility;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.PropertyModificationAllowedCheck;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.TransactionalResourceHelper;
|
||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
@@ -92,6 +93,9 @@ public class FrozenAspectUnitTest
|
||||
@Mock
|
||||
private Set mockSet;
|
||||
|
||||
@Mock
|
||||
private PropertyModificationAllowedCheck mockPropertyModificationAllowedCheck;
|
||||
|
||||
@InjectMocks
|
||||
private FrozenAspect frozenAspect;
|
||||
|
||||
@@ -245,6 +249,7 @@ public class FrozenAspectUnitTest
|
||||
when(mockFreezeService.isFrozen(content)).thenReturn(true);
|
||||
when(mockResourceHelper.getSet(content)).thenReturn(mockSet);
|
||||
when(mockSet.contains("frozen")).thenReturn(false);
|
||||
when(mockPropertyModificationAllowedCheck.check(null, null)).thenReturn(false);
|
||||
frozenAspect.onUpdateProperties(content, null, null);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* #%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 junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Unit test class for PropertyModificationAllowedCheck
|
||||
*
|
||||
* @author Ross Gale
|
||||
* @since 3.2
|
||||
*/
|
||||
public class PropertyModificationAllowedCheckUnitTest
|
||||
{
|
||||
|
||||
private PropertyModificationAllowedCheck propertyModificationAllowedCheck;
|
||||
|
||||
private Map<QName, Serializable> before, after;
|
||||
|
||||
private QName qName, qName2;
|
||||
|
||||
private List<QName> list;
|
||||
|
||||
@Mock
|
||||
private Serializable serializable, serializable2;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
MockitoAnnotations.initMocks(this);
|
||||
propertyModificationAllowedCheck = new PropertyModificationAllowedCheck();
|
||||
before = new HashMap();
|
||||
after = new HashMap();
|
||||
qName = QName.createQName("foo","bar");
|
||||
qName2 = QName.createQName("bar", "foo");
|
||||
before.put(qName, serializable);
|
||||
after.put(qName, serializable2);
|
||||
list = new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check passes when property is in whitelist
|
||||
*/
|
||||
@Test
|
||||
public void testCheckMethodReturnsTrueWhenPropertyInList()
|
||||
{
|
||||
list.add(qName);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertTrue(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check fails when property is not in whitelist
|
||||
*/
|
||||
@Test
|
||||
public void testCheckMethodReturnsFalseIfAnyNonAllowedPropertyInListIsChanged()
|
||||
{
|
||||
list.add(qName);
|
||||
before.put(qName2, serializable2);
|
||||
after.put(qName2, serializable);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertFalse(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check fails when first property is not in whitelist
|
||||
*/
|
||||
@Test
|
||||
public void testCheckMethodReturnsFalseIfFirstPropertyInListIsChangedWithoutWhitelist()
|
||||
{
|
||||
list.add(qName2);
|
||||
before.put(qName2, serializable2);
|
||||
after.put(qName2, serializable);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertFalse(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check passes when all properties are in whitelist
|
||||
*/
|
||||
@Test
|
||||
public void testCheckMethodReturnsTrueIfAllEditedPropertiesInWhitelist()
|
||||
{
|
||||
list.add(qName);
|
||||
list.add(qName2);
|
||||
before.put(qName2, serializable2);
|
||||
after.put(qName2, serializable);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertTrue(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check fails when property added
|
||||
*/
|
||||
@Test
|
||||
public void testCheckMethodReturnsFalseIfPropertyNotInBeforeList()
|
||||
{
|
||||
list.add(qName);
|
||||
after.put(qName2, serializable);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertFalse(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check passes when allowed property added
|
||||
*/
|
||||
@Test
|
||||
public void testCheckMethodReturnsTrueIfAllowedPropertyNotInBeforeList()
|
||||
{
|
||||
list.add(qName2);
|
||||
after.put(qName2, serializable);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertFalse(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check fails when property removed
|
||||
*/
|
||||
@Test
|
||||
public void testCheckMethodReturnsFalseIfPropertyNotInAfterList()
|
||||
{
|
||||
list.add(qName);
|
||||
before.put(qName2, serializable);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertFalse(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check passes when allowed property removed
|
||||
*/
|
||||
@Test
|
||||
public void testCheckMethodReturnsTrueIfAllowedPropertyNotInAfterList()
|
||||
{
|
||||
list.add(qName);
|
||||
list.add(qName2);
|
||||
before.put(qName2, serializable);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertTrue(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check for empty property in before map without whitelist
|
||||
*/
|
||||
@Test
|
||||
public void testNullValueInBeforeList()
|
||||
{
|
||||
before.put(qName, null);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertFalse(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check for empty property in after map without whitelist
|
||||
*/
|
||||
@Test
|
||||
public void testNullValueInAfterList()
|
||||
{
|
||||
after.put(qName, null);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertFalse(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check for empty property in before map with whitelist
|
||||
*/
|
||||
@Test
|
||||
public void testNullValueInBeforeListWithAllowedProperty()
|
||||
{
|
||||
list.add(qName);
|
||||
before.put(qName, null);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertTrue(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check for empty property in after list with whitelist
|
||||
*/
|
||||
@Test
|
||||
public void testNullValueInAfterListWithAllowedProperty()
|
||||
{
|
||||
list.add(qName);
|
||||
after.put(qName, null);
|
||||
propertyModificationAllowedCheck.setWhiteList(list);
|
||||
assertTrue(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test modification check for empty property in both maps
|
||||
*/
|
||||
@Test
|
||||
public void testNullValueInBoth()
|
||||
{
|
||||
before.put(qName, null);
|
||||
after.put(qName, null);
|
||||
assertTrue(propertyModificationAllowedCheck.check(before, after));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user