Search in sources :

Example 31 with TenantId

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

the class DuplicateCommandShould method be_acknowledged_on_client_when_posted_to_an_aggregate.

@Test
public void be_acknowledged_on_client_when_posted_to_an_aggregate() {
    final TenantId tenantId = newTenantId();
    final Command command = command(createProject(), tenantId);
    client.post(command);
    final Ack ack = client.post(command);
    final Status status = ack.getStatus();
    final Error error = status.getError();
    final String errorType = error.getType();
    final String expectedErrorType = DuplicateCommandException.class.getCanonicalName();
    assertEquals(expectedErrorType, errorType);
}
Also used : Status(io.spine.core.Status) TenantId(io.spine.core.TenantId) DuplicateCommandTestEnv.newTenantId(io.spine.server.command.given.DuplicateCommandTestEnv.newTenantId) Command(io.spine.core.Command) Ack(io.spine.core.Ack) Error(io.spine.base.Error) Test(org.junit.Test)

Example 32 with TenantId

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

the class CurrentTenantShould method keep_set_value.

// we check isPresent() in assertion
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void keep_set_value() {
    final TenantId expected = nameOf(getClass());
    CurrentTenant.set(expected);
    final Optional<TenantId> currentTenant = CurrentTenant.get();
    assertTrue(currentTenant.isPresent());
    assertEquals(expected, currentTenant.get());
}
Also used : TenantId(io.spine.core.TenantId) Test(org.junit.Test)

Example 33 with TenantId

use of io.spine.core.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 = newUuid();
    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.core.TenantId) Test(org.junit.Test)

Example 34 with TenantId

use of io.spine.core.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 = newUuid();
    CurrentTenant.set(previousTenant);
    final TenantId newTenant = newUuid();
    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.core.TenantId) Test(org.junit.Test)

Example 35 with TenantId

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

the class TenantRepositoryShould method cache_passed_value.

@Test
public void cache_passed_value() {
    final TenantId tenantId = newUuid();
    repository.keep(tenantId);
    repository.keep(tenantId);
    verify(repository, times(1)).find(tenantId);
}
Also used : TenantId(io.spine.core.TenantId) Test(org.junit.Test)

Aggregations

TenantId (io.spine.core.TenantId)41 Test (org.junit.Test)27 Command (io.spine.core.Command)17 Ack (io.spine.core.Ack)11 Event (io.spine.core.Event)6 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)6 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)6 CommandBus (io.spine.server.commandbus.CommandBus)6 Error (io.spine.base.Error)4 CommandId (io.spine.core.CommandId)4 IdempotencyGuardTestEnv.newProjectId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newProjectId)4 IdempotencyGuardTestEnv.newTenantId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newTenantId)4 IgTestAggregate (io.spine.server.aggregate.given.aggregate.IgTestAggregate)4 Nullable (javax.annotation.Nullable)4 ActorContext (io.spine.core.ActorContext)3 CommandContext (io.spine.core.CommandContext)3 Rejection (io.spine.core.Rejection)3 BoundedContext (io.spine.server.BoundedContext)3 AggregateMessageDispatcher.dispatchRejection (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection)3 AggregateTestEnv.newTaskBoundedContext (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext)3