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