Search in sources :

Example 1 with Any

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

the class TypeConverterShould method map_uint64_to_long.

@Test
public void map_uint64_to_long() {
    final long value = 42L;
    final UInt64Value wrapped = UInt64Value.newBuilder().setValue(value).build();
    final Any packed = AnyPacker.pack(wrapped);
    final long mapped = TypeConverter.toObject(packed, Long.class);
    assertEquals(value, mapped);
}
Also used : Any(com.google.protobuf.Any) UInt64Value(com.google.protobuf.UInt64Value) Test(org.junit.Test)

Example 2 with Any

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

the class TypeConverterShould method checkMapping.

private static void checkMapping(Object javaObject, Message protoObject) {
    final Any wrapped = AnyPacker.pack(protoObject);
    final Object mappedJavaObject = TypeConverter.toObject(wrapped, javaObject.getClass());
    assertEquals(javaObject, mappedJavaObject);
    final Any restoredWrapped = TypeConverter.toAny(mappedJavaObject);
    final Message restored = AnyPacker.unpack(restoredWrapped);
    assertEquals(protoObject, restored);
}
Also used : Message(com.google.protobuf.Message) Any(com.google.protobuf.Any)

Example 3 with Any

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

the class TypeConverterShould method map_uint32_to_int.

@Test
public void map_uint32_to_int() {
    final int value = 42;
    final UInt32Value wrapped = UInt32Value.newBuilder().setValue(value).build();
    final Any packed = AnyPacker.pack(wrapped);
    final int mapped = TypeConverter.toObject(packed, Integer.class);
    assertEquals(value, mapped);
}
Also used : UInt32Value(com.google.protobuf.UInt32Value) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 4 with Any

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

the class MatchFilter method checkFields.

private static boolean checkFields(Message object, FieldFilter filter) {
    final Optional<Field> fieldOptional = Field.forFilter(object.getClass(), filter);
    if (!fieldOptional.isPresent()) {
        return false;
    }
    final Field field = fieldOptional.get();
    final Optional<Message> value;
    try {
        value = field.getValue(object);
    } catch (IllegalStateException ignored) {
        // Wrong Message class -> does not satisfy the criteria.
        return false;
    }
    final Collection<Any> expectedAnys = filter.getValueList();
    final Collection<Message> expectedValues = Collections2.transform(expectedAnys, unpackFunc());
    if (!value.isPresent()) {
        /* If there is no value in the field return `true`
               if the list of required values is also empty. */
        final boolean nothingIsExpected = expectedValues.isEmpty();
        return nothingIsExpected;
    }
    final boolean result = expectedValues.contains(value.get());
    return result;
}
Also used : Field(io.spine.server.reflect.Field) Message(com.google.protobuf.Message) Any(com.google.protobuf.Any)

Example 5 with Any

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

the class AnyPackerShould method unpack_spine_message_from_Any.

@Test
public void unpack_spine_message_from_Any() {
    final Any any = AnyPacker.pack(spineMsg);
    final UserId actual = AnyPacker.unpack(any);
    assertEquals(spineMsg, actual);
}
Also used : UserId(io.spine.users.UserId) Tests.newUserId(io.spine.test.Tests.newUserId) Any(com.google.protobuf.Any) Test(org.junit.Test)

Aggregations

Any (com.google.protobuf.Any)223 Test (org.junit.Test)95 Message (com.google.protobuf.Message)45 TypeConverter.toAny (io.spine.protobuf.TypeConverter.toAny)27 EntityRecord (io.spine.server.entity.EntityRecord)24 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)16 TypeUrl (io.spine.type.TypeUrl)15 Version (io.spine.core.Version)11 Customer (io.spine.test.commandservice.customer.Customer)11 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)10 CommandPacket (org.openkilda.server42.control.messaging.Control.CommandPacket)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 HashSet (java.util.HashSet)8 Query (io.spine.client.Query)7 Project (io.spine.test.storage.Project)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7