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

The following examples show how to use org.camunda.bpm.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: StartProcessIntanceWithInitialVariablesScenario.java    From camunda-bpm-platform with Apache License 2.0 7 votes vote down vote up
@DescribesScenario("startProcessIntanceWithInitialVariablesScenario")
public static ScenarioSetup createUserOperationLogEntries() {
  return new ScenarioSetup() {
    @Override
    public void execute(ProcessEngine engine, String scenarioName) {
      RuntimeService runtimeService = engine.getRuntimeService();

      String businessKey = "712_ProcessIntanceExecuted";
      runtimeService.startProcessInstanceByKey("asyncBeforeStartProcess_712", businessKey,
          Variables.createVariables()
              .putValue("initial1", "value1"));

      businessKey = "7120_ProcessIntanceWithoutExecute";
      runtimeService.startProcessInstanceByKey("asyncBeforeStartProcess_712", businessKey,
          Variables.createVariables()
          .putValue("initial2", "value1"));

      businessKey = "7120_ProcessIntanceWithoutExecuteAndSetVariables";
      runtimeService.startProcessInstanceByKey("asyncBeforeStartProcess_712", businessKey,
          Variables.createVariables()
          .putValue("initial3", "value1"));
    }
  };
}
 
Example 2
Source File: VariableInstanceQueryForOracleTest.java    From camunda-bpm-platform with Apache License 2.0 7 votes vote down vote up
@Test
public void testQueryWhen1001InstancesActive() {
  // given
  Assume.assumeTrue(engineRule.getProcessEngineConfiguration().getDatabaseType().equals("oracle"));
  RuntimeService runtimeService = engineRule.getRuntimeService();
  testRule.deploy(ProcessModels.TWO_TASKS_PROCESS);
  String[] ids = new String[1001];

  // when
  for (int i = 0; i < 1001; i++) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process",
        Variables.createVariables().putValue("foo", "bar"));
    String activityInstanceId = runtimeService.getActivityInstance(processInstance.getId()).getId();
    ids[i] = activityInstanceId;
  }

  // then
  List<VariableInstance> variables = engineRule.getRuntimeService().createVariableInstanceQuery()
      .activityInstanceIdIn(ids).list();
  assertEquals(1001, variables.size());
}
 
Example 3
Source File: TestBPMModule.java    From Orienteer with Apache License 2.0 7 votes vote down vote up
@Test
@Deployment(resources = { "example-sequence.bpmn" })
public void testCorrelateByMessageName() {
	RuntimeService runtimeService = processEngineRule.getRuntimeService();
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process_1");
	assertProcessNotEnded(processInstance.getId());

	// correlate by message name
	runtimeService.createMessageCorrelation("Message-Request").correlate();
	assertProcessNotEnded(processInstance.getId());

	// correlate by message name and process id
	runtimeService.createMessageCorrelation("Message-Approve").processInstanceId(processInstance.getId())
			.correlate();
	assertProcessEnded(processInstance.getId());
}
 
Example 4
Source File: VariableInstanceQueryForOracleTest.java    From camunda-bpm-platform with Apache License 2.0 7 votes vote down vote up
@Test
public void testQueryWhen1000InstancesActive() {
  // given
  Assume.assumeTrue(engineRule.getProcessEngineConfiguration().getDatabaseType().equals("oracle"));
  RuntimeService runtimeService = engineRule.getRuntimeService();
  testRule.deploy(ProcessModels.TWO_TASKS_PROCESS);
  String[] ids = new String[1000];

  // when
  for (int i = 0; i < 1000; i++) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process",
        Variables.createVariables().putValue("foo", "bar"));
    String activityInstanceId = runtimeService.getActivityInstance(processInstance.getId()).getId();
    ids[i] = activityInstanceId;
  }

  // then
  List<VariableInstance> variables = engineRule.getRuntimeService().createVariableInstanceQuery()
      .activityInstanceIdIn(ids).list();
  assertEquals(1000, variables.size());
}
 
Example 5
Source File: TestBPMModule.java    From Orienteer with Apache License 2.0 7 votes vote down vote up
@Test
@Deployment(resources = { "example-sequence.bpmn" })
public void testCorrelateByVariables() {
	RuntimeService runtimeService = processEngineRule.getRuntimeService();
	Map<String, Object> vars = new HashMap<String, Object>();
	vars.put("testString", "testVarString");
	vars.put("testBoolean", new Boolean(true));
	vars.put("testLong", new Long(15));

	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process_1", vars);
	assertProcessNotEnded(processInstance.getId());

	runtimeService.createMessageCorrelation("Message-Request")
			.processInstanceVariableEquals("testString", "testVarString").correlate();
	assertProcessNotEnded(processInstance.getId());

	runtimeService.createMessageCorrelation(null).processInstanceVariableEquals("testString", "NonExisting")
			.correlateAll();
	assertProcessNotEnded(processInstance.getId());

	runtimeService.createMessageCorrelation(null).processInstanceVariableEquals("testString", "testVarString")
			.correlate();

	assertProcessEnded(processInstance.getId());
}
 
Example 6
Source File: VariableInstanceQueryForOracleTest.java    From camunda-bpm-platform with Apache License 2.0 7 votes vote down vote up
@Test
public void testQueryWhen1InstanceActive() {
  // given
  Assume.assumeTrue(engineRule.getProcessEngineConfiguration().getDatabaseType().equals("oracle"));
  RuntimeService runtimeService = engineRule.getRuntimeService();
  testRule.deploy(ProcessModels.TWO_TASKS_PROCESS);

  // when
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process",
      Variables.createVariables().putValue("foo", "bar"));
  String activityInstanceId = runtimeService.getActivityInstance(processInstance.getId()).getId();

  // then
  List<VariableInstance> variables = engineRule.getRuntimeService().createVariableInstanceQuery()
      .activityInstanceIdIn(activityInstanceId).list();
  assertEquals(1, variables.size());
}
 
Example 7
Source File: OSGiELTenantIntegrationTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 7 votes vote down vote up
@Test
public void tenantSubprocessShouldBeResolved() throws InterruptedException {
  Hashtable<String, String> properties = new Hashtable<String, String>();
  properties.put("processExpression", "calledElementTenantIdProvider");
  MockedCalledElementTenantIdProvider service = new MockedCalledElementTenantIdProvider("t1");
  ctx.registerService(MockedCalledElementTenantIdProvider.class, service, properties);

  RuntimeService runtimeService = processEngine.getRuntimeService();
  runtimeService.startProcessInstanceByKey("tenantParentProcess");

  ProcessInstance processInstance = processEngine.getRuntimeService().createProcessInstanceQuery()
    .processDefinitionKey("Process_1").singleResult();
  assertThat(processInstance.isEnded(), is(false));
  Task task = processEngine.getTaskService().createTaskQuery().singleResult();
  assertThat(task.getName(), is("specific tenant task"));
}
 
Example 8
Source File: ProcessEngineRuleParameterizedJunit4Test.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/standalone/testing/ProcessEngineRuleParameterizedJunit4Test.ruleUsageExample.bpmn20.xml")
public void ruleUsageExampleWithNamedAnnotation() {
  RuntimeService runtimeService = engineRule.getRuntimeService();
  runtimeService.startProcessInstanceByKey("ruleUsage");

  TaskService taskService = engineRule.getTaskService();
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("My Task", task.getName());

  taskService.complete(task.getId());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
 
Example 9
Source File: MigrationIncidentTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomIncidentMigrationWithoutConfiguration() {
  // given
  RuntimeService runtimeService = engineRule.getRuntimeService();
  BpmnModelInstance instance1 = Bpmn.createExecutableProcess("process1").startEvent().userTask("u1").endEvent().done();
  BpmnModelInstance instance2 = Bpmn.createExecutableProcess("process2").startEvent().userTask("u2").endEvent().done();

  testHelper.deploy(instance1, instance2);

  ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("process1");
  ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("process2");

  MigrationPlan migrationPlan = runtimeService
      .createMigrationPlan(processInstance1.getProcessDefinitionId(), processInstance2.getProcessDefinitionId())
      .mapActivities("u1", "u2")
      .build();

  runtimeService.createIncident("custom", processInstance1.getId(), null);

  // when
  runtimeService.newMigration(migrationPlan).processInstanceIds(processInstance1.getId()).execute();

  // then
  Incident incident = runtimeService.createIncidentQuery().singleResult();
  assertEquals(processInstance2.getProcessDefinitionId(), incident.getProcessDefinitionId());
  assertEquals("custom", incident.getIncidentType());
  assertEquals(processInstance1.getId(), incident.getExecutionId());
}
 
Example 10
Source File: ProcessEngineRuleParameterizedJunit4Test.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Unnamed @Deployment annotations don't work with parameterized Unit tests
 */
@Ignore
@Test
@Deployment
public void ruleUsageExample() {
  RuntimeService runtimeService = engineRule.getRuntimeService();
  runtimeService.startProcessInstanceByKey("ruleUsage");

  TaskService taskService = engineRule.getTaskService();
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("My Task", task.getName());

  taskService.complete(task.getId());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
 
Example 11
Source File: TestBPMModule.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "example.bpmn" })
public void testEndProcessByCancelMessage() {
	RuntimeService runtimeService = processEngineRule.getRuntimeService();
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process_1");
	assertProcessNotEnded(processInstance.getId());

	runtimeService.createMessageCorrelation("Message-Cancel").processInstanceId(processInstance.getId())
			.correlate();

}
 
Example 12
Source File: ProcessEngineRuleJunit4Test.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void ruleUsageExample() {
  RuntimeService runtimeService = engineRule.getRuntimeService();
  runtimeService.startProcessInstanceByKey("ruleUsage");

  TaskService taskService = engineRule.getTaskService();
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("My Task", task.getName());

  taskService.complete(task.getId());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
 
Example 13
Source File: TestBPMModule.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "example-sequence.bpmn" })
public void testCorrelateByBusinessKey() {
	RuntimeService runtimeService = processEngineRule.getRuntimeService();
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process_1", "business key");
	assertProcessNotEnded(processInstance.getId());

	runtimeService.createMessageCorrelation("Message-Request")
			.processInstanceBusinessKey(processInstance.getBusinessKey()).correlate();
	assertProcessNotEnded(processInstance.getId());

	runtimeService.createMessageCorrelation(null).processInstanceBusinessKey(processInstance.getBusinessKey())
			.correlateAll();
	assertProcessEnded(processInstance.getId());
}
 
Example 14
Source File: TestBPMModule.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "example-sequence.bpmn" })
public void testEndProcessByCancelMessageSequence() {
	RuntimeService runtimeService = processEngineRule.getRuntimeService();
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process_1");
	assertProcessNotEnded(processInstance.getId());

	runtimeService.createMessageCorrelation("Message-Request").processInstanceId(processInstance.getId())
			.correlate();
	assertProcessNotEnded(processInstance.getId());

	runtimeService.createMessageCorrelation("Message-Approve").processInstanceId(processInstance.getId())
			.correlate();
	assertProcessEnded(processInstance.getId());
}
 
Example 15
Source File: TestBPMModule.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "example-simple.bpmn" })
public void testEndProcessByCancelMessageSimple() {
	RuntimeService runtimeService = processEngineRule.getRuntimeService();
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process_1");
	assertProcessNotEnded(processInstance.getId());

	runtimeService.createMessageCorrelation("Message-Approve").processInstanceId(processInstance.getId())
			.correlate();

	assertProcessEnded(processInstance.getId());
}
 
Example 16
Source File: MyDelegationService.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void executeCommand(RuntimeService runtimeService) {
  runtimeService.startProcessInstanceByKey("process");
}
 
Example 17
Source File: ProcessDataLoggingContextTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {
  RuntimeService runtimeService = execution.getProcessEngine().getRuntimeService();
  runtimeService.startProcessInstanceByKey(FAILING_PROCESS, (String) null);
}
 
Example 18
Source File: TestDataGenerator.java    From camunda-bpm-elasticsearch with Apache License 2.0 4 votes vote down vote up
public static HashMap<String, ProcessDataContainer> startInvoiceProcess(ProcessEngine processEngine, final int numberOfInstances, boolean addRandomTimeInterval) {
  RepositoryService repositoryService = processEngine.getRepositoryService();
  RuntimeService runtimeService = processEngine.getRuntimeService();
  TaskService taskService = processEngine.getTaskService();

  Deployment deployment = repositoryService.createDeployment().addClasspathResource("invoice.bpmn").deploy();
  Assert.assertNotNull(repositoryService.createDeploymentQuery().deploymentId(deployment.getId()).singleResult());

  LOGGER.info("Creating " + numberOfInstances + " instances of 'invoice.bpmn' process.");


  HashMap<String, ProcessDataContainer> variablesByProcessIds = new HashMap<String, ProcessDataContainer>(numberOfInstances);

  for (int i = 0; i < numberOfInstances; i++) {
    if (addRandomTimeInterval) {
      ClockUtil.setCurrentTime(new Date(ClockUtil.getCurrentTime().getTime() + getRandomLong()));
    }

    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put(TestDataGenerator.getRandomString(), TestDataGenerator.getRandomString());
    variables.put("long", TestDataGenerator.getRandomLong());
    variables.put("double", TestDataGenerator.getRandomDouble());

    ProcessInstance pi = runtimeService.startProcessInstanceByKey("invoice", variables);
    Assert.assertNotNull(pi);

    List<Task> tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).list();

    assertEquals(1, tasks.size());
    assertEquals("assignApprover", tasks.get(0).getTaskDefinitionKey());

    variables.clear();
    String approver = TestDataGenerator.getRandomString();
    variables.put("approver", approver);
    taskService.complete(tasks.get(0).getId(), variables);

    tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).list();

    assertEquals(1, tasks.size());
    assertEquals("approveInvoice", tasks.get(0).getTaskDefinitionKey());
    assertEquals(approver, tasks.get(0).getAssignee());

    variables.clear();
    variables.put("approved", Boolean.TRUE);
    taskService.complete(tasks.get(0).getId(), variables);

    tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).list();

    // retrieve all variables
    List<VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().processInstanceIdIn(pi.getProcessInstanceId()).list();
    variablesByProcessIds.put(pi.getProcessInstanceId(), new ProcessDataContainer(pi.getProcessInstanceId(), pi.getBusinessKey(), variableInstances));

    assertEquals(1, tasks.size());
    assertEquals("prepareBankTransfer", tasks.get(0).getTaskDefinitionKey());
    taskService.complete(tasks.get(0).getId());

    ProcessEngineAssert.assertProcessEnded(processEngine, pi.getId());
  }

  LOGGER.info("Created " + numberOfInstances + " instances of 'invoice.bpmn' process.");

  return variablesByProcessIds;
}
 
Example 19
Source File: DeployProcessWithoutIsExecutableAttributeTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeployProcessWithoutIsExecutableAttribute() {
  RuntimeService runtimeService = engineRule.getRuntimeService();
  ProcessInstance procInstance = runtimeService.startProcessInstanceByKey("processWithoutIsExecutableAttribute");
  Assert.assertNotNull(procInstance);
}
 
Example 20
Source File: NestedExecutionAPIInvocationTest.java    From camunda-bpm-platform with Apache License 2.0 3 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {

  RuntimeService runtimeService = engine.getRuntimeService();

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");

  // then the wait state is reached immediately after instantiation
  ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId());
  ActivityInstance[] activityInstances = activityInstance.getActivityInstances("waitState");
  Assert.assertEquals(1, activityInstances.length);

}