org.activiti.engine.impl.ProcessEngineImpl Java Examples

The following examples show how to use org.activiti.engine.impl.ProcessEngineImpl. 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: MetaDataTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testMetaData() {
  ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor().execute(new Command<Object>() {
    public Object execute(CommandContext commandContext) {
      // PRINT THE TABLE NAMES TO CHECK IF WE CAN USE METADATA INSTEAD
      // THIS IS INTENDED FOR TEST THAT SHOULD RUN ON OUR QA
      // INFRASTRUCTURE TO SEE IF METADATA
      // CAN BE USED INSTEAD OF PERFORMING A QUERY THAT MIGHT FAIL
      try {
        SqlSession sqlSession = commandContext.getDbSqlSession().getSqlSession();
        ResultSet tables = sqlSession.getConnection().getMetaData().getTables(null, null, null, null);
        while (tables.next()) {
          ResultSetMetaData resultSetMetaData = tables.getMetaData();
          int columnCount = resultSetMetaData.getColumnCount();
          for (int i = 1; i <= columnCount; i++) {
            log.info("result set column {}|{}|{}|{}", i, resultSetMetaData.getColumnName(i), resultSetMetaData.getColumnLabel(i), tables.getString(i));
          }
          log.info("-------------------------------------------------------");
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      return null;
    }
  });
}
 
Example #2
Source File: PluggableActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void initializeProcessEngine() {
  if (cachedProcessEngine == null) {

    pluggableActivitiTestCaseLogger.info("No cached process engine found for test. Retrieving the default engine.");
    ProcessEngines.destroy(); // Just to be sure we're not getting any previously cached version

    cachedProcessEngine = ProcessEngines.getDefaultProcessEngine();
    if (cachedProcessEngine == null) {
      throw new ActivitiException("no default process engine available");
    }
  }
  
  processEngine = cachedProcessEngine;
  processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
  
  // Enable verbose execution tree debugging if needed
  if (this.getClass().isAnnotationPresent(EnableVerboseExecutionTreeLogging.class)) {
    swapCommandInvoker(true);
  }
  
}
 
Example #3
Source File: PlaybackRunTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessInstanceStartEvents() throws Exception {
  recordEvents();

  final SimpleSimulationRun.Builder builder = new SimpleSimulationRun.Builder();
  // init simulation run
  Clock clock = new ThreadLocalClock(new DefaultClockFactory());
  ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
  config.setClock(clock);
  SimulationProcessEngineFactory simulationProcessEngineFactory = new SimulationProcessEngineFactory(config);
  final ProcessEngineImpl simProcessEngine = simulationProcessEngineFactory.getObject();

  builder.processEngine(simProcessEngine)
    .eventCalendar((new SimpleEventCalendarFactory(clock, new SimulationEventComparator(), listener.getSimulationEvents())).getObject())
    .eventHandlers(getHandlers());
  SimpleSimulationRun simRun = builder.build();

  simRun.execute(new NoExecutionVariableScope());

  checkStatus(simProcessEngine);

  simProcessEngine.getProcessEngineConfiguration().setDatabaseSchemaUpdate("create-drop");
  simProcessEngine.close();
  ProcessEngines.destroy();
}
 
Example #4
Source File: AbstractActviti6Test.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@After
public void logCommandInvokerDebugInfo() {

  ProcessExecutionLoggerConfigurator loggerConfigurator = null;
  List<ProcessEngineConfigurator> configurators = ((ProcessEngineImpl) cachedProcessEngine).getProcessEngineConfiguration().getConfigurators();
  if (configurators != null && configurators.size() > 0) {
    for (ProcessEngineConfigurator configurator : configurators) {
      if (configurator instanceof ProcessExecutionLoggerConfigurator) {
        loggerConfigurator = (ProcessExecutionLoggerConfigurator) configurator;
        break;
      }
    }

    if (loggerConfigurator != null) {
      loggerConfigurator.getProcessExecutionLogger().logDebugInfo(true);
    }
  }
}
 
Example #5
Source File: AbstractActviti6Test.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Before
public void initProcessEngine() {
  if (cachedProcessEngine == null) {
    cachedProcessEngine = activitiRule.getProcessEngine();

    // Boot up H2 webapp
    if (cachedProcessEngine instanceof ProcessEngineImpl) {
      if (((ProcessEngineImpl) cachedProcessEngine).getProcessEngineConfiguration().getJdbcUrl().equals(H2_TEST_JDBC_URL)) {
        initializeH2WebApp(cachedProcessEngine);
      }
    }
  }

  this.processEngineConfiguration = (ProcessEngineConfigurationImpl) cachedProcessEngine.getProcessEngineConfiguration();
  this.repositoryService = cachedProcessEngine.getRepositoryService();
  this.runtimeService = cachedProcessEngine.getRuntimeService();
  this.taskService = cachedProcessEngine.getTaskService();
  this.formService = cachedProcessEngine.getFormService();
  this.historyService = cachedProcessEngine.getHistoryService();
  this.managementService = cachedProcessEngine.getManagementService();
}
 
Example #6
Source File: ActivitiMockSupport.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ActivitiMockSupport(ProcessEngine processEngine) {
  ProcessEngineConfigurationImpl processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
  org.activiti5.engine.impl.cfg.ProcessEngineConfigurationImpl activiti5ProcessEngineConfiguration = (org.activiti5.engine.impl.cfg.ProcessEngineConfigurationImpl) 
      processEngineConfiguration.getActiviti5CompatibilityHandler().getRawProcessConfiguration();
  ActivityBehaviorFactory existingActivityBehaviorFactory = activiti5ProcessEngineConfiguration.getActivityBehaviorFactory();
  this.testActivityBehaviorFactory = new TestActivityBehaviorFactory(existingActivityBehaviorFactory);

  activiti5ProcessEngineConfiguration.setActivityBehaviorFactory(testActivityBehaviorFactory);
  activiti5ProcessEngineConfiguration.getBpmnParser().setActivityBehaviorFactory(testActivityBehaviorFactory);
}
 
Example #7
Source File: ActivitiEngineInitializer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onBootstrap(ApplicationEvent event) {
	
	this.processEngine = getApplicationContext().getBean(ProcessEngine.class);
	
	if (workflowAdminService.isEngineEnabled(ActivitiConstants.ENGINE_ID)) 
	{
		((ProcessEngineImpl)processEngine).getProcessEngineConfiguration().getJobExecutor().start();
	}
}
 
Example #8
Source File: ReplayRunTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessInstanceStartEvents() throws Exception {
  ProcessEngineImpl processEngine = initProcessEngine();

  TaskService taskService = processEngine.getTaskService();
  RuntimeService runtimeService = processEngine.getRuntimeService();

  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put(TEST_VARIABLE, TEST_VALUE);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(USERTASK_PROCESS, BUSINESS_KEY, variables);

  Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult();
  TimeUnit.MILLISECONDS.sleep(50);
  taskService.complete(task.getId());

  final SimulationDebugger simRun = new ReplaySimulationRun(processEngine, getReplayHandlers(processInstance.getId()));

  simRun.init(new NoExecutionVariableScope());

  // original process is finished - there should not be any running process instance/task
  assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
  assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

  simRun.step();

  // replay process was started
  assertEquals(1, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
  // there should be one task
  assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

  simRun.step();

  // userTask was completed - replay process was finished
  assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
  assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

  simRun.close();
  processEngine.close();
  ProcessEngines.destroy();
}
 
Example #9
Source File: ReplayRunTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private ProcessEngineImpl initProcessEngine() {
  ProcessEngineConfigurationImpl configuration = getProcessEngineConfiguration();
  ProcessEngineImpl processEngine = (ProcessEngineImpl) configuration.buildProcessEngine();

  processEngine.getRepositoryService().
      createDeployment().
      addClasspathResource(THE_USERTASK_PROCESS).
      deploy();
  return processEngine;
}
 
Example #10
Source File: ActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void initializeServices() {
  processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
  repositoryService = processEngine.getRepositoryService();
  runtimeService = processEngine.getRuntimeService();
  taskService = processEngine.getTaskService();
  historicDataService = processEngine.getHistoryService();
  identityService = processEngine.getIdentityService();
  managementService = processEngine.getManagementService();
  formService = processEngine.getFormService();
}
 
Example #11
Source File: ReplayEventLogTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private ProcessEngineImpl initProcessEngine() {
  ProcessEngineConfigurationImpl configuration = getProcessEngineConfiguration();
  ProcessEngineImpl processEngine = (ProcessEngineImpl) configuration.buildProcessEngine();

  processEngine.getRepositoryService().
      createDeployment().
      addClasspathResource(THE_USERTASK_PROCESS).
      deploy();
  return processEngine;
}
 
Example #12
Source File: CdiActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

  beanManager = ProgrammaticBeanLookup.lookup(BeanManager.class);
  processEngine = ProgrammaticBeanLookup.lookup(ProcessEngine.class);
  processEngineConfiguration = ((ProcessEngineImpl) ProcessEngineLookupForTestsuite.processEngine).getProcessEngineConfiguration();
  activitiRule.setProcessEngineConfiguration(processEngineConfiguration);
  formService = processEngine.getFormService();
  historyService = processEngine.getHistoryService();
  identityService = processEngine.getIdentityService();
  managementService = processEngine.getManagementService();
  repositoryService = processEngine.getRepositoryService();
  runtimeService = processEngine.getRuntimeService();
  taskService = processEngine.getTaskService();
}
 
Example #13
Source File: AbstractActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void initializeServices() {
  processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
  repositoryService = processEngine.getRepositoryService();
  runtimeService = processEngine.getRuntimeService();
  taskService = processEngine.getTaskService();
  formService = processEngine.getFormService();
  historyService = processEngine.getHistoryService();
  identityService = processEngine.getIdentityService();
  managementService = processEngine.getManagementService();
  dynamicBpmnService = processEngine.getDynamicBpmnService();
}
 
Example #14
Source File: EventRecorderTestUtils.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static void closeProcessEngine(ProcessEngine processEngine, ActivitiEventListener listener) {
  if (listener != null) {
    final ProcessEngineConfigurationImpl processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
    processEngineConfiguration.getEventDispatcher().removeEventListener(listener);
  }
  processEngine.close();
}
 
Example #15
Source File: BaseJPARestTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Each test is assumed to clean up all DB content it entered. After a test method executed, this method scans all tables to see if the DB is completely clean. It throws AssertionFailed in case the
 * DB is not clean. If the DB is not clean, it is cleaned by performing a create a drop.
 */
protected void assertAndEnsureCleanDb() throws Throwable {
  log.debug("verifying that db is clean after test");
  Map<String, Long> tableCounts = managementService.getTableCount();
  StringBuilder outputMessage = new StringBuilder();
  for (String tableName : tableCounts.keySet()) {
    String tableNameWithoutPrefix = tableName.replace(processEngineConfiguration.getDatabaseTablePrefix(), "");
    if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
      Long count = tableCounts.get(tableName);
      if (count != 0L) {
        outputMessage.append("  " + tableName + ": " + count + " record(s) ");
      }
    }
  }
  if (outputMessage.length() > 0) {
    outputMessage.insert(0, "DB NOT CLEAN: \n");
    log.error(EMPTY_LINE);
    log.error(outputMessage.toString());

    log.info("dropping and recreating db");

    CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
    commandExecutor.execute(new Command<Object>() {
      public Object execute(CommandContext commandContext) {
        DbSqlSession session = commandContext.getDbSqlSession();
        session.dbSchemaDrop();
        session.dbSchemaCreate();
        return null;
      }
    });

    if (exception != null) {
      throw exception;
    } else {
      Assert.fail(outputMessage.toString());
    }
  } else {
    log.info("database was clean");
  }
}
 
Example #16
Source File: BaseSpringRestTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Each test is assumed to clean up all DB content it entered. After a test method executed, this method scans all tables to see if the DB is completely clean. It throws AssertionFailed in case the
 * DB is not clean. If the DB is not clean, it is cleaned by performing a create a drop.
 */
protected void assertAndEnsureCleanDb() throws Throwable {
  log.debug("verifying that db is clean after test");
  Map<String, Long> tableCounts = managementService.getTableCount();
  StringBuilder outputMessage = new StringBuilder();
  for (String tableName : tableCounts.keySet()) {
    String tableNameWithoutPrefix = tableName.replace(processEngineConfiguration.getDatabaseTablePrefix(), "");
    if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
      Long count = tableCounts.get(tableName);
      if (count != 0L) {
        outputMessage.append("  " + tableName + ": " + count + " record(s) ");
      }
    }
  }
  if (outputMessage.length() > 0) {
    outputMessage.insert(0, "DB NOT CLEAN: \n");
    log.error(EMPTY_LINE);
    log.error(outputMessage.toString());

    log.info("dropping and recreating db");

    CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
    commandExecutor.execute(new Command<Object>() {
      public Object execute(CommandContext commandContext) {
        DbSqlSession session = commandContext.getDbSqlSession();
        session.dbSchemaDrop();
        session.dbSchemaCreate();
        return null;
      }
    });

    if (exception != null) {
      throw exception;
    } else {
      Assert.fail(outputMessage.toString());
    }
  } else {
    log.info("database was clean");
  }
}
 
Example #17
Source File: TestHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/** 
 * Each test is assumed to clean up all DB content it entered.
 * After a test method executed, this method scans all tables to see if the DB is completely clean. 
 * It throws AssertionFailed in case the DB is not clean.
 * If the DB is not clean, it is cleaned by performing a create a drop. 
 */
public static void assertAndEnsureCleanDb(ProcessEngine processEngine) {
  log.debug("verifying that db is clean after test");
  Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();
  StringBuilder outputMessage = new StringBuilder();
  for (String tableName : tableCounts.keySet()) {
    if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableName)) {
      Long count = tableCounts.get(tableName);
      if (count!=0L) {
        outputMessage.append("  ").append(tableName).append(": ").append(count).append(" record(s) ");
      }
    }
  }
  if (outputMessage.length() > 0) {
    outputMessage.insert(0, "DB NOT CLEAN: \n");
    log.error(EMPTY_LINE);
    log.error(outputMessage.toString());

    ((ProcessEngineImpl)processEngine)
    .getProcessEngineConfiguration().getCommandExecutor()
      .execute(new Command<Object>() {
        public Object execute(CommandContext commandContext) {
          DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
          dbSqlSession.dbSchemaDrop();
          dbSqlSession.dbSchemaCreate();
          return null;
        }
      });
    
    throw new AssertionError(outputMessage.toString());
  }
}
 
Example #18
Source File: ActivitiEngineInitializer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onShutdown(ApplicationEvent event) {
	if(workflowAdminService.isEngineEnabled(ActivitiConstants.ENGINE_ID) && 
			((ProcessEngineImpl)processEngine).getProcessEngineConfiguration().getJobExecutor().isActive())
	{
		((ProcessEngineImpl)processEngine).getProcessEngineConfiguration().getJobExecutor().shutdown();
	}
}
 
Example #19
Source File: ManagementServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/mgmt/timerOnTask.bpmn20.xml" })
public void testDeleteJobThatWasAlreadyAcquired() {
  processEngineConfiguration.getClock().setCurrentTime(new Date());

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnTask");
  Job timerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();

  // We need to move time at least one hour to make the timer executable
  processEngineConfiguration.getClock().setCurrentTime(new Date(processEngineConfiguration.getClock().getCurrentTime().getTime() + 7200000L));

  // Acquire job by running the acquire command manually
  ProcessEngineImpl processEngineImpl = (ProcessEngineImpl) processEngine;
  AcquireTimerJobsCmd acquireJobsCmd = new AcquireTimerJobsCmd(processEngine.getProcessEngineConfiguration().getAsyncExecutor());
  CommandExecutor commandExecutor = processEngineImpl.getProcessEngineConfiguration().getCommandExecutor();
  commandExecutor.execute(acquireJobsCmd);

  // Try to delete the job. This should fail.
  try {
    managementService.deleteJob(timerJob.getId());
    fail();
  } catch (ActivitiException e) {
    // Exception is expected
  }

  // Clean up
  managementService.moveTimerToExecutableJob(timerJob.getId());
  managementService.executeJob(timerJob.getId());
}
 
Example #20
Source File: ActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void initializeServices() {
  processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
  repositoryService = processEngine.getRepositoryService();
  runtimeService = processEngine.getRuntimeService();
  taskService = processEngine.getTaskService();
  historicDataService = processEngine.getHistoryService();
  identityService = processEngine.getIdentityService();
  managementService = processEngine.getManagementService();
  formService = processEngine.getFormService();
}
 
Example #21
Source File: ActivitiMockSupport.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ActivitiMockSupport(ProcessEngine processEngine) {
  ProcessEngineConfigurationImpl processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
  ActivityBehaviorFactory existingActivityBehaviorFactory = processEngineConfiguration.getActivityBehaviorFactory();
  this.testActivityBehaviorFactory = new TestActivityBehaviorFactory(existingActivityBehaviorFactory);

  processEngineConfiguration.setActivityBehaviorFactory(testActivityBehaviorFactory);
  processEngineConfiguration.getBpmnParser().setActivityBehaviorFactory(testActivityBehaviorFactory);
}
 
Example #22
Source File: AbstractActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void initializeServices() {
  processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
  repositoryService = processEngine.getRepositoryService();
  runtimeService = processEngine.getRuntimeService();
  taskService = processEngine.getTaskService();
  formService = processEngine.getFormService();
  historyService = processEngine.getHistoryService();
  identityService = processEngine.getIdentityService();
  managementService = processEngine.getManagementService();
  dynamicBpmnService = processEngine.getDynamicBpmnService();
}
 
Example #23
Source File: AbstractMuleTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Each test is assumed to clean up all DB content it entered. After a test method executed, this method scans all tables to see if the DB is completely clean. It throws AssertionFailed in case the
 * DB is not clean. If the DB is not clean, it is cleaned by performing a create a drop.
 */
protected void assertAndEnsureCleanDb(ProcessEngine processEngine) throws Exception {
  log.debug("verifying that db is clean after test");
  Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();
  StringBuilder outputMessage = new StringBuilder();
  for (String tableName : tableCounts.keySet()) {
    String tableNameWithoutPrefix = tableName.replace(processEngine.getProcessEngineConfiguration().getDatabaseTablePrefix(), "");
    if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
      Long count = tableCounts.get(tableName);
      if (count != 0L) {
        outputMessage.append("  " + tableName + ": " + count + " record(s) ");
      }
    }
  }
  if (outputMessage.length() > 0) {
    outputMessage.insert(0, "DB NOT CLEAN: \n");
    log.error(EMPTY_LINE);
    log.error(outputMessage.toString());

    log.info("dropping and recreating db");

    CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
    CommandConfig config = new CommandConfig().transactionNotSupported();
    commandExecutor.execute(config, new Command<Object>() {
      public Object execute(CommandContext commandContext) {
        DbSqlSession session = commandContext.getSession(DbSqlSession.class);
        session.dbSchemaDrop();
        session.dbSchemaCreate();
        return null;
      }
    });

    Assert.fail(outputMessage.toString());

  } else {
    log.info("database was clean");
  }
}
 
Example #24
Source File: TestHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Each test is assumed to clean up all DB content it entered. After a test method executed, this method scans all tables to see if the DB is completely clean. It throws AssertionFailed in case the
 * DB is not clean. If the DB is not clean, it is cleaned by performing a create a drop.
 */
public static void assertAndEnsureCleanDb(ProcessEngine processEngine) {
  log.debug("verifying that db is clean after test");
  Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();
  StringBuilder outputMessage = new StringBuilder();
  for (String tableName : tableCounts.keySet()) {
    if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableName)) {
      Long count = tableCounts.get(tableName);
      if (count != 0L) {
        outputMessage.append("  ").append(tableName).append(": ").append(count).append(" record(s) ");
      }
    }
  }
  if (outputMessage.length() > 0) {
    outputMessage.insert(0, "DB NOT CLEAN: \n");
    log.error(EMPTY_LINE);
    log.error(outputMessage.toString());

    ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor().execute(new Command<Object>() {
      public Object execute(CommandContext commandContext) {
        DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
        dbSqlSession.dbSchemaDrop();
        dbSqlSession.dbSchemaCreate();
        return null;
      }
    });

    throw new AssertionError(outputMessage.toString());
  }
}
 
Example #25
Source File: DbSchemaDrop.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
  CommandExecutor commandExecutor = processEngine.getProcessEngineConfiguration().getCommandExecutor();
  CommandConfig config = new CommandConfig().transactionNotSupported();
  commandExecutor.execute(config, new Command<Object>() {
    public Object execute(CommandContext commandContext) {
      commandContext.getDbSqlSession().dbSchemaDrop();
      return null;
    }
  });
}
 
Example #26
Source File: DbSchemaUpdate.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
  CommandExecutor commandExecutor = processEngine.getProcessEngineConfiguration().getCommandExecutor();
  CommandConfig config = new CommandConfig().transactionNotSupported();
  commandExecutor.execute(config, new Command<Object>() {
    public Object execute(CommandContext commandContext) {
      commandContext.getDbSqlSession().dbSchemaUpdate();
      return null;
    }
  });
}
 
Example #27
Source File: AbstractMuleTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Each test is assumed to clean up all DB content it entered. After a test method executed, this method scans all tables to see if the DB is completely clean. It throws AssertionFailed in case the
 * DB is not clean. If the DB is not clean, it is cleaned by performing a create a drop.
 */
protected void assertAndEnsureCleanDb(ProcessEngine processEngine) throws Exception {
  log.debug("verifying that db is clean after test");
  Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();
  StringBuilder outputMessage = new StringBuilder();
  for (String tableName : tableCounts.keySet()) {
    String tableNameWithoutPrefix = tableName.replace(processEngine.getProcessEngineConfiguration().getDatabaseTablePrefix(), "");
    if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
      Long count = tableCounts.get(tableName);
      if (count != 0L) {
        outputMessage.append("  " + tableName + ": " + count + " record(s) ");
      }
    }
  }
  if (outputMessage.length() > 0) {
    outputMessage.insert(0, "DB NOT CLEAN: \n");
    log.error(EMPTY_LINE);
    log.error(outputMessage.toString());

    log.info("dropping and recreating db");

    CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
    CommandConfig config = new CommandConfig().transactionNotSupported();
    commandExecutor.execute(config, new Command<Object>() {
      public Object execute(CommandContext commandContext) {
        DbSqlSession session = commandContext.getDbSqlSession();
        session.dbSchemaDrop();
        session.dbSchemaCreate();
        return null;
      }
    });

    Assert.fail(outputMessage.toString());

  } else {
    log.info("database was clean");
  }
}
 
Example #28
Source File: DemoDataGenerator.java    From maven-framework-project with MIT License 4 votes vote down vote up
protected void generateReportData() {
    if (generateReportData) {

        // Report data is generated in background thread

        Thread thread = new Thread(new Runnable() {

            public void run() {

                // We need to temporarily disable the job executor or it would interfere with the process execution
                ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getJobExecutor().shutdown();

                Random random = new Random();

                Date now = new Date(new Date().getTime() - (24 * 60 * 60 * 1000));
                ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(now);

                for (int i = 0; i < 50; i++) {

                    if (random.nextBoolean()) {
                        processEngine.getRuntimeService().startProcessInstanceByKey("fixSystemFailure");
                    }

                    if (random.nextBoolean()) {
                        processEngine.getIdentityService().setAuthenticatedUserId("kermit");
                        Map<String, Object> variables = new HashMap<String, Object>();
                        variables.put("customerName", "testCustomer");
                        variables.put("details", "Looks very interesting!");
                        variables.put("notEnoughInformation", false);
                        processEngine.getRuntimeService().startProcessInstanceByKey("reviewSaledLead", variables);
                    }

                    if (random.nextBoolean()) {
                        processEngine.getRuntimeService().startProcessInstanceByKey("escalationExample");
                    }

                    if (random.nextInt(100) < 20) {
                        now = new Date(now.getTime() - ((24 * 60 * 60 * 1000) - (60 * 60 * 1000)));
                        ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(now);
                    }
                }

                List<Job> jobs = processEngine.getManagementService().createJobQuery().list();
                for (int i = 0; i < jobs.size() / 2; i++) {
                    ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(jobs.get(i).getDuedate());
                    processEngine.getManagementService().executeJob(jobs.get(i).getId());
                }

                List<Task> tasks = processEngine.getTaskService().createTaskQuery().list();
                while (tasks.size() > 0) {
                    for (Task task : tasks) {

                        if (task.getAssignee() == null) {
                            String assignee = random.nextBoolean() ? "kermit" : "fozzie";
                            processEngine.getTaskService().claim(task.getId(), assignee);
                        }

                        ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(new Date(task.getCreateTime().getTime() + random.nextInt(60 * 60 * 1000)));

                        processEngine.getTaskService().complete(task.getId());
                    }

                    tasks = processEngine.getTaskService().createTaskQuery().list();
                }

                ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().reset();

                ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getJobExecutor().start();
                LOGGER.info("Demo report data generated");
            }

        });
        thread.start();

    }
}
 
Example #29
Source File: ProcessEngineConfigurationImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessEngine buildProcessEngine() {
    init();
    return new ProcessEngineImpl(this);
}
 
Example #30
Source File: ActivitiMockSupport.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public static boolean isMockSupportPossible(ProcessEngine processEngine) {
  return processEngine instanceof ProcessEngineImpl;
}