use of io.spine.server.stand.Given.StandTestProjectionRepository 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();
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 = GivenVersion.withNumber(1);
stand.update(asEnvelope(someId, Project.getDefaultInstance(), stateVersion));
verify(executor, times(1)).execute(any(Runnable.class));
}
use of io.spine.server.stand.Given.StandTestProjectionRepository 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 CustomerAggregateRepository customerAggregateRepo = new CustomerAggregateRepository();
stand.registerTypeSupplier(customerAggregateRepo);
final StandTestProjectionRepository projectProjectionRepo = new StandTestProjectionRepository();
stand.registerTypeSupplier(projectProjectionRepo);
return stand;
}
use of io.spine.server.stand.Given.StandTestProjectionRepository in project core-java by SpineEventEngine.
the class StandShould method doCheckReadingProjectsById.
private void doCheckReadingProjectsById(int numberOfProjects) {
// Define the types and values used as a test data.
final Map<ProjectId, Project> sampleProjects = newHashMap();
final TypeUrl projectType = TypeUrl.of(Project.class);
fillSampleProjects(sampleProjects, numberOfProjects);
final StandTestProjectionRepository projectionRepository = mock(StandTestProjectionRepository.class);
when(projectionRepository.getEntityStateType()).thenReturn(projectType);
setupExpectedFindAllBehaviour(sampleProjects, projectionRepository);
final Stand stand = prepareStandWithProjectionRepo(projectionRepository);
final Query readMultipleProjects = requestFactory.query().byIds(Project.class, sampleProjects.keySet());
final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
stand.execute(readMultipleProjects, responseObserver);
final List<Any> messageList = checkAndGetMessageList(responseObserver);
assertEquals(sampleProjects.size(), messageList.size());
final Collection<Project> allCustomers = sampleProjects.values();
for (Any singleRecord : messageList) {
final Project unpackedSingleResult = unpack(singleRecord);
assertTrue(allCustomers.contains(unpackedSingleResult));
}
}
use of io.spine.server.stand.Given.StandTestProjectionRepository in project core-java by SpineEventEngine.
the class StandShould method register_projection_repositories.
@Test
public void register_projection_repositories() {
final boolean multitenant = isMultitenant();
final BoundedContext boundedContext = BoundedContext.newBuilder().setMultitenant(multitenant).build();
final Stand stand = boundedContext.getStand();
checkTypesEmpty(stand);
final StandTestProjectionRepository standTestProjectionRepo = new StandTestProjectionRepository();
stand.registerTypeSupplier(standTestProjectionRepo);
checkHasExactlyOne(stand.getExposedTypes(), Project.getDescriptor());
final ImmutableSet<TypeUrl> knownAggregateTypes = stand.getExposedAggregateTypes();
// As we registered a projection repo, known aggregate types should be still empty.
assertTrue("For some reason an aggregate type was registered", knownAggregateTypes.isEmpty());
final StandTestProjectionRepository anotherTestProjectionRepo = new StandTestProjectionRepository();
stand.registerTypeSupplier(anotherTestProjectionRepo);
checkHasExactlyOne(stand.getExposedTypes(), Project.getDescriptor());
}
Aggregations