Search in sources :

Example 6 with Target

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

the class TopicValidator method isSupported.

@Override
protected Optional<RequestNotSupported<Topic>> isSupported(Topic request) {
    final Target target = request.getTarget();
    final boolean targetSupported = checkTargetSupported(target);
    if (targetSupported) {
        return Optional.absent();
    }
    return Optional.of(missingInRegistry(getTypeOf(target)));
}
Also used : Target(io.spine.client.Target)

Example 7 with Target

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

the class StandShould method trigger_each_subscription_callback_once_for_multiple_subscriptions.

@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void trigger_each_subscription_callback_once_for_multiple_subscriptions() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Target allCustomers = Targets.allOf(Customer.class);
    final Set<MemoizeEntityUpdateCallback> callbacks = newHashSet();
    final int totalCallbacks = 100;
    for (int callbackIndex = 0; callbackIndex < totalCallbacks; callbackIndex++) {
        final MemoizeEntityUpdateCallback callback = subscribeWithCallback(stand, allCustomers);
        callbacks.add(callback);
    }
    final Map.Entry<CustomerId, Customer> sampleData = fillSampleCustomers(1).entrySet().iterator().next();
    final CustomerId customerId = sampleData.getKey();
    final Customer customer = sampleData.getValue();
    final Version stateVersion = GivenVersion.withNumber(1);
    stand.update(asEnvelope(customerId, customer, stateVersion));
    final Any packedState = AnyPacker.pack(customer);
    for (MemoizeEntityUpdateCallback callback : callbacks) {
        assertEquals(packedState, callback.newEntityState);
        verify(callback, times(1)).onStateChanged(any(EntityStateUpdate.class));
    }
}
Also used : Customer(io.spine.test.commandservice.customer.Customer) CustomerId(io.spine.test.commandservice.customer.CustomerId) Any(com.google.protobuf.Any) Target(io.spine.client.Target) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) EntityStateUpdate(io.spine.client.EntityStateUpdate) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 8 with Target

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

the class StandShould method do_not_trigger_subscription_callbacks_in_case_of_another_type_criterion_mismatch.

@Test
public void do_not_trigger_subscription_callbacks_in_case_of_another_type_criterion_mismatch() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Target allProjects = Targets.allOf(Project.class);
    final MemoizeEntityUpdateCallback callback = subscribeWithCallback(stand, allProjects);
    final Map.Entry<CustomerId, Customer> sampleData = fillSampleCustomers(1).entrySet().iterator().next();
    final CustomerId customerId = sampleData.getKey();
    final Customer customer = sampleData.getValue();
    final Version stateVersion = GivenVersion.withNumber(1);
    stand.update(asEnvelope(customerId, customer, stateVersion));
    verify(callback, never()).onStateChanged(any(EntityStateUpdate.class));
}
Also used : Target(io.spine.client.Target) Customer(io.spine.test.commandservice.customer.Customer) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) EntityStateUpdate(io.spine.client.EntityStateUpdate) CustomerId(io.spine.test.commandservice.customer.CustomerId) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 9 with Target

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

the class SubscriptionService method selectBoundedContext.

private BoundedContext selectBoundedContext(Subscription subscription) {
    final Target target = subscription.getTopic().getTarget();
    final BoundedContext context = selectBoundedContext(target);
    return context;
}
Also used : Target(io.spine.client.Target)

Example 10 with Target

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

the class QueryValidator method isSupported.

@Override
protected Optional<RequestNotSupported<Query>> isSupported(Query request) {
    final Target target = request.getTarget();
    final boolean targetSupported = checkTargetSupported(target);
    if (targetSupported) {
        return Optional.absent();
    }
    return Optional.of(missingInRegistry(getTypeOf(target)));
}
Also used : Target(io.spine.client.Target)

Aggregations

Target (io.spine.client.Target)16 Test (org.junit.Test)10 Message (com.google.protobuf.Message)4 Subscription (io.spine.client.Subscription)4 Topic (io.spine.client.Topic)4 Any (com.google.protobuf.Any)3 EntityFilters (io.spine.client.EntityFilters)3 Query (io.spine.client.Query)3 ImmutableList (com.google.common.collect.ImmutableList)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 FieldMask (com.google.protobuf.FieldMask)2 EntityId (io.spine.client.EntityId)2 EntityStateUpdate (io.spine.client.EntityStateUpdate)2 SubscriptionUpdate (io.spine.client.SubscriptionUpdate)2 Response (io.spine.core.Response)2 Version (io.spine.core.Version)2 GivenVersion (io.spine.core.given.GivenVersion)2 AbstractVersionableEntity (io.spine.server.entity.AbstractVersionableEntity)2 VersionableEntity (io.spine.server.entity.VersionableEntity)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2