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;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -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
|
* @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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
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.addUserEvent;
|
||||||
import static mops.gruppen2.TestBuilder.apply;
|
import static mops.gruppen2.TestBuilder.apply;
|
||||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
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.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
@ -16,8 +16,8 @@ class AddUserEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent() {
|
void applyEvent() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event addEvent = new AddUserEvent(uuidFromInt(0), "A", "Thomas", "Tom", "tho@mail.de");
|
Event addEvent = new AddUserEvent(uuidMock(0), "A", "Thomas", "Tom", "tho@mail.de");
|
||||||
|
|
||||||
Group group = apply(createEvent, addEvent);
|
Group group = apply(createEvent, addEvent);
|
||||||
|
|
||||||
@ -29,10 +29,10 @@ class AddUserEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent_userAlreadyExists() {
|
void applyEvent_userAlreadyExists() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event addEventA = addUserEvent(uuidFromInt(0), "A");
|
Event addEventA = addUserEvent(uuidMock(0), "A");
|
||||||
Event addEventB = addUserEvent(uuidFromInt(0), "B");
|
Event addEventB = addUserEvent(uuidMock(0), "B");
|
||||||
Event addEventC = addUserEvent(uuidFromInt(0), "A");
|
Event addEventC = addUserEvent(uuidMock(0), "A");
|
||||||
|
|
||||||
Group group = apply(createEvent, addEventA, addEventB);
|
Group group = apply(createEvent, addEventA, addEventB);
|
||||||
|
|
||||||
@ -43,11 +43,11 @@ class AddUserEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent_groupFull() {
|
void applyEvent_groupFull() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event maxSizeEvent = new UpdateUserMaxEvent(uuidFromInt(0), "A", 2L);
|
Event maxSizeEvent = new UpdateUserMaxEvent(uuidMock(0), "A", 2L);
|
||||||
Event addEventA = addUserEvent(uuidFromInt(0), "A");
|
Event addEventA = addUserEvent(uuidMock(0), "A");
|
||||||
Event addEventB = addUserEvent(uuidFromInt(0), "B");
|
Event addEventB = addUserEvent(uuidMock(0), "B");
|
||||||
Event addEventC = addUserEvent(uuidFromInt(0), "C");
|
Event addEventC = addUserEvent(uuidMock(0), "C");
|
||||||
|
|
||||||
Group group = apply(createEvent, maxSizeEvent, addEventA, addEventB);
|
Group group = apply(createEvent, maxSizeEvent, addEventA, addEventB);
|
||||||
|
|
||||||
|
|||||||
@ -6,16 +6,16 @@ import mops.gruppen2.domain.GroupType;
|
|||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
import org.junit.jupiter.api.Test;
|
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;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class CreateGroupEventTest {
|
class CreateGroupEventTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent() {
|
void applyEvent() {
|
||||||
Event createEvent = new CreateGroupEvent(uuidFromInt(0),
|
Event createEvent = new CreateGroupEvent(uuidMock(0),
|
||||||
"A",
|
"A",
|
||||||
uuidFromInt(1),
|
uuidMock(1),
|
||||||
GroupType.SIMPLE,
|
GroupType.SIMPLE,
|
||||||
Visibility.PUBLIC,
|
Visibility.PUBLIC,
|
||||||
100L);
|
100L);
|
||||||
@ -26,7 +26,7 @@ class CreateGroupEventTest {
|
|||||||
assertThat(group.getType()).isEqualTo(GroupType.SIMPLE);
|
assertThat(group.getType()).isEqualTo(GroupType.SIMPLE);
|
||||||
assertThat(group.getVisibility()).isEqualTo(Visibility.PUBLIC);
|
assertThat(group.getVisibility()).isEqualTo(Visibility.PUBLIC);
|
||||||
assertThat(group.getUserMaximum()).isEqualTo(100);
|
assertThat(group.getUserMaximum()).isEqualTo(100);
|
||||||
assertThat(group.getId()).isEqualTo(uuidFromInt(0));
|
assertThat(group.getId()).isEqualTo(uuidMock(0));
|
||||||
assertThat(group.getParent()).isEqualTo(uuidFromInt(1));
|
assertThat(group.getParent()).isEqualTo(uuidMock(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,20 +6,20 @@ import mops.gruppen2.domain.GroupType;
|
|||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
import org.junit.jupiter.api.Test;
|
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;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class DeleteGroupEventTest {
|
class DeleteGroupEventTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent() {
|
void applyEvent() {
|
||||||
Event createEvent = new CreateGroupEvent(uuidFromInt(0),
|
Event createEvent = new CreateGroupEvent(uuidMock(0),
|
||||||
"A",
|
"A",
|
||||||
uuidFromInt(1),
|
uuidMock(1),
|
||||||
GroupType.SIMPLE,
|
GroupType.SIMPLE,
|
||||||
Visibility.PUBLIC,
|
Visibility.PUBLIC,
|
||||||
100L);
|
100L);
|
||||||
Event deleteEvent = new DeleteGroupEvent(uuidFromInt(0), "A");
|
Event deleteEvent = new DeleteGroupEvent(uuidMock(0), "A");
|
||||||
|
|
||||||
Group group = TestBuilder.apply(createEvent, deleteEvent);
|
Group group = TestBuilder.apply(createEvent, deleteEvent);
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class DeleteGroupEventTest {
|
|||||||
assertThat(group.getType()).isEqualTo(null);
|
assertThat(group.getType()).isEqualTo(null);
|
||||||
assertThat(group.getVisibility()).isEqualTo(null);
|
assertThat(group.getVisibility()).isEqualTo(null);
|
||||||
assertThat(group.getUserMaximum()).isEqualTo(0);
|
assertThat(group.getUserMaximum()).isEqualTo(0);
|
||||||
assertThat(group.getId()).isEqualTo(uuidFromInt(0));
|
assertThat(group.getId()).isEqualTo(uuidMock(0));
|
||||||
assertThat(group.getParent()).isEqualTo(null);
|
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.addUserEvent;
|
||||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
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.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
@ -15,9 +15,9 @@ class DeleteUserEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent() {
|
void applyEvent() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
Event addEvent = addUserEvent(uuidMock(0), "A");
|
||||||
Event deleteEvent = new DeleteUserEvent(uuidFromInt(0), "A");
|
Event deleteEvent = new DeleteUserEvent(uuidMock(0), "A");
|
||||||
|
|
||||||
Group group = TestBuilder.apply(createEvent, addEvent, deleteEvent);
|
Group group = TestBuilder.apply(createEvent, addEvent, deleteEvent);
|
||||||
|
|
||||||
@ -26,9 +26,9 @@ class DeleteUserEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent_userNotFound() {
|
void applyEvent_userNotFound() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
Event addEvent = addUserEvent(uuidMock(0), "A");
|
||||||
Event deleteEvent = new DeleteUserEvent(uuidFromInt(0), "B");
|
Event deleteEvent = new DeleteUserEvent(uuidMock(0), "B");
|
||||||
|
|
||||||
Group group = TestBuilder.apply(createEvent, addEvent);
|
Group group = TestBuilder.apply(createEvent, addEvent);
|
||||||
|
|
||||||
|
|||||||
@ -6,15 +6,15 @@ import mops.gruppen2.domain.exception.GroupIdMismatchException;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
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;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
class EventTest {
|
class EventTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void apply() {
|
void apply() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event addEvent = TestBuilder.addUserEvent(uuidFromInt(1));
|
Event addEvent = TestBuilder.addUserEvent(uuidMock(1));
|
||||||
|
|
||||||
Group group = TestBuilder.apply(createEvent);
|
Group group = TestBuilder.apply(createEvent);
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import mops.gruppen2.domain.exception.BadParameterException;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
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.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
@ -14,8 +14,8 @@ class UpdateGroupDescriptionEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent() {
|
void applyEvent() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event updateEvent = new UpdateGroupDescriptionEvent(uuidFromInt(0), "A", "desc.");
|
Event updateEvent = new UpdateGroupDescriptionEvent(uuidMock(0), "A", "desc.");
|
||||||
|
|
||||||
Group group = TestBuilder.apply(createEvent, updateEvent);
|
Group group = TestBuilder.apply(createEvent, updateEvent);
|
||||||
|
|
||||||
@ -24,9 +24,9 @@ class UpdateGroupDescriptionEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent_badDescription() {
|
void applyEvent_badDescription() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event updateEventA = new UpdateGroupDescriptionEvent(uuidFromInt(0), "A", "");
|
Event updateEventA = new UpdateGroupDescriptionEvent(uuidMock(0), "A", "");
|
||||||
Event updateEventB = new UpdateGroupDescriptionEvent(uuidFromInt(0), "A", " ");
|
Event updateEventB = new UpdateGroupDescriptionEvent(uuidMock(0), "A", " ");
|
||||||
|
|
||||||
Group group = TestBuilder.apply(createEvent);
|
Group group = TestBuilder.apply(createEvent);
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import mops.gruppen2.domain.exception.BadParameterException;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
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.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
@ -14,8 +14,8 @@ class UpdateGroupTitleEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent() {
|
void applyEvent() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event updateEvent = new UpdateGroupTitleEvent(uuidFromInt(0), "A", "title.");
|
Event updateEvent = new UpdateGroupTitleEvent(uuidMock(0), "A", "title.");
|
||||||
|
|
||||||
Group group = TestBuilder.apply(createEvent, updateEvent);
|
Group group = TestBuilder.apply(createEvent, updateEvent);
|
||||||
|
|
||||||
@ -24,9 +24,9 @@ class UpdateGroupTitleEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent_badDescription() {
|
void applyEvent_badDescription() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event updateEventA = new UpdateGroupTitleEvent(uuidFromInt(0), "A", "");
|
Event updateEventA = new UpdateGroupTitleEvent(uuidMock(0), "A", "");
|
||||||
Event updateEventB = new UpdateGroupTitleEvent(uuidFromInt(0), "A", " ");
|
Event updateEventB = new UpdateGroupTitleEvent(uuidMock(0), "A", " ");
|
||||||
|
|
||||||
Group group = TestBuilder.apply(createEvent);
|
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.addUserEvent;
|
||||||
import static mops.gruppen2.TestBuilder.apply;
|
import static mops.gruppen2.TestBuilder.apply;
|
||||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
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.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
@ -16,9 +16,9 @@ class UpdateRoleEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent() {
|
void applyEvent() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
Event addEvent = addUserEvent(uuidMock(0), "A");
|
||||||
Event updateEvent = new UpdateRoleEvent(uuidFromInt(0), "A", Role.ADMIN);
|
Event updateEvent = new UpdateRoleEvent(uuidMock(0), "A", Role.ADMIN);
|
||||||
|
|
||||||
Group group = apply(createEvent, addEvent, updateEvent);
|
Group group = apply(createEvent, addEvent, updateEvent);
|
||||||
|
|
||||||
@ -27,9 +27,9 @@ class UpdateRoleEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent_userNotFound() {
|
void applyEvent_userNotFound() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
Event addEvent = addUserEvent(uuidMock(0), "A");
|
||||||
Event updateEvent = new UpdateRoleEvent(uuidFromInt(0), "B", Role.ADMIN);
|
Event updateEvent = new UpdateRoleEvent(uuidMock(0), "B", Role.ADMIN);
|
||||||
|
|
||||||
Group group = apply(createEvent, addEvent);
|
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.addUserEvent;
|
||||||
import static mops.gruppen2.TestBuilder.apply;
|
import static mops.gruppen2.TestBuilder.apply;
|
||||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
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.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
@ -15,8 +15,8 @@ class UpdateUserMaxEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent() {
|
void applyEvent() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event updateEvent = new UpdateUserMaxEvent(uuidFromInt(0), "A", 5L);
|
Event updateEvent = new UpdateUserMaxEvent(uuidMock(0), "A", 5L);
|
||||||
|
|
||||||
Group group = apply(createEvent, updateEvent);
|
Group group = apply(createEvent, updateEvent);
|
||||||
|
|
||||||
@ -25,8 +25,8 @@ class UpdateUserMaxEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent_badParameter_negative() {
|
void applyEvent_badParameter_negative() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event updateEvent = new UpdateUserMaxEvent(uuidFromInt(0), "A", -5L);
|
Event updateEvent = new UpdateUserMaxEvent(uuidMock(0), "A", -5L);
|
||||||
|
|
||||||
Group group = apply(createEvent);
|
Group group = apply(createEvent);
|
||||||
|
|
||||||
@ -35,12 +35,12 @@ class UpdateUserMaxEventTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyEvent_badParameter_tooSmall() {
|
void applyEvent_badParameter_tooSmall() {
|
||||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
Event createEvent = createPublicGroupEvent(uuidMock(0));
|
||||||
Event updateEventA = new UpdateUserMaxEvent(uuidFromInt(0), "A", 5L);
|
Event updateEventA = new UpdateUserMaxEvent(uuidMock(0), "A", 5L);
|
||||||
Event addEventA = addUserEvent(uuidFromInt(0));
|
Event addEventA = addUserEvent(uuidMock(0));
|
||||||
Event addEventB = addUserEvent(uuidFromInt(0));
|
Event addEventB = addUserEvent(uuidMock(0));
|
||||||
Event addEventC = addUserEvent(uuidFromInt(0));
|
Event addEventC = addUserEvent(uuidMock(0));
|
||||||
Event updateEventB = new UpdateUserMaxEvent(uuidFromInt(0), "A", 2L);
|
Event updateEventB = new UpdateUserMaxEvent(uuidMock(0), "A", 2L);
|
||||||
|
|
||||||
Group group = apply(createEvent, updateEventA, addEventA, addEventB, addEventC);
|
Group group = apply(createEvent, updateEventA, addEventA, addEventB, addEventC);
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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?
|
||||||
@ -84,21 +89,21 @@ class GroupServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getGroupEvents() {
|
void getGroupEvents() {
|
||||||
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() {
|
||||||
Event test1 = createPublicGroupEvent(uuidFromInt(0));
|
Event test1 = createPublicGroupEvent(uuidMock(0));
|
||||||
Event test2 = deleteGroupEvent(uuidFromInt(0));
|
Event test2 = deleteGroupEvent(uuidMock(0));
|
||||||
|
|
||||||
//TODO: Hier projectEventlist()?
|
//TODO: Hier projectEventlist()?
|
||||||
Group group = TestBuilder.apply(test1, test2);
|
Group group = TestBuilder.apply(test1, test2);
|
||||||
@ -109,8 +114,8 @@ class GroupServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getAllGroupWithVisibilityPublicTestGroupPublic() {
|
void getAllGroupWithVisibilityPublicTestGroupPublic() {
|
||||||
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);
|
||||||
@ -118,8 +123,8 @@ class GroupServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getAllGroupWithVisibilityPublicTestAddSomeEvents() {
|
void getAllGroupWithVisibilityPublicTestAddSomeEvents() {
|
||||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
|
||||||
deleteGroupEvent(uuidFromInt(0)),
|
deleteGroupEvent(uuidMock(0)),
|
||||||
createPublicGroupEvent(),
|
createPublicGroupEvent(),
|
||||||
createPublicGroupEvent(),
|
createPublicGroupEvent(),
|
||||||
createPublicGroupEvent(),
|
createPublicGroupEvent(),
|
||||||
@ -130,8 +135,8 @@ class GroupServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getAllGroupWithVisibilityPublic_UserInGroup() {
|
void getAllGroupWithVisibilityPublic_UserInGroup() {
|
||||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
eventService.saveAll(createPublicGroupEvent(uuidMock(0)),
|
||||||
addUserEvent(uuidFromInt(0), "kobold"),
|
addUserEvent(uuidMock(0), "kobold"),
|
||||||
createPrivateGroupEvent(),
|
createPrivateGroupEvent(),
|
||||||
createPublicGroupEvent());
|
createPublicGroupEvent());
|
||||||
|
|
||||||
@ -152,10 +157,10 @@ class GroupServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void findGroupWith_UserMember_AllGroups() {
|
void findGroupWith_UserMember_AllGroups() {
|
||||||
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("", account("jens"))).isEmpty();
|
assertThat(groupService.findGroupWith("", account("jens"))).isEmpty();
|
||||||
}
|
}
|
||||||
@ -170,12 +175,12 @@ class GroupServiceTest {
|
|||||||
|
|
||||||
@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);
|
||||||
|
|||||||
Reference in New Issue
Block a user