提交 8bd68730 编写于 作者: J jbarrez

ACT-134: changed activiti.properties to activiti.cfg.xml

上级 11ed2945
......@@ -29,7 +29,7 @@
</fileset>
<fileset dir="../modules/activiti-engine/src/test/resources">
<include name="org/activiti/examples/**" />
<include name="activiti.properties" />
<include name="activiti.cfg.xml" />
<include name="logging.properties" />
</fileset>
</copy>
......@@ -56,6 +56,9 @@
<fileset dir="../modules/activiti-engine/src/main/resources/org/activiti/impl/bpmn/parser">
<include name="*.xsd" />
</fileset>
<fileset dir="../modules/activiti-engine/src/main/resources/org/activiti/impl/cfg">
<include name="*.xsd" />
</fileset>
</copy>
<mkdir dir="${target.distro.root}/lib" />
......
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg">
<database name="@db@" schema-strategy="check-version">
<jdbc url="@jdbc.url@"
driver="@jdbc.driver@"
username="@jdbc.username@"
password="@jdbc.password@" />
</database>
<job-executor auto-activate="on" />
<mail host="localhost" port="5025" />
</activiti-cfg>
database=@db@
jdbc.driver=@jdbc.driver@
jdbc.url=@jdbc.url@
jdbc.username=@jdbc.username@
jdbc.password=@jdbc.password@
db.schema.strategy=check-version
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg">
<database name="h2" schema-strategy="create-drop">
<jdbc url="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
<job-executor auto-activate="off" />
<mail host="localhost" port="5025" />
</activiti-cfg>
database=h2
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000
jdbc.username=sa
jdbc.password=
db.schema.strategy=create-drop
job.executor.auto.activate=off
ws.sync.factory=org.activiti.engine.impl.webservice.CxfWebServiceClientFactory
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg">
<database name="h2" schema-strategy="create-drop">
<jdbc url="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
<job-executor auto-activate="off" />
<mail host="localhost" port="5025" />
</activiti-cfg>
database=h2
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000
#jdbc.url=jdbc:h2:tcp://localhost/activiti
jdbc.username=sa
jdbc.password=
db.schema.strategy=create-drop
job.executor.auto.activate=off
......@@ -51,8 +51,8 @@ public interface ProcessEngine {
/** the version of the activiti library */
public static String VERSION = "5.0.rc1-SNAPSHOT";
/** the name as specified in the 'process.engine.name' property in
* the activiti.properties configuration file or in the
/** The name as specified in 'process-engine-name' in
* the activiti.cfg.xml configuration file.
* The default name for a process engine is 'default */
String getName();
......
......@@ -14,16 +14,23 @@ package org.activiti.engine;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.activiti.engine.impl.cfg.ProcessEngineConfiguration;
import org.activiti.engine.impl.util.IoUtil;
import org.activiti.engine.impl.cfg.ConfigurationParse;
import org.activiti.engine.impl.cfg.ConfigurationParser;
import org.activiti.engine.impl.util.ReflectUtil;
import org.activiti.engine.impl.util.IoUtil;
/**
* Builds a process engine based on a couple of simple properties.
* Builds a process engine based on an XML configuration resource:
*
* <pre>
* ProcessEngine processEngine = ProcessEngineBuilder
* .configureFromResource("activiti.cfg.xml")
* .buildProcessEngine();
* </pre>
*
* To build a ProcessEngine that's using a h2 database over a TCP connection:
* To build programmatically a ProcessEngine that for example uses a h2 database over a TCP connection:
*
* <pre>
* ProcessEngine processEngine = ProcessEngineBuilder
......@@ -55,273 +62,194 @@ import org.activiti.engine.impl.util.ReflectUtil;
*/
public class ProcessEngineBuilder {
protected String processEngineName = ProcessEngines.NAME_DEFAULT;
protected String databaseName = ProcessEngineConfiguration.DEFAULT_DATABASE_NAME;
protected String jdbcDriver = ProcessEngineConfiguration.DEFAULT_JDBC_DRIVER;
protected String jdbcUrl = ProcessEngineConfiguration.DEFAULT_JDBC_URL;
protected String jdbcUsername = ProcessEngineConfiguration.DEFAULT_JDBC_USERNAME;
protected String jdbcPassword = ProcessEngineConfiguration.DEFAULT_JDBC_PASSWORD;
protected String wsSyncFactoryClassName = ProcessEngineConfiguration.DEFAULT_WS_SYNC_FACTORY;
protected String dbSchemaStrategy = DbSchemaStrategy.CHECK_VERSION;
protected boolean jobExecutorAutoActivate = true;
protected boolean localTransactions = true;
protected Object jpaEntityManagerFactory;
protected boolean jpaHandleTransaction;
protected boolean jpaCloseEntityManager;
protected ProcessEngineConfiguration processEngineConfiguration = new ProcessEngineConfiguration();
protected String mailServerSmtpHost;
protected String mailServerSmtpUserName;
protected String mailServerSmtpPassword;
protected int mailServerSmtpPort = ProcessEngineConfiguration.DEFAULT_MAIL_SERVER_SMTP_PORT;
protected String mailServerDefaultFrom = ProcessEngineConfiguration.DEFAULT_FROM_EMAIL_ADDRESS;
protected Integer historyLevel;
public ProcessEngineBuilder setProcessEngineName(String processEngineName) {
this.processEngineName = processEngineName;
processEngineConfiguration.setProcessEngineName(processEngineName);
return this;
}
public ProcessEngineBuilder setDatabaseName(String databaseName) {
this.databaseName = databaseName;
processEngineConfiguration.setDatabaseName(databaseName);
return this;
}
public ProcessEngineBuilder setJdbcDriver(String jdbcDriver) {
this.jdbcDriver = jdbcDriver;
processEngineConfiguration.setJdbcDriver(jdbcDriver);
return this;
}
public ProcessEngineBuilder setLocalTransactions(boolean localTransactions) {
this.localTransactions = localTransactions;
public ProcessEngineBuilder setTransactionsExternallyManaged(boolean transactionsExternallyManaged) {
processEngineConfiguration.setTransactionsExternallyManaged(transactionsExternallyManaged);
return this;
}
public ProcessEngineBuilder setJdbcUrl(String jdbcUrl) {
this.jdbcUrl = jdbcUrl;
processEngineConfiguration.setJdbcUrl(jdbcUrl);
return this;
}
public ProcessEngineBuilder setJdbcUsername(String jdbcUsername) {
this.jdbcUsername = jdbcUsername;
processEngineConfiguration.setJdbcUsername(jdbcUsername);
return this;
}
public ProcessEngineBuilder setJdbcPassword(String jdbcPassword) {
this.jdbcPassword = jdbcPassword;
processEngineConfiguration.setJdbcPassword(jdbcPassword);
return this;
}
public ProcessEngineBuilder setDbSchemaStrategy(String dbSchemaStrategy) {
this.dbSchemaStrategy = dbSchemaStrategy;
processEngineConfiguration.setDbSchemaStrategy(dbSchemaStrategy);
return this;
}
public ProcessEngineBuilder setMailServerSmtpHost(String mailServerSmtpHost) {
this.mailServerSmtpHost = mailServerSmtpHost;
public ProcessEngineBuilder setMailServerHost(String mailServerHost) {
processEngineConfiguration.setMailServerHost(mailServerHost);
return this;
}
public ProcessEngineBuilder setMailServerSmtpUserName(String mailServerSmtpUserName) {
this.mailServerSmtpUserName = mailServerSmtpUserName;
public ProcessEngineBuilder setMailServerUsername(String mailServerUsername) {
processEngineConfiguration.setMailServerUsername(mailServerUsername);
return this;
}
public ProcessEngineBuilder setMailServerSmtpPassword(String mailServerSmtpPassword) {
this.mailServerSmtpPassword = mailServerSmtpPassword;
public ProcessEngineBuilder setMailServerPassword(String mailServerPassword) {
processEngineConfiguration.setMailServerPassword(mailServerPassword);
return this;
}
public ProcessEngineBuilder setMailServerSmtpPort(int mailServerSmtpPort) {
this.mailServerSmtpPort = mailServerSmtpPort;
public ProcessEngineBuilder setMailServerPort(int mailServerPort) {
processEngineConfiguration.setMailServerPort(mailServerPort);
return this;
}
public ProcessEngineBuilder setMailServerDefaultFrom(String mailServerDefaultFrom) {
this.mailServerDefaultFrom = mailServerDefaultFrom;
processEngineConfiguration.setMailServerDefaultFrom(mailServerDefaultFrom);
return this;
}
public ProcessEngineBuilder configureFromProperties(Properties configurationProperties) {
if (configurationProperties == null) {
throw new ActivitiException("configurationProperties is null");
public ProcessEngineBuilder setJobExecutorAutoActivation(boolean jobExecutorAutoActivate) {
processEngineConfiguration.setJobExecutorAutoActivate(jobExecutorAutoActivate);
return this;
}
public ProcessEngineBuilder enableJPA(Object entityManagerFactory, boolean handleTransaction, boolean closeEntityManager) {
processEngineConfiguration.enableJPA(entityManagerFactory, handleTransaction, closeEntityManager);
return this;
}
public ProcessEngineBuilder enableJPA(Object entityManagerFactory) {
return enableJPA(entityManagerFactory, true, true);
}
/**
* Configures a {@link ProcessEngine} based on an XML configuration provided by the inputstream.
*
* Calling methods are responsible for closing the provided inputStream.
*/
public ProcessEngineBuilder configureFromInputStream(InputStream inputStream) {
if (inputStream == null) {
throw new ActivitiException("inputStream is null");
}
String processEngineName = configurationProperties.getProperty("process.engine.name");
ConfigurationParser cfgParser = new ConfigurationParser();
ConfigurationParse cfgParse = cfgParser.createParse()
.sourceInputStream(inputStream)
.execute();
// Process engine
String processEngineName = cfgParse.getProcessEngineName();
if (processEngineName != null) {
this.processEngineName = processEngineName;
processEngineConfiguration.setProcessEngineName(processEngineName);
}
// DATABASE
String databaseName = configurationProperties.getProperty("database");
// Database
String databaseName = cfgParse.getDatabaseName();
if (databaseName != null) {
this.databaseName = databaseName;
}
String jdbcDriver = configurationProperties.getProperty("jdbc.driver");
if (jdbcDriver != null) {
this.jdbcDriver = jdbcDriver;
processEngineConfiguration.setDatabaseName(databaseName);
}
String jdbcUrl = configurationProperties.getProperty("jdbc.url");
if (jdbcUrl != null) {
this.jdbcUrl = jdbcUrl;
String databaseSchemaStrategy = cfgParse.getDatabaseSchemaStrategy();
if (databaseSchemaStrategy != null) {
processEngineConfiguration.setDbSchemaStrategy(databaseSchemaStrategy);
}
String jdbcUsername = configurationProperties.getProperty("jdbc.username");
if (jdbcUsername != null) {
this.jdbcUsername = jdbcUsername;
}
String jdbcPassword = configurationProperties.getProperty("jdbc.password");
if (jdbcPassword != null) {
this.jdbcPassword = jdbcPassword;
}
String dbSchemaStrategy = configurationProperties.getProperty("db.schema.strategy");
if (dbSchemaStrategy != null) {
this.dbSchemaStrategy = dbSchemaStrategy;
if (cfgParse.isJdbcConfigured()) {
String databaseUrl = cfgParse.getJdbcUrl();
if (databaseUrl != null) {
processEngineConfiguration.setJdbcUrl(databaseUrl);
}
String databaseDriver = cfgParse.getJdbcDriver();
if (databaseDriver != null) {
processEngineConfiguration.setJdbcDriver(databaseDriver);
}
String databaseUsername = cfgParse.getJdbcUsername();
if (databaseUsername != null) {
processEngineConfiguration.setJdbcUsername(databaseUsername);
}
String databasePassword = cfgParse.getJdbcPassword();
if (databasePassword != null) {
processEngineConfiguration.setJdbcPassword(databasePassword);
}
}
// JOBEXECUTOR
String jobExecutorAutoActivate = configurationProperties.getProperty("job.executor.auto.activate");
if ((jobExecutorAutoActivate != null)
&& (("false".equals(jobExecutorAutoActivate)) || ("disabled".equals(jobExecutorAutoActivate)) || ("off".equals(jobExecutorAutoActivate)))) {
this.jobExecutorAutoActivate = false;
// Mail
String mailServerHost = cfgParse.getMailServerHost();
if (mailServerHost != null) {
processEngineConfiguration.setMailServerHost(mailServerHost);
}
// WEBSERVICE
String wsSyncFactory = configurationProperties.getProperty("ws.sync.factory");
if (wsSyncFactory != null) {
this.wsSyncFactoryClassName = wsSyncFactory;
Integer mailServerPort = cfgParse.getMailServerPort();
if (mailServerPort != null) {
processEngineConfiguration.setMailServerPort(mailServerPort);
}
// EMAIL
String mailServerSmtpHost = configurationProperties.getProperty("mail.smtp.host");
if (mailServerSmtpHost != null) {
this.mailServerSmtpHost = mailServerSmtpHost;
String mailServerUsername = cfgParse.getMailServerUsername();
if (mailServerUsername != null) {
processEngineConfiguration.setMailServerUsername(mailServerUsername);
}
String mailServerSmtpPort= configurationProperties.getProperty("mail.smtp.port");
if (mailServerSmtpPort != null) {
try {
this.mailServerSmtpPort = Integer.parseInt(mailServerSmtpPort);
} catch (NumberFormatException e) {
throw new ActivitiException("Invalid port number: " + mailServerSmtpPort, e);
}
String mailServerPassword = cfgParse.getMailServerPassword();
if (mailServerPassword != null) {
processEngineConfiguration.setMailServerPassword(mailServerPassword);
}
String mailServerSmtpUserName = configurationProperties.getProperty("mail.smtp.user");
if (mailServerSmtpUserName != null) {
this.mailServerSmtpUserName = mailServerSmtpUserName;
String mailDefaultFrom = cfgParse.getMailDefaultFrom();
if (mailDefaultFrom != null) {
processEngineConfiguration.setMailServerDefaultFrom(mailDefaultFrom);
}
String mailServerSmtpPassword= configurationProperties.getProperty("mail.smtp.password");
if (mailServerSmtpPassword != null) {
this.mailServerSmtpPassword = mailServerSmtpPassword;
// Job executor
Boolean jobExecutorAutoActivate = cfgParse.getIsJobExecutorAutoActivate();
if (jobExecutorAutoActivate != null) {
processEngineConfiguration.setJobExecutorAutoActivate(jobExecutorAutoActivate);
}
String mailServerDefaultFrom= configurationProperties.getProperty("mail.default.from");
if (mailServerDefaultFrom != null) {
this.mailServerDefaultFrom = mailServerDefaultFrom;
}
String historyLevelText = configurationProperties.getProperty("history.level");
if (historyLevelText!=null) {
historyLevel = ProcessEngineConfiguration.parseHistoryLevel(historyLevelText);
// History
Integer historyLevel = cfgParse.getHistoryLevel();
if (historyLevel != null) {
processEngineConfiguration.setHistoryLevel(historyLevel);
}
return this;
}
public ProcessEngineBuilder configureFromPropertiesInputStream(InputStream inputStream) {
/**
* Configures a {@link ProcessEngine} based on an XML configuration file.
*/
public ProcessEngineBuilder configureFromResource(String resource) {
InputStream inputStream = ReflectUtil.getClassLoader().getResourceAsStream(resource);
if (inputStream == null) {
throw new ActivitiException("inputStream is null");
throw new ActivitiException("configuration resource '" + resource
+ "' is unavailable on classpath " + System.getProperty("java.class.path"));
}
Properties properties = new Properties();
try {
properties.load(inputStream);
configureFromInputStream(inputStream);
inputStream.close();
} catch (IOException e) {
throw new ActivitiException("problem while reading activiti configuration properties " + e.getMessage(), e);
throw new ActivitiException("Exception while closing inputstream", e);
} finally {
IoUtil.closeSilently(inputStream);
}
configureFromProperties(properties);
return this;
}
public ProcessEngineBuilder configureFromPropertiesResource(String propertiesResource) {
InputStream inputStream = ReflectUtil.getResourceAsStream(propertiesResource);
if (inputStream == null) {
throw new ActivitiException("configuration properties resource '" + propertiesResource + "' is unavailable on classpath "
+ System.getProperty("java.class.path"));
}
configureFromPropertiesInputStream(inputStream);
return this;
}
public ProcessEngineBuilder setJobExecutorAutoActivation(boolean jobExecutorAutoActivate) {
this.jobExecutorAutoActivate = jobExecutorAutoActivate;
return this;
}
public ProcessEngineBuilder enableJPA(Object entityManagerFactory, boolean handleTransaction, boolean closeEntityManager) {
jpaEntityManagerFactory = entityManagerFactory;
jpaHandleTransaction = handleTransaction;
jpaCloseEntityManager = closeEntityManager;
return this;
}
public ProcessEngineBuilder enableJPA(Object entityManagerFactory) {
return enableJPA(entityManagerFactory, true, true);
}
public ProcessEngine buildProcessEngine() {
if (databaseName == null) {
throw new ActivitiException("no database name specified (used to look up queries and scripts)");
}
ProcessEngineConfiguration processEngineConfiguration = new ProcessEngineConfiguration();
processEngineConfiguration.setProcessEngineName(processEngineName);
// JOBEXECUTOR
processEngineConfiguration.setJobExecutorAutoActivate(jobExecutorAutoActivate);
// HISTORY
if (historyLevel!=null) {
processEngineConfiguration.setHistoryLevel(historyLevel);
}
// DATABASE
processEngineConfiguration.setDbSchemaStrategy(dbSchemaStrategy);
processEngineConfiguration.setJdbcDriver(jdbcDriver);
processEngineConfiguration.setJdbcUrl(jdbcUrl);
processEngineConfiguration.setJdbcUsername(jdbcUsername);
processEngineConfiguration.setJdbcPassword(jdbcPassword);
processEngineConfiguration.setDatabaseName(databaseName);
processEngineConfiguration.setLocalTransactions(localTransactions);
// WEBSERVICE
processEngineConfiguration.setWsSyncFactoryClassName(wsSyncFactoryClassName);
// EMAIL
processEngineConfiguration.setMailServerSmtpHost(mailServerSmtpHost);
processEngineConfiguration.setMailServerSmtpPort(mailServerSmtpPort);
processEngineConfiguration.setMailServerSmtpUserName(mailServerSmtpUserName);
processEngineConfiguration.setMailServerSmtpPassword(mailServerSmtpPassword);
processEngineConfiguration.setMailServerDefaultFrom(mailServerDefaultFrom);
// JPA
if(jpaEntityManagerFactory != null) {
processEngineConfiguration.enableJPA(jpaEntityManagerFactory, jpaHandleTransaction, jpaCloseEntityManager);
}
ProcessEngine engine = processEngineConfiguration.buildProcessEngine();
ProcessEngines.registerProcessEngine(engine);
return engine;
return processEngineConfiguration.buildProcessEngine();
}
}
......@@ -48,7 +48,7 @@ import org.activiti.engine.impl.util.ReflectUtil;
* on this class.<br>
* <br>
* The {@link #init()} method will try to build one {@link ProcessEngine} for
* each activiti.properties file found on the classpath. If you have more then one,
* each activiti.cfg.xml file found on the classpath. If you have more then one,
* make sure you specify different process.engine.name values.
*
* @author Tom Baeyens
......@@ -74,9 +74,9 @@ public abstract class ProcessEngines {
ClassLoader classLoader = ReflectUtil.getClassLoader();
Enumeration<URL> resources = null;
try {
resources = classLoader.getResources("activiti.properties");
resources = classLoader.getResources("activiti.cfg.xml");
} catch (IOException e) {
throw new ActivitiException("can't find activiti.properties resources on the classpath: "+System.getProperty("java.class.path"), e);
throw new ActivitiException("can't find activiti.cfg.xml resources on the classpath: "+System.getProperty("java.class.path"), e);
}
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
......@@ -148,7 +148,7 @@ public abstract class ProcessEngines {
try {
inputStream = resource.openStream();
ProcessEngine processEngine = new ProcessEngineBuilder()
.configureFromPropertiesInputStream(inputStream)
.configureFromInputStream(inputStream)
.buildProcessEngine();
return processEngine;
......
......@@ -160,17 +160,17 @@ public class MailActivityBehavior extends BpmnJavaDelegation {
protected void setMailServerProperties(Email email) {
ProcessEngineConfiguration config = CommandContext.getCurrent().getProcessEngineConfiguration();
String host = config.getMailServerSmtpHost();
String host = config.getMailServerHost();
if (host == null) {
throw new ActivitiException("Could not send email: no SMTP host is configured");
}
email.setHostName(host);
int port = config.getMailServerSmtpPort();
int port = config.getMailServerPort();
email.setSmtpPort(port);
String user = config.getMailServerSmtpUserName();
String password = config.getMailServerSmtpPassword();
String user = config.getMailServerUsername();
String password = config.getMailServerPassword();
if (user != null && password != null) {
email.setAuthentication(user, password);
}
......
......@@ -78,8 +78,7 @@ import org.activiti.engine.impl.variable.VariableDeclaration;
import org.activiti.engine.impl.webservice.WSDLImporter;
/**
* Specific parsing representation created by the {@link BpmnParser} to parse
* one BPMN 2.0 process XML file.
* Specific parsing of one BPMN 2.0 XML file, created by the {@link BpmnParser}.
*
* @author Tom Baeyens
* @author Joram Barrez
......@@ -185,12 +184,12 @@ public class BpmnParse extends Parse {
public BpmnParse execute() {
super.execute(); // schema validation
parseDefinitionsAttributes(rootElement);
parseImports(rootElement);
parseItemDefinitions(rootElement);
parseMessages(rootElement);
parseInterfaces(rootElement);
parseProcessDefinitions(rootElement);
parseDefinitionsAttributes();
parseImports();
parseItemDefinitions();
parseMessages();
parseInterfaces();
parseProcessDefinitions();
if (hasWarnings()) {
logWarnings();
......@@ -202,7 +201,7 @@ public class BpmnParse extends Parse {
return this;
}
private void parseDefinitionsAttributes(Element rootElement) {
private void parseDefinitionsAttributes() {
String typeLanguage = rootElement.attribute("typeLanguage");
String expressionLanguage = rootElement.attribute("expressionLanguage");
......@@ -226,7 +225,7 @@ public class BpmnParse extends Parse {
* @param rootElement
* The root element of the XML file.
*/
private void parseImports(Element rootElement) {
private void parseImports() {
List<Element> imports = rootElement.elements("import");
for (Element theImport : imports) {
String importType = theImport.attribute("importType");
......@@ -247,8 +246,8 @@ public class BpmnParse extends Parse {
* @param definitionsElement
* The root element of the XML file.
*/
public void parseItemDefinitions(Element definitionsElement) {
for (Element itemDefinitionElement : definitionsElement.elements("itemDefinition")) {
public void parseItemDefinitions() {
for (Element itemDefinitionElement : rootElement.elements("itemDefinition")) {
String id = itemDefinitionElement.attribute("id");
String structureRef = itemDefinitionElement.attribute("structureRef");
String itemKind = itemDefinitionElement.attribute("itemKind");
......@@ -279,8 +278,8 @@ public class BpmnParse extends Parse {
* @param definitionsElement
* The root element of the XML file/
*/
public void parseMessages(Element definitionsElement) {
for (Element messageElement : definitionsElement.elements("message")) {
public void parseMessages() {
for (Element messageElement : rootElement.elements("message")) {
String id = messageElement.attribute("id");
String itemRef = messageElement.attribute("itemRef");
......@@ -300,8 +299,8 @@ public class BpmnParse extends Parse {
* @param definitionsElement
* The root element of the XML file/
*/
public void parseInterfaces(Element definitionsElement) {
for (Element interfaceElement : definitionsElement.elements("interface")) {
public void parseInterfaces() {
for (Element interfaceElement : rootElement.elements("interface")) {
// Create the interface
String id = interfaceElement.attribute("id");
......@@ -352,9 +351,9 @@ public class BpmnParse extends Parse {
* @param definitionsElement
* The root element of the XML file.
*/
public void parseProcessDefinitions(Element definitionsElement) {
public void parseProcessDefinitions() {
// TODO: parse specific definitions signalData (id, imports, etc)
for (Element processElement : definitionsElement.elements("process")) {
for (Element processElement : rootElement.elements("process")) {
processDefinitions.add(parseProcess(processElement));
}
}
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.cfg;
import java.io.InputStream;
import java.net.URL;
import org.activiti.engine.impl.util.ReflectUtil;
import org.activiti.engine.impl.util.xml.Element;
import org.activiti.engine.impl.util.xml.Parse;
import org.activiti.engine.impl.util.xml.Parser;
/**
* Specific parsing of one XML configuration file, created by the {@link ConfigurationParser}.
*
* @author Joram Barrez
*/
public class ConfigurationParse extends Parse {
// Process engine
protected String processEngineName;
// Database config
protected boolean isJdbcConfigured;
protected String databaseName;
protected String databaseSchemaStrategy;
protected String jdbcUrl;
protected String jdbcDriver;
protected String jdbcUsername;
protected String jdbcPassword;
// Jobexecutor
protected Boolean isJobExecutorAutoActivate;
// Mail
protected String mailServerHost;
protected Integer mailServerPort;
protected String mailServerUsername;
protected String mailServerPassword;
protected String mailDefaultFrom;
// History
protected Integer historyLevel;
/**
* Note package modifier: only {@link ConfigurationParser} is allowed to create instances.
*/
ConfigurationParse(Parser parser) {
super(parser);
setSchemaResource(ReflectUtil.getClassLoader().getResource(ConfigurationParser.SCHEMA_RESOURCE_5_0).toString());
}
@Override
public ConfigurationParse execute() {
super.execute();
parseRootElementAttributes();
parseDatabaseCfg();
parseJobExecutorCfg();
parseMailServerCfg();
parseHistoryCfg();
if (hasWarnings()) {
logWarnings();
}
if (hasErrors()) {
throwActivitiExceptionForErrors();
}
return this;
}
protected void parseRootElementAttributes() {
this.processEngineName = rootElement.attribute("process-engine-name");
}
protected void parseDatabaseCfg() {
Element databaseElement = rootElement.element("database");
if (databaseElement != null) {
this.databaseName = databaseElement.attribute("name");
this.databaseSchemaStrategy = databaseElement.attribute("schema-strategy");
// Jdbc
Element jdbcElement = databaseElement.element("jdbc");
if (jdbcElement != null) {
this.isJdbcConfigured = true;
this.jdbcUrl = jdbcElement.attribute("url");
this.jdbcDriver = jdbcElement.attribute("driver");
this.jdbcUsername = jdbcElement.attribute("username");
this.jdbcPassword = jdbcElement.attribute("password");
}
// Datasource through jndi: TODO
} else {
addError("Could not find required element 'database'", rootElement);
}
}
protected void parseJobExecutorCfg() {
Element jobExecutorElement = rootElement.element("job-executor");
if (jobExecutorElement != null) {
String autoActivateString = jobExecutorElement.attribute("auto-activate");
if (autoActivateString != null) {
if (autoActivateString.equals("off")
|| autoActivateString.equals("disabled")
|| autoActivateString.equals("false")) {
this.isJobExecutorAutoActivate = false;
} else if (autoActivateString.equals("on")
|| autoActivateString.equals("enabled")
|| autoActivateString.equals("true")) {
this.isJobExecutorAutoActivate = true;
} else {
addError("Invalid value for 'auto-activate', current values are supported:"
+ "on/off enabled/disabled true/false", jobExecutorElement);
}
}
}
}
protected void parseMailServerCfg() {
Element mailElement = rootElement.element("mail");
if (mailElement != null) {
this.mailServerHost = mailElement.attribute("host");
this.mailServerUsername = mailElement.attribute("username");
this.mailServerPassword = mailElement.attribute("password");
this.mailDefaultFrom = mailElement.attribute("default-from");
try {
this.mailServerPort = Integer.parseInt(mailElement.attribute("port"));
} catch (NumberFormatException e) {
addError("Invalid port for mail service", mailElement);
}
}
}
protected void parseHistoryCfg() {
Element historyElement = rootElement.element("history");
if (historyElement != null) {
String historyLevelString = historyElement.attribute("level");
if (historyLevelString != null) {
this.historyLevel = ProcessEngineConfiguration.parseHistoryLevel(historyLevelString);
}
}
}
// Source definition operations //////////////////////////////////////////////////
@Override
public ConfigurationParse sourceInputStream(InputStream inputStream) {
super.sourceInputStream(inputStream);
return this;
}
@Override
public ConfigurationParse sourceResource(String resource) {
super.sourceResource(resource);
return this;
}
@Override
public ConfigurationParse sourceResource(String resource, ClassLoader classLoader) {
super.sourceResource(resource, classLoader);
return this;
}
@Override
public ConfigurationParse sourceString(String string) {
super.sourceString(string);
return this;
}
@Override
public ConfigurationParse sourceUrl(String url) {
super.sourceUrl(url);
return this;
}
@Override
public ConfigurationParse sourceUrl(URL url) {
super.sourceUrl(url);
return this;
}
// Getters (available after calling execute() ) ////////////////////////////////////
public String getProcessEngineName() {
return processEngineName;
}
public boolean isJdbcConfigured() {
return isJdbcConfigured;
}
public String getDatabaseName() {
return databaseName;
}
public String getDatabaseSchemaStrategy() {
return databaseSchemaStrategy;
}
public String getJdbcUrl() {
return jdbcUrl;
}
public String getJdbcDriver() {
return jdbcDriver;
}
public String getJdbcUsername() {
return jdbcUsername;
}
public String getJdbcPassword() {
return jdbcPassword;
}
public Boolean getIsJobExecutorAutoActivate() {
return isJobExecutorAutoActivate;
}
public String getMailServerHost() {
return mailServerHost;
}
public Integer getMailServerPort() {
return mailServerPort;
}
public String getMailServerUsername() {
return mailServerUsername;
}
public String getMailServerPassword() {
return mailServerPassword;
}
public String getMailDefaultFrom() {
return mailDefaultFrom;
}
public Integer getHistoryLevel() {
return historyLevel;
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.cfg;
import org.activiti.engine.impl.util.xml.Parser;
/**
* Parser for the Activiti XML configuration.
*
* @author Joram Barrez
*/
public class ConfigurationParser extends Parser {
protected static final String SCHEMA_RESOURCE_5_0 = "org/activiti/impl/cfg/activiti-cfg-5.0.xsd";
@Override
public ConfigurationParse createParse() {
return new ConfigurationParse(this);
}
}
......@@ -87,22 +87,25 @@ import org.activiti.engine.impl.variable.VariableTypes;
* @author Tom Baeyens
*/
public class ProcessEngineConfiguration {
// Static values (defaults, etc.) ////////////////////////////////////////////
public static final String DEFAULT_DATABASE_NAME = "h2";
public static final String DEFAULT_JDBC_DRIVER = "org.h2.Driver";
public static final String DEFAULT_JDBC_URL = "jdbc:h2:mem:activiti";
public static final String DEFAULT_JDBC_USERNAME = "sa";
public static final String DEFAULT_JDBC_PASSWORD = "";
// Exprimental scheme strategies (ie not in DbSchemaStrategy)
public static final String DBSCHEMASTRATEGY_CREATE = "create";
public static final String DBSCHEMASTRATEGY_CREATE_IF_NECESSARY = "create-if-necessary";
public static final String DBSCHEMASTRATEGY_DROP_CREATE = "drop-create";
public static final String DEFAULT_WS_SYNC_FACTORY = "org.activiti.engine.impl.webservice.CxfWebServiceClientFactory";
public static final String DEFAULT_FROM_EMAIL_ADDRESS = "noreply@activiti.org";
public static final int DEFAULT_MAIL_SERVER_SMTP_PORT = 25;
public static final String DBSCHEMASTRATEGY_CREATE = "create";
public static final String DBSCHEMASTRATEGY_CREATE_IF_NECESSARY = "create-if-necessary";
public static final String DBSCHEMASTRATEGY_DROP_CREATE = "drop-create";
public static final int HISTORYLEVEL_NONE = 0;
public static final int HISTORYLEVEL_ACTIVITY = 1;
public static final int HISTORYLEVEL_AUDIT = 2;
......@@ -123,10 +126,13 @@ public class ProcessEngineConfiguration {
}
throw new ActivitiException("invalid history level: "+historyLevelText);
}
// Configurable member fields //////////////////////////////////////////////
protected String processEngineName;
// Command executor and interceptor stack
/** the configurable list which will be {@link #initializeInterceptorChain(List) processed} to build the {@link #commandExecutorTxRequired} */
protected List<CommandInterceptor> commandInterceptorsTxRequired;
/** this will be initialized during the configurationComplete() */
......@@ -139,6 +145,7 @@ public class ProcessEngineConfiguration {
protected CommandContextFactory commandContextFactory;
protected TransactionContextFactory transactionContextFactory;
// Services
protected RepositoryService repositoryService;
protected RuntimeService runtimeService;
protected HistoryService historyService;
......@@ -147,49 +154,64 @@ public class ProcessEngineConfiguration {
protected FormService formService;
protected ManagementService managementService;
// Session Factories
protected Map<Class<?>, SessionFactory> sessionFactories;
protected List<Deployer> deployers;
// Job executor
protected JobExecutor jobExecutor;
protected JobHandlers jobHandlers;
protected boolean jobExecutorAutoActivate;
// Database
protected String databaseName;
protected String dbSchemaStrategy;
protected IdGenerator idGenerator;
protected long idBlockSize;
protected DataSource dataSource;
protected boolean localTransactions;
protected String jdbcDriver;
protected String jdbcUrl;
protected String jdbcUsername;
protected String jdbcPassword;
protected ScriptingEngines scriptingEngines;
protected VariableTypes variableTypes;
protected ExpressionManager expressionManager;
protected BusinessCalendarManager businessCalendarManager;
protected boolean transactionsExternallyManaged;
protected int historyLevel = HISTORYLEVEL_AUDIT;
// Id generator
protected IdGenerator idGenerator;
protected long idBlockSize;
// History
protected int historyLevel;
protected Map<String, List<TaskListener>> taskListeners;
protected boolean isConfigurationCompleted = false;
// Webservices
protected String wsSyncFactoryClassName;
protected String mailServerSmtpHost;
protected String mailServerSmtpUserName;
protected String mailServerSmtpPassword;
protected int mailServerSmtpPort;
// Mail
protected String mailServerHost;
protected String mailServerUsername;
protected String mailServerPassword;
protected int mailServerPort;
protected String mailServerDefaultFrom;
// Forms
protected Map<String, FormEngine> formEngines;
protected FormTypes formTypes;
// Classloading
protected static ThreadLocal<ClassLoader> currentClassLoaderParameter = new ThreadLocal<ClassLoader>();
protected ClassLoader classLoader;
// miscellaneous
protected ScriptingEngines scriptingEngines;
protected VariableTypes variableTypes;
protected ExpressionManager expressionManager;
protected BusinessCalendarManager businessCalendarManager;
// Indicates whether the configuration has been completed:
// ie a process engine has been built using this configuration
protected boolean isConfigurationCompleted = false;
/**
* Constructs a {@link ProcessEngineConfiguration} based on the default settings.
*/
public ProcessEngineConfiguration() {
processEngineName = ProcessEngines.NAME_DEFAULT;
......@@ -229,12 +251,12 @@ public class ProcessEngineConfiguration {
jobExecutor = new JobExecutor();
jobExecutorAutoActivate = false;
databaseName = DEFAULT_DATABASE_NAME;
databaseName = "h2";
dbSchemaStrategy = DbSchemaStrategy.CREATE_DROP;
idGenerator = new DbIdGenerator();
idBlockSize = 100;
dataSource = null;
localTransactions = true;
transactionsExternallyManaged = false;
jdbcDriver = DEFAULT_JDBC_DRIVER;
jdbcUrl = DEFAULT_JDBC_URL;
jdbcUsername = DEFAULT_JDBC_USERNAME;
......@@ -247,8 +269,10 @@ public class ProcessEngineConfiguration {
mapBusinessCalendarManager.addBusinessCalendar(DurationBusinessCalendar.NAME, new DurationBusinessCalendar());
businessCalendarManager = mapBusinessCalendarManager;
historyLevel = HISTORYLEVEL_AUDIT;
mailServerDefaultFrom = DEFAULT_FROM_EMAIL_ADDRESS;
mailServerSmtpPort = DEFAULT_MAIL_SERVER_SMTP_PORT;
mailServerPort = DEFAULT_MAIL_SERVER_SMTP_PORT;
formEngines = new HashMap<String, FormEngine>();
FormEngine defaultFormEngine = new JuelFormEngine();
......@@ -262,6 +286,12 @@ public class ProcessEngineConfiguration {
}
public ProcessEngine buildProcessEngine() {
// Validation of settings
if (databaseName == null) {
throw new ActivitiException("No database name provided. "
+ "This is required for schema creation and query lookup");
}
configurationComplete();
classLoader = currentClassLoaderParameter.get();
......@@ -602,12 +632,12 @@ public class ProcessEngineConfiguration {
this.jobExecutorAutoActivate = jobExecutorAutoActivate;
}
public boolean isLocalTransactions() {
return localTransactions;
public boolean isTransactionsExternallyManaged() {
return transactionsExternallyManaged;
}
public void setLocalTransactions(boolean localTransactions) {
this.localTransactions = localTransactions;
public void setTransactionsExternallyManaged(boolean transactionsExternallyManaged) {
this.transactionsExternallyManaged = transactionsExternallyManaged;
}
public List<Deployer> getDeployers() {
......@@ -634,42 +664,41 @@ public class ProcessEngineConfiguration {
this.wsSyncFactoryClassName = wsSyncFactoryClassName;
}
public String getMailServerSmtpHost() {
return mailServerSmtpHost;
public String getMailServerHost() {
return mailServerHost;
}
public void setMailServerSmtpHost(String mailServerSmtpHost) {
this.mailServerSmtpHost = mailServerSmtpHost;
public void setMailServerHost(String mailServerHost) {
this.mailServerHost = mailServerHost;
}
public String getMailServerSmtpUserName() {
return mailServerSmtpUserName;
public String getMailServerUsername() {
return mailServerUsername;
}
public void setMailServerSmtpUserName(String mailServerSmtpUserName) {
this.mailServerSmtpUserName = mailServerSmtpUserName;
public void setMailServerUsername(String mailServerUsername) {
this.mailServerUsername = mailServerUsername;
}
public String getMailServerSmtpPassword() {
return mailServerSmtpPassword;
public String getMailServerPassword() {
return mailServerPassword;
}
public void setMailServerSmtpPassword(String mailServerSmtpPassword) {
this.mailServerSmtpPassword = mailServerSmtpPassword;
public void setMailServerPassword(String mailServerPassword) {
this.mailServerPassword = mailServerPassword;
}
public int getMailServerSmtpPort() {
return mailServerSmtpPort;
public int getMailServerPort() {
return mailServerPort;
}
public void setMailServerSmtpPort(int mailServerSmtpPort) {
this.mailServerSmtpPort = mailServerSmtpPort;
public void setMailServerPort(int mailServerPort) {
this.mailServerPort = mailServerPort;
}
public String getMailServerDefaultFrom() {
return mailServerDefaultFrom;
}
public void setMailServerDefaultFrom(String mailServerDefaultFrom) {
this.mailServerDefaultFrom = mailServerDefaultFrom;
......
......@@ -122,10 +122,10 @@ public class DbSqlSessionFactory implements SessionFactory, ProcessEngineConfigu
}
TransactionFactory transactionFactory = null;
if (processEngineConfiguration.isLocalTransactions()) {
transactionFactory = new JdbcTransactionFactory();
} else {
if (processEngineConfiguration.isTransactionsExternallyManaged()) {
transactionFactory = new ManagedTransactionFactory();
} else {
transactionFactory = new JdbcTransactionFactory();
}
this.sqlSessionFactory = createSessionFactory(dataSource, transactionFactory);
......@@ -229,7 +229,7 @@ public class DbSqlSessionFactory implements SessionFactory, ProcessEngineConfigu
} catch (Exception e) {
if (isMissingTablesException(e)) {
throw new ActivitiException(
"no activiti tables in db. set property db.schema.strategy=create-drop in activiti.properties for automatic schema creation", e);
"no activiti tables in db. set schema-strategy='create-drop' in activiti.cfg.xml for automatic schema creation", e);
} else {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
......
......@@ -29,7 +29,7 @@ public class DefaultProcessEngineInitializer implements ProcessEngineInitializer
public ProcessEngine getProcessEngine() {
log.fine("==== BUILDING PROCESS ENGINE ========================================================================");
ProcessEngine processEngine = new ProcessEngineBuilder()
.configureFromPropertiesResource("activiti.properties")
.configureFromResource("activiti.cfg.xml")
.buildProcessEngine();
log.fine("==== PROCESS ENGINE CREATED =========================================================================");
return processEngine;
......
......@@ -198,7 +198,7 @@ public abstract class TestHelper {
if (processEngine==null) {
log.fine("==== BUILDING PROCESS ENGINE ========================================================================");
processEngine = new ProcessEngineBuilder()
.configureFromPropertiesResource(configurationResource)
.configureFromResource(configurationResource)
.buildProcessEngine();
log.fine("==== PROCESS ENGINE CREATED =========================================================================");
processEngines.put(configurationResource, processEngine);
......
......@@ -47,13 +47,13 @@ public class Element {
public Element(String uri, String localName, String qName, Attributes attributes, Locator locator) {
this.uri = uri;
this.tagName = localName;
this.tagName = (uri == null || uri.equals("")) ? qName : localName;
if (attributes!=null) {
for (int i=0; i<attributes.getLength(); i++) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
String attributeUri = attributes.getURI(i);
String name = (attributeUri == null || attributeUri.equals("")) ? attributes.getQName(i) : attributes.getLocalName(i);
String value = attributes.getValue(i);
this.attributeMap.put(composeMapKey(attributeUri, name),
new Attribute(name, value, attributeUri));
}
......
......@@ -17,8 +17,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Stack;
import java.util.logging.Logger;
import javax.xml.parsers.SAXParser;
......@@ -54,7 +52,6 @@ public class Parse extends DefaultHandler {
protected List<Problem> errors = new ArrayList<Problem>();
protected List<Problem> warnings = new ArrayList<Problem>();
protected String schemaResource;
protected Stack<Object> contextStack;
public Parse(Parser parser) {
this.parser = parser;
......@@ -119,12 +116,17 @@ public class Parse extends DefaultHandler {
public Parse execute() {
try {
InputStream inputStream = streamSource.getInputStream();
SAXParser saxParser = parser.getSaxParser();
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
saxParser.setProperty(JAXP_SCHEMA_SOURCE, schemaResource);
if (schemaResource != null) {
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
saxParser.setProperty(JAXP_SCHEMA_SOURCE, schemaResource);
} else {
parser.getSaxParserFactory().setNamespaceAware(false);
parser.getSaxParserFactory().setValidating(false);
}
saxParser.parse(inputStream, new ParseHandler(this));
} catch (Exception e) { // any exception can happen (Activiti, Io, etc.)
throw new ActivitiException("couldn't parse '"+name+"': "+e.getMessage(), e);
}
......@@ -185,35 +187,5 @@ public class Parse extends DefaultHandler {
saxParserFactory.setValidating(true);
this.schemaResource = schemaResource;
}
public void pushContextObject(Object obj) {
if (contextStack == null) {
contextStack = new Stack<Object>();
}
contextStack.push(obj);
}
public Object popContextObject() {
if (contextStack != null) {
return contextStack.pop();
} else {
throw new ActivitiException("Context stack was never initialised, so calling the pop() operation is invalid");
}
}
/**
* Searches the contextual stack from top to bottom for an object of the given class
*/
public <T> T findContextualObject(Class<T> clazz) {
if (contextStack != null) {
ListIterator<Object> iterator = contextStack.listIterator(contextStack.size());
while (iterator.hasPrevious()) {
Object obj = iterator.previous();
if (clazz.isInstance(obj)) {
return clazz.cast(obj);
}
}
}
return null;
}
}
......@@ -42,7 +42,7 @@ import org.junit.runners.model.FrameworkMethod;
*
* <p>The ProcessEngine and the services will be made available to the test class
* through the getters of the activitiRule.
* The processEngine will be initialized by default with the activiti.properties resource
* The processEngine will be initialized by default with the activiti.cfg.xml resource
* on the classpath. To specify a different configuration file, pass the
* resource location in {@link #ActivitiRule(String) the appropriate constructor}.
* Process engines will be cached statically. Right before the first time the setUp is called for a given
......@@ -66,7 +66,7 @@ import org.junit.runners.model.FrameworkMethod;
*/
public class ActivitiRule extends TestWatchman {
protected String DEFAULT_CONIFGURATION_RESOURCE = "activiti.properties";
protected String configurationResource = "activiti.cfg.xml";
protected String deploymentId = null;
protected ProcessEngine processEngine;
......@@ -81,7 +81,7 @@ public class ActivitiRule extends TestWatchman {
}
public ActivitiRule(String configurationResource) {
this.DEFAULT_CONIFGURATION_RESOURCE = configurationResource;
this.configurationResource = configurationResource;
}
public ActivitiRule(ProcessEngine processEngine) {
......@@ -99,7 +99,7 @@ public class ActivitiRule extends TestWatchman {
}
protected void initializeProcessEngine() {
processEngine = TestHelper.getProcessEngine(DEFAULT_CONIFGURATION_RESOURCE);
processEngine = TestHelper.getProcessEngine(configurationResource);
}
protected void initializeServices() {
......@@ -123,11 +123,11 @@ public class ActivitiRule extends TestWatchman {
}
public String getConfigurationResource() {
return DEFAULT_CONIFGURATION_RESOURCE;
return configurationResource;
}
public void setConfigurationResource(String configurationResource) {
this.DEFAULT_CONIFGURATION_RESOURCE = configurationResource;
this.configurationResource = configurationResource;
}
public ProcessEngine getProcessEngine() {
......
......@@ -33,7 +33,7 @@ import org.activiti.engine.impl.util.ClockUtil;
* <p>Usage: <code>public class YourTest extends ActivitiTestCase</code></p>
*
* <p>The ProcessEngine and the services available to subclasses through protected member fields.
* The processEngine will be initialized by default with the activiti.properties resource
* The processEngine will be initialized by default with the activiti.cfg.xml resource
* on the classpath. To specify a different configuration file, override the
* {@link #getConfigurationResource()} method.
* Process engines will be cached statically. The first time the setUp is called for a given
......@@ -57,7 +57,7 @@ import org.activiti.engine.impl.util.ClockUtil;
*/
public class ActivitiTestCase extends TestCase {
protected String configurationResource = "activiti.properties";
protected String configurationResource = "activiti.cfg.xml";
protected String deploymentId = null;
protected ProcessEngine processEngine;
......@@ -68,7 +68,7 @@ public class ActivitiTestCase extends TestCase {
protected IdentityService identityService;
protected ManagementService managementService;
/** uses 'activiti.properties' as it's configuration resource */
/** uses 'activiti.cfg.xml' as it's configuration resource */
public ActivitiTestCase() {
}
......
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
targetNamespace="http://activiti.org/cfg"
xmlns:tns="http://activiti.org/cfg">
<annotation>
<documentation>XML schema for Activiti configuration filees.</documentation>
</annotation>
<element name="activiti-cfg">
<annotation>
<documentation>Root element of an Activiti configuration.</documentation>
</annotation>
<complexType>
<choice minOccurs="1" maxOccurs="unbounded">
<element ref="tns:database" minOccurs="1" maxOccurs="1" />
<element ref="tns:job-executor" minOccurs="0" maxOccurs="1" />
<element ref="tns:mail" minOccurs="0" maxOccurs="1" />
<element ref="tns:history" minOccurs="0" maxOccurs="1" />
</choice>
<attribute name="process-engine-name" type="string">
<annotation>
<documentation>
Optional name for the process engine. If not provided,
the process engine will be named 'default'
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="database">
<annotation>
<documentation>
Configuration for the Activiti database.
</documentation>
</annotation>
<complexType>
<choice>
<element ref="tns:jdbc" />
<element ref="tns:datasource" />
</choice>
<attribute name="name" use="required" type="string">
<annotation>
<documentation>
The name of the database (eg. h2, oracle, mysql, etc.).
See Activiti userguide for supported databases (http://activiti.org/userguide/)
</documentation>
</annotation>
</attribute>
<attribute name="schema-strategy" type="string">
<annotation>
<documentation>
Specifies the strategy to synchronize between the library version and the
database schema version (eg create-drop, check-version, etc.).
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="jdbc">
<annotation>
<documentation>
Configuration of the Activiti database using JDBC connection properties.
</documentation>
</annotation>
<complexType>
<attribute name="url" use="required" />
<attribute name="driver" use="required" />
<attribute name="username" use="required" />
<attribute name="password" use="required" />
</complexType>
</element>
<element name="datasource">
<annotation>
<documentation>
Configuration of the Activiti database using a JNDI datasource.
</documentation>
</annotation>
<complexType>
<attribute name="jndi" use="required">
<annotation>
<documentation>
Jndi name used to look up the Activiti datasource.
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="job-executor">
<annotation>
<documentation>
Configuration of the job executor.
</documentation>
</annotation>
<complexType>
<attribute name="auto-activate" use="required" type="string">
<annotation>
<documentation>
Specifies if the job executor must be activated when the engine starts.
Possible values: on/off enabled/disabled true/false.
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="mail">
<annotation>
<documentation>
Configuration of an SMTP mail server to send e-mails during business process execution.
</documentation>
</annotation>
<complexType>
<attribute name="host" use="required" type="string">
<annotation>
<documentation>
Host of the SMTP mail server.
</documentation>
</annotation>
</attribute>
<attribute name="port" type="string">
<annotation>
<documentation>
Port of the SMTP mail server. By default port 25.
</documentation>
</annotation>
</attribute>
<attribute name="username" type="string">
<annotation>
<documentation>
Optional user name for secured SMTP mail servers.
</documentation>
</annotation>
</attribute>
<attribute name="password">
<annotation>
<documentation>
Optional password for secured SMTP mail servers.
</documentation>
</annotation>
</attribute>
<attribute name="default-from" type="string">
<annotation>
<documentation>
Process engine wide setting for the default mail address from
which e-mail are sent in business processes. Process definitions
can overwrite this process engine wide 'from address' if needed.
Default value is 'noreply@activiti.org'.
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="history">
<annotation>
<documentation>
Configuration for the history capabilities of Activiti.
</documentation>
</annotation>
<complexType>
<attribute name="level" use="required">
<annotation>
<documentation>
Indicates the level of history logging.
</documentation>
</annotation>
<simpleType>
<restriction base="string">
<enumeration value="none" />
<enumeration value="activity" />
<enumeration value="audit" />
<enumeration value="full" />
</restriction>
</simpleType>
</attribute>
</complexType>
</element>
</schema>
\ No newline at end of file
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.test.cfg;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.cfg.ConfigurationParse;
import org.activiti.engine.impl.cfg.ConfigurationParser;
import org.activiti.engine.impl.cfg.ProcessEngineConfiguration;
import org.activiti.engine.impl.test.PvmTestCase;
/**
* @author Joram Barrez
*/
public class ConfigurationParserTest extends PvmTestCase {
protected ConfigurationParser configurationParser;
@Override
protected void setUp() throws Exception {
super.setUp();
this.configurationParser = new ConfigurationParser();
}
public void testInvalidXml() {
try {
configurationParser.createParse()
.sourceResource("org/activiti/engine/test/cfg/invalid.activiti.cfg.xml")
.execute();
fail("Invalid config xml should not parse");
} catch (ActivitiException e) {
assertTextPresent("Cannot find the declaration of element 'activiti-invalid'", e.getMessage());
}
}
public void testMissingDbConfiguration() {
try {
configurationParser.createParse()
.sourceResource("org/activiti/engine/test/cfg/no-db-config.activiti.cfg.xml")
.execute();
fail("Invalid config xml should not parse");
} catch (ActivitiException e) {
assertTextPresent("Could not find required element 'database'", e.getMessage());
}
}
public void testOnlyDbConfiguration() {
ConfigurationParse parse =
configurationParser.createParse()
.sourceResource("org/activiti/engine/test/cfg/only-db-config.activiti.cfg.xml")
.execute();
assertNotNull(parse);
assertEquals("only-db", parse.getProcessEngineName());
}
public void testMultipleDbConfigurations() {
try {
configurationParser.createParse()
.sourceResource("org/activiti/engine/test/cfg/multiple-db-config.activiti.cfg.xml")
.execute();
fail("Invalid config xml should not parse");
} catch (ActivitiException e) {
assertTextPresent("multiple elements with tag name database found", e.getMessage());
}
}
public void testValidConfiguration() {
ConfigurationParse parse =
configurationParser.createParse()
.sourceResource("org/activiti/engine/test/cfg/complete.activiti.cfg.xml")
.execute();
assertNotNull(parse);
assertEquals("complete-cfg", parse.getProcessEngineName());
assertEquals("localhost", parse.getMailServerHost());
assertEquals(new Integer(5025), parse.getMailServerPort());
assertNull(parse.getMailDefaultFrom());
assertNull(parse.getMailServerUsername());
assertNull(parse.getMailServerPassword());
assertEquals("h2", parse.getDatabaseName());
assertEquals("create-if-necessary", parse.getDatabaseSchemaStrategy());
assertEquals("jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000", parse.getJdbcUrl());
assertEquals("org.h2.Driver", parse.getJdbcDriver());
assertEquals("sa", parse.getJdbcUsername());
assertEquals("", parse.getJdbcPassword());
assertTrue(parse.getIsJobExecutorAutoActivate());
assertEquals(ProcessEngineConfiguration.parseHistoryLevel("audit"), parse.getHistoryLevel());
}
}
......@@ -24,7 +24,7 @@ public class NoDbConnectionTest extends PvmTestCase {
public void testNoDbConnection() {
try {
new ProcessEngineBuilder().configureFromPropertiesResource("org/activiti/standalone/initialization/nodbconnection.activiti.properties").buildProcessEngine();
new ProcessEngineBuilder().configureFromResource("org/activiti/standalone/initialization/nodbconnection.activiti.cfg.xml").buildProcessEngine();
fail("expected exception");
} catch (RuntimeException e) {
assertTrue(containsSqlException(e));
......
......@@ -35,19 +35,19 @@ public class ProcessEngineInitializationTest extends PvmTestCase {
public void testNoTables() {
try {
new ProcessEngineBuilder()
.configureFromPropertiesResource("org/activiti/standalone/initialization/notables.activiti.properties")
.configureFromResource("org/activiti/standalone/initialization/notables.activiti.cfg.xml")
.buildProcessEngine();
fail("expected exception");
} catch (Exception e) {
// OK
assertTextPresent("no activiti tables in db. set property db.schema.strategy=create-drop in activiti.properties for automatic schema creation", e.getMessage());
assertTextPresent("no activiti tables in db", e.getMessage());
}
}
public void testVersionMismatch() {
// first create the schema
ProcessEngineImpl processEngine = (ProcessEngineImpl) new ProcessEngineBuilder()
.configureFromPropertiesResource("org/activiti/standalone/initialization/notables.activiti.properties")
.configureFromResource("org/activiti/standalone/initialization/notables.activiti.cfg.xml")
.setDbSchemaStrategy(DbSchemaStrategy.CREATE_DROP)
.buildProcessEngine();
......@@ -80,7 +80,7 @@ public class ProcessEngineInitializationTest extends PvmTestCase {
// now we can see what happens if when a process engine is being
// build with a version mismatch between library and db tables
new ProcessEngineBuilder()
.configureFromPropertiesResource("org/activiti/standalone/initialization/notables.activiti.properties")
.configureFromResource("org/activiti/standalone/initialization/notables.activiti.cfg.xml")
.setDbSchemaStrategy(DbSchemaStrategy.CHECK_VERSION)
.buildProcessEngine();
......
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg">
<database name="h2" schema-strategy="create-if-necessary">
<jdbc url="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
<job-executor auto-activate="off" />
<mail host="localhost" port="5025" />
</activiti-cfg>
database=h2
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000
jdbc.username=sa
jdbc.password=
db.schema.strategy=create-if-necessary
job.executor.auto.activate=off
mail.smtp.host=localhost
mail.smtp.port=5025
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://activiti.org/cfg http://activiti.org/cfg/activiti-cfg-5.0.xsd"
process-engine-name="complete-cfg">
<mail host="localhost" port="5025" />
<job-executor auto-activate="on" />
<history level="audit" />
<database name="h2" schema-strategy="create-if-necessary">
<jdbc url="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
</activiti-cfg>
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg" process-engine-name="complete-cfg">
<mail host="localhost" port="5025" />
<job-executor auto-activate="on" />
<history level="audit" />
<database name="h2" schema-strategy="create-if-necessary">
<jdbc url="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
</activiti-cfg>
<?xml version="1.0" encoding="UTF-8"?>
<activiti-invalid xmlns="http://activiti.org/cfg">
</activiti-invalid>
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg" process-engine-name="only-db">
<database name="h2" schema-strategy="create-if-necessary">
<jdbc url="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
<database name="h2" schema-strategy="create-if-necessary">
<jdbc url="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
</activiti-cfg>
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg">
<job-executor auto-activate="off" />
<mail host="localhost" port="5025" />
</activiti-cfg>
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg" process-engine-name="only-db">
<database name="h2" schema-strategy="create-if-necessary">
<jdbc url="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
</activiti-cfg>
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg">
<database name="h2" schema-strategy="drop-create">
<jdbc url="jdbc:h2:tcp://non-existing-host/non-existing-db;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
<job-executor auto-activate="off" />
<mail host="localhost" port="5025" />
</activiti-cfg>
database=h2
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:tcp://non-existing-host/non-existing-db
jdbc.username=sa
jdbc.password=
db.schema.strategy=drop-create
job.executor.auto.activate=off
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg">
<database name="h2" schema-strategy="check-version">
<jdbc url="jdbc:h2:mem:ProcessEngineInitializationTest;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
<job-executor auto-activate="off" />
<mail host="localhost" port="5025" />
</activiti-cfg>
database=h2
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:mem:ProcessEngineInitializationTest;DB_CLOSE_DELAY=1000
jdbc.username=sa
jdbc.password=
db.schema.strategy=check-version
job.executor.auto.activate=off
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg">
<database name="h2" schema-strategy="create-if-necessary">
<jdbc url="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
<job-executor auto-activate="off" />
<mail host="localhost" port="5025" />
</activiti-cfg>
database=h2
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000
jdbc.username=sa
jdbc.password=
db.schema.strategy=create-drop
job.executor.auto.activate=off
ws.sync.factory=org.activiti.engine.impl.webservice.CxfWebServiceClientFactory
......@@ -33,7 +33,6 @@ import org.activiti.engine.impl.interceptor.CommandExecutorImpl;
import org.activiti.engine.impl.interceptor.CommandInterceptor;
import org.activiti.engine.impl.interceptor.LogInterceptor;
import org.activiti.engine.impl.jobexecutor.JobExecutor;
import org.activiti.engine.impl.variable.VariableTypes;
import org.activiti.engine.repository.DeploymentBuilder;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
......@@ -93,7 +92,7 @@ public class ProcessEngineFactoryBean implements FactoryBean<ProcessEngine>, Dis
}
private void initializeSpringTransactionInterceptor() {
processEngineConfiguration.setLocalTransactions(transactionManager == null);
processEngineConfiguration.setTransactionsExternallyManaged(transactionManager != null);
if (transactionManager != null) {
List<CommandInterceptor> commandInterceptorsTxRequired = new ArrayList<CommandInterceptor>();
......@@ -219,24 +218,20 @@ public class ProcessEngineFactoryBean implements FactoryBean<ProcessEngine>, Dis
processEngineConfiguration.setProcessEngineName(processEngineName);
}
public void setVariableTypes(VariableTypes variableTypes) {
processEngineConfiguration.setVariableTypes(variableTypes);
}
public void setMailServerHost(String mailServerHost) {
processEngineConfiguration.setMailServerSmtpHost(mailServerHost);
processEngineConfiguration.setMailServerHost(mailServerHost);
}
public void setMailServerPort(int mailServerPort) {
processEngineConfiguration.setMailServerSmtpPort(mailServerPort);
processEngineConfiguration.setMailServerPort(mailServerPort);
}
public void setMailServerUserName(String userName) {
processEngineConfiguration.setMailServerSmtpUserName(userName);
public void setMailServerUsername(String username) {
processEngineConfiguration.setMailServerUsername(username);
}
public void setMailServerPassword(String password) {
processEngineConfiguration.setMailServerSmtpPassword(password);
processEngineConfiguration.setMailServerPassword(password);
}
public void setMailServerDefaultFromAddress(String defaultFromAddress) {
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.activiti.engine.delegate.EventListener;
import org.activiti.engine.delegate.EventListenerExecution;
/**
* @author Tom Baeyens
*/
public class EventCollector implements EventListener {
private static Logger log = Logger.getLogger(EventCollector.class.getName());
public List<String> events = new ArrayList<String>();
public void notify(EventListenerExecution execution) {
log.fine("collecting event: "+execution.getEventName()+" on "+execution.getEventSource());
events.add(execution.getEventName()+" on "+execution.getEventSource());
}
public String toString() {
StringBuilder text = new StringBuilder();
for (String event: events) {
text.append(event);
text.append("\n");
}
return text.toString();
}
}
package org.activiti.test.pvm;
import java.util.ArrayList;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.WaitState;
import org.activiti.test.pvm.activities.While;
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author Tom Baeyens
*/
public class PvmBasicLinearExecutionTest extends PvmTestCase {
/**
* +-------+ +-----+
* | start |-->| end |
* +-------+ +-----+
*/
public void testStartEnd() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
/**
* +-----+ +-----+ +-------+
* | one |-->| two |-->| three |
* +-----+ +-----+ +-------+
*/
public void testSingleAutomatic() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("one")
.initial()
.behavior(new Automatic())
.transition("two")
.endActivity()
.createActivity("two")
.behavior(new Automatic())
.transition("three")
.endActivity()
.createActivity("three")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
/**
* +-----+ +-----+ +-------+
* | one |-->| two |-->| three |
* +-----+ +-----+ +-------+
*/
public void testSingleWaitState() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("one")
.initial()
.behavior(new Automatic())
.transition("two")
.endActivity()
.createActivity("two")
.behavior(new WaitState())
.transition("three")
.endActivity()
.createActivity("three")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
PvmExecution activityInstance = processInstance.findExecution("two");
assertNotNull(activityInstance);
activityInstance.signal(null, null);
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
/**
* +-----+ +-----+ +-------+ +------+ +------+
* | one |-->| two |-->| three |-->| four |--> | five |
* +-----+ +-----+ +-------+ +------+ +------+
*/
public void testCombinationOfWaitStatesAndAutomatics() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("one")
.endActivity()
.createActivity("one")
.behavior(new WaitState())
.transition("two")
.endActivity()
.createActivity("two")
.behavior(new WaitState())
.transition("three")
.endActivity()
.createActivity("three")
.behavior(new Automatic())
.transition("four")
.endActivity()
.createActivity("four")
.behavior(new Automatic())
.transition("five")
.endActivity()
.createActivity("five")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
PvmExecution activityInstance = processInstance.findExecution("one");
assertNotNull(activityInstance);
activityInstance.signal(null, null);
activityInstance = processInstance.findExecution("two");
assertNotNull(activityInstance);
activityInstance.signal(null, null);
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
/**
* +----------------------------+
* v |
* +-------+ +------+ +-----+ +-----+ +-------+
* | start |-->| loop |-->| one |-->| two |--> | three |
* +-------+ +------+ +-----+ +-----+ +-------+
* |
* | +-----+
* +-->| end |
* +-----+
*/
public void testWhileLoop() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("loop")
.endActivity()
.createActivity("loop")
.behavior(new While("count", 0, 500))
.transition("one", "more")
.transition("end", "done")
.endActivity()
.createActivity("one")
.behavior(new Automatic())
.transition("two")
.endActivity()
.createActivity("two")
.behavior(new Automatic())
.transition("three")
.endActivity()
.createActivity("three")
.behavior(new Automatic())
.transition("loop")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.EmbeddedSubProcess;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.ParallelGateway;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmEmbeddedSubProcessTest extends PvmTestCase {
/**
* +------------------------------+
* | embedded subprocess |
* +-----+ | +-----------+ +---------+ | +---+
* |start|-->| |startInside|-->|endInside| |-->|end|
* +-----+ | +-----------+ +---------+ | +---+
* +------------------------------+
*/
public void testEmbeddedSubProcess() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("embeddedsubprocess")
.endActivity()
.createActivity("embeddedsubprocess")
.scope()
.behavior(new EmbeddedSubProcess())
.createActivity("startInside")
.behavior(new Automatic())
.transition("endInside")
.endActivity()
.createActivity("endInside")
.behavior(new End())
.endActivity()
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedActiveActivityIds = new ArrayList<String>();
expectedActiveActivityIds.add("end");
assertEquals(expectedActiveActivityIds, processInstance.findActiveActivityIds());
}
/**
* +----------------------------------------+
* | embeddedsubprocess +----------+ |
* | +---->|endInside1| |
* | | +----------+ |
* | | |
* +-----+ | +-----------+ +----+ +----------+ | +---+
* |start|-->| |startInside|-->|fork|-->|endInside2| |-->|end|
* +-----+ | +-----------+ +----+ +----------+ | +---+
* | | |
* | | +----------+ |
* | +---->|endInside3| |
* | +----------+ |
* +----------------------------------------+
*/
public void testMultipleConcurrentEndsInsideEmbeddedSubProcess() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("embeddedsubprocess")
.endActivity()
.createActivity("embeddedsubprocess")
.scope()
.behavior(new EmbeddedSubProcess())
.createActivity("startInside")
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("endInside1")
.transition("endInside2")
.transition("endInside3")
.endActivity()
.createActivity("endInside1")
.behavior(new End())
.endActivity()
.createActivity("endInside2")
.behavior(new End())
.endActivity()
.createActivity("endInside3")
.behavior(new End())
.endActivity()
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertTrue(processInstance.isEnded());
}
/**
* +-------------------------------------------------+
* | embeddedsubprocess +----------+ |
* | +---->|endInside1| |
* | | +----------+ |
* | | |
* +-----+ | +-----------+ +----+ +----+ +----------+ | +---+
* |start|-->| |startInside|-->|fork|-->|wait|-->|endInside2| |-->|end|
* +-----+ | +-----------+ +----+ +----+ +----------+ | +---+
* | | |
* | | +----------+ |
* | +---->|endInside3| |
* | +----------+ |
* +-------------------------------------------------+
*/
public void testMultipleConcurrentEndsInsideEmbeddedSubProcessWithWaitState() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("embeddedsubprocess")
.endActivity()
.createActivity("embeddedsubprocess")
.scope()
.behavior(new EmbeddedSubProcess())
.createActivity("startInside")
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("endInside1")
.transition("wait")
.transition("endInside3")
.endActivity()
.createActivity("endInside1")
.behavior(new End())
.endActivity()
.createActivity("wait")
.behavior(new WaitState())
.transition("endInside2")
.endActivity()
.createActivity("endInside2")
.behavior(new End())
.endActivity()
.createActivity("endInside3")
.behavior(new End())
.endActivity()
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertFalse(processInstance.isEnded());
PvmExecution execution = processInstance.findExecution("wait");
execution.signal(null, null);
assertTrue(processInstance.isEnded());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.delegate.EventListener;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.EmbeddedSubProcess;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.ParallelGateway;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmEventTest extends PvmTestCase {
/**
* +-------+ +-----+
* | start |-->| end |
* +-------+ +-----+
*/
public void testStartEndEvents() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("events")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.startTransition("end")
.eventListener(eventCollector)
.endTransition()
.endActivity()
.createActivity("end")
.behavior(new End())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedEvents = new ArrayList<String>();
expectedEvents.add("start on ProcessDefinition(events)");
expectedEvents.add("start on Activity(start)");
expectedEvents.add("end on Activity(start)");
expectedEvents.add("take on (start)-->(end)");
expectedEvents.add("start on Activity(end)");
expectedEvents.add("end on Activity(end)");
expectedEvents.add("end on ProcessDefinition(events)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
}
/**
* +--------------+
* |outerscope |
* | +----------+ |
* | |innerscope| |
* +-----+ | | +----+ | | +---+
* |start|---->|wait|------>|end|
* +-----+ | | +----+ | | +---+
* | +----------+ |
* +--------------+
*/
public void testNestedActivitiesEventsOnTransitionEvents() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("events")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.startTransition("wait")
.eventListener(eventCollector)
.endTransition()
.endActivity()
.createActivity("outerscope")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("innerscope")
.scope()
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("wait")
.behavior(new WaitState())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("end")
.endActivity()
.endActivity()
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedEvents = new ArrayList<String>();
expectedEvents.add("start on ProcessDefinition(events)");
expectedEvents.add("start on Activity(start)");
expectedEvents.add("end on Activity(start)");
expectedEvents.add("take on (start)-->(wait)");
expectedEvents.add("start on Activity(outerscope)");
expectedEvents.add("start on Activity(innerscope)");
expectedEvents.add("start on Activity(wait)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
PvmExecution execution = processInstance.findExecution("wait");
execution.signal(null, null);
expectedEvents.add("end on Activity(wait)");
expectedEvents.add("end on Activity(innerscope)");
expectedEvents.add("end on Activity(outerscope)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
}
/**
* +------------------------------+
* +-----+ | +-----------+ +----------+ | +---+
* |start|-->| |startInside|-->|endInsdide| |-->|end|
* +-----+ | +-----------+ +----------+ | +---+
* +------------------------------+
*/
public void testEmbeddedSubProcessEvents() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("events")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("embeddedsubprocess")
.endActivity()
.createActivity("embeddedsubprocess")
.scope()
.behavior(new EmbeddedSubProcess())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("startInside")
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("endInside")
.endActivity()
.createActivity("endInside")
.behavior(new End())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedEvents = new ArrayList<String>();
expectedEvents.add("start on ProcessDefinition(events)");
expectedEvents.add("start on Activity(start)");
expectedEvents.add("end on Activity(start)");
expectedEvents.add("start on Activity(embeddedsubprocess)");
expectedEvents.add("start on Activity(startInside)");
expectedEvents.add("end on Activity(startInside)");
expectedEvents.add("start on Activity(endInside)");
expectedEvents.add("end on Activity(endInside)");
expectedEvents.add("end on Activity(embeddedsubprocess)");
expectedEvents.add("start on Activity(end)");
expectedEvents.add("end on Activity(end)");
expectedEvents.add("end on ProcessDefinition(events)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
}
/**
* +--+
* +--->|c1|---+
* | +--+ |
* | v
* +-----+ +----+ +----+ +---+
* |start|-->|fork| |join|-->|end|
* +-----+ +----+ +----+ +---+
* | ^
* | +--+ |
* +--->|c2|---+
* +--+
*/
public void testSimpleAutmaticConcurrencyEvents() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("events")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("c1")
.transition("c2")
.endActivity()
.createActivity("c1")
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("join")
.endActivity()
.createActivity("c2")
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("join")
.endActivity()
.createActivity("join")
.behavior(new ParallelGateway())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedEvents = new ArrayList<String>();
expectedEvents.add("start on ProcessDefinition(events)");
expectedEvents.add("start on Activity(start)");
expectedEvents.add("end on Activity(start)");
expectedEvents.add("start on Activity(fork)");
expectedEvents.add("end on Activity(fork)");
expectedEvents.add("start on Activity(c1)");
expectedEvents.add("end on Activity(c1)");
expectedEvents.add("start on Activity(join)");
expectedEvents.add("end on Activity(fork)");
expectedEvents.add("start on Activity(c2)");
expectedEvents.add("end on Activity(c2)");
expectedEvents.add("start on Activity(join)");
expectedEvents.add("end on Activity(join)");
expectedEvents.add("start on Activity(end)");
expectedEvents.add("end on Activity(end)");
expectedEvents.add("end on ProcessDefinition(events)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.ParallelGateway;
/**
* @author Tom Baeyens
*/
public class PvmParallelEndTest extends PvmTestCase {
/**
* +----+
* +--->|end1|
* | +----+
* |
* +-----+ +----+
* |start|-->|fork|
* +-----+ +----+
* |
* | +----+
* +--->|end2|
* +----+
*/
public void testParallelEnd() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("end1")
.transition("end2")
.endActivity()
.createActivity("end1")
.behavior(new End())
.endActivity()
.createActivity("end2")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertTrue(processInstance.isEnded());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.ParallelGateway;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmParallelTest extends PvmTestCase {
public void testSimpleAutmaticConcurrency() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("c1")
.transition("c2")
.endActivity()
.createActivity("c1")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("c2")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("join")
.behavior(new ParallelGateway())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertTrue(processInstance.isEnded());
}
public void testSimpleWaitStateConcurrency() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("c1")
.transition("c2")
.endActivity()
.createActivity("c1")
.behavior(new WaitState())
.transition("join")
.endActivity()
.createActivity("c2")
.behavior(new WaitState())
.transition("join")
.endActivity()
.createActivity("join")
.behavior(new ParallelGateway())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
PvmExecution activityInstanceC1 = processInstance.findExecution("c1");
assertNotNull(activityInstanceC1);
PvmExecution activityInstanceC2 = processInstance.findExecution("c2");
assertNotNull(activityInstanceC2);
activityInstanceC1.signal(null, null);
activityInstanceC2.signal(null, null);
List<String> activityNames = processInstance.findActiveActivityIds();
List<String> expectedActivityNames = new ArrayList<String>();
expectedActivityNames.add("end");
assertEquals(expectedActivityNames, activityNames);
}
public void testUnstructuredConcurrencyTwoJoins() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("c1")
.transition("c2")
.transition("c3")
.endActivity()
.createActivity("c1")
.behavior(new Automatic())
.transition("join1")
.endActivity()
.createActivity("c2")
.behavior(new Automatic())
.transition("join1")
.endActivity()
.createActivity("c3")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("join1")
.behavior(new ParallelGateway())
.transition("c4")
.endActivity()
.createActivity("c4")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("join2")
.behavior(new ParallelGateway())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertNotNull(processInstance.findExecution("end"));
}
public void testUnstructuredConcurrencyTwoForks() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork1")
.endActivity()
.createActivity("fork1")
.behavior(new ParallelGateway())
.transition("c1")
.transition("c2")
.transition("fork2")
.endActivity()
.createActivity("c1")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("c2")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("fork2")
.behavior(new ParallelGateway())
.transition("c3")
.transition("c4")
.endActivity()
.createActivity("c3")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("c4")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("join")
.behavior(new ParallelGateway())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertNotNull(processInstance.findExecution("end"));
}
public void testJoinForkCombinedInOneParallelGateway() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("c1")
.transition("c2")
.transition("c3")
.endActivity()
.createActivity("c1")
.behavior(new Automatic())
.transition("join1")
.endActivity()
.createActivity("c2")
.behavior(new Automatic())
.transition("join1")
.endActivity()
.createActivity("c3")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("join1")
.behavior(new ParallelGateway())
.transition("c4")
.transition("c5")
.transition("c6")
.endActivity()
.createActivity("c4")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("c5")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("c6")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("join2")
.behavior(new ParallelGateway())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertNotNull(processInstance.findExecution("end"));
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import org.activiti.engine.delegate.EventListener;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmProcessInstanceEndTest extends PvmTestCase {
public void testSimpleProcessInstanceEnd() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("wait")
.endActivity()
.createActivity("wait")
.behavior(new WaitState())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
System.err.println(eventCollector);
processInstance.deleteCascade("test");
System.err.println();
System.err.println(eventCollector);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.ReusableSubProcess;
/**
* @author Tom Baeyens
*/
public class PvmReusableSubProcessTest extends PvmTestCase {
public void testReusableSubProcess() {
PvmProcessDefinition subProcessDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("subEnd")
.endActivity()
.createActivity("subEnd")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessDefinition superProcessDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("subprocess")
.endActivity()
.createActivity("subprocess")
.behavior(new ReusableSubProcess(subProcessDefinition))
.transition("superEnd")
.endActivity()
.createActivity("superEnd")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = superProcessDefinition.createProcessInstance();
processInstance.start();
assertTrue(processInstance.isEnded());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.delegate.EventListener;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmScopeAndEventsTest extends PvmTestCase {
/**
* +--------------------------------------------------------------------------------+
* | mostOuterNestedActivity |
* | +----------------------------------------------------------------------------+ |
* | | outerScope (scope) | |
* | | +----------------------------------+ +-----------------------------------+ | |
* | | | firstInnerScope (scope) | | secondInnerScope (scope) | | |
* | | | +------------------------------+ | | +-------------------------------+ | | |
* | | | | firstMostInnerNestedActivity | | | | secondMostInnerNestedActivity | | | |
* | | | | +-------+ +-------------+ | | | | +--------------+ +-----+ | | | |
* | | | | | start |-->| waitInFirst |--------->| waitInSecond |--> | end | | | | |
* | | | | +-------+ +-------------+ | | | | +--------------+ +-----+ | | | |
* | | | +------------------------------+ | | +-------------------------------+ | | |
* | | +----------------------------------+ +-----------------------------------+ | |
* | +----------------------------------------------------------------------------+ |
* +--------------------------------------------------------------------------------+
*
*/
public void testStartEndWithScopesAndNestedActivities() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("scopes and events")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("mostOuterNestedActivity")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("outerScope")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("firstInnerScope")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("firstMostInnerNestedActivity")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("waitInFirst")
.endActivity()
.createActivity("waitInFirst")
.behavior(new WaitState())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("waitInSecond")
.endActivity()
.endActivity()
.endActivity()
.createActivity("secondInnerScope")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("secondMostInnerNestedActivity")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("waitInSecond")
.behavior(new WaitState())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.endActivity()
.endActivity()
.endActivity()
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedEvents = new ArrayList<String>();
expectedEvents.add("start on ProcessDefinition(scopes and events)");
expectedEvents.add("start on Activity(mostOuterNestedActivity)");
expectedEvents.add("start on Activity(outerScope)");
expectedEvents.add("start on Activity(firstInnerScope)");
expectedEvents.add("start on Activity(firstMostInnerNestedActivity)");
expectedEvents.add("start on Activity(start)");
expectedEvents.add("end on Activity(start)");
expectedEvents.add("start on Activity(waitInFirst)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
eventCollector.events.clear();
PvmExecution execution = processInstance.findExecution("waitInFirst");
execution.signal(null, null);
expectedEvents = new ArrayList<String>();
expectedEvents.add("end on Activity(waitInFirst)");
expectedEvents.add("end on Activity(firstMostInnerNestedActivity)");
expectedEvents.add("end on Activity(firstInnerScope)");
expectedEvents.add("start on Activity(secondInnerScope)");
expectedEvents.add("start on Activity(secondMostInnerNestedActivity)");
expectedEvents.add("start on Activity(waitInSecond)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
eventCollector.events.clear();
execution = processInstance.findExecution("waitInSecond");
execution.signal(null, null);
expectedEvents = new ArrayList<String>();
expectedEvents.add("end on Activity(waitInSecond)");
expectedEvents.add("start on Activity(end)");
expectedEvents.add("end on Activity(end)");
expectedEvents.add("end on Activity(secondMostInnerNestedActivity)");
expectedEvents.add("end on Activity(secondInnerScope)");
expectedEvents.add("end on Activity(outerScope)");
expectedEvents.add("end on Activity(mostOuterNestedActivity)");
expectedEvents.add("end on ProcessDefinition(scopes and events)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
eventCollector.events.clear();
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmScopeWaitStateTest extends PvmTestCase {
/**
* +-----+ +----------+ +---+
* |start|-->|scopedWait|-->|end|
* +-----+ +----------+ +---+
*/
public void testWaitStateScope() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("scopedWait")
.endActivity()
.createActivity("scopedWait")
.scope()
.behavior(new WaitState())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
PvmExecution execution = processInstance.findExecution("scopedWait");
assertNotNull(execution);
execution.signal(null, null);
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
/**
* +--------------+
* | outerScope |
* +-----+ | +----------+ | +---+
* |start|--->|scopedWait|--->|end|
* +-----+ | +----------+ | +---+
* +--------------+
*/
public void testNestedScope() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("scopedWait")
.endActivity()
.createActivity("outerScope")
.scope()
.createActivity("scopedWait")
.scope()
.behavior(new WaitState())
.transition("end")
.endActivity()
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
PvmExecution activityInstance = processInstance.findExecution("scopedWait");
assertNotNull(activityInstance);
activityInstance.signal(null, null);
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.WaitState;
import org.junit.Test;
/**
* @author Tom Baeyens
*/
public class PvmVariablesTest extends PvmTestCase {
@Test
public void testVariables() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("a")
.initial()
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.setVariable("amount", 500L);
processInstance.setVariable("msg", "hello world");
processInstance.start();
assertEquals(500L, processInstance.getVariable("amount"));
assertEquals("hello world", processInstance.getVariable("msg"));
PvmExecution activityInstance = processInstance.findExecution("a");
assertEquals(500L, activityInstance.getVariable("amount"));
assertEquals("hello world", activityInstance.getVariable("msg"));
Map<String, Object> expectedVariables = new HashMap<String, Object>();
expectedVariables.put("amount", 500L);
expectedVariables.put("msg", "hello world");
assertEquals(expectedVariables, activityInstance.getVariables());
assertEquals(expectedVariables, processInstance.getVariables());
}
}
\ No newline at end of file
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import org.activiti.engine.delegate.ActivityBehavior;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.impl.pvm.PvmTransition;
/**
* @author Tom Baeyens
*/
public class Automatic implements ActivityBehavior {
public void execute(ActivityExecution execution) throws Exception {
PvmTransition transition = execution.getActivity().getOutgoingTransitions().get(0);
execution.take(transition);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.delegate.CompositeActivityBehavior;
import org.activiti.engine.impl.pvm.PvmActivity;
import org.activiti.engine.impl.pvm.PvmTransition;
/**
* @author Tom Baeyens
*/
public class EmbeddedSubProcess implements CompositeActivityBehavior {
public void execute(ActivityExecution execution) throws Exception {
List<PvmActivity> startActivities = new ArrayList<PvmActivity>();
for (PvmActivity activity: execution.getActivity().getActivities()) {
if (activity.getIncomingTransitions().isEmpty()) {
startActivities.add(activity);
}
}
for (PvmActivity startActivity: startActivities) {
execution.executeActivity(startActivity);
}
}
@SuppressWarnings("unchecked")
public void lastExecutionEnded(ActivityExecution execution) {
List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
execution.takeAll(outgoingTransitions, Collections.EMPTY_LIST);
}
// used by timers
@SuppressWarnings("unchecked")
public void timerFires(ActivityExecution execution, String signalName, Object signalData) throws Exception {
PvmActivity timerActivity = execution.getActivity();
boolean isInterrupting = (Boolean) timerActivity.getProperty("isInterrupting");
List<ActivityExecution> recyclableExecutions = null;
if (isInterrupting) {
recyclableExecutions = removeAllExecutions(execution);
} else {
recyclableExecutions = Collections.EMPTY_LIST;
}
execution.takeAll(timerActivity.getOutgoingTransitions(), recyclableExecutions);
}
private List<ActivityExecution> removeAllExecutions(ActivityExecution execution) {
return null;
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import org.activiti.engine.delegate.ActivityBehavior;
import org.activiti.engine.delegate.ActivityExecution;
/**
* @author Tom Baeyens
*/
public class End implements ActivityBehavior {
public void execute(ActivityExecution execution) throws Exception {
execution.end();
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.activiti.engine.delegate.ActivityBehavior;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.impl.pvm.PvmActivity;
import org.activiti.engine.impl.pvm.PvmTransition;
import org.activiti.engine.impl.pvm.runtime.ExecutionImpl;
/**
* @author Tom Baeyens
*/
public class ParallelGateway implements ActivityBehavior {
private static Logger log = Logger.getLogger(ParallelGateway.class.getName());
public void execute(ActivityExecution execution) {
PvmActivity activity = execution.getActivity();
List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
execution.inactivate();
List<ActivityExecution> joinedExecutions = execution.findInactiveConcurrentExecutions(activity);
int nbrOfExecutionsToJoin = execution.getActivity().getIncomingTransitions().size();
int nbrOfExecutionsJoined = joinedExecutions.size();
if (nbrOfExecutionsJoined==nbrOfExecutionsToJoin) {
log.fine("parallel gateway '"+activity.getId()+"' activates: "+nbrOfExecutionsJoined+" of "+nbrOfExecutionsToJoin+" joined");
execution.takeAll(outgoingTransitions, joinedExecutions);
} else if (log.isLoggable(Level.FINE)){
log.fine("parallel gateway '"+activity.getId()+"' does not activate: "+nbrOfExecutionsJoined+" of "+nbrOfExecutionsToJoin+" joined");
}
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import java.util.List;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.SubProcessActivityBehavior;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.pvm.PvmTransition;
/**
* @author Tom Baeyens
*/
public class ReusableSubProcess implements SubProcessActivityBehavior {
PvmProcessDefinition processDefinition;
public ReusableSubProcess(PvmProcessDefinition processDefinition) {
this.processDefinition = processDefinition;
}
public void execute(ActivityExecution execution) throws Exception {
PvmProcessInstance subProcessInstance = execution.createSubProcessInstance(processDefinition);
// TODO set variables
subProcessInstance.start();
}
public void completing(DelegateExecution execution, DelegateExecution subProcessInstance) throws Exception {
// TODO extract information from the subprocess and inject it into the superprocess
}
public void completed(ActivityExecution execution) throws Exception {
List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
execution.takeAll(outgoingTransitions, null);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.delegate.SignallableActivityBehavior;
import org.activiti.engine.impl.pvm.PvmTransition;
/**
* @author Tom Baeyens
*/
public class WaitState implements SignallableActivityBehavior {
public void execute(ActivityExecution execution) throws Exception {
}
public void signal(ActivityExecution execution, String signalName, Object signalData) throws Exception {
PvmTransition transition = execution.getActivity().getOutgoingTransitions().get(0);
execution.take(transition);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import org.activiti.engine.delegate.ActivityBehavior;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.impl.pvm.PvmTransition;
/**
* @author Tom Baeyens
*/
public class While implements ActivityBehavior {
String variableName;
int from;
int to;
public While(String variableName, int from, int to) {
this.variableName = variableName;
this.from = from;
this.to = to;
}
public void execute(ActivityExecution execution) throws Exception {
PvmTransition more = execution.getActivity().findOutgoingTransition("more");
PvmTransition done = execution.getActivity().findOutgoingTransition("done");
Integer value = (Integer) execution.getVariable(variableName);
if (value==null) {
execution.setVariable(variableName, from);
execution.take(more);
} else {
value = value+1;
if (value<to) {
execution.setVariable(variableName, value);
execution.take(more);
} else {
execution.take(done);
}
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<activiti-cfg xmlns="http://activiti.org/cfg">
<database name="h2" schema-strategy="create-if-necessary">
<jdbc url="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"
driver="org.h2.Driver"
username="sa"
password="" />
</database>
<job-executor auto-activate="off" />
<mail host="localhost" port="5025" />
</activiti-cfg>
database=h2
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000
jdbc.username=sa
jdbc.password=
db.schema.strategy=create-if-necessary
job.executor.auto.activate=off
mail.smtp.host=localhost
mail.smtp.port=5025
......@@ -13,7 +13,7 @@
<bean id="config"
class="org.activiti.rest.Config"
scope="singleton">
<!-- The "engine" value must match the process.engine.name property as configured int he activiti.properties file -->
<!-- The "engine" value must match the process.engine.name property as configured int he activiti.cfg.xml file -->
<property name="engine" value="default"/>
<!-- The following ids must match the ids in the engine's database -->
<property name="adminGroupId" value="admin"/>
......
......@@ -38,7 +38,7 @@
</target>
<target name="create.activiti.prop">
<echo message="creating activiti.properties in target environment"/>
<echo message="creating activiti.cfg.xml in target environment"/>
<echo message=" basedir: ${basedir}"/>
<echo message=" database: ${database}"/>
......@@ -49,7 +49,7 @@
<echo message=" jdbc.username: ${jdbc.username}"/>
<echo message=" jdbc.password: ${jdbc.password}"/>
<propertyfile file="./target/test-classes/activiti.properties">
<propertyfile file="./target/test-classes/activiti.cfg.xml">
<entry key="database" value="${database}"/>
<entry key="jdbc.driver" value="${jdbc.driver}"/>
<entry key="jdbc.url" value="${jdbc.url}"/>
......
......@@ -53,7 +53,7 @@
</thead>
<tbody>
<row>
<entry><emphasis role="bold">h2</emphasis></entry>
<entry>h2</entry>
<entry>1.2.132</entry>
<entry></entry>
</row>
......@@ -70,13 +70,18 @@
<row>
<entry>postgresql</entry>
<entry></entry>
<entry>not yet supported (coming soon)</entry>
<entry>8.4</entry>
</row>
<row>
<entry>db2</entry>
<entry></entry>
<entry>not yet supported (coming soon)</entry>
</row>
<row>
<entry>Mssql</entry>
<entry></entry>
<entry>not yet supported (coming soon)</entry>
</row>
</tbody>
</tgroup>
</table>
......
......@@ -30,8 +30,8 @@
<listitem><para><literal>jobExecutorAutoActivate</literal> (boolean) see <xref linkend="configurationproperties"/></para> </listitem>
<listitem><para><literal>mailServerHost</literal> (String) see <xref linkend="configurationproperties"/></para> </listitem>
<listitem><para><literal>mailServerPort</literal> (String) see <xref linkend="configurationproperties"/></para> </listitem>
<listitem><para><literal>mailServerSmtpUserName</literal> (String) see <xref linkend="configurationproperties"/></para> </listitem>
<listitem><para><literal>mailServerSmtpPassword</literal> (String) see <xref linkend="configurationproperties"/></para> </listitem>
<listitem><para><literal>mailServerUsername</literal> (String) see <xref linkend="configurationproperties"/></para> </listitem>
<listitem><para><literal>mailServerPassword</literal> (String) see <xref linkend="configurationproperties"/></para> </listitem>
<listitem><para><literal>mailServerDefaultFromAddress</literal> (String) see <xref linkend="configurationproperties"/></para> </listitem>
<listitem><para><literal>jpaEntityManagerFactory</literal> (javax.persistence.EntityManagerFactory) see <xref linkend="jpaconfigurationspring"/></para> </listitem>
<listitem><para><literal>jpaHandleTransaction</literal> (boolean) see <xref linkend="jpaconfigurationspring"/></para> </listitem>
......
......@@ -1894,7 +1894,7 @@ public void testEventListenerFieldInjection() {
The Email task is implemented as a dedicated <link linkend="bpmnJavaServiceTask">Service Task</link>
and is defined by setting <emphasis>'mail'</emphasis> for the <emphasis>type</emphasis> of the service task.
<programlisting>
&lt;serviceTask id=&quot;sendMail&quot; <emphasis role="bold">activiti:type=&quot;mail&quot;</emphasis>&lt;
&lt;serviceTask id=&quot;sendMail&quot; <emphasis role="bold">activiti:type=&quot;mail&quot;</emphasis>&gt;
</programlisting>
</para>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册