1

new eventbuilderservice + projectionservice + searchservice, some renamings etc

This commit is contained in:
Christoph
2020-04-06 00:07:46 +02:00
parent 5a5d1586ed
commit 3d66f58af8
17 changed files with 503 additions and 389 deletions

View File

@ -2,7 +2,7 @@ package mops.gruppen2.controller;
import mops.gruppen2.Gruppen2Application;
import mops.gruppen2.repository.EventRepository;
import mops.gruppen2.service.EventService;
import mops.gruppen2.service.EventStoreService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -33,13 +33,13 @@ class APIControllerTest {
private EventRepository eventRepository;
@Autowired
private APIController apiController;
private EventService eventService;
private EventStoreService eventStoreService;
@Autowired
private JdbcTemplate template;
@BeforeEach
void setUp() {
eventService = new EventService(eventRepository);
eventStoreService = new EventStoreService(eventRepository);
eventRepository.deleteAll();
//noinspection SqlResolve
template.execute("ALTER TABLE event ALTER COLUMN event_id RESTART WITH 1");
@ -57,11 +57,11 @@ class APIControllerTest {
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void updateGroup_singleGroup() {
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
addUserEvent(uuidMock(0)));
eventStoreService.saveAll(createPublicGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
addUserEvent(uuidMock(0)));
assertThat(apiController.updateGroups(0L).getGroupList()).hasSize(1);
assertThat(apiController.updateGroups(4L).getGroupList()).hasSize(1);
@ -73,13 +73,13 @@ class APIControllerTest {
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void updateGroup_multipleGroups() {
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
createPrivateGroupEvent(uuidMock(1)),
addUserEvent(uuidMock(1)),
addUserEvent(uuidMock(1)),
addUserEvent(uuidMock(1)));
eventStoreService.saveAll(createPublicGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
createPrivateGroupEvent(uuidMock(1)),
addUserEvent(uuidMock(1)),
addUserEvent(uuidMock(1)),
addUserEvent(uuidMock(1)));
assertThat(apiController.updateGroups(0L).getGroupList()).hasSize(2);
assertThat(apiController.updateGroups(4L).getGroupList()).hasSize(1);
@ -97,10 +97,10 @@ class APIControllerTest {
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupsOfUser_singleGroup() {
eventService.saveAll(createPrivateGroupEvent(uuidMock(0)),
createPrivateGroupEvent(uuidMock(1)),
createPrivateGroupEvent(uuidMock(2)),
addUserEvent(uuidMock(0), "A"));
eventStoreService.saveAll(createPrivateGroupEvent(uuidMock(0)),
createPrivateGroupEvent(uuidMock(1)),
createPrivateGroupEvent(uuidMock(2)),
addUserEvent(uuidMock(0), "A"));
assertThat(apiController.getGroupIdsOfUser("A")).hasSize(1);
}
@ -108,9 +108,9 @@ class APIControllerTest {
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupsOfUser_singleGroupDeletedUser() {
eventService.saveAll(createPrivateGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0), "A"),
deleteUserEvent(uuidMock(0), "A"));
eventStoreService.saveAll(createPrivateGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0), "A"),
deleteUserEvent(uuidMock(0), "A"));
assertThat(apiController.getGroupIdsOfUser("A")).isEmpty();
}
@ -118,9 +118,9 @@ class APIControllerTest {
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupsOfUser_singleDeletedGroup() {
eventService.saveAll(createPrivateGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0), "A"),
deleteGroupEvent(uuidMock(0)));
eventStoreService.saveAll(createPrivateGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0), "A"),
deleteGroupEvent(uuidMock(0)));
assertThat(apiController.getGroupIdsOfUser("A")).isEmpty();
}
@ -128,14 +128,14 @@ class APIControllerTest {
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupsOfUser_multipleGroups() {
eventService.saveAll(createPrivateGroupEvent(uuidMock(0)),
createPrivateGroupEvent(uuidMock(1)),
createPrivateGroupEvent(uuidMock(2)),
addUserEvent(uuidMock(0), "A"),
addUserEvent(uuidMock(0), "B"),
addUserEvent(uuidMock(1), "A"),
addUserEvent(uuidMock(2), "A"),
addUserEvent(uuidMock(2), "B"));
eventStoreService.saveAll(createPrivateGroupEvent(uuidMock(0)),
createPrivateGroupEvent(uuidMock(1)),
createPrivateGroupEvent(uuidMock(2)),
addUserEvent(uuidMock(0), "A"),
addUserEvent(uuidMock(0), "B"),
addUserEvent(uuidMock(1), "A"),
addUserEvent(uuidMock(2), "A"),
addUserEvent(uuidMock(2), "B"));
assertThat(apiController.getGroupIdsOfUser("A")).hasSize(3);
assertThat(apiController.getGroupIdsOfUser("B")).hasSize(2);
@ -150,7 +150,7 @@ class APIControllerTest {
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupFromId_singleGroup() {
eventService.saveAll(createPrivateGroupEvent(uuidMock(0)));
eventStoreService.saveAll(createPrivateGroupEvent(uuidMock(0)));
assertThat(apiController.getGroupById(uuidMock(0).toString()).getId()).isEqualTo(uuidMock(0));
}
@ -158,9 +158,9 @@ class APIControllerTest {
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupFromId_deletedGroup() {
eventService.saveAll(createPrivateGroupEvent(uuidMock(0)),
updateGroupTitleEvent(uuidMock(0)),
deleteGroupEvent(uuidMock(0)));
eventStoreService.saveAll(createPrivateGroupEvent(uuidMock(0)),
updateGroupTitleEvent(uuidMock(0)),
deleteGroupEvent(uuidMock(0)));
assertThat(apiController.getGroupById(uuidMock(0).toString()).getTitle()).isEqualTo(null);
}

View File

@ -38,7 +38,7 @@ class ControllerServiceTest {
Account account2;
Account account3;
ControllerService controllerService;
EventService eventService;
EventStoreService eventStoreService;
UserService userService;
ValidationService validationService;
@Autowired
@ -46,14 +46,18 @@ class ControllerServiceTest {
GroupService groupService;
@Autowired
InviteService inviteService;
@Autowired
SearchService searchService;
@Autowired
ProjectionService projectionService;
@BeforeEach
void setUp() {
eventService = new EventService(eventRepository);
groupService = new GroupService(eventService, eventRepository);
userService = new UserService(groupService, eventService);
validationService = new ValidationService(userService, groupService);
controllerService = new ControllerService(eventService, userService, validationService, inviteService);
eventStoreService = new EventStoreService(eventRepository);
groupService = new GroupService(eventStoreService, eventRepository);
userService = new UserService(groupService, eventStoreService, projectionService);
validationService = new ValidationService(userService, searchService);
controllerService = new ControllerService(eventStoreService, userService, validationService, inviteService);
Set<String> roles = new HashSet<>();
roles.add("l");
account = new Account("ich", "ich@hhu.de", "l", "ichdude", "jap", roles);

View File

@ -26,17 +26,17 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = Gruppen2Application.class)
@Transactional
@Rollback
class EventServiceTest {
class EventStoreServiceTest {
@Autowired
private EventRepository eventRepository;
private EventService eventService;
private EventStoreService eventStoreService;
@Autowired
private JdbcTemplate template;
@BeforeEach
void setUp() {
eventService = new EventService(eventRepository);
eventStoreService = new EventStoreService(eventRepository);
eventRepository.deleteAll();
//noinspection SqlResolve
template.execute("ALTER TABLE event ALTER COLUMN event_id RESTART WITH 1");
@ -44,22 +44,22 @@ class EventServiceTest {
@Test
void saveEvent() {
eventService.saveEvent(createPublicGroupEvent());
eventStoreService.saveEvent(createPublicGroupEvent());
assertThat(eventRepository.findAll()).hasSize(1);
}
@Test
void saveAll() {
eventService.saveAll(createPrivateGroupEvents(10));
eventStoreService.saveAll(createPrivateGroupEvents(10));
assertThat(eventRepository.findAll()).hasSize(10);
}
@Test
void testSaveAll() {
eventService.saveAll(createPublicGroupEvents(5),
createPrivateGroupEvents(5));
eventStoreService.saveAll(createPublicGroupEvents(5),
createPrivateGroupEvents(5));
assertThat(eventRepository.findAll()).hasSize(10);
}
@ -68,7 +68,7 @@ class EventServiceTest {
void getDTO() {
Event event = createPublicGroupEvent();
EventDTO dto = eventService.getDTOFromEvent(event);
EventDTO dto = eventStoreService.getDTOFromEvent(event);
assertThat(dto.getGroup_id()).isEqualTo(event.getGroupId().toString());
assertThat(dto.getUser_id()).isEqualTo(event.getUserId());
@ -78,22 +78,22 @@ class EventServiceTest {
@Test
void getEventsOfGroup() {
eventService.saveAll(addUserEvents(10, uuidMock(0)),
addUserEvents(5, uuidMock(1)));
eventStoreService.saveAll(addUserEvents(10, uuidMock(0)),
addUserEvents(5, uuidMock(1)));
assertThat(eventService.getEventsOfGroup(uuidMock(0))).hasSize(10);
assertThat(eventService.getEventsOfGroup(uuidMock(1))).hasSize(5);
assertThat(eventStoreService.getEventsOfGroup(uuidMock(0))).hasSize(10);
assertThat(eventStoreService.getEventsOfGroup(uuidMock(1))).hasSize(5);
}
@Test
void findGroupIdsByUser() {
eventService.saveAll(addUserEvent(uuidMock(0), "A"),
addUserEvent(uuidMock(1), "A"),
addUserEvent(uuidMock(2), "A"),
addUserEvent(uuidMock(3), "A"),
addUserEvent(uuidMock(3), "B"));
eventStoreService.saveAll(addUserEvent(uuidMock(0), "A"),
addUserEvent(uuidMock(1), "A"),
addUserEvent(uuidMock(2), "A"),
addUserEvent(uuidMock(3), "A"),
addUserEvent(uuidMock(3), "B"));
assertThat(eventService.findGroupIdsByUser("A")).hasSize(4);
assertThat(eventService.findGroupIdsByUser("B")).hasSize(1);
assertThat(eventStoreService.findGroupIdsByUser("A")).hasSize(4);
assertThat(eventStoreService.findGroupIdsByUser("B")).hasSize(1);
}
}

View File

@ -43,45 +43,52 @@ class GroupServiceTest {
@Autowired
private EventRepository eventRepository;
@Autowired
private EventService eventService;
SearchService searchService;
private GroupService groupService;
@Autowired
private JdbcTemplate template;
@Autowired
ProjectionService projectionService;
@Autowired
private EventStoreService eventStoreService;
@BeforeEach
void setUp() {
groupService = new GroupService(eventService, eventRepository);
groupService = new GroupService(eventStoreService, eventRepository);
eventRepository.deleteAll();
//noinspection SqlResolve
template.execute("ALTER TABLE event ALTER COLUMN event_id RESTART WITH 1");
}
//TODO: Wofür ist dieser Test?
//TODO: ProjectionServiceTest
@Test
void rightClassForSuccessfulGroup() {
List<Event> eventList = completePrivateGroup(1);
List<Group> groups = groupService.projectEventList(eventList);
List<Group> groups = projectionService.projectEventList(eventList);
assertThat(groups.get(0)).isInstanceOf(Group.class);
}
//TODO: ProjectionServiceTest
@Test
void projectEventList_SingleGroup() {
List<Event> eventList = completePrivateGroup(5);
List<Group> groups = groupService.projectEventList(eventList);
List<Group> groups = projectionService.projectEventList(eventList);
assertThat(groups).hasSize(1);
assertThat(groups.get(0).getMembers()).hasSize(5);
assertThat(groups.get(0).getVisibility()).isEqualTo(Visibility.PRIVATE);
}
//TODO: ProjectionServiceTest
@Test
void projectEventList_MultipleGroups() {
List<Event> eventList = completePrivateGroups(10, 2);
eventList.addAll(completePublicGroups(10, 5));
List<Group> groups = groupService.projectEventList(eventList);
List<Group> groups = projectionService.projectEventList(eventList);
assertThat(groups).hasSize(20);
assertThat(groups.stream().map(group -> group.getMembers().size()).reduce(Integer::sum).get()).isEqualTo(70);
@ -89,9 +96,9 @@ class GroupServiceTest {
@Test
void getGroupEvents() {
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
createPublicGroupEvent(uuidMock(1)),
createPrivateGroupEvent(uuidMock(2)));
eventStoreService.saveAll(createPublicGroupEvent(uuidMock(0)),
createPublicGroupEvent(uuidMock(1)),
createPrivateGroupEvent(uuidMock(2)));
List<UUID> groupIds = Arrays.asList(uuidMock(0), uuidMock(1));
@ -100,6 +107,7 @@ class GroupServiceTest {
assertThat(groupService.getGroupEvents(groupIds).get(1).getGroupId()).isEqualTo(uuidMock(1));
}
//TODO: ProjectionServiceTest
@Test
void getAllGroupWithVisibilityPublicTestCreateAndDeleteSameGroup() {
Event test1 = createPublicGroupEvent(uuidMock(0));
@ -109,83 +117,90 @@ class GroupServiceTest {
Group group = TestBuilder.apply(test1, test2);
assertThat(group.getType()).isEqualTo(null);
assertThat(groupService.getAllGroupWithVisibilityPublic("errer")).isEmpty();
assertThat(projectionService.getAllGroupWithVisibilityPublic("errer")).isEmpty();
}
//TODO: ProjectionServiceTest
@Test
void getAllGroupWithVisibilityPublicTestGroupPublic() {
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
deleteGroupEvent(uuidMock(0)),
createPublicGroupEvent());
eventStoreService.saveAll(createPublicGroupEvent(uuidMock(0)),
deleteGroupEvent(uuidMock(0)),
createPublicGroupEvent());
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
assertThat(projectionService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
}
//TODO: ProjectionServiceTest
@Test
void getAllGroupWithVisibilityPublicTestAddSomeEvents() {
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
deleteGroupEvent(uuidMock(0)),
createPublicGroupEvent(),
createPublicGroupEvent(),
createPublicGroupEvent(),
createPrivateGroupEvent());
eventStoreService.saveAll(createPublicGroupEvent(uuidMock(0)),
deleteGroupEvent(uuidMock(0)),
createPublicGroupEvent(),
createPublicGroupEvent(),
createPublicGroupEvent(),
createPrivateGroupEvent());
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
assertThat(projectionService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
}
//TODO: ProjectionServiceTest
@Test
void getAllGroupWithVisibilityPublic_UserInGroup() {
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0), "kobold"),
createPrivateGroupEvent(),
createPublicGroupEvent());
eventStoreService.saveAll(createPublicGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0), "kobold"),
createPrivateGroupEvent(),
createPublicGroupEvent());
assertThat(groupService.getAllGroupWithVisibilityPublic("kobold")).hasSize(1);
assertThat(groupService.getAllGroupWithVisibilityPublic("peter")).hasSize(2);
assertThat(projectionService.getAllGroupWithVisibilityPublic("kobold")).hasSize(1);
assertThat(projectionService.getAllGroupWithVisibilityPublic("peter")).hasSize(2);
}
//TODO: ProjectionServiceTest
@Test
void getAllLecturesWithVisibilityPublic() {
eventService.saveAll(createLectureEvent(),
createPublicGroupEvent(),
createLectureEvent(),
createLectureEvent(),
createLectureEvent());
eventStoreService.saveAll(createLectureEvent(),
createPublicGroupEvent(),
createLectureEvent(),
createLectureEvent(),
createLectureEvent());
assertThat(groupService.getAllLecturesWithVisibilityPublic().size()).isEqualTo(4);
assertThat(projectionService.getAllLecturesWithVisibilityPublic().size()).isEqualTo(4);
}
//TODO: SearchServiceTest
@Test
void findGroupWith_UserMember_AllGroups() {
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0), "jens"),
updateGroupTitleEvent(uuidMock(0)),
updateGroupDescriptionEvent(uuidMock(0)));
eventStoreService.saveAll(createPublicGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0), "jens"),
updateGroupTitleEvent(uuidMock(0)),
updateGroupDescriptionEvent(uuidMock(0)));
assertThat(groupService.findGroupWith("", account("jens"))).isEmpty();
assertThat(searchService.findGroupWith("", account("jens"))).isEmpty();
}
//TODO: SearchServiceTest
@Test
void findGroupWith_UserNoMember_AllGroups() {
eventService.saveAll(completePublicGroups(10, 0),
completePrivateGroups(10, 0));
eventStoreService.saveAll(completePublicGroups(10, 0),
completePrivateGroups(10, 0));
assertThat(groupService.findGroupWith("", account("jens"))).hasSize(10);
assertThat(searchService.findGroupWith("", account("jens"))).hasSize(10);
}
//TODO: SearchServiceTest
@Test
void findGroupWith_FilterGroups() {
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
updateGroupTitleEvent(uuidMock(0), "KK"),
updateGroupDescriptionEvent(uuidMock(0), "ABCDE"),
createPublicGroupEvent(uuidMock(1)),
updateGroupTitleEvent(uuidMock(1), "ABCDEFG"),
updateGroupDescriptionEvent(uuidMock(1), "KK"),
createPrivateGroupEvent());
eventStoreService.saveAll(createPublicGroupEvent(uuidMock(0)),
updateGroupTitleEvent(uuidMock(0), "KK"),
updateGroupDescriptionEvent(uuidMock(0), "ABCDE"),
createPublicGroupEvent(uuidMock(1)),
updateGroupTitleEvent(uuidMock(1), "ABCDEFG"),
updateGroupDescriptionEvent(uuidMock(1), "KK"),
createPrivateGroupEvent());
assertThat(groupService.findGroupWith("A", account("jesus"))).hasSize(2);
assertThat(groupService.findGroupWith("F", account("jesus"))).hasSize(1);
assertThat(groupService.findGroupWith("Z", account("jesus"))).hasSize(0);
assertThat(searchService.findGroupWith("A", account("jesus"))).hasSize(2);
assertThat(searchService.findGroupWith("F", account("jesus"))).hasSize(1);
assertThat(searchService.findGroupWith("Z", account("jesus"))).hasSize(0);
}
}