1

new api tests + fixes

Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
Christoph
2020-03-29 17:24:25 +02:00
parent 36ebb6b8b6
commit 0c8e841c8e
10 changed files with 258 additions and 84 deletions

View File

@ -22,10 +22,9 @@ import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* Ein Beispiel für eine API mit Swagger. * Api zum Datenabgleich mit Gruppenfindung.
*/ */
//TODO: Testing //TODO: API-Service?
//TODO: API-Service
@RestController @RestController
@RequestMapping("/gruppen2/api") @RequestMapping("/gruppen2/api")
public class APIController { public class APIController {
@ -40,20 +39,20 @@ public class APIController {
this.userService = userService; this.userService = userService;
} }
@GetMapping("/updateGroups/{status}") @GetMapping("/updateGroups/{lastEventId}")
@Secured("ROLE_api_user") @Secured("ROLE_api_user")
@ApiOperation("Gibt alle Gruppen zurück, in denen sich etwas geändert hat") @ApiOperation("Gibt alle Gruppen zurück, in denen sich etwas geändert hat")
public GroupRequestWrapper updateGroup(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long status) throws EventException { public GroupRequestWrapper updateGroups(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long lastEventId) throws EventException {
List<Event> events = eventService.getNewEvents(status); List<Event> events = eventService.getNewEvents(lastEventId);
return APIFormatterService.wrap(eventService.getMaxEventId(), groupService.projectEventList(events)); return APIFormatterService.wrap(eventService.getMaxEventId(), groupService.projectEventList(events));
} }
@GetMapping("/getGroupIdsOfUser/{teilnehmer}") @GetMapping("/getGroupIdsOfUser/{userId}")
@Secured("ROLE_api_user") @Secured("ROLE_api_user")
@ApiOperation("Gibt alle Gruppen zurück, in denen sich ein Teilnehmer befindet") @ApiOperation("Gibt alle Gruppen zurück, in denen sich ein Teilnehmer befindet")
public List<String> getGroupsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String teilnehmer) { public List<String> getGroupIdsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String userId) {
return userService.getUserGroups(teilnehmer).stream() return userService.getUserGroups(userId).stream()
.map(group -> group.getId().toString()) .map(group -> group.getId().toString())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -61,10 +60,14 @@ public class APIController {
@GetMapping("/getGroup/{groupId}") @GetMapping("/getGroup/{groupId}")
@Secured("ROLE_api_user") @Secured("ROLE_api_user")
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück") @ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable String groupId) throws EventException { public Group getGroupById(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable String groupId) throws EventException {
List<Event> eventList = eventService.getEventsOfGroup(UUID.fromString(groupId)); List<Event> eventList = eventService.getEventsOfGroup(UUID.fromString(groupId));
List<Group> groups = groupService.projectEventList(eventList); List<Group> groups = groupService.projectEventList(eventList);
if (groups.isEmpty()) {
return null;
}
return groups.get(0); return groups.get(0);
} }

View File

@ -11,7 +11,7 @@ public final class APIFormatterService {
private APIFormatterService() {} private APIFormatterService() {}
public static GroupRequestWrapper wrap(Long status, List<Group> groupList) { public static GroupRequestWrapper wrap(long status, List<Group> groupList) {
return new GroupRequestWrapper(status, groupList); return new GroupRequestWrapper(status, groupList);
} }
} }

View File

@ -18,11 +18,9 @@ import java.util.stream.Collectors;
public class EventService { public class EventService {
private static final Logger LOG = LoggerFactory.getLogger(EventService.class); private static final Logger LOG = LoggerFactory.getLogger(EventService.class);
private final JsonService jsonService;
private final EventRepository eventStore; private final EventRepository eventStore;
public EventService(JsonService jsonService, EventRepository eventStore) { public EventService(EventRepository eventStore) {
this.jsonService = jsonService;
this.eventStore = eventStore; this.eventStore = eventStore;
} }
@ -121,8 +119,16 @@ public class EventService {
return events; return events;
} }
public Long getMaxEventId() { public long getMaxEventId() {
return eventStore.getHighesEventID(); long highestEvent = 0;
try {
highestEvent = eventStore.getHighesEventID();
} catch (NullPointerException e) {
LOG.debug("Eine maxId von 0 wurde zurückgegeben, da keine Events vorhanden sind.");
}
return highestEvent;
} }
/** /**

View File

@ -25,7 +25,7 @@ public class UserService {
@Cacheable("groups") @Cacheable("groups")
public List<Group> getUserGroups(String userId) throws EventException { public List<Group> getUserGroups(String userId) throws EventException {
return getUserGroups(new User(userId, null, null, null)); return getUserGroups(new User(userId, "", "", ""));
} }
/** /**
@ -35,6 +35,7 @@ public class UserService {
* *
* @return Liste aus Gruppen * @return Liste aus Gruppen
*/ */
//TODO: Nur AddUserEvents + DeleteUserEvents betrachten
@Cacheable("groups") @Cacheable("groups")
public List<Group> getUserGroups(User user) { public List<Group> getUserGroups(User user) {
List<UUID> groupIds = eventService.findGroupIdsByUser(user.getId()); List<UUID> groupIds = eventService.findGroupIdsByUser(user.getId());

View File

@ -1,6 +0,0 @@
insert into event values
(1,'8c15f614-fe04-4ac4-a2d7-d13e62ba8597','orga','CreateGroupEvent','{"type":"CreateGroupEvent","groupId":"8c15f614-fe04-4ac4-a2d7-d13e62ba8597","userId":"orga","groupVisibility":"PUBLIC","groupParent":null,"groupType":"SIMPLE","groupUserMaximum":2}'),
(2,'8c15f614-fe04-4ac4-a2d7-d13e62ba8597','orga','AddUserEvent','{"type":"AddUserEvent","groupId":"8c15f614-fe04-4ac4-a2d7-d13e62ba8597","userId":"orga","givenname":"orga","familyname":"orga","email":"blorga@orga.org"}'),
(3,'8c15f614-fe04-4ac4-a2d7-d13e62ba8597','orga','UpdateGroupTitleEvent','{"type":"UpdateGroupTitleEvent","groupId":"8c15f614-fe04-4ac4-a2d7-d13e62ba8597","userId":"orga","newGroupTitle":"sdsad"}'),
(4,'8c15f614-fe04-4ac4-a2d7-d13e62ba8597','orga','UpdateGroupDescriptionEvent','{"type":"UpdateGroupDescriptionEvent","groupId":"8c15f614-fe04-4ac4-a2d7-d13e62ba8597","userId":"orga","newGroupDescription":"sadsad"}'),
(5,'8c15f614-fe04-4ac4-a2d7-d13e62ba8597','orga','UpdateRoleEvent','{"type":"UpdateRoleEvent","groupId":"8c15f614-fe04-4ac4-a2d7-d13e62ba8597","userId":"orga","newRole":"ADMIN"}');

View File

@ -55,10 +55,11 @@ public class TestBuilder {
* *
* @return UUID * @return UUID
*/ */
public static UUID uuidFromInt(int id) { public static UUID uuidMock(int id) {
String idString = String.valueOf(Math.abs(id + 1));
return UUID.fromString("00000000-0000-0000-0000-" return UUID.fromString("00000000-0000-0000-0000-"
+ "0".repeat(11 - String.valueOf(id).length()) + "0".repeat(11 - idString.length())
+ id); + idString);
} }
/** /**

View File

@ -0,0 +1,167 @@
package mops.gruppen2.controller;
import mops.gruppen2.Gruppen2Application;
import mops.gruppen2.repository.EventRepository;
import mops.gruppen2.service.EventService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;
import static mops.gruppen2.TestBuilder.addUserEvent;
import static mops.gruppen2.TestBuilder.createPrivateGroupEvent;
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.uuidMock;
import static org.assertj.core.api.Assertions.assertThat;
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Gruppen2Application.class)
@Transactional
@Rollback
class APIControllerTest {
@Autowired
private EventRepository eventRepository;
@Autowired
private APIController apiController;
private EventService eventService;
@Autowired
private JdbcTemplate template;
@BeforeEach
void setUp() {
eventService = new EventService(eventRepository);
eventRepository.deleteAll();
//noinspection SqlResolve
template.execute("ALTER TABLE event ALTER COLUMN event_id RESTART WITH 1");
}
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void updateGroup_noGroup() {
assertThat(apiController.updateGroups(0L).getGroupList()).hasSize(0);
assertThat(apiController.updateGroups(4L).getGroupList()).hasSize(0);
assertThat(apiController.updateGroups(10L).getGroupList()).hasSize(0);
assertThat(apiController.updateGroups(0L).getStatus()).isEqualTo(0);
}
@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)));
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);
}
@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)));
assertThat(apiController.updateGroups(0L).getGroupList()).hasSize(2);
assertThat(apiController.updateGroups(4L).getGroupList()).hasSize(1);
assertThat(apiController.updateGroups(6L).getGroupList()).hasSize(1);
assertThat(apiController.updateGroups(7L).getGroupList()).hasSize(0);
assertThat(apiController.updateGroups(0L).getStatus()).isEqualTo(7);
}
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupsOfUser_noGroup() {
assertThat(apiController.getGroupIdsOfUser("A")).isEmpty();
}
@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"));
assertThat(apiController.getGroupIdsOfUser("A")).hasSize(1);
}
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupsOfUser_singleGroupDeletedUser() {
eventService.saveAll(createPrivateGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0), "A"),
deleteUserEvent(uuidMock(0), "A"));
assertThat(apiController.getGroupIdsOfUser("A")).isEmpty();
}
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupsOfUser_singleDeletedGroup() {
eventService.saveAll(createPrivateGroupEvent(uuidMock(0)),
addUserEvent(uuidMock(0), "A"),
deleteGroupEvent(uuidMock(0)));
assertThat(apiController.getGroupIdsOfUser("A")).isEmpty();
}
@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"));
assertThat(apiController.getGroupIdsOfUser("A")).hasSize(3);
assertThat(apiController.getGroupIdsOfUser("B")).hasSize(2);
}
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupFromId_noGroup() {
assertThat(apiController.getGroupById(uuidMock(0).toString())).isEqualTo(null);
}
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupFromId_singleGroup() {
eventService.saveAll(createPrivateGroupEvent(uuidMock(0)));
assertThat(apiController.getGroupById(uuidMock(0).toString()).getId()).isEqualTo(uuidMock(0));
}
@Test
@WithMockUser(username = "api_user", roles = "api_user")
void getGroupFromId_deletedGroup() {
eventService.saveAll(createPrivateGroupEvent(uuidMock(0)),
updateGroupTitleEvent(uuidMock(0)),
deleteGroupEvent(uuidMock(0)));
assertThat(apiController.getGroupById(uuidMock(0).toString()).getTitle()).isEqualTo(null);
}
}

View File

@ -45,13 +45,11 @@ class ControllerServiceTest {
EventRepository eventRepository; EventRepository eventRepository;
GroupService groupService; GroupService groupService;
@Autowired @Autowired
JsonService jsonService;
@Autowired
InviteService inviteService; InviteService inviteService;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
eventService = new EventService(jsonService, eventRepository); eventService = new EventService(eventRepository);
groupService = new GroupService(eventService, eventRepository); groupService = new GroupService(eventService, eventRepository);
userService = new UserService(groupService, eventService); userService = new UserService(groupService, eventService);
validationService = new ValidationService(userService, groupService); validationService = new ValidationService(userService, groupService);

View File

@ -5,26 +5,23 @@ import mops.gruppen2.domain.dto.EventDTO;
import mops.gruppen2.domain.event.Event; import mops.gruppen2.domain.event.Event;
import mops.gruppen2.repository.EventRepository; import mops.gruppen2.repository.EventRepository;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.annotation.Rollback; import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import static mops.gruppen2.TestBuilder.addUserEvent; import static mops.gruppen2.TestBuilder.addUserEvent;
import static mops.gruppen2.TestBuilder.addUserEvents; import static mops.gruppen2.TestBuilder.addUserEvents;
import static mops.gruppen2.TestBuilder.createPrivateGroupEvent;
import static mops.gruppen2.TestBuilder.createPrivateGroupEvents; import static mops.gruppen2.TestBuilder.createPrivateGroupEvents;
import static mops.gruppen2.TestBuilder.createPublicGroupEvent; import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
import static mops.gruppen2.TestBuilder.createPublicGroupEvents; import static mops.gruppen2.TestBuilder.createPublicGroupEvents;
import static mops.gruppen2.TestBuilder.updateGroupDescriptionEvent; import static mops.gruppen2.TestBuilder.uuidMock;
import static mops.gruppen2.TestBuilder.uuidFromInt;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
//TODO: Der ID autocounter wird nicht resettet -> Tests schlagen fehl beim nacheinanderausführen
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Gruppen2Application.class) @SpringBootTest(classes = Gruppen2Application.class)
@Transactional @Transactional
@ -33,14 +30,16 @@ class EventServiceTest {
@Autowired @Autowired
private EventRepository eventRepository; private EventRepository eventRepository;
@Autowired
private JsonService jsonService;
private EventService eventService; private EventService eventService;
@Autowired
private JdbcTemplate template;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
eventService = new EventService(jsonService, eventRepository); eventService = new EventService(eventRepository);
eventRepository.deleteAll(); eventRepository.deleteAll();
//noinspection SqlResolve
template.execute("ALTER TABLE event ALTER COLUMN event_id RESTART WITH 1");
} }
@Test @Test
@ -79,20 +78,20 @@ class EventServiceTest {
@Test @Test
void getEventsOfGroup() { void getEventsOfGroup() {
eventService.saveAll(addUserEvents(10, uuidFromInt(0)), eventService.saveAll(addUserEvents(10, uuidMock(0)),
addUserEvents(5, uuidFromInt(1))); addUserEvents(5, uuidMock(1)));
assertThat(eventService.getEventsOfGroup(uuidFromInt(0))).hasSize(10); assertThat(eventService.getEventsOfGroup(uuidMock(0))).hasSize(10);
assertThat(eventService.getEventsOfGroup(uuidFromInt(1))).hasSize(5); assertThat(eventService.getEventsOfGroup(uuidMock(1))).hasSize(5);
} }
@Test @Test
void findGroupIdsByUser() { void findGroupIdsByUser() {
eventService.saveAll(addUserEvent(uuidFromInt(0), "A"), eventService.saveAll(addUserEvent(uuidMock(0), "A"),
addUserEvent(uuidFromInt(1), "A"), addUserEvent(uuidMock(1), "A"),
addUserEvent(uuidFromInt(2), "A"), addUserEvent(uuidMock(2), "A"),
addUserEvent(uuidFromInt(3), "A"), addUserEvent(uuidMock(3), "A"),
addUserEvent(uuidFromInt(3), "B")); addUserEvent(uuidMock(3), "B"));
assertThat(eventService.findGroupIdsByUser("A")).hasSize(4); assertThat(eventService.findGroupIdsByUser("A")).hasSize(4);
assertThat(eventService.findGroupIdsByUser("B")).hasSize(1); assertThat(eventService.findGroupIdsByUser("B")).hasSize(1);

View File

@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.annotation.Rollback; import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -30,7 +31,7 @@ import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
import static mops.gruppen2.TestBuilder.deleteGroupEvent; import static mops.gruppen2.TestBuilder.deleteGroupEvent;
import static mops.gruppen2.TestBuilder.updateGroupDescriptionEvent; import static mops.gruppen2.TestBuilder.updateGroupDescriptionEvent;
import static mops.gruppen2.TestBuilder.updateGroupTitleEvent; import static mops.gruppen2.TestBuilder.updateGroupTitleEvent;
import static mops.gruppen2.TestBuilder.uuidFromInt; import static mops.gruppen2.TestBuilder.uuidMock;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
@ -44,11 +45,15 @@ class GroupServiceTest {
@Autowired @Autowired
private EventService eventService; private EventService eventService;
private GroupService groupService; private GroupService groupService;
@Autowired
private JdbcTemplate template;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
groupService = new GroupService(eventService, eventRepository); groupService = new GroupService(eventService, eventRepository);
eventRepository.deleteAll(); eventRepository.deleteAll();
//noinspection SqlResolve
template.execute("ALTER TABLE event ALTER COLUMN event_id RESTART WITH 1");
} }
//TODO: Wofür ist dieser Test? //TODO: Wofür ist dieser Test?
@ -91,23 +96,23 @@ class GroupServiceTest {
//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(uuidMock(0)),
createPublicGroupEvent(uuidFromInt(1)), createPublicGroupEvent(uuidMock(1)),
createPrivateGroupEvent(uuidFromInt(2))); createPrivateGroupEvent(uuidMock(2)));
List<UUID> groupIds = Arrays.asList(uuidFromInt(0), uuidFromInt(1)); List<UUID> groupIds = Arrays.asList(uuidMock(0), uuidMock(1));
assertThat(groupService.getGroupEvents(groupIds)).hasSize(2); assertThat(groupService.getGroupEvents(groupIds)).hasSize(2);
assertThat(groupService.getGroupEvents(groupIds).get(0).getGroupId()).isEqualTo(uuidFromInt(0)); assertThat(groupService.getGroupEvents(groupIds).get(0).getGroupId()).isEqualTo(uuidMock(0));
assertThat(groupService.getGroupEvents(groupIds).get(1).getGroupId()).isEqualTo(uuidFromInt(1)); assertThat(groupService.getGroupEvents(groupIds).get(1).getGroupId()).isEqualTo(uuidMock(1));
} }
@Test @Test
void getAllGroupWithVisibilityPublicTestCreateAndDeleteSameGroup() { void getAllGroupWithVisibilityPublicTestCreateAndDeleteSameGroup() {
//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);
//DeleteGroupEvent test2 = new DeleteGroupEvent(uuidFromInt(0), "test1"); //DeleteGroupEvent test2 = new DeleteGroupEvent(uuidFromInt(0), "test1");
Event test1 = createPublicGroupEvent(uuidFromInt(0)); Event test1 = createPublicGroupEvent(uuidMock(0));
Event test2 = deleteGroupEvent(uuidFromInt(0)); Event test2 = deleteGroupEvent(uuidMock(0));
//Group group = new Group(); //Group group = new Group();
//test1.apply(group); //test1.apply(group);
@ -127,9 +132,9 @@ class GroupServiceTest {
//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(uuidMock(0)),
deleteGroupEvent(uuidFromInt(0)), deleteGroupEvent(uuidMock(0)),
createPublicGroupEvent()); createPublicGroupEvent());
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1); assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
} }
@ -144,12 +149,12 @@ class GroupServiceTest {
//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(uuidMock(0)),
deleteGroupEvent(uuidFromInt(0)), deleteGroupEvent(uuidMock(0)),
createPublicGroupEvent(), createPublicGroupEvent(),
createPublicGroupEvent(), createPublicGroupEvent(),
createPublicGroupEvent(), createPublicGroupEvent(),
createPrivateGroupEvent()); createPrivateGroupEvent());
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3); assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
} }
@ -159,10 +164,10 @@ class GroupServiceTest {
//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(uuidMock(0)),
addUserEvent(uuidFromInt(0), "kobold"), addUserEvent(uuidMock(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);
@ -181,10 +186,10 @@ class GroupServiceTest {
//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);
} }
@ -197,10 +202,10 @@ class GroupServiceTest {
//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(uuidMock(0)),
addUserEvent(uuidFromInt(0), "jens"), addUserEvent(uuidMock(0), "jens"),
updateGroupTitleEvent(uuidFromInt(0)), updateGroupTitleEvent(uuidMock(0)),
updateGroupDescriptionEvent(uuidFromInt(0))); updateGroupDescriptionEvent(uuidMock(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();
@ -209,20 +214,20 @@ 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);
} }
@Test @Test
void findGroupWith_FilterGroups() { void findGroupWith_FilterGroups() {
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)), eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
updateGroupTitleEvent(uuidFromInt(0), "KK"), updateGroupTitleEvent(uuidMock(0), "KK"),
updateGroupDescriptionEvent(uuidFromInt(0), "ABCDE"), updateGroupDescriptionEvent(uuidMock(0), "ABCDE"),
createPublicGroupEvent(uuidFromInt(1)), createPublicGroupEvent(uuidMock(1)),
updateGroupTitleEvent(uuidFromInt(1), "ABCDEFG"), updateGroupTitleEvent(uuidMock(1), "ABCDEFG"),
updateGroupDescriptionEvent(uuidFromInt(1), "KK"), updateGroupDescriptionEvent(uuidMock(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);