Search in sources :

Example 1 with ActorRequestFactory

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

the class ActorRequestFactoryShould method create_instance_by_user.

@Test
public void create_instance_by_user() {
    final int currentOffset = ZoneOffsets.getDefault().getAmountSeconds();
    final ActorRequestFactory aFactory = builder().setActor(actor).build();
    assertEquals(actor, aFactory.getActor());
    assertEquals(currentOffset, aFactory.getZoneOffset().getAmountSeconds());
}
Also used : ActorRequestFactory(io.spine.client.ActorRequestFactory) Test(org.junit.Test)

Example 2 with ActorRequestFactory

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

the class AbstractCommandRouter method commandFactory.

/**
     * Creates a {@code CommandFactory} using the {@linkplain io.spine.users.UserId actor},
     * {@linkplain io.spine.users.TenantId tenant ID} and {@linkplain io.spine.time.ZoneOffset
     * zone offset} from the given command context.
     */
private static CommandFactory commandFactory(CommandContext sourceContext) {
    final ActorContext actorContext = sourceContext.getActorContext();
    final ActorRequestFactory factory = ActorRequestFactory.newBuilder().setActor(actorContext.getActor()).setTenantId(actorContext.getTenantId()).setZoneOffset(actorContext.getZoneOffset()).build();
    return factory.command();
}
Also used : ActorRequestFactory(io.spine.client.ActorRequestFactory) ActorContext(io.spine.base.ActorContext)

Example 3 with ActorRequestFactory

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

the class MultiTenantStandShould method not_allow_reading_aggregate_records_for_another_tenant.

@Test
public void not_allow_reading_aggregate_records_for_another_tenant() {
    final Stand stand = doCheckReadingCustomersById(15);
    final TenantId anotherTenant = newTenantUuid();
    final ActorRequestFactory requestFactory = createRequestFactory(anotherTenant);
    final Query readAllCustomers = requestFactory.query().all(Customer.class);
    final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
    stand.execute(readAllCustomers, responseObserver);
    final QueryResponse response = responseObserver.getResponseHandled();
    assertTrue(Responses.isOk(response.getResponse()));
    assertEquals(0, response.getMessagesCount());
}
Also used : TenantId(io.spine.users.TenantId) Query(io.spine.client.Query) QueryResponse(io.spine.client.QueryResponse) ActorRequestFactory(io.spine.client.ActorRequestFactory) Test(org.junit.Test)

Example 4 with ActorRequestFactory

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

the class MultiTenantStandShould method not_trigger_updates_of_aggregate_records_for_another_tenant_subscriptions.

@Test
public void not_trigger_updates_of_aggregate_records_for_another_tenant_subscriptions() {
    final StandStorage standStorage = InMemoryStorageFactory.getInstance(isMultitenant()).createStandStorage();
    final Stand stand = prepareStandWithAggregateRepo(standStorage);
    // --- Default Tenant
    final ActorRequestFactory requestFactory = getRequestFactory();
    final MemoizeEntityUpdateCallback defaultTenantCallback = subscribeToAllOf(stand, requestFactory, Customer.class);
    // --- Another Tenant
    final TenantId anotherTenant = newTenantUuid();
    final ActorRequestFactory anotherFactory = createRequestFactory(anotherTenant);
    final MemoizeEntityUpdateCallback anotherCallback = subscribeToAllOf(stand, anotherFactory, Customer.class);
    // Trigger updates in Default Tenant.
    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);
    // Verify that Default Tenant callback has got the update.
    assertEquals(packedState, defaultTenantCallback.getNewEntityState());
    // And Another Tenant callback has not been called.
    assertEquals(null, anotherCallback.getNewEntityState());
}
Also used : TenantId(io.spine.users.TenantId) Customer(io.spine.test.commandservice.customer.Customer) Version(io.spine.base.Version) StandStorage(io.spine.server.stand.StandStorage) ActorRequestFactory(io.spine.client.ActorRequestFactory) CustomerId(io.spine.test.commandservice.customer.CustomerId) Map(java.util.Map) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 5 with ActorRequestFactory

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

the class TypeUrlShould method obtain_type_of_command.

@Test
public void obtain_type_of_command() {
    final ActorRequestFactory factory = TestActorRequestFactory.newInstance(TypeUrlShould.class);
    final StringValue message = Wrapper.forString(newUuid());
    final Command command = factory.command().create(message);
    final TypeUrl typeUrl = TypeUrl.ofCommand(command);
    assertIsStringValueUrl(typeUrl);
}
Also used : Command(io.spine.base.Command) ActorRequestFactory(io.spine.client.ActorRequestFactory) TestActorRequestFactory(io.spine.test.TestActorRequestFactory) TypeUrl.composeTypeUrl(io.spine.type.TypeUrl.composeTypeUrl) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Aggregations

ActorRequestFactory (io.spine.client.ActorRequestFactory)6 Test (org.junit.Test)5 TenantId (io.spine.users.TenantId)2 Any (com.google.protobuf.Any)1 StringValue (com.google.protobuf.StringValue)1 ActorContext (io.spine.base.ActorContext)1 Command (io.spine.base.Command)1 Version (io.spine.base.Version)1 Query (io.spine.client.Query)1 QueryResponse (io.spine.client.QueryResponse)1 StandStorage (io.spine.server.stand.StandStorage)1 TestActorRequestFactory (io.spine.test.TestActorRequestFactory)1 Customer (io.spine.test.commandservice.customer.Customer)1 CustomerId (io.spine.test.commandservice.customer.CustomerId)1 TypeUrl.composeTypeUrl (io.spine.type.TypeUrl.composeTypeUrl)1 Map (java.util.Map)1