use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class EntityQueryMatcherShould method match_columns.
// Mocks <-> reflection issues
@SuppressWarnings("unchecked")
@Test
public void match_columns() {
final String targetName = "feature";
final Column<?> target = mock(Column.class);
when(target.isNullable()).thenReturn(true);
when(target.getName()).thenReturn(targetName);
when(target.getType()).thenReturn((Class) Boolean.class);
final Object acceptedValue = true;
final Collection<Object> ids = Collections.emptyList();
final Map<Column<?>, Object> params = ImmutableMap.<Column<?>, Object>of(target, acceptedValue);
final EntityQuery<?> query = EntityQuery.of(ids, params);
final Any matchingId = AnyPacker.pack(Sample.messageOfType(TaskId.class));
final Any nonMatchingId = AnyPacker.pack(Sample.messageOfType(TaskId.class));
final EntityQueryMatcher<?> matcher = new EntityQueryMatcher<>(query);
final EntityRecord matching = EntityRecord.newBuilder().setEntityId(matchingId).build();
final EntityRecord nonMatching = EntityRecord.newBuilder().setEntityId(nonMatchingId).build();
final Column.MemoizedValue storedValue = mock(Column.MemoizedValue.class);
when(storedValue.getSourceColumn()).thenReturn(target);
when(storedValue.getValue()).thenReturn(acceptedValue);
final Map<String, Column.MemoizedValue<?>> matchingColumns = ImmutableMap.<String, Column.MemoizedValue<?>>of(targetName, storedValue);
final EntityRecordWithColumns nonMatchingRecord = of(nonMatching);
final EntityRecordWithColumns matchingRecord = io.spine.server.entity.storage.EntityRecordWithColumns.of(matching, matchingColumns);
assertTrue(matcher.apply(matchingRecord));
assertFalse(matcher.apply(nonMatchingRecord));
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class IdentifiersShould method convert_to_string_message_id_wrapped_in_Any.
@Test
public void convert_to_string_message_id_wrapped_in_Any() {
final StringValue messageToWrap = forString(TEST_ID);
final Any any = AnyPacker.pack(messageToWrap);
final String result = idToString(any);
assertEquals(TEST_ID, result);
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class StandStorageShould method checkIds.
protected void checkIds(List<AggregateStateId> ids, Collection<EntityRecord> records) {
assertSize(ids.size(), records);
final Collection<ProjectId> projectIds = Collections2.transform(ids, new Function<AggregateStateId, ProjectId>() {
@Nullable
@Override
public ProjectId apply(@Nullable AggregateStateId input) {
if (input == null) {
return null;
}
return (ProjectId) input.getAggregateId();
}
});
for (EntityRecord record : records) {
final Any packedState = record.getState();
final Project state = AnyPacker.unpack(packedState);
final ProjectId id = state.getId();
assertContains(id, projectIds);
}
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class SubscriptionRecordShould method match_record_to_given_parameters.
@Test
public void match_record_to_given_parameters() {
final SubscriptionRecord matchingRecord = new SubscriptionRecord(Given.subscription(), Given.target(), Given.TYPE);
final Project entityState = Project.getDefaultInstance();
final Any wrappedState = AnyPacker.pack(entityState);
final ProjectId redundantId = ProjectId.getDefaultInstance();
final boolean matchResult = matchingRecord.matches(Given.TYPE, redundantId, wrappedState);
assertTrue(matchResult);
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class ProcessManagerShould method entityAlreadyArchived.
private static RejectionEnvelope entityAlreadyArchived(Class<? extends Message> commandMessageCls) {
final Any id = Identifier.pack(ProcessManagerShould.class.getName());
final EntityAlreadyArchived rejectionMessage = EntityAlreadyArchived.newBuilder().setEntityId(id).build();
final Command command = ACommand.withMessage(Sample.messageOfType(commandMessageCls));
final Rejection rejection = Rejections.createRejection(rejectionMessage, command);
return RejectionEnvelope.of(rejection);
}
Aggregations