use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class TestTransaction method injectState.
/**
* A hack allowing to inject state and version into an {@code EventPlayingEntity} instance
* by creating and committing a fake transaction.
*
* <p>To be used in tests only.
*/
public static void injectState(EventPlayingEntity entity, Message state, Version version) {
@SuppressWarnings("unchecked") final Transaction tx = new Transaction(entity, state, version) {
@Override
protected void dispatch(EventPlayingEntity entity, Message eventMessage, EventContext context) throws InvocationTargetException {
// do nothing.
}
};
tx.commit();
}
use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class EventPlayingEntityShould method verifyEventApplied.
private static void verifyEventApplied(Transaction txMock, Event event) {
final Message actualMessage = unpack(event.getMessage());
verify(txMock).apply(eq(actualMessage), eq(event.getContext()));
}
use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class EventClass method of.
/**
* Creates a new instance of the event class by passed event instance.
*
* <p>If an instance of {@link Event} (which implements {@code Message}) is passed to
* this method, enclosing event message will be un-wrapped to determine the class of the event.
*
* @param event an event instance
* @return new instance
*/
public static EventClass of(Message event) {
final Message message = checkNotNull(event);
if (message instanceof Event) {
final Event eventRecord = (Event) event;
final Message enclosed = Events.getMessage(eventRecord);
return of(enclosed.getClass());
}
final EventClass result = of(message.getClass());
return result;
}
use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class TypeUrl method of.
/** Obtains the type URL for the passed message class. */
public static TypeUrl of(Class<? extends Message> cls) {
final Message defaultInstance = getDefaultInstance(cls);
final TypeUrl result = of(defaultInstance);
return result;
}
use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class TypeUrl method ofEnclosedMessage.
private static TypeUrl ofEnclosedMessage(MessageEnvelope envelope) {
checkNotNull(envelope);
final Message message = envelope.getMessage();
final TypeUrl result = of(message);
return result;
}
Aggregations