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);
}
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());
}
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());
}
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;
}
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);
}
}
Aggregations