From aa6c4aff4232363f217069e65b1def66d6da8e89 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Tue, 31 Mar 2015 08:15:35 +0000 Subject: [PATCH] RM-2027 Add option to specify user names in MockAuthenticationUtilHelper. +review RM-9 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@100775 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../util/MockAuthenticationUtilHelper.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/MockAuthenticationUtilHelper.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/MockAuthenticationUtilHelper.java index d527117b09..0f934d248d 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/MockAuthenticationUtilHelper.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/MockAuthenticationUtilHelper.java @@ -53,6 +53,23 @@ public class MockAuthenticationUtilHelper return mockAuthenticationUtil; } + /** + * Create a Mockito mock AuthenticationUtil that executes all methods assuming the user has permission. + * + * @param adminUserName The name of the default admin user. + * @param fullyAuthenticatedUser The name of the user that last authenticated. + * @param systemUserName The name of the system user. + * @return The new mock. + */ + public static AuthenticationUtil create(String adminUserName, String fullyAuthenticatedUser, String systemUserName) + { + AuthenticationUtil mockAuthenticationUtil = mock(AuthenticationUtil.class); + + setup(mockAuthenticationUtil, adminUserName, fullyAuthenticatedUser, systemUserName); + + return mockAuthenticationUtil; + } + /** * Set up a Mockito mock AuthenticationUtil so that it executes all methods assuming the user has * permissions. If the mock is asked for details about the user then it assumes the user is "admin". @@ -63,6 +80,24 @@ public class MockAuthenticationUtilHelper */ @SuppressWarnings("unchecked") protected static void setup(AuthenticationUtil mockAuthenticationUtil) + { + setup(mockAuthenticationUtil, "admin", "admin", "admin"); + } + + /** + * Set up a Mockito mock AuthenticationUtil so that it executes all methods assuming the user has + * permissions. + *

+ * TODO: Change this method to private and this class to be a factory. + * + * @param mockAuthenticationUtil The mock to initialise. + * @param adminUserName The name of the default admin user. + * @param fullyAuthenticatedUser The name of the user that last authenticated. + * @param systemUserName The name of the system user. + */ + @SuppressWarnings("unchecked") + protected static void setup(AuthenticationUtil mockAuthenticationUtil, String adminUserName, + String fullyAuthenticatedUser, String systemUserName) { reset(mockAuthenticationUtil); @@ -93,7 +128,8 @@ public class MockAuthenticationUtilHelper }).when(mockAuthenticationUtil). runAs(any(RunAsWork.class), anyString()); // assume admin - doReturn("admin").when(mockAuthenticationUtil).getAdminUserName(); - doReturn("admin").when(mockAuthenticationUtil).getFullyAuthenticatedUser(); + doReturn(adminUserName).when(mockAuthenticationUtil).getAdminUserName(); + doReturn(fullyAuthenticatedUser).when(mockAuthenticationUtil).getFullyAuthenticatedUser(); + doReturn(systemUserName).when(mockAuthenticationUtil).getSystemUserName(); } }