1

Fix Checkstyle Errors :(

Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
Christoph
2020-03-18 23:17:57 +01:00
parent 08717611d5
commit a05ffe9e4c
33 changed files with 260 additions and 269 deletions

View File

@ -16,7 +16,7 @@
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
-->
<module name = "Checker">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
@ -30,7 +30,7 @@
<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter">
<property name="file" value="${org.checkstyle.google.suppressionfilter.config}"
default="checkstyle-suppressions.xml" />
default="checkstyle-suppressions.xml"/>
<property name="optional" value="true"/>
</module>
@ -40,13 +40,15 @@
<property name="eachLine" value="true"/>
</module>
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="100"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<!-- <module name="LineLength">-->
<!-- <property name="fileExtensions" value="java"/>-->
<!-- <property name="max" value="100"/>-->
<!-- <property name="ignorePattern"-->
<!-- value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>-->
<!-- </module>-->
<module name="TreeWalker">
<module name="SuppressWarningsHolder"/>
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
@ -234,7 +236,7 @@
<module name="MethodParamPad">
<property name="tokens"
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF"/>
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF"/>
</module>
<module name="NoWhitespaceBefore">
<property name="tokens"
@ -244,15 +246,15 @@
<module name="ParenPad">
<property name="tokens"
value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF,
EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL,
METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA"/>
EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL,
METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA"/>
</module>
<module name="OperatorWrap">
<property name="option" value="NL"/>
<property name="tokens"
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,
LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/>
LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/>
</module>
<module name="AnnotationLocation">
<property name="id" value="AnnotationLocationMostCases"/>
@ -284,14 +286,14 @@
<property name="allowedAnnotations" value="Override, Test"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
</module>
<module name="MissingJavadocMethod">
<property name="scope" value="public"/>
<property name="minLineCount" value="2"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
</module>
<!-- <module name="MissingJavadocMethod">-->
<!-- <property name="scope" value="public"/>-->
<!-- <property name="minLineCount" value="2"/>-->
<!-- <property name="allowedAnnotations" value="Override, Test"/>-->
<!-- <property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>-->
<!-- </module>-->
<module name="MethodName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
<property name="format" value="^[a-z][a-zA-Z0-9][a-zA-Z0-9_]*$"/>
<message key="name.invalidPattern"
value="Method name ''{0}'' must match pattern ''{1}''."/>
</module>
@ -307,7 +309,7 @@
<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->
<module name="SuppressionXpathFilter">
<property name="file" value="${org.checkstyle.google.suppressionxpathfilter.config}"
default="checkstyle-xpath-suppressions.xml" />
default="checkstyle-xpath-suppressions.xml"/>
<property name="optional" value="true"/>
</module>
</module>

View File

@ -54,8 +54,8 @@ public class APIController {
@ApiOperation("Gibt die Gruppe mit der als Parameter mitgegebenden groupId zurück")
public Group getGroupFromId(@ApiParam("GruppenId der gefordeten Gruppe") @PathVariable Long groupId) throws EventException {
List<Event> eventList = eventService.getEventsOfGroup(groupId);
List<Group> groups = groupService.projectEventList(eventList);
return groups.get(0);
}

View File

@ -98,14 +98,14 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_actuator)"})
@PostMapping("/details/members/addUsersFromCsv")
public String addUsersFromCsv(@RequestParam("group_id") Long group_id,
public String addUsersFromCsv(@RequestParam("group_id") Long groupId,
@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
List<User> userList = new ArrayList<>();
if (!file.isEmpty()) {
userList = CsvService.read(file.getInputStream());
}
controllerService.addUserList(userList, group_id);
return "redirect:/gruppen2/details/members/" + group_id;
controllerService.addUserList(userList, groupId);
return "redirect:/gruppen2/details/members/" + groupId;
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@ -117,11 +117,11 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/findGroup")
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String suchbegriff) throws EventException {
public String findGroup(KeycloakAuthenticationToken token, Model model, @RequestParam(value = "suchbegriff", required = false) String search) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
List<Group> groupse = new ArrayList<>();
if (suchbegriff != null) {
groupse = groupService.findGroupWith(suchbegriff, account);
if (search != null) {
groupse = groupService.findGroupWith(search, account);
}
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
model.addAttribute("gruppen", groupse);
@ -144,10 +144,10 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/{id}")
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable("id") Long id) throws EventException, ResponseStatusException {
public String showGroupDetails(KeycloakAuthenticationToken token, Model model, @PathVariable("id") Long groupId) throws EventException, ResponseStatusException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(id);
Group group = userService.getGroupById(groupId);
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
if (group != null) {
@ -162,23 +162,23 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/detailsBeitreten")
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long id) throws EventException {
public String joinGroup(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
Group group = userService.getGroupById(id);
Group group = userService.getGroupById(groupId);
if (group.getMembers().contains(user)) {
return "errorRenameLater"; //hier soll eigentlich auf die bereits beigetretene Gruppe weitergeleitet werden
}
controllerService.addUser(account, id);
controllerService.addUser(account, groupId);
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@GetMapping("/detailsSearch")
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long id) throws EventException {
public String showGroupDetailsNoMember(KeycloakAuthenticationToken token, Model model, @RequestParam("id") Long groupId) throws EventException {
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
Group group = userService.getGroupById(id);
Group group = userService.getGroupById(groupId);
if (group != null) {
model.addAttribute("group", group);
return "detailsNoMember";
@ -200,18 +200,18 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator"})
@PostMapping("/leaveGroup")
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") Long id) throws EventException {
public String pLeaveGroup(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
controllerService.deleteUser(user.getUser_id(), id);
controllerService.deleteUser(user.getId(), groupId);
return "redirect:/gruppen2/";
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@GetMapping("/details/members/{id}")
public String editMembers(Model model, KeycloakAuthenticationToken token, @PathVariable("id") Long id) throws EventException {
public String editMembers(Model model, KeycloakAuthenticationToken token, @PathVariable("id") Long groupId) throws EventException {
Account account = keyCloakService.createAccountFromPrincipal(token);
Group group = userService.getGroupById(id);
Group group = userService.getGroupById(groupId);
if (group.getRoles().get(account.getName()) == Role.ADMIN) {
model.addAttribute("account", account);
model.addAttribute("members", group.getMembers());
@ -225,17 +225,17 @@ public class Gruppen2Controller {
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/changeRole")
public String changeRole(KeycloakAuthenticationToken token, @RequestParam("group_id") Long group_id,
@RequestParam("user_id") String user_id) throws EventException {
controllerService.updateRole(user_id, group_id);
return "redirect:/gruppen2/details/members/" + group_id;
public String changeRole(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId,
@RequestParam("user_id") String userId) throws EventException {
controllerService.updateRole(userId, groupId);
return "redirect:/gruppen2/details/members/" + groupId;
}
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
@PostMapping("/details/members/deleteUser")
public String deleteUser(KeycloakAuthenticationToken token, @RequestParam("group_id") Long group_id,
@RequestParam("user_id") String user_id) throws EventException {
controllerService.deleteUser(user_id, group_id);
return "redirect:/gruppen2/details/members/" + group_id;
public String deleteUser(KeycloakAuthenticationToken token, @RequestParam("group_id") Long groupId,
@RequestParam("user_id") String userId) throws EventException {
controllerService.deleteUser(userId, groupId);
return "redirect:/gruppen2/details/members/" + groupId;
}
}

View File

@ -9,7 +9,7 @@ import lombok.Getter;
@EqualsAndHashCode(exclude = {"givenname", "familyname", "email"})
public class User {
private final String user_id;
private final String id;
private final String givenname;
private final String familyname;
private final String email;

View File

@ -6,7 +6,7 @@ import mops.gruppen2.domain.Group;
import java.util.List;
/**
* Kombiniert den Status und die Gruppenliste zur ausgabe über die API
* Kombiniert den Status und die Gruppenliste zur ausgabe über die API.
*/
@AllArgsConstructor
public class GroupRequestWrapper {

View File

@ -4,6 +4,7 @@ import lombok.Value;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
@SuppressWarnings("checkstyle:membername")
@Table("invite")
@Value
public class InviteLinkDTO {

View File

@ -21,21 +21,22 @@ public class AddUserEvent extends Event {
private String familyname;
private String email;
public AddUserEvent(Long group_id, String user_id, String givenname, String familyname, String email) {
super(group_id, user_id);
public AddUserEvent(Long groupId, String userId, String givenname, String familyname, String email) {
super(groupId, userId);
this.givenname = givenname;
this.familyname = familyname;
this.email = email;
}
@Override
public void apply(Group group) throws EventException {
User user = new User(this.user_id, this.givenname, this.familyname, this.email);
User user = new User(this.userId, this.givenname, this.familyname, this.email);
if (group.getMembers().contains(user)) {
throw new UserAlreadyExistsException("Der User existiert bereits");
}
group.getMembers().add(user);
group.getRoles().put(user_id, Role.MEMBER);
group.getRoles().put(userId, Role.MEMBER);
}
}

View File

@ -16,15 +16,16 @@ public class CreateGroupEvent extends Event {
private Long groupParent;
private GroupType groupType;
public CreateGroupEvent(Long group_id, String user_id, Long parent, GroupType type, Visibility visibility) {
super(group_id, user_id);
public CreateGroupEvent(Long groupId, String userId, Long parent, GroupType type, Visibility visibility) {
super(groupId, userId);
this.groupParent = parent;
this.groupType = type;
this.groupVisibility = visibility;
}
@Override
public void apply(Group group) {
group.setId(this.group_id);
group.setId(this.groupId);
group.setParent(this.groupParent);
group.setType(this.groupType);
group.setVisibility(this.groupVisibility);

View File

@ -8,8 +8,8 @@ import mops.gruppen2.domain.Group;
@NoArgsConstructor // For Jackson
public class DeleteGroupEvent extends Event {
public DeleteGroupEvent(long group_id, String user_id) {
super(group_id, user_id);
public DeleteGroupEvent(Long groupId, String userId) {
super(groupId, userId);
}
@Override

View File

@ -14,15 +14,16 @@ import mops.gruppen2.domain.exception.UserNotFoundException;
@NoArgsConstructor // For Jackson
public class DeleteUserEvent extends Event {
public DeleteUserEvent(Long group_id, String user_id) {
super(group_id, user_id);
public DeleteUserEvent(Long groupId, String userId) {
super(groupId, userId);
}
@Override
public void apply(Group group) throws EventException {
for (User user : group.getMembers()) {
if (user.getUser_id().equals(this.user_id)) {
if (user.getId().equals(this.userId)) {
group.getMembers().remove(user);
group.getRoles().remove(user.getUser_id());
group.getRoles().remove(user.getId());
return;
}
}

View File

@ -27,8 +27,8 @@ import mops.gruppen2.domain.exception.EventException;
@AllArgsConstructor
public class Event {
protected Long group_id;
protected String user_id;
protected Long groupId;
protected String userId;
public void apply(Group group) throws EventException {}
}

View File

@ -15,11 +15,12 @@ public class UpdateGroupDescriptionEvent extends Event {
private String newGroupDescription;
public UpdateGroupDescriptionEvent(Long group_id, String user_id, String newGroupDescription) {
super(group_id, user_id);
public UpdateGroupDescriptionEvent(Long groupId, String userId, String newGroupDescription) {
super(groupId, userId);
this.newGroupDescription = newGroupDescription;
}
@Override
public void apply(Group group) {
group.setDescription(this.newGroupDescription);
}

View File

@ -15,11 +15,12 @@ public class UpdateGroupTitleEvent extends Event {
private String newGroupTitle;
public UpdateGroupTitleEvent(Long group_id, String user_id, String newGroupTitle) {
super(group_id, user_id);
public UpdateGroupTitleEvent(Long groupId, String userId, String newGroupTitle) {
super(groupId, userId);
this.newGroupTitle = newGroupTitle;
}
@Override
public void apply(Group group) {
group.setTitle(this.newGroupTitle);
}

View File

@ -17,16 +17,17 @@ public class UpdateRoleEvent extends Event {
private Role newRole;
public UpdateRoleEvent(Long group_id, String user_id, Role newRole) {
super(group_id, user_id);
public UpdateRoleEvent(Long groupId, String userId, Role newRole) {
super(groupId, userId);
this.newRole = newRole;
}
@Override
public void apply(Group group) throws UserNotFoundException {
if (!group.getRoles().containsKey(user_id)) {
if (!group.getRoles().containsKey(userId)) {
throw new UserNotFoundException("Der User wurde nicht gefunden");
}
group.getRoles().put(this.user_id, this.newRole);
group.getRoles().put(this.userId, this.newRole);
}
}

View File

@ -12,10 +12,10 @@ import java.util.List;
public interface EventRepository extends CrudRepository<EventDTO, Long> {
@Query("select distinct group_id from event where user_id =:id")
List<Long> findGroup_idsWhereUser_id(@Param("id") String user_id);
List<Long> findGroup_idsWhereUser_id(@Param("id") String userId);
@Query("select * from event where group_id =:id")
List<EventDTO> findEventDTOByGroup_id(@Param("id") Long group_id);
List<EventDTO> findEventDTOByGroup_id(@Param("id") Long groupId);
//@Query("SELECT * FROM event WHERE event_id > ?#{[0]}")
//Iterable<EventDTO> findNewEventSinceStatus(@Param("status") Long status);

View File

@ -9,7 +9,7 @@ import java.util.List;
@Service
public class APIFormatterService {
static public GroupRequestWrapper wrap(Long status, List<Group> groupList) {
public static GroupRequestWrapper wrap(Long status, List<Group> groupList) {
return new GroupRequestWrapper(status, groupList);
}
}

View File

@ -35,91 +35,90 @@ public class ControllerService {
public void createGroup(Account account, String title, String description, Boolean visibility) throws EventException {
Visibility visibility1;
Long group_id = eventService.checkGroup();
Long groupId = eventService.checkGroup();
if (visibility) {
visibility1 = Visibility.PUBLIC;
} else {
visibility1 = Visibility.PRIVATE;
createInviteLink(group_id);
createInviteLink(groupId);
}
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null, GroupType.SIMPLE, visibility1);
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.SIMPLE, visibility1);
eventService.saveEvent(createGroupEvent);
User user = new User(account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
addUser(account, group_id);
updateTitle(account, group_id, title);
updateDescription(account, group_id, description);
updateRole(user.getUser_id(), group_id);
addUser(account, groupId);
updateTitle(account, groupId, title);
updateDescription(account, groupId, description);
updateRole(account.getName(), groupId);
}
private void createInviteLink(Long group_id) {
inviteLinkRepositoryService.saveInvite(group_id, UUID.randomUUID());
private void createInviteLink(Long groupId) {
inviteLinkRepositoryService.saveInvite(groupId, UUID.randomUUID());
}
public void addUser(Account account, Long group_id) {
AddUserEvent addUserEvent = new AddUserEvent(group_id, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
public void addUser(Account account, Long groupId) {
AddUserEvent addUserEvent = new AddUserEvent(groupId, account.getName(), account.getGivenname(), account.getFamilyname(), account.getEmail());
eventService.saveEvent(addUserEvent);
}
public void addUserList(List<User> users, Long group_id) {
public void addUserList(List<User> users, Long groupId) {
for (User user : users) {
AddUserEvent addUserEvent = new AddUserEvent(group_id, user.getUser_id(), user.getGivenname(), user.getFamilyname(), user.getEmail());
AddUserEvent addUserEvent = new AddUserEvent(groupId, user.getId(), user.getGivenname(), user.getFamilyname(), user.getEmail());
eventService.saveEvent(addUserEvent);
}
}
public void updateTitle(Account account, Long group_id, String title) {
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(group_id, account.getName(), title);
public void updateTitle(Account account, Long groupId, String title) {
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(groupId, account.getName(), title);
eventService.saveEvent(updateGroupTitleEvent);
}
public void updateDescription(Account account, Long group_id, String description) {
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(group_id, account.getName(), description);
public void updateDescription(Account account, Long groupId, String description) {
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(groupId, account.getName(), description);
eventService.saveEvent(updateGroupDescriptionEvent);
}
public void updateRole(String user_id, Long group_id) throws EventException {
public void updateRole(String userId, Long groupId) throws EventException {
UpdateRoleEvent updateRoleEvent;
Group group = userService.getGroupById(group_id);
Group group = userService.getGroupById(groupId);
User user = null;
for (User member : group.getMembers()) {
if (member.getUser_id().equals(user_id)) {
if (member.getId().equals(userId)) {
user = member;
}
}
assert user != null;
if (group.getRoles().get(user.getUser_id()) == Role.ADMIN) {
updateRoleEvent = new UpdateRoleEvent(group_id, user.getUser_id(), Role.MEMBER);
if (group.getRoles().get(user.getId()) == Role.ADMIN) {
updateRoleEvent = new UpdateRoleEvent(groupId, user.getId(), Role.MEMBER);
} else {
updateRoleEvent = new UpdateRoleEvent(group_id, user.getUser_id(), Role.ADMIN);
updateRoleEvent = new UpdateRoleEvent(groupId, user.getId(), Role.ADMIN);
}
eventService.saveEvent(updateRoleEvent);
}
public void deleteUser(String user_id, Long group_id) throws EventException {
Group group = userService.getGroupById(group_id);
public void deleteUser(String userId, Long groupId) throws EventException {
Group group = userService.getGroupById(groupId);
User user = null;
for (User member : group.getMembers()) {
if (member.getUser_id().equals(user_id)) {
if (member.getId().equals(userId)) {
user = member;
}
}
assert user != null;
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(group_id, user.getUser_id());
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(groupId, user.getId());
eventService.saveEvent(deleteUserEvent);
}
public void deleteGroupEvent(User user, Long group_id) {
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(group_id, user.getUser_id());
public void deleteGroupEvent(User user, Long groupId) {
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(groupId, user.getId());
eventService.saveEvent(deleteGroupEvent);
}
public void createLecture(Account account, String title, String description, Boolean visibility, List<User> users) throws EventException {
Visibility visibility1;
Long group_id = eventService.checkGroup();
Long groupId = eventService.checkGroup();
if (visibility) {
visibility1 = Visibility.PUBLIC;
@ -127,13 +126,13 @@ public class ControllerService {
visibility1 = Visibility.PRIVATE;
}
CreateGroupEvent createGroupEvent = new CreateGroupEvent(group_id, account.getName(), null, GroupType.LECTURE, visibility1);
CreateGroupEvent createGroupEvent = new CreateGroupEvent(groupId, account.getName(), null, GroupType.LECTURE, visibility1);
eventService.saveEvent(createGroupEvent);
addUser(account, group_id);
updateTitle(account, group_id, title);
updateDescription(account, group_id, description);
updateRole(account.getName(), group_id);
addUserList(users, group_id);
addUser(account, groupId);
updateTitle(account, groupId, title);
updateDescription(account, groupId, description);
updateRole(account.getName(), groupId);
addUserList(users, groupId);
}
}

View File

@ -23,9 +23,9 @@ public class EventService {
}
/**
* sichert ein Event Objekt indem es ein EventDTO Objekt erzeugt
* Erzeugt ein DTO aus einem Event und speicher es.
*
* @param event
* @param event Event, welches gespeichert wird
*/
public void saveEvent(Event event) {
EventDTO eventDTO = getDTO(event);
@ -36,8 +36,8 @@ public class EventService {
* Erzeugt aus einem Event Objekt ein EventDTO Objekt.
* Ist die Gruppe öffentlich, dann wird die visibility auf true gesetzt.
*
* @param event
* @return EventDTO
* @param event Event, welches in DTO übersetzt wird
* @return EventDTO Neues DTO
*/
public EventDTO getDTO(Event event) {
boolean visibility = false;
@ -52,14 +52,14 @@ public class EventService {
e.printStackTrace();
}
return new EventDTO(null, event.getGroup_id(), event.getUser_id(), payload, visibility);
return new EventDTO(null, event.getGroupId(), event.getUserId(), payload, visibility);
}
/**
* Gibt die nächst höhere groupID zurück die belegt werden kann.
* Gibt 1 zurück, falls keine Gruppe vorhanden ist.
*
* @return Gibt Long zurück
* @return Long GruppenId
*/
public Long checkGroup() {
Long maxGroupID = eventStore.getMaxGroupID();
@ -70,10 +70,10 @@ public class EventService {
}
/**
* Findet alle Events welche ab dem neuen Status hinzugekommen sind
* Findet alle Events welche ab dem neuen Status hinzugekommen sind.
*
* @param status
* @return Liste von Events
* @param status Die Id des zuletzt gespeicherten Events
* @return Liste von neueren Events
*/
public List<Event> getNewEvents(Long status) {
List<Long> groupIdsThatChanged = eventStore.findNewEventSinceStatus(status);
@ -83,9 +83,9 @@ public class EventService {
}
/**
* Erzeugt aus einer Liste von eventDTOs eine Liste von Events
* Erzeugt aus einer Liste von eventDTOs eine Liste von Events.
*
* @param eventDTOS
* @param eventDTOS Liste von DTOs
* @return Liste von Events
*/
public List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS) {
@ -102,12 +102,12 @@ public class EventService {
}
/**
* Sichert eine Liste von Event Objekten mithilfe der Methode saveEvent(Event event)
* Sichert eine Liste von Event Objekten mithilfe der Methode saveEvent(Event event).
*
* @param createGroupEvents Liste von Event Objekten
* @param eventList Liste von Event Objekten
*/
public void saveEventList(List<Event> createGroupEvents) {
for (Event event : createGroupEvents) {
public void saveEventList(List<Event> eventList) {
for (Event event : eventList) {
saveEvent(event);
}
}

View File

@ -28,13 +28,13 @@ public class GroupService {
* Sucht in der DB alle Zeilen raus welche eine der Gruppen_ids hat.
* Wandelt die Zeilen in Events um und gibt davon eine Liste zurück.
*
* @param group_ids
* @return
* @param groupIds Liste an IDs
* @return Liste an Events
*/
public List<Event> getGroupEvents(List<Long> group_ids) {
public List<Event> getGroupEvents(List<Long> groupIds) {
List<EventDTO> eventDTOS = new ArrayList<>();
for (Long group_id : group_ids) {
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(group_id));
for (Long groupId : groupIds) {
eventDTOS.addAll(eventRepository.findEventDTOByGroup_id(groupId));
}
return eventService.translateEventDTOs(eventDTOS);
}
@ -43,67 +43,58 @@ public class GroupService {
* Erzeugt eine neue Map wo Gruppen aus den Events erzeugt und den Gruppen_ids zugeordnet werden.
* Die Gruppen werden als Liste zurückgegeben
*
* @param events
* @return
* @throws EventException
* @param events Liste an Events
* @return Liste an Projizierten Gruppen
* @throws EventException Projektionsfehler
*/
public List<Group> projectEventList(List<Event> events) throws EventException {
Map<Long, Group> groupMap = new HashMap<>();
for (Event event : events) {
Group group = getOrCreateGroup(groupMap, event.getGroup_id());
Group group = getOrCreateGroup(groupMap, event.getGroupId());
event.apply(group);
}
return new ArrayList<>(groupMap.values());
}
/**
* guckt in der Map anhand der Id nach ob die Gruppe schon in der Map vorhanden ist, wenn nicht wird eine neue
* Gruppe erzeugt
*
* @param groups
* @param group_id
* @return
*/
private Group getOrCreateGroup(Map<Long, Group> groups, long group_id) {
if (!groups.containsKey(group_id)) {
groups.put(group_id, new Group());
private Group getOrCreateGroup(Map<Long, Group> groups, long groupId) {
if (!groups.containsKey(groupId)) {
groups.put(groupId, new Group());
}
return groups.get(group_id);
return groups.get(groupId);
}
private List<Long> removeUserGroups(List<Long> group_ids, List<Long> user_groups) {
for (Long group_id : user_groups) {
group_ids.remove(group_id);
private List<Long> removeUserGroups(List<Long> groupIds, List<Long> userGroups) {
for (Long groupId : userGroups) {
groupIds.remove(groupId);
}
return group_ids;
return groupIds;
}
/**
* sucht alle Zeilen in der DB wo die Visibility true ist und entfernt alle Gruppen des Users.
* Erstellt eine Liste aus Gruppen.
* Sucht alle Zeilen in der DB mit visibility=true.
* Erstellt eine Liste aus öffentlichen Gruppen (ohen bereits beigetretenen Gruppen).
*
* @return
* @throws EventException
* @return Liste von projizierten Gruppen
* @throws EventException Projektionsfehler
*/
public List<Group> getAllGroupWithVisibilityPublic(String user_id) throws EventException {
List<Long> group_ids = removeUserGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE), eventRepository.findGroup_idsWhereUser_id(user_id));
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(group_ids);
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
List<Long> groupIds = removeUserGroups(eventRepository.findGroup_idsWhereVisibility(Boolean.TRUE), eventRepository.findGroup_idsWhereUser_id(userId));
List<EventDTO> eventDTOS = eventRepository.findAllEventsOfGroups(groupIds);
List<Event> events = eventService.translateEventDTOs(eventDTOS);
List<Group> groups = projectEventList(events);
return groups;
return projectEventList(events);
}
/**
* Filtert alle öffentliche Gruppen nach dem suchbegriff und gibt diese als Liste von Gruppen zurück.
* Groß und kleinschreibung wird beachtet.
* Filtert alle öffentliche Gruppen nach dem Suchbegriff und gibt diese als Liste von Gruppen zurück.
* Groß und Kleinschreibung wird nicht beachtet.
*
* @param search
* @return
* @throws EventException
* @param search Der Suchstring
* @return Liste von projizierten Gruppen
* @throws EventException Projektionsfehler
*/
public List<Group> findGroupWith(String search, Account account) throws EventException {
List<Group> groups = new ArrayList<>();

View File

@ -19,8 +19,8 @@ public class InviteLinkRepositoryService {
return inviteLinkRepository.findGroupIdByLink(link);
}
public void saveInvite(Long group_id, UUID link) {
inviteLinkRepository.save(new InviteLinkDTO(null, group_id, link.toString()));
public void saveInvite(Long groupId, UUID link) {
inviteLinkRepository.save(new InviteLinkDTO(null, groupId, link.toString()));
}
}

View File

@ -16,7 +16,7 @@ public class JsonService {
*
* @param event Java-Event-Repräsentation
* @return JSON-Event-Payload als String
* @throws JsonProcessingException
* @throws JsonProcessingException Bei JSON Fehler
*/
public String serializeEvent(Event event) throws JsonProcessingException {
@ -29,7 +29,7 @@ public class JsonService {
*
* @param json JSON-Event-Payload als String
* @return Java-Event-Repräsentation
* @throws JsonProcessingException
* @throws JsonProcessingException Bei JSON Fehler
*/
public Event deserializeEvent(String json) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();

View File

@ -25,8 +25,8 @@ public class UserService {
//Test nötig??
public List<Group> getUserGroups(User user) throws EventException {
List<Long> group_ids = eventRepository.findGroup_idsWhereUser_id(user.getUser_id());
List<Event> events = groupService.getGroupEvents(group_ids);
List<Long> groupIds = eventRepository.findGroup_idsWhereUser_id(user.getId());
List<Event> events = groupService.getGroupEvents(groupIds);
List<Group> groups = groupService.projectEventList(events);
List<Group> newGroups = new ArrayList<>();
for (Group group : groups) {
@ -37,10 +37,10 @@ public class UserService {
return newGroups;
}
public Group getGroupById(Long group_id) throws EventException {
List<Long> group_ids = new ArrayList<>();
group_ids.add(group_id);
List<Event> events = groupService.getGroupEvents(group_ids);
public Group getGroupById(Long groupId) throws EventException {
List<Long> groupIds = new ArrayList<>();
groupIds.add(groupId);
List<Event> events = groupService.getGroupEvents(groupIds);
return groupService.projectEventList(events).get(0);
}
}

View File

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}">
<html lang="en"
th:replace="~{mopslayout :: html(name='Gruppenbildung', headcontent=~{:: headcontent}, navigation=~{:: navigation}, bodycontent=~{:: bodycontent})}"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>Gruppendetails</title>
@ -13,16 +14,16 @@
<nav class="navigation navigation-secondary" is="mops-navigation" th:fragment="navigation">
<ul>
<li class="active">
<a th:href="@{/gruppen2}" href="/">Gruppen</a>
<a href="/" th:href="@{/gruppen2}">Gruppen</a>
</li>
<li>
<a th:href="@{/gruppen2/createGroup}" href="/createGroup">Erstellen</a>
<a href="/createGroup" th:href="@{/gruppen2/createGroup}">Erstellen</a>
</li>
<li>
<a th:href="@{/gruppen2/findGroup}" href="/findGroup">Suche</a>
<a href="/findGroup" th:href="@{/gruppen2/findGroup}">Suche</a>
</li>
<li th:if="${account.getRoles().contains('orga')}">
<a th:href="@{/gruppen2/createLecture}" href="/createLecture">Veranstaltung</a>
<a href="/createLecture" th:href="@{/gruppen2/createLecture}">Veranstaltung</a>
</li>
</ul>
</nav>
@ -46,12 +47,12 @@
<p style="overflow-wrap: break-word" th:text="${group.getDescription()}"></p>
</div>
<br>
<div class="text-right btn-toolbar" style="float: right" role="toolbar">
<div class="text-right btn-toolbar" role="toolbar" style="float: right">
<button class="btn btn-primary"
style="background: dodgerblue; border: none; margin: 5px">
<a th:href="@{/gruppen2}" style="color: white">Zurück</a>
<a style="color: white" th:href="@{/gruppen2}">Zurück</a>
</button>
<form method="post" action="/gruppen2/leaveGroup">
<form action="/gruppen2/leaveGroup" method="post">
<button class="btn btn-danger" style="border-style: none; margin: 5px"
th:name="group_id" th:value="${group.getId()}"
type="submit">Gruppe verlassen
@ -62,7 +63,7 @@
<div class="col-3" style="white-space: nowrap">
<div style="display: inline-block; margin: 0">
<h2>Mitglieder</h2>
<div th:if='${group.getRoles().get(user.getUser_id()) == admin}'>
<div th:if="${group.getRoles().get(user.getId()) == admin}">
<form method="get"
th:action="@{/gruppen2/details/members/{id}(id=${group.getId()})}">
<button class="btn btn-secondary"

View File

@ -5,13 +5,12 @@ import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class })
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = ImportOption.DoNotIncludeTests.class)
public class ControllerTest {
@ArchTest

View File

@ -8,7 +8,7 @@ import com.tngtech.archunit.lang.ArchRule;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class })
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = ImportOption.DoNotIncludeTests.class)
public class DomainTest {
@ArchTest

View File

@ -6,7 +6,7 @@ import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.library.Architectures;
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class })
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = ImportOption.DoNotIncludeTests.class)
public class LayeredArchitectureTest {
private static Architectures.LayeredArchitecture layeredArchitecture = Architectures

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Repository;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class })
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = ImportOption.DoNotIncludeTests.class)
public class RepositoryTest {
@ArchTest

View File

@ -8,7 +8,7 @@ import org.springframework.stereotype.Service;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = { ImportOption.DoNotIncludeTests.class })
@AnalyzeClasses(packages = "mops.gruppen2", importOptions = ImportOption.DoNotIncludeTests.class)
public class ServiceTest {
@ArchTest

View File

@ -1,8 +1,18 @@
package mops.gruppen2.builder;
import com.github.javafaker.Faker;
import mops.gruppen2.domain.*;
import mops.gruppen2.domain.event.*;
import mops.gruppen2.domain.Group;
import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Role;
import mops.gruppen2.domain.User;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.AddUserEvent;
import mops.gruppen2.domain.event.CreateGroupEvent;
import mops.gruppen2.domain.event.DeleteUserEvent;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.domain.event.UpdateGroupDescriptionEvent;
import mops.gruppen2.domain.event.UpdateGroupTitleEvent;
import mops.gruppen2.domain.event.UpdateRoleEvent;
import java.util.ArrayList;
import java.util.List;
@ -10,9 +20,9 @@ import java.util.List;
public class EventBuilder {
/**
* Generiert ein EventLog mit mehreren Gruppen nud Usern
* Generiert ein EventLog mit mehreren Gruppen nud Usern.
*
* @param count Gruppenanzahl
* @param count Gruppenanzahl
* @param membercount Gesamte Mitgliederanzahl
* @return
*/
@ -26,23 +36,23 @@ public class EventBuilder {
return eventList;
}
public static List<Event> completeGroup(long group_id, int membercount) {
public static List<Event> completeGroup(long groupId, int membercount) {
List<Event> eventList = new ArrayList<>();
eventList.add(EventBuilder.createGroupEvent(group_id));
eventList.add(EventBuilder.updateGroupTitleEvent(group_id));
eventList.add(EventBuilder.updateGroupDescriptionEvent(group_id));
eventList.add(EventBuilder.createGroupEvent(groupId));
eventList.add(EventBuilder.updateGroupTitleEvent(groupId));
eventList.add(EventBuilder.updateGroupDescriptionEvent(groupId));
eventList.addAll(EventBuilder.addUserEvents(membercount, group_id));
eventList.addAll(EventBuilder.addUserEvents(membercount, groupId));
return eventList;
}
public static CreateGroupEvent createGroupEvent(long group_id) {
public static CreateGroupEvent createGroupEvent(long groupId) {
Faker faker = new Faker();
return new CreateGroupEvent(
group_id,
groupId,
faker.random().hex(),
null,
GroupType.SIMPLE,
@ -51,10 +61,10 @@ public class EventBuilder {
}
/**
* Generiert mehrere CreateGroupEvents, 1 <= group_id <= count
* Generiert mehrere CreateGroupEvents, 1 <= groupId <= count.
*
* @param count Anzahl der verschiedenen Gruppen.
* @return
* @param count Anzahl der verschiedenen Gruppen
* @return Eventliste
*/
public static List<CreateGroupEvent> createGroupEvents(int count) {
List<CreateGroupEvent> eventList = new ArrayList<>();
@ -66,15 +76,15 @@ public class EventBuilder {
return eventList;
}
public static AddUserEvent addUserEvent(long group_id, String user_id) {
public static AddUserEvent addUserEvent(long groupId, String userId) {
Faker faker = new Faker();
String firstname = faker.name().firstName();
String lastname = faker.name().lastName();
return new AddUserEvent(
group_id,
user_id,
groupId,
userId,
firstname,
lastname,
firstname + "." + lastname + "@mail.de"
@ -82,73 +92,69 @@ public class EventBuilder {
}
/**
* Generiert mehrere AddUserEvents für eine Gruppe, 1 <= user_id <= count
* Generiert mehrere AddUserEvents für eine Gruppe, 1 <= user_id <= count.
*
* @param count
* @param group_id
* @return
* @param count Anzahl der Mitglieder
* @param groupId Gruppe, zu welcher geaddet wird
* @return Eventliste
*/
public static List<Event> addUserEvents(int count, long group_id) {
public static List<Event> addUserEvents(int count, long groupId) {
List<Event> eventList = new ArrayList<>();
for (int i = 1; i <= count; i++) {
eventList.add(EventBuilder.addUserEvent(group_id, "" + i));
eventList.add(EventBuilder.addUserEvent(groupId, "" + i));
}
return eventList;
}
public static DeleteUserEvent deleteUserEvent(long group_id, String user_id) {
Faker faker = new Faker();
public static DeleteUserEvent deleteUserEvent(long groupId, String userId) {
return new DeleteUserEvent(
group_id,
user_id
groupId,
userId
);
}
/**
* Erzeugt mehrere DeleteUserEvents, sodass eine Gruppe komplett geleert wird
* Erzeugt mehrere DeleteUserEvents, sodass eine Gruppe komplett geleert wird.
*
* @param group Gruppe welche geleert wird
* @return
* @return Eventliste
*/
public static List<DeleteUserEvent> deleteUserEvents(Group group) {
List<DeleteUserEvent> eventList = new ArrayList<>();
for (User user : group.getMembers()) {
eventList.add(EventBuilder.deleteUserEvent(group.getId(), user.getUser_id()));
eventList.add(EventBuilder.deleteUserEvent(group.getId(), user.getId()));
}
return eventList;
}
public static UpdateGroupDescriptionEvent updateGroupDescriptionEvent(long group_id) {
public static UpdateGroupDescriptionEvent updateGroupDescriptionEvent(long groupId) {
Faker faker = new Faker();
return new UpdateGroupDescriptionEvent(
group_id,
groupId,
faker.random().hex(),
faker.leagueOfLegends().quote()
);
}
public static UpdateGroupTitleEvent updateGroupTitleEvent(long group_id) {
public static UpdateGroupTitleEvent updateGroupTitleEvent(long groupId) {
Faker faker = new Faker();
return new UpdateGroupTitleEvent(
group_id,
groupId,
faker.random().hex(),
faker.leagueOfLegends().champion()
);
}
public static UpdateRoleEvent randomUpdateRoleEvent(long group_id, String user_id, Role role) {
Faker faker = new Faker();
public static UpdateRoleEvent randomUpdateRoleEvent(long groupId, String userId, Role role) {
return new UpdateRoleEvent(
group_id,
user_id,
groupId,
userId,
role
);
}

View File

@ -12,21 +12,18 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class AddUserEventTest {
@Test
public void userAllreadyExistExeption() throws EventException {
void userAlreadyExistExeption() throws EventException {
Group group = new Group();
User user = new User("user1","Stein", "Speck", "@sdasd");
User user = new User("user1", "Stein", "Speck", "@sdasd");
group.getMembers().add(user);
Event event1 = new AddUserEvent(4L, "user2", "Rock", "Roll", "and");
event1.apply(group);
Event event2 = new AddUserEvent(4L, "user1", "Rock", "Roll", "and");
assertThrows(UserAlreadyExistsException.class, ()->
assertThrows(UserAlreadyExistsException.class, () ->
event2.apply(group)
);
);
assertThat(group.getMembers().size()).isEqualTo(2);
}

View File

@ -15,19 +15,14 @@ class DeleteUserEventTest {
@Test
void applyDeleteUser() throws EventException {
Group group = new Group();
User user = new User("user1","Stein", "Speck", "@sdasd");
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");
User user2 = new User("user2", "Rock", "Roll", "and");
group.getMembers().add(user2);
group.getRoles().put("user2", MEMBER);
Event event = new DeleteUserEvent(1L, "user1");
event.apply(group);
assertThat(group.getMembers().size()).isEqualTo(1);
@ -38,18 +33,14 @@ class DeleteUserEventTest {
@Test
void userDoesNotExistExeption() {
Group group = new Group();
User user = new User("user1","Stein", "Speck", "@sdasd");
User user = new User("user1", "Stein", "Speck", "@sdasd");
group.getMembers().add(user);
group.getRoles().put("user1", MEMBER);
Event event = new DeleteUserEvent(17L,"user5");
assertThrows(UserNotFoundException.class, ()->
Event event = new DeleteUserEvent(17L, "user5");
assertThrows(UserNotFoundException.class, () ->
event.apply(group)
);
assertThat(group.getMembers().size()).isEqualTo(1);
}
}

View File

@ -21,24 +21,25 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
class EventServiceTest {
private EventRepository eventRepository;
private EventService eventService;
private EventRepository eventRepositoryMock = mock(EventRepository.class);
@BeforeEach
void setUp() {
eventService = new EventService(mock(JsonService.class), eventRepositoryMock);
eventRepository = mock(EventRepository.class);
eventService = new EventService(mock(JsonService.class), eventRepository);
}
@Test
void getMaxID() {
when(eventRepositoryMock.getHighesEvent_ID()).thenReturn(42L);
when(eventRepository.getHighesEvent_ID()).thenReturn(42L);
assertEquals(eventService.getMaxEvent_id(), 42L);
}
@Test
void checkGroupReturnNextValue() {
when(eventRepositoryMock.getMaxGroupID()).thenReturn(2L);
when(eventRepository.getMaxGroupID()).thenReturn(2L);
assertEquals(eventService.checkGroup(), 3L);
}
@ -46,7 +47,7 @@ class EventServiceTest {
@Test
void checkGroupReturnOneIfDBIsEmpty() {
List<EventDTO> eventDTOS = new ArrayList<>();
when(eventRepositoryMock.findAll()).thenReturn(eventDTOS);
when(eventRepository.findAll()).thenReturn(eventDTOS);
assertEquals(eventService.checkGroup(), 1);
}

View File

@ -5,12 +5,9 @@ import mops.gruppen2.domain.GroupType;
import mops.gruppen2.domain.Visibility;
import mops.gruppen2.domain.event.AddUserEvent;
import mops.gruppen2.domain.event.CreateGroupEvent;
import mops.gruppen2.domain.event.DeleteGroupEvent;
import mops.gruppen2.domain.event.Event;
import mops.gruppen2.repository.EventRepository;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
@ -20,23 +17,23 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
class GroupServiceTest {
GroupService groupService;
EventRepository eventRepository;
private GroupService groupService;
@BeforeEach
public void setUp() {
groupService = new GroupService(mock(EventService.class), eventRepository);
void setUp() {
groupService = new GroupService(mock(EventService.class), mock(EventRepository.class));
}
@Test
void rightClassForSucsessfulGroup() throws Exception {
void rightClassForSuccessfulGroup() throws Exception {
List<Event> eventList = new ArrayList<>();
eventList.add(new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE));
eventList.add(new AddUserEvent(1L, "Ulli", "Ulli", "Honnis", "FC@B.de"));
assertThat(groupService.projectEventList(eventList).get(0)).isInstanceOf(Group.class);
List<Group> groups = groupService.projectEventList(eventList);
assertThat(groups.get(0)).isInstanceOf(Group.class);
}
}
}