use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class BpmnDeploymentTest method testDiagramCreationDisabled.
public void testDiagramCreationDisabled() {
// disable diagram generation
processEngineConfiguration.setCreateDiagramOnDeploy(false);
try {
repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/bpmn/parse/BpmnParseTest.testParseDiagramInterchangeElements.bpmn20.xml").deploy();
// Graphical information is not yet exposed publicly, so we need to do some plumbing
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
ProcessDefinitionEntity processDefinitionEntity = commandExecutor.execute(new Command<ProcessDefinitionEntity>() {
public ProcessDefinitionEntity execute(CommandContext commandContext) {
return Context.getProcessEngineConfiguration().getDeploymentManager().findDeployedLatestProcessDefinitionByKey("myProcess");
}
});
assertNotNull(processDefinitionEntity);
assertEquals(7, processDefinitionEntity.getActivities().size());
// Check that no diagram has been created
List<String> resourceNames = repositoryService.getDeploymentResourceNames(processDefinitionEntity.getDeploymentId());
assertEquals(1, resourceNames.size());
repositoryService.deleteDeployment(repositoryService.createDeploymentQuery().singleResult().getId(), true);
} finally {
processEngineConfiguration.setCreateDiagramOnDeploy(true);
}
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class CustomMybatisMapperConfigurationTest method executeCustomMybatisXmlQuery.
@Test
public void executeCustomMybatisXmlQuery() throws Exception {
AnnotationConfigApplicationContext applicationContext = this.context(Application.class);
ManagementService managementService = applicationContext.getBean(ManagementService.class);
String processDefinitionDeploymentId = managementService.executeCommand(new Command<String>() {
@Override
public String execute(CommandContext commandContext) {
return (String) commandContext.getDbSqlSession().selectOne("selectProcessDefinitionDeploymentIdByKey", "waiter");
}
});
Assert.assertNotNull("the processDefinitionDeploymentId should not be null!", processDefinitionDeploymentId);
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class CustomMybatisXMLMapperTest method testSelectOneTask.
public void testSelectOneTask() {
// Create test data
for (int i = 0; i < 4; i++) {
createTask(i + "", null, null, 0);
}
final String taskId = createTask("4", null, null, 0);
CustomTask customTask = managementService.executeCommand(new Command<CustomTask>() {
@Override
public CustomTask execute(CommandContext commandContext) {
return (CustomTask) commandContext.getDbSqlSession().selectOne("selectOneCustomTask", taskId);
}
});
assertEquals("4", customTask.getName());
// test default query as well
List<Task> tasks = taskService.createTaskQuery().list();
assertEquals(5, tasks.size());
Task task = taskService.createTaskQuery().taskName("2").singleResult();
assertEquals("2", task.getName());
// Cleanup
deleteTasks(taskService.createTaskQuery().list());
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class AbstractActivitiTestCase method assertAndEnsureCleanDb.
/** 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(" ").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());
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;
}
});
if (exception != null) {
throw exception;
} else {
Assert.fail(outputMessage.toString());
}
} else {
log.info("database was clean");
}
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class BpmnDeployer method removeExistingMessageEventSubscriptions.
protected void removeExistingMessageEventSubscriptions(ProcessDefinitionEntity processDefinition, ProcessDefinitionEntity latestProcessDefinition) {
if (latestProcessDefinition != null) {
CommandContext commandContext = Context.getCommandContext();
List<EventSubscriptionEntity> subscriptionsToDisable = commandContext.getEventSubscriptionEntityManager().findEventSubscriptionsByTypeAndProcessDefinitionId(MessageEventHandler.EVENT_HANDLER_TYPE, latestProcessDefinition.getId(), latestProcessDefinition.getTenantId());
for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsToDisable) {
eventSubscriptionEntity.delete();
}
}
}
Aggregations