Search in sources :

Example 6 with BoundedContext

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

the class StandPostShould method aggregateRepositoryDispatch.

private static BoundedContextAction aggregateRepositoryDispatch() {
    return new BoundedContextAction() {

        @Override
        public void perform(BoundedContext context) {
            // Init repository
            final AggregateRepository<?, ?> repository = Given.aggregateRepo(context);
            repository.initStorage(storageFactory(context.isMultitenant()));
            try {
                // Mock aggregate and mock stand are not able to handle events
                // returned after command handling.
                // This causes IllegalStateException to be thrown.
                // Note that this is not the end of a test case,
                // so we can't just "expect=IllegalStateException".
                final CommandEnvelope cmd = CommandEnvelope.of(Given.validCommand());
                repository.dispatch(cmd);
            } catch (IllegalStateException e) {
                // Proceed crash if it's not.
                if (!e.getMessage().contains("No record found for command ID: EMPTY")) {
                    throw e;
                }
            }
        }
    };
}
Also used : CommandEnvelope(io.spine.envelope.CommandEnvelope) BoundedContext(io.spine.server.BoundedContext)

Example 7 with BoundedContext

use of io.spine.server.BoundedContext 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 io.spine.server.Given.CustomerAggregateRepository customerAggregateRepo = new io.spine.server.Given.CustomerAggregateRepository(boundedContext);
    stand.registerTypeSupplier(customerAggregateRepo);
    final StandTestProjectionRepository projectProjectionRepo = new StandTestProjectionRepository(boundedContext);
    stand.registerTypeSupplier(projectProjectionRepo);
    return stand;
}
Also used : StreamObservers.noOpObserver(io.spine.io.StreamObservers.noOpObserver) StreamObserver(io.grpc.stub.StreamObserver) MemoizingObserver(io.spine.io.StreamObservers.MemoizingObserver) StreamObservers.memoizingObserver(io.spine.io.StreamObservers.memoizingObserver) BoundedContext(io.spine.server.BoundedContext) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository)

Example 8 with BoundedContext

use of io.spine.server.BoundedContext 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));
}
Also used : StreamObservers.noOpObserver(io.spine.io.StreamObservers.noOpObserver) StreamObserver(io.grpc.stub.StreamObserver) MemoizingObserver(io.spine.io.StreamObservers.MemoizingObserver) StreamObservers.memoizingObserver(io.spine.io.StreamObservers.memoizingObserver) 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) Version(io.spine.base.Version) StandStorage(io.spine.server.stand.StandStorage) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 9 with BoundedContext

use of io.spine.server.BoundedContext 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 io.spine.server.Given.CustomerAggregateRepository customerAggregateRepo = new io.spine.server.Given.CustomerAggregateRepository(boundedContext);
    stand.registerTypeSupplier(customerAggregateRepo);
    final Descriptors.Descriptor customerEntityDescriptor = Customer.getDescriptor();
    checkHasExactlyOne(stand.getExposedTypes(), customerEntityDescriptor);
    checkHasExactlyOne(stand.getExposedAggregateTypes(), customerEntityDescriptor);
    @SuppressWarnings("LocalVariableNamingConvention") final io.spine.server.Given.CustomerAggregateRepository anotherCustomerAggregateRepo = new io.spine.server.Given.CustomerAggregateRepository(boundedContext);
    stand.registerTypeSupplier(anotherCustomerAggregateRepo);
    checkHasExactlyOne(stand.getExposedTypes(), customerEntityDescriptor);
    checkHasExactlyOne(stand.getExposedAggregateTypes(), customerEntityDescriptor);
}
Also used : StreamObservers.noOpObserver(io.spine.io.StreamObservers.noOpObserver) StreamObserver(io.grpc.stub.StreamObserver) MemoizingObserver(io.spine.io.StreamObservers.MemoizingObserver) StreamObservers.memoizingObserver(io.spine.io.StreamObservers.memoizingObserver) BoundedContext(io.spine.server.BoundedContext) Descriptors(com.google.protobuf.Descriptors) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 10 with BoundedContext

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

the class StandShould method use_provided_executor_upon_update_of_watched_type.

@Test
public void use_provided_executor_upon_update_of_watched_type() {
    final Executor executor = mock(Executor.class);
    final BoundedContext boundedContext = BoundedContext.newBuilder().setStand(Stand.newBuilder().setCallbackExecutor(executor)).build();
    final Stand stand = boundedContext.getStand();
    final StandTestProjectionRepository standTestProjectionRepo = new StandTestProjectionRepository(boundedContext);
    stand.registerTypeSupplier(standTestProjectionRepo);
    final Topic projectProjections = requestFactory.topic().allOf(Project.class);
    final MemoizingObserver<Subscription> observer = memoizingObserver();
    stand.subscribe(projectProjections, observer);
    final Subscription subscription = observer.firstResponse();
    final StreamObserver<Response> noopObserver = noOpObserver();
    stand.activate(subscription, emptyUpdateCallback(), noopObserver);
    assertNotNull(subscription);
    verify(executor, never()).execute(any(Runnable.class));
    final ProjectId someId = ProjectId.getDefaultInstance();
    final Version stateVersion = Tests.newVersionWithNumber(1);
    stand.update(asEnvelope(someId, Project.getDefaultInstance(), stateVersion));
    verify(executor, times(1)).execute(any(Runnable.class));
}
Also used : QueryResponse(io.spine.client.QueryResponse) Response(io.spine.base.Response) Executor(java.util.concurrent.Executor) Version(io.spine.base.Version) ProjectId(io.spine.test.projection.ProjectId) BoundedContext(io.spine.server.BoundedContext) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

BoundedContext (io.spine.server.BoundedContext)26 Test (org.junit.Test)16 Before (org.junit.Before)5 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)4 StreamObserver (io.grpc.stub.StreamObserver)3 MemoizingObserver (io.spine.io.StreamObservers.MemoizingObserver)3 StreamObservers.memoizingObserver (io.spine.io.StreamObservers.memoizingObserver)3 StreamObservers.noOpObserver (io.spine.io.StreamObservers.noOpObserver)3 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)3 NullPointerTester (com.google.common.testing.NullPointerTester)2 Any (com.google.protobuf.Any)2 Version (io.spine.base.Version)2 CommandEnvelope (io.spine.envelope.CommandEnvelope)2 CommandBus (io.spine.server.commandbus.CommandBus)2 EventStore (io.spine.server.event.EventStore)2 ProjectionRepository (io.spine.server.projection.ProjectionRepository)2 ProjectId (io.spine.test.projection.ProjectId)2 MultiTenant.newBoundedContext (io.spine.testdata.TestBoundedContextFactory.MultiTenant.newBoundedContext)2 TypeUrl (io.spine.type.TypeUrl)2 Executor (java.util.concurrent.Executor)2