Search in sources :

Example 16 with TenantId

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

the class MultiTenantStandShould method setUp.

@Override
@Before
public void setUp() {
    super.setUp();
    final TenantId tenantId = newUuid();
    setCurrentTenant(tenantId);
    setMultitenant(true);
    setRequestFactory(createRequestFactory(tenantId));
}
Also used : TenantId(io.spine.core.TenantId) Before(org.junit.Before)

Example 17 with TenantId

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

the class CurrentTenantShould method clear_set_value.

@Test
public void clear_set_value() {
    final TenantId value = nameOf(getClass());
    CurrentTenant.set(value);
    CurrentTenant.clear();
    assertFalse(CurrentTenant.get().isPresent());
}
Also used : TenantId(io.spine.core.TenantId) Test(org.junit.Test)

Example 18 with TenantId

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

the class TenantAwareOperationShould method create_instance_for_non_command_execution_context.

@Test
public void create_instance_for_non_command_execution_context() {
    final TenantId tenant = newUuid();
    CurrentTenant.set(tenant);
    final TenantAwareOperation op = createOperation();
    assertEquals(tenant, op.tenantId());
    op.execute();
    assertEquals(tenant, getTenantFromRun(op));
}
Also used : TenantId(io.spine.core.TenantId) Test(org.junit.Test)

Example 19 with TenantId

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

the class GivenCommandContext method withActorAndTime.

/**
 * Creates a new {@link CommandContext} instance based upon given actor and creation date.
 *
 * @return a new {@code CommandContext} instance
 */
public static CommandContext withActorAndTime(UserId actor, Timestamp when) {
    final TenantId tenantId = GivenTenantId.newUuid();
    final ActorContext.Builder actorContext = ActorContext.newBuilder().setActor(actor).setTimestamp(when).setZoneOffset(UTC).setTenantId(tenantId);
    final CommandContext.Builder builder = CommandContext.newBuilder().setActorContext(actorContext);
    return builder.build();
}
Also used : TenantId(io.spine.core.TenantId) CommandContext(io.spine.core.CommandContext) ActorContext(io.spine.core.ActorContext)

Example 20 with TenantId

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

the class CommandStoreShould method set_command_status_to_rejection_when_handler_throws_rejection.

@Test
public void set_command_status_to_rejection_when_handler_throws_rejection() {
    ModelTests.clearModel();
    final TestRejection rejection = new TestRejection();
    final Command command = givenThrowingHandler(rejection);
    final CommandId commandId = command.getId();
    final Message commandMessage = getMessage(command);
    commandBus.post(command, observer);
    // Check that the logging was called.
    verify(log).rejectedWith(eq(rejection), eq(commandMessage), eq(commandId));
    // Check that the status has the correct code,
    // and the rejection matches the thrown rejection.
    final TenantId tenantId = command.getContext().getActorContext().getTenantId();
    final ProcessingStatus status = getStatus(commandId, tenantId);
    assertEquals(CommandStatus.REJECTED, status.getCode());
    assertEquals(toRejection(rejection, command).getMessage(), status.getRejection().getMessage());
}
Also used : TenantId(io.spine.core.TenantId) Commands.getMessage(io.spine.core.Commands.getMessage) ThrowableMessage(io.spine.base.ThrowableMessage) CommandMessage.createProjectMessage(io.spine.server.commandbus.Given.CommandMessage.createProjectMessage) Message(com.google.protobuf.Message) Command(io.spine.core.Command) CommandId(io.spine.core.CommandId) 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