Search in sources :

Example 1 with Status

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

the class DuplicateCommandShould method not_be_acknowledged_on_client_when_not_sent.

@Test
public void not_be_acknowledged_on_client_when_not_sent() {
    final TenantId tenantId = newTenantId();
    final Command command = command(createProject(), tenantId);
    final Ack ack = client.post(command);
    final Status status = ack.getStatus();
    assertTrue(status.hasOk());
}
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) Test(org.junit.Test)

Example 2 with Status

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

the class Buses method reject.

/**
 * Creates {@code Ack} response for the given message ID with the error status.
 *
 * @param id    the ID of the message to provide with the status
 * @param cause the cause of the message rejection
 * @return the {@code Ack} response with the given message ID
 */
public static Ack reject(Message id, Error cause) {
    checkNotNull(cause);
    checkArgument(isNotDefault(cause));
    final Status status = Status.newBuilder().setError(cause).build();
    return setStatus(id, status);
}
Also used : Status(io.spine.core.Status)

Example 3 with Status

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

the class CommandServiceShould method return_error_status_if_command_is_unsupported.

@Test
public void return_error_status_if_command_is_unsupported() {
    final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(getClass());
    final Command unsupportedCmd = factory.createCommand(StringValue.getDefaultInstance());
    service.post(unsupportedCmd, responseObserver);
    assertTrue(responseObserver.isCompleted());
    final Ack result = responseObserver.firstResponse();
    assertNotNull(result);
    assertTrue(isNotDefault(result));
    final Status status = result.getStatus();
    assertEquals(ERROR, status.getStatusCase());
    final Error error = status.getError();
    assertEquals(CommandValidationError.getDescriptor().getFullName(), error.getType());
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) Status(io.spine.core.Status) Command(io.spine.core.Command) Ack(io.spine.core.Ack) Error(io.spine.base.Error) CommandValidationError(io.spine.core.CommandValidationError) Test(org.junit.Test)

Example 4 with Status

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

the class AbstractCommandRouter method checkSent.

private static void checkSent(Command command, Ack ack) {
    final Status status = ack.getStatus();
    final CommandId routedCommandId = unpack(ack.getMessageId());
    final CommandId commandId = command.getId();
    checkState(commandId.equals(routedCommandId), "Unexpected command posted. Intending (%s) but was (%s).", commandId, routedCommandId);
    checkState(status.getStatusCase() == Status.StatusCase.OK, "Command posting failed with status: %s.", status);
}
Also used : Status(io.spine.core.Status) CommandId(io.spine.core.CommandId)

Example 5 with Status

use of io.spine.core.Status 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)

Aggregations

Status (io.spine.core.Status)7 Error (io.spine.base.Error)3 Ack (io.spine.core.Ack)3 Command (io.spine.core.Command)3 Test (org.junit.Test)3 CommandId (io.spine.core.CommandId)2 CommandValidationError (io.spine.core.CommandValidationError)2 TenantId (io.spine.core.TenantId)2 DuplicateCommandTestEnv.newTenantId (io.spine.server.command.given.DuplicateCommandTestEnv.newTenantId)2 TestActorRequestFactory (io.spine.client.TestActorRequestFactory)1