1

improved testing

This commit is contained in:
Christoph
2020-03-24 22:28:56 +01:00
parent cdb22828aa
commit a0d6243b5c
8 changed files with 409 additions and 140 deletions

View File

@ -39,7 +39,7 @@ public class AddUserEvent extends Event {
throw new UserAlreadyExistsException(this.getClass().toString());
}
if (group.getMembers().size() == group.getUserMaximum()) {
if (group.getMembers().size() >= group.getUserMaximum()) {
throw new GroupFullException(this.getClass().toString());
}

View File

@ -5,7 +5,7 @@ import org.springframework.http.HttpStatus;
public class GroupFullException extends EventException {
public GroupFullException(String info) {
super(HttpStatus.INTERNAL_SERVER_ERROR, "Der User existiert bereits.", info);
super(HttpStatus.INTERNAL_SERVER_ERROR, "Die Gruppe ist voll.", info);
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
//TODO Rename Queries + Formatting
public interface EventRepository extends CrudRepository<EventDTO, Long> {
@Query("select distinct group_id from event where user_id =:id")

View File

@ -12,6 +12,7 @@ import java.util.UUID;
import java.util.stream.Collectors;
@Service
//TODO: Evtl aufsplitten in EventRepoService und EventService?
public class EventService {
private final JsonService jsonService;
@ -28,8 +29,22 @@ public class EventService {
* @param event Event, welches gespeichert wird
*/
public void saveEvent(Event event) {
EventDTO eventDTO = getDTO(event);
eventStore.save(eventDTO);
eventStore.save(getDTO(event));
}
public void saveAll(Event... events) {
for (Event event : events) {
eventStore.save(getDTO(event));
}
}
@SafeVarargs
public final void saveAll(List<Event>... events) {
for (List<Event> eventlist : events) {
for (Event event : eventlist) {
eventStore.save(getDTO(event));
}
}
}
/**
@ -39,6 +54,7 @@ public class EventService {
* @param event Event, welches in DTO übersetzt wird
* @return EventDTO Neues DTO
*/
//TODO Rename: getDTOFromEvent?
public EventDTO getDTO(Event event) {
String payload = "";
try {
@ -58,6 +74,7 @@ public class EventService {
/**
* Findet alle Events welche ab dem neuen Status hinzugekommen sind.
* Sucht alle Events mit event_id > status
*
* @param status Die Id des zuletzt gespeicherten Events
* @return Liste von neueren Events
@ -75,6 +92,7 @@ public class EventService {
* @param eventDTOS Liste von DTOs
* @return Liste von Events
*/
//TODO Rename: getEventsFromDTO?
public List<Event> translateEventDTOs(Iterable<EventDTO> eventDTOS) {
List<Event> events = new ArrayList<>();
@ -88,7 +106,6 @@ public class EventService {
return events;
}
public Long getMaxEvent_id() {
return eventStore.getHighesEvent_ID();
}
@ -98,6 +115,7 @@ public class EventService {
return translateEventDTOs(eventDTOList);
}
//TODO: Nur AddUserEvents betrachten
public List<UUID> findGroupIdsByUser(String userId) {
List<String> groupIDs = eventStore.findGroup_idsWhereUser_id(userId);

View File

@ -35,6 +35,7 @@ public class GroupService {
* @param groupIds Liste an IDs
* @return Liste an Events
*/
//TODO Das vielleicht in den EventRepoService?
public List<Event> getGroupEvents(List<UUID> groupIds) {
List<EventDTO> eventDTOS = new ArrayList<>();
for (UUID groupId : groupIds) {
@ -54,8 +55,6 @@ public class GroupService {
public List<Group> projectEventList(List<Event> events) throws EventException {
Map<UUID, Group> groupMap = new HashMap<>();
events.forEach(System.out::println);
events.parallelStream()
.forEachOrdered(event -> event.apply(getOrCreateGroup(groupMap, event.getGroupId())));
@ -77,6 +76,7 @@ public class GroupService {
* @return Liste von projizierten Gruppen
* @throws EventException Projektionsfehler
*/
//TODO Rename
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
@ -95,6 +95,7 @@ public class GroupService {
}
//TODO Rename
public List<Group> getAllLecturesWithVisibilityPublic() throws EventException {
List<Event> createEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
createEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
@ -103,7 +104,6 @@ public class GroupService {
List<Group> visibleGroups = projectEventList(createEvents);
return visibleGroups.parallelStream()
.filter(group -> group.getType() != null)
.filter(group -> group.getType() == GroupType.LECTURE)
.filter(group -> group.getVisibility() == Visibility.PUBLIC)
.collect(Collectors.toList());
@ -118,12 +118,16 @@ public class GroupService {
* @return Liste von projizierten Gruppen
* @throws EventException Projektionsfehler
*/
//Todo Rename
public List<Group> findGroupWith(String search, Account account) throws EventException {
if (search.isEmpty()) {
return getAllGroupWithVisibilityPublic(account.getName());
}
return getAllGroupWithVisibilityPublic(account.getName())
.parallelStream()
.filter(group ->
group.getTitle().toLowerCase().contains(search.toLowerCase()) ||
group.getDescription().toLowerCase().contains(search.toLowerCase()))
.filter(group -> group.getTitle().toLowerCase().contains(search.toLowerCase())
|| group.getDescription().toLowerCase().contains(search.toLowerCase()))
.collect(Collectors.toList());
}
}