1

Added DeleteGroupEvent and GroupDoesNotExistException

This commit is contained in:
Mahgs
2020-03-10 15:09:35 +01:00
parent 3425e1fcec
commit c0d2bbbf7f
8 changed files with 162 additions and 30 deletions

View File

@ -1,5 +1,6 @@
package mops.gruppen2.domain;
import mops.gruppen2.domain.Exceptions.GroupDoesNotExistException;
import mops.gruppen2.domain.Exceptions.UserAlreadyExistsException;
import mops.gruppen2.domain.Exceptions.UserNotFoundException;
import mops.gruppen2.domain.event.*;
@ -12,7 +13,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class GroupTest {
@BeforeEach
public void setUp(){
public void setUp() {
}
@ -21,8 +22,8 @@ class GroupTest {
}
@Test
void createSingleGroup() throws Exception{
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,2L, "asd", "hello", "foo");
void createSingleGroup() throws Exception {
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 2L, "asd", "hello", "foo");
Group group = new Group();
@ -36,31 +37,31 @@ class GroupTest {
// Verwendet CreateGroupEvent
@Test
void addSingleUser() throws Exception{
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,1L,"prof1", "hi", "foo");
void addSingleUser() throws Exception {
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 1L, "prof1", "hi", "foo");
Group group = new Group();
group.applyEvent(createGroupEvent);
User user = new User("prof", "jens", "bendi", "hi@gmail.com");
AddUserEvent addUserEvent = new AddUserEvent(1L,1L, user);
AddUserEvent addUserEvent = new AddUserEvent(1L, 1L, user);
group.applyEvent(addUserEvent);
assertThat(group.getMembers().get(0)).isEqualTo(user);
}
@Test
void addExistingUser() throws Exception{
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L,1L,"prof1", "hi", "foo");
void addExistingUser() throws Exception {
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, 1L, "prof1", "hi", "foo");
Group group = new Group();
group.applyEvent(createGroupEvent);
User user1 = new User("prof", "jens", "bendi", "hi@gmail.com");
AddUserEvent addUserEvent1 = new AddUserEvent(2L,1L, user1);
AddUserEvent addUserEvent1 = new AddUserEvent(2L, 1L, user1);
group.applyEvent(addUserEvent1);
User user2 = new User("prof", "olga", "bendi", "hi@gmail.com");
AddUserEvent addUserEvent2 = new AddUserEvent(3L,1L, user2);
Assertions.assertThrows(UserAlreadyExistsException.class, () ->{
AddUserEvent addUserEvent2 = new AddUserEvent(3L, 1L, user2);
Assertions.assertThrows(UserAlreadyExistsException.class, () -> {
group.applyEvent(addUserEvent2);
});
@ -69,7 +70,7 @@ class GroupTest {
}
@Test
void deleteSingleUser() throws Exception{
void deleteSingleUser() throws Exception {
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 2L, "Prof", "Tolle Gruppe", "Tolle Beshreibung");
User user = new User("Prof", "Pro", "fessor", "pro@fessor.de");
AddUserEvent addUserEvent = new AddUserEvent(2L, 2L, user);
@ -84,21 +85,21 @@ class GroupTest {
}
@Test
void deleteUserThatDoesNotExists() throws Exception{
void deleteUserThatDoesNotExists() throws Exception {
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 2L, "Prof", "Tolle Gruppe", "Tolle Beshreibung");
Group group = new Group();
group.applyEvent(createGroupEvent);
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(3L, 2L, "Prof");
Assertions.assertThrows(UserNotFoundException.class, () ->{
Assertions.assertThrows(UserNotFoundException.class, () -> {
group.applyEvent(deleteUserEvent);
});
}
// Verwendet CreateGroupEvent und AddUserEvent
@Test
void updateRoleForExistingUser() throws Exception{
void updateRoleForExistingUser() throws Exception {
// Arrange
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, 1L, "1L", "gruppe1", "Eine Testgruppe");
AddUserEvent addUserEvent = new AddUserEvent(1L, 1L, "5L", "Peter", "Pan", "123@mail.de");
@ -119,20 +120,20 @@ class GroupTest {
}
@Test
void updateRoleForNonExistingUser() throws Exception{
void updateRoleForNonExistingUser() throws Exception {
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, 1L, "1L", "gruppe1", "Eine Testgruppe");
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(345L, 33L , "coolerUser", Role.ADMIN);
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(345L, 33L, "coolerUser", Role.ADMIN);
Group group = new Group();
group.applyEvent(createGroupEvent);
Assertions.assertThrows(UserNotFoundException.class, () ->{
Assertions.assertThrows(UserNotFoundException.class, () -> {
group.applyEvent(updateRoleEvent);
});
}
@Test
void updateTitle() throws Exception{
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,1L,"prof1", "hi", "foo");
void updateTitle() throws Exception {
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 1L, "prof1", "hi", "foo");
Group group = new Group();
group.applyEvent(createGroupEvent);
@ -143,8 +144,8 @@ class GroupTest {
}
@Test
void updateBeschreibung() throws Exception{
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,1L,"prof1", "hi", "foo");
void updateBeschreibung() throws Exception {
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 1L, "prof1", "hi", "foo");
Group group = new Group();
group.applyEvent(createGroupEvent);
@ -153,4 +154,17 @@ class GroupTest {
assertThat(group.getDescription()).isEqualTo("Tolle Beschreibung");
}
@Test
void deleteGroup() throws Exception {
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 1L, "prof1", "hi", "foo");
Group group = new Group();
group.applyEvent(createGroupEvent);
DeleteGroupEvent deleteGroupEvent = new DeleteGroupEvent(44, 1, "loescher78");
group.applyEvent(deleteGroupEvent);
assertThat(group.id).isEqualTo(-1L);
}
}