WorkflowInstanceService { public boolean setSignal(long workflowInstanceId, Optional<Integer> signal, String reason, WorkflowActionType actionType) { Assert.notNull(workflowDefinitionService, "workflowDefinitionService cannot be null"); signal.ifPresent(signalValue -> { AbstractWorkflowDefinition<?> definition = getDefinition(workflowInstanceId); if (!definition.getSupportedSignals().containsKey(signalValue)) { logger.warn("Setting unsupported signal value {} to instance {}.", signalValue, workflowInstanceId); } }); return workflowInstanceDao.setSignal(workflowInstanceId, signal, reason, actionType); } @Inject  WorkflowInstanceService(WorkflowInstanceDao workflowInstanceDao, WorkflowDefinitionService workflowDefinitionService,
      WorkflowInstancePreProcessor workflowInstancePreProcessor); WorkflowInstance getWorkflowInstance(long id, Set<WorkflowInstanceInclude> includes, Long maxActions); @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "getInitialState().toString() has no cast") long insertWorkflowInstance(WorkflowInstance instance); @Transactional boolean updateWorkflowInstance(WorkflowInstance instance, WorkflowInstanceAction action); @Transactional boolean wakeupWorkflowInstance(long id, List<String> expectedStates); Collection<WorkflowInstance> listWorkflowInstances(QueryWorkflowInstances query); Stream<WorkflowInstance> listWorkflowInstancesAsStream(QueryWorkflowInstances query); Optional<Integer> getSignal(long workflowInstanceId); boolean setSignal(long workflowInstanceId, Optional<Integer> signal, String reason, WorkflowActionType actionType);  }
@Test public void setSignalWorks() { when(workflowInstanceDao.getWorkflowInstanceType(99)).thenReturn("type"); AbstractWorkflowDefinition<?> definition = mock(AbstractWorkflowDefinition.class); doReturn(definition).when(workflowDefinitions).getWorkflowDefinition("type"); when(definition.getSupportedSignals()).thenReturn(Collections.singletonMap(42, "supported")); service.setSignal(99, Optional.of(42), "testing", WorkflowActionType.stateExecution); verify(workflowInstanceDao).setSignal(99, Optional.of(42), "testing", WorkflowActionType.stateExecution); verify(workflowInstanceDao).getWorkflowInstanceType(99); verify(workflowDefinitions).getWorkflowDefinition("type"); }
@Test public void setSignalWorksWithUnsupportedSignal() { when(workflowInstanceDao.getWorkflowInstanceType(99)).thenReturn("type"); AbstractWorkflowDefinition<?> definition = mock(AbstractWorkflowDefinition.class); doReturn(definition).when(workflowDefinitions).getWorkflowDefinition("type"); when(definition.getSupportedSignals()).thenReturn(Collections.singletonMap(42, "supported")); service.setSignal(99, Optional.of(1), "testing", WorkflowActionType.stateExecution); verify(workflowInstanceDao).setSignal(99, Optional.of(1), "testing", WorkflowActionType.stateExecution); verify(workflowInstanceDao).getWorkflowInstanceType(99); verify(workflowDefinitions).getWorkflowDefinition("type"); }
@Test public void resetSignalDoesNotQueryWorkflowDefinition() { service.setSignal(99, Optional.empty(), "testing", WorkflowActionType.stateExecution); verify(workflowInstanceDao).setSignal(99, Optional.empty(), "testing", WorkflowActionType.stateExecution); verify(workflowInstanceDao, never()).getWorkflowInstanceType(99); verify(workflowDefinitions, never()).getWorkflowDefinition(anyString()); }