private void assertGroupEquals(Group expected, Group found) { assertThat(found).isNotNull(); assertThat(found).isEqualTo(expected); assertThat(found.getName()).isEqualTo(expected.getName()); assertThat(expected.getSubjectCredentials()).isEqualTo(found.getSubjectCredentials()); Asserts.assertCreatedTimestamps(expected, found); }
@Test public void test_delete_group() { Group group = Group.Builder.create().name("group1").build(); subjectCredentialsService.createGroup(group.getName()); subjectCredentialsService.delete(group); assertThat(subjectCredentialsService.getGroups()).isEmpty(); }
@Test public void test_remove_groups_from_user() { SubjectCredentials subjectCredentials = SubjectCredentials.Builder.create() .authenticationType(SubjectCredentials.AuthenticationType.PASSWORD) .name("user1") .password("password") .groups(Sets.newHashSet("group1", "group2")) .build(); subjectCredentialsService.save(subjectCredentials); subjectCredentials.removeGroup("group1"); subjectCredentialsService.save(subjectCredentials); SubjectCredentials found = subjectCredentialsService.getSubjectCredentials(subjectCredentials.getName()); assertSubjectEquals(subjectCredentials, found); assertThat(subjectCredentialsService.getGroups()).hasSize(2); Group group1 = subjectCredentialsService.getGroup("group1"); assertThat(group1).isNotNull(); assertThat(group1.getSubjectCredentials()).isEmpty(); Group group2 = subjectCredentialsService.getGroup("group2"); assertThat(group2).isNotNull(); assertThat(group2.getSubjectCredentials()).hasSize(1); assertThat(group2.getSubjectCredentials()).contains(subjectCredentials.getName()); }
@Test public void test_create_new_group() { Group group = Group.Builder.create().name("group1").build(); subjectCredentialsService.createGroup(group.getName()); List<Group> groups = newArrayList(subjectCredentialsService.getGroups()); assertThat(groups).hasSize(1); assertGroupEquals(group, groups.get(0)); Group found = subjectCredentialsService.getGroup(group.getName()); assertGroupEquals(group, found); }
@Test public void test_delete_user_with_groups() { SubjectCredentials subjectCredentials = SubjectCredentials.Builder.create() .authenticationType(SubjectCredentials.AuthenticationType.PASSWORD) .name("user1") .password("password") .groups(Sets.newHashSet("group1", "group2")) .build(); subjectCredentialsService.save(subjectCredentials); subjectCredentialsService.delete(subjectCredentials); assertThat( subjectCredentialsService.getSubjectCredentials( SubjectCredentials.AuthenticationType.PASSWORD)) .isEmpty(); Group group1 = subjectCredentialsService.getGroup("group1"); assertThat(group1.getSubjectCredentials()).isEmpty(); Group group2 = subjectCredentialsService.getGroup("group2"); assertThat(group2.getSubjectCredentials()).isEmpty(); }