Search in sources :

Example 1 with TestActorRequestFactory

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

the class StorageShould method store_command_with_error_and_generate_ID_if_needed.

@Test
public void store_command_with_error_and_generate_ID_if_needed() {
    final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(getClass());
    final Command command = factory.createCommand(createProjectMessage());
    final Error error = newError();
    repository.store(command, error);
    final List<CommandRecord> records = Lists.newArrayList(repository.iterator(ERROR));
    assertEquals(1, records.size());
    final String commandIdStr = Identifier.toString(records.get(0).getCommandId());
    assertFalse(commandIdStr.isEmpty());
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) Command(io.spine.core.Command) Error(io.spine.base.Error) CommandRecord(io.spine.server.commandbus.CommandRecord) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 2 with TestActorRequestFactory

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

the class AggregateMessageDispatcherShould method dispatch_command.

@Test
public void dispatch_command() {
    final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(getClass());
    final int messageValue = 2017_07_28;
    final UInt32Value message = UInt32Value.newBuilder().setValue(messageValue).build();
    final CommandEnvelope commandEnvelope = CommandEnvelope.of(factory.createCommand(message));
    final List<? extends Message> eventMessages = dispatchCommand(aggregate, commandEnvelope);
    assertTrue(aggregate.getState().getValue().contains(String.valueOf(messageValue)));
    assertEquals(1, eventMessages.size());
    assertTrue(eventMessages.get(0) instanceof StringValue);
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) UInt32Value(com.google.protobuf.UInt32Value) CommandEnvelope(io.spine.core.CommandEnvelope) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 3 with TestActorRequestFactory

use of io.spine.client.TestActorRequestFactory 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 TestActorRequestFactory

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

the class AggregateRepositoryShould method not_pass_command_rejection_to_onError.

@Test
public void not_pass_command_rejection_to_onError() {
    final FailingAggregateRepository repository = new FailingAggregateRepository();
    boundedContext.register(repository);
    final TestActorRequestFactory requestFactory = TestActorRequestFactory.newInstance(getClass());
    // Passing negative long value to `FailingAggregate` should cause a rejection.
    final CommandEnvelope ce = CommandEnvelope.of(requestFactory.createCommand(UInt64Value.newBuilder().setValue(-100_000_000L).build()));
    boundedContext.getCommandBus().post(ce.getCommand(), StreamObservers.<Ack>noOpObserver());
    assertFalse(repository.isErrorLogged());
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) FailingAggregateRepository(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.FailingAggregateRepository) CommandEnvelope(io.spine.core.CommandEnvelope) Test(org.junit.Test)

Example 5 with TestActorRequestFactory

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

the class Given method invalidProjectNameRejection.

public static Rejection invalidProjectNameRejection() {
    final ProjectId projectId = newProjectId();
    final ProjectRejections.InvalidProjectName invalidProjectName = ProjectRejections.InvalidProjectName.newBuilder().setProjectId(projectId).build();
    final StringChange nameChange = StringChange.newBuilder().setNewValue("Too short").build();
    final RjUpdateProjectName updateProjectName = RjUpdateProjectNameVBuilder.newBuilder().setId(projectId).setNameUpdate(nameChange).build();
    final TenantId generatedTenantId = TenantId.newBuilder().setValue(newUuid()).build();
    final TestActorRequestFactory factory = TestActorRequestFactory.newInstance(RejectionBusShould.class, generatedTenantId);
    final Command command = factory.createCommand(updateProjectName);
    return Rejections.createRejection(invalidProjectName, command);
}
Also used : TestActorRequestFactory(io.spine.client.TestActorRequestFactory) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) ProjectRejections(io.spine.test.rejection.ProjectRejections) ProjectId(io.spine.test.rejection.ProjectId) RjUpdateProjectName(io.spine.test.rejection.command.RjUpdateProjectName) StringChange(io.spine.change.StringChange)

Aggregations

TestActorRequestFactory (io.spine.client.TestActorRequestFactory)9 Test (org.junit.Test)7 Command (io.spine.core.Command)4 CommandEnvelope (io.spine.core.CommandEnvelope)4 StringValue (com.google.protobuf.StringValue)2 Error (io.spine.base.Error)2 NullPointerTester (com.google.common.testing.NullPointerTester)1 UInt32Value (com.google.protobuf.UInt32Value)1 StringChange (io.spine.change.StringChange)1 Ack (io.spine.core.Ack)1 CommandValidationError (io.spine.core.CommandValidationError)1 EventEnvelope (io.spine.core.EventEnvelope)1 Status (io.spine.core.Status)1 TenantId (io.spine.core.TenantId)1 FailingAggregateRepository (io.spine.server.aggregate.given.AggregateRepositoryTestEnv.FailingAggregateRepository)1 TestEventFactory (io.spine.server.command.TestEventFactory)1 CommandRecord (io.spine.server.commandbus.CommandRecord)1 EventFactory (io.spine.server.event.EventFactory)1 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)1 ProjectId (io.spine.test.rejection.ProjectId)1