From d42c0cabddef43dc2d2b840a8032e2e94bd8d8d1 Mon Sep 17 00:00:00 2001 From: David Webster Date: Fri, 15 May 2015 16:09:36 +0000 Subject: [PATCH] RM-2197: Adds missing unit tests, as identified by Tom during +review RM-56 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@104306 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../SecurityClearanceServiceImplUnitTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImplUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImplUnitTest.java index fa88848576..85528df09b 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImplUnitTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImplUnitTest.java @@ -27,9 +27,11 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.*; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import com.google.common.collect.ImmutableList; import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.LevelIdNotFound; import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper; import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; @@ -49,6 +51,7 @@ import org.mockito.MockitoAnnotations; * Unit tests for {@link SecurityClearanceServiceImpl}. * * @author Neil Mc Erlean + * @author David Webster * @since 3.0 */ public class SecurityClearanceServiceImplUnitTest @@ -331,4 +334,54 @@ public class SecurityClearanceServiceImplUnitTest assertFalse(securityClearanceServiceImpl.hasClearance(nodeRef)); } + + /** + * Check that all levels are returned + */ + @Test public void getClearanceLevels() + { + + // Create a list of clearance levels + ImmutableList mockClearanceLevels = ImmutableList.of( + new ClearanceLevel(new ClassificationLevel("level1", "Level One"), "Clearance One"), + new ClearanceLevel(new ClassificationLevel("level2", "Level Two"), "Clearance Two"), + new ClearanceLevel(new ClassificationLevel("level3", "Level Three"), "Clearance Three") + ); + + when(mockClearanceLevelManager.getClearanceLevels()) + .thenReturn(mockClearanceLevels); + when(mockClearanceLevelManager.getMostSecureLevel()) + .thenReturn(mockClearanceLevels.get(0)); + + List actualClearanceLevels = securityClearanceServiceImpl.getClearanceLevels(); + + assertEquals(mockClearanceLevels.size(), actualClearanceLevels.size()); + assertEquals(mockClearanceLevels.get(0), actualClearanceLevels.get(0)); + assertEquals(mockClearanceLevels.get(1), actualClearanceLevels.get(1)); + assertEquals(mockClearanceLevels.get(2), actualClearanceLevels.get(2)); + } + + /** + * Check that a user with restricted access only gets some of the levels. + */ + @Test + public void getRestrictedClearanceLevels() + { + + // Create a list of clearance levels + ImmutableList mockClearanceLevels = ImmutableList.of( + new ClearanceLevel(new ClassificationLevel("level1", "Level One"), "Clearance One"), + new ClearanceLevel(new ClassificationLevel("level2", "Level Two"), "Clearance Two"), + new ClearanceLevel(new ClassificationLevel("level3", "Level Three"), "Clearance Three") + ); + + when(mockClearanceLevelManager.getClearanceLevels()).thenReturn(mockClearanceLevels); + when(mockClearanceLevelManager.getMostSecureLevel()).thenReturn(mockClearanceLevels.get(1)); + + List restrictedClearanceLevels = securityClearanceServiceImpl.getClearanceLevels(); + + assertEquals(2, restrictedClearanceLevels.size()); + assertEquals(mockClearanceLevels.get(1), restrictedClearanceLevels.get(0)); + assertEquals(mockClearanceLevels.get(2), restrictedClearanceLevels.get(1)); + } }