mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Unit test for hold capability condition
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@67103 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* 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.declarative.condition;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.anyBoolean;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.security.AccessStatus;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Spy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Freeze evaluator unit test.
|
||||||
|
*
|
||||||
|
* @author Roy Wetherall
|
||||||
|
*/
|
||||||
|
public class HoldCapabilityConditionUnitTest extends BaseUnitTest
|
||||||
|
{
|
||||||
|
/** test data */
|
||||||
|
private NodeRef hold1;
|
||||||
|
private NodeRef hold2;
|
||||||
|
private List<NodeRef> holds;
|
||||||
|
|
||||||
|
/** mocked objects */
|
||||||
|
@Mock(name="kinds") Set<FilePlanComponentKind> mockedKinds;
|
||||||
|
|
||||||
|
/** evaluator */
|
||||||
|
@Spy @InjectMocks HoldCapabilityCondition evaluator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest#before()
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
@Override
|
||||||
|
public void before()
|
||||||
|
{
|
||||||
|
super.before();
|
||||||
|
|
||||||
|
// setup test data
|
||||||
|
hold1 = generateNodeRef(TYPE_HOLD);
|
||||||
|
hold2 = generateNodeRef(TYPE_HOLD);
|
||||||
|
holds = new ArrayList<NodeRef>(2);
|
||||||
|
holds.add(hold1);
|
||||||
|
holds.add(hold2);
|
||||||
|
|
||||||
|
// setup interactions
|
||||||
|
doReturn(false).when(mockedKinds).contains(FilePlanComponentKind.RECORD_CATEGORY);
|
||||||
|
doReturn(true).when(mockedKinds).contains(FilePlanComponentKind.RECORD_FOLDER);
|
||||||
|
doReturn(true).when(mockedKinds).contains(FilePlanComponentKind.HOLD);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test given there are no holds
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void noHolds()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
doReturn(Collections.EMPTY_LIST).when(mockedHoldService).heldBy(eq(recordFolder), anyBoolean());
|
||||||
|
|
||||||
|
// when
|
||||||
|
boolean result = evaluator.evaluate(recordFolder);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertFalse(result);
|
||||||
|
verify(mockedPermissionService, never()).hasPermission(any(NodeRef.class), eq(RMPermissionModel.FILING));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test given the user has no filling permissions on any of the available holds
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void noFillingOnHolds()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
doReturn(holds).when(mockedHoldService).heldBy(eq(recordFolder), anyBoolean());
|
||||||
|
doReturn(AccessStatus.DENIED).when(mockedPermissionService).hasPermission(hold1, RMPermissionModel.FILING);
|
||||||
|
doReturn(AccessStatus.DENIED).when(mockedPermissionService).hasPermission(hold2, RMPermissionModel.FILING);
|
||||||
|
|
||||||
|
// when
|
||||||
|
boolean result = evaluator.evaluate(recordFolder);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertFalse(result);
|
||||||
|
verify(mockedPermissionService, times(2)).hasPermission(any(NodeRef.class), eq(RMPermissionModel.FILING));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test given the user has filling on one of the available holds
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void fillingOnHolds()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
doReturn(holds).when(mockedHoldService).heldBy(eq(recordFolder), anyBoolean());
|
||||||
|
doReturn(AccessStatus.DENIED).when(mockedPermissionService).hasPermission(hold1, RMPermissionModel.FILING);
|
||||||
|
doReturn(AccessStatus.ALLOWED).when(mockedPermissionService).hasPermission(hold2, RMPermissionModel.FILING);
|
||||||
|
|
||||||
|
// when
|
||||||
|
boolean result = evaluator.evaluate(recordFolder);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertTrue(result);
|
||||||
|
verify(mockedPermissionService, times(2)).hasPermission(any(NodeRef.class), eq(RMPermissionModel.FILING));
|
||||||
|
}
|
||||||
|
}
|
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.module.org_alfresco_module_rm.test;
|
package org.alfresco.module.org_alfresco_module_rm.test;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.capability.declarative.condition.HoldCapabilityConditionUnitTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.forms.RecordsManagementTypeFormFilterUnitTest;
|
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.hold.HoldServiceImplUnitTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.jscript.app.evaluator.FrozenEvaluatorUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.jscript.app.evaluator.FrozenEvaluatorUnitTest;
|
||||||
@@ -56,7 +57,10 @@ import org.junit.runners.Suite.SuiteClasses;
|
|||||||
// web scripts
|
// web scripts
|
||||||
HoldsGetUnitTest.class,
|
HoldsGetUnitTest.class,
|
||||||
HoldPostUnitTest.class,
|
HoldPostUnitTest.class,
|
||||||
HoldPutUnitTest.class
|
HoldPutUnitTest.class,
|
||||||
|
|
||||||
|
// capability conditions
|
||||||
|
HoldCapabilityConditionUnitTest.class
|
||||||
})
|
})
|
||||||
public class AllUnitTestSuite
|
public class AllUnitTestSuite
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user