use of io.spine.server.entity.idfunc.IdSetEventFunction in project core-java by SpineEventEngine.
the class IdSetFunctions method put.
/**
* Puts a function into the map.
*
* @param eventClass the class of the event handled by the function
* @param func the function instance
* @param <E> the type of the event message
*/
public <E extends Message> void put(Class<E> eventClass, IdSetEventFunction<I, E> func) {
final EventClass clazz = EventClass.of(eventClass);
@SuppressWarnings("unchecked") final IdSetEventFunction<I, Message> // since we want to store {@code IdSetFunction}s for various event types.
casted = (IdSetEventFunction<I, Message>) func;
map.put(clazz, casted);
}
use of io.spine.server.entity.idfunc.IdSetEventFunction in project core-java by SpineEventEngine.
the class IdSetFunctions method get.
/**
* Obtains a function for the passed event class.
*
* @param eventClass the class of the event message
* @param <E> the type of the event message
* @return the function wrapped into {@code Optional} or empty {@code Optional}
* if there is no matching function
*/
public <E extends Message> Optional<IdSetEventFunction<I, E>> get(Class<E> eventClass) {
final EventClass clazz = EventClass.of(eventClass);
final IdSetEventFunction<I, Message> func = map.get(clazz);
// we ensure the type when we put into the map.
@SuppressWarnings("unchecked") final IdSetEventFunction<I, E> result = (IdSetEventFunction<I, E>) func;
return Optional.fromNullable(result);
}
use of io.spine.server.entity.idfunc.IdSetEventFunction in project core-java by SpineEventEngine.
the class ProjectionRepositoryShould method use_id_set_function.
@Test
public void use_id_set_function() {
final IdSetEventFunction<ProjectId, ProjectCreated> delegateFn = new IdSetEventFunction<ProjectId, ProjectCreated>() {
@Override
public Set<ProjectId> apply(ProjectCreated message, EventContext context) {
return newHashSet();
}
};
final IdSetEventFunction<ProjectId, ProjectCreated> idSetFunction = spy(delegateFn);
repository().addIdSetFunction(ProjectCreated.class, idSetFunction);
final Event event = createEvent(PRODUCER_ID, projectCreated());
repository().dispatch(event);
final ProjectCreated expectedEventMessage = Events.getMessage(event);
final EventContext context = event.getContext();
verify(idSetFunction).apply(eq(expectedEventMessage), eq(context));
}
Aggregations