1

fixed checkstyle in tests

This commit is contained in:
[Mahgs]
2020-03-27 14:38:07 +01:00
parent 9ccb7c77a2
commit 9c984f8572
5 changed files with 93 additions and 92 deletions

View File

@ -226,7 +226,6 @@
<property name="lineWrappingIndentation" value="8"/> <property name="lineWrappingIndentation" value="8"/>
<property name="arrayInitIndent" value="4"/> <property name="arrayInitIndent" value="4"/>
</module> </module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="VariableDeclarationUsageDistance"/> <module name="VariableDeclarationUsageDistance"/>
<module name="MethodParamPad"> <module name="MethodParamPad">
<property name="tokens" <property name="tokens"

View File

@ -48,7 +48,7 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
@Bean @Bean
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST, @Scope(scopeName = WebApplicationContext.SCOPE_REQUEST,
proxyMode = ScopedProxyMode.TARGET_CLASS) proxyMode = ScopedProxyMode.TARGET_CLASS)
public AccessToken getAccessToken() { public AccessToken getAccessToken() {
HttpServletRequest request = HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder ((ServletRequestAttributes) RequestContextHolder
@ -61,10 +61,10 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
super.configure(http); super.configure(http);
http.authorizeRequests() http.authorizeRequests()
.antMatchers("/actuator/**") .antMatchers("/actuator/**")
.hasRole("monitoring") .hasRole("monitoring")
.anyRequest() .anyRequest()
.permitAll(); .permitAll();
} }
/** /**

View File

@ -13,7 +13,9 @@ public class InviteService {
private final InviteRepository inviteRepository; private final InviteRepository inviteRepository;
public InviteService(InviteRepository inviteRepository) {this.inviteRepository = inviteRepository;} public InviteService(InviteRepository inviteRepository) {
this.inviteRepository = inviteRepository;
}
public void createLink(UUID groupId) { public void createLink(UUID groupId) {
inviteRepository.save(new InviteLinkDTO(null, groupId.toString(), UUID.randomUUID().toString())); inviteRepository.save(new InviteLinkDTO(null, groupId.toString(), UUID.randomUUID().toString()));

View File

@ -29,11 +29,11 @@ public class TestBuilder {
public static Account account(String name) { public static Account account(String name) {
return new Account(name, return new Account(name,
"", "",
"", "",
"", "",
"", "",
null); null);
} }
public static Group apply(Group group, Event... events) { public static Group apply(Group group, Event... events) {
@ -56,8 +56,8 @@ public class TestBuilder {
*/ */
public static UUID uuidFromInt(int id) { public static UUID uuidFromInt(int id) {
return UUID.fromString("00000000-0000-0000-0000-" return UUID.fromString("00000000-0000-0000-0000-"
+ "0".repeat(11 - String.valueOf(id).length()) + "0".repeat(11 - String.valueOf(id).length())
+ id); + id);
} }
/** /**
@ -69,18 +69,18 @@ public class TestBuilder {
*/ */
public static List<Event> completePublicGroups(int count, int membercount) { public static List<Event> completePublicGroups(int count, int membercount) {
return IntStream.range(0, count) return IntStream.range(0, count)
.parallel() .parallel()
.mapToObj(i -> completePublicGroup(membercount)) .mapToObj(i -> completePublicGroup(membercount))
.flatMap(Collection::stream) .flatMap(Collection::stream)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static List<Event> completePrivateGroups(int count, int membercount) { public static List<Event> completePrivateGroups(int count, int membercount) {
return IntStream.range(0, count) return IntStream.range(0, count)
.parallel() .parallel()
.mapToObj(i -> completePrivateGroup(membercount)) .mapToObj(i -> completePrivateGroup(membercount))
.flatMap(Collection::stream) .flatMap(Collection::stream)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static List<Event> completePublicGroup(int membercount) { public static List<Event> completePublicGroup(int membercount) {
@ -123,25 +123,25 @@ public class TestBuilder {
*/ */
public static List<Event> createPublicGroupEvents(int count) { public static List<Event> createPublicGroupEvents(int count) {
return IntStream.range(0, count) return IntStream.range(0, count)
.parallel() .parallel()
.mapToObj(i -> createPublicGroupEvent()) .mapToObj(i -> createPublicGroupEvent())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static List<Event> createPrivateGroupEvents(int count) { public static List<Event> createPrivateGroupEvents(int count) {
return IntStream.range(0, count) return IntStream.range(0, count)
.parallel() .parallel()
.mapToObj(i -> createPublicGroupEvent()) .mapToObj(i -> createPublicGroupEvent())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static List<Event> createMixedGroupEvents(int count) { public static List<Event> createMixedGroupEvents(int count) {
return IntStream.range(0, count) return IntStream.range(0, count)
.parallel() .parallel()
.mapToObj(i -> faker.random().nextInt(0, 1) > 0.5 .mapToObj(i -> faker.random().nextInt(0, 1) > 0.5
? createPublicGroupEvent() ? createPublicGroupEvent()
: createPrivateGroupEvent()) : createPrivateGroupEvent())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static Event createPrivateGroupEvent(UUID groupId) { public static Event createPrivateGroupEvent(UUID groupId) {
@ -195,9 +195,9 @@ public class TestBuilder {
*/ */
public static List<Event> addUserEvents(int count, UUID groupId) { public static List<Event> addUserEvents(int count, UUID groupId) {
return IntStream.range(0, count) return IntStream.range(0, count)
.parallel() .parallel()
.mapToObj(i -> addUserEvent(groupId, String.valueOf(i))) .mapToObj(i -> addUserEvent(groupId, String.valueOf(i)))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static Event addUserEvent(UUID groupId, String userId) { public static Event addUserEvent(UUID groupId, String userId) {
@ -221,8 +221,8 @@ public class TestBuilder {
public static List<Event> deleteUserEvents(int count, List<Event> eventList) { public static List<Event> deleteUserEvents(int count, List<Event> eventList) {
List<Event> removeEvents = new ArrayList<>(); List<Event> removeEvents = new ArrayList<>();
List<Event> shuffle = eventList.parallelStream() List<Event> shuffle = eventList.parallelStream()
.filter(event -> event instanceof AddUserEvent) .filter(event -> event instanceof AddUserEvent)
.collect(Collectors.toList()); .collect(Collectors.toList());
Collections.shuffle(shuffle); Collections.shuffle(shuffle);
@ -245,8 +245,8 @@ public class TestBuilder {
*/ */
public static List<Event> deleteUserEvents(Group group) { public static List<Event> deleteUserEvents(Group group) {
return group.getMembers().parallelStream() return group.getMembers().parallelStream()
.map(user -> deleteUserEvent(group.getId(), user.getId())) .map(user -> deleteUserEvent(group.getId(), user.getId()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static Event deleteUserEvent(UUID groupId, String userId) { public static Event deleteUserEvent(UUID groupId, String userId) {

View File

@ -87,12 +87,12 @@ class GroupServiceTest {
@Test @Test
void getGroupEvents() { void getGroupEvents() {
// CreateGroupEvent test1 = new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L); //CreateGroupEvent test1 = new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L);
// CreateGroupEvent test2 = new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.SIMPLE, Visibility.PUBLIC, 10L); //CreateGroupEvent test2 = new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.SIMPLE, Visibility.PUBLIC, 10L);
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)), eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
createPublicGroupEvent(uuidFromInt(1)), createPublicGroupEvent(uuidFromInt(1)),
createPrivateGroupEvent(uuidFromInt(2))); createPrivateGroupEvent(uuidFromInt(2)));
List<UUID> groupIds = Arrays.asList(uuidFromInt(0), uuidFromInt(1)); List<UUID> groupIds = Arrays.asList(uuidFromInt(0), uuidFromInt(1));
@ -121,47 +121,47 @@ class GroupServiceTest {
@Test @Test
void getAllGroupWithVisibilityPublicTestGroupPublic() { void getAllGroupWithVisibilityPublicTestGroupPublic() {
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
// eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1")); //eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
// eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); //Wofür ist das //eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); //Wofür ist das
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)), eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
deleteGroupEvent(uuidFromInt(0)), deleteGroupEvent(uuidFromInt(0)),
createPublicGroupEvent()); createPublicGroupEvent());
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1); assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
} }
@Test @Test
void getAllGroupWithVisibilityPublicTestAddSomeEvents() { void getAllGroupWithVisibilityPublicTestAddSomeEvents() {
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
// eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1")); //eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
// eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); // Wofür? //eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); // Wofür?
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(2), "test3", null, GroupType.LECTURE, Visibility.PUBLIC, 10L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(2), "test3", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(3), "test4", null, GroupType.LECTURE, Visibility.PUBLIC, 10L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(3), "test4", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)), eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
deleteGroupEvent(uuidFromInt(0)), deleteGroupEvent(uuidFromInt(0)),
createPublicGroupEvent(), createPublicGroupEvent(),
createPublicGroupEvent(), createPublicGroupEvent(),
createPublicGroupEvent(), createPublicGroupEvent(),
createPrivateGroupEvent()); createPrivateGroupEvent());
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3); assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
} }
@Test @Test
void getAllGroupWithVisibilityPublic_UserInGroup() { void getAllGroupWithVisibilityPublic_UserInGroup() {
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
// eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test")); //eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test"));
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)), eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
addUserEvent(uuidFromInt(0), "kobold"), addUserEvent(uuidFromInt(0), "kobold"),
createPrivateGroupEvent(), createPrivateGroupEvent(),
createPublicGroupEvent()); createPublicGroupEvent());
//Das kommt glaube ich eher in einen Test für die Projektion //Das kommt glaube ich eher in einen Test für die Projektion
//assertThat(groupService.getAllGroupWithVisibilityPublic("test2").get(0).getMembers().size()).isEqualTo(1); //assertThat(groupService.getAllGroupWithVisibilityPublic("test2").get(0).getMembers().size()).isEqualTo(1);
@ -172,34 +172,34 @@ class GroupServiceTest {
@Test @Test
void getAllLecturesWithVisibilityPublic() { void getAllLecturesWithVisibilityPublic() {
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
// eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); // Hä //eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); // Hä
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(2), "test3", null, GroupType.LECTURE, Visibility.PUBLIC, 10L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(2), "test3", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(3), "test4", null, GroupType.LECTURE, Visibility.PUBLIC, 10L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(3), "test4", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
eventService.saveAll(createLectureEvent(), eventService.saveAll(createLectureEvent(),
createPublicGroupEvent(), createPublicGroupEvent(),
createLectureEvent(), createLectureEvent(),
createLectureEvent(), createLectureEvent(),
createLectureEvent()); createLectureEvent());
assertThat(groupService.getAllLecturesWithVisibilityPublic().size()).isEqualTo(4); assertThat(groupService.getAllLecturesWithVisibilityPublic().size()).isEqualTo(4);
} }
@Test @Test
void findGroupWith_UserMember_AllGroups() { void findGroupWith_UserMember_AllGroups() {
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L)); //eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
// eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test")); //eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test"));
// eventService.saveEvent(new UpdateGroupTitleEvent(uuidFromInt(0), "test1", "TestGroup")); //eventService.saveEvent(new UpdateGroupTitleEvent(uuidFromInt(0), "test1", "TestGroup"));
// eventService.saveEvent(new UpdateGroupDescriptionEvent(uuidFromInt(0), "test1", "TestDescription")); //eventService.saveEvent(new UpdateGroupDescriptionEvent(uuidFromInt(0), "test1", "TestDescription"));
// eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(0), "test1", Role.MEMBER)); //eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(0), "test1", Role.MEMBER));
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)), eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
addUserEvent(uuidFromInt(0), "jens"), addUserEvent(uuidFromInt(0), "jens"),
updateGroupTitleEvent(uuidFromInt(0)), updateGroupTitleEvent(uuidFromInt(0)),
updateGroupDescriptionEvent(uuidFromInt(0))); updateGroupDescriptionEvent(uuidFromInt(0)));
//assertThat(groupService.findGroupWith("T", new Account("jens", "a@A", "test", "peter", "mueller", null)).size()).isEqualTo(1); //assertThat(groupService.findGroupWith("T", new Account("jens", "a@A", "test", "peter", "mueller", null)).size()).isEqualTo(1);
assertThat(groupService.findGroupWith("", account("jens"))).isEmpty(); assertThat(groupService.findGroupWith("", account("jens"))).isEmpty();
@ -208,7 +208,7 @@ class GroupServiceTest {
@Test @Test
void findGroupWith_UserNoMember_AllGroups() { void findGroupWith_UserNoMember_AllGroups() {
eventService.saveAll(completePublicGroups(10, 0), eventService.saveAll(completePublicGroups(10, 0),
completePrivateGroups(10, 0)); completePrivateGroups(10, 0));
assertThat(groupService.findGroupWith("", account("jens"))).hasSize(10); assertThat(groupService.findGroupWith("", account("jens"))).hasSize(10);
} }
@ -216,12 +216,12 @@ class GroupServiceTest {
@Test @Test
void findGroupWith_FilterGroups() { void findGroupWith_FilterGroups() {
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)), eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
updateGroupTitleEvent(uuidFromInt(0), "KK"), updateGroupTitleEvent(uuidFromInt(0), "KK"),
updateGroupDescriptionEvent(uuidFromInt(0), "ABCDE"), updateGroupDescriptionEvent(uuidFromInt(0), "ABCDE"),
createPublicGroupEvent(uuidFromInt(1)), createPublicGroupEvent(uuidFromInt(1)),
updateGroupTitleEvent(uuidFromInt(1), "ABCDEFG"), updateGroupTitleEvent(uuidFromInt(1), "ABCDEFG"),
updateGroupDescriptionEvent(uuidFromInt(1), "KK"), updateGroupDescriptionEvent(uuidFromInt(1), "KK"),
createPrivateGroupEvent()); createPrivateGroupEvent());
assertThat(groupService.findGroupWith("A", account("jesus"))).hasSize(2); assertThat(groupService.findGroupWith("A", account("jesus"))).hasSize(2);
assertThat(groupService.findGroupWith("F", account("jesus"))).hasSize(1); assertThat(groupService.findGroupWith("F", account("jesus"))).hasSize(1);