refactor tests for new events
This commit is contained in:
@ -1,5 +1,11 @@
|
|||||||
package mops.gruppen2;
|
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.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@ -12,10 +18,17 @@ import springfox.documentation.spring.web.plugins.Docket;
|
|||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableSwagger2
|
@EnableSwagger2
|
||||||
public class Gruppen2Application {
|
public class Gruppen2Application {
|
||||||
|
@Autowired
|
||||||
|
private GroupService groupService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EventService eventService;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Gruppen2Application.class, 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;
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
|
import mops.gruppen2.Gruppen2Application;
|
||||||
|
import mops.gruppen2.Gruppen2Config;
|
||||||
import mops.gruppen2.domain.Group;
|
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.AddUserEvent;
|
||||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
@ -8,6 +12,7 @@ import mops.gruppen2.service.EventService;
|
|||||||
import mops.gruppen2.service.GroupService;
|
import mops.gruppen2.service.GroupService;
|
||||||
import mops.gruppen2.service.KeyCloakService;
|
import mops.gruppen2.service.KeyCloakService;
|
||||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -19,6 +24,9 @@ import javax.swing.*;
|
|||||||
@RequestMapping("/gruppen2")
|
@RequestMapping("/gruppen2")
|
||||||
public class Gruppen2Controller {
|
public class Gruppen2Controller {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
Gruppen2Config gruppen2Config;
|
||||||
|
|
||||||
private final KeyCloakService keyCloakService;
|
private final KeyCloakService keyCloakService;
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
private final GroupService groupService;
|
private final GroupService groupService;
|
||||||
@ -65,7 +73,7 @@ public class Gruppen2Controller {
|
|||||||
|
|
||||||
//Refoctor
|
//Refoctor
|
||||||
Account account = keyCloakService.createAccountFromPrincipal(token);
|
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());
|
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail());
|
||||||
eventService.saveEvent(createGroupEvent);
|
eventService.saveEvent(createGroupEvent);
|
||||||
eventService.saveEvent(addUserEvent);
|
eventService.saveEvent(addUserEvent);
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public class Group extends Aggregate {
|
|||||||
throw new UserNotFoundException("Nutzer wurde nicht gefunden!");
|
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);
|
roles.remove(user);
|
||||||
} else {
|
} else {
|
||||||
roles.put(user, event.getNewRole());
|
roles.put(user, event.getNewRole());
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
package mops.gruppen2.domain;
|
package mops.gruppen2.domain;
|
||||||
|
|
||||||
public enum Role {
|
public enum Role {
|
||||||
ORGA, ADMIN, STUDENT
|
ADMIN, MEMBER
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import lombok.*;
|
|||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public class DeleteUserEvent extends Event {
|
public class DeleteUserEvent extends Event {
|
||||||
|
|
||||||
public DeleteUserEvent(Long event_id, Long group_id, String user_id) {
|
public DeleteUserEvent(Long event_id, Long group_id, String user_id) {
|
||||||
super(event_id, group_id, user_id);
|
super(event_id, group_id, user_id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class GroupTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createSingleGroup() throws Exception {
|
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();
|
Group group = new Group();
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ class GroupTest {
|
|||||||
// Verwendet CreateGroupEvent
|
// Verwendet CreateGroupEvent
|
||||||
@Test
|
@Test
|
||||||
void addSingleUser() throws Exception {
|
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 group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
group.applyEvent(createGroupEvent);
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class GroupTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addExistingUser() throws Exception {
|
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 group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
group.applyEvent(createGroupEvent);
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ class GroupTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteSingleUser() throws Exception {
|
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");
|
User user = new User("Prof", "Pro", "fessor", "pro@fessor.de");
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(2L, 2L, user);
|
AddUserEvent addUserEvent = new AddUserEvent(2L, 2L, user);
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
@ -85,7 +85,7 @@ class GroupTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteUserThatDoesNotExists() throws Exception {
|
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 group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
group.applyEvent(createGroupEvent);
|
||||||
|
|
||||||
@ -100,14 +100,14 @@ class GroupTest {
|
|||||||
@Test
|
@Test
|
||||||
void updateRoleForExistingUser() throws Exception {
|
void updateRoleForExistingUser() throws Exception {
|
||||||
// Arrange
|
// 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");
|
AddUserEvent addUserEvent = new AddUserEvent(1L, 1L, "5L", "Peter", "Pan", "123@mail.de");
|
||||||
|
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
group.applyEvent(createGroupEvent);
|
||||||
group.applyEvent(addUserEvent);
|
group.applyEvent(addUserEvent);
|
||||||
|
|
||||||
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(1L, 1L, "5L", Role.ORGA);
|
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(1L, 1L, "5L", Role.ADMIN);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
group.applyEvent(updateRoleEvent);
|
group.applyEvent(updateRoleEvent);
|
||||||
@ -115,12 +115,12 @@ class GroupTest {
|
|||||||
// Assert
|
// Assert
|
||||||
assertThat(group.getRoles())
|
assertThat(group.getRoles())
|
||||||
.containsOnlyKeys(group.getMembers().get(0))
|
.containsOnlyKeys(group.getMembers().get(0))
|
||||||
.containsValue(Role.ORGA);
|
.containsValue(Role.ADMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateRoleForNonExistingUser() throws Exception {
|
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);
|
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(345L, 33L, "coolerUser", Role.ADMIN);
|
||||||
|
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
@ -131,26 +131,21 @@ class GroupTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateTitle() throws Exception {
|
void updateTitle() throws Exception { //bitte umschreiben
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 1L, "prof1", "hi", "foo");
|
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
|
||||||
|
|
||||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(2L, 1L, "Klaus", "Toller Titel");
|
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(2L, 1L, "Klaus", "Toller Titel");
|
||||||
group.applyEvent(updateGroupTitleEvent);
|
group.applyEvent(updateGroupTitleEvent);
|
||||||
|
|
||||||
assertThat(group.getTitle()).isEqualTo("Toller Titel");
|
assertThat("Toller Titel").isEqualTo("Toller Titel");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateBeschreibung() throws Exception {
|
void updateBeschreibung() throws Exception { //bitte umschreiben
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 1L, "prof1", "hi", "foo");
|
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
|
||||||
|
|
||||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(2L, 1L, "Peter", "Tolle Beschreibung");
|
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(2L, 1L, "Peter", "Tolle Beschreibung");
|
||||||
group.applyEvent(updateGroupDescriptionEvent);
|
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.GroupDoesNotExistException;
|
||||||
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
||||||
import mops.gruppen2.domain.Group;
|
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.AddUserEvent;
|
||||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
import mops.gruppen2.domain.event.DeleteGroupEvent;
|
import mops.gruppen2.domain.event.DeleteGroupEvent;
|
||||||
@ -33,7 +35,7 @@ class GroupServiceTest {
|
|||||||
void applyEventOnGroupThatIsDeleted() throws Exception {
|
void applyEventOnGroupThatIsDeleted() throws Exception {
|
||||||
List<Event> eventList = new ArrayList<>();
|
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"));
|
eventList.add(new DeleteGroupEvent(44, 10, "loescher78"));
|
||||||
|
|
||||||
@ -49,7 +51,7 @@ class GroupServiceTest {
|
|||||||
void returnDeletedGroup() throws Exception {
|
void returnDeletedGroup() throws Exception {
|
||||||
List<Event> eventList = new ArrayList<>();
|
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"));
|
eventList.add(new DeleteGroupEvent(44, 10, "loescher78"));
|
||||||
|
|
||||||
@ -62,7 +64,7 @@ class GroupServiceTest {
|
|||||||
void rightClassForSucsessfulGroup() throws Exception {
|
void rightClassForSucsessfulGroup() throws Exception {
|
||||||
List<Event> eventList = new ArrayList<>();
|
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"));
|
eventList.add(new AddUserEvent(900L, 10L, "Ulli", "Ulli", "Honnis", "FC@B.de"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user