Search in sources :

Example 11 with Any

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

the class Events method getMessage.

/**
     * Extracts the event message from the passed event.
     *
     * @param event an event to get message from
     */
public static <M extends Message> M getMessage(Event event) {
    checkNotNull(event);
    final Any any = event.getMessage();
    final M result = unpack(any);
    return result;
}
Also used : Any(com.google.protobuf.Any)

Example 12 with Any

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

the class Failures method createFailure.

/**
     * Creates a new {@code Failure} instance.
     *
     * @param messageOrAny the failure message or {@code Any} containing the message
     * @param command      the {@code Command}, which triggered the failure.
     * @return created failure instance
     */
public static Failure createFailure(Message messageOrAny, Command command) {
    checkNotNull(messageOrAny);
    checkNotNull(command);
    final Any packedFailureMessage = toAny(messageOrAny);
    final FailureContext context = FailureContext.newBuilder().setCommand(command).build();
    final Failure result = Failure.newBuilder().setMessage(packedFailureMessage).setContext(context).build();
    return result;
}
Also used : Any(com.google.protobuf.Any) Messages.toAny(io.spine.protobuf.Messages.toAny)

Example 13 with Any

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

the class IntegerFieldValidatorShould method wrap_to_any.

@Test
public void wrap_to_any() {
    final Any any = validator.wrap(VALUE);
    final Int32Value msg = AnyPacker.unpack(any);
    assertEquals(VALUE, (Integer) msg.getValue());
}
Also used : Int32Value(com.google.protobuf.Int32Value) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 14 with Any

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

the class LongFieldValidatorShould method wrap_to_any.

@Test
public void wrap_to_any() {
    final Any any = validator.wrap(VALUE);
    final Int64Value msg = AnyPacker.unpack(any);
    assertEquals(VALUE, (Long) msg.getValue());
}
Also used : Int64Value(com.google.protobuf.Int64Value) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 15 with Any

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

the class PackingIterator method next.

/**
     * Takes the message from the source iterator, wraps it into {@code Any}
     * and returns.
     *
     * <p>If the source iterator returns {@code null} message, the default instance
     * of {@code Any} will be returned.
     *
     * @return the packed message or default {@code Any}
     */
@Override
public Any next() {
    final Message next = source.next();
    final Any result = next != null ? AnyPacker.pack(next) : Any.getDefaultInstance();
    return result;
}
Also used : Message(com.google.protobuf.Message) Any(com.google.protobuf.Any)

Aggregations

Any (com.google.protobuf.Any)212 Test (org.junit.Test)88 Message (com.google.protobuf.Message)45 TypeConverter.toAny (io.spine.protobuf.TypeConverter.toAny)27 EntityRecord (io.spine.server.entity.EntityRecord)24 TypeUrl (io.spine.type.TypeUrl)15 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)11 Version (io.spine.core.Version)11 Customer (io.spine.test.commandservice.customer.Customer)11 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)10 CdsUpdate (io.grpc.xds.XdsClient.CdsUpdate)9 GivenVersion (io.spine.core.given.GivenVersion)9 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)8 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)8 CustomerId (io.spine.test.commandservice.customer.CustomerId)8 Query (io.spine.client.Query)7 Project (io.spine.test.storage.Project)7 FieldMask (com.google.protobuf.FieldMask)6 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)6 EntityId (io.spine.client.EntityId)6