use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class InvalidEntityStateException method getEntityState.
/**
* Returns a related event message.
*/
public Message getEntityState() {
if (entityState instanceof Any) {
final Any any = (Any) entityState;
Message unpacked = AnyPacker.unpack(any);
return unpacked;
}
return entityState;
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class EntityQueryMatcher method idMatches.
private boolean idMatches(EntityRecordWithColumns record) {
if (!acceptedIds.isEmpty()) {
final Any entityId = record.getRecord().getEntityId();
final Object genericId = Identifiers.idFromAny(entityId);
@SuppressWarnings("SuspiciousMethodCalls") final boolean // The Collection.contains behavior about the non-assignable types is acceptable
idMatches = acceptedIds.contains(genericId);
if (!idMatches) {
return false;
}
}
return true;
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class ProjectionStorageShould method checkProjectIdIsInList.
@SuppressWarnings("BreakStatement")
private static <I> Project checkProjectIdIsInList(EntityRecord project, List<I> ids) {
final Any packedState = project.getState();
final Project state = AnyPacker.unpack(packedState);
final ProjectId id = state.getId();
final String stringIdRepr = id.getId();
boolean isIdPresent = false;
for (I genericId : ids) {
isIdPresent = genericId.toString().equals(stringIdRepr);
if (isIdPresent) {
break;
}
}
assertTrue(isIdPresent);
return state;
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class ProjectionStorageShould method read_all_messages_with_field_mask.
@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void read_all_messages_with_field_mask() {
final List<I> ids = fillStorage(5);
final String projectDescriptor = Project.getDescriptor().getFullName();
// clashes with non-related tests.
@SuppressWarnings("DuplicateStringLiteralInspection") final FieldMask fieldMask = maskForPaths(projectDescriptor + ".id", projectDescriptor + ".name");
final Map<I, EntityRecord> read = storage.readAll(fieldMask);
assertSize(ids.size(), read);
for (Map.Entry<I, EntityRecord> record : read.entrySet()) {
assertContains(record.getKey(), ids);
final Any packedState = record.getValue().getState();
final Project state = AnyPacker.unpack(packedState);
assertMatchesMask(state, fieldMask);
}
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class BoundedContextShould method not_notify_integration_event_subscriber_if_event_is_invalid.
@Test
public void not_notify_integration_event_subscriber_if_event_is_invalid() {
final BoundedContext boundedContext = TestBoundedContextFactory.MultiTenant.newBoundedContext();
final TestEventSubscriber sub = new TestEventSubscriber();
boundedContext.getEventBus().register(sub);
final Any invalidMsg = AnyPacker.pack(ProjectCreated.getDefaultInstance());
final IntegrationEvent event = Given.AnIntegrationEvent.projectCreated().toBuilder().setMessage(invalidMsg).build();
boundedContext.notify(event, new TestResponseObserver());
assertNull(sub.eventHandled);
}
Aggregations