org.camunda.bpm.engine.ProcessEngine Java Examples

The following examples show how to use org.camunda.bpm.engine.ProcessEngine. 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: MockedProcessEngineProvider.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void mockServices(ProcessEngine engine) {
  RepositoryService repoService = mock(RepositoryService.class);
  IdentityService identityService = mock(IdentityService.class);
  TaskService taskService = mock(TaskService.class);
  RuntimeService runtimeService = mock(RuntimeService.class);
  FormService formService = mock(FormService.class);
  HistoryService historyService = mock(HistoryService.class);
  ManagementService managementService = mock(ManagementService.class);
  CaseService caseService = mock(CaseService.class);
  FilterService filterService = mock(FilterService.class);
  ExternalTaskService externalTaskService = mock(ExternalTaskService.class);

  when(engine.getRepositoryService()).thenReturn(repoService);
  when(engine.getIdentityService()).thenReturn(identityService);
  when(engine.getTaskService()).thenReturn(taskService);
  when(engine.getRuntimeService()).thenReturn(runtimeService);
  when(engine.getFormService()).thenReturn(formService);
  when(engine.getHistoryService()).thenReturn(historyService);
  when(engine.getManagementService()).thenReturn(managementService);
  when(engine.getCaseService()).thenReturn(caseService);
  when(engine.getFilterService()).thenReturn(filterService);
  when(engine.getExternalTaskService()).thenReturn(externalTaskService);
}
 
Example #2
Source File: AbstractQueryDto.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void applySortingOptions(T query, ProcessEngine engine) {
  if (sortBy != null) {
    applySortBy(query, sortBy, null, engine);
  }
  if (sortOrder != null) {
    applySortOrder(query, sortOrder);
  }

  if (sortings != null) {
    for (SortingDto sorting : sortings) {
      String sortingOrder = sorting.getSortOrder();
      String sortingBy = sorting.getSortBy();

      if (sortingBy != null) {
        applySortBy(query, sortingBy, sorting.getParameters(), engine);
      }
      if (sortingOrder != null) {
        applySortOrder(query, sortingOrder);
      }
    }
  }
}
 
Example #3
Source File: NestedNonInterruptingEventSubprocessNestedSubprocessScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("init.innerSubProcess")
@ExtendsScenario("init")
@Times(6)
public static ScenarioSetup initNestedSubProcessEnterSubprocess() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      Task eventSubProcessTask = engine.getTaskService()
        .createTaskQuery()
        .processInstanceBusinessKey(scenarioName)
        .taskDefinitionKey("eventSubProcessTask")
        .singleResult();

      engine.getTaskService().complete(eventSubProcessTask.getId());
    }
  };
}
 
Example #4
Source File: EmbeddedProcessApplicationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testDeployAppWithCustomEngine() {

    TestApplicationWithCustomEngine processApplication = new TestApplicationWithCustomEngine();
    processApplication.deploy();

    ProcessEngine processEngine = BpmPlatform.getProcessEngineService().getProcessEngine("embeddedEngine");
    assertNotNull(processEngine);
    assertEquals("embeddedEngine", processEngine.getName());

    ProcessEngineConfiguration configuration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();

    // assert engine properties specified
    assertTrue(configuration.isJobExecutorDeploymentAware());
    assertTrue(configuration.isJobExecutorPreferTimerJobs());
    assertTrue(configuration.isJobExecutorAcquireByDueDate());
    assertEquals(5, configuration.getJdbcMaxActiveConnections());

    processApplication.undeploy();

  }
 
Example #5
Source File: SignalEventFactory.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public MigratingBpmnEventTrigger addEventSubProcess(ProcessEngine engine, BpmnModelInstance modelInstance, String parentId, String subProcessId, String startEventId) {
  ModifiableBpmnModelInstance.wrap(modelInstance)
    .addSubProcessTo(parentId)
    .id(subProcessId)
    .triggerByEvent()
    .embeddedSubProcess()
      .startEvent(startEventId).signal(SIGNAL_NAME)
    .subProcessDone()
    .done();

  SignalTrigger trigger = new SignalTrigger();
  trigger.engine = engine;
  trigger.signalName = SIGNAL_NAME;
  trigger.activityId = startEventId;

  return trigger;
}
 
Example #6
Source File: SequentialMultiInstanceCompensationScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("subProcessHandler.multiInstancePartial")
@Times(3)
public static ScenarioSetup subProcessHandlerMultiInstancePartial() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      engine
        .getRuntimeService()
        .startProcessInstanceByKey("SequentialMultiInstanceCompensationSubProcessHandlerScenario", scenarioName);

      // complete two out of three MI tasks
      Task miTask = engine.getTaskService().createTaskQuery()
          .processInstanceBusinessKey(scenarioName).singleResult();
      engine.getTaskService().complete(miTask.getId());

      miTask = engine.getTaskService().createTaskQuery()
          .processInstanceBusinessKey(scenarioName).singleResult();
      engine.getTaskService().complete(miTask.getId());
    }
  };
}
 
Example #7
Source File: HistoricIdentityLinkLogQueryDto.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void applySortBy(HistoricIdentityLinkLogQuery query, String sortBy, Map<String, Object> parameters, ProcessEngine engine) {
  if (sortBy.equals(SORT_BY_TIME)) {
    query.orderByTime();
  } else if (sortBy.equals(SORT_BY_TYPE)) {
    query.orderByType();
  } else if (sortBy.equals(SORT_BY_USER_ID)) {
    query.orderByUserId();
  } else if (sortBy.equals(SORT_BY_GROUP_ID)) {
    query.orderByGroupId();
  } else if (sortBy.equals(SORT_BY_TASK_ID)) {
    query.orderByTaskId();
  } else if (sortBy.equals(SORT_BY_OPERATION_TYPE)) {
    query.orderByOperationType();
  } else if (sortBy.equals(SORT_BY_ASSIGNER_ID)) {
    query.orderByAssignerId();
  } else if (sortBy.equals(SORT_BY_PROCESS_DEFINITION_ID)) {
    query.orderByProcessDefinitionId();
  } else if (sortBy.equals(SORT_BY_PROCESS_DEFINITION_KEY)) {
    query.orderByProcessDefinitionKey();
  } else if (sortBy.equals(SORT_BY_TENANT_ID)) {
    query.orderByTenantId();
  }
}
 
Example #8
Source File: TwoLevelNestedNonInterruptingEventSubprocessScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("initLevel1")
@Times(7)
public static ScenarioSetup initLevelOneEventSubProcess() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      engine
        .getRuntimeService()
        .startProcessInstanceByKey("NestedNonInterruptingMessageEventSubprocessScenarioNestedSubprocess",
            scenarioName);

      engine.getRuntimeService()
        .createMessageCorrelation("OuterEventSubProcessMessage")
        .processInstanceBusinessKey(scenarioName)
        .correlate();
    }
  };
}
 
Example #9
Source File: OSGiELTenantIntegrationTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
private void createProcessEngine() {
  StandaloneProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
  configuration.setDatabaseSchemaUpdate("create-drop")
    .setDataSource(createDatasource())
    .setJobExecutorActivate(false);
  configuration.setExpressionManager(new OSGiExpressionManager());
  ProcessEngineFactory processEngineFactory = new ProcessEngineFactory();
  processEngineFactory.setProcessEngineConfiguration(configuration);
  processEngineFactory
    .setBundle(getBundle("org.camunda.bpm.extension.osgi"));
  try {
    processEngineFactory.init();
    processEngine = processEngineFactory.getObject();
    ctx.registerService(ProcessEngine.class.getName(), processEngine,
      new Hashtable<String, String>());
  } catch (Exception e) {
    fail(e.toString());
  }
}
 
Example #10
Source File: Scenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void create(ProcessEngine engine, Map<String, Scenario> scenarios, String scenarioInstanceName) {
  // recursively set up all extended scenarios first
  if (extendedScenario != null) {
    if (scenarios.containsKey(extendedScenario)) {
      Scenario parentScenario = scenarios.get(extendedScenario);
      parentScenario.create(engine, scenarios, scenarioInstanceName);
    }
    else {
      throw new ProcessEngineException("Extended scenario " + extendedScenario + " not registered");
    }
  }

  if (setup != null) {
    setup.execute(engine, scenarioInstanceName);
  }
}
 
Example #11
Source File: SequentialMultiInstanceCompensationScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("subProcessHandler.beforeCompensate")
@Times(3)
public static ScenarioSetup subProcessHandlerBeforeCompensate() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      engine
        .getRuntimeService()
        .startProcessInstanceByKey("SequentialMultiInstanceCompensationSubProcessHandlerScenario", scenarioName);

      // complete all mi tasks
      Task miTask = engine.getTaskService().createTaskQuery()
          .processInstanceBusinessKey(scenarioName).singleResult();
      engine.getTaskService().complete(miTask.getId());

      miTask = engine.getTaskService().createTaskQuery()
          .processInstanceBusinessKey(scenarioName).singleResult();
      engine.getTaskService().complete(miTask.getId());

      miTask = engine.getTaskService().createTaskQuery()
          .processInstanceBusinessKey(scenarioName).singleResult();
      engine.getTaskService().complete(miTask.getId());
    }
  };
}
 
Example #12
Source File: CreateFilterConfigurationTest.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@Test
public void do_not_create_when_already_exist() throws Exception {
  CamundaBpmProperties camundaBpmProperties = new CamundaBpmProperties();
  camundaBpmProperties.getFilter().setCreate("All");
  final CreateFilterConfiguration configuration = new CreateFilterConfiguration();
  ReflectionTestUtils.setField(configuration, "camundaBpmProperties", camundaBpmProperties);
  configuration.init();

  ProcessEngine engine = mock(ProcessEngine.class);
  FilterService filterService = mock(FilterService.class);
  FilterQuery filterQuery = mock(FilterQuery.class);
  Filter filter = mock(Filter.class);

  when(engine.getFilterService()).thenReturn(filterService);
  when(filterService.createFilterQuery()).thenReturn(filterQuery);
  when(filterQuery.filterName(anyString())).thenReturn(filterQuery);
  when(filterQuery.singleResult()).thenReturn(filter);

  configuration.postProcessEngineBuild(engine);

  verify(filterService).createFilterQuery();
  verify(filterQuery).filterName("All");
  verify(filterService, never()).newTaskFilter("All");

}
 
Example #13
Source File: HistoryCleanupOnEngineBootstrapTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCreateHistoryCleanupJobLogs() {

  final ProcessEngineConfigurationImpl standaloneInMemProcessEngineConfiguration =
      (ProcessEngineConfigurationImpl)ProcessEngineConfiguration
          .createStandaloneInMemProcessEngineConfiguration();
  standaloneInMemProcessEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00");
  standaloneInMemProcessEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00");
  standaloneInMemProcessEngineConfiguration
      .setJdbcUrl("jdbc:h2:mem:camunda" + getClass().getSimpleName() + "testHistoryCleanupJobScheduled");

  ProcessEngine engine = standaloneInMemProcessEngineConfiguration.buildProcessEngine();
  try {
    List<HistoricJobLog> historicJobLogs = engine.getHistoryService()
                                                 .createHistoricJobLogQuery()
                                                 .jobDefinitionType(HistoryCleanupJobHandler.TYPE)
                                                 .list();
    for (HistoricJobLog historicJobLog : historicJobLogs) {
      assertNotNull(historicJobLog.getHostname());
    }
  } finally {
    closeProcessEngine(engine);
  }
}
 
Example #14
Source File: NonInterruptingEventSubprocessScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("init.outerTask")
@ExtendsScenario("init")
@Times(3)
public static ScenarioSetup completeSubprocessTask() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      Task task = engine
        .getTaskService()
        .createTaskQuery()
        .processInstanceBusinessKey(scenarioName)
        .taskDefinitionKey("outerTask")
        .singleResult();

      engine.getTaskService().complete(task.getId());
    }
  };
}
 
Example #15
Source File: SequentialMultiInstanceCompensationScenario.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@DescribesScenario("subProcessHandler.beforeCompensate.throwCompensate")
@ExtendsScenario("subProcessHandler.beforeCompensate")
@Times(3)
public static ScenarioSetup subProcessHandlerThrowCompensate() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      Task beforeCompensateTask = engine.getTaskService().createTaskQuery()
          .processInstanceBusinessKey(scenarioName).singleResult();

      engine.getTaskService().complete(beforeCompensateTask.getId());
    }
  };
}
 
Example #16
Source File: JobSuspensionStateDto.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected UpdateJobSuspensionStateBuilder createUpdateSuspensionStateBuilder(ProcessEngine engine) {
  UpdateJobSuspensionStateSelectBuilder selectBuilder = engine.getManagementService().updateJobSuspensionState();

  if (jobId != null) {
    return selectBuilder.byJobId(jobId);

  } else  if (jobDefinitionId != null) {
    return selectBuilder.byJobDefinitionId(jobDefinitionId);

  } else if (processInstanceId != null) {
    return selectBuilder.byProcessInstanceId(processInstanceId);

  } else if (processDefinitionId != null) {
    return selectBuilder.byProcessDefinitionId(processDefinitionId);

  } else {
    UpdateJobSuspensionStateTenantBuilder tenantBuilder = selectBuilder.byProcessDefinitionKey(processDefinitionKey);

    if (processDefinitionTenantId != null) {
      tenantBuilder.processDefinitionTenantId(processDefinitionTenantId);

    } else if (processDefinitionWithoutTenantId) {
      tenantBuilder.processDefinitionWithoutTenantId();
    }

    return tenantBuilder;
  }
}
 
Example #17
Source File: GroupQueryDto.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected void applySortBy(GroupQuery query, String sortBy, Map<String, Object> parameters, ProcessEngine engine) {
  if (sortBy.equals(SORT_BY_GROUP_ID_VALUE)) {
    query.orderByGroupId();
  } else if (sortBy.equals(SORT_BY_GROUP_NAME_VALUE)) {
    query.orderByGroupName();
  } else if (sortBy.equals(SORT_BY_GROUP_TYPE_VALUE)) {
    query.orderByGroupType();
  }
}
 
Example #18
Source File: TestFixture.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
    .createProcessEngineConfigurationFromResource("camunda.cfg.xml");
  ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();

  // register test scenarios
  ScenarioRunner runner = new ScenarioRunner(processEngine, ENGINE_VERSION);

  // compensation
  runner.setupScenarios(CreateProcessInstanceWithVariableScenario.class);

  processEngine.close();
}
 
Example #19
Source File: KeycloakAuthenticationProvider.java    From camunda-bpm-identity-keycloak with Apache License 2.0 5 votes vote down vote up
private List<String> getUserGroups(String userId, ProcessEngine engine){
    List<String> groupIds = new ArrayList<>();
    // query groups using KeycloakIdentityProvider plugin
    engine.getIdentityService().createGroupQuery().groupMember(userId).list()
    	.forEach( g -> groupIds.add(g.getId()));
    return groupIds;
}
 
Example #20
Source File: TestFixture.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
    .createProcessEngineConfigurationFromResource("camunda.cfg.xml");
  ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();

  // register test scenarios
  ScenarioRunner runner = new ScenarioRunner(processEngine, ENGINE_VERSION);

  // cmmn sentries
  runner.setupScenarios(SentryScenario.class);

  // compensation
  runner.setupScenarios(SingleActivityCompensationScenario.class);
  runner.setupScenarios(NestedCompensationScenario.class);
  runner.setupScenarios(SingleActivityConcurrentCompensationScenario.class);
  runner.setupScenarios(ParallelMultiInstanceCompensationScenario.class);
  runner.setupScenarios(SequentialMultiInstanceCompensationScenario.class);
  runner.setupScenarios(NestedMultiInstanceCompensationScenario.class);
  runner.setupScenarios(InterruptingEventSubProcessCompensationScenario.class);
  runner.setupScenarios(NonInterruptingEventSubProcessCompensationScenario.class);
  runner.setupScenarios(InterruptingEventSubProcessNestedCompensationScenario.class);

  // job
  runner.setupScenarios(JobMigrationScenario.class);

  // boundary events
  runner.setupScenarios(NonInterruptingBoundaryEventScenario.class);

  processEngine.close();
}
 
Example #21
Source File: ProcessWithExternalTaskScenario.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@DescribesScenario("init")
@Times(1)
public static ScenarioSetup startProcess() {
  return new ScenarioSetup() {

    @Override
    public void execute(ProcessEngine engine, String scenarioName) {
      deploy(engine, scenarioName);
      engine.getRuntimeService().startProcessInstanceByKey(PROCESS_DEF_KEY, scenarioName);
    }
  };
}
 
Example #22
Source File: IncidentQueryDto.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected void applySortBy(IncidentQuery query, String sortBy, Map<String, Object> parameters, ProcessEngine engine) {
  if (sortBy.equals(SORT_BY_INCIDENT_ID)) {
    query.orderByIncidentId();
  } else if (sortBy.equals(SORT_BY_INCIDENT_MESSAGE)) {
    query.orderByIncidentMessage();
  } else if (sortBy.equals(SORT_BY_INCIDENT_TIMESTAMP)) {
    query.orderByIncidentTimestamp();
  } else if (sortBy.equals(SORT_BY_INCIDENT_TYPE)) {
    query.orderByIncidentType();
  } else if (sortBy.equals(SORT_BY_EXECUTION_ID)) {
    query.orderByExecutionId();
  } else if (sortBy.equals(SORT_BY_ACTIVITY_ID)) {
    query.orderByActivityId();
  } else if (sortBy.equals(SORT_BY_PROCESS_INSTANCE_ID)) {
    query.orderByProcessInstanceId();
  } else if (sortBy.equals(SORT_BY_PROCESS_DEFINITION_ID)) {
    query.orderByProcessDefinitionId();
  } else if (sortBy.equals(SORT_BY_CAUSE_INCIDENT_ID)) {
    query.orderByCauseIncidentId();
  } else if (sortBy.equals(SORT_BY_ROOT_CAUSE_INCIDENT_ID)) {
    query.orderByRootCauseIncidentId();
  } else if (sortBy.equals(SORT_BY_CONFIGURATION)) {
    query.orderByConfiguration();
  } else if (sortBy.equals(SORT_BY_TENANT_ID)) {
    query.orderByTenantId();
  }
}
 
Example #23
Source File: ProcessEngineFactoryTest.java    From camunda-bpm-platform-osgi with Apache License 2.0 5 votes vote down vote up
@Test
public void initProcessEngine() throws Exception {
	// create mocks
	Bundle bundle = mock(Bundle.class);
	ProcessEngineConfiguration configuration = mock(ProcessEngineConfiguration.class);
	ProcessEngine engine = mock(ProcessEngine.class);
	// mock behaviour
	when(configuration.buildProcessEngine()).thenReturn(engine);
	ArgumentCaptor<ClassLoader> classLoaderCaptor = ArgumentCaptor
			.forClass(ClassLoader.class);
	// call methods
	factory.setBundle(bundle);
	factory.setProcessEngineConfiguration(configuration);
	factory.init();
	// checks
	verify(configuration).setClassLoader(classLoaderCaptor.capture());
	assertThat(classLoaderCaptor.getValue(),
			is(instanceOf(BundleDelegatingClassLoader.class)));
	BundleDelegatingClassLoader bundleDelCl = (BundleDelegatingClassLoader) classLoaderCaptor
			.getValue();
	assertThat(bundleDelCl.getBundle(), is(bundle));
	verify(configuration).buildProcessEngine();
	assertThat(Thread.currentThread().getContextClassLoader(),
			is(not(instanceOf(ClassLoaderWrapper.class))));
	assertThat(factory.getObject(), is(engine));
	assertThat(factory.getBundle(), is(bundle));
	assertThat(factory.getProcessEngineConfiguration(), is(configuration));
	factory.destroy();
	verify(engine).close();
}
 
Example #24
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public Set<String> getProcessEngineNames() {
  HashSet<String> result = new HashSet<String>();
  for (ProcessEngine engine : processEngines) {
    result.add(engine.getName());
  }
  return result;
}
 
Example #25
Source File: FetchAndLockHandlerImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected FetchAndLockResult tryFetchAndLock(FetchAndLockRequest request) {

    ProcessEngine processEngine = null;
    IdentityService identityService = null;
    FetchAndLockResult result = null;

    try {
      processEngine = getProcessEngine(request);

      identityService = processEngine.getIdentityService();
      identityService.setAuthentication(request.getAuthentication());

      FetchExternalTasksExtendedDto fetchingDto = request.getDto();
      List<LockedExternalTaskDto> lockedTasks = executeFetchAndLock(fetchingDto, processEngine);
      result = FetchAndLockResult.successful(lockedTasks);
    }
    catch (Exception e) {
      result = FetchAndLockResult.failed(e);
    }
    finally {
      if (identityService != null) {
        identityService.clearAuthentication();
      }
    }

    return result;
  }
 
Example #26
Source File: PurgeDatabaseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that the database is clean after the test. This means the test has to remove
 * all resources it entered to the database.
 * If the DB is not clean, it is cleaned by performing a create a drop.
 *
 * @param processEngine the {@link ProcessEngine} to check
 * @param fail if true the method will throw an {@link AssertionError} if the database is not clean
 * @return the database summary if fail is set to false or null if database was clean
 * @throws AssertionError if the database was not clean and fail is set to true
 */
public static void assertAndEnsureCleanDb(ProcessEngine processEngine) {
  ProcessEngineConfigurationImpl processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
  String databaseTablePrefix = processEngineConfiguration.getDatabaseTablePrefix().trim();

  Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();

  StringBuilder outputMessage = new StringBuilder();
  for (String tableName : tableCounts.keySet()) {
    String tableNameWithoutPrefix = tableName.replace(databaseTablePrefix, "");
    if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
      Long count = tableCounts.get(tableName);
      if (count!=0L) {
        outputMessage.append("\t").append(tableName).append(": ").append(count).append(" record(s)\n");
      }
    }
  }

  if (outputMessage.length() > 0) {
    outputMessage.insert(0, "DB NOT CLEAN: \n");
    /** skip drop and recreate if a table prefix is used */
    if (databaseTablePrefix.isEmpty()) {
      processEngineConfiguration
        .getCommandExecutorSchemaOperations()
        .execute(new Command<Object>() {
          public Object execute(CommandContext commandContext) {
            PersistenceSession persistenceSession = commandContext.getSession(PersistenceSession.class);
            persistenceSession.dbSchemaDrop();
            persistenceSession.dbSchemaCreate();
            HistoryLevelSetupCommand.dbCreateHistoryLevel(commandContext);
            return null;
          }
        });
    }
    Assert.fail(outputMessage.toString());
  }
}
 
Example #27
Source File: ExecutionQueryDto.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected void applySortBy(ExecutionQuery query, String sortBy, Map<String, Object> parameters, ProcessEngine engine) {
  if (sortBy.equals(SORT_BY_INSTANCE_ID_VALUE)) {
    query.orderByProcessInstanceId();
  } else if (sortBy.equals(SORT_BY_DEFINITION_KEY_VALUE)) {
    query.orderByProcessDefinitionKey();
  } else if (sortBy.equals(SORT_BY_DEFINITION_ID_VALUE)) {
    query.orderByProcessDefinitionId();
  } else if (sortBy.equals(SORT_BY_TENANT_ID)) {
    query.orderByTenantId();
  }
}
 
Example #28
Source File: TestHelper.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static String assertAndEnsureNoProcessApplicationsRegistered(ProcessEngine processEngine) {
  ProcessEngineConfigurationImpl engineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
  ProcessApplicationManager processApplicationManager = engineConfiguration.getProcessApplicationManager();

  if (processApplicationManager.hasRegistrations()) {
    processApplicationManager.clearRegistrations();
    return "There are still process applications registered";
  }
  else {
    return null;
  }

}
 
Example #29
Source File: MockedProcessEngineProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private ProcessEngine mockProcessEngine(String engineName) {
  ProcessEngine engine = mock(ProcessEngine.class);
  when(engine.getName()).thenReturn(engineName);
  mockServices(engine);
  mockProcessEngineConfiguration(engine);
  return engine;
}
 
Example #30
Source File: TransactionCancelCompensationScenario.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@DescribesScenario("init.triggerCompensation")
@ExtendsScenario("init")
@Times(3)
public static ScenarioSetup instantiateAndTriggerCompensation() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      // throw compensation by executing the cancel end event;
      // the compensation handler for userTask should then be active
      Task beforeCancelTask = engine.getTaskService().createTaskQuery()
          .processInstanceBusinessKey(scenarioName).singleResult();
      engine.getTaskService().complete(beforeCancelTask.getId());
    }
  };
}