use of io.spine.client.Query in project core-java by SpineEventEngine.
the class QueryServiceShould method dispatch_queries_to_proper_bounded_context.
@Test
public void dispatch_queries_to_proper_bounded_context() {
final Query query = Given.AQuery.readAllProjects();
final Stand stand = projectsContext.getStand();
service.read(query, responseObserver);
checkOkResponse(responseObserver);
verify(stand).execute(query, responseObserver);
verify(customersContext.getStand(), never()).execute(query, responseObserver);
}
use of io.spine.client.Query in project core-java by SpineEventEngine.
the class StandShould method doCheckReadingCustomersById.
@CanIgnoreReturnValue
Stand doCheckReadingCustomersById(int numberOfCustomers) {
// Define the types and values used as a test data.
final TypeUrl customerType = TypeUrl.of(Customer.class);
final Map<CustomerId, Customer> sampleCustomers = fillSampleCustomers(numberOfCustomers);
// Prepare the stand and its storage to act.
final StandStorage standStorage = setupStandStorageWithCustomers(sampleCustomers, customerType);
final Stand stand = prepareStandWithAggregateRepo(standStorage);
triggerMultipleUpdates(sampleCustomers, stand);
final Query readMultipleCustomers = requestFactory.query().byIds(Customer.class, sampleCustomers.keySet());
final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
stand.execute(readMultipleCustomers, responseObserver);
final List<Any> messageList = checkAndGetMessageList(responseObserver);
assertEquals(sampleCustomers.size(), messageList.size());
final Collection<Customer> allCustomers = sampleCustomers.values();
for (Any singleRecord : messageList) {
final Customer unpackedSingleResult = AnyPacker.unpack(singleRecord);
assertTrue(allCustomers.contains(unpackedSingleResult));
}
return stand;
}
use of io.spine.client.Query in project core-java by SpineEventEngine.
the class StandShould method return_empty_list_for_aggregate_reads_with_filters_not_set.
@Test
public void return_empty_list_for_aggregate_reads_with_filters_not_set() {
final StandStorage standStorageMock = mock(StandStorage.class);
// Return non-empty results on any storage read call.
final EntityRecord someRecord = EntityRecord.getDefaultInstance();
final ImmutableList<EntityRecord> nonEmptyList = ImmutableList.<EntityRecord>builder().add(someRecord).build();
when(standStorageMock.readAllByType(any(TypeUrl.class))).thenReturn(nonEmptyList);
when(standStorageMock.read(any(AggregateStateId.class))).thenReturn(Optional.of(someRecord));
when(standStorageMock.readAll()).thenReturn(Maps.<AggregateStateId, EntityRecord>newHashMap());
when(standStorageMock.readMultiple(ArgumentMatchers.<AggregateStateId>anyIterable())).thenReturn(nonEmptyList);
final Stand stand = prepareStandWithAggregateRepo(standStorageMock);
final Query noneOfCustomersQuery = requestFactory.query().byIds(Customer.class, Collections.<Message>emptySet());
final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
stand.execute(noneOfCustomersQuery, responseObserver);
verifyObserver(responseObserver);
final List<Any> messageList = checkAndGetMessageList(responseObserver);
assertTrue("Query returned a non-empty response message list " + "though the filter was not set", messageList.isEmpty());
}
use of io.spine.client.Query 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 = AnyPacker.unpack(singleRecord);
assertTrue(allCustomers.contains(unpackedSingleResult));
}
}
use of io.spine.client.Query in project core-java by SpineEventEngine.
the class StandShould method return_empty_list_for_aggregate_read_by_ids_on_empty_stand_storage.
@Test
public void return_empty_list_for_aggregate_read_by_ids_on_empty_stand_storage() {
final Query readCustomersById = requestFactory.query().byIds(Customer.class, newHashSet(customerIdFor(1), customerIdFor(2)));
checkEmptyResultForTargetOnEmptyStorage(readCustomersById);
}
Aggregations