Search in sources :

Example 1 with TenantId

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

the class CommandStoreShould method set_command_status_to_failure_when_handler_throws_failure.

@Test
public void set_command_status_to_failure_when_handler_throws_failure() {
    final TestFailure failure = new TestFailure();
    final Command command = givenThrowingHandler(failure);
    final CommandId commandId = command.getId();
    final Message commandMessage = getMessage(command);
    commandBus.post(command, responseObserver);
    // Check that the logging was called.
    verify(log).failureHandling(eq(failure), eq(commandMessage), eq(commandId));
    // Check that the status has the correct code,
    // and the failure matches the thrown failure.
    final TenantId tenantId = command.getContext().getActorContext().getTenantId();
    final ProcessingStatus status = getStatus(commandId, tenantId);
    assertEquals(CommandStatus.FAILURE, status.getCode());
    assertEquals(failure.toFailure(command).getMessage(), status.getFailure().getMessage());
}
Also used : TenantId(io.spine.users.TenantId) Commands.getMessage(io.spine.base.Commands.getMessage) CommandMessage.createProjectMessage(io.spine.server.commandbus.Given.CommandMessage.createProjectMessage) Message(com.google.protobuf.Message) Command(io.spine.base.Command) CommandId(io.spine.base.CommandId) Test(org.junit.Test)

Example 2 with TenantId

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

the class FailureBusShould method invalidProjectNameFailure.

private static Failure invalidProjectNameFailure() {
    final ProjectId projectId = ProjectId.newBuilder().setId(newUuid()).build();
    final ProjectFailures.InvalidProjectName invalidProjectName = ProjectFailures.InvalidProjectName.newBuilder().setProjectId(projectId).build();
    final StringChange nameChange = StringChange.newBuilder().setNewValue("Too short").build();
    final UpdateProjectName updateProjectName = UpdateProjectName.newBuilder().setId(projectId).setNameUpdate(nameChange).build();
    final TenantId generatedTenantId = TenantId.newBuilder().setValue(newUuid()).build();
    final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(FailureBusShould.class, generatedTenantId);
    final Command command = factory.createCommand(updateProjectName);
    return Failures.createFailure(invalidProjectName, command);
}
Also used : TestActorRequestFactory(io.spine.test.TestActorRequestFactory) TenantId(io.spine.users.TenantId) Command(io.spine.base.Command) UpdateProjectName(io.spine.test.failure.command.UpdateProjectName) ProjectId(io.spine.test.failure.ProjectId) ProjectFailures(io.spine.test.failure.ProjectFailures) StringChange(io.spine.change.StringChange)

Example 3 with TenantId

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

the class CommandFactoryShould method create_command_context.

@Test
public void create_command_context() {
    final TenantId tenantId = newTenantUuid();
    final UserId userId = newUserUuid();
    final ZoneOffset zoneOffset = ZoneOffsets.ofHours(-3);
    final int targetVersion = 100500;
    final CommandContext commandContext = CommandFactory.createContext(tenantId, userId, zoneOffset, targetVersion);
    final ActorContext actorContext = commandContext.getActorContext();
    assertEquals(tenantId, actorContext.getTenantId());
    assertEquals(userId, actorContext.getActor());
    assertEquals(zoneOffset, actorContext.getZoneOffset());
    assertEquals(targetVersion, commandContext.getTargetVersion());
}
Also used : TenantId(io.spine.users.TenantId) CommandContext(io.spine.base.CommandContext) UserId(io.spine.users.UserId) ZoneOffset(io.spine.time.ZoneOffset) ActorContext(io.spine.base.ActorContext) Test(org.junit.Test)

Example 4 with TenantId

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

the class TenantFunction method execute.

/**
     * Applies the function and returns the result.
     *
     * @return the result of the function
     */
@Nullable
public T execute() {
    final TenantId currentTenant = tenantId();
    final T result = apply(currentTenant);
    return result;
}
Also used : TenantId(io.spine.users.TenantId) Nullable(javax.annotation.Nullable)

Example 5 with TenantId

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

the class MultiTenantStandShould method setUp.

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

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