1

Merge remote-tracking branch 'origin/master' into ControllerServiceTests

# Conflicts:
#	src/main/java/mops/gruppen2/service/ControllerService.java
#	src/main/java/mops/gruppen2/service/GroupService.java
#	src/test/java/mops/gruppen2/service/ControllerServiceTest.java
#	src/test/java/mops/gruppen2/service/GroupServiceTest.java
This commit is contained in:
killerber4t
2020-03-27 14:48:54 +01:00
89 changed files with 1348 additions and 467 deletions

View File

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

View File

@ -88,12 +88,12 @@ class GroupServiceTest {
@Test
void getGroupEvents() {
// 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 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);
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
createPublicGroupEvent(uuidFromInt(1)),
createPrivateGroupEvent(uuidFromInt(2)));
createPublicGroupEvent(uuidFromInt(1)),
createPrivateGroupEvent(uuidFromInt(2)));
List<UUID> groupIds = Arrays.asList(uuidFromInt(0), uuidFromInt(1));
@ -117,90 +117,90 @@ class GroupServiceTest {
Group group = TestBuilder.apply(test1, test2);
assertThat(group.getType()).isEqualTo(null);
assertThat(groupService.getAllGroupsWithVisibilityPublic("test1")).isEmpty();
assertThat(groupService.getAllGroupWithVisibilityPublic("errer")).isEmpty();
}
@Test
void getAllGroupWithVisibilityPublicTestGroupPublic() {
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
// eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
// 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 CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
//eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
//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.saveAll(createPublicGroupEvent(uuidFromInt(0)),
deleteGroupEvent(uuidFromInt(0)),
createPublicGroupEvent());
deleteGroupEvent(uuidFromInt(0)),
createPublicGroupEvent());
assertThat(groupService.getAllGroupsWithVisibilityPublic("test1").size()).isEqualTo(1);
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
}
@Test
void getAllGroupWithVisibilityPublicTestAddSomeEvents() {
// eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
// eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
// 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 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(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
//eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
//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 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(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
deleteGroupEvent(uuidFromInt(0)),
createPublicGroupEvent(),
createPublicGroupEvent(),
createPublicGroupEvent(),
createPrivateGroupEvent());
deleteGroupEvent(uuidFromInt(0)),
createPublicGroupEvent(),
createPublicGroupEvent(),
createPublicGroupEvent(),
createPrivateGroupEvent());
assertThat(groupService.getAllGroupsWithVisibilityPublic("test1").size()).isEqualTo(3);
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
}
@Test
void getAllGroupWithVisibilityPublic_UserInGroup() {
// 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 CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
//eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test"));
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
addUserEvent(uuidFromInt(0), "kobold"),
createPrivateGroupEvent(),
createPublicGroupEvent());
addUserEvent(uuidFromInt(0), "kobold"),
createPrivateGroupEvent(),
createPublicGroupEvent());
//Das kommt glaube ich eher in einen Test für die Projektion
//assertThat(groupService.getAllGroupWithVisibilityPublic("test2").get(0).getMembers().size()).isEqualTo(1);
assertThat(groupService.getAllGroupsWithVisibilityPublic("kobold")).hasSize(1);
assertThat(groupService.getAllGroupsWithVisibilityPublic("peter")).hasSize(2);
assertThat(groupService.getAllGroupWithVisibilityPublic("kobold")).hasSize(1);
assertThat(groupService.getAllGroupWithVisibilityPublic("peter")).hasSize(2);
}
@Test
void getAllLecturesWithVisibilityPublic() {
// 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 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(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(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
//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 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(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
eventService.saveAll(createLectureEvent(),
createPublicGroupEvent(),
createLectureEvent(),
createLectureEvent(),
createLectureEvent());
createPublicGroupEvent(),
createLectureEvent(),
createLectureEvent(),
createLectureEvent());
assertThat(groupService.getAllLecturesWithVisibilityPublic().size()).isEqualTo(4);
}
@Test
void findGroupWith_UserMember_AllGroups() {
// 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 UpdateGroupTitleEvent(uuidFromInt(0), "test1", "TestGroup"));
// eventService.saveEvent(new UpdateGroupDescriptionEvent(uuidFromInt(0), "test1", "TestDescription"));
// eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(0), "test1", Role.MEMBER));
//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 UpdateGroupTitleEvent(uuidFromInt(0), "test1", "TestGroup"));
//eventService.saveEvent(new UpdateGroupDescriptionEvent(uuidFromInt(0), "test1", "TestDescription"));
//eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(0), "test1", Role.MEMBER));
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
addUserEvent(uuidFromInt(0), "jens"),
updateGroupTitleEvent(uuidFromInt(0)),
updateGroupDescriptionEvent(uuidFromInt(0)));
addUserEvent(uuidFromInt(0), "jens"),
updateGroupTitleEvent(uuidFromInt(0)),
updateGroupDescriptionEvent(uuidFromInt(0)));
//assertThat(groupService.findGroupWith("T", new Account("jens", "a@A", "test", "peter", "mueller", null)).size()).isEqualTo(1);
assertThat(groupService.findGroupWith("", account("jens"))).isEmpty();
@ -209,7 +209,7 @@ class GroupServiceTest {
@Test
void findGroupWith_UserNoMember_AllGroups() {
eventService.saveAll(completePublicGroups(10, 0),
completePrivateGroups(10, 0));
completePrivateGroups(10, 0));
assertThat(groupService.findGroupWith("", account("jens"))).hasSize(10);
}
@ -217,12 +217,12 @@ class GroupServiceTest {
@Test
void findGroupWith_FilterGroups() {
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
updateGroupTitleEvent(uuidFromInt(0), "KK"),
updateGroupDescriptionEvent(uuidFromInt(0), "ABCDE"),
createPublicGroupEvent(uuidFromInt(1)),
updateGroupTitleEvent(uuidFromInt(1), "ABCDEFG"),
updateGroupDescriptionEvent(uuidFromInt(1), "KK"),
createPrivateGroupEvent());
updateGroupTitleEvent(uuidFromInt(0), "KK"),
updateGroupDescriptionEvent(uuidFromInt(0), "ABCDE"),
createPublicGroupEvent(uuidFromInt(1)),
updateGroupTitleEvent(uuidFromInt(1), "ABCDEFG"),
updateGroupDescriptionEvent(uuidFromInt(1), "KK"),
createPrivateGroupEvent());
assertThat(groupService.findGroupWith("A", account("jesus"))).hasSize(2);
assertThat(groupService.findGroupWith("F", account("jesus"))).hasSize(1);