private void handleReply(boolean compensating) { SagaInstance expectedSagaInstanceAfterSecondStep = makeExpectedSagaInstanceAfterSecondStep(); when(sagaInstanceRepository.find(sagaType, sagaId)) .thenReturn(sagaInstance); when(sagaDefinition.handleReply(anyString(), any(TestSagaData.class), any(Message.class))) .thenReturn(makeSecondSagaActions(compensating)); when(sagaCommandProducer.sendCommands(anyString(), anyString(), anyList(), anyString())).thenReturn (requestId2.asString()); sagaMessageHandler.accept(replyFromParticipant1); verify(sagaInstanceRepository).find(sagaType, sagaId); verify(sagaCommandProducer).sendCommands(sagaType, sagaId, Collections.singletonList(commandForParticipant2), sagaReplyChannel); verify(sagaInstanceRepository).update(argThat(sagaInstance -> sagaInstanceEquals(expectedSagaInstanceAfterSecondStep, sagaInstance))); assertSagaInstanceEquals(expectedSagaInstanceAfterSecondStep, sagaInstance); verifyNoMoreInteractions(sagaInstanceRepository, sagaCommandProducer); }
private void startSaga() { when(sagaDefinition.start(initialSagaData)).thenReturn(makeFirstSagaActions()); when(sagaCommandProducer.sendCommands(anyString(), anyString(), anyList(), anyString())) .thenReturn(requestId1.asString()); doAnswer(this::assignSagaIdWhenSaved).when(sagaInstanceRepository).save(any(SagaInstance.class)); sagaInstance = sm.create(initialSagaData); SagaInstance expectedSagaInstanceAfterFirstStep = makeExpectedSagaInstanceAfterFirstStep(); assertSagaInstanceEquals(expectedSagaInstanceAfterFirstStep, sagaInstance); verify(sagaCommandProducer).sendCommands(sagaType, sagaId, Collections.singletonList(commandForParticipant1), sagaReplyChannel); verify(sagaInstanceRepository).save(any(SagaInstance.class)); verify(sagaInstanceRepository).update(argThat(sagaInstance -> sagaInstanceEquals(expectedSagaInstanceAfterFirstStep, sagaInstance))); assertSagaInstanceEquals(expectedSagaInstanceAfterFirstStep, sagaInstance); verifyNoMoreInteractions(sagaInstanceRepository, sagaCommandProducer); }