Search in sources :

Example 16 with TenantId

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

the class TenantAwareOperationShould method remember_and_restore_current_tenant.

@Test
public void remember_and_restore_current_tenant() {
    final TenantId previousTenant = newTenantUuid();
    CurrentTenant.set(previousTenant);
    final TenantId newTenant = newTenantUuid();
    final TenantAwareOperation op = createOperation(newTenant);
    // Check that the construction of the operation does not change the current tenant.
    assertEquals(previousTenant, CurrentTenant.get().get());
    op.execute();
    // Check that we got right value inside run().
    assertEquals(newTenant, getTenantFromRun(op));
    // Check that the current tenant is restored.
    assertEquals(previousTenant, CurrentTenant.get().get());
}
Also used : TenantId(io.spine.users.TenantId) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation) Test(org.junit.Test)

Example 17 with TenantId

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

the class TenantAwareOperationShould method clear_current_tenant_on_restore_if_no_tenant_was_set.

@Test
public void clear_current_tenant_on_restore_if_no_tenant_was_set() {
    // Make sure there's not current tenant.
    CurrentTenant.clear();
    // Create new operation.
    final TenantId newTenant = newTenantUuid();
    final TenantAwareOperation op = createOperation(newTenant);
    // Check that the construction did not set the tenant.
    assertFalse(CurrentTenant.get().isPresent());
    op.execute();
    // Check that the execution was on the correct tenant.
    assertEquals(newTenant, getTenantFromRun(op));
    // Check that the execution cleared the current tenant.
    assertFalse(CurrentTenant.get().isPresent());
}
Also used : TenantId(io.spine.users.TenantId) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation) Test(org.junit.Test)

Example 18 with TenantId

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

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

the class CommandStoreShould method set_command_status_to_OK_when_handler_returns.

@Test
public void set_command_status_to_OK_when_handler_returns() {
    commandBus.register(createProjectHandler);
    final Command command = requestFactory.command().create(createProjectMessage());
    commandBus.post(command, responseObserver);
    final TenantId tenantId = command.getContext().getActorContext().getTenantId();
    final CommandId commandId = command.getId();
    final ProcessingStatus status = getStatus(commandId, tenantId);
    assertEquals(CommandStatus.OK, status.getCode());
}
Also used : TenantId(io.spine.users.TenantId) Command(io.spine.base.Command) CommandId(io.spine.base.CommandId) Test(org.junit.Test)

Example 20 with TenantId

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

the class CommandStoreShould method getProcessingStatus.

private ProcessingStatus getProcessingStatus(CommandEnvelope commandEnvelope) {
    final TenantId tenantId = commandEnvelope.getCommandContext().getActorContext().getTenantId();
    final TenantAwareFunction<CommandId, ProcessingStatus> func = new TenantAwareFunction<CommandId, ProcessingStatus>(tenantId) {

        @Override
        public ProcessingStatus apply(@Nullable CommandId input) {
            return commandStore.getStatus(checkNotNull(input));
        }
    };
    final ProcessingStatus result = func.execute(commandEnvelope.getCommandId());
    return result;
}
Also used : TenantId(io.spine.users.TenantId) TenantAwareFunction(io.spine.server.tenant.TenantAwareFunction) CommandId(io.spine.base.CommandId) Nullable(javax.annotation.Nullable)

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