Merge pull request #162 from hhu-propra2/TEST-api-tests
new api tests + fixes
This commit is contained in:
@ -22,10 +22,9 @@ import java.util.UUID;
|
||||
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
|
||||
@RequestMapping("/gruppen2/api")
|
||||
public class APIController {
|
||||
@ -40,20 +39,20 @@ public class APIController {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/updateGroups/{status}")
|
||||
@GetMapping("/updateGroups/{lastEventId}")
|
||||
@Secured("ROLE_api_user")
|
||||
@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 {
|
||||
List<Event> events = eventService.getNewEvents(status);
|
||||
public GroupRequestWrapper updateGroups(@ApiParam("Letzter Status des Anfragestellers") @PathVariable Long lastEventId) throws EventException {
|
||||
List<Event> events = eventService.getNewEvents(lastEventId);
|
||||
|
||||
return APIFormatterService.wrap(eventService.getMaxEventId(), groupService.projectEventList(events));
|
||||
}
|
||||
|
||||
@GetMapping("/getGroupIdsOfUser/{teilnehmer}")
|
||||
@GetMapping("/getGroupIdsOfUser/{userId}")
|
||||
@Secured("ROLE_api_user")
|
||||
@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) {
|
||||
return userService.getUserGroups(teilnehmer).stream()
|
||||
public List<String> getGroupIdsOfUser(@ApiParam("Teilnehmer dessen groupIds zurückgegeben werden sollen") @PathVariable String userId) {
|
||||
return userService.getUserGroups(userId).stream()
|
||||
.map(group -> group.getId().toString())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@ -61,10 +60,14 @@ public class APIController {
|
||||
@GetMapping("/getGroup/{groupId}")
|
||||
@Secured("ROLE_api_user")
|
||||
@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<Group> groups = groupService.projectEventList(eventList);
|
||||
|
||||
if (groups.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return groups.get(0);
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ public final class 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);
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,9 @@ import java.util.stream.Collectors;
|
||||
public class EventService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EventService.class);
|
||||
private final JsonService jsonService;
|
||||
private final EventRepository eventStore;
|
||||
|
||||
public EventService(JsonService jsonService, EventRepository eventStore) {
|
||||
this.jsonService = jsonService;
|
||||
public EventService(EventRepository eventStore) {
|
||||
this.eventStore = eventStore;
|
||||
}
|
||||
|
||||
@ -121,8 +119,16 @@ public class EventService {
|
||||
return events;
|
||||
}
|
||||
|
||||
public Long getMaxEventId() {
|
||||
return eventStore.getHighesEventID();
|
||||
public long getMaxEventId() {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,7 @@ public class UserService {
|
||||
|
||||
@Cacheable("groups")
|
||||
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
|
||||
*/
|
||||
//TODO: Nur AddUserEvents + DeleteUserEvents betrachten
|
||||
@Cacheable("groups")
|
||||
public List<Group> getUserGroups(User user) {
|
||||
List<UUID> groupIds = eventService.findGroupIdsByUser(user.getId());
|
||||
|
@ -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"}');
|
@ -55,10 +55,11 @@ public class TestBuilder {
|
||||
*
|
||||
* @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-"
|
||||
+ "0".repeat(11 - String.valueOf(id).length())
|
||||
+ id);
|
||||
+ "0".repeat(11 - idString.length())
|
||||
+ idString);
|
||||
}
|
||||
|
||||
/**
|
||||
|
167
src/test/java/mops/gruppen2/controller/APIControllerTest.java
Normal file
167
src/test/java/mops/gruppen2/controller/APIControllerTest.java
Normal 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);
|
||||
}
|
||||
}
|
@ -8,7 +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.uuidFromInt;
|
||||
import static mops.gruppen2.TestBuilder.uuidMock;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@ -16,8 +16,8 @@ class AddUserEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = new AddUserEvent(uuidFromInt(0), "A", "Thomas", "Tom", "tho@mail.de");
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event addEvent = new AddUserEvent(uuidMock(0), "A", "Thomas", "Tom", "tho@mail.de");
|
||||
|
||||
Group group = apply(createEvent, addEvent);
|
||||
|
||||
@ -29,10 +29,10 @@ class AddUserEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent_userAlreadyExists() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEventA = addUserEvent(uuidFromInt(0), "A");
|
||||
Event addEventB = addUserEvent(uuidFromInt(0), "B");
|
||||
Event addEventC = addUserEvent(uuidFromInt(0), "A");
|
||||
Event createEvent = createPublicGroupEvent(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);
|
||||
|
||||
@ -43,11 +43,11 @@ class AddUserEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent_groupFull() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event maxSizeEvent = new UpdateUserMaxEvent(uuidFromInt(0), "A", 2L);
|
||||
Event addEventA = addUserEvent(uuidFromInt(0), "A");
|
||||
Event addEventB = addUserEvent(uuidFromInt(0), "B");
|
||||
Event addEventC = addUserEvent(uuidFromInt(0), "C");
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event maxSizeEvent = new UpdateUserMaxEvent(uuidMock(0), "A", 2L);
|
||||
Event addEventA = addUserEvent(uuidMock(0), "A");
|
||||
Event addEventB = addUserEvent(uuidMock(0), "B");
|
||||
Event addEventC = addUserEvent(uuidMock(0), "C");
|
||||
|
||||
Group group = apply(createEvent, maxSizeEvent, addEventA, addEventB);
|
||||
|
||||
|
@ -6,16 +6,16 @@ import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static mops.gruppen2.TestBuilder.uuidMock;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class CreateGroupEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = new CreateGroupEvent(uuidFromInt(0),
|
||||
Event createEvent = new CreateGroupEvent(uuidMock(0),
|
||||
"A",
|
||||
uuidFromInt(1),
|
||||
uuidMock(1),
|
||||
GroupType.SIMPLE,
|
||||
Visibility.PUBLIC,
|
||||
100L);
|
||||
@ -26,7 +26,7 @@ class CreateGroupEventTest {
|
||||
assertThat(group.getType()).isEqualTo(GroupType.SIMPLE);
|
||||
assertThat(group.getVisibility()).isEqualTo(Visibility.PUBLIC);
|
||||
assertThat(group.getUserMaximum()).isEqualTo(100);
|
||||
assertThat(group.getId()).isEqualTo(uuidFromInt(0));
|
||||
assertThat(group.getParent()).isEqualTo(uuidFromInt(1));
|
||||
assertThat(group.getId()).isEqualTo(uuidMock(0));
|
||||
assertThat(group.getParent()).isEqualTo(uuidMock(1));
|
||||
}
|
||||
}
|
||||
|
@ -6,20 +6,20 @@ import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static mops.gruppen2.TestBuilder.uuidMock;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class DeleteGroupEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = new CreateGroupEvent(uuidFromInt(0),
|
||||
Event createEvent = new CreateGroupEvent(uuidMock(0),
|
||||
"A",
|
||||
uuidFromInt(1),
|
||||
uuidMock(1),
|
||||
GroupType.SIMPLE,
|
||||
Visibility.PUBLIC,
|
||||
100L);
|
||||
Event deleteEvent = new DeleteGroupEvent(uuidFromInt(0), "A");
|
||||
Event deleteEvent = new DeleteGroupEvent(uuidMock(0), "A");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent, deleteEvent);
|
||||
|
||||
@ -27,7 +27,7 @@ class DeleteGroupEventTest {
|
||||
assertThat(group.getType()).isEqualTo(null);
|
||||
assertThat(group.getVisibility()).isEqualTo(null);
|
||||
assertThat(group.getUserMaximum()).isEqualTo(0);
|
||||
assertThat(group.getId()).isEqualTo(uuidFromInt(0));
|
||||
assertThat(group.getId()).isEqualTo(uuidMock(0));
|
||||
assertThat(group.getParent()).isEqualTo(null);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +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.uuidFromInt;
|
||||
import static mops.gruppen2.TestBuilder.uuidMock;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@ -15,9 +15,9 @@ class DeleteUserEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
||||
Event deleteEvent = new DeleteUserEvent(uuidFromInt(0), "A");
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event addEvent = addUserEvent(uuidMock(0), "A");
|
||||
Event deleteEvent = new DeleteUserEvent(uuidMock(0), "A");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent, addEvent, deleteEvent);
|
||||
|
||||
@ -26,9 +26,9 @@ class DeleteUserEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent_userNotFound() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
||||
Event deleteEvent = new DeleteUserEvent(uuidFromInt(0), "B");
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event addEvent = addUserEvent(uuidMock(0), "A");
|
||||
Event deleteEvent = new DeleteUserEvent(uuidMock(0), "B");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent, addEvent);
|
||||
|
||||
|
@ -6,15 +6,15 @@ import mops.gruppen2.domain.exception.GroupIdMismatchException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static mops.gruppen2.TestBuilder.uuidMock;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class EventTest {
|
||||
|
||||
@Test
|
||||
void apply() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = TestBuilder.addUserEvent(uuidFromInt(1));
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event addEvent = TestBuilder.addUserEvent(uuidMock(1));
|
||||
|
||||
Group group = TestBuilder.apply(createEvent);
|
||||
|
||||
|
@ -6,7 +6,7 @@ import mops.gruppen2.domain.exception.BadParameterException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static mops.gruppen2.TestBuilder.uuidMock;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@ -14,8 +14,8 @@ class UpdateGroupDescriptionEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEvent = new UpdateGroupDescriptionEvent(uuidFromInt(0), "A", "desc.");
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event updateEvent = new UpdateGroupDescriptionEvent(uuidMock(0), "A", "desc.");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent, updateEvent);
|
||||
|
||||
@ -24,9 +24,9 @@ class UpdateGroupDescriptionEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent_badDescription() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEventA = new UpdateGroupDescriptionEvent(uuidFromInt(0), "A", "");
|
||||
Event updateEventB = new UpdateGroupDescriptionEvent(uuidFromInt(0), "A", " ");
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event updateEventA = new UpdateGroupDescriptionEvent(uuidMock(0), "A", "");
|
||||
Event updateEventB = new UpdateGroupDescriptionEvent(uuidMock(0), "A", " ");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent);
|
||||
|
||||
|
@ -6,7 +6,7 @@ import mops.gruppen2.domain.exception.BadParameterException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static mops.gruppen2.TestBuilder.uuidMock;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@ -14,8 +14,8 @@ class UpdateGroupTitleEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEvent = new UpdateGroupTitleEvent(uuidFromInt(0), "A", "title.");
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event updateEvent = new UpdateGroupTitleEvent(uuidMock(0), "A", "title.");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent, updateEvent);
|
||||
|
||||
@ -24,9 +24,9 @@ class UpdateGroupTitleEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent_badDescription() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEventA = new UpdateGroupTitleEvent(uuidFromInt(0), "A", "");
|
||||
Event updateEventB = new UpdateGroupTitleEvent(uuidFromInt(0), "A", " ");
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event updateEventA = new UpdateGroupTitleEvent(uuidMock(0), "A", "");
|
||||
Event updateEventB = new UpdateGroupTitleEvent(uuidMock(0), "A", " ");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent);
|
||||
|
||||
|
@ -8,7 +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.uuidFromInt;
|
||||
import static mops.gruppen2.TestBuilder.uuidMock;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@ -16,9 +16,9 @@ class UpdateRoleEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
||||
Event updateEvent = new UpdateRoleEvent(uuidFromInt(0), "A", Role.ADMIN);
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event addEvent = addUserEvent(uuidMock(0), "A");
|
||||
Event updateEvent = new UpdateRoleEvent(uuidMock(0), "A", Role.ADMIN);
|
||||
|
||||
Group group = apply(createEvent, addEvent, updateEvent);
|
||||
|
||||
@ -27,9 +27,9 @@ class UpdateRoleEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent_userNotFound() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
||||
Event updateEvent = new UpdateRoleEvent(uuidFromInt(0), "B", Role.ADMIN);
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event addEvent = addUserEvent(uuidMock(0), "A");
|
||||
Event updateEvent = new UpdateRoleEvent(uuidMock(0), "B", Role.ADMIN);
|
||||
|
||||
Group group = apply(createEvent, addEvent);
|
||||
|
||||
|
@ -7,7 +7,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.uuidFromInt;
|
||||
import static mops.gruppen2.TestBuilder.uuidMock;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@ -15,8 +15,8 @@ class UpdateUserMaxEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEvent = new UpdateUserMaxEvent(uuidFromInt(0), "A", 5L);
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event updateEvent = new UpdateUserMaxEvent(uuidMock(0), "A", 5L);
|
||||
|
||||
Group group = apply(createEvent, updateEvent);
|
||||
|
||||
@ -25,8 +25,8 @@ class UpdateUserMaxEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent_badParameter_negative() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEvent = new UpdateUserMaxEvent(uuidFromInt(0), "A", -5L);
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event updateEvent = new UpdateUserMaxEvent(uuidMock(0), "A", -5L);
|
||||
|
||||
Group group = apply(createEvent);
|
||||
|
||||
@ -35,12 +35,12 @@ class UpdateUserMaxEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent_badParameter_tooSmall() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEventA = new UpdateUserMaxEvent(uuidFromInt(0), "A", 5L);
|
||||
Event addEventA = addUserEvent(uuidFromInt(0));
|
||||
Event addEventB = addUserEvent(uuidFromInt(0));
|
||||
Event addEventC = addUserEvent(uuidFromInt(0));
|
||||
Event updateEventB = new UpdateUserMaxEvent(uuidFromInt(0), "A", 2L);
|
||||
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||
Event updateEventA = new UpdateUserMaxEvent(uuidMock(0), "A", 5L);
|
||||
Event addEventA = addUserEvent(uuidMock(0));
|
||||
Event addEventB = addUserEvent(uuidMock(0));
|
||||
Event addEventC = addUserEvent(uuidMock(0));
|
||||
Event updateEventB = new UpdateUserMaxEvent(uuidMock(0), "A", 2L);
|
||||
|
||||
Group group = apply(createEvent, updateEventA, addEventA, addEventB, addEventC);
|
||||
|
||||
|
@ -45,13 +45,11 @@ class ControllerServiceTest {
|
||||
EventRepository eventRepository;
|
||||
GroupService groupService;
|
||||
@Autowired
|
||||
JsonService jsonService;
|
||||
@Autowired
|
||||
InviteService inviteService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
eventService = new EventService(jsonService, eventRepository);
|
||||
eventService = new EventService(eventRepository);
|
||||
groupService = new GroupService(eventService, eventRepository);
|
||||
userService = new UserService(groupService, eventService);
|
||||
validationService = new ValidationService(userService, groupService);
|
||||
|
@ -5,26 +5,23 @@ import mops.gruppen2.domain.dto.EventDTO;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
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.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.addUserEvents;
|
||||
import static mops.gruppen2.TestBuilder.createPrivateGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.createPrivateGroupEvents;
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvents;
|
||||
import static mops.gruppen2.TestBuilder.updateGroupDescriptionEvent;
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static mops.gruppen2.TestBuilder.uuidMock;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
//TODO: Der ID autocounter wird nicht resettet -> Tests schlagen fehl beim nacheinanderausführen
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = Gruppen2Application.class)
|
||||
@Transactional
|
||||
@ -33,14 +30,16 @@ class EventServiceTest {
|
||||
|
||||
@Autowired
|
||||
private EventRepository eventRepository;
|
||||
@Autowired
|
||||
private JsonService jsonService;
|
||||
private EventService eventService;
|
||||
@Autowired
|
||||
private JdbcTemplate template;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
eventService = new EventService(jsonService, eventRepository);
|
||||
eventService = new EventService(eventRepository);
|
||||
eventRepository.deleteAll();
|
||||
//noinspection SqlResolve
|
||||
template.execute("ALTER TABLE event ALTER COLUMN event_id RESTART WITH 1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -79,20 +78,20 @@ class EventServiceTest {
|
||||
|
||||
@Test
|
||||
void getEventsOfGroup() {
|
||||
eventService.saveAll(addUserEvents(10, uuidFromInt(0)),
|
||||
addUserEvents(5, uuidFromInt(1)));
|
||||
eventService.saveAll(addUserEvents(10, uuidMock(0)),
|
||||
addUserEvents(5, uuidMock(1)));
|
||||
|
||||
assertThat(eventService.getEventsOfGroup(uuidFromInt(0))).hasSize(10);
|
||||
assertThat(eventService.getEventsOfGroup(uuidFromInt(1))).hasSize(5);
|
||||
assertThat(eventService.getEventsOfGroup(uuidMock(0))).hasSize(10);
|
||||
assertThat(eventService.getEventsOfGroup(uuidMock(1))).hasSize(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void findGroupIdsByUser() {
|
||||
eventService.saveAll(addUserEvent(uuidFromInt(0), "A"),
|
||||
addUserEvent(uuidFromInt(1), "A"),
|
||||
addUserEvent(uuidFromInt(2), "A"),
|
||||
addUserEvent(uuidFromInt(3), "A"),
|
||||
addUserEvent(uuidFromInt(3), "B"));
|
||||
eventService.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);
|
||||
|
@ -11,6 +11,7 @@ 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.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
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.updateGroupDescriptionEvent;
|
||||
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;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ -44,11 +45,15 @@ class GroupServiceTest {
|
||||
@Autowired
|
||||
private EventService eventService;
|
||||
private GroupService groupService;
|
||||
@Autowired
|
||||
private JdbcTemplate template;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
groupService = new GroupService(eventService, eventRepository);
|
||||
eventRepository.deleteAll();
|
||||
//noinspection SqlResolve
|
||||
template.execute("ALTER TABLE event ALTER COLUMN event_id RESTART WITH 1");
|
||||
}
|
||||
|
||||
//TODO: Wofür ist dieser Test?
|
||||
@ -84,21 +89,21 @@ class GroupServiceTest {
|
||||
|
||||
@Test
|
||||
void getGroupEvents() {
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent(uuidFromInt(1)),
|
||||
createPrivateGroupEvent(uuidFromInt(2)));
|
||||
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
|
||||
createPublicGroupEvent(uuidMock(1)),
|
||||
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).get(0).getGroupId()).isEqualTo(uuidFromInt(0));
|
||||
assertThat(groupService.getGroupEvents(groupIds).get(1).getGroupId()).isEqualTo(uuidFromInt(1));
|
||||
assertThat(groupService.getGroupEvents(groupIds).get(0).getGroupId()).isEqualTo(uuidMock(0));
|
||||
assertThat(groupService.getGroupEvents(groupIds).get(1).getGroupId()).isEqualTo(uuidMock(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllGroupWithVisibilityPublicTestCreateAndDeleteSameGroup() {
|
||||
Event test1 = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event test2 = deleteGroupEvent(uuidFromInt(0));
|
||||
Event test1 = createPublicGroupEvent(uuidMock(0));
|
||||
Event test2 = deleteGroupEvent(uuidMock(0));
|
||||
|
||||
//TODO: Hier projectEventlist()?
|
||||
Group group = TestBuilder.apply(test1, test2);
|
||||
@ -109,8 +114,8 @@ class GroupServiceTest {
|
||||
|
||||
@Test
|
||||
void getAllGroupWithVisibilityPublicTestGroupPublic() {
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
deleteGroupEvent(uuidFromInt(0)),
|
||||
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
|
||||
deleteGroupEvent(uuidMock(0)),
|
||||
createPublicGroupEvent());
|
||||
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
|
||||
@ -118,8 +123,8 @@ class GroupServiceTest {
|
||||
|
||||
@Test
|
||||
void getAllGroupWithVisibilityPublicTestAddSomeEvents() {
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
deleteGroupEvent(uuidFromInt(0)),
|
||||
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
|
||||
deleteGroupEvent(uuidMock(0)),
|
||||
createPublicGroupEvent(),
|
||||
createPublicGroupEvent(),
|
||||
createPublicGroupEvent(),
|
||||
@ -130,8 +135,8 @@ class GroupServiceTest {
|
||||
|
||||
@Test
|
||||
void getAllGroupWithVisibilityPublic_UserInGroup() {
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
addUserEvent(uuidFromInt(0), "kobold"),
|
||||
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
|
||||
addUserEvent(uuidMock(0), "kobold"),
|
||||
createPrivateGroupEvent(),
|
||||
createPublicGroupEvent());
|
||||
|
||||
@ -152,10 +157,10 @@ class GroupServiceTest {
|
||||
|
||||
@Test
|
||||
void findGroupWith_UserMember_AllGroups() {
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
addUserEvent(uuidFromInt(0), "jens"),
|
||||
updateGroupTitleEvent(uuidFromInt(0)),
|
||||
updateGroupDescriptionEvent(uuidFromInt(0)));
|
||||
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
|
||||
addUserEvent(uuidMock(0), "jens"),
|
||||
updateGroupTitleEvent(uuidMock(0)),
|
||||
updateGroupDescriptionEvent(uuidMock(0)));
|
||||
|
||||
assertThat(groupService.findGroupWith("", account("jens"))).isEmpty();
|
||||
}
|
||||
@ -170,12 +175,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"),
|
||||
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());
|
||||
|
||||
assertThat(groupService.findGroupWith("A", account("jesus"))).hasSize(2);
|
||||
|
Reference in New Issue
Block a user