1

rename package

Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
Christoph
2020-03-29 14:12:43 +02:00
parent eee7b4367a
commit 36ebb6b8b6
17 changed files with 155 additions and 196 deletions

View File

@ -1,4 +1,4 @@
package mops.gruppen2.security; package mops.gruppen2.config;
import org.keycloak.OAuth2Constants; import org.keycloak.OAuth2Constants;
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver; import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;

View File

@ -1,4 +1,4 @@
package mops.gruppen2.security; package mops.gruppen2.config;
import org.keycloak.KeycloakPrincipal; import org.keycloak.KeycloakPrincipal;
import org.keycloak.adapters.springsecurity.KeycloakSecurityComponents; import org.keycloak.adapters.springsecurity.KeycloakSecurityComponents;

View File

@ -1,6 +1,6 @@
package mops.gruppen2.controller; package mops.gruppen2.controller;
import mops.gruppen2.security.Account; import mops.gruppen2.domain.Account;
import mops.gruppen2.service.ControllerService; import mops.gruppen2.service.ControllerService;
import mops.gruppen2.service.GroupService; import mops.gruppen2.service.GroupService;
import mops.gruppen2.service.KeyCloakService; import mops.gruppen2.service.KeyCloakService;

View File

@ -1,9 +1,9 @@
package mops.gruppen2.controller; package mops.gruppen2.controller;
import mops.gruppen2.domain.Account;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.Role; import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.User; import mops.gruppen2.domain.User;
import mops.gruppen2.security.Account;
import mops.gruppen2.service.ControllerService; import mops.gruppen2.service.ControllerService;
import mops.gruppen2.service.InviteService; import mops.gruppen2.service.InviteService;
import mops.gruppen2.service.KeyCloakService; import mops.gruppen2.service.KeyCloakService;
@ -50,10 +50,7 @@ public class GroupDetailsController {
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
Account account = KeyCloakService.createAccountFromPrincipal(token); Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), User user = new User(account);
account.getGivenname(),
account.getFamilyname(),
account.getEmail());
UUID parentId = group.getParent(); UUID parentId = group.getParent();
String actualURL = request.getRequestURL().toString(); String actualURL = request.getRequestURL().toString();
String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/")); String serverURL = actualURL.substring(0, actualURL.indexOf("gruppen2/"));
@ -91,10 +88,7 @@ public class GroupDetailsController {
@PathVariable("id") String groupId) { @PathVariable("id") String groupId) {
Account account = KeyCloakService.createAccountFromPrincipal(token); Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), User user = new User(account);
account.getGivenname(),
account.getFamilyname(),
account.getEmail());
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
validationService.throwIfNoAdmin(group, user); validationService.throwIfNoAdmin(group, user);
@ -119,8 +113,7 @@ public class GroupDetailsController {
@RequestParam("groupId") String groupId) { @RequestParam("groupId") String groupId) {
Account account = KeyCloakService.createAccountFromPrincipal(token); Account account = KeyCloakService.createAccountFromPrincipal(token);
//TODO: new Constructor/Method User user = new User(account);
User user = new User(account.getName(), "", "", "");
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
validationService.throwIfNoAdmin(group, user); validationService.throwIfNoAdmin(group, user);
@ -139,7 +132,7 @@ public class GroupDetailsController {
Account account = KeyCloakService.createAccountFromPrincipal(token); Account account = KeyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
User user = new User(account.getName(), "", "", ""); User user = new User(account);
validationService.throwIfNoAdmin(group, user); validationService.throwIfNoAdmin(group, user);
@ -160,7 +153,7 @@ public class GroupDetailsController {
Account account = KeyCloakService.createAccountFromPrincipal(token); Account account = KeyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
User principle = new User(account.getName(), "", "", ""); User principle = new User(account);
User user = new User(userId, "", "", ""); User user = new User(userId, "", "", "");
validationService.throwIfNoAdmin(group, principle); validationService.throwIfNoAdmin(group, principle);
@ -199,7 +192,7 @@ public class GroupDetailsController {
@RequestParam("user_id") String userId) { @RequestParam("user_id") String userId) {
Account account = KeyCloakService.createAccountFromPrincipal(token); Account account = KeyCloakService.createAccountFromPrincipal(token);
User principle = new User(account.getName(), "", "", ""); User principle = new User(account);
User user = new User(userId, "", "", ""); User user = new User(userId, "", "", "");
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
@ -222,10 +215,7 @@ public class GroupDetailsController {
@RequestParam("id") String groupId) { @RequestParam("id") String groupId) {
Account account = KeyCloakService.createAccountFromPrincipal(token); Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), User user = new User(account);
account.getGivenname(),
account.getFamilyname(),
account.getEmail());
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
validationService.throwIfUserAlreadyInGroup(group, user); validationService.throwIfUserAlreadyInGroup(group, user);
@ -245,7 +235,7 @@ public class GroupDetailsController {
@RequestParam("group_id") String groupId) { @RequestParam("group_id") String groupId) {
Account account = KeyCloakService.createAccountFromPrincipal(token); Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), "", "", ""); User user = new User(account);
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
controllerService.deleteUser(account, user, group); controllerService.deleteUser(account, user, group);
@ -260,10 +250,7 @@ public class GroupDetailsController {
@RequestParam("group_id") String groupId) { @RequestParam("group_id") String groupId) {
Account account = KeyCloakService.createAccountFromPrincipal(token); Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), User user = new User(account);
account.getGivenname(),
account.getFamilyname(),
account.getEmail());
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
validationService.throwIfNoAdmin(group, user); validationService.throwIfNoAdmin(group, user);

View File

@ -1,8 +1,8 @@
package mops.gruppen2.controller; package mops.gruppen2.controller;
import mops.gruppen2.domain.Account;
import mops.gruppen2.domain.User; import mops.gruppen2.domain.User;
import mops.gruppen2.domain.exception.PageNotFoundException; import mops.gruppen2.domain.exception.PageNotFoundException;
import mops.gruppen2.security.Account;
import mops.gruppen2.service.KeyCloakService; import mops.gruppen2.service.KeyCloakService;
import mops.gruppen2.service.UserService; import mops.gruppen2.service.UserService;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken; import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
@ -35,10 +35,7 @@ public class GruppenfindungController {
Account account = KeyCloakService.createAccountFromPrincipal(token); Account account = KeyCloakService.createAccountFromPrincipal(token);
//TODO: new Contructor/method //TODO: new Contructor/method
User user = new User(account.getName(), User user = new User(account);
account.getGivenname(),
account.getFamilyname(),
account.getEmail());
model.addAttribute("account", account); model.addAttribute("account", account);
model.addAttribute("gruppen", userService.getUserGroups(user)); model.addAttribute("gruppen", userService.getUserGroups(user));

View File

@ -1,9 +1,9 @@
package mops.gruppen2.controller; package mops.gruppen2.controller;
import mops.gruppen2.domain.Account;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.User; import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility; import mops.gruppen2.domain.Visibility;
import mops.gruppen2.security.Account;
import mops.gruppen2.service.ControllerService; import mops.gruppen2.service.ControllerService;
import mops.gruppen2.service.InviteService; import mops.gruppen2.service.InviteService;
import mops.gruppen2.service.KeyCloakService; import mops.gruppen2.service.KeyCloakService;
@ -69,8 +69,7 @@ public class SearchAndInviteController {
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
UUID parentId = group.getParent(); UUID parentId = group.getParent();
Group parent = controllerService.getParent(parentId); Group parent = controllerService.getParent(parentId);
//TODO: Replace User user = new User(account);
User user = new User(account.getName(), "", "", "");
model.addAttribute("account", account); model.addAttribute("account", account);
if (validationService.checkIfUserInGroup(group, user)) { if (validationService.checkIfUserInGroup(group, user)) {
@ -111,12 +110,7 @@ public class SearchAndInviteController {
@RequestParam("id") String groupId) { @RequestParam("id") String groupId) {
Account account = KeyCloakService.createAccountFromPrincipal(token); Account account = KeyCloakService.createAccountFromPrincipal(token);
User user = new User(account);
User user = new User(account.getName(),
account.getGivenname(),
account.getFamilyname(),
account.getEmail());
Group group = userService.getGroupById(UUID.fromString(groupId)); Group group = userService.getGroupById(UUID.fromString(groupId));
validationService.throwIfUserAlreadyInGroup(group, user); validationService.throwIfUserAlreadyInGroup(group, user);

View File

@ -1,4 +1,4 @@
package mops.gruppen2.security; package mops.gruppen2.domain;
import lombok.Value; import lombok.Value;

View File

@ -15,4 +15,11 @@ public class User {
private String givenname; private String givenname;
private String familyname; private String familyname;
private String email; private String email;
public User(Account account) {
id = account.getName();
givenname = account.getGivenname();
familyname = account.getFamilyname();
email = account.getEmail();
}
} }

View File

@ -22,6 +22,6 @@ public class UpdateUserMaxEvent extends Event {
@Override @Override
protected void applyEvent(Group group) throws EventException { protected void applyEvent(Group group) throws EventException {
group.setUserMaximum(this.userMaximum); group.setUserMaximum(userMaximum);
} }
} }

View File

@ -1,5 +1,6 @@
package mops.gruppen2.service; package mops.gruppen2.service;
import mops.gruppen2.domain.Account;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.GroupType; import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Role; import mops.gruppen2.domain.Role;
@ -15,7 +16,6 @@ import mops.gruppen2.domain.event.UpdateRoleEvent;
import mops.gruppen2.domain.event.UpdateUserMaxEvent; import mops.gruppen2.domain.event.UpdateUserMaxEvent;
import mops.gruppen2.domain.exception.EventException; import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.WrongFileException; import mops.gruppen2.domain.exception.WrongFileException;
import mops.gruppen2.security.Account;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -72,20 +72,35 @@ public class ControllerService {
* @param parent Parameter für die neue Gruppe * @param parent Parameter für die neue Gruppe
* @param file Parameter für die neue Gruppe * @param file Parameter für die neue Gruppe
*/ */
public void createGroupAsOrga(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent, MultipartFile file) { public void createGroupAsOrga(Account account,
String title,
String description,
Boolean isVisibilityPrivate,
Boolean isLecture,
Boolean isMaximumInfinite,
Long userMaximum,
UUID parent,
MultipartFile file) {
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum); userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
List<User> newUsers = readCsvFile(file); List<User> newUsers = readCsvFile(file);
List<User> oldUsers = new ArrayList<>(); List<User> oldUsers = new ArrayList<>();
User user = new User(account.getName(), "", "", ""); User user = new User(account);
oldUsers.add(user); oldUsers.add(user);
removeOldUsersFromNewUsers(oldUsers, newUsers); removeOldUsersFromNewUsers(oldUsers, newUsers);
userMaximum = adjustUserMaximum((long) newUsers.size(), 1L, userMaximum); userMaximum = adjustUserMaximum((long) newUsers.size(), 1L, userMaximum);
UUID groupId = createGroup(account, title, description, isVisibilityPrivate, isLecture, isMaximumInfinite, userMaximum, parent); UUID groupId = createGroup(account,
title,
description,
isVisibilityPrivate,
isLecture,
isMaximumInfinite,
userMaximum, parent);
addUserList(newUsers, groupId); addUserList(newUsers, groupId);
} }
@ -99,7 +114,7 @@ public class ControllerService {
* *
* @return Maximum an Usern * @return Maximum an Usern
*/ */
private Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) { private static Long checkInfiniteUsers(Boolean isMaximumInfinite, Long userMaximum) {
isMaximumInfinite = isMaximumInfinite != null; isMaximumInfinite = isMaximumInfinite != null;
if (isMaximumInfinite) { if (isMaximumInfinite) {
@ -109,6 +124,52 @@ public class ControllerService {
return userMaximum; return userMaximum;
} }
/**
* Erzeugt eine neue Gruppe, fügt den User, der die Gruppe erstellt hat, hinzu und setzt seine Rolle als Admin fest.
* Zudem wird der Gruppentitel und die Gruppenbeschreibung erzeugt, welche vorher der Methode übergeben wurden.
* Aus diesen Event-Objekten wird eine Liste erzeugt, welche daraufhin mithilfe des EventServices gesichert wird.
*
* @param account Keycloak-Account
* @param title Gruppentitel
* @param description Gruppenbeschreibung
*/
//TODO: remove booleans
public UUID createGroup(Account account,
String title,
String description,
Boolean isVisibilityPrivate,
Boolean isLecture,
Boolean isMaximumInfinite,
Long userMaximum,
UUID parent) {
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate);
UUID groupId = UUID.randomUUID();
GroupType groupType = setGroupType(isLecture);
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId,
account.getName(),
parent,
groupType,
groupVisibility,
userMaximum);
eventService.saveEvent(createGroupEvent);
inviteService.createLink(groupId);
User user = new User(account.getName(), "", "", "");
addUser(account, groupId);
updateTitle(account, groupId, title);
updateDescription(account, groupId, description);
updateRole(user, groupId);
return groupId;
}
private static List<User> readCsvFile(MultipartFile file) throws EventException { private static List<User> readCsvFile(MultipartFile file) throws EventException {
if (file == null) { if (file == null) {
return new ArrayList<>(); return new ArrayList<>();
@ -138,39 +199,6 @@ public class ControllerService {
return maxUsers; return maxUsers;
} }
/**
* Erzeugt eine neue Gruppe, fügt den User, der die Gruppe erstellt hat, hinzu und setzt seine Rolle als Admin fest.
* Zudem wird der Gruppentitel und die Gruppenbeschreibung erzeugt, welche vorher der Methode übergeben wurden.
* Aus diesen Event Objekten wird eine Liste erzeugt, welche daraufhin mithilfe des EventServices gesichert wird.
*
* @param account Keycloak-Account
* @param title Gruppentitel
* @param description Gruppenbeschreibung
*/
//TODO: remove booleans
public UUID createGroup(Account account, String title, String description, Boolean isVisibilityPrivate, Boolean isLecture, Boolean isMaximumInfinite, Long userMaximum, UUID parent) {
userMaximum = checkInfiniteUsers(isMaximumInfinite, userMaximum);
Visibility groupVisibility = setGroupVisibility(isVisibilityPrivate);
UUID groupId = UUID.randomUUID();
GroupType groupType = setGroupType(isLecture);
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), parent, groupType, groupVisibility, userMaximum);
eventService.saveEvent(createGroupEvent);
inviteService.createLink(groupId);
User user = new User(account.getName(), "", "", "");
addUser(account, groupId);
updateTitle(account, groupId, title);
updateDescription(account, groupId, description);
updateRole(user, groupId);
return groupId;
}
private void addUserList(List<User> newUsers, UUID groupId) { private void addUserList(List<User> newUsers, UUID groupId) {
for (User user : newUsers) { for (User user : newUsers) {
Group group = userService.getGroupById(groupId); Group group = userService.getGroupById(groupId);

View File

@ -1,5 +1,6 @@
package mops.gruppen2.service; package mops.gruppen2.service;
import mops.gruppen2.domain.Account;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.GroupType; import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Visibility; import mops.gruppen2.domain.Visibility;
@ -7,7 +8,6 @@ import mops.gruppen2.domain.dto.EventDTO;
import mops.gruppen2.domain.event.Event; import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.exception.EventException; import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.repository.EventRepository; import mops.gruppen2.repository.EventRepository;
import mops.gruppen2.security.Account;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -60,7 +60,10 @@ public class GroupService {
List<Group> visibleGroups = projectEventList(createEvents); List<Group> visibleGroups = projectEventList(createEvents);
return visibleGroups.stream().filter(group -> group.getType() == GroupType.LECTURE).filter(group -> group.getVisibility() == Visibility.PUBLIC).collect(Collectors.toList()); return visibleGroups.stream()
.filter(group -> group.getType() == GroupType.LECTURE)
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
.collect(Collectors.toList());
} }
/** /**
@ -76,7 +79,8 @@ public class GroupService {
public List<Group> projectEventList(List<Event> events) throws EventException { public List<Group> projectEventList(List<Event> events) throws EventException {
Map<UUID, Group> groupMap = new HashMap<>(); Map<UUID, Group> groupMap = new HashMap<>();
events.parallelStream().forEachOrdered(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId()))); events.parallelStream()
.forEachOrdered(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId())));
return new ArrayList<>(groupMap.values()); return new ArrayList<>(groupMap.values());
} }

View File

@ -1,6 +1,6 @@
package mops.gruppen2.service; package mops.gruppen2.service;
import mops.gruppen2.security.Account; import mops.gruppen2.domain.Account;
import org.keycloak.KeycloakPrincipal; import org.keycloak.KeycloakPrincipal;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken; import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;

View File

@ -1,5 +1,6 @@
package mops.gruppen2.service; package mops.gruppen2.service;
import mops.gruppen2.domain.Account;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.Role; import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.User; import mops.gruppen2.domain.User;
@ -11,7 +12,6 @@ import mops.gruppen2.domain.exception.NoAccessException;
import mops.gruppen2.domain.exception.NoAdminAfterActionException; import mops.gruppen2.domain.exception.NoAdminAfterActionException;
import mops.gruppen2.domain.exception.UserAlreadyExistsException; import mops.gruppen2.domain.exception.UserAlreadyExistsException;
import mops.gruppen2.domain.exception.UserNotFoundException; import mops.gruppen2.domain.exception.UserNotFoundException;
import mops.gruppen2.security.Account;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -99,12 +99,10 @@ public class ValidationService {
boolean checkIfLastAdmin(Account account, Group group) { boolean checkIfLastAdmin(Account account, Group group) {
for (Map.Entry<String, Role> entry : group.getRoles().entrySet()) { for (Map.Entry<String, Role> entry : group.getRoles().entrySet()) {
if (entry.getValue() == ADMIN) { if (entry.getValue() == ADMIN && !(entry.getKey().equals(account.getName()))) {
if (!(entry.getKey().equals(account.getName()))) {
return false; return false;
} }
} }
}
return true; return true;
} }
@ -128,12 +126,10 @@ public class ValidationService {
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben"); throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
} }
if (userMaximum != null) { if (userMaximum != null && (userMaximum < 1 || userMaximum > 10000L)) {
if (userMaximum < 1 || userMaximum > 10000L) {
throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben"); throw new BadParameterException("Teilnehmeranzahl wurde nicht korrekt angegeben");
} }
} }
}
public void checkFields(String title, String description) { public void checkFields(String title, String description) {
if (description == null || description.trim().isEmpty()) { if (description == null || description.trim().isEmpty()) {

View File

@ -1,6 +1,7 @@
package mops.gruppen2; package mops.gruppen2;
import com.github.javafaker.Faker; import com.github.javafaker.Faker;
import mops.gruppen2.domain.Account;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.GroupType; import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Role; import mops.gruppen2.domain.Role;
@ -13,7 +14,6 @@ import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent; import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
import mops.gruppen2.domain.event.UpdateGroupTitleEvent; import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
import mops.gruppen2.domain.event.UpdateRoleEvent; import mops.gruppen2.domain.event.UpdateRoleEvent;
import mops.gruppen2.security.Account;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -52,6 +52,7 @@ public class TestBuilder {
* Baut eine UUID. * Baut eine UUID.
* *
* @param id Integer id * @param id Integer id
*
* @return UUID * @return UUID
*/ */
public static UUID uuidFromInt(int id) { public static UUID uuidFromInt(int id) {
@ -65,6 +66,7 @@ public class TestBuilder {
* *
* @param count Gruppenanzahl * @param count Gruppenanzahl
* @param membercount Mitgliederanzahl pro Gruppe * @param membercount Mitgliederanzahl pro Gruppe
*
* @return Eventliste * @return Eventliste
*/ */
public static List<Event> completePublicGroups(int count, int membercount) { public static List<Event> completePublicGroups(int count, int membercount) {
@ -119,6 +121,7 @@ public class TestBuilder {
* Generiert mehrere CreateGroupEvents, 1 <= groupId <= count. * Generiert mehrere CreateGroupEvents, 1 <= groupId <= count.
* *
* @param count Anzahl der verschiedenen Gruppen * @param count Anzahl der verschiedenen Gruppen
*
* @return Eventliste * @return Eventliste
*/ */
public static List<Event> createPublicGroupEvents(int count) { public static List<Event> createPublicGroupEvents(int count) {
@ -191,6 +194,7 @@ public class TestBuilder {
* *
* @param count Anzahl der Mitglieder * @param count Anzahl der Mitglieder
* @param groupId Gruppe, zu welcher geaddet wird * @param groupId Gruppe, zu welcher geaddet wird
*
* @return Eventliste * @return Eventliste
*/ */
public static List<Event> addUserEvents(int count, UUID groupId) { public static List<Event> addUserEvents(int count, UUID groupId) {
@ -241,6 +245,7 @@ public class TestBuilder {
* Erzeugt mehrere DeleteUserEvents, sodass eine Gruppe komplett geleert wird. * Erzeugt mehrere DeleteUserEvents, sodass eine Gruppe komplett geleert wird.
* *
* @param group Gruppe welche geleert wird * @param group Gruppe welche geleert wird
*
* @return Eventliste * @return Eventliste
*/ */
public static List<Event> deleteUserEvents(Group group) { public static List<Event> deleteUserEvents(Group group) {

View File

@ -1,34 +1,12 @@
package mops.gruppen2.domain.event; package mops.gruppen2.domain.event;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.UserAlreadyExistsException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
class AddUserEventTest { class AddUserEventTest {
@Test @Test
void userAlreadyExistExeption() throws EventException { void applyEvent() {
Group group = new Group();
User user = new User("user1", "Stein", "Speck", "@sdasd");
group.getMembers().add(user);
group.setUserMaximum(10L);
UUID id = UUID.randomUUID();
Event event1 = new AddUserEvent(id, "user2", "Rock", "Roll", "and");
event1.apply(group);
Event event2 = new AddUserEvent(id, "user1", "Rock", "Roll", "and");
assertThrows(UserAlreadyExistsException.class, () ->
event2.apply(group)
);
assertThat(group.getMembers().size()).isEqualTo(2);
} }

View File

@ -1,48 +1,10 @@
package mops.gruppen2.domain.event; package mops.gruppen2.domain.event;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.exception.EventException;
import mops.gruppen2.domain.exception.UserNotFoundException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.UUID;
import static mops.gruppen2.domain.Role.MEMBER;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
class DeleteUserEventTest { class DeleteUserEventTest {
@Test @Test
void applyDeleteUser() throws EventException { void applyEvent() {
Group group = new Group();
User user = new User("user1", "Stein", "Speck", "@sdasd");
group.getMembers().add(user);
group.getRoles().put("user1", MEMBER);
User user2 = new User("user2", "Rock", "Roll", "and");
group.getMembers().add(user2);
group.getRoles().put("user2", MEMBER);
Event event = new DeleteUserEvent(UUID.randomUUID(), "user1");
event.apply(group);
assertThat(group.getMembers().size()).isEqualTo(1);
assertThat(group.getRoles().size()).isEqualTo(1);
}
@Test
void userDoesNotExistExeption() {
Group group = new Group();
User user = new User("user1", "Stein", "Speck", "@sdasd");
group.getMembers().add(user);
group.getRoles().put("user1", MEMBER);
Event event = new DeleteUserEvent(UUID.randomUUID(), "user5");
assertThrows(UserNotFoundException.class, () ->
event.apply(group)
);
assertThat(group.getMembers().size()).isEqualTo(1);
} }
} }

View File

@ -1,14 +1,14 @@
package mops.gruppen2.service; package mops.gruppen2.service;
import mops.gruppen2.Gruppen2Application; import mops.gruppen2.Gruppen2Application;
import mops.gruppen2.domain.User; import mops.gruppen2.domain.Account;
import mops.gruppen2.domain.Group; import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.GroupType; import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.exception.UserNotFoundException; import mops.gruppen2.domain.exception.UserNotFoundException;
import mops.gruppen2.repository.EventRepository; import mops.gruppen2.repository.EventRepository;
import mops.gruppen2.security.Account;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
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;
@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@Transactional @Transactional
@Rollback @Rollback
class ControllerServiceTest { class ControllerServiceTest {
Account account; Account account;
Account account2; Account account2;
Account account3; Account account3;