BaseJavaDelegate implements JavaDelegate { @Override public final void execute(DelegateExecution execution) throws Exception { long taskBeginTimeMillis = 0; boolean taskSuccessFlag = false; try { taskBeginTimeMillis = System.currentTimeMillis(); SecurityContextHolder.clearContext(); configurationDaoHelper.checkNotAllowedMethod(this.getClass().getCanonicalName()); ApplicationUser applicationUser = getApplicationUser(execution); setSecurityContext(applicationUser); MDC.put(ACTIVITI_PROCESS_INSTANCE_ID_KEY, "activitiProcessInstanceId=" + execution.getProcessInstanceId()); MDC.put(USER_ID_KEY, "userId=" + (applicationUser.getUserId() == null ? "" : applicationUser.getUserId())); logInputParameters(execution); executeImpl(execution); activitiRuntimeHelper.setTaskSuccessInWorkflow(execution); taskSuccessFlag = true; } catch (Exception ex) { handleException(execution, ex); } finally { logTaskExecutionTime(taskBeginTimeMillis, taskSuccessFlag); MDC.remove(ACTIVITI_PROCESS_INSTANCE_ID_KEY); MDC.remove(USER_ID_KEY); SecurityContextHolder.clearContext(); } }  abstract void executeImpl(DelegateExecution execution); @Override final void execute(DelegateExecution execution); void setJsonResponseAsWorkflowVariable(Object responseObject, DelegateExecution execution); void setJsonResponseAsWorkflowVariable(Object responseObject, String executionId, String activitiId); boolean isSpringInitialized(); void setSpringInitialized(boolean springInitialized); static final String VARIABLE_JSON_RESPONSE; }
@Test public void testExecute() throws Exception { String jobDefinitionNamespace = "jobDefinitionNamespace"; String jobDefinitionName = "jobDefinitionName"; String processDefinitionId = "processDefinitionId"; String processDefinitionKey = String.format("%s.%s", jobDefinitionNamespace, jobDefinitionName); String updatedBy = "updatedBy"; JobDefinitionEntity jobDefinitionEntity = new JobDefinitionEntity(); jobDefinitionEntity.setUpdatedBy(updatedBy); when(delegateExecution.getProcessDefinitionId()).thenReturn(processDefinitionId); ProcessDefinition processDefinition = mock(ProcessDefinition.class); when(processDefinition.getKey()).thenReturn(processDefinitionKey); when(activitiService.getProcessDefinitionById(any())).thenReturn(processDefinition); when(jobDefinitionDaoHelper.getJobDefinitionEntity(any(), any())).thenReturn(jobDefinitionEntity); baseJavaDelegate.execute(delegateExecution); InOrder inOrder = inOrder(configurationDaoHelper, activitiService, jobDefinitionDaoHelper, userNamespaceAuthorizationHelper, activitiRuntimeHelper); inOrder.verify(configurationDaoHelper).checkNotAllowedMethod(baseJavaDelegate.getClass().getCanonicalName()); inOrder.verify(activitiService).getProcessDefinitionById(processDefinitionId); inOrder.verify(jobDefinitionDaoHelper).getJobDefinitionEntity(jobDefinitionNamespace, jobDefinitionName); inOrder.verify(userNamespaceAuthorizationHelper).buildNamespaceAuthorizations(applicationUserUserIdEq(updatedBy)); inOrder.verify(activitiRuntimeHelper).setTaskSuccessInWorkflow(delegateExecution); inOrder.verifyNoMoreInteractions(); verifyNoMoreInteractions(configurationDaoHelper, activitiService, jobDefinitionDaoHelper, userNamespaceAuthorizationHelper, activitiRuntimeHelper); assertNull(SecurityContextHolder.getContext().getAuthentication()); }