new individual event-tests + removed old comments + removed doubled exception
Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import mops.gruppen2.domain.Group;
|
||||
@ -16,7 +15,6 @@ import java.util.UUID;
|
||||
* Fügt einen einzelnen Nutzer einer Gruppe hinzu.
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor // For Jackson
|
||||
public class AddUserEvent extends Event {
|
||||
|
||||
@ -33,14 +31,14 @@ public class AddUserEvent extends Event {
|
||||
|
||||
@Override
|
||||
protected void applyEvent(Group group) throws EventException {
|
||||
User user = new User(this.userId, this.givenname, this.familyname, this.email);
|
||||
User user = new User(userId, givenname, familyname, email);
|
||||
|
||||
if (group.getMembers().contains(user)) {
|
||||
throw new UserAlreadyExistsException(this.getClass().toString());
|
||||
throw new UserAlreadyExistsException(getClass().toString());
|
||||
}
|
||||
|
||||
if (group.getMembers().size() >= group.getUserMaximum()) {
|
||||
throw new GroupFullException(this.getClass().toString());
|
||||
throw new GroupFullException(getClass().toString());
|
||||
}
|
||||
|
||||
group.getMembers().add(user);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import mops.gruppen2.domain.Group;
|
||||
@ -10,7 +9,6 @@ import mops.gruppen2.domain.Visibility;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor // For Jackson
|
||||
public class CreateGroupEvent extends Event {
|
||||
|
||||
@ -21,18 +19,18 @@ public class CreateGroupEvent extends Event {
|
||||
|
||||
public CreateGroupEvent(UUID groupId, String userId, UUID parent, GroupType type, Visibility visibility, Long userMaximum) {
|
||||
super(groupId, userId);
|
||||
this.groupParent = parent;
|
||||
this.groupType = type;
|
||||
this.groupVisibility = visibility;
|
||||
this.groupUserMaximum = userMaximum;
|
||||
groupParent = parent;
|
||||
groupType = type;
|
||||
groupVisibility = visibility;
|
||||
groupUserMaximum = userMaximum;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyEvent(Group group) {
|
||||
group.setId(this.groupId);
|
||||
group.setParent(this.groupParent);
|
||||
group.setType(this.groupType);
|
||||
group.setVisibility(this.groupVisibility);
|
||||
group.setUserMaximum(this.groupUserMaximum);
|
||||
group.setId(groupId);
|
||||
group.setParent(groupParent);
|
||||
group.setType(groupType);
|
||||
group.setVisibility(groupVisibility);
|
||||
group.setUserMaximum(groupUserMaximum);
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,6 @@ public class DeleteGroupEvent extends Event {
|
||||
group.setVisibility(null);
|
||||
group.setType(null);
|
||||
group.setParent(null);
|
||||
group.setUserMaximum(0L);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.exception.NoValueException;
|
||||
import mops.gruppen2.domain.exception.BadParameterException;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -12,7 +11,6 @@ import java.util.UUID;
|
||||
* Ändert nur die Gruppenbeschreibung.
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor // For Jackson
|
||||
public class UpdateGroupDescriptionEvent extends Event {
|
||||
|
||||
@ -25,10 +23,10 @@ public class UpdateGroupDescriptionEvent extends Event {
|
||||
|
||||
@Override
|
||||
protected void applyEvent(Group group) {
|
||||
if (this.newGroupDescription.isEmpty()) {
|
||||
throw new NoValueException(this.getClass().toString());
|
||||
if (newGroupDescription.isEmpty()) {
|
||||
throw new BadParameterException("Die Beschreibung ist leer.");
|
||||
}
|
||||
|
||||
group.setDescription(this.newGroupDescription);
|
||||
group.setDescription(newGroupDescription);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.exception.NoValueException;
|
||||
import mops.gruppen2.domain.exception.BadParameterException;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -12,7 +11,6 @@ import java.util.UUID;
|
||||
* Ändert nur den Gruppentitel.
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor // For Jackson
|
||||
public class UpdateGroupTitleEvent extends Event {
|
||||
|
||||
@ -26,7 +24,7 @@ public class UpdateGroupTitleEvent extends Event {
|
||||
@Override
|
||||
protected void applyEvent(Group group) {
|
||||
if (newGroupTitle.isEmpty()) {
|
||||
throw new NoValueException(getClass().toString());
|
||||
throw new BadParameterException("Der Titel ist leer.");
|
||||
}
|
||||
|
||||
group.setTitle(newGroupTitle);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import mops.gruppen2.domain.Group;
|
||||
@ -13,7 +12,6 @@ import java.util.UUID;
|
||||
* Aktualisiert die Gruppenrolle eines Teilnehmers.
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor // For Jackson
|
||||
public class UpdateRoleEvent extends Event {
|
||||
|
||||
@ -26,12 +24,12 @@ public class UpdateRoleEvent extends Event {
|
||||
|
||||
@Override
|
||||
protected void applyEvent(Group group) throws UserNotFoundException {
|
||||
if (group.getRoles().containsKey(this.userId)) {
|
||||
group.getRoles().put(this.userId, this.newRole);
|
||||
if (group.getRoles().containsKey(userId)) {
|
||||
group.getRoles().put(userId, newRole);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new UserNotFoundException(this.getClass().toString());
|
||||
throw new UserNotFoundException(getClass().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.exception.BadParameterException;
|
||||
import mops.gruppen2.domain.exception.EventException;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UpdateUserMaxEvent extends Event {
|
||||
|
||||
@ -22,6 +21,10 @@ public class UpdateUserMaxEvent extends Event {
|
||||
|
||||
@Override
|
||||
protected void applyEvent(Group group) throws EventException {
|
||||
if (userMaximum <= 0 || userMaximum < group.getMembers().size()) {
|
||||
throw new BadParameterException("Usermaximum zu klein.");
|
||||
}
|
||||
|
||||
group.setUserMaximum(userMaximum);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
package mops.gruppen2.domain.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
public class NoValueException extends EventException {
|
||||
|
||||
public NoValueException(String info) {
|
||||
super(HttpStatus.BAD_REQUEST, "Eine Information fehlt.", info);
|
||||
}
|
||||
}
|
@ -1,13 +1,57 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.exception.GroupFullException;
|
||||
import mops.gruppen2.domain.exception.UserAlreadyExistsException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.addUserEvent;
|
||||
import static mops.gruppen2.TestBuilder.apply;
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class AddUserEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = new AddUserEvent(uuidFromInt(0), "A", "Thomas", "Tom", "tho@mail.de");
|
||||
|
||||
Group group = apply(createEvent, addEvent);
|
||||
|
||||
assertThat(group.getMembers()).hasSize(1);
|
||||
assertThat(group.getMembers().get(0).getGivenname()).isEqualTo("Thomas");
|
||||
assertThat(group.getMembers().get(0).getFamilyname()).isEqualTo("Tom");
|
||||
assertThat(group.getMembers().get(0).getEmail()).isEqualTo("tho@mail.de");
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyEvent_userAlreadyExists() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEventA = addUserEvent(uuidFromInt(0), "A");
|
||||
Event addEventB = addUserEvent(uuidFromInt(0), "B");
|
||||
Event addEventC = addUserEvent(uuidFromInt(0), "A");
|
||||
|
||||
Group group = apply(createEvent, addEventA, addEventB);
|
||||
|
||||
assertThrows(UserAlreadyExistsException.class, () -> addEventA.apply(group));
|
||||
assertThrows(UserAlreadyExistsException.class, () -> addEventC.apply(group));
|
||||
assertThat(group.getMembers()).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyEvent_groupFull() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event maxSizeEvent = new UpdateUserMaxEvent(uuidFromInt(0), "A", 2L);
|
||||
Event addEventA = addUserEvent(uuidFromInt(0), "A");
|
||||
Event addEventB = addUserEvent(uuidFromInt(0), "B");
|
||||
Event addEventC = addUserEvent(uuidFromInt(0), "C");
|
||||
|
||||
Group group = apply(createEvent, maxSizeEvent, addEventA, addEventB);
|
||||
|
||||
assertThrows(GroupFullException.class, () -> addEventC.apply(group));
|
||||
assertThat(group.getMembers()).hasSize(2);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,32 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.TestBuilder;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class CreateGroupEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = new CreateGroupEvent(uuidFromInt(0),
|
||||
"A",
|
||||
uuidFromInt(1),
|
||||
GroupType.SIMPLE,
|
||||
Visibility.PUBLIC,
|
||||
100L);
|
||||
|
||||
Group group = TestBuilder.apply(createEvent);
|
||||
|
||||
assertThat(group.getMembers()).hasSize(0);
|
||||
assertThat(group.getType()).isEqualTo(GroupType.SIMPLE);
|
||||
assertThat(group.getVisibility()).isEqualTo(Visibility.PUBLIC);
|
||||
assertThat(group.getUserMaximum()).isEqualTo(100);
|
||||
assertThat(group.getId()).isEqualTo(uuidFromInt(0));
|
||||
assertThat(group.getParent()).isEqualTo(uuidFromInt(1));
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,33 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.TestBuilder;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class DeleteGroupEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = new CreateGroupEvent(uuidFromInt(0),
|
||||
"A",
|
||||
uuidFromInt(1),
|
||||
GroupType.SIMPLE,
|
||||
Visibility.PUBLIC,
|
||||
100L);
|
||||
Event deleteEvent = new DeleteGroupEvent(uuidFromInt(0), "A");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent, deleteEvent);
|
||||
|
||||
assertThat(group.getMembers()).isEmpty();
|
||||
assertThat(group.getType()).isEqualTo(null);
|
||||
assertThat(group.getVisibility()).isEqualTo(null);
|
||||
assertThat(group.getUserMaximum()).isEqualTo(0);
|
||||
assertThat(group.getId()).isEqualTo(uuidFromInt(0));
|
||||
assertThat(group.getParent()).isEqualTo(null);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,38 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.TestBuilder;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.addUserEvent;
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class DeleteUserEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
||||
Event deleteEvent = new DeleteUserEvent(uuidFromInt(0), "A");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent, addEvent, deleteEvent);
|
||||
|
||||
assertThat(group.getMembers()).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyEvent_userNotFound() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
||||
Event deleteEvent = new DeleteUserEvent(uuidFromInt(0), "B");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent, addEvent);
|
||||
|
||||
assertThrows(UserNotFoundException.class, () -> deleteEvent.apply(group));
|
||||
assertThat(group.getMembers()).hasSize(1);
|
||||
}
|
||||
}
|
||||
|
24
src/test/java/mops/gruppen2/domain/event/EventTest.java
Normal file
24
src/test/java/mops/gruppen2/domain/event/EventTest.java
Normal file
@ -0,0 +1,24 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.TestBuilder;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.exception.GroupIdMismatchException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class EventTest {
|
||||
|
||||
@Test
|
||||
void apply() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = TestBuilder.addUserEvent(uuidFromInt(1));
|
||||
|
||||
Group group = TestBuilder.apply(createEvent);
|
||||
|
||||
assertThrows(GroupIdMismatchException.class, () -> addEvent.apply(group));
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,36 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.TestBuilder;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.exception.BadParameterException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class UpdateGroupDescriptionEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEvent = new UpdateGroupDescriptionEvent(uuidFromInt(0), "A", "desc.");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent, updateEvent);
|
||||
|
||||
assertThat(group.getDescription()).isEqualTo("desc.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyEvent_badDescription() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEventA = new UpdateGroupDescriptionEvent(uuidFromInt(0), "A", "");
|
||||
Event updateEventB = new UpdateGroupDescriptionEvent(uuidFromInt(0), "A", " ");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent);
|
||||
|
||||
assertThrows(BadParameterException.class, () -> updateEventA.apply(group));
|
||||
assertThrows(BadParameterException.class, () -> updateEventB.apply(group));
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,36 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.TestBuilder;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.exception.BadParameterException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class UpdateGroupTitleEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEvent = new UpdateGroupTitleEvent(uuidFromInt(0), "A", "title.");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent, updateEvent);
|
||||
|
||||
assertThat(group.getTitle()).isEqualTo("title.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyEvent_badDescription() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEventA = new UpdateGroupTitleEvent(uuidFromInt(0), "A", "");
|
||||
Event updateEventB = new UpdateGroupTitleEvent(uuidFromInt(0), "A", " ");
|
||||
|
||||
Group group = TestBuilder.apply(createEvent);
|
||||
|
||||
assertThrows(BadParameterException.class, () -> updateEventA.apply(group));
|
||||
assertThrows(BadParameterException.class, () -> updateEventB.apply(group));
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,39 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.addUserEvent;
|
||||
import static mops.gruppen2.TestBuilder.apply;
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class UpdateRoleEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
||||
Event updateEvent = new UpdateRoleEvent(uuidFromInt(0), "A", Role.ADMIN);
|
||||
|
||||
Group group = apply(createEvent, addEvent, updateEvent);
|
||||
|
||||
assertThat(group.getRoles().get("A")).isEqualTo(Role.ADMIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyEvent_userNotFound() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event addEvent = addUserEvent(uuidFromInt(0), "A");
|
||||
Event updateEvent = new UpdateRoleEvent(uuidFromInt(0), "B", Role.ADMIN);
|
||||
|
||||
Group group = apply(createEvent, addEvent);
|
||||
|
||||
assertThrows(UserNotFoundException.class, () -> updateEvent.apply(group));
|
||||
assertThat(group.getRoles().get("A")).isEqualTo(Role.MEMBER);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,49 @@
|
||||
package mops.gruppen2.domain.event;
|
||||
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.exception.BadParameterException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static mops.gruppen2.TestBuilder.addUserEvent;
|
||||
import static mops.gruppen2.TestBuilder.apply;
|
||||
import static mops.gruppen2.TestBuilder.createPublicGroupEvent;
|
||||
import static mops.gruppen2.TestBuilder.uuidFromInt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class UpdateUserMaxEventTest {
|
||||
|
||||
@Test
|
||||
void applyEvent() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEvent = new UpdateUserMaxEvent(uuidFromInt(0), "A", 5L);
|
||||
|
||||
Group group = apply(createEvent, updateEvent);
|
||||
|
||||
assertThat(group.getUserMaximum()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyEvent_badParameter_negative() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEvent = new UpdateUserMaxEvent(uuidFromInt(0), "A", -5L);
|
||||
|
||||
Group group = apply(createEvent);
|
||||
|
||||
assertThrows(BadParameterException.class, () -> updateEvent.apply(group));
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyEvent_badParameter_tooSmall() {
|
||||
Event createEvent = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event updateEventA = new UpdateUserMaxEvent(uuidFromInt(0), "A", 5L);
|
||||
Event addEventA = addUserEvent(uuidFromInt(0));
|
||||
Event addEventB = addUserEvent(uuidFromInt(0));
|
||||
Event addEventC = addUserEvent(uuidFromInt(0));
|
||||
Event updateEventB = new UpdateUserMaxEvent(uuidFromInt(0), "A", 2L);
|
||||
|
||||
Group group = apply(createEvent, updateEventA, addEventA, addEventB, addEventC);
|
||||
|
||||
assertThrows(BadParameterException.class, () -> updateEventB.apply(group));
|
||||
}
|
||||
}
|
||||
|
@ -54,10 +54,6 @@ class GroupServiceTest {
|
||||
//TODO: Wofür ist dieser Test?
|
||||
@Test
|
||||
void rightClassForSuccessfulGroup() {
|
||||
/*List<Event> eventList = new ArrayList<>();
|
||||
UUID id = UUID.randomUUID();
|
||||
eventList.add(new CreateGroupEvent(id, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE, 1000L));
|
||||
eventList.add(new AddUserEvent(id, "Ulli", "Ulli", "Honnis", "FC@B.de"));*/
|
||||
List<Event> eventList = completePrivateGroup(1);
|
||||
|
||||
List<Group> groups = groupService.projectEventList(eventList);
|
||||
@ -88,12 +84,9 @@ class GroupServiceTest {
|
||||
|
||||
@Test
|
||||
void getGroupEvents() {
|
||||
//CreateGroupEvent test1 = new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L);
|
||||
//CreateGroupEvent test2 = new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.SIMPLE, Visibility.PUBLIC, 10L);
|
||||
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent(uuidFromInt(1)),
|
||||
createPrivateGroupEvent(uuidFromInt(2)));
|
||||
createPublicGroupEvent(uuidFromInt(1)),
|
||||
createPrivateGroupEvent(uuidFromInt(2)));
|
||||
|
||||
List<UUID> groupIds = Arrays.asList(uuidFromInt(0), uuidFromInt(1));
|
||||
|
||||
@ -104,15 +97,9 @@ class GroupServiceTest {
|
||||
|
||||
@Test
|
||||
void getAllGroupWithVisibilityPublicTestCreateAndDeleteSameGroup() {
|
||||
//CreateGroupEvent test1 = new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L);
|
||||
//DeleteGroupEvent test2 = new DeleteGroupEvent(uuidFromInt(0), "test1");
|
||||
Event test1 = createPublicGroupEvent(uuidFromInt(0));
|
||||
Event test2 = deleteGroupEvent(uuidFromInt(0));
|
||||
|
||||
//Group group = new Group();
|
||||
//test1.apply(group);
|
||||
//test2.apply(group);
|
||||
|
||||
//TODO: Hier projectEventlist()?
|
||||
Group group = TestBuilder.apply(test1, test2);
|
||||
|
||||
@ -122,50 +109,31 @@ class GroupServiceTest {
|
||||
|
||||
@Test
|
||||
void getAllGroupWithVisibilityPublicTestGroupPublic() {
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
//eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); //Wofür ist das
|
||||
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
deleteGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent());
|
||||
deleteGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent());
|
||||
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllGroupWithVisibilityPublicTestAddSomeEvents() {
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
//eventService.saveEvent(new DeleteGroupEvent(uuidFromInt(0), "test1"));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); // Wofür?
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(2), "test3", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(3), "test4", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
deleteGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent(),
|
||||
createPublicGroupEvent(),
|
||||
createPublicGroupEvent(),
|
||||
createPrivateGroupEvent());
|
||||
deleteGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent(),
|
||||
createPublicGroupEvent(),
|
||||
createPublicGroupEvent(),
|
||||
createPrivateGroupEvent());
|
||||
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllGroupWithVisibilityPublic_UserInGroup() {
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
//eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test"));
|
||||
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
addUserEvent(uuidFromInt(0), "kobold"),
|
||||
createPrivateGroupEvent(),
|
||||
createPublicGroupEvent());
|
||||
|
||||
//Das kommt glaube ich eher in einen Test für die Projektion
|
||||
//assertThat(groupService.getAllGroupWithVisibilityPublic("test2").get(0).getMembers().size()).isEqualTo(1);
|
||||
addUserEvent(uuidFromInt(0), "kobold"),
|
||||
createPrivateGroupEvent(),
|
||||
createPublicGroupEvent());
|
||||
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("kobold")).hasSize(1);
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("peter")).hasSize(2);
|
||||
@ -173,43 +141,29 @@ class GroupServiceTest {
|
||||
|
||||
@Test
|
||||
void getAllLecturesWithVisibilityPublic() {
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(1), "test2", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(1), "test2", Role.MEMBER)); // Hä
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(2), "test3", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(3), "test4", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(4), "test5", null, GroupType.LECTURE, Visibility.PUBLIC, 10L));
|
||||
|
||||
eventService.saveAll(createLectureEvent(),
|
||||
createPublicGroupEvent(),
|
||||
createLectureEvent(),
|
||||
createLectureEvent(),
|
||||
createLectureEvent());
|
||||
createPublicGroupEvent(),
|
||||
createLectureEvent(),
|
||||
createLectureEvent(),
|
||||
createLectureEvent());
|
||||
|
||||
assertThat(groupService.getAllLecturesWithVisibilityPublic().size()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
void findGroupWith_UserMember_AllGroups() {
|
||||
//eventService.saveEvent(new CreateGroupEvent(uuidFromInt(0), "test1", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L));
|
||||
//eventService.saveEvent(new AddUserEvent(uuidFromInt(0), "test1", "test", "test", "test@test"));
|
||||
//eventService.saveEvent(new UpdateGroupTitleEvent(uuidFromInt(0), "test1", "TestGroup"));
|
||||
//eventService.saveEvent(new UpdateGroupDescriptionEvent(uuidFromInt(0), "test1", "TestDescription"));
|
||||
//eventService.saveEvent(new UpdateRoleEvent(uuidFromInt(0), "test1", Role.MEMBER));
|
||||
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
addUserEvent(uuidFromInt(0), "jens"),
|
||||
updateGroupTitleEvent(uuidFromInt(0)),
|
||||
updateGroupDescriptionEvent(uuidFromInt(0)));
|
||||
addUserEvent(uuidFromInt(0), "jens"),
|
||||
updateGroupTitleEvent(uuidFromInt(0)),
|
||||
updateGroupDescriptionEvent(uuidFromInt(0)));
|
||||
|
||||
//assertThat(groupService.findGroupWith("T", new Account("jens", "a@A", "test", "peter", "mueller", null)).size()).isEqualTo(1);
|
||||
assertThat(groupService.findGroupWith("", account("jens"))).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void findGroupWith_UserNoMember_AllGroups() {
|
||||
eventService.saveAll(completePublicGroups(10, 0),
|
||||
completePrivateGroups(10, 0));
|
||||
completePrivateGroups(10, 0));
|
||||
|
||||
assertThat(groupService.findGroupWith("", account("jens"))).hasSize(10);
|
||||
}
|
||||
@ -217,12 +171,12 @@ class GroupServiceTest {
|
||||
@Test
|
||||
void findGroupWith_FilterGroups() {
|
||||
eventService.saveAll(createPublicGroupEvent(uuidFromInt(0)),
|
||||
updateGroupTitleEvent(uuidFromInt(0), "KK"),
|
||||
updateGroupDescriptionEvent(uuidFromInt(0), "ABCDE"),
|
||||
createPublicGroupEvent(uuidFromInt(1)),
|
||||
updateGroupTitleEvent(uuidFromInt(1), "ABCDEFG"),
|
||||
updateGroupDescriptionEvent(uuidFromInt(1), "KK"),
|
||||
createPrivateGroupEvent());
|
||||
updateGroupTitleEvent(uuidFromInt(0), "KK"),
|
||||
updateGroupDescriptionEvent(uuidFromInt(0), "ABCDE"),
|
||||
createPublicGroupEvent(uuidFromInt(1)),
|
||||
updateGroupTitleEvent(uuidFromInt(1), "ABCDEFG"),
|
||||
updateGroupDescriptionEvent(uuidFromInt(1), "KK"),
|
||||
createPrivateGroupEvent());
|
||||
|
||||
assertThat(groupService.findGroupWith("A", account("jesus"))).hasSize(2);
|
||||
assertThat(groupService.findGroupWith("F", account("jesus"))).hasSize(1);
|
||||
|
Reference in New Issue
Block a user