Search in sources :

Example 66 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class IteratingCommandRouter method routeNext.

/**
 * Creates and posts a next command.
 *
 * <p>The commands are created and posted in the sequence their messages were added.
 *
 * @return the posted command
 * @throws NoSuchElementException if there are no command messages to post
 * @see #hasNext()
 */
protected Command routeNext() {
    final Message message = next();
    final Command command = route(message);
    return command;
}
Also used : Message(com.google.protobuf.Message) Command(io.spine.core.Command)

Example 67 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class QueryBuilderShould method create_queries_with_multiple_params.

@Test
public void create_queries_with_multiple_params() {
    final String columnName1 = "myColumn";
    final Object columnValue1 = 42;
    final String columnName2 = "oneMore";
    final Object columnValue2 = newMessageId();
    final Query query = factory().query().select(TestEntity.class).where(eq(columnName1, columnValue1), eq(columnName2, columnValue2)).build();
    assertNotNull(query);
    final Target target = query.getTarget();
    assertFalse(target.getIncludeAll());
    final EntityFilters entityFilters = target.getFilters();
    final List<CompositeColumnFilter> aggregatingColumnFilters = entityFilters.getFilterList();
    assertSize(1, aggregatingColumnFilters);
    final Collection<ColumnFilter> columnFilters = aggregatingColumnFilters.get(0).getFilterList();
    final Any actualValue1 = findByName(columnFilters, columnName1).getValue();
    assertNotNull(actualValue1);
    final int actualGenericValue1 = toObject(actualValue1, int.class);
    assertEquals(columnValue1, actualGenericValue1);
    final Any actualValue2 = findByName(columnFilters, columnName2).getValue();
    assertNotNull(actualValue2);
    final Message actualGenericValue2 = toObject(actualValue2, ProjectId.class);
    assertEquals(columnValue2, actualGenericValue2);
}
Also used : Message(com.google.protobuf.Message) TypeConverter.toObject(io.spine.protobuf.TypeConverter.toObject) Matchers.containsString(org.hamcrest.Matchers.containsString) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 68 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class MessageMismatch method unpackActual.

/**
 * Obtains actual value as a {@code Message} from the passed mismatch.
 *
 * @throws RuntimeException if the passed instance represent a mismatch of
 *                          non-{@code Message} values
 */
public static Message unpackActual(ValueMismatch mismatch) {
    checkNotNull(mismatch);
    final Any any = mismatch.getActual();
    final Message result = unpack(any);
    return result;
}
Also used : Message(com.google.protobuf.Message) Any(com.google.protobuf.Any)

Example 69 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class MessageMismatch method expectedDefault.

/**
 * Creates {@code ValueMismatch} for the case of discovering a non-default value,
 * when the default value was expected by a command.
 *
 * @param actual   the value discovered instead of the default value
 * @param newValue the new value requested in the command
 * @param version  the version of the entity in which the mismatch is discovered
 * @return new {@code ValueMismatch} instance
 */
public static ValueMismatch expectedDefault(Message actual, Message newValue, int version) {
    checkNotNull(actual);
    checkNotNull(newValue);
    final Message expectedDefault = actual.getDefaultInstanceForType();
    return of(expectedDefault, actual, newValue, version);
}
Also used : Message(com.google.protobuf.Message)

Example 70 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class MessageMismatch method expectedNotDefault.

/**
 * Creates a {@code ValueMismatch} for a command that wanted to <em>clear</em> a value,
 * but discovered that the field already has the default value.
 *
 * @param expected the value of the field that the command wanted to clear
 * @param version  the version of the entity in which the mismatch is discovered
 * @return new {@code ValueMismatch} instance
 */
public static ValueMismatch expectedNotDefault(Message expected, int version) {
    checkNotNull(expected);
    final Message defaultValue = expected.getDefaultInstanceForType();
    return of(expected, defaultValue, defaultValue, version);
}
Also used : Message(com.google.protobuf.Message)

Aggregations

Message (com.google.protobuf.Message)185 Test (org.junit.Test)62 Any (com.google.protobuf.Any)30 Command (io.spine.core.Command)14 EntityRecord (io.spine.server.entity.EntityRecord)10 ByteString (com.google.protobuf.ByteString)9 Event (io.spine.core.Event)8 Event (io.spine.base.Event)7 CommandEnvelope (io.spine.core.CommandEnvelope)7 TypeUrl (io.spine.type.TypeUrl)7 IOException (java.io.IOException)7 Timestamp (com.google.protobuf.Timestamp)5 Error (io.spine.base.Error)5 Rejection (io.spine.core.Rejection)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Method (java.lang.reflect.Method)5 FieldMask (com.google.protobuf.FieldMask)4 GeneratedMessage (com.google.protobuf.GeneratedMessage)4 ThrowableMessage (io.spine.base.ThrowableMessage)4 EntityFilters (io.spine.client.EntityFilters)4