Search in sources :

Example 6 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class TypeNameShould method return_simple_name_if_no_package.

@Test
public void return_simple_name_if_no_package() {
    // A msg type without Protobuf package
    final String name = IfMissingOption.class.getSimpleName();
    final TypeUrl typeUrl = TypeName.of(name).toUrl();
    final String actual = TypeName.from(typeUrl).getSimpleName();
    assertEquals(name, actual);
}
Also used : TypeUrl(io.spine.type.TypeUrl) Test(org.junit.Test)

Example 7 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class JsonShould method build_JsonFormat_registry_for_known_types.

@Test
public void build_JsonFormat_registry_for_known_types() {
    final JsonFormat.TypeRegistry typeRegistry = Json.typeRegistry();
    final List<Descriptors.Descriptor> found = Lists.newLinkedList();
    for (TypeUrl typeUrl : KnownTypes.getAllUrls()) {
        final Descriptors.Descriptor descriptor = typeRegistry.find(typeUrl.getTypeName());
        if (descriptor != null) {
            found.add(descriptor);
        }
    }
    assertFalse(found.isEmpty());
}
Also used : JsonFormat(com.google.protobuf.util.JsonFormat) TypeUrl(io.spine.type.TypeUrl) Descriptors(com.google.protobuf.Descriptors) Test(org.junit.Test)

Example 8 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class AnyPackerShould method pack_spine_message_to_Any.

@Test
public void pack_spine_message_to_Any() {
    final Any actual = AnyPacker.pack(spineMsg);
    final TypeUrl typeUrl = TypeUrl.of(spineMsg);
    assertEquals(Any.pack(spineMsg).getValue(), actual.getValue());
    assertEquals(typeUrl.value(), actual.getTypeUrl());
}
Also used : TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 9 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class AnyPacker method pack.

/**
     * Wraps {@link Message} object inside of {@link Any} instance.
     *
     * <p>If an instance of {@code Any} passed, this instance is returned.
     *
     * @param message the message to pack
     * @return the wrapping instance of {@link Any} or the message itself, if it is {@code Any}
     */
public static Any pack(Message message) {
    if (message instanceof Any) {
        return (Any) message;
    }
    final TypeUrl typeUrl = TypeUrl.from(message.getDescriptorForType());
    final String typeUrlPrefix = typeUrl.getPrefix();
    final Any result = Any.pack(message, typeUrlPrefix);
    return result;
}
Also used : TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any)

Example 10 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class QueryService method read.

@SuppressWarnings("MethodDoesntCallSuperMethod")
// as we override default implementation with `unimplemented` status.
@Override
public void read(Query query, StreamObserver<QueryResponse> responseObserver) {
    log().debug("Incoming query: {}", query);
    final TypeUrl type = Queries.typeOf(query);
    final BoundedContext boundedContext = typeToContextMap.get(type);
    final Stand stand = boundedContext.getStand();
    try {
        stand.execute(query, responseObserver);
    } catch (@SuppressWarnings("OverlyBroadCatchBlock") Exception e) {
        log().error("Error processing query", e);
        responseObserver.onError(e);
    }
}
Also used : Stand(io.spine.server.stand.Stand) TypeUrl(io.spine.type.TypeUrl)

Aggregations

TypeUrl (io.spine.type.TypeUrl)37 Any (com.google.protobuf.Any)12 Test (org.junit.Test)11 EntityRecord (io.spine.server.entity.EntityRecord)7 Message (com.google.protobuf.Message)6 StandStorage (io.spine.server.stand.StandStorage)4 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)3 ClassName (io.spine.type.ClassName)3 TypeName (io.spine.type.TypeName)3 Descriptors (com.google.protobuf.Descriptors)2 Version (io.spine.base.Version)2 Query (io.spine.client.Query)2 BoundedContext (io.spine.server.BoundedContext)2 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 Customer (io.spine.test.commandservice.customer.Customer)2 CustomerId (io.spine.test.commandservice.customer.CustomerId)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 CanIgnoreReturnValue (com.google.errorprone.annotations.CanIgnoreReturnValue)1