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