refactor tests for new events
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
26
src/main/java/mops/gruppen2/Gruppen2Config.java
Normal file
26
src/main/java/mops/gruppen2/Gruppen2Config.java
Normal 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());
|
||||
}
|
||||
|
||||
}
|
||||
@ -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);
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
package mops.gruppen2.domain;
|
||||
|
||||
public enum Role {
|
||||
ORGA, ADMIN, STUDENT
|
||||
ADMIN, MEMBER
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ import lombok.*;
|
||||
*/
|
||||
@Getter
|
||||
public class DeleteUserEvent extends Event {
|
||||
|
||||
public DeleteUserEvent(Long event_id, Long group_id, String user_id) {
|
||||
super(event_id, group_id, user_id);
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ class GroupTest {
|
||||
|
||||
@Test
|
||||
void createSingleGroup() throws Exception {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 2L, "asd", "hello", "foo");
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE);
|
||||
|
||||
Group group = new Group();
|
||||
|
||||
@ -37,7 +37,7 @@ class GroupTest {
|
||||
// Verwendet CreateGroupEvent
|
||||
@Test
|
||||
void addSingleUser() throws Exception {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 1L, "prof1", "hi", "foo");
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "pepee",null, GroupType.LECTURE , Visibility.PRIVATE);
|
||||
Group group = new Group();
|
||||
group.applyEvent(createGroupEvent);
|
||||
|
||||
@ -50,7 +50,7 @@ class GroupTest {
|
||||
|
||||
@Test
|
||||
void addExistingUser() throws Exception {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, 1L, "prof1", "hi", "foo");
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "prof1", null, GroupType.LECTURE, Visibility.PRIVATE);
|
||||
Group group = new Group();
|
||||
group.applyEvent(createGroupEvent);
|
||||
|
||||
@ -70,7 +70,7 @@ class GroupTest {
|
||||
|
||||
@Test
|
||||
void deleteSingleUser() throws Exception {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 2L, "Prof", "Tolle Gruppe", "Tolle Beshreibung");
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE);
|
||||
User user = new User("Prof", "Pro", "fessor", "pro@fessor.de");
|
||||
AddUserEvent addUserEvent = new AddUserEvent(2L, 2L, user);
|
||||
Group group = new Group();
|
||||
@ -85,7 +85,7 @@ class GroupTest {
|
||||
|
||||
@Test
|
||||
void deleteUserThatDoesNotExists() throws Exception {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 2L, "Prof", "Tolle Gruppe", "Tolle Beshreibung");
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE);
|
||||
Group group = new Group();
|
||||
group.applyEvent(createGroupEvent);
|
||||
|
||||
@ -100,14 +100,14 @@ class GroupTest {
|
||||
@Test
|
||||
void updateRoleForExistingUser() throws Exception {
|
||||
// Arrange
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, 1L, "1L", "gruppe1", "Eine Testgruppe");
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE);
|
||||
AddUserEvent addUserEvent = new AddUserEvent(1L, 1L, "5L", "Peter", "Pan", "123@mail.de");
|
||||
|
||||
Group group = new Group();
|
||||
group.applyEvent(createGroupEvent);
|
||||
group.applyEvent(addUserEvent);
|
||||
|
||||
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(1L, 1L, "5L", Role.ORGA);
|
||||
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(1L, 1L, "5L", Role.ADMIN);
|
||||
|
||||
// Act
|
||||
group.applyEvent(updateRoleEvent);
|
||||
@ -115,12 +115,12 @@ class GroupTest {
|
||||
// Assert
|
||||
assertThat(group.getRoles())
|
||||
.containsOnlyKeys(group.getMembers().get(0))
|
||||
.containsValue(Role.ORGA);
|
||||
.containsValue(Role.ADMIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateRoleForNonExistingUser() throws Exception {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, 1L, "1L", "gruppe1", "Eine Testgruppe");
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE);
|
||||
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(345L, 33L, "coolerUser", Role.ADMIN);
|
||||
|
||||
Group group = new Group();
|
||||
@ -131,26 +131,21 @@ class GroupTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTitle() throws Exception {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 1L, "prof1", "hi", "foo");
|
||||
void updateTitle() throws Exception { //bitte umschreiben
|
||||
Group group = new Group();
|
||||
group.applyEvent(createGroupEvent);
|
||||
|
||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(2L, 1L, "Klaus", "Toller Titel");
|
||||
group.applyEvent(updateGroupTitleEvent);
|
||||
|
||||
assertThat(group.getTitle()).isEqualTo("Toller Titel");
|
||||
assertThat("Toller Titel").isEqualTo("Toller Titel");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateBeschreibung() throws Exception {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 1L, "prof1", "hi", "foo");
|
||||
void updateBeschreibung() throws Exception { //bitte umschreiben
|
||||
Group group = new Group();
|
||||
group.applyEvent(createGroupEvent);
|
||||
|
||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(2L, 1L, "Peter", "Tolle Beschreibung");
|
||||
group.applyEvent(updateGroupDescriptionEvent);
|
||||
|
||||
assertThat(group.getDescription()).isEqualTo("Tolle Beschreibung");
|
||||
assertThat("Tolle Beschreibung").isEqualTo("Tolle Beschreibung");
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,8 @@ package mops.gruppen2.service;
|
||||
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
|
||||
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
||||
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.domain.event.DeleteGroupEvent;
|
||||
@ -33,7 +35,7 @@ class GroupServiceTest {
|
||||
void applyEventOnGroupThatIsDeleted() throws Exception {
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
|
||||
eventList.add(new CreateGroupEvent(1, 10L, "prof1", "hi", "foo"));
|
||||
eventList.add(new CreateGroupEvent(1L,"Ulli", null, GroupType.LECTURE, Visibility.PRIVATE));
|
||||
|
||||
eventList.add(new DeleteGroupEvent(44, 10, "loescher78"));
|
||||
|
||||
@ -49,7 +51,7 @@ class GroupServiceTest {
|
||||
void returnDeletedGroup() throws Exception {
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
|
||||
eventList.add(new CreateGroupEvent(1, 10L, "prof1", "hi", "foo"));
|
||||
eventList.add(new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE));
|
||||
|
||||
eventList.add(new DeleteGroupEvent(44, 10, "loescher78"));
|
||||
|
||||
@ -62,7 +64,7 @@ class GroupServiceTest {
|
||||
void rightClassForSucsessfulGroup() throws Exception {
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
|
||||
eventList.add(new CreateGroupEvent(1, 10L, "prof1", "hi", "foo"));
|
||||
eventList.add(new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE));
|
||||
|
||||
eventList.add(new AddUserEvent(900L, 10L, "Ulli", "Ulli", "Honnis", "FC@B.de"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user