destroygroupevent test
This commit is contained in:
@ -20,7 +20,7 @@ public class DestroyGroupEvent extends Event {
|
||||
|
||||
@Override
|
||||
protected void updateCache(GroupCache cache, Group group) {
|
||||
cache.groupsRemove(groupid);
|
||||
cache.groupsRemove(groupid, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,15 +77,9 @@ public abstract class Event {
|
||||
}
|
||||
|
||||
checkGroupIdMatch(group.getId());
|
||||
group.updateVersion(version);
|
||||
applyEvent(group);
|
||||
updateCache(cache, group); // Update erst nachdem apply keine exception geworfen hat
|
||||
|
||||
// Danach hat die Gruppe nur Nullfelder
|
||||
if (this instanceof DestroyGroupEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
group.updateVersion(version);
|
||||
}
|
||||
|
||||
public void apply(Group group) throws EventException {
|
||||
@ -98,6 +92,7 @@ public abstract class Event {
|
||||
checkGroupIdMatch(group.getId());
|
||||
group.updateVersion(version);
|
||||
applyEvent(group);
|
||||
|
||||
}
|
||||
|
||||
private void checkGroupIdMatch(UUID groupid) throws IdMismatchException {
|
||||
|
@ -58,7 +58,7 @@ public class Group {
|
||||
private GroupMeta meta = GroupMeta.EMPTY();
|
||||
|
||||
//TODO: UI set + use for options
|
||||
private GroupOptions options = GroupOptions.DEFAULT();
|
||||
private final GroupOptions options = GroupOptions.DEFAULT();
|
||||
|
||||
// Inhalt
|
||||
private Title title = Title.EMPTY();
|
||||
@ -71,7 +71,7 @@ public class Group {
|
||||
// Integrationen
|
||||
|
||||
// Teilnehmer
|
||||
private Map<String, Membership> memberships = new HashMap<>();
|
||||
private final Map<String, Membership> memberships = new HashMap<>();
|
||||
|
||||
|
||||
// ####################################### Members ###########################################
|
||||
@ -318,7 +318,9 @@ public class Group {
|
||||
}
|
||||
|
||||
groupid = null;
|
||||
type = null;
|
||||
// Wenn man alles null setzt hat der cache mehr arbeit, weil dieser erst nach der löschung
|
||||
// geupdated wird und sich link und mitgliedschaften selber heraussuchen muss
|
||||
/*type = null;
|
||||
parent = null;
|
||||
limit = null;
|
||||
link = null;
|
||||
@ -327,7 +329,7 @@ public class Group {
|
||||
title = null;
|
||||
description = null;
|
||||
body = null;
|
||||
memberships = null;
|
||||
memberships = null;*/
|
||||
}
|
||||
|
||||
public String format() {
|
||||
|
@ -159,12 +159,15 @@ public class GroupCache {
|
||||
groups.put(groupid, group);
|
||||
}
|
||||
|
||||
public void groupsRemove(UUID groupid) {
|
||||
public void groupsRemove(UUID groupid, Group group) {
|
||||
if (!groups.containsKey(groupid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
groups.remove(groupid);
|
||||
links.remove(group.getLink());
|
||||
group.getMembers().forEach(user -> users.get(user.getId()).removeIf(usergroup -> !usergroup.exists()));
|
||||
types.get(group.getType()).removeIf(typegroup -> !typegroup.exists());
|
||||
}
|
||||
|
||||
public void linksPut(String link, Group group) {
|
||||
|
@ -58,7 +58,7 @@ class AddMemberEventTest {
|
||||
void apply_userExists() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().limit(2).build();
|
||||
Event add = new AddMemberEvent(TestHelper.uuid(1), "TEST", "TEST", new User("TEST"));
|
||||
add.init(3);
|
||||
add.init(5);
|
||||
|
||||
assertThatThrownBy(() -> add.apply(group, cache))
|
||||
.isInstanceOf(UserExistsException.class);
|
||||
@ -68,7 +68,7 @@ class AddMemberEventTest {
|
||||
void apply_groupFull() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().build();
|
||||
Event add = new AddMemberEvent(TestHelper.uuid(1), "TEST", "PETER", new User("PETER"));
|
||||
add.init(2);
|
||||
add.init(4);
|
||||
|
||||
assertThatThrownBy(() -> add.apply(group, cache))
|
||||
.isInstanceOf(GroupFullException.class);
|
||||
|
@ -1,5 +1,45 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.domain.model.group.Group;
|
||||
import mops.gruppen2.domain.service.EventStoreService;
|
||||
import mops.gruppen2.infrastructure.GroupCache;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static mops.gruppen2.TestHelper.uuid;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class CreateGroupEventTest {
|
||||
|
||||
GroupCache cache;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
cache = new GroupCache(mock(EventStoreService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply() {
|
||||
Group group = Group.EMPTY();
|
||||
Event add = new CreateGroupEvent(uuid(1), "TEST", LocalDateTime.now());
|
||||
add.init(1);
|
||||
|
||||
assertThat(group.exists()).isFalse();
|
||||
add.apply(group);
|
||||
assertThat(group.exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply_cache() {
|
||||
Group group = Group.EMPTY();
|
||||
Event add = new CreateGroupEvent(uuid(1), "TEST", LocalDateTime.now());
|
||||
add.init(1);
|
||||
|
||||
add.apply(group, cache);
|
||||
assertThat(group.exists()).isTrue();
|
||||
assertThat(cache.groups()).hasSize(1);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,110 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.GroupBuilder;
|
||||
import mops.gruppen2.domain.exception.NoAccessException;
|
||||
import mops.gruppen2.domain.model.group.Group;
|
||||
import mops.gruppen2.domain.service.EventStoreService;
|
||||
import mops.gruppen2.infrastructure.GroupCache;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestHelper.uuid;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class DestroyGroupEventTest {
|
||||
|
||||
GroupCache cache;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
cache = new GroupCache(mock(EventStoreService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().build();
|
||||
Event destroy = new DestroyGroupEvent(uuid(1), "TEST");
|
||||
destroy.init(4);
|
||||
|
||||
assertThat(group.exists()).isTrue();
|
||||
destroy.apply(group);
|
||||
assertThat(group.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply_noadmin() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().limit(3).add("PETER").build();
|
||||
Event destroy = new DestroyGroupEvent(uuid(1), "PETER");
|
||||
destroy.init(6);
|
||||
|
||||
assertThatThrownBy(() -> destroy.apply(group))
|
||||
.isInstanceOf(NoAccessException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply_noadmin_empty() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().build();
|
||||
Event destroy = new DestroyGroupEvent(uuid(1), "PETER");
|
||||
destroy.init(2);
|
||||
|
||||
destroy.apply(group);
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply_cache_private() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().privat().build();
|
||||
Event destroy = new DestroyGroupEvent(uuid(1), "TEST");
|
||||
destroy.init(5);
|
||||
|
||||
assertThat(cache.groups()).hasSize(1);
|
||||
assertThat(cache.userGroups("TEST")).hasSize(1);
|
||||
assertThat(cache.privates()).hasSize(1);
|
||||
destroy.apply(group, cache);
|
||||
assertThat(cache.groups()).isEmpty();
|
||||
assertThat(cache.userGroups("TEST")).isEmpty();
|
||||
assertThat(cache.privates()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply_cache_public() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().publik().build();
|
||||
Event destroy = new DestroyGroupEvent(uuid(1), "TEST");
|
||||
destroy.init(5);
|
||||
|
||||
assertThat(cache.publics()).hasSize(1);
|
||||
destroy.apply(group, cache);
|
||||
assertThat(cache.publics()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply_cache_lecture() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().lecture().build();
|
||||
Event destroy = new DestroyGroupEvent(uuid(1), "TEST");
|
||||
destroy.init(5);
|
||||
|
||||
assertThat(cache.lectures()).hasSize(1);
|
||||
destroy.apply(group, cache);
|
||||
assertThat(cache.lectures()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply_cache_multipleUsers() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().privat().limit(5).add("A").add("B").add("C").add("D").build();
|
||||
Event destroy = new DestroyGroupEvent(uuid(1), "TEST");
|
||||
destroy.init(10);
|
||||
|
||||
assertThat(cache.userGroups("TEST")).hasSize(1);
|
||||
assertThat(cache.userGroups("A")).hasSize(1);
|
||||
assertThat(cache.userGroups("B")).hasSize(1);
|
||||
assertThat(cache.userGroups("C")).hasSize(1);
|
||||
assertThat(cache.userGroups("D")).hasSize(1);
|
||||
destroy.apply(group, cache);
|
||||
assertThat(cache.userGroups("TEST")).hasSize(0);
|
||||
assertThat(cache.userGroups("A")).hasSize(0);
|
||||
assertThat(cache.userGroups("B")).hasSize(0);
|
||||
assertThat(cache.userGroups("C")).hasSize(0);
|
||||
assertThat(cache.userGroups("D")).hasSize(0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user