private StandardUserDetailsService getUserDetailsTestService(CoreContext ctx, boolean imEnabled) { User u = new User() { @Override public boolean hasPermission(PermissionName permission) { return true; } }; u.setUserName(USER_NAME); u.setUniqueId(); AddressBookEntry abe = new AddressBookEntry(); abe.setImId(USER_IM_ID); u.setAddressBookEntry(abe); u.setSettings(TestHelper.loadSettings("commserver/user-settings.xml")); u.setSettingTypedValue("im/im-account", imEnabled); AcdContext acdContext = createMock(AcdContext.class); StandardUserDetailsService uds = new StandardUserDetailsService(); uds.setCoreContext(ctx); uds.setAcdContext(acdContext); ctx.loadUserByUserNameOrAlias(USER_IM_ID); expectLastCall().andReturn(null); ctx.loadUserByConfiguredImId(USER_IM_ID); expectLastCall().andReturn(u); acdContext.getUsersWithAgents(); expectLastCall().andReturn(Collections.emptyList()); replay(ctx, acdContext); return uds; }
public void testLoadUserByUsername() { User u = new User() { @Override public boolean hasPermission(PermissionName permission) { return true; } }; u.setUserName(USER_NAME); u.setUniqueId(); CoreContext coreContext = createMock(CoreContext.class); AcdContext acdContext = createMock(AcdContext.class); StandardUserDetailsService uds = new StandardUserDetailsService(); uds.setCoreContext(coreContext); uds.setAcdContext(acdContext); coreContext.loadUserByUserNameOrAlias(USER_NAME); expectLastCall().andReturn(u); acdContext.getUsersWithAgents(); expectLastCall().andReturn(Collections.emptyList()); replay(coreContext, acdContext); // load the user details UserDetails details = uds.loadUserByUsername(USER_NAME); assertEquals(USER_NAME, details.getUsername()); GrantedAuthority[] authorities = details.getAuthorities(); assertTrue(contains(authorities, UserRole.Admin.toAuth())); assertTrue(contains(authorities, UserRole.User.toAuth())); assertFalse(contains(authorities, UserRole.AcdAgent.toAuth())); assertFalse(contains(authorities, UserRole.AcdSupervisor.toAuth())); assertTrue(contains(authorities, UserRole.AttendantAdmin.toAuth())); verify(coreContext, acdContext); }