Search in sources :

Example 26 with Message

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();
}
Also used : EventContext(io.spine.base.EventContext) Transaction(io.spine.server.entity.Transaction) Message(com.google.protobuf.Message)

Example 27 with Message

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()));
}
Also used : Message(com.google.protobuf.Message)

Example 28 with Message

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;
}
Also used : Message(com.google.protobuf.Message) Event(io.spine.base.Event)

Example 29 with Message

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;
}
Also used : Message(com.google.protobuf.Message)

Example 30 with Message

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;
}
Also used : Message(com.google.protobuf.Message)

Aggregations

Message (com.google.protobuf.Message)266 Test (org.junit.Test)84 Any (com.google.protobuf.Any)30 ByteString (com.google.protobuf.ByteString)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)15 Command (io.spine.core.Command)14 DynamicMessage (com.google.protobuf.DynamicMessage)13 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)10 EntityRecord (io.spine.server.entity.EntityRecord)10 Test (org.junit.jupiter.api.Test)9 HeronTuples (com.twitter.heron.proto.system.HeronTuples)8 Event (io.spine.core.Event)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 Method (java.lang.reflect.Method)8 Event (io.spine.base.Event)7 MockHttpInputMessage (org.springframework.http.MockHttpInputMessage)7 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)7 Descriptor (com.google.protobuf.Descriptors.Descriptor)6 Builder (com.google.protobuf.Message.Builder)5