I have a parent workflow that calls a child workflow PaymentSettlementWorkflow
. I’m mocking PaymentSettlementWorkflow
as per HelloChildJUnit5Test.java. Upon running the test is hanging indefinitely.
This the how I’m mocking the child workflow.
class ParentWorkflowImplTest {
@RegisterExtension
public static final TestWorkflowExtension testWorkflowExtension = TestWorkflowExtension.newBuilder()
.registerWorkflowImplementationTypes(ParentWorkflowImpl.class)
.setDoNotStart(true)
.build();
@Test
void testSettlementFailed(TestWorkflowEnvironment testEnv, Worker worker, ParentWorkflowInterface workflow) {
PaymentSettlementWorkflow paymentSettlementWorkflow = mock(PaymentSettlementWorkflow.class);
when(paymentSettlementWorkflow.checkSettlementStatus(any())).thenReturn(PayinSettlementStatusType.FAILED);
worker.registerWorkflowImplementationFactory(
PaymentSettlementWorkflow.class,
() -> paymentSettlementWorkflow
);
testEnv.start();
ApplicationStatus applicationStatus = workflow.process(input);
assertNotNull(applicationStatus);
assertEquals(ApplicationStatusType.REJECTED, applicationStatus.status());
}
}
This the parent workflow logic that I’m testing
ChildWorkflowOptions applicantWorkflowOptions = ChildWorkflowOptions.newBuilder()
.setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON)
.setWorkflowId(workflowId)
.setTaskQueue(WorkflowApplicationObserver.TASK_QUEUE)
.build();
PaymentSettlementWorkflow paymentSettlementWorkflow = Workflow.newChildWorkflowStub(PaymentSettlementWorkflow.class, applicantWorkflowOptions);
PayinSettlementStatusType settlementStatus = paymentSettlementWorkflow.checkSettlementStatus(payin);
if (PayinSettlementStatusType.FAILED.equals(settlementStatus)) {
//handle failure
//return Rejected status
}