@Test public void testSearchUserFromGroupsViaCriteria() throws Exception { Configuration config = new Configuration(); config.setUseGroups(true); Capture<SearchRestriction[]> restrictions = new Capture<SearchRestriction[]>(); expect(holder.getUserManager()).andReturn(userManager); expect(holder.getNexusRoleManager()).andReturn(nexusRoleManager).times(2); expect(holder.getConfiguration()).andReturn(config); expect(userManager.searchUsers(capture(restrictions))).andReturn(Arrays.asList(user1, user2)); expect(nexusRoleManager.getNexusRoles("user1")).andReturn(Arrays.asList("one", "two")); expect(nexusRoleManager.getNexusRoles("user2")).andReturn(Arrays.asList("two")); replay(holder, userManager, nexusRoleManager); PlexusUserSearchCriteria critera = new PlexusUserSearchCriteria("me"); critera.setOneOfRoleIds(Sets.newHashSet("role1")); Set<PlexusUser> set = locator.searchUsers(critera); assertThat(set.size(), equalTo(2)); assertThat(restrictions.getValue().length, equalTo(5)); assertThat(restrictions.getValue()[1].getName(), equalTo(SearchContext.PRINCIPAL_NAME)); assertThat(restrictions.getValue()[1].getValue(), equalTo("me")); assertThat(restrictions.getValue()[4].getName(), equalTo(SearchContext.GROUP_PRINCIPAL_MEMBER)); assertThat(restrictions.getValue()[4].getValue(), equalTo("role1")); verify(holder, userManager, nexusRoleManager); }
@Test public void testGetUserDoesntExist() throws Exception { expect(holder.getUserManager()).andReturn(userManager); expect(userManager.getUser("user1")).andThrow(new ObjectNotFoundException()); replay(holder, userManager); PlexusUser u = locator.getUser("user1"); assertThat(u, nullValue()); verify(holder, userManager); }
@Test public void testGetUser() throws Exception { expect(holder.getUserManager()).andReturn(userManager); expect(holder.getNexusRoleManager()).andReturn(nexusRoleManager); expect(userManager.getUser("user1")).andReturn(user1); expect(nexusRoleManager.getNexusRoles("user1")).andReturn(Arrays.asList("one", "two")); replay(holder, userManager, nexusRoleManager); PlexusUser u = locator.getUser("user1"); assertThat(u.getEmailAddress(), equalTo("*****@*****.**")); assertThat(u.getName(), equalTo("First1 Last1")); assertThat(u.getRoles().size(), equalTo(2)); verify(holder, userManager, nexusRoleManager); }
@Test public void testSearchUserById() throws Exception { Capture<SearchRestriction[]> restrictions = new Capture<SearchRestriction[]>(); expect(holder.getUserManager()).andReturn(userManager); expect(holder.getNexusRoleManager()).andReturn(nexusRoleManager).times(2); expect(userManager.searchUsers(capture(restrictions))).andReturn(Arrays.asList(user1, user2)); expect(nexusRoleManager.getNexusRoles("user1")).andReturn(Arrays.asList("one", "two")); expect(nexusRoleManager.getNexusRoles("user2")).andReturn(Arrays.asList("two")); replay(holder, userManager, nexusRoleManager); Set<PlexusUser> set = locator.searchUserById("me"); assertThat(set.size(), equalTo(2)); assertThat(restrictions.getValue().length, equalTo(4)); assertThat(restrictions.getValue()[1].getName(), equalTo(SearchContext.PRINCIPAL_NAME)); assertThat(restrictions.getValue()[1].getValue(), equalTo("me")); verify(holder, userManager, nexusRoleManager); }