Search in sources :

Example 21 with TenantId

use of io.spine.users.TenantId in project core-java by SpineEventEngine.

the class Stand method post.

/**
     * Posts the state of an {@link VersionableEntity} to this {@link Stand}.
     *
     * @param entity         the entity which state should be delivered to the {@code Stand}
     * @param commandContext the context of the command, which triggered the entity state update.
     */
public void post(final VersionableEntity entity, CommandContext commandContext) {
    final TenantId tenantId = commandContext.getActorContext().getTenantId();
    final EntityStateEnvelope envelope = EntityStateEnvelope.of(entity, tenantId);
    delivery.deliver(envelope);
}
Also used : TenantId(io.spine.users.TenantId) EntityStateEnvelope(io.spine.server.entity.EntityStateEnvelope)

Example 22 with TenantId

use of io.spine.users.TenantId 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 23 with TenantId

use of io.spine.users.TenantId in project core-java by SpineEventEngine.

the class ProcessManagerRepositoryShould method testDispatchCommand.

private void testDispatchCommand(Message cmdMsg) throws InvocationTargetException {
    final TenantId generatedTenantId = TenantId.newBuilder().setValue(newUuid()).build();
    final Command cmd = TestActorRequestFactory.newInstance(ProcessManagerRepositoryShould.class, generatedTenantId).command().create(cmdMsg);
    repository.dispatchCommand(CommandEnvelope.of(cmd));
    assertTrue(TestProcessManager.processed(cmdMsg));
}
Also used : TenantId(io.spine.users.TenantId) Command(io.spine.base.Command)

Example 24 with TenantId

use of io.spine.users.TenantId in project core-java by SpineEventEngine.

the class CommandFactoryShould method set_tenant_ID_in_commands_when_created_with_tenant_ID.

@Test
public void set_tenant_ID_in_commands_when_created_with_tenant_ID() {
    final TenantId tenantId = TenantId.newBuilder().setValue(getClass().getSimpleName()).build();
    final ActorRequestFactory mtFactory = ActorRequestFactory.newBuilder().setTenantId(tenantId).setActor(getActor()).setZoneOffset(getZoneOffset()).build();
    final Command command = mtFactory.command().create(StringValue.getDefaultInstance());
    assertEquals(tenantId, command.getContext().getActorContext().getTenantId());
}
Also used : TenantId(io.spine.users.TenantId) Command(io.spine.base.Command) RequiredFieldCommand(io.spine.test.commands.RequiredFieldCommand) Test(org.junit.Test)

Aggregations

TenantId (io.spine.users.TenantId)24 Test (org.junit.Test)14 Command (io.spine.base.Command)6 TenantAwareOperation (io.spine.server.tenant.TenantAwareOperation)4 CommandId (io.spine.base.CommandId)3 ActorRequestFactory (io.spine.client.ActorRequestFactory)2 Subscription (io.spine.client.Subscription)2 Tests.newTenantId (io.spine.test.Tests.newTenantId)2 Nullable (javax.annotation.Nullable)2 Any (com.google.protobuf.Any)1 Message (com.google.protobuf.Message)1 ActorContext (io.spine.base.ActorContext)1 CommandContext (io.spine.base.CommandContext)1 Commands.getMessage (io.spine.base.Commands.getMessage)1 Version (io.spine.base.Version)1 StringChange (io.spine.change.StringChange)1 Query (io.spine.client.Query)1 QueryResponse (io.spine.client.QueryResponse)1 CommandMessage.createProjectMessage (io.spine.server.commandbus.Given.CommandMessage.createProjectMessage)1 EntityStateEnvelope (io.spine.server.entity.EntityStateEnvelope)1