use of io.spine.server.entity.Repository in project core-java by SpineEventEngine.
the class BoundedContextShould method not_change_storage_during_registration_if_a_repository_has_one.
@Test
public void not_change_storage_during_registration_if_a_repository_has_one() {
final ProjectAggregateRepository repository = new ProjectAggregateRepository();
final Repository spy = spy(repository);
boundedContext.register(repository);
verify(spy, never()).initStorage(any(StorageFactory.class));
}
use of io.spine.server.entity.Repository in project core-java by SpineEventEngine.
the class BoundedContextShould method propagate_registered_repositories_to_stand.
@Test
public void propagate_registered_repositories_to_stand() {
final BoundedContext boundedContext = BoundedContext.newBuilder().build();
final Stand stand = Spy.ofClass(Stand.class).on(boundedContext);
verify(stand, never()).registerTypeSupplier(any(Repository.class));
final ProjectAggregateRepository repository = new ProjectAggregateRepository();
boundedContext.register(repository);
verify(stand).registerTypeSupplier(eq(repository));
}
use of io.spine.server.entity.Repository in project core-java by SpineEventEngine.
the class AggregatePartRepositoryLookup method find.
/**
* Find the repository in the bounded context.
*
* @throws IllegalStateException if the repository was not found, or
* if not of the expected type, or
* IDs are not of the expected type
*/
<A extends AggregatePart<I, S, ?, ?>> AggregatePartRepository<I, A, ?> find() {
final Optional<Repository> optional = boundedContext.findRepository(stateClass);
if (!optional.isPresent()) {
final String errMsg = format("Unable to find repository for the state class: %s", stateClass);
throw new IllegalStateException(errMsg);
}
final Repository repo = optional.get();
checkIsAggregatePartRepository(repo);
final AggregatePartRepository<I, A, ?> result = checkIdClass((AggregatePartRepository<?, ?, ?>) repo);
return result;
}
use of io.spine.server.entity.Repository in project core-java by SpineEventEngine.
the class BoundedContextTest method sameStateRepositories.
/**
* Returns all combinations of repositories that manage entities of the same state.
*
* <p>To check whether a {@link io.spine.server.BoundedContext} really throws
* an {@code IllegalStateException} upon an attempt to register a repository that manages an
* entity of a state that a registered entity repository is already managing, all combinations
* of entities that take state as a type parameter need to be checked.
*
* <p>This method returns a stream of pairs of all such combinations, which is a Cartesian
* product of:
* <ul>
* <li>{@linkplain io.spine.server.procman.ProcessManagerRepository process manager};
* <li>{@linkplain io.spine.server.aggregate.AggregateRepository aggregate};
* <li>{@linkplain io.spine.server.projection.ProjectionRepository projection}.
* </ul>
* All of the returned repositories manage entities of the same state type.
*/
@SuppressWarnings("unused")
private static /* A method source. */
Stream<Arguments> sameStateRepositories() {
Set<Repository<?, ?>> repositories = ImmutableSet.of(DefaultRepository.of(ProjectAggregate.class), DefaultRepository.of(ProjectProjection.class), new ProjectCreationRepository());
Set<Repository<?, ?>> sameStateRepositories = ImmutableSet.of(DefaultRepository.of(AnotherProjectAggregate.class), DefaultRepository.of(FinishedProjectProjection.class), DefaultRepository.of(ProjectRemovalProcman.class));
var cartesianProduct = Sets.cartesianProduct(repositories, sameStateRepositories);
var result = cartesianProduct.stream().map(repos -> Arguments.of(repos.get(0), repos.get(1)));
return result;
}
Aggregations