last tests
This commit is contained in:
@ -52,6 +52,7 @@ public abstract class Event {
|
||||
@JsonProperty("date")
|
||||
protected LocalDateTime date;
|
||||
|
||||
//TODO: Eigentlich sollte die Gruppe aus dem Cache genommen werden, nicht übergeben
|
||||
public Event(UUID groupid, String exec, String target) {
|
||||
this.groupid = groupid;
|
||||
this.exec = exec;
|
||||
|
@ -3,6 +3,7 @@ package mops.gruppen2.domain.event;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Value;
|
||||
import lombok.experimental.NonFinal;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
import mops.gruppen2.domain.model.group.Group;
|
||||
@ -20,6 +21,12 @@ public class SetTypeEvent extends Event {
|
||||
@JsonProperty("type")
|
||||
Type type;
|
||||
|
||||
//TODO: blöder hack, das soll eigentlich anders gehen
|
||||
// Problem ist, dass die Gruppe vor dem Cache verändert wird, also kann der cache den alten Typ
|
||||
// nicht mehr aus der Gruppe holen
|
||||
@NonFinal
|
||||
Type oldType;
|
||||
|
||||
public SetTypeEvent(UUID groupId, String exec, @Valid Type type) {
|
||||
super(groupId, exec, null);
|
||||
|
||||
@ -28,12 +35,13 @@ public class SetTypeEvent extends Event {
|
||||
|
||||
@Override
|
||||
protected void updateCache(GroupCache cache, Group group) {
|
||||
cache.typesRemove(group);
|
||||
cache.typesRemove(oldType, group);
|
||||
cache.typesPut(type, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyEvent(Group group) throws EventException {
|
||||
oldType = group.getType();
|
||||
group.setType(exec, type);
|
||||
}
|
||||
|
||||
|
@ -198,11 +198,11 @@ public class GroupCache {
|
||||
types.get(type).add(group);
|
||||
}
|
||||
|
||||
public void typesRemove(Group group) {
|
||||
if (!types.containsKey(group.getType())) {
|
||||
public void typesRemove(Type type, Group group) {
|
||||
if (!types.containsKey(type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
types.get(group.getType()).remove(group);
|
||||
types.get(type).remove(group);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,44 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.GroupBuilder;
|
||||
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.mockito.Mockito.mock;
|
||||
|
||||
class KickMemberEventTest {
|
||||
|
||||
GroupCache cache;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
cache = new GroupCache(mock(EventStoreService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().build();
|
||||
Event kick = new KickMemberEvent(uuid(1), "TEST", "TEST");
|
||||
kick.init(4);
|
||||
|
||||
assertThat(group.size()).isOne();
|
||||
kick.apply(group);
|
||||
assertThat(group.size()).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply_cache() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().build();
|
||||
Event kick = new KickMemberEvent(uuid(1), "TEST", "TEST");
|
||||
kick.init(4);
|
||||
|
||||
assertThat(cache.userGroups("TEST")).hasSize(1);
|
||||
kick.apply(group, cache);
|
||||
assertThat(cache.userGroups("TEST")).hasSize(0);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
class SetDescriptionEventTest {
|
||||
|
||||
}
|
@ -1,5 +1,44 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.GroupBuilder;
|
||||
import mops.gruppen2.domain.model.group.Group;
|
||||
import mops.gruppen2.domain.model.group.wrapper.Link;
|
||||
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.mockito.Mockito.mock;
|
||||
|
||||
class SetInviteLinkEventTest {
|
||||
|
||||
GroupCache cache;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
cache = new GroupCache(mock(EventStoreService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().build();
|
||||
Event link = new SetInviteLinkEvent(uuid(1), "TEST", new Link(uuid(2).toString()));
|
||||
link.init(4);
|
||||
|
||||
link.apply(group);
|
||||
assertThat(group.getLink()).isEqualTo(uuid(2).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply_cache() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().build();
|
||||
Event link = new SetInviteLinkEvent(uuid(1), "TEST", new Link(uuid(2).toString()));
|
||||
link.init(4);
|
||||
|
||||
assertThat(cache.group(group.getLink())).isEqualTo(group);
|
||||
link.apply(group, cache);
|
||||
assertThat(cache.group(uuid(2).toString())).isEqualTo(group);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,34 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.GroupBuilder;
|
||||
import mops.gruppen2.domain.exception.BadArgumentException;
|
||||
import mops.gruppen2.domain.model.group.Group;
|
||||
import mops.gruppen2.domain.model.group.wrapper.Limit;
|
||||
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.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class SetLimitEventTest {
|
||||
|
||||
GroupCache cache;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
cache = new GroupCache(mock(EventStoreService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply_tooSmall() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().limit(2).add("PETER").build();
|
||||
Event limit = new SetLimitEvent(uuid(1), "TEST", new Limit(1));
|
||||
limit.init(6);
|
||||
|
||||
assertThatThrownBy(() -> limit.apply(group))
|
||||
.isInstanceOf(BadArgumentException.class);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
class SetParentEventTest {
|
||||
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
class SetTitleEventTest {
|
||||
|
||||
}
|
@ -1,5 +1,36 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.GroupBuilder;
|
||||
import mops.gruppen2.domain.model.group.Group;
|
||||
import mops.gruppen2.domain.model.group.Type;
|
||||
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.mockito.Mockito.mock;
|
||||
|
||||
class SetTypeEventTest {
|
||||
|
||||
GroupCache cache;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
cache = new GroupCache(mock(EventStoreService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void apply_cache() {
|
||||
Group group = GroupBuilder.get(cache, 1).group().testadmin().privat().build();
|
||||
Event type = new SetTypeEvent(uuid(1), "TEST", Type.LECTURE);
|
||||
type.init(5);
|
||||
|
||||
assertThat(cache.privates()).hasSize(1);
|
||||
assertThat(cache.lectures()).isEmpty();
|
||||
type.apply(group, cache);
|
||||
assertThat(cache.lectures()).hasSize(1);
|
||||
assertThat(cache.privates()).isEmpty();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
class UpdateRoleEventTest {
|
||||
|
||||
}
|
Reference in New Issue
Block a user