package jnpf.flowable.service; import jnpf.exception.WorkFlowException; import jnpf.flowable.entity.*; import jnpf.flowable.mapper.TaskMapper; import jnpf.flowable.mapper.TemplateNodeMapper; import jnpf.flowable.util.OperatorUtil; import org.junit.Before; import org.junit.Test; import java.util.*; import static org.junit.Assert.*; import static org.mockito.Mockito.*; public class WorkflowAuditContextResolverTest { private OperatorUtil operators; private TaskMapper tasks; private TemplateNodeMapper nodes; private OperatorEntity operator; private WorkflowAuditContextResolverImpl resolver; @Before public void setup() throws Exception { operators = mock(OperatorUtil.class); tasks = mock(TaskMapper.class); nodes = mock(TemplateNodeMapper.class); resolver = new WorkflowAuditContextResolverImpl(operators, tasks, nodes); operator = new OperatorEntity(); operator.setId("operator-round-2"); operator.setTaskId("task"); operator.setNodeId("node"); operator.setNodeCode("review"); operator.setNodeName("审核"); when(operators.checkOperator("operator-round-2")).thenReturn(operator); TaskEntity task = new TaskEntity(); task.setFlowId("version"); when(tasks.getInfo("task")).thenReturn(task); TemplateNodeEntity node = new TemplateNodeEntity(); node.setNodeCode("review"); node.setFormId("form"); when(nodes.getList("version")).thenReturn(List.of(node)); } @Test public void freezesServerNodeAndExistingHandlingRoundBeforeCompletion() throws Exception { Map result = resolver.resolve("task", "form", "operator-round-2"); operator.setNodeName("下一环节"); assertEquals("审核", result.get("nodeName")); assertEquals("operator-round-2", result.get("operatorId")); assertEquals("task", result.get("taskId")); verify(operators).checkOperatorPermission("operator-round-2"); } @Test public void rejectsReferenceFromAnotherTask() throws Exception { try { resolver.resolve("other", "form", "operator-round-2"); fail(); } catch (WorkFlowException expected) { } verifyNoInteractions(tasks, nodes); } @Test public void rejectsAnotherFormOnTheSameTask() throws Exception { try { resolver.resolve("task", "other", "operator-round-2"); fail(); } catch (WorkFlowException expected) { } } @Test public void rejectsUnauthorizedHandlingReference() throws Exception { doThrow(new WorkFlowException("no permission")).when(operators).checkOperatorPermission("operator-round-2"); try { resolver.resolve("task", "form", "operator-round-2"); fail(); } catch (WorkFlowException expected) { } verifyNoInteractions(tasks, nodes); } @Test public void rejectsCompletedOrInvalidHandlingReference() throws Exception { when(operators.checkOperator("operator-round-2")).thenThrow(new WorkFlowException("already completed")); try { resolver.resolve("task", "form", "operator-round-2"); fail(); } catch (WorkFlowException expected) { } verifyNoInteractions(tasks, nodes); } }