public static <TEvent> Operation<Object, Object, TEvent> appendOf( final AppendHandlerSingle<TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false); }
public static <TParams, TEvent> Operation<Object, TParams, TEvent> appendOf( final ParameterizedAppendHandlerSingle<TParams, TEvent> handler) { return new OperationHandlerOperation<>(handler, false, true); }
public static <TEvent> Operation<Object, Object, TEvent> appendOf( final AppendHandlerSingle<TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false); }
public static <TEvent> Operation<Object, Object, TEvent> appendOf( final AppendHandler<TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false); }
public static <TParams, TEvent> Operation<Object, TParams, TEvent> appendOf( final ParameterizedAppendHandlerSingle<TParams, TEvent> handler) { return new OperationHandlerOperation<>(handler, false, true); }
public static <TParams, TEvent> Operation<Object, TParams, TEvent> appendOf( final ParameterizedAppendHandler<TParams, TEvent> handler) { return new OperationHandlerOperation<>(handler, false, true); }
public static <TEvent> Operation<Object, Object, TEvent> appendOf( final AppendHandler<TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false); }
public static <TParams, TEvent> Operation<Object, TParams, TEvent> appendOf( final ParameterizedAppendHandler<TParams, TEvent> handler) { return new OperationHandlerOperation<>(handler, false, true); }
public static <TEvent> Operation<Object, Object, TEvent> constructorOf( final ConstructorHandler<TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false, ExpectedVersion.notCreated()); }
public static <TEvent> Operation<Object, Object, TEvent> constructorOf( final ConstructorHandlerSingle<TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false, ExpectedVersion.notCreated()); }
public static <TParams, TEvent> Operation<Object, TParams, TEvent> constructorOf( final ParameterizedConstructorHandlerSingle<TParams, TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false, ExpectedVersion.notCreated()); }
public static <TParams, TEvent> Operation<Object, TParams, TEvent> constructorOf( final ParameterizedConstructorHandler<TParams, TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false, ExpectedVersion.notCreated()); }
public static <TEvent> Operation<Object, Object, TEvent> constructorOf( final ConstructorHandler<TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false, ExpectedVersion.notCreated()); }
public static <TEvent> Operation<Object, Object, TEvent> constructorOf( final ConstructorHandlerSingle<TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false, ExpectedVersion.notCreated()); }
public static <TParams, TEvent> Operation<Object, TParams, TEvent> constructorOf( final ParameterizedConstructorHandler<TParams, TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false, ExpectedVersion.notCreated()); }
public static <TParams, TEvent> Operation<Object, TParams, TEvent> constructorOf( final ParameterizedConstructorHandlerSingle<TParams, TEvent> handler) { return new OperationHandlerOperation<>(handler, false, false, ExpectedVersion.notCreated()); }
/** * Creates an update operation, optionally requiring an existing aggregate. * * @param handler The handler to invoke with the current state to apply updates. * @param autoCreate If true, the handler will be invoked with a null state in the case where no * current aggregate exists. If false, the command will fail without the * handler being invoked if the aggregate is not already present. * @return An operation representing the supplied logic, with metadata. */ public static <TState, TParams, TEvent> Operation<TState, TParams, TEvent> updateOf( final ParameterizedUpdateHandler<TState, TParams, TEvent> handler, final boolean autoCreate) { ExpectedVersion expectedVersion = autoCreate ? ExpectedVersion.any() : ExpectedVersion.anyExisting(); return new OperationHandlerOperation<>( handler, true, true, expectedVersion, true); }
@Test @SuppressWarnings("unchecked") public void aggregateReadWhenStateRequired() { Operation operation = new OperationHandlerOperation( (x, y) -> ImmutableList.of(new TestEvent("test")), true, false, ExpectedVersion.any()); DefaultCommand command = new DefaultCommand(repository, operation); when(repository.load(any())) .thenReturn(DefaultImmutableAggregate.fromExisting( mock(AggregateProjection.class), AGGREGATE_ID, 42, new TestState("test"))); command.setAggregateId(AGGREGATE_ID); command.run(); verify(repository).load(AGGREGATE_ID); }
@Test @SuppressWarnings("unchecked") public void idempotentCreateMeansNoOpIfExisting() { Operation operation = new OperationHandlerOperation( (x, y) -> ImmutableList.of(new TestEvent("xxx")), false, false, ExpectedVersion.notCreated()); when(repository.load(any())) .thenReturn(DefaultImmutableAggregate.fromExisting( mock(AggregateProjection.class), AGGREGATE_ID, 42, new TestState("test"))); DefaultCommand command = new DefaultCommand(repository, operation); command.setAggregateId(AGGREGATE_ID); command.setIdempotentCreate(true); CommandResult commandResult = command.run(); Assert.assertTrue(commandResult.getEvents().isEmpty()); }
@Test(expected = InvalidCommandException.class) @SuppressWarnings("unchecked") public void conflictingVersionsGiveInvalidCommand() { PowerMockito.mockStatic(ExpectedVersion.class); PowerMockito.when(ExpectedVersion.merge(any(), any())) .thenThrow(new ConflictingExpectedVersionsException( "error", null, null)); Operation operation = new OperationHandlerOperation( (x, y) -> null, true, false, ExpectedVersion.exactly(42)); DefaultCommand command = new DefaultCommand(repository, operation); command.setAggregateId(AGGREGATE_ID); command.run(); }