Search in sources :

Example 6 with Query

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);
}
Also used : Stand(io.spine.server.stand.Stand) Query(io.spine.client.Query) Test(org.junit.Test)

Example 7 with Query

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;
}
Also used : Query(io.spine.client.Query) Customer(io.spine.test.commandservice.customer.Customer) StandStorage(io.spine.server.stand.StandStorage) TypeUrl(io.spine.type.TypeUrl) CustomerId(io.spine.test.commandservice.customer.CustomerId) Any(com.google.protobuf.Any) CanIgnoreReturnValue(com.google.errorprone.annotations.CanIgnoreReturnValue)

Example 8 with Query

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());
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Query(io.spine.client.Query) StandStorage(io.spine.server.stand.StandStorage) TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 9 with Query

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));
    }
}
Also used : Project(io.spine.test.projection.Project) Query(io.spine.client.Query) ProjectId(io.spine.test.projection.ProjectId) TypeUrl(io.spine.type.TypeUrl) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository) Any(com.google.protobuf.Any)

Example 10 with Query

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);
}
Also used : Query(io.spine.client.Query) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

Query (io.spine.client.Query)27 Test (org.junit.Test)23 Any (com.google.protobuf.Any)10 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)8 Target (io.spine.client.Target)6 Customer (io.spine.test.commandservice.customer.Customer)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 FieldMask (com.google.protobuf.FieldMask)5 Version (io.spine.base.Version)5 EntityFilters (io.spine.client.EntityFilters)5 QueryResponse (io.spine.client.QueryResponse)4 Message (com.google.protobuf.Message)3 EntityId (io.spine.client.EntityId)3 TestEntity (io.spine.test.client.TestEntity)3 CustomerId (io.spine.test.commandservice.customer.CustomerId)3 TypeUrl (io.spine.type.TypeUrl)3 EntityIdFilter (io.spine.client.EntityIdFilter)2 StandStorage (io.spine.server.stand.StandStorage)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 CanIgnoreReturnValue (com.google.errorprone.annotations.CanIgnoreReturnValue)1