use of io.spine.test.commandservice.customer.CustomerId 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 = AnyPacker.unpack(singleRecord);
assertTrue(allCustomers.contains(unpackedSingleResult));
}
return stand;
}
use of io.spine.test.commandservice.customer.CustomerId in project core-java by SpineEventEngine.
the class StandShould method do_not_trigger_subscription_callbacks_in_case_of_another_type_criterion_mismatch.
@Test
public void do_not_trigger_subscription_callbacks_in_case_of_another_type_criterion_mismatch() {
final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
final Target allProjects = Targets.allOf(Project.class);
final MemoizeEntityUpdateCallback callback = subscribeWithCallback(stand, allProjects);
final Map.Entry<CustomerId, Customer> sampleData = fillSampleCustomers(1).entrySet().iterator().next();
final CustomerId customerId = sampleData.getKey();
final Customer customer = sampleData.getValue();
final Version stateVersion = Tests.newVersionWithNumber(1);
stand.update(asEnvelope(customerId, customer, stateVersion));
verify(callback, never()).onStateChanged(any(Any.class));
}
use of io.spine.test.commandservice.customer.CustomerId in project core-java by SpineEventEngine.
the class StandShould method trigger_each_subscription_callback_once_for_multiple_subscriptions.
@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void trigger_each_subscription_callback_once_for_multiple_subscriptions() {
final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
final Target allCustomers = Targets.allOf(Customer.class);
final Set<MemoizeEntityUpdateCallback> callbacks = newHashSet();
final int totalCallbacks = 100;
for (int callbackIndex = 0; callbackIndex < totalCallbacks; callbackIndex++) {
final MemoizeEntityUpdateCallback callback = subscribeWithCallback(stand, allCustomers);
callbacks.add(callback);
}
final Map.Entry<CustomerId, Customer> sampleData = fillSampleCustomers(1).entrySet().iterator().next();
final CustomerId customerId = sampleData.getKey();
final Customer customer = sampleData.getValue();
final Version stateVersion = Tests.newVersionWithNumber(1);
stand.update(asEnvelope(customerId, customer, stateVersion));
final Any packedState = AnyPacker.pack(customer);
for (MemoizeEntityUpdateCallback callback : callbacks) {
assertEquals(packedState, callback.newEntityState);
verify(callback, times(1)).onStateChanged(any(Any.class));
}
}
use of io.spine.test.commandservice.customer.CustomerId 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 io.spine.server.Given.CustomerAggregateRepository customerAggregateRepo = new io.spine.server.Given.CustomerAggregateRepository(boundedContext);
stand.registerTypeSupplier(customerAggregateRepo);
final int numericIdValue = 17;
final CustomerId customerId = customerIdFor(numericIdValue);
final io.spine.server.Given.CustomerAggregate customerAggregate = customerAggregateRepo.create(customerId);
final Customer customerState = customerAggregate.getState();
final TypeUrl customerType = TypeUrl.of(Customer.class);
final Version stateVersion = Tests.newVersionWithNumber(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));
}
use of io.spine.test.commandservice.customer.CustomerId in project core-java by SpineEventEngine.
the class StandShould method setupStandStorageWithCustomers.
private StandStorage setupStandStorageWithCustomers(Map<CustomerId, Customer> sampleCustomers, TypeUrl customerType) {
final StandStorage standStorage = StorageFactorySwitch.get(isMultitenant()).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;
}
Aggregations