use of io.spine.server.Given.CustomerAggregate 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));
}
Aggregations