Search in sources :

Example 11 with Customer

use of io.spine.test.commandservice.customer.Customer 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 = GivenVersion.withNumber(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 = 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) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) QueryResponse(io.spine.client.QueryResponse) FieldMask(com.google.protobuf.FieldMask) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet)

Example 12 with Customer

use of io.spine.test.commandservice.customer.Customer in project core-java by SpineEventEngine.

the class StandShould method requestSampleCustomer.

private void requestSampleCustomer(int[] fieldIndexes, final MemoizeQueryResponseObserver observer) {
    final Stand stand = prepareStandWithAggregateRepo(createStandStorage());
    final Customer sampleCustomer = getSampleCustomer();
    final Version stateVersion = GivenVersion.withNumber(1);
    stand.update(asEnvelope(sampleCustomer.getId(), sampleCustomer, stateVersion));
    final String[] paths = new String[fieldIndexes.length];
    for (int i = 0; i < fieldIndexes.length; i++) {
        paths[i] = Customer.getDescriptor().getFields().get(fieldIndexes[i]).getFullName();
    }
    final Query customerQuery = requestFactory.query().allWithMask(Customer.class, paths);
    stand.execute(customerQuery, observer);
    verifyObserver(observer);
}
Also used : Query(io.spine.client.Query) Customer(io.spine.test.commandservice.customer.Customer) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version)

Example 13 with Customer

use of io.spine.test.commandservice.customer.Customer in project core-java by SpineEventEngine.

the class StandShould method select_entity_singleton_by_id_and_apply_field_masks.

@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void select_entity_singleton_by_id_and_apply_field_masks() {
    final Stand stand = prepareStandWithAggregateRepo(createStandStorage());
    final String customerDescriptor = Customer.getDescriptor().getFullName();
    // clashes with non-related tests.
    @SuppressWarnings("DuplicateStringLiteralInspection") final String[] paths = { customerDescriptor + ".id", customerDescriptor + ".name" };
    final FieldMask fieldMask = FieldMask.newBuilder().addAllPaths(Arrays.asList(paths)).build();
    final List<Customer> customers = new LinkedList<>();
    final int count = 10;
    for (int i = 0; i < count; i++) {
        // Has new ID each time
        final Customer customer = getSampleCustomer();
        customers.add(customer);
        final Version stateVersion = GivenVersion.withNumber(1);
        stand.update(asEnvelope(customer.getId(), customer, stateVersion));
    }
    final Set<CustomerId> ids = Collections.singleton(customers.get(0).getId());
    final Query customerQuery = requestFactory.query().byIdsWithMask(Customer.class, ids, paths);
    final MemoizeQueryResponseObserver observer = new MemoizeQueryResponseObserver();
    stand.execute(customerQuery, observer);
    final List<Any> read = observer.responseHandled.getMessagesList();
    Verify.assertSize(1, read);
    final Customer customer = unpack(read.get(0));
    assertMatches(customer, fieldMask);
    assertTrue(ids.contains(customer.getId()));
    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) LinkedList(java.util.LinkedList) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 14 with Customer

use of io.spine.test.commandservice.customer.Customer in project core-java by SpineEventEngine.

the class StandShould method retrieve_all_data_if_field_mask_is_not_set.

@Test
public void retrieve_all_data_if_field_mask_is_not_set() {
    final Stand stand = prepareStandWithAggregateRepo(createStandStorage());
    final Customer sampleCustomer = getSampleCustomer();
    final Version stateVersion = GivenVersion.withNumber(1);
    stand.update(asEnvelope(sampleCustomer.getId(), sampleCustomer, stateVersion));
    final Query customerQuery = requestFactory.query().all(Customer.class);
    // noinspection OverlyComplexAnonymousInnerClass
    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 = unpack(messages.get(0));
            for (Descriptors.FieldDescriptor field : customer.getDescriptorForType().getFields()) {
                assertTrue(customer.getField(field).equals(sampleCustomer.getField(field)));
            }
        }
    };
    stand.execute(customerQuery, observer);
    verifyObserver(observer);
}
Also used : Query(io.spine.client.Query) Customer(io.spine.test.commandservice.customer.Customer) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) QueryResponse(io.spine.client.QueryResponse) Descriptors(com.google.protobuf.Descriptors) Any(com.google.protobuf.Any) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 15 with Customer

use of io.spine.test.commandservice.customer.Customer 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 = GivenVersion.withNumber(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 = 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) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) QueryResponse(io.spine.client.QueryResponse) Any(com.google.protobuf.Any) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

Customer (io.spine.test.commandservice.customer.Customer)17 Version (io.spine.core.Version)13 GivenVersion (io.spine.core.given.GivenVersion)13 CustomerId (io.spine.test.commandservice.customer.CustomerId)13 Any (com.google.protobuf.Any)11 Test (org.junit.Test)10 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)9 Query (io.spine.client.Query)6 Map (java.util.Map)6 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)5 QueryResponse (io.spine.client.QueryResponse)4 EntityStateUpdate (io.spine.client.EntityStateUpdate)3 Topic (io.spine.client.Topic)3 FieldMask (com.google.protobuf.FieldMask)2 Target (io.spine.client.Target)2 BoundedContext (io.spine.server.BoundedContext)2 EntityRecord (io.spine.server.entity.EntityRecord)2 TypeUrl (io.spine.type.TypeUrl)2 ImmutableList (com.google.common.collect.ImmutableList)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1