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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations