@Test public void deactivate_user() throws Exception { MockUserSession.set().setLogin("simon").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); service.deactivate("julien"); verify(dao).deactivateUserByLogin("julien"); verify(userService).index(); }
@Test public void self_deactivation_is_not_possible() throws Exception { try { MockUserSession.set().setLogin("simon").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); service.deactivate("simon"); fail(); } catch (BadRequestException e) { assertThat(e).hasMessage("Self-deactivation is not possible"); verify(dao, never()).deactivateUserByLogin("simon"); } }
@Test public void fail_to_deactivate_when_blank_login() throws Exception { MockUserSession.set().setLogin("simon").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); try { service.deactivate(""); fail(); } catch (BadRequestException e) { assertThat(e).hasMessage("Login is missing"); verifyZeroInteractions(dao); } }
@Test public void user_deactivation_requires_admin_permission() throws Exception { try { MockUserSession.set() .setLogin("simon") .setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); service.deactivate("julien"); fail(); } catch (ForbiddenException e) { verify(dao, never()).deactivateUserByLogin("simon"); } }
@Test public void update_only_scm_accounts() throws Exception { Map<String, Object> params = newHashMap(); params.put("login", "john"); params.put("scm_accounts", newArrayList("jn")); service.update(params); ArgumentCaptor<UpdateUser> userCaptor = ArgumentCaptor.forClass(UpdateUser.class); verify(userService).update(userCaptor.capture()); assertThat(userCaptor.getValue().isNameChanged()).isFalse(); assertThat(userCaptor.getValue().isEmailChanged()).isFalse(); assertThat(userCaptor.getValue().isScmAccountsChanged()).isTrue(); assertThat(userCaptor.getValue().isPasswordChanged()).isFalse(); }
@Test public void create() throws Exception { Map<String, Object> params = newHashMap(); params.put("login", "john"); params.put("name", "John"); params.put("email", "*****@*****.**"); params.put("scm_accounts", newArrayList("jn")); service.create(params); ArgumentCaptor<NewUser> newUserCaptor = ArgumentCaptor.forClass(NewUser.class); verify(userService).create(newUserCaptor.capture()); assertThat(newUserCaptor.getValue().login()).isEqualTo("john"); assertThat(newUserCaptor.getValue().name()).isEqualTo("John"); assertThat(newUserCaptor.getValue().email()).isEqualTo("*****@*****.**"); assertThat(newUserCaptor.getValue().scmAccounts()).containsOnly("jn"); }
@Test public void test_empty_query() throws Exception { service.find(Maps.<String, Object>newHashMap()); verify(finder, times(1)) .find( argThat( new ArgumentMatcher<UserQuery>() { @Override public boolean matches(Object o) { UserQuery query = (UserQuery) o; return !query.includeDeactivated() && query.logins() == null && query.searchText() == null; } })); }
@Test public void update() throws Exception { Map<String, Object> params = newHashMap(); params.put("login", "john"); params.put("name", "John"); params.put("email", "*****@*****.**"); params.put("scm_accounts", newArrayList("jn")); params.put("password", "1234"); params.put("password_confirmation", "1234"); service.update(params); ArgumentCaptor<UpdateUser> userCaptor = ArgumentCaptor.forClass(UpdateUser.class); verify(userService).update(userCaptor.capture()); assertThat(userCaptor.getValue().login()).isEqualTo("john"); assertThat(userCaptor.getValue().name()).isEqualTo("John"); assertThat(userCaptor.getValue().email()).isEqualTo("*****@*****.**"); assertThat(userCaptor.getValue().scmAccounts()).containsOnly("jn"); assertThat(userCaptor.getValue().password()).isEqualTo("1234"); assertThat(userCaptor.getValue().passwordConfirmation()).isEqualTo("1234"); }
@Test public void parse_query() throws Exception { service.find( ImmutableMap.<String, Object>of( "logins", "simon,loic", "includeDeactivated", "true", "s", "sim")); verify(finder, times(1)) .find( argThat( new ArgumentMatcher<UserQuery>() { @Override public boolean matches(Object o) { UserQuery query = (UserQuery) o; return query.includeDeactivated() && query.logins().contains("simon") && query.logins().contains("loic") && query.logins().size() == 2 && query.searchText().equals("sim"); } })); }
@Test public void index() throws Exception { service.index(); verify(userService).index(); }
@Test public void get_by_login() throws Exception { service.getByLogin("john"); verify(userService).getNullableByLogin("john"); }