Search in sources :

Example 1 with CustomerAggregateRepository

use of io.spine.server.Given.CustomerAggregateRepository in project core-java by SpineEventEngine.

the class StandShould method register_aggregate_repositories.

@Test
public void register_aggregate_repositories() {
    final BoundedContext boundedContext = BoundedContext.newBuilder().build();
    final Stand stand = boundedContext.getStand();
    checkTypesEmpty(stand);
    final CustomerAggregateRepository customerAggregateRepo = new CustomerAggregateRepository();
    stand.registerTypeSupplier(customerAggregateRepo);
    final Descriptors.Descriptor customerEntityDescriptor = Customer.getDescriptor();
    checkHasExactlyOne(stand.getExposedTypes(), customerEntityDescriptor);
    checkHasExactlyOne(stand.getExposedAggregateTypes(), customerEntityDescriptor);
    @SuppressWarnings("LocalVariableNamingConvention") final CustomerAggregateRepository anotherCustomerAggregateRepo = new CustomerAggregateRepository();
    stand.registerTypeSupplier(anotherCustomerAggregateRepo);
    checkHasExactlyOne(stand.getExposedTypes(), customerEntityDescriptor);
    checkHasExactlyOne(stand.getExposedAggregateTypes(), customerEntityDescriptor);
}
Also used : BoundedContext(io.spine.server.BoundedContext) Descriptors(com.google.protobuf.Descriptors) CustomerAggregateRepository(io.spine.server.Given.CustomerAggregateRepository) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 2 with CustomerAggregateRepository

use of io.spine.server.Given.CustomerAggregateRepository 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 3 with CustomerAggregateRepository

use of io.spine.server.Given.CustomerAggregateRepository in project core-java by SpineEventEngine.

the class StandShould method prepareStandWithAggregateRepo.

protected Stand prepareStandWithAggregateRepo(StandStorage standStorage) {
    final BoundedContext boundedContext = BoundedContext.newBuilder().setMultitenant(multitenant).setStand(Stand.newBuilder().setStorage(standStorage)).build();
    final Stand stand = boundedContext.getStand();
    assertNotNull(stand);
    final CustomerAggregateRepository customerAggregateRepo = new CustomerAggregateRepository();
    stand.registerTypeSupplier(customerAggregateRepo);
    final StandTestProjectionRepository projectProjectionRepo = new StandTestProjectionRepository();
    stand.registerTypeSupplier(projectProjectionRepo);
    return stand;
}
Also used : BoundedContext(io.spine.server.BoundedContext) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository) CustomerAggregateRepository(io.spine.server.Given.CustomerAggregateRepository)

Aggregations

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