use of io.spine.test.commandservice.customer.CustomerId in project core-java by SpineEventEngine.
the class StandShould method trigger_subscription_callbacks_matching_by_id.
@Test
public void trigger_subscription_callbacks_matching_by_id() {
final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
final Map<CustomerId, Customer> sampleCustomers = fillSampleCustomers(10);
final Topic someCustomers = requestFactory.topic().someOf(Customer.class, sampleCustomers.keySet());
final Map<CustomerId, Customer> callbackStates = newHashMap();
final MemoizeEntityUpdateCallback callback = new MemoizeEntityUpdateCallback() {
@Override
public void onStateChanged(EntityStateUpdate update) {
super.onStateChanged(update);
final Customer customerInCallback = unpack(update.getState());
final CustomerId customerIdInCallback = unpack(update.getId());
callbackStates.put(customerIdInCallback, customerInCallback);
}
};
subscribeAndActivate(stand, someCustomers, callback);
for (Map.Entry<CustomerId, Customer> sampleEntry : sampleCustomers.entrySet()) {
final CustomerId customerId = sampleEntry.getKey();
final Customer customer = sampleEntry.getValue();
final Version stateVersion = GivenVersion.withNumber(1);
stand.update(asEnvelope(customerId, customer, stateVersion));
}
assertEquals(newHashMap(sampleCustomers), callbackStates);
}
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 = GivenVersion.withNumber(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(EntityStateUpdate.class));
}
}
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 = GivenVersion.withNumber(1);
stand.update(asEnvelope(customerId, customer, stateVersion));
verify(callback, never()).onStateChanged(any(EntityStateUpdate.class));
}
use of io.spine.test.commandservice.customer.CustomerId in project core-java by SpineEventEngine.
the class StandShould method fillSampleCustomers.
protected static Map<CustomerId, Customer> fillSampleCustomers(int numberOfCustomers) {
final Map<CustomerId, Customer> sampleCustomers = newHashMap();
@SuppressWarnings("UnsecureRandomNumberGeneration") final Random randomizer = new Random(Integer.MAX_VALUE);
for (int customerIndex = 0; customerIndex < numberOfCustomers; customerIndex++) {
final int numericId = randomizer.nextInt();
final CustomerId customerId = customerIdFor(numericId);
final Customer customer = Customer.newBuilder().setName(PersonName.newBuilder().setGivenName(String.valueOf(numericId))).build();
sampleCustomers.put(customerId, customer);
}
return sampleCustomers;
}
use of io.spine.test.commandservice.customer.CustomerId in project core-java by SpineEventEngine.
the class MultiTenantStandShould method not_trigger_updates_of_aggregate_records_for_another_tenant_subscriptions.
@Test
public void not_trigger_updates_of_aggregate_records_for_another_tenant_subscriptions() {
final StandStorage standStorage = InMemoryStorageFactory.newInstance(newName(getClass().getSimpleName()), isMultitenant()).createStandStorage();
final Stand stand = prepareStandWithAggregateRepo(standStorage);
// --- Default Tenant
final ActorRequestFactory requestFactory = getRequestFactory();
final MemoizeEntityUpdateCallback defaultTenantCallback = subscribeToAllOf(stand, requestFactory, Customer.class);
// --- Another Tenant
final TenantId anotherTenant = newUuid();
final ActorRequestFactory anotherFactory = createRequestFactory(anotherTenant);
final MemoizeEntityUpdateCallback anotherCallback = subscribeToAllOf(stand, anotherFactory, Customer.class);
// Trigger updates in Default Tenant.
final Map.Entry<CustomerId, Customer> sampleData = fillSampleCustomers(1).entrySet().iterator().next();
final CustomerId customerId = sampleData.getKey();
final Customer customer = sampleData.getValue();
final Version stateVersion = GivenVersion.withNumber(1);
stand.update(asEnvelope(customerId, customer, stateVersion));
final Any packedState = AnyPacker.pack(customer);
// Verify that Default Tenant callback has got the update.
assertEquals(packedState, defaultTenantCallback.getNewEntityState());
// And Another Tenant callback has not been called.
assertEquals(null, anotherCallback.getNewEntityState());
}
Aggregations