fix 修复 定时发起流程 上下文为空问题

This commit is contained in:
疯狂的狮子Li 2026-10-30 15:21:46 +08:00
parent e8b0be6dfb
commit 6d0bcceb6d
2 changed files with 13 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import org.dromara.warm.flow.core.entity.EventWait;
import org.dromara.warm.flow.core.enums.EventType;
import org.dromara.warm.flow.core.service.impl.EventRuntimeHandler;
import org.dromara.warm.flow.core.timer.EventTaskHandler;
import org.dromara.warm.flow.core.workflow.context.WorkflowContext;
import org.dromara.workflow.common.ConditionalOnEnable;
import org.springframework.stereotype.Component;
@ -46,8 +47,10 @@ public class DemoTimerInspectHandler implements EventTaskHandler {
if (isInspectTimerStart(wait)) {
// 这里应该使用业务的id demo使用自动生成id 需要用户自行替换
String businessId = String.valueOf(IdWorker.getId());
WorkflowContext context = new WorkflowContext();
context.setHandler(FlowEngine.getFlowConfig().getSystemHandler());
FlowEngine.insService().startByTimer(businessId, wait.getDefinitionId(),
wait.getNodeCode(), null, null);
wait.getNodeCode(), null, context);
log.info("定时启动示例已自动发起审批: businessId={}", businessId);
return;
}

View File

@ -1,16 +1,19 @@
package org.dromara.workflow.demo;
import org.dromara.warm.flow.core.FlowEngine;
import org.dromara.warm.flow.core.config.WarmFlow;
import org.dromara.warm.flow.core.entity.Definition;
import org.dromara.warm.flow.core.entity.EventWait;
import org.dromara.warm.flow.core.enums.EventType;
import org.dromara.warm.flow.core.service.DefService;
import org.dromara.warm.flow.core.service.InsService;
import org.dromara.warm.flow.core.workflow.context.WorkflowContext;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.MockedStatic;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
@ -32,17 +35,22 @@ class DemoTimerInspectHandlerTest {
DefService defService = mock(DefService.class);
when(defService.getById(12L)).thenReturn(definition);
InsService insService = mock(InsService.class);
WarmFlow flowConfig = mock(WarmFlow.class);
when(flowConfig.getSystemHandler()).thenReturn("0");
try (MockedStatic<FlowEngine> engine = mockStatic(FlowEngine.class)) {
engine.when(FlowEngine::defService).thenReturn(defService);
engine.when(FlowEngine::insService).thenReturn(insService);
engine.when(FlowEngine::getFlowConfig).thenReturn(flowConfig);
assertDoesNotThrow(() -> new DemoTimerInspectHandler().handle(wait));
ArgumentCaptor<String> businessId = ArgumentCaptor.forClass(String.class);
verify(insService).startByTimer(businessId.capture(), eq(12L), eq("timerStart"), isNull(), isNull());
ArgumentCaptor<WorkflowContext> context = ArgumentCaptor.forClass(WorkflowContext.class);
verify(insService).startByTimer(businessId.capture(), eq(12L), eq("timerStart"), isNull(), context.capture());
assertTrue(businessId.getValue().matches("[0-9]+"));
assertTrue(Long.parseLong(businessId.getValue()) > 0);
assertEquals("0", context.getValue().getHandler());
}
}
}