Search in sources :

Example 1 with Repository

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));
}
Also used : ProjectReportRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectReportRepository) AnotherProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository) SecretProjectRepository(io.spine.server.bc.given.BoundedContextTestEnv.SecretProjectRepository) Repository(io.spine.server.entity.Repository) ProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository) StorageFactory(io.spine.server.storage.StorageFactory) AnotherProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository) ProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository) Test(org.junit.Test)

Example 2 with Repository

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));
}
Also used : Stand(io.spine.server.stand.Stand) ProjectReportRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectReportRepository) AnotherProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository) SecretProjectRepository(io.spine.server.bc.given.BoundedContextTestEnv.SecretProjectRepository) Repository(io.spine.server.entity.Repository) ProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository) AnotherProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository) ProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 3 with 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;
}
Also used : Repository(io.spine.server.entity.Repository)

Example 4 with Repository

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;
}
Also used : AnotherProjectAggregate(io.spine.server.bc.given.AnotherProjectAggregate) ProjectAggregate(io.spine.server.bc.given.ProjectAggregate) Repository(io.spine.server.entity.Repository) SecretProjectRepository(io.spine.server.bc.given.SecretProjectRepository) ProjectCreationRepository(io.spine.server.bc.given.ProjectCreationRepository) ProjectCreationRepository(io.spine.server.bc.given.ProjectCreationRepository) ProjectRemovalProcman(io.spine.server.bc.given.ProjectRemovalProcman) FinishedProjectProjection(io.spine.server.bc.given.FinishedProjectProjection) ProjectProjection(io.spine.server.bc.given.ProjectProjection) FinishedProjectProjection(io.spine.server.bc.given.FinishedProjectProjection) AnotherProjectAggregate(io.spine.server.bc.given.AnotherProjectAggregate)

Aggregations

Repository (io.spine.server.entity.Repository)4 AnotherProjectAggregateRepository (io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository)2 ProjectAggregateRepository (io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository)2 ProjectReportRepository (io.spine.server.bc.given.BoundedContextTestEnv.ProjectReportRepository)2 SecretProjectRepository (io.spine.server.bc.given.BoundedContextTestEnv.SecretProjectRepository)2 Test (org.junit.Test)2 BoundedContext (io.spine.server.BoundedContext)1 AnotherProjectAggregate (io.spine.server.bc.given.AnotherProjectAggregate)1 FinishedProjectProjection (io.spine.server.bc.given.FinishedProjectProjection)1 ProjectAggregate (io.spine.server.bc.given.ProjectAggregate)1 ProjectCreationRepository (io.spine.server.bc.given.ProjectCreationRepository)1 ProjectProjection (io.spine.server.bc.given.ProjectProjection)1 ProjectRemovalProcman (io.spine.server.bc.given.ProjectRemovalProcman)1 SecretProjectRepository (io.spine.server.bc.given.SecretProjectRepository)1 Stand (io.spine.server.stand.Stand)1 StorageFactory (io.spine.server.storage.StorageFactory)1