Search in sources :

Example 1 with ProjectAggregateRepository

use of io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository in project core-java by SpineEventEngine.

the class BoundedContextShould method registerAll.

/**
 * Registers all test repositories, handlers etc.
 */
private void registerAll() {
    final ProjectAggregateRepository repo = new ProjectAggregateRepository();
    boundedContext.register(repo);
    boundedContext.getEventBus().register(subscriber);
    handlersRegistered = true;
}
Also used : AnotherProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository) ProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository)

Example 2 with ProjectAggregateRepository

use of io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository in project core-java by SpineEventEngine.

the class BoundedContextShould method register_AggregateRepository.

@Test
public void register_AggregateRepository() {
    final ProjectAggregateRepository repository = new ProjectAggregateRepository();
    boundedContext.register(repository);
}
Also used : AnotherProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository) ProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository) Test(org.junit.Test)

Example 3 with ProjectAggregateRepository

use of io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository in project core-java by SpineEventEngine.

the class BoundedContextShould method throw_NPE_when_registering_repository_and_default_state_is_null.

/**
 * This test checks, whether {@code BoundedContext} properly handles the issues upon repository
 * registration.
 *
 * <p>In particular, we intentionally break an interaction between {@code Model}
 * and a {@code BoundedContext} on attempt to ensure there is an entity default state present
 * for the given repository instance.
 *
 * <p>The expected behavior of {@code BoundedContext} instance is to fail fast in case such
 * a default state is absent.
 *
 * <p>In real-life this use case can never happen given the current implementation of
 * {@code Model} and {@code BoundedContext}. However, previously such an issue was caught.
 * Therefore this test case ensures it's never happening again.
 */
@Test(expected = NullPointerException.class)
public void throw_NPE_when_registering_repository_and_default_state_is_null() {
    final ProjectAggregateRepository repository = new ProjectAggregateRepository();
    final Map mockMap = mock(Map.class);
    when(mockMap.get(any())).thenReturn(null);
    final Object defaultStateRegistry = getObjectFromNestedEnumField(DEFAULT_STATE_REGISTRY_FULL_CLASS_NAME, DEFAULT_STATE_REGISTRY_SINGLETON_FIELD_NAME);
    injectField(defaultStateRegistry, DEFAULT_STATES_FIELD_NAME, mockMap);
    try {
        boundedContext.register(repository);
    } catch (NullPointerException e) {
        // reassigning mock map to real map, to prevent failing other tests
        final Map<Class<? extends Entity>, Message> defaultState = newConcurrentMap();
        injectField(defaultStateRegistry, DEFAULT_STATES_FIELD_NAME, defaultState);
        throw e;
    }
}
Also used : AnotherProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository) ProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository) Map(java.util.Map) Maps.newConcurrentMap(com.google.common.collect.Maps.newConcurrentMap) Test(org.junit.Test)

Example 4 with ProjectAggregateRepository

use of io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository 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 5 with ProjectAggregateRepository

use of io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository in project core-java by SpineEventEngine.

the class BoundedContextShould method not_allow_two_aggregate_repositories_with_aggregates_with_the_same_state.

@Test(expected = IllegalStateException.class)
public void not_allow_two_aggregate_repositories_with_aggregates_with_the_same_state() {
    final ProjectAggregateRepository repository = new ProjectAggregateRepository();
    boundedContext.register(repository);
    final AnotherProjectAggregateRepository anotherRepo = new AnotherProjectAggregateRepository();
    boundedContext.register(anotherRepo);
}
Also used : AnotherProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository) ProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository) AnotherProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository) Test(org.junit.Test)

Aggregations

AnotherProjectAggregateRepository (io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository)7 ProjectAggregateRepository (io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository)7 Test (org.junit.Test)6 ProjectReportRepository (io.spine.server.bc.given.BoundedContextTestEnv.ProjectReportRepository)2 SecretProjectRepository (io.spine.server.bc.given.BoundedContextTestEnv.SecretProjectRepository)2 Repository (io.spine.server.entity.Repository)2 Maps.newConcurrentMap (com.google.common.collect.Maps.newConcurrentMap)1 BoundedContext (io.spine.server.BoundedContext)1 Stand (io.spine.server.stand.Stand)1 StorageFactory (io.spine.server.storage.StorageFactory)1 Map (java.util.Map)1