Search in sources :

Example 31 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project herd by FINRAOS.

the class ActivitiDelegateTest method testActivitiReportableError.

/**
 * This method tests the scenario when an error that is not workflow related is throws while workflow is executing an Async type task like Timer. This error
 * is logged as ERROR.
 */
@Test(expected = ActivitiException.class)
public void testActivitiReportableError() throws Exception {
    BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_HERD_TIMER_WITH_CLASSPATH);
    ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("servicetask1");
    FieldExtension exceptionField = new FieldExtension();
    exceptionField.setFieldName("exceptionToThrow");
    exceptionField.setExpression("${exceptionToThrow}");
    serviceTask.getFieldExtensions().add(exceptionField);
    jobDefinitionServiceTestHelper.createJobDefinitionForActivitiXml(getActivitiXmlFromBpmnModel(bpmnModel));
    List<Parameter> parameters = new ArrayList<>();
    Parameter parameter = new Parameter("exceptionToThrow", MockJavaDelegate.EXCEPTION_BPMN_ERROR);
    parameters.add(parameter);
    Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, parameters));
    org.activiti.engine.runtime.Job timer = activitiManagementService.createJobQuery().processInstanceId(job.getId()).timers().singleResult();
    if (timer != null) {
        executeWithoutLogging(Arrays.asList(ActivitiRuntimeHelper.class, TimerExecuteNestedActivityJobHandler.class), () -> {
            activitiManagementService.executeJob(timer.getId());
        });
    }
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) FieldExtension(org.activiti.bpmn.model.FieldExtension) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) TimerExecuteNestedActivityJobHandler(org.activiti.engine.impl.jobexecutor.TimerExecuteNestedActivityJobHandler) Job(org.finra.herd.model.api.xml.Job) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test) HerdActivitiServiceTaskTest(org.finra.herd.service.activiti.task.HerdActivitiServiceTaskTest)

Example 32 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project herd by FINRAOS.

the class JobDefinitionServiceTest method testUpdateJobDefinitionAssertSuccessWhenFirstTaskAsync.

/**
 * Asserts that update job definition proceeds without exceptions when first task is set to async
 *
 * @throws Exception
 */
@Test
public void testUpdateJobDefinitionAssertSuccessWhenFirstTaskAsync() throws Exception {
    String namespace = NAMESPACE;
    String jobName = JOB_NAME;
    BpmnModel bpmnModel = new BpmnModel();
    Process process = new Process();
    process.setId(namespace + '.' + jobName);
    {
        StartEvent element = new StartEvent();
        element.setId("start");
        process.addFlowElement(element);
    }
    {
        ScriptTask element = new ScriptTask();
        element.setId("script");
        element.setScriptFormat("js");
        element.setScript("// do nothing");
        element.setAsynchronous(true);
        process.addFlowElement(element);
    }
    {
        EndEvent element = new EndEvent();
        element.setId("end");
        process.addFlowElement(element);
    }
    process.addFlowElement(new SequenceFlow("start", "script"));
    process.addFlowElement(new SequenceFlow("script", "end"));
    bpmnModel.addProcess(process);
    String activitiJobXml = getActivitiXmlFromBpmnModel(bpmnModel);
    namespaceDaoTestHelper.createNamespaceEntity(namespace);
    jobDefinitionService.createJobDefinition(new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null), true);
    jobDefinitionService.updateJobDefinition(namespace, jobName, new JobDefinitionUpdateRequest(null, activitiJobXml, null, null), true);
// Assert no exceptions
}
Also used : ScriptTask(org.activiti.bpmn.model.ScriptTask) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) StartEvent(org.activiti.bpmn.model.StartEvent) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) EndEvent(org.activiti.bpmn.model.EndEvent) Process(org.activiti.bpmn.model.Process) BpmnModel(org.activiti.bpmn.model.BpmnModel) JobDefinitionUpdateRequest(org.finra.herd.model.api.xml.JobDefinitionUpdateRequest) Test(org.junit.Test)

Example 33 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project herd by FINRAOS.

the class JobDefinitionServiceTest method testCreateJobDefinitionAssertSuccessWhenFirstTaskNotAsyncable.

/**
 * Asserts that create job definition proceeds without exceptions when first task does not support async (ex. events)
 *
 * @throws Exception
 */
@Test
public void testCreateJobDefinitionAssertSuccessWhenFirstTaskNotAsyncable() throws Exception {
    String namespace = NAMESPACE;
    String jobName = JOB_NAME;
    BpmnModel bpmnModel = new BpmnModel();
    Process process = new Process();
    process.setId(namespace + '.' + jobName);
    {
        StartEvent element = new StartEvent();
        element.setId("start");
        process.addFlowElement(element);
    }
    {
        EndEvent element = new EndEvent();
        element.setId("end");
        process.addFlowElement(element);
    }
    process.addFlowElement(new SequenceFlow("start", "end"));
    bpmnModel.addProcess(process);
    String activitiJobXml = getActivitiXmlFromBpmnModel(bpmnModel);
    namespaceDaoTestHelper.createNamespaceEntity(namespace);
    jobDefinitionService.createJobDefinition(new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null), true);
// Assert no exceptions
}
Also used : SequenceFlow(org.activiti.bpmn.model.SequenceFlow) StartEvent(org.activiti.bpmn.model.StartEvent) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) EndEvent(org.activiti.bpmn.model.EndEvent) Process(org.activiti.bpmn.model.Process) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 34 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project herd by FINRAOS.

the class JobDefinitionServiceTest method testCreateJobDefinitionAssertSuccessWhenFirstTaskAsync.

/**
 * Asserts that create job definition proceeds without exceptions when first task is set to async
 *
 * @throws Exception
 */
@Test
public void testCreateJobDefinitionAssertSuccessWhenFirstTaskAsync() throws Exception {
    String namespace = NAMESPACE;
    String jobName = JOB_NAME;
    BpmnModel bpmnModel = new BpmnModel();
    Process process = new Process();
    process.setId(namespace + '.' + jobName);
    {
        StartEvent element = new StartEvent();
        element.setId("start");
        process.addFlowElement(element);
    }
    {
        ScriptTask element = new ScriptTask();
        element.setId("script");
        element.setScriptFormat("js");
        element.setScript("// do nothing");
        element.setAsynchronous(true);
        process.addFlowElement(element);
    }
    {
        EndEvent element = new EndEvent();
        element.setId("end");
        process.addFlowElement(element);
    }
    process.addFlowElement(new SequenceFlow("start", "script"));
    process.addFlowElement(new SequenceFlow("script", "end"));
    bpmnModel.addProcess(process);
    String activitiJobXml = getActivitiXmlFromBpmnModel(bpmnModel);
    namespaceDaoTestHelper.createNamespaceEntity(namespace);
    jobDefinitionService.createJobDefinition(new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null), true);
// Assert no exceptions
}
Also used : ScriptTask(org.activiti.bpmn.model.ScriptTask) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) StartEvent(org.activiti.bpmn.model.StartEvent) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) EndEvent(org.activiti.bpmn.model.EndEvent) Process(org.activiti.bpmn.model.Process) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 35 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project herd by FINRAOS.

the class HerdActivitiServiceTaskTest method buildActivitiXml.

protected String buildActivitiXml(String implementation, List<FieldExtension> fieldExtensionList) throws Exception {
    BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_TEST_SERVICE_TASK_WITH_CLASSPATH);
    ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement(serviceTaskId);
    serviceTask.setImplementation(implementation);
    serviceTask.getFieldExtensions().addAll(fieldExtensionList);
    return getActivitiXmlFromBpmnModel(bpmnModel);
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Aggregations

BpmnModel (org.activiti.bpmn.model.BpmnModel)265 Test (org.junit.jupiter.api.Test)123 Test (org.junit.Test)57 Process (org.activiti.bpmn.model.Process)26 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)22 InputStream (java.io.InputStream)19 StartEvent (org.activiti.bpmn.model.StartEvent)17 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)16 ArrayList (java.util.ArrayList)14 FlowElement (org.activiti.bpmn.model.FlowElement)13 ServiceTask (org.activiti.bpmn.model.ServiceTask)13 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)12 EndEvent (org.activiti.bpmn.model.EndEvent)11 ValidationError (org.activiti.validation.ValidationError)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 SubProcess (org.activiti.bpmn.model.SubProcess)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 Deployment (org.activiti.engine.repository.Deployment)9 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 ProcessDiagramGenerator (org.activiti.image.ProcessDiagramGenerator)9