Java Code Examples for org.activiti.engine.RuntimeService#startProcessInstanceByKey()

The following examples show how to use org.activiti.engine.RuntimeService#startProcessInstanceByKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivitiRuleJunit4Test.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/activiti/engine/test/bpmn/async/AsyncTaskTest.testAsyncTask.bpmn20.xml" })
public void testWaitForJobs() {
  RuntimeService runtimeService = activitiRule.getRuntimeService();
  ManagementService managementService = activitiRule.getManagementService();

  // start process
  runtimeService.startProcessInstanceByKey("asyncTask");

  // now there should be one job in the database:
  assertEquals(1, managementService.createJobQuery().count());

  JobTestHelper.waitForJobExecutorToProcessAllJobs(activitiRule, 5000L, 500L);

  // the job is done
  assertEquals(0, managementService.createJobQuery().count());
}
 
Example 2
Source File: VerySimpleLeaveProcessTest.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
@Test
public void testStartProcess() throws Exception {
    // 创建流程引擎,使用内存数据库
    ProcessEngine processEngine = ProcessEngineConfiguration
            .createStandaloneInMemProcessEngineConfiguration()
            .buildProcessEngine();

    // 部署流程定义文件
    RepositoryService repositoryService = processEngine.getRepositoryService();
    String processFileName = "me/kafeitu/activiti/helloworld/sayhelloleave.bpmn";
    repositoryService.createDeployment().addClasspathResource(processFileName)
            .deploy();

    // 验证已部署流程定义
    ProcessDefinition processDefinition = repositoryService
            .createProcessDefinitionQuery().singleResult();
    assertEquals("leavesayhello", processDefinition.getKey());

    // 启动流程并返回流程实例
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService
            .startProcessInstanceByKey("leavesayhello");
    assertNotNull(processInstance);
    System.out.println("pid=" + processInstance.getId() + ", pdid="
            + processInstance.getProcessDefinitionId());
}
 
Example 3
Source File: MuleVMTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void send() throws Exception {
  Assert.assertTrue(muleContext.isStarted());

  ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  RepositoryService repositoryService = processEngine.getRepositoryService();
  Deployment deployment = repositoryService.createDeployment().addClasspathResource("org/activiti/mule/testVM.bpmn20.xml").deploy();

  RuntimeService runtimeService = processEngine.getRuntimeService();
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
  Assert.assertFalse(processInstance.isEnded());
  Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
  Assert.assertEquals(30, result);
  runtimeService.deleteProcessInstance(processInstance.getId(), "test");

  processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
  repositoryService.deleteDeployment(deployment.getId());
  assertAndEnsureCleanDb(processEngine);
  ProcessEngines.destroy();
}
 
Example 4
Source File: MuleHttpTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void http() throws Exception {
  Assert.assertTrue(muleContext.isStarted());

  ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  Deployment deployment = processEngine.getRepositoryService().createDeployment().addClasspathResource("org/activiti/mule/testHttp.bpmn20.xml").deploy();
  RuntimeService runtimeService = processEngine.getRuntimeService();
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
  Assert.assertFalse(processInstance.isEnded());
  Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
  Assert.assertEquals(20, result);
  runtimeService.deleteProcessInstance(processInstance.getId(), "test");
  processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
  processEngine.getRepositoryService().deleteDeployment(deployment.getId());
  assertAndEnsureCleanDb(processEngine);
  ProcessEngines.destroy();
}
 
Example 5
Source File: MuleHttpBasicAuthTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void httpWithBasicAuth() throws Exception {
  Assert.assertTrue(muleContext.isStarted());

  ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  Deployment deployment = processEngine.getRepositoryService()
      .createDeployment()
      .addClasspathResource("org/activiti5/mule/testHttpBasicAuth.bpmn20.xml")
      .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
      .deploy();
  RuntimeService runtimeService = processEngine.getRuntimeService();
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
  Assert.assertFalse(processInstance.isEnded());
  Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
  Assert.assertEquals(10, result);
  runtimeService.deleteProcessInstance(processInstance.getId(), "test");
  processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
  processEngine.getRepositoryService().deleteDeployment(deployment.getId());
  assertAndEnsureCleanDb(processEngine);
  ProcessEngines.destroy();
}
 
Example 6
Source File: MuleVMTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void send() throws Exception {
  Assert.assertTrue(muleContext.isStarted());

  ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  RepositoryService repositoryService = processEngine.getRepositoryService();
  Deployment deployment = repositoryService.createDeployment()
      .addClasspathResource("org/activiti5/mule/testVM.bpmn20.xml")
      .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
      .deploy();

  RuntimeService runtimeService = processEngine.getRuntimeService();
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
  Assert.assertFalse(processInstance.isEnded());
  Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
  Assert.assertEquals(30, result);
  runtimeService.deleteProcessInstance(processInstance.getId(), "test");

  processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
  repositoryService.deleteDeployment(deployment.getId());
  assertAndEnsureCleanDb(processEngine);
  ProcessEngines.destroy();
}
 
Example 7
Source File: IntegrationAutoConfigurationTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testLaunchingGatewayProcessDefinition() throws Exception {
    AnnotationConfigApplicationContext applicationContext = this.context(InboundGatewayConfiguration.class);
    
    RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
    RuntimeService runtimeService = applicationContext.getBean(RuntimeService.class);
    ProcessEngine processEngine = applicationContext.getBean(ProcessEngine.class);

    Assert.assertNotNull("the process engine should not be null", processEngine);
    Assert.assertNotNull("we should have a default repositoryService included", repositoryService);
    String integrationGatewayProcess = "integrationGatewayProcess";
    List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey(integrationGatewayProcess)
            .list();
    ProcessDefinition processDefinition = processDefinitionList.iterator().next();
    Assert.assertEquals(processDefinition.getKey(), integrationGatewayProcess);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("customerId", 232);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(integrationGatewayProcess, vars);
    Assert.assertNotNull("the processInstance should not be null", processInstance);
    org.junit.Assert.assertTrue(
            applicationContext.getBean(InboundGatewayConfiguration.AnalysingService.class)
                    .getStringAtomicReference().get().equals(projectId));
}
 
Example 8
Source File: ExpressionInJavaDelegateTestDataGenerator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void generateTestData(ProcessEngine processEngine) {
    RepositoryService repositoryService = processEngine.getRepositoryService();
    repositoryService.createDeployment().addClasspathResource("expressionInJavaDelegateProcess.bpmn20.xml").deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    runtimeService.startProcessInstanceByKey("expressionInJavaDelegate");
}
 
Example 9
Source File: ProcessTestExecutionListenerInTask.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
public void startProcess() throws Exception {
	RepositoryService repositoryService = activitiRule.getRepositoryService();
	repositoryService.createDeployment().addInputStream("executionListenerInTask.bpmn20.xml",
			new FileInputStream(filename)).deploy();
	RuntimeService runtimeService = activitiRule.getRuntimeService();
	Map<String, Object> variableMap = new HashMap<String, Object>();
	variableMap.put("name", "Activiti");
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("executionListenerInTask", variableMap);
	assertNotNull(processInstance.getId());
	System.out.println("id " + processInstance.getId() + " "
			+ processInstance.getProcessDefinitionId());
}
 
Example 10
Source File: ProcessTestExecutionListenerInTask.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
public void startProcess() throws Exception {
	RepositoryService repositoryService = activitiRule.getRepositoryService();
	repositoryService.createDeployment().addInputStream("executionListenerInTask.bpmn20.xml",
			new FileInputStream(filename)).deploy();
	RuntimeService runtimeService = activitiRule.getRuntimeService();
	Map<String, Object> variableMap = new HashMap<String, Object>();
	variableMap.put("name", "Activiti");
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("executionListenerInTask", variableMap);
	assertNotNull(processInstance.getId());
	System.out.println("id " + processInstance.getId() + " "
			+ processInstance.getProcessDefinitionId());
}
 
Example 11
Source File: Application.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Bean
CommandLineRunner basics(final RuntimeService runtimeService) {
    return new CommandLineRunner() {
        @Override
        public void run(String... strings) throws Exception {
            runtimeService.startProcessInstanceByKey("waiter", Collections.singletonMap("customerId", (Object) 243L));
        }
    };
}
 
Example 12
Source File: ProcessTestExecutionListenerInTask.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
public void startProcess() throws Exception {
	RepositoryService repositoryService = activitiRule.getRepositoryService();
	repositoryService.createDeployment().addInputStream("executionListenerInTask.bpmn20.xml",
			new FileInputStream(filename)).deploy();
	RuntimeService runtimeService = activitiRule.getRuntimeService();
	Map<String, Object> variableMap = new HashMap<String, Object>();
	variableMap.put("name", "Activiti");
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("executionListenerInTask", variableMap);
	assertNotNull(processInstance.getId());
	System.out.println("id " + processInstance.getId() + " "
			+ processInstance.getProcessDefinitionId());
}
 
Example 13
Source File: App.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	// 存储服务
	RepositoryService repositoryService = engine.getRepositoryService();
	// 运行时服务
	RuntimeService runtimeService = engine.getRuntimeService();
	// 任务服务
	TaskService taskService =engine.getTaskService();
	// 部署服务
	repositoryService.createDeployment().addClasspathResource("MyFirstProcess.bpmn").deploy();
	// process的id属性
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess");
	
	// 普通员工完成请假的任务
	Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("当前流程节点:" + task.getName());
	taskService.complete(task.getId());
	
	// 经理审批任务
	task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("当前流程节点:" + task.getName());
	taskService.complete(task.getId());
	
	// 流程结束
	task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("流程结束:" + task);
	// 关闭流程引擎
	engine.close();
}
 
Example 14
Source File: ActivitiSmokeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testDeploy() throws Exception
    {
        ProcessEngine engine = buildProcessEngine();

        RepositoryService repoService = engine.getRepositoryService();

        Deployment deployment = deployDefinition(repoService);

        assertNotNull(deployment);

        RuntimeService runtimeService = engine.getRuntimeService();
        try
        {
            ProcessInstance instance = runtimeService.startProcessInstanceByKey("testTask");
            assertNotNull(instance);
            
            String instanceId = instance.getId();
            ProcessInstance instanceInDb = findProcessInstance(runtimeService, instanceId);
            assertNotNull(instanceInDb);
            runtimeService.deleteProcessInstance(instanceId, "");
        }
        finally
        {
            
//            List<Deployment> deployments = repoService.createDeploymentQuery().list();
//            for (Deployment deployment2 : deployments)
//            {
//                repoService.deleteDeployment(deployment2.getId());
//            }
            
            repoService.deleteDeployment(deployment.getId());
        }
    }
 
Example 15
Source File: JavaDelegateTestDataGenerator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void generateTestData(ProcessEngine processEngine) {
  RepositoryService repositoryService = processEngine.getRepositoryService();
  repositoryService.createDeployment().addClasspathResource("javaDelegateProcess.bpmn20.xml").deploy();
  
  RuntimeService runtimeService = processEngine.getRuntimeService();
  runtimeService.startProcessInstanceByKey("javaDelegateTestProcess");
}
 
Example 16
Source File: ParseHandlerTestDataGenerator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void generateTestData(ProcessEngine processEngine) {
    RepositoryService repositoryService = processEngine.getRepositoryService();
    repositoryService.createDeployment().addClasspathResource("parseHandlerProcess.bpmn20.xml").deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    runtimeService.startProcessInstanceByKey("parseHandlerTestProcess");
}
 
Example 17
Source File: App.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	// 存储服务
	RepositoryService repositoryService = engine.getRepositoryService();
	// 运行时服务
	RuntimeService runtimeService = engine.getRuntimeService();
	// 任务服务
	TaskService taskService =engine.getTaskService();
	// 部署服务
	repositoryService.createDeployment().addClasspathResource("MyFirstProcess.bpmn").deploy();
	// process的id属性
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess");
	
	// 普通员工完成请假的任务
	Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("当前流程节点:" + task.getName());
	taskService.complete(task.getId());
	
	// 经理审批任务
	task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("当前流程节点:" + task.getName());
	taskService.complete(task.getId());
	
	// 流程结束
	task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("流程结束:" + task);
	// 关闭流程引擎
	engine.close();
}
 
Example 18
Source File: StartProcessInstanceTestDelegate.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
    RuntimeService runtimeService = Context.getProcessEngineConfiguration().getRuntimeService();
    runtimeService.startProcessInstanceByKey("oneTaskProcess");
}
 
Example 19
Source File: StartProcessInstanceTestDelegate.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
  RuntimeService runtimeService = Context.getProcessEngineConfiguration().getRuntimeService();
  runtimeService.startProcessInstanceByKey("oneTaskProcess");
}
 
Example 20
Source File: StartProcessInstanceTestDelegate.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
  RuntimeService runtimeService = Context.getProcessEngineConfiguration().getRuntimeService();
  runtimeService.startProcessInstanceByKey("oneTaskProcess");
}