Search in sources :

Example 21 with Any

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));
}
Also used : TaskId(io.spine.test.entity.TaskId) Any(com.google.protobuf.Any) EntityRecord(io.spine.server.entity.EntityRecord) Test(org.junit.Test)

Example 22 with Any

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);
}
Also used : Identifiers.idToString(io.spine.base.Identifiers.idToString) Wrapper.forString(io.spine.protobuf.Wrapper.forString) StringValue(com.google.protobuf.StringValue) Identifiers.idToAny(io.spine.base.Identifiers.idToAny) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 23 with Any

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);
    }
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) ProjectId(io.spine.test.storage.ProjectId) Any(com.google.protobuf.Any) Nullable(javax.annotation.Nullable)

Example 24 with Any

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);
}
Also used : Project(io.spine.test.aggregate.Project) ProjectId(io.spine.test.aggregate.ProjectId) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 25 with Any

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);
}
Also used : Rejection(io.spine.core.Rejection) Command(io.spine.core.Command) ACommand(io.spine.server.commandbus.Given.ACommand) EntityAlreadyArchived(io.spine.server.entity.rejection.StandardRejections.EntityAlreadyArchived) Any(com.google.protobuf.Any)

Aggregations

Any (com.google.protobuf.Any)212 Test (org.junit.Test)88 Message (com.google.protobuf.Message)45 TypeConverter.toAny (io.spine.protobuf.TypeConverter.toAny)27 EntityRecord (io.spine.server.entity.EntityRecord)24 TypeUrl (io.spine.type.TypeUrl)15 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)11 Version (io.spine.core.Version)11 Customer (io.spine.test.commandservice.customer.Customer)11 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)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 Query (io.spine.client.Query)7 Project (io.spine.test.storage.Project)7 FieldMask (com.google.protobuf.FieldMask)6 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)6 EntityId (io.spine.client.EntityId)6