Search in sources :

Example 31 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 I genericId = Identifier.unpack(entityId);
        final boolean idMatches = acceptedIds.contains(genericId);
        if (!idMatches) {
            return false;
        }
    }
    return true;
}
Also used : Any(com.google.protobuf.Any)

Example 32 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class StandShould method doCheckReadingCustomersById.

@CanIgnoreReturnValue
Stand doCheckReadingCustomersById(int numberOfCustomers) {
    // Define the types and values used as a test data.
    final TypeUrl customerType = TypeUrl.of(Customer.class);
    final Map<CustomerId, Customer> sampleCustomers = fillSampleCustomers(numberOfCustomers);
    // Prepare the stand and its storage to act.
    final StandStorage standStorage = setupStandStorageWithCustomers(sampleCustomers, customerType);
    final Stand stand = prepareStandWithAggregateRepo(standStorage);
    triggerMultipleUpdates(sampleCustomers, stand);
    final Query readMultipleCustomers = requestFactory.query().byIds(Customer.class, sampleCustomers.keySet());
    final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
    stand.execute(readMultipleCustomers, responseObserver);
    final List<Any> messageList = checkAndGetMessageList(responseObserver);
    assertEquals(sampleCustomers.size(), messageList.size());
    final Collection<Customer> allCustomers = sampleCustomers.values();
    for (Any singleRecord : messageList) {
        final Customer unpackedSingleResult = unpack(singleRecord);
        assertTrue(allCustomers.contains(unpackedSingleResult));
    }
    return stand;
}
Also used : Query(io.spine.client.Query) Customer(io.spine.test.commandservice.customer.Customer) TypeUrl(io.spine.type.TypeUrl) CustomerId(io.spine.test.commandservice.customer.CustomerId) Any(com.google.protobuf.Any) CanIgnoreReturnValue(com.google.errorprone.annotations.CanIgnoreReturnValue)

Example 33 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class StandShould method operate_with_storage_provided_through_builder.

@SuppressWarnings("OverlyCoupledMethod")
@Test
public void operate_with_storage_provided_through_builder() {
    final StandStorage standStorageMock = mock(StandStorage.class);
    final BoundedContext boundedContext = BoundedContext.newBuilder().setStand(Stand.newBuilder().setStorage(standStorageMock)).build();
    final Stand stand = boundedContext.getStand();
    assertNotNull(stand);
    final CustomerAggregateRepository customerAggregateRepo = new CustomerAggregateRepository();
    stand.registerTypeSupplier(customerAggregateRepo);
    final int numericIdValue = 17;
    final CustomerId customerId = customerIdFor(numericIdValue);
    final CustomerAggregate customerAggregate = customerAggregateRepo.create(customerId);
    final Customer customerState = customerAggregate.getState();
    final TypeUrl customerType = TypeUrl.of(Customer.class);
    final Version stateVersion = GivenVersion.withNumber(1);
    verify(standStorageMock, never()).write(any(AggregateStateId.class), any(EntityRecordWithColumns.class));
    stand.update(asEnvelope(customerId, customerState, stateVersion));
    final AggregateStateId expectedAggregateStateId = AggregateStateId.of(customerId, customerType);
    final Any packedState = AnyPacker.pack(customerState);
    final EntityRecord expectedRecord = EntityRecord.newBuilder().setState(packedState).build();
    verify(standStorageMock, times(1)).write(eq(expectedAggregateStateId), recordStateMatcher(expectedRecord));
}
Also used : Customer(io.spine.test.commandservice.customer.Customer) TypeUrl(io.spine.type.TypeUrl) CustomerId(io.spine.test.commandservice.customer.CustomerId) Any(com.google.protobuf.Any) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) EntityRecord(io.spine.server.entity.EntityRecord) CustomerAggregate(io.spine.server.Given.CustomerAggregate) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) BoundedContext(io.spine.server.BoundedContext) CustomerAggregateRepository(io.spine.server.Given.CustomerAggregateRepository) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 34 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class StandShould method setupStandStorageWithCustomers.

private StandStorage setupStandStorageWithCustomers(Map<CustomerId, Customer> sampleCustomers, TypeUrl customerType) {
    final BoundedContext bc = BoundedContext.newBuilder().setMultitenant(isMultitenant()).build();
    final StandStorage standStorage = bc.getStorageFactory().createStandStorage();
    final ImmutableList.Builder<AggregateStateId> stateIdsBuilder = ImmutableList.builder();
    final ImmutableList.Builder<EntityRecord> recordsBuilder = ImmutableList.builder();
    for (CustomerId customerId : sampleCustomers.keySet()) {
        final AggregateStateId stateId = AggregateStateId.of(customerId, customerType);
        final Customer customer = sampleCustomers.get(customerId);
        final Any customerState = AnyPacker.pack(customer);
        final EntityRecord entityRecord = EntityRecord.newBuilder().setState(customerState).build();
        stateIdsBuilder.add(stateId);
        recordsBuilder.add(entityRecord);
        standStorage.write(stateId, entityRecord);
    }
    return standStorage;
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Customer(io.spine.test.commandservice.customer.Customer) ImmutableList(com.google.common.collect.ImmutableList) BoundedContext(io.spine.server.BoundedContext) CustomerId(io.spine.test.commandservice.customer.CustomerId) Any(com.google.protobuf.Any)

Example 35 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class StandShould method doCheckReadingProjectsById.

private void doCheckReadingProjectsById(int numberOfProjects) {
    // Define the types and values used as a test data.
    final Map<ProjectId, Project> sampleProjects = newHashMap();
    final TypeUrl projectType = TypeUrl.of(Project.class);
    fillSampleProjects(sampleProjects, numberOfProjects);
    final StandTestProjectionRepository projectionRepository = mock(StandTestProjectionRepository.class);
    when(projectionRepository.getEntityStateType()).thenReturn(projectType);
    setupExpectedFindAllBehaviour(sampleProjects, projectionRepository);
    final Stand stand = prepareStandWithProjectionRepo(projectionRepository);
    final Query readMultipleProjects = requestFactory.query().byIds(Project.class, sampleProjects.keySet());
    final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
    stand.execute(readMultipleProjects, responseObserver);
    final List<Any> messageList = checkAndGetMessageList(responseObserver);
    assertEquals(sampleProjects.size(), messageList.size());
    final Collection<Project> allCustomers = sampleProjects.values();
    for (Any singleRecord : messageList) {
        final Project unpackedSingleResult = unpack(singleRecord);
        assertTrue(allCustomers.contains(unpackedSingleResult));
    }
}
Also used : Project(io.spine.test.projection.Project) Query(io.spine.client.Query) ProjectId(io.spine.test.projection.ProjectId) TypeUrl(io.spine.type.TypeUrl) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository) 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