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