Search in sources :

Example 6 with QueryResponse

use of io.spine.client.QueryResponse in project core-java by SpineEventEngine.

the class StandShould method doCheckReadingCustomersByIdAndFieldMask.

@SuppressWarnings("MethodWithMultipleLoops")
private void doCheckReadingCustomersByIdAndFieldMask(String... paths) {
    final Stand stand = prepareStandWithAggregateRepo(createStandStorage());
    final int querySize = 2;
    final Set<CustomerId> ids = new HashSet<>();
    for (int i = 0; i < querySize; i++) {
        final Customer customer = getSampleCustomer().toBuilder().setId(CustomerId.newBuilder().setNumber(i)).build();
        final Version stateVersion = Tests.newVersionWithNumber(1);
        stand.update(asEnvelope(customer.getId(), customer, stateVersion));
        ids.add(customer.getId());
    }
    final Query customerQuery = requestFactory.query().byIdsWithMask(Customer.class, ids, paths);
    final FieldMask fieldMask = FieldMask.newBuilder().addAllPaths(Arrays.asList(paths)).build();
    final MemoizeQueryResponseObserver observer = new MemoizeQueryResponseObserver() {

        @Override
        public void onNext(QueryResponse value) {
            super.onNext(value);
            final List<Any> messages = value.getMessagesList();
            Verify.assertSize(ids.size(), messages);
            for (Any message : messages) {
                final Customer customer = AnyPacker.unpack(message);
                assertNotEquals(customer, null);
                assertMatches(customer, fieldMask);
            }
        }
    };
    stand.execute(customerQuery, observer);
    verifyObserver(observer);
}
Also used : Query(io.spine.client.Query) Customer(io.spine.test.commandservice.customer.Customer) CustomerId(io.spine.test.commandservice.customer.CustomerId) Any(com.google.protobuf.Any) Version(io.spine.base.Version) QueryResponse(io.spine.client.QueryResponse) FieldMask(com.google.protobuf.FieldMask) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet)

Example 7 with QueryResponse

use of io.spine.client.QueryResponse in project core-java by SpineEventEngine.

the class StandShould method getDuplicateCostumerStreamObserver.

private static MemoizeQueryResponseObserver getDuplicateCostumerStreamObserver() {
    return new MemoizeQueryResponseObserver() {

        @Override
        public void onNext(QueryResponse value) {
            super.onNext(value);
            final List<Any> messages = value.getMessagesList();
            assertFalse(messages.isEmpty());
            final Customer customer = AnyPacker.unpack(messages.get(0));
            final Customer sampleCustomer = getSampleCustomer();
            assertEquals(sampleCustomer.getName(), customer.getName());
            assertEquals(sampleCustomer.getNicknamesList(), customer.getNicknamesList());
            assertTrue(customer.hasId());
        }
    };
}
Also used : Customer(io.spine.test.commandservice.customer.Customer) QueryResponse(io.spine.client.QueryResponse) Any(com.google.protobuf.Any)

Example 8 with QueryResponse

use of io.spine.client.QueryResponse in project core-java by SpineEventEngine.

the class StandShould method checkAndGetMessageList.

private static List<Any> checkAndGetMessageList(MemoizeQueryResponseObserver responseObserver) {
    assertTrue("Query has not completed successfully", responseObserver.isCompleted);
    assertNull("Throwable has been caught upon query execution", responseObserver.throwable);
    final QueryResponse response = responseObserver.responseHandled;
    assertEquals("Query response is not OK", Responses.ok(), response.getResponse());
    assertNotNull("Query response must not be null", response);
    final List<Any> messageList = response.getMessagesList();
    assertNotNull("Query response has null message list", messageList);
    return messageList;
}
Also used : QueryResponse(io.spine.client.QueryResponse) Any(com.google.protobuf.Any)

Example 9 with QueryResponse

use of io.spine.client.QueryResponse in project core-java by SpineEventEngine.

the class StandShould method handle_mistakes_in_query_silently.

@Test
public void handle_mistakes_in_query_silently() {
    //noinspection ZeroLengthArrayAllocation
    final Stand stand = prepareStandWithAggregateRepo(createStandStorage());
    final Customer sampleCustomer = getSampleCustomer();
    final Version stateVersion = Tests.newVersionWithNumber(1);
    stand.update(asEnvelope(sampleCustomer.getId(), sampleCustomer, stateVersion));
    // FieldMask with invalid type URLs.
    final String[] paths = { "invalid_type_url_example", Project.getDescriptor().getFields().get(2).getFullName() };
    final Query customerQuery = requestFactory.query().allWithMask(Customer.class, paths);
    final MemoizeQueryResponseObserver observer = new MemoizeQueryResponseObserver() {

        @Override
        public void onNext(QueryResponse value) {
            super.onNext(value);
            final List<Any> messages = value.getMessagesList();
            assertFalse(messages.isEmpty());
            final Customer customer = AnyPacker.unpack(messages.get(0));
            assertNotEquals(customer, null);
            assertFalse(customer.hasId());
            assertFalse(customer.hasName());
            assertTrue(customer.getNicknamesList().isEmpty());
        }
    };
    stand.execute(customerQuery, observer);
    verifyObserver(observer);
}
Also used : Query(io.spine.client.Query) Customer(io.spine.test.commandservice.customer.Customer) Version(io.spine.base.Version) QueryResponse(io.spine.client.QueryResponse) Any(com.google.protobuf.Any) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

QueryResponse (io.spine.client.QueryResponse)9 Any (com.google.protobuf.Any)6 Query (io.spine.client.Query)4 Customer (io.spine.test.commandservice.customer.Customer)4 Version (io.spine.base.Version)3 Test (org.junit.Test)3 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 Descriptors (com.google.protobuf.Descriptors)1 FieldMask (com.google.protobuf.FieldMask)1 ActorRequestFactory (io.spine.client.ActorRequestFactory)1 QueryOperation (io.spine.server.tenant.QueryOperation)1 CustomerId (io.spine.test.commandservice.customer.CustomerId)1 TypeUrl (io.spine.type.TypeUrl)1 TenantId (io.spine.users.TenantId)1 HashSet (java.util.HashSet)1