Search in sources :

Example 86 with Any

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;
}
Also used : Message(com.google.protobuf.Message) Any(com.google.protobuf.Any)

Example 87 with Any

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;
}
Also used : Any(com.google.protobuf.Any)

Example 88 with Any

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

Example 89 with Any

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

Example 90 with Any

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);
}
Also used : IntegrationEvent(io.spine.server.integration.IntegrationEvent) BoundedContext(io.spine.server.BoundedContext) Any(com.google.protobuf.Any) Test(org.junit.Test)

Aggregations

Any (com.google.protobuf.Any)117 Test (org.junit.Test)40 Message (com.google.protobuf.Message)25 EntityRecord (io.spine.server.entity.EntityRecord)19 Version (io.spine.base.Version)13 Customer (io.spine.test.commandservice.customer.Customer)13 TypeUrl (io.spine.type.TypeUrl)13 StandStorage (io.spine.server.stand.StandStorage)12 Query (io.spine.client.Query)10 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)10 CustomerId (io.spine.test.commandservice.customer.CustomerId)10 Map (java.util.Map)8 FieldMask (com.google.protobuf.FieldMask)7 EntityFilters (io.spine.client.EntityFilters)7 EntityId (io.spine.client.EntityId)7 Target (io.spine.client.Target)7 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)6 Identifiers.idToAny (io.spine.base.Identifiers.idToAny)6 QueryResponse (io.spine.client.QueryResponse)6 EntityIdFilter (io.spine.client.EntityIdFilter)5