1

refactor tests for new events

This commit is contained in:
killerber4t
2020-03-11 16:10:58 +01:00
parent b7b4485d03
commit 846eee9606
8 changed files with 69 additions and 26 deletions

View File

@ -1,5 +1,11 @@
package mops.gruppen2;
import lombok.Setter;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.Group;
import mops.gruppen2.service.EventService;
import mops.gruppen2.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@ -12,10 +18,17 @@ import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Collections;
import java.util.List;
@SpringBootApplication
@EnableSwagger2
public class Gruppen2Application {
@Autowired
private GroupService groupService;
@Autowired
private EventService eventService;
public static void main(String[] args) {
SpringApplication.run(Gruppen2Application.class, args);
}

View File

@ -0,0 +1,26 @@
package mops.gruppen2;
import mops.gruppen2.domain.Exceptions.EventException;
import mops.gruppen2.domain.Group;
import mops.gruppen2.service.EventService;
import mops.gruppen2.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
@Configuration
public class Gruppen2Config {
@Autowired
GroupService groupService;
@Autowired
EventService eventService;
@Bean
public List<Group> groups() throws EventException {
return groupService.projectEventList(eventService.findAllEvents());
}
}

View File

@ -1,6 +1,10 @@
package mops.gruppen2.controller;
import mops.gruppen2.Gruppen2Application;
import mops.gruppen2.Gruppen2Config;
import mops.gruppen2.domain.Group;
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.security.Account;
@ -8,6 +12,7 @@ import mops.gruppen2.service.EventService;
import mops.gruppen2.service.GroupService;
import mops.gruppen2.service.KeyCloakService;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@ -19,6 +24,9 @@ import javax.swing.*;
@RequestMapping("/gruppen2")
public class Gruppen2Controller {
@Autowired
Gruppen2Config gruppen2Config;
private final KeyCloakService keyCloakService;
private final EventService eventService;
private final GroupService groupService;
@ -65,7 +73,7 @@ public class Gruppen2Controller {
//Refoctor
Account account = keyCloakService.createAccountFromPrincipal(token);
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), account.getName(), title, beschreibung);
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), account.getName(), null ,GroupType.LECTURE, Visibility.PUBLIC);
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
eventService.saveEvent(createGroupEvent);
eventService.saveEvent(addUserEvent);

View File

@ -48,7 +48,7 @@ public class Group extends Aggregate {
throw new UserNotFoundException("Nutzer wurde nicht gefunden!");
}
if (roles.containsKey(user) && event.getNewRole() == Role.STUDENT) {
if (roles.containsKey(user) && event.getNewRole() == Role.MEMBER) {
roles.remove(user);
} else {
roles.put(user, event.getNewRole());

View File

@ -1,5 +1,5 @@
package mops.gruppen2.domain;
public enum Role {
ORGA, ADMIN, STUDENT
ADMIN, MEMBER
}

View File

@ -6,8 +6,7 @@ import lombok.*;
* Entfernt ein einzelnes Mitglied einer Gruppe.
*/
@Getter
public class DeleteUserEvent extends Event {
public class DeleteUserEvent extends Event {
public DeleteUserEvent(Long event_id, Long group_id, String user_id) {
super(event_id, group_id, user_id);
}