Search in sources :

Example 1 with CustomerAggregate

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));
}
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)

Aggregations

Any (com.google.protobuf.Any)1 Version (io.spine.core.Version)1 GivenVersion (io.spine.core.given.GivenVersion)1 BoundedContext (io.spine.server.BoundedContext)1 CustomerAggregate (io.spine.server.Given.CustomerAggregate)1 CustomerAggregateRepository (io.spine.server.Given.CustomerAggregateRepository)1 EntityRecord (io.spine.server.entity.EntityRecord)1 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)1 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)1 Customer (io.spine.test.commandservice.customer.Customer)1 CustomerId (io.spine.test.commandservice.customer.CustomerId)1 TypeUrl (io.spine.type.TypeUrl)1 Test (org.junit.Test)1