1

"finish" service refactor + fix obvious bugs after refactor (everything should run pretty much)

This commit is contained in:
Christoph
2020-04-08 20:48:42 +02:00
parent 9da2d51897
commit 482dde7960
48 changed files with 655 additions and 520 deletions

View File

@ -14,6 +14,7 @@ import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
import mops.gruppen2.domain.event.UpdateRoleEvent;
import mops.gruppen2.domain.event.UpdateUserLimitEvent;
import java.util.ArrayList;
import java.util.Collection;
@ -93,6 +94,7 @@ public class TestBuilder {
eventList.add(createPublicGroupEvent(groupId));
eventList.add(updateGroupTitleEvent(groupId));
eventList.add(updateGroupDescriptionEvent(groupId));
eventList.add(new UpdateUserLimitEvent(groupId, "fgsadggas", Long.MAX_VALUE));
eventList.addAll(addUserEvents(membercount, groupId));
return eventList;
@ -105,6 +107,7 @@ public class TestBuilder {
eventList.add(createPrivateGroupEvent(groupId));
eventList.add(updateGroupTitleEvent(groupId));
eventList.add(updateGroupDescriptionEvent(groupId));
eventList.add(new UpdateUserLimitEvent(groupId, "fgsadggas", Long.MAX_VALUE));
eventList.addAll(addUserEvents(membercount, groupId));
return eventList;
@ -170,8 +173,7 @@ public class TestBuilder {
faker.random().hex(),
null,
GroupType.SIMPLE,
visibility,
10000000L
visibility
);
}
@ -185,8 +187,7 @@ public class TestBuilder {
faker.random().hex(),
null,
GroupType.LECTURE,
Visibility.PUBLIC,
10000000L
Visibility.PUBLIC
);
}
@ -286,6 +287,10 @@ public class TestBuilder {
);
}
public static Event updateUserLimitMaxEvent(UUID groupId) {
return new UpdateUserLimitEvent(groupId, firstname(), Long.MAX_VALUE);
}
public static Event updateRoleEvent(UUID groupId, String userId, Role role) {
return new UpdateRoleEvent(
groupId,

View File

@ -22,6 +22,7 @@ import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
import static mops.gruppen2.TestBuilder.deleteGroupEvent;
import static mops.gruppen2.TestBuilder.deleteUserEvent;
import static mops.gruppen2.TestBuilder.updateGroupTitleEvent;
import static mops.gruppen2.TestBuilder.updateUserLimitMaxEvent;
import static mops.gruppen2.TestBuilder.uuidMock;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -36,13 +37,13 @@ class APIControllerTest {
private EventRepository eventRepository;
@Autowired
private APIController apiController;
@Autowired
private EventStoreService eventStoreService;
@Autowired
private JdbcTemplate template;
@BeforeEach
void setUp() {
eventStoreService = new EventStoreService(eventRepository);
eventRepository.deleteAll();
//noinspection SqlResolve
template.execute("ALTER TABLE event ALTER COLUMN event_id RESTART WITH 1");
@ -61,6 +62,7 @@ class APIControllerTest {
@WithMockUser(username = "api_user", roles = "api_user")
void updateGroup_singleGroup() {
eventStoreService.saveAll(createPublicGroupEvent(uuidMock(0)),
updateUserLimitMaxEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
@ -69,7 +71,7 @@ class APIControllerTest {
assertThat(apiController.updateGroups(0L).getGroupList()).hasSize(1);
assertThat(apiController.updateGroups(4L).getGroupList()).hasSize(1);
assertThat(apiController.updateGroups(10L).getGroupList()).hasSize(0);
assertThat(apiController.updateGroups(0L).getStatus()).isEqualTo(5);
assertThat(apiController.updateGroups(0L).getStatus()).isEqualTo(6);
}
@ -77,9 +79,11 @@ class APIControllerTest {
@WithMockUser(username = "api_user", roles = "api_user")
void updateGroup_multipleGroups() {
eventStoreService.saveAll(createPublicGroupEvent(uuidMock(0)),
updateUserLimitMaxEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
addUserEvent(uuidMock(0)),
createPrivateGroupEvent(uuidMock(1)),
updateUserLimitMaxEvent(uuidMock(1)),
addUserEvent(uuidMock(1)),
addUserEvent(uuidMock(1)),
addUserEvent(uuidMock(1)));

View File

@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test;
import static mops.gruppen2.TestBuilder.addUserEvent;
import static mops.gruppen2.TestBuilder.apply;
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
import static mops.gruppen2.TestBuilder.updateUserLimitMaxEvent;
import static mops.gruppen2.TestBuilder.uuidMock;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -17,9 +18,10 @@ class AddUserEventTest {
@Test
void applyEvent() {
Event createEvent = createPublicGroupEvent(uuidMock(0));
Event updateLimitEvent = updateUserLimitMaxEvent(uuidMock(0));
Event addEvent = new AddUserEvent(uuidMock(0), "A", "Thomas", "Tom", "tho@mail.de");
Group group = apply(createEvent, addEvent);
Group group = apply(createEvent, updateLimitEvent, addEvent);
assertThat(group.getMembers()).hasSize(1);
assertThat(group.getMembers().get(0).getGivenname()).isEqualTo("Thomas");
@ -30,11 +32,12 @@ class AddUserEventTest {
@Test
void applyEvent_userAlreadyExists() {
Event createEvent = createPublicGroupEvent(uuidMock(0));
Event updateLimitEvent = updateUserLimitMaxEvent(uuidMock(0));
Event addEventA = addUserEvent(uuidMock(0), "A");
Event addEventB = addUserEvent(uuidMock(0), "B");
Event addEventC = addUserEvent(uuidMock(0), "A");
Group group = apply(createEvent, addEventA, addEventB);
Group group = apply(createEvent, updateLimitEvent, addEventA, addEventB);
assertThrows(UserAlreadyExistsException.class, () -> addEventA.apply(group));
assertThrows(UserAlreadyExistsException.class, () -> addEventC.apply(group));

View File

@ -17,15 +17,13 @@ class CreateGroupEventTest {
"A",
uuidMock(1),
GroupType.SIMPLE,
Visibility.PUBLIC,
100L);
Visibility.PUBLIC);
Group group = TestBuilder.apply(createEvent);
assertThat(group.getMembers()).hasSize(0);
assertThat(group.getType()).isEqualTo(GroupType.SIMPLE);
assertThat(group.getVisibility()).isEqualTo(Visibility.PUBLIC);
assertThat(group.getUserLimit()).isEqualTo(100);
assertThat(group.getId()).isEqualTo(uuidMock(0));
assertThat(group.getParent()).isEqualTo(uuidMock(1));
}

View File

@ -17,8 +17,7 @@ class DeleteGroupEventTest {
"A",
uuidMock(1),
GroupType.SIMPLE,
Visibility.PUBLIC,
100L);
Visibility.PUBLIC);
Event deleteEvent = new DeleteGroupEvent(uuidMock(0), "A");
Group group = TestBuilder.apply(createEvent, deleteEvent);

View File

@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test;
import static mops.gruppen2.TestBuilder.addUserEvent;
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
import static mops.gruppen2.TestBuilder.updateUserLimitMaxEvent;
import static mops.gruppen2.TestBuilder.uuidMock;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -16,10 +17,11 @@ class DeleteUserEventTest {
@Test
void applyEvent() {
Event createEvent = createPublicGroupEvent(uuidMock(0));
Event updateLimitEvent = updateUserLimitMaxEvent(uuidMock(0));
Event addEvent = addUserEvent(uuidMock(0), "A");
Event deleteEvent = new DeleteUserEvent(uuidMock(0), "A");
Group group = TestBuilder.apply(createEvent, addEvent, deleteEvent);
Group group = TestBuilder.apply(createEvent, updateLimitEvent, addEvent, deleteEvent);
assertThat(group.getMembers()).hasSize(0);
}
@ -27,10 +29,11 @@ class DeleteUserEventTest {
@Test
void applyEvent_userNotFound() {
Event createEvent = createPublicGroupEvent(uuidMock(0));
Event updateLimitEvent = updateUserLimitMaxEvent(uuidMock(0));
Event addEvent = addUserEvent(uuidMock(0), "A");
Event deleteEvent = new DeleteUserEvent(uuidMock(0), "B");
Group group = TestBuilder.apply(createEvent, addEvent);
Group group = TestBuilder.apply(createEvent, updateLimitEvent, addEvent);
assertThrows(UserNotFoundException.class, () -> deleteEvent.apply(group));
assertThat(group.getMembers()).hasSize(1);

View File

@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test;
import static mops.gruppen2.TestBuilder.addUserEvent;
import static mops.gruppen2.TestBuilder.apply;
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
import static mops.gruppen2.TestBuilder.updateUserLimitMaxEvent;
import static mops.gruppen2.TestBuilder.uuidMock;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -17,10 +18,11 @@ class UpdateRoleEventTest {
@Test
void applyEvent() {
Event createEvent = createPublicGroupEvent(uuidMock(0));
Event updateLimitEvent = updateUserLimitMaxEvent(uuidMock(0));
Event addEvent = addUserEvent(uuidMock(0), "A");
Event updateEvent = new UpdateRoleEvent(uuidMock(0), "A", Role.ADMIN);
Group group = apply(createEvent, addEvent, updateEvent);
Group group = apply(createEvent, updateLimitEvent, addEvent, updateEvent);
assertThat(group.getRoles().get("A")).isEqualTo(Role.ADMIN);
}
@ -28,10 +30,11 @@ class UpdateRoleEventTest {
@Test
void applyEvent_userNotFound() {
Event createEvent = createPublicGroupEvent(uuidMock(0));
Event updateLimitEvent = updateUserLimitMaxEvent(uuidMock(0));
Event addEvent = addUserEvent(uuidMock(0), "A");
Event updateEvent = new UpdateRoleEvent(uuidMock(0), "B", Role.ADMIN);
Group group = apply(createEvent, addEvent);
Group group = apply(createEvent, updateLimitEvent, addEvent);
assertThrows(UserNotFoundException.class, () -> updateEvent.apply(group));
assertThat(group.getRoles().get("A")).isEqualTo(Role.MEMBER);

View File

@ -1,6 +1,7 @@
package mops.gruppen2.service;
import mops.gruppen2.Gruppen2Application;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.dto.EventDTO;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.repository.EventRepository;
@ -93,7 +94,7 @@ class EventStoreServiceTest {
addUserEvent(uuidMock(3), "A"),
addUserEvent(uuidMock(3), "B"));
assertThat(eventStoreService.findExistingUserGroups("A")).hasSize(4);
assertThat(eventStoreService.findExistingUserGroups("B")).hasSize(1);
assertThat(eventStoreService.findExistingUserGroups(new User("A"))).hasSize(4);
assertThat(eventStoreService.findExistingUserGroups(new User("B"))).hasSize(1);
}
}

View File

@ -3,6 +3,7 @@ package mops.gruppen2.service;
import mops.gruppen2.Gruppen2Application;
import mops.gruppen2.TestBuilder;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.repository.EventRepository;
@ -58,7 +59,7 @@ class GroupServiceTest {
@BeforeEach
void setUp() {
groupService = new GroupService(eventStoreService, validationService, inviteService);
groupService = new GroupService(eventStoreService, inviteService);
eventRepository.deleteAll();
//noinspection SqlResolve
template.execute("ALTER TABLE event ALTER COLUMN event_id RESTART WITH 1");
@ -184,7 +185,7 @@ class GroupServiceTest {
updateGroupTitleEvent(uuidMock(0)),
updateGroupDescriptionEvent(uuidMock(0)));
assertThat(searchService.searchPublicGroups("", "jens")).isEmpty();
assertThat(searchService.searchPublicGroups("", new User("jens"))).isEmpty();
}
//TODO: SearchServiceTest
@ -193,7 +194,7 @@ class GroupServiceTest {
eventStoreService.saveAll(completePublicGroups(10, 0),
completePrivateGroups(10, 0));
assertThat(searchService.searchPublicGroups("", "jens")).hasSize(10);
assertThat(searchService.searchPublicGroups("", new User("jens"))).hasSize(10);
}
//TODO: SearchServiceTest
@ -207,9 +208,9 @@ class GroupServiceTest {
updateGroupDescriptionEvent(uuidMock(1), "KK"),
createPrivateGroupEvent());
assertThat(searchService.searchPublicGroups("A", "jesus")).hasSize(2);
assertThat(searchService.searchPublicGroups("F", "jesus")).hasSize(1);
assertThat(searchService.searchPublicGroups("Z", "jesus")).hasSize(0);
assertThat(searchService.searchPublicGroups("A", new User("jesus"))).hasSize(2);
assertThat(searchService.searchPublicGroups("F", new User("jesus"))).hasSize(1);
assertThat(searchService.searchPublicGroups("Z", new User("jesus"))).hasSize(0);
}
}