Search in sources :

Example 11 with CustomerId

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

the class StandShould method trigger_subscription_callback_upon_update_of_aggregate.

@Test
public void trigger_subscription_callback_upon_update_of_aggregate() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Topic allCustomers = requestFactory.topic().allOf(Customer.class);
    final MemoizeEntityUpdateCallback memoizeCallback = new MemoizeEntityUpdateCallback();
    subscribeAndActivate(stand, allCustomers, memoizeCallback);
    assertNull(memoizeCallback.newEntityState);
    final Map.Entry<CustomerId, Customer> sampleData = fillSampleCustomers(1).entrySet().iterator().next();
    final CustomerId customerId = sampleData.getKey();
    final Customer customer = sampleData.getValue();
    final Version stateVersion = Tests.newVersionWithNumber(1);
    stand.update(asEnvelope(customerId, customer, stateVersion));
    final Any packedState = AnyPacker.pack(customer);
    assertEquals(packedState, memoizeCallback.newEntityState);
}
Also used : Customer(io.spine.test.commandservice.customer.Customer) Version(io.spine.base.Version) StandStorage(io.spine.server.stand.StandStorage) CustomerId(io.spine.test.commandservice.customer.CustomerId) Topic(io.spine.client.Topic) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Any(com.google.protobuf.Any) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 12 with CustomerId

use of io.spine.test.commandservice.customer.CustomerId 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 13 with CustomerId

use of io.spine.test.commandservice.customer.CustomerId 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 = Tests.newVersionWithNumber(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 = AnyPacker.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) Version(io.spine.base.Version) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

Customer (io.spine.test.commandservice.customer.Customer)13 CustomerId (io.spine.test.commandservice.customer.CustomerId)13 Any (com.google.protobuf.Any)10 Version (io.spine.base.Version)10 StandStorage (io.spine.server.stand.StandStorage)9 Test (org.junit.Test)8 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)7 Map (java.util.Map)6 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)5 Query (io.spine.client.Query)3 Topic (io.spine.client.Topic)3 FieldMask (com.google.protobuf.FieldMask)2 Target (io.spine.client.Target)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 CanIgnoreReturnValue (com.google.errorprone.annotations.CanIgnoreReturnValue)1 StreamObserver (io.grpc.stub.StreamObserver)1 ActorRequestFactory (io.spine.client.ActorRequestFactory)1