added deserialization tests
This commit is contained in:
@ -8,6 +8,7 @@ import mops.gruppen2.domain.event.Event;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -20,41 +21,6 @@ public class GroupService {
|
||||
this.eventService = eventService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Konstruiert eine vollständige Gruppe aus Events, welche dieselbe Gruppe betreffen.
|
||||
*
|
||||
* @param eventList Die restlichen Events für diese Gruppe
|
||||
* @return Gruppe auf aktuellem Stand
|
||||
*/
|
||||
Group buildGroupFromEvents(List<Event> eventList) throws EventException {
|
||||
Group newGroup = new Group();
|
||||
|
||||
try {
|
||||
if (!(eventList.get(0) instanceof CreateGroupEvent)) {
|
||||
throw new GroupDoesNotExistException("Die Gruppe existiert nicht");
|
||||
} else {
|
||||
newGroup.applyEvent(eventList.get(0));
|
||||
eventList.remove(0);
|
||||
}
|
||||
for (Event event : eventList) {
|
||||
if (!(newGroup.getId() > 0)) {
|
||||
throw new GroupDoesNotExistException("Die Gruppe existiert nicht");
|
||||
}
|
||||
newGroup.applyEvent(event);
|
||||
}
|
||||
} catch (EventException e) {
|
||||
if (e instanceof GroupDoesNotExistException) {
|
||||
throw e;
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (newGroup.getId() < 0) {
|
||||
return null;
|
||||
}
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
public List<Group> projectEventList(Map<Long, Group> groupMap, List<Event> events) {
|
||||
for (Event event : events) {
|
||||
if (event instanceof CreateGroupEvent) {
|
||||
@ -77,4 +43,8 @@ public class GroupService {
|
||||
|
||||
return new ArrayList<>(groupMap.values());
|
||||
}
|
||||
|
||||
public List<Group> projectEventList(List<Event> events) {
|
||||
return projectEventList(new HashMap<>(), events);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ public class EventBuilder {
|
||||
);
|
||||
}
|
||||
|
||||
public static AddUserEvent randomAddUserEvent() {
|
||||
public static AddUserEvent randomAddUserEvent(long group_id) {
|
||||
Faker faker = new Faker();
|
||||
|
||||
String firstname = faker.name().firstName();
|
||||
@ -29,7 +29,7 @@ public class EventBuilder {
|
||||
|
||||
return new AddUserEvent(
|
||||
faker.random().nextLong(),
|
||||
faker.random().nextLong(),
|
||||
group_id,
|
||||
faker.random().hex(),
|
||||
firstname,
|
||||
lastname,
|
||||
@ -37,11 +37,11 @@ public class EventBuilder {
|
||||
);
|
||||
}
|
||||
|
||||
public static List<Event> randomAddUserEvents(int count) {
|
||||
public static List<Event> randomAddUserEvents(int count, long group_id) {
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
eventList.add(EventBuilder.randomAddUserEvent());
|
||||
eventList.add(EventBuilder.randomAddUserEvent(group_id));
|
||||
}
|
||||
|
||||
return eventList;
|
||||
|
||||
Reference in New Issue
Block a user