1

added deserialization tests

This commit is contained in:
Christoph
2020-03-10 16:29:28 +01:00
parent d229b2089a
commit 2f4af867e8
2 changed files with 9 additions and 39 deletions

View File

@ -8,6 +8,7 @@ import mops.gruppen2.domain.event.Event;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -20,41 +21,6 @@ public class GroupService {
this.eventService = eventService; 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) { public List<Group> projectEventList(Map<Long, Group> groupMap, List<Event> events) {
for (Event event : events) { for (Event event : events) {
if (event instanceof CreateGroupEvent) { if (event instanceof CreateGroupEvent) {
@ -77,4 +43,8 @@ public class GroupService {
return new ArrayList<>(groupMap.values()); return new ArrayList<>(groupMap.values());
} }
public List<Group> projectEventList(List<Event> events) {
return projectEventList(new HashMap<>(), events);
}
} }

View File

@ -21,7 +21,7 @@ public class EventBuilder {
); );
} }
public static AddUserEvent randomAddUserEvent() { public static AddUserEvent randomAddUserEvent(long group_id) {
Faker faker = new Faker(); Faker faker = new Faker();
String firstname = faker.name().firstName(); String firstname = faker.name().firstName();
@ -29,7 +29,7 @@ public class EventBuilder {
return new AddUserEvent( return new AddUserEvent(
faker.random().nextLong(), faker.random().nextLong(),
faker.random().nextLong(), group_id,
faker.random().hex(), faker.random().hex(),
firstname, firstname,
lastname, 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<>(); List<Event> eventList = new ArrayList<>();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
eventList.add(EventBuilder.randomAddUserEvent()); eventList.add(EventBuilder.randomAddUserEvent(group_id));
} }
return eventList; return eventList;