diff --git a/fixflow-test/.classpath b/fixflow-test/.classpath index 0d84e3fe..0c0f6f2a 100644 --- a/fixflow-test/.classpath +++ b/fixflow-test/.classpath @@ -7,5 +7,14 @@ + + + + + + + + + diff --git a/modules/fixflow-common-servlet/src/main/java/com/founder/fix/fixflow/service/FlowIdentityService.java b/modules/fixflow-common-servlet/src/main/java/com/founder/fix/fixflow/service/FlowIdentityService.java index 02b19a43..3a083dc1 100644 --- a/modules/fixflow-common-servlet/src/main/java/com/founder/fix/fixflow/service/FlowIdentityService.java +++ b/modules/fixflow-common-servlet/src/main/java/com/founder/fix/fixflow/service/FlowIdentityService.java @@ -17,7 +17,6 @@ */ package com.founder.fix.fixflow.service; -import java.sql.Connection; import java.sql.SQLException; import java.util.Map; diff --git a/modules/fixflow-common-servlet/src/main/java/com/founder/fix/fixflow/service/impl/FlowCenterServiceImpl.java b/modules/fixflow-common-servlet/src/main/java/com/founder/fix/fixflow/service/impl/FlowCenterServiceImpl.java index 9d41356f..67d1f91d 100644 --- a/modules/fixflow-common-servlet/src/main/java/com/founder/fix/fixflow/service/impl/FlowCenterServiceImpl.java +++ b/modules/fixflow-common-servlet/src/main/java/com/founder/fix/fixflow/service/impl/FlowCenterServiceImpl.java @@ -22,7 +22,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; @@ -45,7 +44,6 @@ import com.founder.fix.fixflow.core.impl.bpmn.behavior.TaskCommandInst; import com.founder.fix.fixflow.core.impl.bpmn.behavior.UserTaskBehavior; import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; -import com.founder.fix.fixflow.core.impl.identity.GroupDefinition; import com.founder.fix.fixflow.core.impl.identity.GroupTo; import com.founder.fix.fixflow.core.impl.identity.UserTo; import com.founder.fix.fixflow.core.impl.task.QueryExpandTo; @@ -54,7 +52,6 @@ import com.founder.fix.fixflow.core.runtime.ProcessInstance; import com.founder.fix.fixflow.core.runtime.ProcessInstanceQuery; import com.founder.fix.fixflow.core.runtime.ProcessInstanceType; -import com.founder.fix.fixflow.core.task.IdentityLink; import com.founder.fix.fixflow.core.task.TaskInstance; import com.founder.fix.fixflow.core.task.TaskQuery; import com.founder.fix.fixflow.service.FlowCenterService; diff --git a/modules/fixflow-converter/src/main/java/com/founder/fix/fixflow/editor/language/json/converter/BpmnJsonConverter.java b/modules/fixflow-converter/src/main/java/com/founder/fix/fixflow/editor/language/json/converter/BpmnJsonConverter.java index d2d80fd7..05e4f6d5 100644 --- a/modules/fixflow-converter/src/main/java/com/founder/fix/fixflow/editor/language/json/converter/BpmnJsonConverter.java +++ b/modules/fixflow-converter/src/main/java/com/founder/fix/fixflow/editor/language/json/converter/BpmnJsonConverter.java @@ -234,6 +234,11 @@ public ObjectNode convertToJson(Definitions model) { propertiesNode.put(PROPERTY_NAME, mainProcess.getName()); } + String dbid = StringUtil.getString(mainProcess.eGet(FixFlowPackage.Literals.DOCUMENT_ROOT__DBID)); + if(dbid != null){ + propertiesNode.put(PROPERTY_PROCESS_DBID, dbid); + } + //fixflow扩展流程属性 String category = mainProcess.getCategory(); if(category != null){ @@ -439,6 +444,12 @@ public Definitions convertToBpmnModel(JsonNode modelNode) { BpmnModelUtil.addExtensionElement(process, FixFlowPackage.Literals.DOCUMENT_ROOT__TASK_SUBJECT, taskSubject); } + //流程分类 + JsonNode process_dbid = JsonConverterUtil.getProperty(PROPERTY_PROCESS_DBID, modelNode); + if(process_dbid != null &&!"null".equals(process_dbid.asText()) && StringUtil.isNotEmpty(process_dbid.asText())){ + BpmnModelUtil.addExtensionAttribute(process, FixFlowPackage.Literals.DOCUMENT_ROOT__DBID, process_dbid.asText()); + } + //流程分类 JsonNode processCategory = JsonConverterUtil.getProperty(PROPERTY_PROCESS_CATEGORY, modelNode); if(processCategory != null &&!"null".equals(processCategory.asText()) && StringUtil.isNotEmpty(processCategory.asText())){ diff --git a/modules/fixflow-core/src/main/java/com/founder/fix/fixflow/core/impl/persistence/definition/ProcessDefinitionPersistence.java b/modules/fixflow-core/src/main/java/com/founder/fix/fixflow/core/impl/persistence/definition/ProcessDefinitionPersistence.java index 6315f861..efdb801e 100644 --- a/modules/fixflow-core/src/main/java/com/founder/fix/fixflow/core/impl/persistence/definition/ProcessDefinitionPersistence.java +++ b/modules/fixflow-core/src/main/java/com/founder/fix/fixflow/core/impl/persistence/definition/ProcessDefinitionPersistence.java @@ -1,540 +1,541 @@ -/** - * Copyright 1996-2013 Founder International Co.,Ltd. - * - * 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 kenshin - */ -package com.founder.fix.fixflow.core.impl.persistence.definition; - -import java.io.ByteArrayInputStream; -import java.net.URL; -import java.sql.Connection; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.bpmn2.Activity; -import org.eclipse.bpmn2.BaseElement; -import org.eclipse.bpmn2.Bpmn2Package; -import org.eclipse.bpmn2.FlowElement; -import org.eclipse.bpmn2.FlowNode; -import org.eclipse.bpmn2.RootElement; -import org.eclipse.bpmn2.SubProcess; -import org.eclipse.bpmn2.di.BpmnDiPackage; -import org.eclipse.bpmn2.impl.BaseElementImpl; -import org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl; -import org.eclipse.dd.dc.DcPackage; -import org.eclipse.dd.di.DiPackage; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; - -import com.founder.fix.bpmn2extensions.fixflow.ConnectorInstance; -import com.founder.fix.bpmn2extensions.fixflow.ConnectorParameterInputs; -import com.founder.fix.bpmn2extensions.fixflow.ConnectorParameterOutputs; -import com.founder.fix.bpmn2extensions.fixflow.DataVariable; -import com.founder.fix.bpmn2extensions.fixflow.FixFlowPackage; -import com.founder.fix.fixflow.core.ProcessEngineManagement; -import com.founder.fix.fixflow.core.db.pagination.Pagination; -import com.founder.fix.fixflow.core.exception.FixFlowClassLoadingException; -import com.founder.fix.fixflow.core.exception.FixFlowException; -import com.founder.fix.fixflow.core.impl.Context; -import com.founder.fix.fixflow.core.impl.Page; -import com.founder.fix.fixflow.core.impl.ProcessDefinitionQueryImpl; -import com.founder.fix.fixflow.core.impl.bpmn.behavior.DataVariableBehavior; -import com.founder.fix.fixflow.core.impl.bpmn.behavior.DefinitionsBehavior; -import com.founder.fix.fixflow.core.impl.bpmn.behavior.ProcessDefinitionBehavior; -import com.founder.fix.fixflow.core.impl.connector.ConnectorInstanceBehavior; -import com.founder.fix.fixflow.core.impl.datavariable.DataVariableMgmtDefinition; -import com.founder.fix.fixflow.core.impl.db.PersistentObject; -import com.founder.fix.fixflow.core.impl.db.SqlCommand; -import com.founder.fix.fixflow.core.impl.event.BaseElementEventImpl; -import com.founder.fix.fixflow.core.impl.persistence.deployer.DeploymentCache; -import com.founder.fix.fixflow.core.impl.util.EMFExtensionUtil; -import com.founder.fix.fixflow.core.impl.util.QueryTableUtil; -import com.founder.fix.fixflow.core.impl.util.ReflectUtil; -import com.founder.fix.fixflow.core.impl.util.StringUtil; -import com.founder.fix.fixflow.core.internationalization.ExceptionCode; - -public class ProcessDefinitionPersistence { - - public Connection connection; - protected SqlCommand sqlCommand; - Pagination pagination = Context.getProcessEngineConfiguration().getDbConfig().getPagination(); - - public ProcessDefinitionPersistence(Connection connection) { - this.connection = connection; - // 初始化数据库操作类 - sqlCommand = new SqlCommand(connection); - } - - public void insertProcessDefinition(PersistentObject persistentObject) { - Map resourceMap = persistentObject.getPersistentState(); - // 构建查询参数 - Map objectParam = new HashMap(); - objectParam.put("PROCESS_ID", resourceMap.get("processDefinitionId")); - objectParam.put("PROCESS_NAME", resourceMap.get("processDefinitionName")); - objectParam.put("PROCESS_KEY", resourceMap.get("processDefinitionKey")); - objectParam.put("CATEGORY", resourceMap.get("category")); - objectParam.put("VERSION", resourceMap.get("version")); - objectParam.put("RESOURCE_NAME", resourceMap.get("resourceName")); - objectParam.put("DEPLOYMENT_ID", resourceMap.get("deploymentId")); - objectParam.put("DIAGRAM_RESOURCE_NAME", resourceMap.get("diagramResourceName")); - objectParam.put("RESOURCE_ID", resourceMap.get("resourceId")); - // 执行插入语句 - sqlCommand.insert("FIXFLOW_DEF_PROCESSDEFINITION", objectParam); - } - - public ProcessDefinitionBehavior selectLatestProcessDefinitionByKey(String processDefinitionKey) { - String sqlText = "select * " + "from FIXFLOW_DEF_PROCESSDEFINITION " + "where PROCESS_KEY = ? and " - + "VERSION = (select max(VERSION) from FIXFLOW_DEF_PROCESSDEFINITION where PROCESS_KEY = ?)"; - // 构建查询参数 - List objectParamWhere = new ArrayList(); - objectParamWhere.add(processDefinitionKey); - objectParamWhere.add(processDefinitionKey); - List> dataObj = sqlCommand.queryForList(sqlText, objectParamWhere); - if (dataObj == null || dataObj.size() == 0) { - return null; - } - Map dataMap = dataObj.get(0); - ProcessDefinitionBehavior processDefinitionBehavior = getProcessDefinition(dataMap); - return processDefinitionBehavior; - } - - public ProcessDefinitionBehavior selectProcessDefinitionById(String processDefinitionId) { - DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache(); - ProcessDefinitionBehavior processDefinition = deploymentCache.getProcessDefinitionCache().get(processDefinitionId); - if (processDefinition == null) { - String sqlText = "select * " + "from FIXFLOW_DEF_PROCESSDEFINITION " + "where PROCESS_ID = ?"; - // 构建查询参数 - List objectParamWhere = new ArrayList(); - objectParamWhere.add(processDefinitionId); - List> dataObj = sqlCommand.queryForList(sqlText, objectParamWhere); - if (dataObj.size() == 0) { - throw new FixFlowException("流程定义 " + processDefinitionId + " 未查询到!"); - } - Map dataMap = dataObj.get(0); - ProcessDefinitionBehavior processDefinitionBehavior = getProcessDefinition(dataMap); - return processDefinitionBehavior; - } - return processDefinition; - } - - public String selectProcessDefinitionsByQueryCriteria(String selectProcessDefinitionsByQueryCriteriaSql, ProcessDefinitionQueryImpl processDefinitionQuery, - List objectParamWhere) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " from FIXFLOW_DEF_PROCESSDEFINITION PD "; - selectProcessDefinitionsByQueryCriteriaSql += " left join FIXFLOW_DEF_DEPLOYMENT DP ON PD.DEPLOYMENT_ID = DP.ID "; - // 自定义扩展查询 - if (processDefinitionQuery.getQueryExpandTo() != null && processDefinitionQuery.getQueryExpandTo().getLeftJoinSql() != null - && !processDefinitionQuery.getQueryExpandTo().getLeftJoinSql().equals("")) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql - + processDefinitionQuery.getQueryExpandTo().getLeftJoinSql(); - } - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " WHERE 1=1"; - // 自定义扩展查询 - if (processDefinitionQuery.getQueryExpandTo() != null && processDefinitionQuery.getQueryExpandTo().getWhereSql() != null - && !processDefinitionQuery.getQueryExpandTo().getWhereSql().equals("")) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and " - + processDefinitionQuery.getQueryExpandTo().getWhereSql(); - if (processDefinitionQuery.getQueryExpandTo().getWhereSqlObj() != null && processDefinitionQuery.getQueryExpandTo().getWhereSqlObj().size() > 0) { - objectParamWhere.addAll(processDefinitionQuery.getQueryExpandTo().getWhereSqlObj()); - } - } - if (processDefinitionQuery.getId() != null) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.PROCESS_ID=? "; - objectParamWhere.add(processDefinitionQuery.getId()); - } - if (processDefinitionQuery.getKey() != null) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.PROCESS_KEY=? "; - objectParamWhere.add(processDefinitionQuery.getKey()); - } - if (processDefinitionQuery.getKeyLike() != null) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.PROCESS_KEY like '%" - + processDefinitionQuery.getKeyLike() + "%' "; - } - if (processDefinitionQuery.isLatest()) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql - + " and PD.VERSION = (select max(VERSION) from FIXFLOW_DEF_PROCESSDEFINITION where PROCESS_KEY = PD.PROCESS_KEY)"; - } - if (processDefinitionQuery.getCategory() != null) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.CATEGORY = ?"; - objectParamWhere.add(processDefinitionQuery.getCategory()); - } - if (processDefinitionQuery.getCategoryLike() != null) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.CATEGORY like '%" - + processDefinitionQuery.getCategoryLike() + "%'"; - } - if (processDefinitionQuery.getName() != null) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.PROCESS_NAME =?"; - objectParamWhere.add(processDefinitionQuery.getName()); - } - if (processDefinitionQuery.getNameLike() != null) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.PROCESS_NAME like '%" - + processDefinitionQuery.getNameLike() + "%'"; - } - if (processDefinitionQuery.getVersion() != null) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.VERSION =?"; - objectParamWhere.add(processDefinitionQuery.getVersion()); - } - if (processDefinitionQuery.getDeploymentId() != null) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.DEPLOYMENT_ID =?"; - objectParamWhere.add(processDefinitionQuery.getDeploymentId()); - } - - return selectProcessDefinitionsByQueryCriteriaSql; - } - - public List selectProcessDefinitionsByQueryCriteria(ProcessDefinitionQueryImpl processDefinitionQuery, Page page) { - List objectParamWhere = new ArrayList(); - String selectProcessDefinitionsByQueryCriteriaSql = " select " + Context.getProcessEngineConfiguration().getDbConfig().getDbSqlMap().get("topOrderBy") + " PD.* ,DP.*"; - if (processDefinitionQuery.getQueryExpandTo() != null && processDefinitionQuery.getQueryExpandTo().getFieldSql() != null - && !processDefinitionQuery.getQueryExpandTo().getFieldSql().equals("")) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " , " - + processDefinitionQuery.getQueryExpandTo().getFieldSql(); - } - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteria(selectProcessDefinitionsByQueryCriteriaSql, - processDefinitionQuery, objectParamWhere); - if (processDefinitionQuery.getOrderBy() != null) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " order by " - + processDefinitionQuery.getOrderBy().toString(); - } - String orderByString = ""; - if (processDefinitionQuery.getOrderBy() != null && page != null) { - String orderBySql = processDefinitionQuery.getOrderBy(); - String orderBySqlFin = ""; - if (orderBySql.indexOf(",") >= 0) { - String[] orderBySqlTemp = orderBySql.split(","); - for (String orderByObj : orderBySqlTemp) { - if (orderBySqlFin.equals("")) { - orderBySqlFin = orderBySqlFin + orderByObj.substring(orderByObj.indexOf(".") + 1, orderByObj.length()); - } else { - orderBySqlFin = orderBySqlFin + "," + orderByObj.substring(orderByObj.indexOf(".") + 1, orderByObj.length()); - } - } - orderByString = orderByString + " order by " + orderBySqlFin; - } else { - orderByString = orderByString + " order by " + processDefinitionQuery.getOrderBy().toString().substring(3); - } - } - if (page != null) { - selectProcessDefinitionsByQueryCriteriaSql = pagination.getPaginationSql(selectProcessDefinitionsByQueryCriteriaSql, page.getFirstResult(), - page.getMaxResults(), "*", orderByString); - } - if (processDefinitionQuery.getOrderBy() != null && page != null) { - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + orderByString; - } - List> dataObj = sqlCommand.queryForList(selectProcessDefinitionsByQueryCriteriaSql, objectParamWhere); - List processDefinitionList = new ArrayList(); - for (Map dataMap : dataObj) { - ProcessDefinitionBehavior processDefinition = getProcessDefinition(dataMap); - processDefinitionList.add(processDefinition); - } - return processDefinitionList; - } - - public long selectProcessDefinitionsCountByQueryCriteria(ProcessDefinitionQueryImpl processDefinitionQuery) { - List objectParamWhere = new ArrayList(); - String selectProcessDefinitionsByQueryCriteriaSql = " select count(*)"; - selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteria(selectProcessDefinitionsByQueryCriteriaSql, - processDefinitionQuery, objectParamWhere); - Object returnObj = sqlCommand.queryForValue(selectProcessDefinitionsByQueryCriteriaSql, objectParamWhere); - return Integer.parseInt(returnObj.toString()); - } - - private ResourceSet getResourceSet() { - ResourceSet resourceSet = new ResourceSetImpl(); - (EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE); - (EPackage.Registry.INSTANCE).put("http://www.founderfix.com/fixflow", FixFlowPackage.eINSTANCE); - (EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/DD/20100524/DI", DiPackage.eINSTANCE); - (EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/DD/20100524/DC", DcPackage.eINSTANCE); - (EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/BPMN/20100524/DI", BpmnDiPackage.eINSTANCE); - FixFlowPackage.eINSTANCE.eClass(); - FixFlowPackage xxxPackage = FixFlowPackage.eINSTANCE; - EPackage.Registry.INSTANCE.put(xxxPackage.getNsURI(), xxxPackage); - Bpmn2ResourceFactoryImpl ddd = new Bpmn2ResourceFactoryImpl(); - Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("fixflow", ddd); - resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn", ddd); - resourceSet.getPackageRegistry().put(xxxPackage.getNsURI(), xxxPackage); - Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bpmn", ddd); - return resourceSet; - } - - private ProcessDefinitionBehavior getProcessDefinition(Map processDataMap) { - String processId = StringUtil.getString(processDataMap.get("PROCESS_ID")); - String deploymentId = StringUtil.getString(processDataMap.get("DEPLOYMENT_ID")); - String resourceName = StringUtil.getString(processDataMap.get("RESOURCE_NAME")); - String processKey = StringUtil.getString(processDataMap.get("PROCESS_KEY")); - DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache(); - ProcessDefinitionBehavior processDefinition = deploymentCache.getProcessDefinitionCache().get(processId); - if (processDefinition == null) { - String sqlText = "SELECT BYTES FROM FIXFLOW_DEF_BYTEARRAY WHERE NAME=? and DEPLOYMENT_ID=?"; - // 构建查询参数 - List objectParamWhere = new ArrayList(); - objectParamWhere.add(resourceName); - objectParamWhere.add(deploymentId); - List> dataObj = sqlCommand.queryForList(sqlText, objectParamWhere); - Map dataMap = dataObj.get(0); - Object bytesObject = dataMap.get("BYTES"); - if (bytesObject != null) { - byte[] bytes = (byte[]) bytesObject; - ResourceSet resourceSet = getResourceSet(); - String fixflowFilePath = ProcessEngineManagement.getDefaultProcessEngine().getProcessEngineConfiguration().getFixFlowFilePath(); - URL url = ReflectUtil.getResource(fixflowFilePath); - if(url == null){ - throw new FixFlowClassLoadingException(ExceptionCode.CLASSLOAD_EXCEPTION_FILENOTFOUND,fixflowFilePath); - } - String filePath = url.toString(); - Resource ddddResource = null; - try { - if (!filePath.startsWith("jar")) { - filePath = java.net.URLDecoder.decode(url.getFile(),"utf-8"); - ddddResource = resourceSet.createResource(URI.createFileURI(filePath)); - } else { - ddddResource = resourceSet.createResource(URI.createURI(filePath)); - } - ddddResource.load(new ByteArrayInputStream(bytes), null); - } catch (Exception e) { - throw new FixFlowClassLoadingException(ExceptionCode.CLASSLOAD_EXCEPTION, e); - } - DefinitionsBehavior definitions = (DefinitionsBehavior) ddddResource.getContents().get(0).eContents().get(0); - definitions.setProcessId(processId); - - for (RootElement rootElement : definitions.getRootElements()) { - if (rootElement instanceof ProcessDefinitionBehavior) { - ProcessDefinitionBehavior processObj = (ProcessDefinitionBehavior) rootElement; - if (processObj.getProcessDefinitionKey().equals(processKey)) { - processDefinition = (ProcessDefinitionBehavior) rootElement; - break; - } - } - } - processDefinition.setDefinitions(definitions); - // 加载事件定义. - loadEvent(processDefinition); - // 加载数据变量 - loadVariable(processDefinition); - // 设置FlowNode元素的子流程 - loadSubProcess(processDefinition); - processDefinition.persistentInit(processDataMap); - deploymentCache.addProcessDefinition(processDefinition); - return processDefinition; - - } - return null; - } else { - return processDefinition; - } - } - - private void setSubProcess(SubProcess subProcess) { - for (FlowElement flowElement : subProcess.getFlowElements()) { - if (flowElement instanceof FlowNode) { - FlowNode flowNode = (FlowNode) flowElement; - flowNode.setSubProcess(subProcess); - if (flowElement instanceof SubProcess) { - setSubProcess(subProcess); - } - } - } - } - - private void loadSubProcess(ProcessDefinitionBehavior process) { - for (FlowElement flowElement : process.getFlowElements()) { - if (flowElement instanceof SubProcess) { - setSubProcess((SubProcess) flowElement); - } - } - } - - private void loadVariable(ProcessDefinitionBehavior process) { - process.setDataVariableMgmtDefinition(new DataVariableMgmtDefinition(process)); - addVariable(process, process, true); - for (FlowElement flowElement : process.getFlowElements()) { - if (flowElement instanceof SubProcess) { - addVariable(flowElement, process, false); - addSubProcessElement((SubProcess) flowElement, process); - } else { - addVariable(flowElement, process, false); - } - } - } - - private void addVariable(BaseElement baseElement, ProcessDefinitionBehavior process, boolean isPubilc) { - List dataVariables = EMFExtensionUtil.getDataVariables(baseElement); - if (dataVariables == null) { - return; - } - for (DataVariable dataVariable : dataVariables) { - process.getDataVariableMgmtDefinition().addDataVariableBehavior(new DataVariableBehavior(dataVariable, baseElement.getId(), isPubilc)); - } - } - - private void addSubProcessElement(SubProcess subProcess, ProcessDefinitionBehavior process) { - for (FlowElement flowElementSub : subProcess.getFlowElements()) { - if (flowElementSub instanceof SubProcess) { - addVariable(subProcess, process, false); - addSubProcessElement((SubProcess) flowElementSub, process); - } else { - addVariable(flowElementSub, process, false); - } - } - } - - private ProcessDefinitionBehavior loadEvent(ProcessDefinitionBehavior processDefinitionBehavior) { - for (FlowElement flowElement : processDefinitionBehavior.getFlowElements()) { - if (flowElement instanceof Activity) { - loadEventObj(flowElement); - } - } - loadEventObj(processDefinitionBehavior); - return processDefinitionBehavior; - } - - private void loadEventObj(BaseElement baseElement) { - BaseElementImpl baseElementImpl = (BaseElementImpl) baseElement; - if (baseElement instanceof SubProcess) { - SubProcess subProcess = (SubProcess) baseElement; - List flowElements = subProcess.getFlowElements(); - for (FlowElement flowElement : flowElements) { - if (flowElement instanceof Activity) { - loadEventObj(flowElement); - } - } - } - List connectorInstances = baseElementImpl.getConnectorInstances(); - if (connectorInstances != null) { - for (ConnectorInstance connectorInstance : connectorInstances) { - String packageNamesString = connectorInstance.getPackageName(); - String classNameString = connectorInstance.getClassName(); - String eventTypeString = connectorInstance.getEventType(); - String connectorIdString = connectorInstance.getConnectorId(); - String connectorInstanceIdString = connectorInstance.getConnectorInstanceId(); - String connectorInstanceNameString = connectorInstance.getConnectorInstanceName(); - String errorHandlingString = connectorInstance.getErrorHandling(); - String errorCodeString = connectorInstance.getErrorCode(); - boolean isTimeExecute = connectorInstance.isIsTimeExecute(); - String documentationString = connectorInstance.getDocumentation().getValue(); - String skipExpression = null; - if (connectorInstance.getSkipComment() != null) { - skipExpression = connectorInstance.getSkipComment().getExpression().getValue(); - } - String timeExpression = null; - if (connectorInstance.getTimeExpression() != null) { - timeExpression = connectorInstance.getTimeExpression().getExpression().getValue(); - } - ConnectorInstanceBehavior connectorInstanceBehavior = new ConnectorInstanceBehavior(); - connectorInstanceBehavior.setConnectorId(connectorIdString); - connectorInstanceBehavior.setConnectorInstanceId(connectorInstanceIdString); - connectorInstanceBehavior.setClassName(classNameString); - connectorInstanceBehavior.setConnectorInstanceName(connectorInstanceNameString); - connectorInstanceBehavior.setDocumentation(documentationString); - connectorInstanceBehavior.setErrorCode(errorCodeString); - connectorInstanceBehavior.setErrorHandling(errorHandlingString); - connectorInstanceBehavior.setEventType(eventTypeString); - connectorInstanceBehavior.setPackageName(packageNamesString); - connectorInstanceBehavior.setSkipExpression(skipExpression); - if (isTimeExecute) { - connectorInstanceBehavior.setTimeExecute(true); - connectorInstanceBehavior.setTimeExpression(timeExpression); - } else { - connectorInstanceBehavior.setTimeExecute(false); - } - if (baseElementImpl.getEvents().get(eventTypeString) == null) { - BaseElementEventImpl flowNodeEventImpl = new BaseElementEventImpl(eventTypeString); - flowNodeEventImpl.addConnector(connectorInstanceBehavior); - baseElementImpl.addEvent(flowNodeEventImpl); - } else { - baseElementImpl.getEvents().get(eventTypeString).addConnector(connectorInstanceBehavior); - } - List connectorParameterInputs = connectorInstance.getConnectorParameterInputs(); - connectorInstanceBehavior.getConnectorParameterInputs().clear(); - connectorInstanceBehavior.getConnectorParameterInputs().addAll(connectorParameterInputs); - List connectorParameterOutputs = connectorInstance.getConnectorParameterOutputs(); - connectorInstanceBehavior.getConnectorParameterOutputs().clear(); - connectorInstanceBehavior.getConnectorParameterOutputs().addAll(connectorParameterOutputs); - } - } - } - - public void deleteProcessDefinitionsByDeploymentId(String deploymentId) { - // 构建Where查询参数 - Object[] objectParamWhere = { deploymentId }; - sqlCommand.delete("FIXFLOW_DEF_PROCESSDEFINITION", " DEPLOYMENT_ID=?", objectParamWhere); - } - - public List> selectProcessDefinitionGroupKey() { - String sqlTextString = "select * from (select max(VERSION) as VERSION,PROCESS_KEY from FIXFLOW_DEF_PROCESSDEFINITION GROUP BY PROCESS_KEY ) t1 "+ - " left join FIXFLOW_DEF_PROCESSDEFINITION t2 on "+ - "t1.VERSION=t2.VERSION and t1.PROCESS_KEY=t2.PROCESS_KEY"; - List> listMap = sqlCommand.queryForList(sqlTextString); - return listMap; - } - - @SuppressWarnings("unchecked") - public ProcessDefinitionBehavior selectLatestProcessDefinitionByKeyAndVersion(Object parameter) { - Map parameters = (Map) parameter; - String processDefinitionKey = StringUtil.getString(parameters.get("processDefinitionKey")); - int processDefinitionVersion = StringUtil.getInt(parameters.get("processDefinitionVersion")); - String sqlText = "select * " + "from FIXFLOW_DEF_PROCESSDEFINITION " + "where PROCESS_KEY = ? AND VERSION=? "; - // 构建查询参数 - List objectParamWhere = new ArrayList(); - objectParamWhere.add(processDefinitionKey); - objectParamWhere.add(processDefinitionVersion); - List> dataObj = sqlCommand.queryForList(sqlText, objectParamWhere); - Map dataMap = dataObj.get(0); - ProcessDefinitionBehavior processDefinition = getProcessDefinition(dataMap); - return processDefinition; - } - - @SuppressWarnings("unchecked") - public Object selectProcessDefinitionByDeploymentAndKey(Object parameter) { - Map strmap = (Map) parameter; - String deploymentIdTemp = strmap.get("deploymentId"); - String processKeyTemp = strmap.get("processDefinitionKey"); - String sqlText = "select * " + "from FIXFLOW_DEF_PROCESSDEFINITION " + "where PROCESS_KEY = ? AND DEPLOYMENT_ID=? "; - // 构建查询参数 - List objectParamWhere = new ArrayList(); - objectParamWhere.add(processKeyTemp); - objectParamWhere.add(deploymentIdTemp); - List> dataObj = sqlCommand.queryForList(sqlText, objectParamWhere); - Map dataMap = dataObj.get(0); - ProcessDefinitionBehavior processDefinition = getProcessDefinition(dataMap); - - return processDefinition; - } - - public List> findUserSubmitProcess(String userId, int number) { - String sqlTextString = "select processdefinition_key from (" + "select p.processdefinition_key, max(p.start_time) start_time, p.initiator" - + " from "+ QueryTableUtil.getDefaultTableName("fixflow_run_processinstance") +" p" + " group by p.processdefinition_key, p.initiator" + " having p.initiator = ? " - + ")t order by start_time desc"; - List objectParamWhere = new ArrayList(); - objectParamWhere.add(userId); - - - sqlTextString = pagination.getPaginationSql(sqlTextString, 1,number, " processdefinition_key ", ""); - - - - sqlTextString = "SELECT * FROM (SELECT PROCESS_KEY,MAX(PROCESS_NAME) AS PROCESS_NAME,MAX(CATEGORY) AS CATEGORY ,MAX(RESOURCE_NAME) AS RESOURCE_NAME,MAX(RESOURCE_ID) AS RESOURCE_ID,"+ - "MAX(DEPLOYMENT_ID) AS DEPLOYMENT_ID,MAX(DIAGRAM_RESOURCE_NAME) AS DIAGRAM_RESOURCE_NAME ,MAX(PROCESS_ID) AS PROCESS_ID " - + "FROM FIXFLOW_DEF_PROCESSDEFINITION GROUP BY PROCESS_KEY) YY WHERE YY.PROCESS_KEY IN (SELECT JJ.* FROM ("+sqlTextString+") JJ) "; - - List> dataObj = sqlCommand.queryForList(sqlTextString, objectParamWhere); - return dataObj; - } - -} +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 kenshin + */ +package com.founder.fix.fixflow.core.impl.persistence.definition; + +import java.io.ByteArrayInputStream; +import java.net.URL; +import java.sql.Connection; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.bpmn2.Activity; +import org.eclipse.bpmn2.BaseElement; +import org.eclipse.bpmn2.Bpmn2Package; +import org.eclipse.bpmn2.FlowElement; +import org.eclipse.bpmn2.FlowNode; +import org.eclipse.bpmn2.RootElement; +import org.eclipse.bpmn2.SubProcess; +import org.eclipse.bpmn2.di.BpmnDiPackage; +import org.eclipse.bpmn2.impl.BaseElementImpl; +import org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl; +import org.eclipse.dd.dc.DcPackage; +import org.eclipse.dd.di.DiPackage; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; + +import com.founder.fix.bpmn2extensions.fixflow.ConnectorInstance; +import com.founder.fix.bpmn2extensions.fixflow.ConnectorParameterInputs; +import com.founder.fix.bpmn2extensions.fixflow.ConnectorParameterOutputs; +import com.founder.fix.bpmn2extensions.fixflow.DataVariable; +import com.founder.fix.bpmn2extensions.fixflow.FixFlowPackage; +import com.founder.fix.fixflow.core.ProcessEngineManagement; +import com.founder.fix.fixflow.core.db.pagination.Pagination; +import com.founder.fix.fixflow.core.exception.FixFlowClassLoadingException; +import com.founder.fix.fixflow.core.exception.FixFlowException; +import com.founder.fix.fixflow.core.impl.Context; +import com.founder.fix.fixflow.core.impl.Page; +import com.founder.fix.fixflow.core.impl.ProcessDefinitionQueryImpl; +import com.founder.fix.fixflow.core.impl.bpmn.behavior.DataVariableBehavior; +import com.founder.fix.fixflow.core.impl.bpmn.behavior.DefinitionsBehavior; +import com.founder.fix.fixflow.core.impl.bpmn.behavior.ProcessDefinitionBehavior; +import com.founder.fix.fixflow.core.impl.connector.ConnectorInstanceBehavior; +import com.founder.fix.fixflow.core.impl.datavariable.DataVariableMgmtDefinition; +import com.founder.fix.fixflow.core.impl.db.PersistentObject; +import com.founder.fix.fixflow.core.impl.db.SqlCommand; +import com.founder.fix.fixflow.core.impl.event.BaseElementEventImpl; +import com.founder.fix.fixflow.core.impl.persistence.deployer.DeploymentCache; +import com.founder.fix.fixflow.core.impl.util.EMFExtensionUtil; +import com.founder.fix.fixflow.core.impl.util.QueryTableUtil; +import com.founder.fix.fixflow.core.impl.util.ReflectUtil; +import com.founder.fix.fixflow.core.impl.util.StringUtil; +import com.founder.fix.fixflow.core.internationalization.ExceptionCode; + +public class ProcessDefinitionPersistence { + + public Connection connection; + protected SqlCommand sqlCommand; + Pagination pagination = Context.getProcessEngineConfiguration().getDbConfig().getPagination(); + + public ProcessDefinitionPersistence(Connection connection) { + this.connection = connection; + // 初始化数据库操作类 + sqlCommand = new SqlCommand(connection); + } + + public void insertProcessDefinition(PersistentObject persistentObject) { + Map resourceMap = persistentObject.getPersistentState(); + // 构建查询参数 + Map objectParam = new HashMap(); + objectParam.put("PROCESS_ID", resourceMap.get("processDefinitionId")); + objectParam.put("PROCESS_NAME", resourceMap.get("processDefinitionName")); + objectParam.put("PROCESS_KEY", resourceMap.get("processDefinitionKey")); + objectParam.put("CATEGORY", resourceMap.get("category")); + objectParam.put("VERSION", resourceMap.get("version")); + objectParam.put("RESOURCE_NAME", resourceMap.get("resourceName")); + objectParam.put("DEPLOYMENT_ID", resourceMap.get("deploymentId")); + objectParam.put("DIAGRAM_RESOURCE_NAME", resourceMap.get("diagramResourceName")); + objectParam.put("RESOURCE_ID", resourceMap.get("resourceId")); + // 执行插入语句 + sqlCommand.insert("FIXFLOW_DEF_PROCESSDEFINITION", objectParam); + } + + public ProcessDefinitionBehavior selectLatestProcessDefinitionByKey(String processDefinitionKey) { + String sqlText = "select * " + "from FIXFLOW_DEF_PROCESSDEFINITION " + "where PROCESS_KEY = ? and " + + "VERSION = (select max(VERSION) from FIXFLOW_DEF_PROCESSDEFINITION where PROCESS_KEY = ?)"; + // 构建查询参数 + List objectParamWhere = new ArrayList(); + objectParamWhere.add(processDefinitionKey); + objectParamWhere.add(processDefinitionKey); + List> dataObj = sqlCommand.queryForList(sqlText, objectParamWhere); + if (dataObj == null || dataObj.size() == 0) { + return null; + } + Map dataMap = dataObj.get(0); + ProcessDefinitionBehavior processDefinitionBehavior = getProcessDefinition(dataMap); + return processDefinitionBehavior; + } + + public ProcessDefinitionBehavior selectProcessDefinitionById(String processDefinitionId) { + DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache(); + ProcessDefinitionBehavior processDefinition = deploymentCache.getProcessDefinitionCache().get(processDefinitionId); + if (processDefinition == null) { + String sqlText = "select * " + "from FIXFLOW_DEF_PROCESSDEFINITION " + "where PROCESS_ID = ?"; + // 构建查询参数 + List objectParamWhere = new ArrayList(); + objectParamWhere.add(processDefinitionId); + List> dataObj = sqlCommand.queryForList(sqlText, objectParamWhere); + if (dataObj.size() == 0) { + throw new FixFlowException("流程定义 " + processDefinitionId + " 未查询到!"); + } + Map dataMap = dataObj.get(0); + ProcessDefinitionBehavior processDefinitionBehavior = getProcessDefinition(dataMap); + return processDefinitionBehavior; + } + return processDefinition; + } + + public String selectProcessDefinitionsByQueryCriteria(String selectProcessDefinitionsByQueryCriteriaSql, ProcessDefinitionQueryImpl processDefinitionQuery, + List objectParamWhere) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " from FIXFLOW_DEF_PROCESSDEFINITION PD "; + selectProcessDefinitionsByQueryCriteriaSql += " left join FIXFLOW_DEF_DEPLOYMENT DP ON PD.DEPLOYMENT_ID = DP.ID "; + // 自定义扩展查询 + if (processDefinitionQuery.getQueryExpandTo() != null && processDefinitionQuery.getQueryExpandTo().getLeftJoinSql() != null + && !processDefinitionQuery.getQueryExpandTo().getLeftJoinSql().equals("")) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + + processDefinitionQuery.getQueryExpandTo().getLeftJoinSql(); + } + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " WHERE 1=1"; + // 自定义扩展查询 + if (processDefinitionQuery.getQueryExpandTo() != null && processDefinitionQuery.getQueryExpandTo().getWhereSql() != null + && !processDefinitionQuery.getQueryExpandTo().getWhereSql().equals("")) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and " + + processDefinitionQuery.getQueryExpandTo().getWhereSql(); + if (processDefinitionQuery.getQueryExpandTo().getWhereSqlObj() != null && processDefinitionQuery.getQueryExpandTo().getWhereSqlObj().size() > 0) { + objectParamWhere.addAll(processDefinitionQuery.getQueryExpandTo().getWhereSqlObj()); + } + } + if (processDefinitionQuery.getId() != null) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.PROCESS_ID=? "; + objectParamWhere.add(processDefinitionQuery.getId()); + } + if (processDefinitionQuery.getKey() != null) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.PROCESS_KEY=? "; + objectParamWhere.add(processDefinitionQuery.getKey()); + } + if (processDefinitionQuery.getKeyLike() != null) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.PROCESS_KEY like '%" + + processDefinitionQuery.getKeyLike() + "%' "; + } + if (processDefinitionQuery.isLatest()) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + + " and PD.VERSION = (select max(VERSION) from FIXFLOW_DEF_PROCESSDEFINITION where PROCESS_KEY = PD.PROCESS_KEY)"; + } + if (processDefinitionQuery.getCategory() != null) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.CATEGORY = ?"; + objectParamWhere.add(processDefinitionQuery.getCategory()); + } + if (processDefinitionQuery.getCategoryLike() != null) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.CATEGORY like '%" + + processDefinitionQuery.getCategoryLike() + "%'"; + } + if (processDefinitionQuery.getName() != null) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.PROCESS_NAME =?"; + objectParamWhere.add(processDefinitionQuery.getName()); + } + if (processDefinitionQuery.getNameLike() != null) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.PROCESS_NAME like '%" + + processDefinitionQuery.getNameLike() + "%'"; + } + if (processDefinitionQuery.getVersion() != null) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.VERSION =?"; + objectParamWhere.add(processDefinitionQuery.getVersion()); + } + if (processDefinitionQuery.getDeploymentId() != null) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " and PD.DEPLOYMENT_ID =?"; + objectParamWhere.add(processDefinitionQuery.getDeploymentId()); + } + + return selectProcessDefinitionsByQueryCriteriaSql; + } + + public List selectProcessDefinitionsByQueryCriteria(ProcessDefinitionQueryImpl processDefinitionQuery, Page page) { + List objectParamWhere = new ArrayList(); + String selectProcessDefinitionsByQueryCriteriaSql = " select " + Context.getProcessEngineConfiguration().getDbConfig().getDbSqlMap().get("topOrderBy") + " PD.* ,DP.*"; + if (processDefinitionQuery.getQueryExpandTo() != null && processDefinitionQuery.getQueryExpandTo().getFieldSql() != null + && !processDefinitionQuery.getQueryExpandTo().getFieldSql().equals("")) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " , " + + processDefinitionQuery.getQueryExpandTo().getFieldSql(); + } + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteria(selectProcessDefinitionsByQueryCriteriaSql, + processDefinitionQuery, objectParamWhere); + if (processDefinitionQuery.getOrderBy() != null) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + " order by " + + processDefinitionQuery.getOrderBy().toString(); + } + String orderByString = ""; + if (processDefinitionQuery.getOrderBy() != null && page != null) { + String orderBySql = processDefinitionQuery.getOrderBy(); + String orderBySqlFin = ""; + if (orderBySql.indexOf(",") >= 0) { + String[] orderBySqlTemp = orderBySql.split(","); + for (String orderByObj : orderBySqlTemp) { + if (orderBySqlFin.equals("")) { + orderBySqlFin = orderBySqlFin + orderByObj.substring(orderByObj.indexOf(".") + 1, orderByObj.length()); + } else { + orderBySqlFin = orderBySqlFin + "," + orderByObj.substring(orderByObj.indexOf(".") + 1, orderByObj.length()); + } + } + orderByString = orderByString + " order by " + orderBySqlFin; + } else { + orderByString = orderByString + " order by " + processDefinitionQuery.getOrderBy().toString().substring(3); + } + } + if (page != null) { + selectProcessDefinitionsByQueryCriteriaSql = pagination.getPaginationSql(selectProcessDefinitionsByQueryCriteriaSql, page.getFirstResult(), + page.getMaxResults(), "*", orderByString); + } + if (processDefinitionQuery.getOrderBy() != null && page != null) { + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteriaSql + orderByString; + } + List> dataObj = sqlCommand.queryForList(selectProcessDefinitionsByQueryCriteriaSql, objectParamWhere); + List processDefinitionList = new ArrayList(); + for (Map dataMap : dataObj) { + ProcessDefinitionBehavior processDefinition = getProcessDefinition(dataMap); + processDefinitionList.add(processDefinition); + } + return processDefinitionList; + } + + public long selectProcessDefinitionsCountByQueryCriteria(ProcessDefinitionQueryImpl processDefinitionQuery) { + List objectParamWhere = new ArrayList(); + String selectProcessDefinitionsByQueryCriteriaSql = " select count(*)"; + selectProcessDefinitionsByQueryCriteriaSql = selectProcessDefinitionsByQueryCriteria(selectProcessDefinitionsByQueryCriteriaSql, + processDefinitionQuery, objectParamWhere); + Object returnObj = sqlCommand.queryForValue(selectProcessDefinitionsByQueryCriteriaSql, objectParamWhere); + return Integer.parseInt(returnObj.toString()); + } + + private ResourceSet getResourceSet() { + ResourceSet resourceSet = new ResourceSetImpl(); + (EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE); + (EPackage.Registry.INSTANCE).put("http://www.founderfix.com/fixflow", FixFlowPackage.eINSTANCE); + (EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/DD/20100524/DI", DiPackage.eINSTANCE); + (EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/DD/20100524/DC", DcPackage.eINSTANCE); + (EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/BPMN/20100524/DI", BpmnDiPackage.eINSTANCE); + FixFlowPackage.eINSTANCE.eClass(); + FixFlowPackage xxxPackage = FixFlowPackage.eINSTANCE; + EPackage.Registry.INSTANCE.put(xxxPackage.getNsURI(), xxxPackage); + Bpmn2ResourceFactoryImpl ddd = new Bpmn2ResourceFactoryImpl(); + Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("fixflow", ddd); + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn", ddd); + resourceSet.getPackageRegistry().put(xxxPackage.getNsURI(), xxxPackage); + Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bpmn", ddd); + return resourceSet; + } + + private ProcessDefinitionBehavior getProcessDefinition(Map processDataMap) { + String processId = StringUtil.getString(processDataMap.get("PROCESS_ID")); + String deploymentId = StringUtil.getString(processDataMap.get("DEPLOYMENT_ID")); + String resourceName = StringUtil.getString(processDataMap.get("RESOURCE_NAME")); + String processKey = StringUtil.getString(processDataMap.get("PROCESS_KEY")); + DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache(); + ProcessDefinitionBehavior processDefinition = deploymentCache.getProcessDefinitionCache().get(processId); + if (processDefinition == null) { + String sqlText = "SELECT BYTES FROM FIXFLOW_DEF_BYTEARRAY WHERE NAME=? and DEPLOYMENT_ID=?"; + // 构建查询参数 + List objectParamWhere = new ArrayList(); + objectParamWhere.add(resourceName); + objectParamWhere.add(deploymentId); + List> dataObj = sqlCommand.queryForList(sqlText, objectParamWhere); + Map dataMap = dataObj.get(0); + Object bytesObject = dataMap.get("BYTES"); + if (bytesObject != null) { + byte[] bytes = (byte[]) bytesObject; + ResourceSet resourceSet = getResourceSet(); + String fixflowFilePath = ProcessEngineManagement.getDefaultProcessEngine().getProcessEngineConfiguration().getFixFlowFilePath(); + URL url = ReflectUtil.getResource(fixflowFilePath); + if(url == null){ + throw new FixFlowClassLoadingException(ExceptionCode.CLASSLOAD_EXCEPTION_FILENOTFOUND,fixflowFilePath); + } + String filePath = url.toString(); + Resource ddddResource = null; + try { + if (!filePath.startsWith("jar")) { + filePath = java.net.URLDecoder.decode(url.getFile(),"utf-8"); + ddddResource = resourceSet.createResource(URI.createFileURI(filePath)); + } else { + ddddResource = resourceSet.createResource(URI.createURI(filePath)); + } + ddddResource.load(new ByteArrayInputStream(bytes), null); + } catch (Exception e) { + throw new FixFlowClassLoadingException(ExceptionCode.CLASSLOAD_EXCEPTION, e); + } + DefinitionsBehavior definitions = (DefinitionsBehavior) ddddResource.getContents().get(0).eContents().get(0); + definitions.setProcessId(processId); + + for (RootElement rootElement : definitions.getRootElements()) { + if (rootElement instanceof ProcessDefinitionBehavior) { + ProcessDefinitionBehavior processObj = (ProcessDefinitionBehavior) rootElement; + if (processObj.getProcessDefinitionKey().equals(processKey)) { + processDefinition = (ProcessDefinitionBehavior) rootElement; + break; + } + } + } + processDefinition.setDefinitions(definitions); + // 加载事件定义. + loadEvent(processDefinition); + // 加载数据变量 + loadVariable(processDefinition); + // 设置FlowNode元素的子流程 + loadSubProcess(processDefinition); + processDefinition.persistentInit(processDataMap); + deploymentCache.addProcessDefinition(processDefinition); + return processDefinition; + + } + return null; + } else { + return processDefinition; + } + } + + private void setSubProcess(SubProcess subProcess) { + for (FlowElement flowElement : subProcess.getFlowElements()) { + if (flowElement instanceof FlowNode) { + FlowNode flowNode = (FlowNode) flowElement; + flowNode.setSubProcess(subProcess); + if (flowElement instanceof SubProcess) { + setSubProcess(subProcess); + } + } + } + } + + private void loadSubProcess(ProcessDefinitionBehavior process) { + for (FlowElement flowElement : process.getFlowElements()) { + if (flowElement instanceof SubProcess) { + setSubProcess((SubProcess) flowElement); + } + } + } + + private void loadVariable(ProcessDefinitionBehavior process) { + process.setDataVariableMgmtDefinition(new DataVariableMgmtDefinition(process)); + addVariable(process, process, true); + for (FlowElement flowElement : process.getFlowElements()) { + if (flowElement instanceof SubProcess) { + addVariable(flowElement, process, false); + addSubProcessElement((SubProcess) flowElement, process); + } else { + addVariable(flowElement, process, false); + } + } + } + + private void addVariable(BaseElement baseElement, ProcessDefinitionBehavior process, boolean isPubilc) { + List dataVariables = EMFExtensionUtil.getDataVariables(baseElement); + if (dataVariables == null) { + return; + } + for (DataVariable dataVariable : dataVariables) { + process.getDataVariableMgmtDefinition().addDataVariableBehavior(new DataVariableBehavior(dataVariable, baseElement.getId(), isPubilc)); + } + } + + private void addSubProcessElement(SubProcess subProcess, ProcessDefinitionBehavior process) { + for (FlowElement flowElementSub : subProcess.getFlowElements()) { + if (flowElementSub instanceof SubProcess) { + addVariable(subProcess, process, false); + addSubProcessElement((SubProcess) flowElementSub, process); + } else { + addVariable(flowElementSub, process, false); + } + } + } + + private ProcessDefinitionBehavior loadEvent(ProcessDefinitionBehavior processDefinitionBehavior) { + for (FlowElement flowElement : processDefinitionBehavior.getFlowElements()) { + if (flowElement instanceof Activity) { + loadEventObj(flowElement); + } + } + loadEventObj(processDefinitionBehavior); + return processDefinitionBehavior; + } + + private void loadEventObj(BaseElement baseElement) { + BaseElementImpl baseElementImpl = (BaseElementImpl) baseElement; + if (baseElement instanceof SubProcess) { + SubProcess subProcess = (SubProcess) baseElement; + List flowElements = subProcess.getFlowElements(); + for (FlowElement flowElement : flowElements) { + if (flowElement instanceof Activity) { + loadEventObj(flowElement); + } + } + } + List connectorInstances = baseElementImpl.getConnectorInstances(); + if (connectorInstances != null) { + for (ConnectorInstance connectorInstance : connectorInstances) { + String packageNamesString = connectorInstance.getPackageName(); + String classNameString = connectorInstance.getClassName(); + String eventTypeString = connectorInstance.getEventType(); + String connectorIdString = connectorInstance.getConnectorId(); + String connectorInstanceIdString = connectorInstance.getConnectorInstanceId(); + String connectorInstanceNameString = connectorInstance.getConnectorInstanceName(); + String errorHandlingString = connectorInstance.getErrorHandling(); + String errorCodeString = connectorInstance.getErrorCode(); + boolean isTimeExecute = connectorInstance.isIsTimeExecute(); + String documentationString = connectorInstance.getDocumentation().getValue(); + String skipExpression = null; + if (connectorInstance.getSkipComment() != null) { + skipExpression = connectorInstance.getSkipComment().getExpression().getValue(); + } + String timeExpression = null; + if (connectorInstance.getTimeExpression() != null) { + timeExpression = connectorInstance.getTimeExpression().getExpression().getValue(); + } + ConnectorInstanceBehavior connectorInstanceBehavior = new ConnectorInstanceBehavior(); + connectorInstanceBehavior.setConnectorId(connectorIdString); + connectorInstanceBehavior.setConnectorInstanceId(connectorInstanceIdString); + connectorInstanceBehavior.setClassName(classNameString); + connectorInstanceBehavior.setConnectorInstanceName(connectorInstanceNameString); + connectorInstanceBehavior.setDocumentation(documentationString); + connectorInstanceBehavior.setErrorCode(errorCodeString); + connectorInstanceBehavior.setErrorHandling(errorHandlingString); + connectorInstanceBehavior.setEventType(eventTypeString); + connectorInstanceBehavior.setPackageName(packageNamesString); + connectorInstanceBehavior.setSkipExpression(skipExpression); + if (isTimeExecute) { + connectorInstanceBehavior.setTimeExecute(true); + connectorInstanceBehavior.setTimeExpression(timeExpression); + } else { + connectorInstanceBehavior.setTimeExecute(false); + } + if (baseElementImpl.getEvents().get(eventTypeString) == null) { + BaseElementEventImpl flowNodeEventImpl = new BaseElementEventImpl(eventTypeString); + flowNodeEventImpl.addConnector(connectorInstanceBehavior); + baseElementImpl.addEvent(flowNodeEventImpl); + } else { + baseElementImpl.getEvents().get(eventTypeString).addConnector(connectorInstanceBehavior); + } + List connectorParameterInputs = connectorInstance.getConnectorParameterInputs(); + connectorInstanceBehavior.getConnectorParameterInputs().clear(); + connectorInstanceBehavior.getConnectorParameterInputs().addAll(connectorParameterInputs); + List connectorParameterOutputs = connectorInstance.getConnectorParameterOutputs(); + connectorInstanceBehavior.getConnectorParameterOutputs().clear(); + connectorInstanceBehavior.getConnectorParameterOutputs().addAll(connectorParameterOutputs); + } + } + } + + public void deleteProcessDefinitionsByDeploymentId(String deploymentId) { + // 构建Where查询参数 + Object[] objectParamWhere = { deploymentId }; + sqlCommand.delete("FIXFLOW_DEF_PROCESSDEFINITION", " DEPLOYMENT_ID=?", objectParamWhere); + } + + public List> selectProcessDefinitionGroupKey() { + String sqlTextString = "select * from (select max(VERSION) as VERSION,PROCESS_KEY from FIXFLOW_DEF_PROCESSDEFINITION GROUP BY PROCESS_KEY ) t1 "+ + " left join FIXFLOW_DEF_PROCESSDEFINITION t2 on "+ + "t1.VERSION=t2.VERSION and t1.PROCESS_KEY=t2.PROCESS_KEY"; + List> listMap = sqlCommand.queryForList(sqlTextString); + return listMap; + } + + @SuppressWarnings("unchecked") + public ProcessDefinitionBehavior selectLatestProcessDefinitionByKeyAndVersion(Object parameter) { + Map parameters = (Map) parameter; + String processDefinitionKey = StringUtil.getString(parameters.get("processDefinitionKey")); + int processDefinitionVersion = StringUtil.getInt(parameters.get("processDefinitionVersion")); + String sqlText = "select * " + "from FIXFLOW_DEF_PROCESSDEFINITION " + "where PROCESS_KEY = ? AND VERSION=? "; + // 构建查询参数 + List objectParamWhere = new ArrayList(); + objectParamWhere.add(processDefinitionKey); + objectParamWhere.add(processDefinitionVersion); + List> dataObj = sqlCommand.queryForList(sqlText, objectParamWhere); + Map dataMap = dataObj.get(0); + ProcessDefinitionBehavior processDefinition = getProcessDefinition(dataMap); + return processDefinition; + } + + @SuppressWarnings("unchecked") + public Object selectProcessDefinitionByDeploymentAndKey(Object parameter) { + Map strmap = (Map) parameter; + String deploymentIdTemp = strmap.get("deploymentId"); + String processKeyTemp = strmap.get("processDefinitionKey"); + String sqlText = "select * " + "from FIXFLOW_DEF_PROCESSDEFINITION " + "where PROCESS_KEY = ? AND DEPLOYMENT_ID=? "; + // 构建查询参数 + List objectParamWhere = new ArrayList(); + objectParamWhere.add(processKeyTemp); + objectParamWhere.add(deploymentIdTemp); + List> dataObj = sqlCommand.queryForList(sqlText, objectParamWhere); + Map dataMap = dataObj.get(0); + ProcessDefinitionBehavior processDefinition = getProcessDefinition(dataMap); + + return processDefinition; + } + + public List> findUserSubmitProcess(String userId, int number) { + String order = "start_time desc"; + String sqlTextString = "select processdefinition_key from (" + "select p.processdefinition_key, max(p.start_time) start_time, p.initiator" + + " from "+ QueryTableUtil.getDefaultTableName("fixflow_run_processinstance") +" p" + " group by p.processdefinition_key, p.initiator" + " having p.initiator = ? " + + ")t"; + List objectParamWhere = new ArrayList(); + objectParamWhere.add(userId); + + + sqlTextString = pagination.getPaginationSql(sqlTextString, 1,number, " processdefinition_key ",order); + + + + sqlTextString = "SELECT * FROM (SELECT PROCESS_KEY,MAX(PROCESS_NAME) AS PROCESS_NAME,MAX(CATEGORY) AS CATEGORY ,MAX(RESOURCE_NAME) AS RESOURCE_NAME,MAX(RESOURCE_ID) AS RESOURCE_ID,"+ + "MAX(DEPLOYMENT_ID) AS DEPLOYMENT_ID,MAX(DIAGRAM_RESOURCE_NAME) AS DIAGRAM_RESOURCE_NAME ,MAX(PROCESS_ID) AS PROCESS_ID " + + "FROM FIXFLOW_DEF_PROCESSDEFINITION GROUP BY PROCESS_KEY) YY WHERE YY.PROCESS_KEY IN (SELECT JJ.* FROM ("+sqlTextString+") JJ) "; + + List> dataObj = sqlCommand.queryForList(sqlTextString, objectParamWhere); + return dataObj; + } + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/AbstractFixFlowTestCase.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/AbstractFixFlowTestCase.java new file mode 100644 index 00000000..5ac6de0a --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/AbstractFixFlowTestCase.java @@ -0,0 +1,140 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 kenshin + */ +package com.founder.fix.fixflow.test; + +import java.lang.reflect.Method; + + +import com.founder.fix.fixflow.core.FormService; +import com.founder.fix.fixflow.core.HistoryService; +import com.founder.fix.fixflow.core.IdentityService; +import com.founder.fix.fixflow.core.ModelService; +import com.founder.fix.fixflow.core.ProcessEngine; +import com.founder.fix.fixflow.core.ProcessEngineManagement; +import com.founder.fix.fixflow.core.RuntimeService; +import com.founder.fix.fixflow.core.ScheduleService; +import com.founder.fix.fixflow.core.TaskService; +import com.founder.fix.fixflow.core.exception.FixFlowException; +import com.founder.fix.fixflow.core.impl.ExternalContent; +import com.founder.fix.fixflow.core.impl.ProcessEngineConfigurationImpl; +import com.founder.fix.fixflow.core.impl.ProcessEngineImpl; +import com.founder.fix.fixflow.core.impl.identity.Authentication; +import com.founder.fix.fixflow.core.model.DeploymentBuilder; + +import junit.framework.TestCase; + +public abstract class AbstractFixFlowTestCase extends TestCase { + + public static ProcessEngine processEngine=ProcessEngineManagement.getDefaultProcessEngine(); + protected String deploymentId; + + protected ProcessEngineConfigurationImpl processEngineConfiguration; + protected ModelService modelService; + protected RuntimeService runtimeService; + protected TaskService taskService; + protected FormService formService; + protected HistoryService historyService; + protected IdentityService identityService; + protected ScheduleService scheduleService; + + + + + + protected void initializeServices() { + processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration(); + + + modelService = processEngine.getModelService(); + runtimeService = processEngine.getRuntimeService(); + taskService = processEngine.getTaskService(); + formService = processEngine.getFormService(); + historyService = processEngine.getHistoryService(); + identityService = processEngine.getIdentityService(); + scheduleService = processEngine.getScheduleService(); + } + + + + protected void initializeProcessEngine() { + + + ExternalContent externalContent=new ExternalContent(); + externalContent.setAuthenticatedUserId(Authentication.getSystemId()); + externalContent.setConnectionManagement("General"); + processEngine.setExternalContent(externalContent); + //processEngine.getProcessEngineConfiguration().setConnectionManagement("General"); + } + + public void runBare() throws Throwable { + + if (modelService == null) { + initializeProcessEngine(); + initializeServices(); + } + + try { + deploymentId = annotationDeploymentSetUp(processEngine, getClass(), getName()); + super.runBare(); + } finally { + cleanDb(); + } + + } + + protected void cleanDb() { + + processEngine.rollBackConnection(); + + processEngine.contextClose(true, true); + + } + + + public String annotationDeploymentSetUp(ProcessEngine processEngine, Class testClass, String methodName) throws Exception { + String deploymentId = null; + Method method = null; + try { + method = testClass.getDeclaredMethod(methodName, (Class[]) null); + } catch (Exception e) { + throw new FixFlowException("获取方法失败!", e); + } + Deployment deploymentAnnotation = method.getAnnotation(Deployment.class); + if (deploymentAnnotation != null) { + String[] resources = deploymentAnnotation.resources(); + if (resources.length == 0) { + return null; + } + + + DeploymentBuilder deploymentBuilder = processEngine.getModelService().createDeployment().name("测试名称"); + + for (String resource : resources) { + deploymentBuilder.addClasspathResource(resource); + } + + deploymentId = deploymentBuilder.deploy().getId(); + + // connection.close(); + // processEngine.contextClose(); + } + return deploymentId; + + } + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/Deployment.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/Deployment.java new file mode 100644 index 00000000..53bd897f --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/Deployment.java @@ -0,0 +1,29 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 kenshin + */ +package com.founder.fix.fixflow.test; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + + +@Retention(RetentionPolicy.RUNTIME) +public @interface Deployment { + + public String[] resources() default {}; + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/bpmndiagram/BPMNDiagramQueryTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/bpmndiagram/BPMNDiagramQueryTest.java new file mode 100644 index 00000000..4fc3a698 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/bpmndiagram/BPMNDiagramQueryTest.java @@ -0,0 +1,37 @@ +package com.founder.fix.fixflow.test.bpmn.bpmndiagram; + +import java.util.List; + +import org.eclipse.bpmn2.di.BPMNDiagram; + + +import com.founder.fix.fixflow.core.impl.bpmn.behavior.ProcessDefinitionBehavior; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + + +public class BPMNDiagramQueryTest extends AbstractFixFlowTestCase { + @Override + protected void setUp() throws Exception { + // 初始化测试方法 + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + // 测试完毕清理方法 + super.tearDown(); + } + + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/bpmndiagram/bpmndiagram.bpmn" }) + @SuppressWarnings("unused") + public void testProcessDefinitionQuery() { + + ProcessDefinitionBehavior processDefinition = modelService.createProcessDefinitionQuery().processDefinitionKey("bpmndiagramTest") + .singleResult(); + + List BPMNDiagramList=processDefinition.getDefinitions().getDiagrams(); + assertNotNull(processDefinition); + } + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/callactivity/CallActivityTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/callactivity/CallActivityTest.java new file mode 100644 index 00000000..fa1b5d5d --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/callactivity/CallActivityTest.java @@ -0,0 +1,172 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 demonrain + */ + +package com.founder.fix.fixflow.test.bpmn.callactivity; + +import java.util.List; + +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.model.DeploymentBuilder; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.runtime.ProcessInstanceQuery; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class CallActivityTest extends AbstractFixFlowTestCase { + + public void testCallActivity() { + DeploymentBuilder deploymentBuilder = processEngine.getModelService().createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/bpmn/callactivity/CallActivityTest.bpmn"); + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + assertNotNull(deploymentIdTemp); + //重置下流程发布,发布下一个流程 + DeploymentBuilder deploymentBuilder2 = processEngine.getModelService().createDeployment().name("测试发布"); + deploymentBuilder2.addClasspathResource("com/founder/fix/fixflow/test/bpmn/subprocess/SubProcessTest.bpmn"); + //发布 + deploymentIdTemp = deploymentBuilder2.deploy().getId(); + assertNotNull(deploymentIdTemp); + + // 启动测试流程 + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("CallActivityTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置数据变量 +// expandTaskCommand.setTransientVariables(transientVariables); + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + // 拿到流程实例ID + String mainProcessInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(mainProcessInstanceId); + //创建流程实例查询 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //拿到子流程实例 + ProcessInstance subProcessInstance = processInstanceQuery.processDefinitionKey("SubProcessTest").singleResult(); + //验证是否为设置的子流程 + assertEquals("SubProcessTest", subProcessInstance.getProcessDefinitionKey()); + //主流程的任务应该没有了,查询子流程中的任务 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(subProcessInstance.getId()).taskNotEnd().list(); + TaskInstance taskInstance = taskInstances.get(0); + //启动子流程,并且令牌停留在UserTask_1节点 + assertEquals("UserTask_1", taskInstance.getNodeId()); + + //下面是正常走SubProcess流程 + //=========================================================================== + // 创建一个启动并提交命令 + expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("SubProcessTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("submit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置任务编号 + expandTaskCommand.setTaskId(taskInstance.getId()); + //设置数据变量 +// expandTaskCommand.setTransientVariables(transientVariables); + + // 执行这个启动并提交的命令,返回启动的流程实例 + processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + // 拿到流程实例ID + String subProcessInstanceId = subProcessInstance.getId(); + // 验证是否成功启动 + assertNotNull(subProcessInstanceId); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(subProcessInstanceId).taskNotEnd().list(); + taskInstance = taskInstances.get(0); + //启动子流程,并且令牌停留在UserTask_2节点 + assertEquals("UserTask_2", taskInstance.getNodeId()); + //创建一个处理命令 + expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("SubProcessTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,通用按钮 + expandTaskCommand.setCommandType("general"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置任务ID + expandTaskCommand.setTaskId(taskInstance.getId()); + //执行处理命令 + taskService.expandTaskComplete(expandTaskCommand, null); + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(subProcessInstanceId).taskNotEnd().list(); + taskInstance = taskInstances.get(0); + //令牌停留在UserTask_3节点 + assertEquals("UserTask_3", taskInstance.getNodeId()); + //创建一个处理命令 + expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("SubProcessTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,通用按钮 + expandTaskCommand.setCommandType("general"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置任务ID + expandTaskCommand.setTaskId(taskInstance.getId()); + //执行处理命令 + taskService.expandTaskComplete(expandTaskCommand, null); + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(subProcessInstanceId).taskNotEnd().list(); + taskInstance = taskInstances.get(0); + //令牌停留在UserTask_4节点 + assertEquals("UserTask_4", taskInstance.getNodeId()); + //创建一个处理命令 + expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("SubProcessTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,通用按钮 + expandTaskCommand.setCommandType("general"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置任务ID + expandTaskCommand.setTaskId(taskInstance.getId()); + //执行处理命令 + taskService.expandTaskComplete(expandTaskCommand, null); + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(subProcessInstanceId).taskNotEnd().list(); + //全部走完,任务为空 + assertEquals(0, taskInstances.size()); + //=========================================================================== + //这个时候子流程走完会回到主流程上来 + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(mainProcessInstanceId).taskNotEnd().list(); + taskInstance = taskInstances.get(0); + //令牌停留在UserTask_2节点 + assertEquals("UserTask_2", taskInstance.getNodeId()); + } +} \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/connector/ConnectorTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/connector/ConnectorTest.java new file mode 100644 index 00000000..c8a22aa0 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/connector/ConnectorTest.java @@ -0,0 +1,146 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 demonrain + */ + +package com.founder.fix.fixflow.test.bpmn.connector; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.founder.fix.fixflow.core.impl.Context; +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.impl.command.StartProcessInstanceCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class ConnectorTest extends AbstractFixFlowTestCase { + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/connector/ConnectorTest.bpmn" }) + public void testConnector() { + // 流程数据变量 + // 瞬态 + Map transientVariables = new HashMap(); + // 持久化 + // Map Variables = new HashMap(); + + transientVariables.put("连接器跳过策略条件", false); + transientVariables.put("测试变量", "我是测试变量"); + transientVariables.put("输出变量", ""); + + // 设置流程实例参数 + StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand(); + // 设置流程ID + startProcessInstanceCommand.setProcessDefinitionKey("ConnectorTest"); + // 设置流程业务关联键 + startProcessInstanceCommand.setBusinessKey("1234567890"); + // 设置启动提交人 + startProcessInstanceCommand.setStartAuthor("1200119390"); + // 设置数据变量 + startProcessInstanceCommand.setTransientVariables(transientVariables); + + // 启动流程,只启动流程 ,流程停在第一步 + ProcessInstance processInstanceQueryTo = runtimeService.noneStartProcessInstance(startProcessInstanceCommand); + String processInstanceId = processInstanceQueryTo.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + String nodeId = taskInstance.getNodeId(); + // 验证流程实例是否在第一个节点 + assertEquals(nodeId, "UserTask_1"); + + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("ConnectorTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + processInstanceId = processInstance.getId(); + + // 验证是否成功启动 + assertNotNull(processInstanceId); + + //创建任务查询 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 验证是否成功启动 + taskInstance = taskInstances.get(0); + nodeId = taskInstance.getNodeId(); + + // 验证当前任务是否在第二个节点 + assertEquals(nodeId, "UserTask_2"); + + //如果没有跳过,测试变量的值会被赋值 + assertEquals("我是赋值后的测试变量", Context.getAbstractScriptLanguageMgmt().getVariable("测试变量")); + //验证变量是否已经赋值到输出变量 + assertEquals("我是赋值后的测试变量", Context.getAbstractScriptLanguageMgmt().getVariable("输出变量")); + //如果有跳过策略,测试变量的值应该不变 +// assertEquals("我是测试变量", Context.getAbstractScriptLanguageMgmt().getVariable("测试变量")); + //验证变量是否已经赋值到输出变量 +// assertEquals("", Context.getAbstractScriptLanguageMgmt().getVariable("输出变量")); +/* + + // 创建一个启动并提交命令 + expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("ConnectorTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("general"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + + expandTaskCommand.setTaskId(taskInstance.getId()); + + // 执行这个启动并提交的命令,返回启动的流程实例 + processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + processInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + +// assertEquals(0, taskInstances.size()); + + // 验证是否成功启动 + taskInstance = taskInstances.get(0); + + nodeId = taskInstance.getNodeId(); + // 验证当前任务是否在第二个节点 + assertEquals(nodeId, "UserTask_3");*/ + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/ComplexGatewayTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/ComplexGatewayTest.java new file mode 100644 index 00000000..b89f0f8a --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/ComplexGatewayTest.java @@ -0,0 +1,75 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 demonrain + */ + +package com.founder.fix.fixflow.test.bpmn.gateway; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class ComplexGatewayTest extends AbstractFixFlowTestCase{ + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/gateway/ComplexGatewayTest.bpmn" }) + public void testComplexGateway() { + /*ProcessDefinitionBehavior processDefinition = modelService.createProcessDefinitionQuery().processDefinitionKey("ExclusiveGatewayTest").singleResult(); + assertNotNull(processDefinition);*/ + // 数据变量 + // 瞬态 + Map transientVariables = new HashMap(); + // 持久化 + // Map Variables = new HashMap(); + transientVariables.put("条件网关条件", true); + + // 启动测试流程 + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("ComplexGatewayTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置数据变量 + expandTaskCommand.setTransientVariables(transientVariables); + + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + // 拿到流程实例ID + String processInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 由于条件不满足,不能往后走,抛出异常,没有生成任务实例 + //===================================== + //如果条件满足则产生两个任务实例,作用同包容网关 + assertEquals(2, taskInstances.size()); + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/ExclusiveGatewayTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/ExclusiveGatewayTest.java new file mode 100644 index 00000000..148831f1 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/ExclusiveGatewayTest.java @@ -0,0 +1,81 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 demonrain + */ + +package com.founder.fix.fixflow.test.bpmn.gateway; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.founder.fix.fixflow.core.impl.bpmn.behavior.ProcessDefinitionBehavior; +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.impl.command.StartProcessInstanceCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.runtime.Token; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class ExclusiveGatewayTest extends AbstractFixFlowTestCase { + + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/gateway/ExclusiveGatewayTest.bpmn" }) + public void testExclusiveGateway() { + /*ProcessDefinitionBehavior processDefinition = modelService.createProcessDefinitionQuery().processDefinitionKey("ExclusiveGatewayTest").singleResult(); + assertNotNull(processDefinition);*/ + //数据变量 + // 瞬态 + Map transientVariables = new HashMap(); + // 持久化 + // Map Variables = new HashMap(); + + transientVariables.put("金额", 700); + // 启动测试流程 + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("ExclusiveGatewayTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置数据变量 + expandTaskCommand.setTransientVariables(transientVariables); + + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + //拿到流程实例ID + String processInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //由于是排他网关,只会走后面线条中的一条,所以任务实例应该只有1个 + assertEquals(1, taskInstances.size()); + //根据设置的金额来判断走哪条路线,上面设置的是700,应该走到UserTask_3节点 + assertEquals("UserTask_3", taskInstances.get(0).getNodeId()); + + } + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/InclusiveGatewayTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/InclusiveGatewayTest.java new file mode 100644 index 00000000..fbcd40fb --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/InclusiveGatewayTest.java @@ -0,0 +1,113 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 demonrain + */ + +package com.founder.fix.fixflow.test.bpmn.gateway; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class InclusiveGatewayTest extends AbstractFixFlowTestCase{ + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/gateway/InclusiveGatewayTest.bpmn" }) + public void testInclusiveGateway() { + /*ProcessDefinitionBehavior processDefinition = modelService.createProcessDefinitionQuery().processDefinitionKey("ExclusiveGatewayTest").singleResult(); + assertNotNull(processDefinition);*/ + // 数据变量 + // 瞬态 + Map transientVariables = new HashMap(); + // 持久化 + // Map Variables = new HashMap(); + transientVariables.put("金额", 1500); + + // 启动测试流程 + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("InclusiveGatewayTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置数据变量 + expandTaskCommand.setTransientVariables(transientVariables); + + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + // 拿到流程实例ID + String processInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 由于是包容网关,设定的金额为1500,同时满足后面两个线条,会发散成两个任务,任务实例应该有2个 + assertEquals(2, taskInstances.size()); + + //定义测试通过标志 + boolean result = false; + String tmp = ""; + // 循环2个任务 + for (int i = 0; i < taskInstances.size(); i++) { + // 创建一个同意命令 + expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("InclusiveGatewayTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为通用 + expandTaskCommand.setCommandType("general"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + // 设置任务ID + expandTaskCommand.setTaskId(taskInstances.get(i).getId()); + // 执行处理命令 + taskService.expandTaskComplete(expandTaskCommand, null); + String nodeId = taskInstances.get(i).getNodeId(); + //主要验证两个任务一个为UserTask_2,另一个为UserTask_3且顺序不定 + //如果已经存在UserTask_2,则此节点应该为UserTask_3 + if("UserTask_2".equals(tmp)){ + if("UserTask_3".equals(nodeId)){ + result = true; + } + }else if("UserTask_3".equals(tmp)){ + //如果已经存在UserTask_3,则此节点应该为UserTask_2 + if("UserTask_2".equals(nodeId)){ + result = true; + } + }else{ + //如果tmp为空则表示i==0,给tmp赋值 + tmp = nodeId; + } + } + + // 走完两个任务,任务停留在UserTask_5上 + assertEquals("UserTask_5", taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0).getNodeId()); + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/ParallelGatewayTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/ParallelGatewayTest.java new file mode 100644 index 00000000..c0e45949 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/gateway/ParallelGatewayTest.java @@ -0,0 +1,104 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 demonrain + */ + +package com.founder.fix.fixflow.test.bpmn.gateway; + +import java.util.List; + +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class ParallelGatewayTest extends AbstractFixFlowTestCase { + + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/gateway/ParallelGatewayTest.bpmn" }) + public void testParallelGateway() { + /*ProcessDefinitionBehavior processDefinition = modelService.createProcessDefinitionQuery().processDefinitionKey("ExclusiveGatewayTest").singleResult(); + assertNotNull(processDefinition);*/ + // 数据变量 + // 瞬态 + // Map transientVariables = new HashMap(); + // 持久化 + // Map Variables = new HashMap(); + + // 启动测试流程 + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("ParallelGatewayTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + // 拿到流程实例ID + String processInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 由于是并行网关,会发散成两个任务,任务实例应该有2个 + assertEquals(2, taskInstances.size()); + + // 循环2个任务 + for (int i = 0; i < taskInstances.size(); i++) { + // 创建一个同意命令 + expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("ParallelGatewayTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为通用 + expandTaskCommand.setCommandType("general"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + // 设置任务ID + expandTaskCommand.setTaskId(taskInstances.get(i).getId()); + // 执行处理命令 + taskService.expandTaskComplete(expandTaskCommand, null); + + if (i == 0) { + // 第一个任务停靠在UserTask_2上 +// assertEquals("UserTask_2", taskInstances.get(i).getNodeId()); + // 第一个任务执行完,应该只剩下一个任务实例了 + assertEquals(1, taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().size()); + } + if (i == 1) { + // 第二个任务停靠在UserTask_3上 +// assertEquals("UserTask_3", taskInstances.get(i).getNodeId()); + // 第二个任务执行完,会走合并的并行网关,应该还有一个任务实例 + assertEquals(1, taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().size()); + } + } + + // 走完吧、合并的并行网关,任务停留在UserTask_4上 + assertEquals("UserTask_4", taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0).getNodeId()); + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/scripttask/ScriptTaskTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/scripttask/ScriptTaskTest.java new file mode 100644 index 00000000..bbd8c934 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/scripttask/ScriptTaskTest.java @@ -0,0 +1,82 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 demonrain + */ + +package com.founder.fix.fixflow.test.bpmn.scripttask; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class ScriptTaskTest extends AbstractFixFlowTestCase { + /** + * 测试脚本任务 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/scripttask/ScriptTaskTest.bpmn" }) + public void testMultiInstanceLoop() { + /*// 拿到流程定义 + ProcessDefinitionBehavior processDefinition = modelService.createProcessDefinitionQuery().processDefinitionKey("UserTaskTest").singleResult(); + // 测试是否为空 + assertNotNull(processDefinition);*/ + + // 流程数据变量 + // 瞬态 + Map transientVariables = new HashMap(); + // 持久化 + // Map Variables = new HashMap(); + + //打印语句变量 + transientVariables.put("打印语句", "打印语句测试");//后面给boolean值就可以 + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("ScriptTaskTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置数据变量 + expandTaskCommand.setTransientVariables(transientVariables); + + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + //拿到流程实例ID + String processInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + + // 脚本任务没有停留,流程实例应该结束,任务实例应该为0 + assertEquals(0, taskInstances.size()); + + //看打印语句是否已经打印到控制台 + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/sequenceflow/SequenceFlowTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/sequenceflow/SequenceFlowTest.java new file mode 100644 index 00000000..9744d7a8 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/sequenceflow/SequenceFlowTest.java @@ -0,0 +1,86 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 demonrain + */ + +package com.founder.fix.fixflow.test.bpmn.sequenceflow; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.founder.fix.fixflow.core.impl.bpmn.behavior.ProcessDefinitionBehavior; +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class SequenceFlowTest extends AbstractFixFlowTestCase { + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/sequenceflow/SequenceFlowTest.bpmn" }) + public void testSequenceFlow() { + // 拿到流程定义 + ProcessDefinitionBehavior processDefinition = modelService.createProcessDefinitionQuery().processDefinitionKey("SequenceFlowTest").singleResult(); + // 测试是否为空 + assertNotNull(processDefinition); + + // 流程数据变量 + // 瞬态 + Map transientVariables = new HashMap(); + // 持久化 + // Map Variables = new HashMap(); + + transientVariables.put("test", "123"); + + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("SequenceFlowTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + // 设置数据变量 + expandTaskCommand.setTransientVariables(transientVariables); + + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + // 拿到流程实例ID + String processInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //当变量是123时应该结束任务了,任务数为0 + assertEquals(0, taskInstances.size()); + + //下面是变量不为123时的判断 + // 验证是否成功启动 + // taskInstance = taskInstances.get(0); + + // nodeId = taskInstance.getNodeId(); + // 验证当前任务是否在第二个节点 + // assertEquals(nodeId, "UserTask_2"); + + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/subprocess/SubProcessTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/subprocess/SubProcessTest.java new file mode 100644 index 00000000..35741aca --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/subprocess/SubProcessTest.java @@ -0,0 +1,112 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 demonrain + */ + +package com.founder.fix.fixflow.test.bpmn.subprocess; + +import java.util.List; + +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class SubProcessTest extends AbstractFixFlowTestCase { + + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/subprocess/SubProcessTest.bpmn" }) + public void testSubProcess() { + /*ProcessDefinitionBehavior processDefinition = modelService.createProcessDefinitionQuery().processDefinitionKey("ExclusiveGatewayTest").singleResult(); + assertNotNull(processDefinition);*/ + // 数据变量 + // 瞬态 +// Map transientVariables = new HashMap(); + // 持久化 + // Map Variables = new HashMap(); + + // 启动测试流程 + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("SubProcessTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置数据变量 +// expandTaskCommand.setTransientVariables(transientVariables); + + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + // 拿到流程实例ID + String processInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + TaskInstance taskInstance = taskInstances.get(0); + //启动子流程,并且令牌停留在UserTask_2节点 + assertEquals("UserTask_2", taskInstance.getNodeId()); + + //创建一个处理命令 + expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("SubProcessTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,通用按钮 + expandTaskCommand.setCommandType("general"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置任务ID + expandTaskCommand.setTaskId(taskInstance.getId()); + //执行处理命令 + taskService.expandTaskComplete(expandTaskCommand, null); + + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + taskInstance = taskInstances.get(0); + //令牌停留在UserTask_3节点 + assertEquals("UserTask_3", taskInstance.getNodeId()); + + //创建一个处理命令 + expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("SubProcessTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,通用按钮 + expandTaskCommand.setCommandType("general"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置任务ID + expandTaskCommand.setTaskId(taskInstance.getId()); + //执行处理命令 + taskService.expandTaskComplete(expandTaskCommand, null); + + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + taskInstance = taskInstances.get(0); + //令牌停留在UserTask_4节点 + assertEquals("UserTask_4", taskInstance.getNodeId()); + } +} \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/usertask/UserTaskTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/usertask/UserTaskTest.java new file mode 100644 index 00000000..b8ba7880 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/bpmn/usertask/UserTaskTest.java @@ -0,0 +1,241 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 demonrain + */ + +package com.founder.fix.fixflow.test.bpmn.usertask; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.founder.fix.fixflow.core.impl.Context; +import com.founder.fix.fixflow.core.impl.bpmn.behavior.ProcessDefinitionBehavior; +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.impl.command.StartProcessInstanceCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class UserTaskTest extends AbstractFixFlowTestCase { + /** + * 测试多实例任务运行(会签) + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/usertask/UserTaskTest.bpmn" }) + public void testMultiInstanceLoop() { + /*// 拿到流程定义 + ProcessDefinitionBehavior processDefinition = modelService.createProcessDefinitionQuery().processDefinitionKey("UserTaskTest").singleResult(); + // 测试是否为空 + assertNotNull(processDefinition);*/ + + // 流程数据变量 + // 瞬态 + Map transientVariables = new HashMap(); + // 持久化 + // Map Variables = new HashMap(); + + // 多实例运行(会签)变量 + transientVariables.put("输入数据集", "1200119390,test01,test02".split(","));// 模拟接收三个人的数组, + transientVariables.put("输入项", "");// 把上面存人编号的数组一个个取出放在这个变量里面 + transientVariables.put("输出项", "");// 进行任务处理命令后存的值 + transientVariables.put("输出数据集", new ArrayList());// 多实例运行完毕后存放的List + //跳过策略变量 + transientVariables.put("跳过策略条件", false);//后面给boolean值就可以 + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("UserTaskTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置数据变量 + expandTaskCommand.setTransientVariables(transientVariables); + + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + //拿到流程实例ID + String processInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + + // 是否已经分成两个任务,多实例 + assertEquals(3, taskInstances.size()); + + // 循环执行多实例 + for (int i = 0; i < taskInstances.size(); i++) { + // 创建一个同意命令 + expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("UserTaskTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为通用 + expandTaskCommand.setCommandType("general"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2");// 不同意是HandleCommand_3 + // 设置任务ID + expandTaskCommand.setTaskId(taskInstances.get(i).getId()); + // 执行处理命令 + taskService.expandTaskComplete(expandTaskCommand, null); + + if (i == 0) { + // 第一次循环结束,输出项被赋值同意并且输出数据集里面有一个数据 + assertEquals("同意", Context.getAbstractScriptLanguageMgmt().getVariable("输出项")); + assertEquals(1, ((List)Context.getAbstractScriptLanguageMgmt().getVariable("输出数据集")).size()); + } + if (i == 1) { + // 第二次循环结束,输出项被赋值同意并且输出数据集里面有两个数据 + assertEquals("同意", Context.getAbstractScriptLanguageMgmt().getVariable("输出项")); + assertEquals(2, ((List)Context.getAbstractScriptLanguageMgmt().getVariable("输出数据集")).size()); + } + if (i == 2) { + // 第三次循环结束,输出项被赋值同意并且输出数据集里面有三个数据 + assertEquals("同意", Context.getAbstractScriptLanguageMgmt().getVariable("输出项")); + assertEquals(3, ((List)Context.getAbstractScriptLanguageMgmt().getVariable("输出数据集")).size()); + } + } + + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + + // 是否已经合并成一个任务 如果是不同意大于2个,就直接结束任务 +// assertEquals(0, taskInstances.size()); + + //如果走完了会合并成一个任务 + assertEquals(1, taskInstances.size()); + + //如果是同意大于2个,就走到usertask_3节点 + assertEquals("UserTask_3", taskInstances.get(0).getNodeId()); + } + + /** + * 测试任务主题 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/usertask/UserTaskTest.bpmn" }) + public void testTaskSubject() { + // 流程数据变量 + // 瞬态 + Map transientVariables = new HashMap(); + // 持久化 + // Map Variables = new HashMap(); + + // 多实例运行(会签)变量 + transientVariables.put("输入数据集", "1200119390,test01,test02".split(","));// 模拟接收三个人的数组, + transientVariables.put("输入项", "");// 把上面存人编号的数组一个个取出放在这个变量里面 + transientVariables.put("输出项", "");// 进行任务处理命令后存的值 + transientVariables.put("输出数据集", new ArrayList());// 多实例运行完毕后存放的List + //跳过策略变量 + transientVariables.put("跳过策略条件", false);//后面给boolean值就可以 + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("UserTaskTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置数据变量 + expandTaskCommand.setTransientVariables(transientVariables); + + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + //拿到流程实例ID + String processInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + + //任务主题流程默认给了人工任务测试流程,那就是人工任务测试流程 +// assertEquals("人工任务测试流程", taskInstances.get(0).getDescription()); + //如果有节点上设置的主题,那就用节点上设置的主题 + assertEquals("节点主题", taskInstances.get(0).getDescription()); + } + + /** + * 测试跳过策略 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/bpmn/usertask/UserTaskTest.bpmn" }) + public void testSkipStrategy() { + // 流程数据变量 + // 瞬态 + Map transientVariables = new HashMap(); + // 持久化 + // Map Variables = new HashMap(); + + // 多实例运行(会签)变量 + transientVariables.put("输入数据集", "1200119390,test01,test02".split(","));// 模拟接收三个人的数组, + transientVariables.put("输入项", "");// 把上面存人编号的数组一个个取出放在这个变量里面 + transientVariables.put("输出项", "");// 进行任务处理命令后存的值 + transientVariables.put("输出数据集", new ArrayList());// 多实例运行完毕后存放的List + //跳过策略变量 + transientVariables.put("跳过策略条件", true);//后面给boolean值就可以 + // 创建一个启动并提交命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + // 设置流程名 + expandTaskCommand.setProcessDefinitionKey("UserTaskTest"); + // 设置流程的业务关联键 + expandTaskCommand.setBusinessKey("1234567890"); + // 命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + // 设置提交人 + expandTaskCommand.setInitiator("1200119390"); + // 设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //设置数据变量 + expandTaskCommand.setTransientVariables(transientVariables); + + // 执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance) taskService.expandTaskComplete(expandTaskCommand, null); + //拿到流程实例ID + String processInstanceId = processInstance.getId(); + // 验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //直接跳到任务节点UserTask_4上 + assertEquals("UserTask_4", taskInstances.get(0).getNodeId()); + //查询已经完成的任务 + List taskInstances2 = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskIsEnd().list(); + for (TaskInstance taskInstance : taskInstances2) { + //循环,查询任务类型是FIXBPMTASK的 + if(taskInstance.getTaskInstanceType().toString().equals("FIXBPMTASK")) { + //查看处理命令类型是不是自动跳过 + assertEquals("skipNode", taskInstance.getCommandType()); + } + } + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/connection/ConnectionTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/connection/ConnectionTest.java new file mode 100644 index 00000000..0ca66eb4 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/connection/ConnectionTest.java @@ -0,0 +1,22 @@ +package com.founder.fix.fixflow.test.connection; + + +import com.founder.fix.fixflow.core.impl.Context; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; + + +public class ConnectionTest extends AbstractFixFlowTestCase { + + + /** + * 测试获取数据库连接 + * @throws Exception + */ + public void testConnection() throws Exception + { + assertNotNull(Context.getDbConnection()); + } + + + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/db/pagination/PaginationTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/db/pagination/PaginationTest.java new file mode 100644 index 00000000..12daddf9 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/db/pagination/PaginationTest.java @@ -0,0 +1,47 @@ +package com.founder.fix.fixflow.test.db.pagination; + +import java.util.List; +import java.util.Map; + +import com.founder.fix.fixflow.core.db.pagination.Pagination; +import com.founder.fix.fixflow.core.impl.Context; +import com.founder.fix.fixflow.core.impl.db.SqlCommand; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; + +/** + * 分页测试 + * @author kenshin + * + */ +public class PaginationTest extends AbstractFixFlowTestCase{ + + + @Override + protected void setUp() throws Exception { + + // 初始化测试方法 + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + // 测试完毕清理方法 + super.tearDown(); + + } + + public void testOraclePagination() + { + SqlCommand sqlCommand=new SqlCommand(processEngineConfiguration.createConnection()); + Pagination pagination=processEngineConfiguration.getDbConfig().getPagination(); + String runSqlString="SELECT * FROM AU_USERINFO ORDER BY SSOID"; + String paginationSqlString= pagination.getPaginationSql(runSqlString, 3, 5, "*", null); + List> dataList=sqlCommand.queryForList(paginationSqlString); + assertNotNull(dataList); + return; + + + } + + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/ProcessEngineTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/ProcessEngineTest.java new file mode 100644 index 00000000..17025936 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/ProcessEngineTest.java @@ -0,0 +1,73 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine; + + +import com.founder.fix.fixflow.core.ProcessEngine; +import com.founder.fix.fixflow.core.ProcessEngineManagement; + + +import junit.framework.TestCase; + +public class ProcessEngineTest extends TestCase { + + /** + * 根据默认配置文件创建一个processEngine + * 当是第一次获取的时候会创建一个processEngine + * 第二次的时候直接拿到创建好的processEngine + */ + public void testCreateProcessEngine() { + ProcessEngine processEngine = ProcessEngineManagement.getDefaultProcessEngine(); + assertNotNull(processEngine); + } + + /** + * 给获取来的processEngine设置一个外部内容构造器 + * 外部内容构造器中可以设置一些外部传递给流程引擎的内容 + */ + public void testCreateExternalContent() { +// // 获取一个processEngine +// ProcessEngine processEngine = ProcessEngineManagement.getDefaultProcessEngine(); +// // 创建外部内容构造器 +// ExternalContent externalContent = new ExternalContent(); +// Connection connection = null; +// try { +// connection = createConnection(); +// // 当流程引擎需要从外部传入数据库链接的时候需要在外部内容构造器中放入connection +// externalContent.setConnection(connection); +// // 设置当前的操作人 +// externalContent.setAuthenticatedUserId("admin"); +// +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// try { +// // 当操作完成之后需要在外部关闭数据库链接!流程引擎本身不负责关闭 +// connection.close(); +// } catch (SQLException e) { +// e.printStackTrace(); +// } +// } + +// assertNotNull(processEngine); +// assertNotNull(externalContent.getAuthenticatedUserId()); +// assertNotNull(externalContent.getConnection()); + } + + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/QuickStartTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/QuickStartTest.java new file mode 100644 index 00000000..18b37e26 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/QuickStartTest.java @@ -0,0 +1,155 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine.api; + +import java.util.List; + +import com.founder.fix.fixflow.core.impl.bpmn.behavior.ProcessDefinitionBehavior; +import com.founder.fix.fixflow.core.impl.bpmn.behavior.TaskCommandInst; +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.model.ProcessDefinitionQuery; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.runtime.ProcessInstanceQuery; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +/** + * 快速启动 + * 1.获取启动按钮及其表单 + * 2.获取提交表单Toolbar + * 3.处理提交表单toolbar + * 4.获取第二个任务节点的任务【查询代办任务】 + * 5.打开第二个任务节点表单 + * 6.获取第二个任务节点toolbar + * 7.完成第二个节点处理命令 + * 8.流程结束,查询流程追踪。 + * @author yangchenhui + * + */ +public class QuickStartTest extends AbstractFixFlowTestCase { + + /** + * 测试快速启动,包含流程的全部基本操作 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testQuickStart(){ + + /*********1.获取启动按钮及其表单 ***********************/ + //获取流程的启动表单 + String formUrl = formService.getStartFormByKey("TaskServiceNewTest"); + //验证表单是否为配置的“add” + assertEquals("add", formUrl); + /*********2.获取提交表单Toolbar***********************/ + List commandList = taskService.getSubTaskTaskCommandByKey("TaskServiceNewTest"); + TaskCommandInst startAndSubmitCommand = null; + for(int i = 0;i < commandList.size(); i++){ + if("startandsubmit".equals(commandList.get(i).getTaskCommandType())){ + startAndSubmitCommand = commandList.get(i); + } + } + assertNotNull(startAndSubmitCommand); + /*********3.处理提交表单toolbar***********************/ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型 + expandTaskCommand.setCommandType(startAndSubmitCommand.getTaskCommandType()); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId(startAndSubmitCommand.getId()); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + /*********4.获取第二个任务节点的任务【查询代办任务】***********************/ + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + //验证这个待办是否为空 + assertNotNull(taskInstance); + String nodeId = taskInstance.getNodeId(); + //验证流程实例是否在第二个节点 + assertEquals(nodeId, "UserTask_2"); + + /*********5.打开第二个任务节点表单***********************/ + + //获取任务节点上的formUrl + String taskFormUrl = taskInstance.getFormUri(); + //验证是否为配置的add + assertEquals("add", taskFormUrl); + + /*********6.获取第二个任务节点toolbar***********************/ + //创建流程定义查询 + ProcessDefinitionQuery processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //获取流程定义 + ProcessDefinitionBehavior processDefinition = processDefinitionQuery.processDefinitionKey("TaskServiceNewTest").singleResult(); + //获取流程定义编号 页面上用的时候应该能拿到流程定义号,就不用这样取了。 + String processDefinitionId = processDefinition.getProcessDefinitionId(); + //获取节点上的处理命令 + List taskCommandList= taskService.getTaskCommandById(processDefinitionId, nodeId); + assertNotNull(taskCommandList); + + /*********7.完成第二个节点处理命令***********************/ + TaskCommandInst generalTaskCommand = null; + for(int i = 0;i < taskCommandList.size(); i++){ + if("general".equals(taskCommandList.get(i).getTaskCommandType())){ + generalTaskCommand = taskCommandList.get(i); + } + } + assertNotNull(generalTaskCommand); + + //创建通用命令 + ExpandTaskCommand expandTaskCommandGeneral=new ExpandTaskCommand(); + //设置命令为领取任务 + expandTaskCommandGeneral.setCommandType("general"); + //设置命令的ID,需和节点上配置的按钮编号对应,会执行其中脚本 + expandTaskCommandGeneral.setUserCommandId("HandleCommand_2"); + //设置命令的处理任务号 + expandTaskCommandGeneral.setTaskId(taskInstance.getId()); + //领取任务 + taskService.expandTaskComplete(expandTaskCommandGeneral, null); + + //创建流程实例查询 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //获得上面的流程实例 + ProcessInstance process = processInstanceQuery.processInstanceId(processInstanceId).singleResult(); + //验证流程实例是否已经结束,结束说明通用按钮已经驱动流程离开当前节点。 + assertTrue(process.hasEnded()); + + /*********8.流程结束,查询流程追踪。***********************/ + + //重置任务实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询1200119390参与的流程(流程追踪) + List processInstances = processInstanceQuery.taskParticipants("1200119390").processDefinitionKey("TaskServiceNewTest").list(); + //验证是否查询正确 + assertNotNull(processInstances); + + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/model/ModelServiceTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/model/ModelServiceTest.java new file mode 100644 index 00000000..c0596acf --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/model/ModelServiceTest.java @@ -0,0 +1,526 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine.api.model; + +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipInputStream; + +import org.eclipse.bpmn2.FlowElement; + +import com.founder.fix.fixflow.core.impl.bpmn.behavior.ProcessDefinitionBehavior; +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.impl.persistence.definition.DeploymentEntity; +import com.founder.fix.fixflow.core.impl.persistence.definition.ResourceEntity; +import com.founder.fix.fixflow.core.impl.util.ReflectUtil; +import com.founder.fix.fixflow.core.model.DeploymentBuilder; +import com.founder.fix.fixflow.core.model.ProcessDefinitionQuery; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +/** + * ModelService的测试类 + */ +public class ModelServiceTest extends AbstractFixFlowTestCase { + + /** + * 测试流程定义查询 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn" }) + public void testProcessDefinitionQuery() { + //创建一个查询 + ProcessDefinitionQuery processDefinitionQuery=modelService.createProcessDefinitionQuery(); + //因为方法上面的声明会自动发布流程,所以此刻可以查到这个流程信息 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否查到此流程发布的信息 + assertNotNull(processDefinitionBehavior); + } + + /** + * 测试流程定义发布 + */ + public void testDeployProcessDefinition() { + + DeploymentBuilder deploymentBuilder = processEngine.getModelService().createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"); + //发布 + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + assertNotNull(deploymentIdTemp); + //创建一个查询 + ProcessDefinitionQuery processDefinitionQuery=modelService.createProcessDefinitionQuery(); + //查询上面发布的流程 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否发布成功 + assertNotNull(processDefinitionBehavior); + + } + /** + * 测试删除流程删除定义部署 + */ + public void testDeleteDeployment() { + + DeploymentBuilder deploymentBuilder = processEngine.getModelService().createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"); + //发布 + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + assertNotNull(deploymentIdTemp); + //创建一个流程定义查询 + ProcessDefinitionQuery processDefinitionQuery=modelService.createProcessDefinitionQuery(); + //查询上面发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + //获得刚发布的流程定义 + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证流程定义存在 + assertNotNull(processDefinitionBehavior); + //删除定义部署,并级联删除其下的所有流程定义 + modelService.deleteDeployment(deploymentIdTemp, true); + //重置流程定义查询 + processDefinitionQuery=modelService.createProcessDefinitionQuery(); + //查询上面发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + //查找刚发布的流程定义 + processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证流程定义已经被删除 + assertNull(processDefinitionBehavior); + + } + /** + * 测试检索一个指定的定义部署清单资源---方法未实现 + */ + public void testGetDeploymentResourceNames(){ + DeploymentBuilder deploymentBuilder = processEngine.getModelService().createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"); + //发布 + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + assertNotNull(deploymentIdTemp); + List list = modelService.getDeploymentResourceNames(deploymentIdTemp); + //System.out.println(list.size()+"***************"); + } + + + /** + * 获取流程图SVG格式 + */ + public void testGetFlowGraphicsSvg() { + + DeploymentBuilder deploymentBuilder = modelService.createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"); + //发布 + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + assertNotNull(deploymentIdTemp); + //创建一个流程定义查询 + ProcessDefinitionQuery processDefinitionQuery=modelService.createProcessDefinitionQuery(); + //查询刚刚发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否发布成功 + assertNotNull(processDefinitionBehavior); + + //根据流程定义唯一编号获取流程图SVG + String svgString=modelService.getFlowGraphicsSvg(processDefinitionBehavior.getProcessDefinitionId()); + //验证是否得到 + assertNotNull(svgString); + + } + /** + * 获取流程的默认表单 + */ + public void testGetDefaultFormUri(){ + DeploymentBuilder deploymentBuilder = modelService.createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"); + //发布 + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + assertNotNull(deploymentIdTemp); + //创建一个流程定义查询 + ProcessDefinitionQuery processDefinitionQuery=modelService.createProcessDefinitionQuery(); + //查询Process_TaskServiceTest的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + //获取流程定义 + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否为空 + assertNotNull(processDefinitionBehavior); + + //根据流程定义唯一编号获取流程默认的表单formUri + String formUri=modelService.getDefaultFromUri(processDefinitionBehavior.getProcessDefinitionId()); + //验证是否正确得到流程默认表单 + assertEquals("aaa.html", formUri); + } + /** + * 获取流程图IMG路径 + */ + public void testGetFlowGraphicsImgPath(){ + DeploymentBuilder deploymentBuilder = modelService.createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"); + //发布 + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + //验证是否发布成功 + assertNotNull(deploymentIdTemp); + //创建一个流程定义查询 + ProcessDefinitionQuery processDefinitionQuery=modelService.createProcessDefinitionQuery(); + //查询刚发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否得到 + assertNotNull(processDefinitionBehavior); + + //根据流程定义唯一编号获取流程图img + String imgPath=modelService.GetFlowGraphicsImgPath(processDefinitionBehavior.getProcessDefinitionId()); + //验证是否获得img的path + assertNotNull(imgPath); + } + /** + * 通过字节流访问定义部署资源。 + */ + public void testGetResourceAsStream(){ + DeploymentBuilder deploymentBuilder = modelService.createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"); + //发布 + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + //验证是否发布成功 + assertNotNull(deploymentIdTemp); + //定义一个流程定义查询 + ProcessDefinitionQuery processDefinitionQuery=modelService.createProcessDefinitionQuery(); + //查询刚发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否得到流程定义 + assertNotNull(processDefinitionBehavior); + + //定义部署资源的字节流 + ResourceEntity resourceEntity = modelService.getResourceAsStream(processDefinitionBehavior.getResourceId()); + //验证是否得到定义部署资源的字节流 + assertNotNull(resourceEntity); + } + /** + * 获取流程定义 + */ + public void testGetProcessDefinition(){ + DeploymentBuilder deploymentBuilder = modelService.createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"); + //发布 + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + //验证是否发布成功 + assertNotNull(deploymentIdTemp); + //定义一个流程定义查询 + ProcessDefinitionQuery processDefinitionQuery=modelService.createProcessDefinitionQuery(); + //查询刚发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否得到流程定义 + assertNotNull(processDefinitionBehavior); + + //根据流程定义号获得流程定义 + ProcessDefinitionBehavior processDefinitionBehavior2 = modelService.getProcessDefinition(processDefinitionBehavior.getProcessDefinitionId()); + //验证获得的流程定义正确 + assertEquals(processDefinitionBehavior, processDefinitionBehavior2); + } + /** + * 获取流程图节点信息,只包含节点,不包含线条信息 + */ + public void testGetFlowGraphicsElementPosition(){ + DeploymentBuilder deploymentBuilder = modelService.createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"); + //发布 + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + //验证是否发布成功 + assertNotNull(deploymentIdTemp); + //定义一个流程定义查询 + ProcessDefinitionQuery processDefinitionQuery=modelService.createProcessDefinitionQuery(); + //查询刚发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否得到流程定义 + assertNotNull(processDefinitionBehavior); + //获得流程图节点的位置信息 + Map> map = modelService.GetFlowGraphicsElementPosition(processDefinitionBehavior.getProcessDefinitionId()); + //验证是否含有UserTask_1,UserTask_4,EndEvent_1等节点 + assertTrue(map.containsKey("UserTask_1")); + assertTrue(map.containsKey("UserTask_4")); + assertTrue(map.containsKey("EndEvent_1")); + } + + /** + * 测试获取用户有权限启动的流程。 startProcessByUser.bpmn设置为所有人启动,StartProcessInstanceTest.bpmn设置为1035555启动,结果中应含有前者,不含有后者。 + */ + public void testGetStartProcessByUserId() { + + DeploymentBuilder deploymentBuilder = processEngine.getModelService().createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/engine/api/model/startProcessByUser.bpmn"); + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + assertNotNull(deploymentIdTemp); + //重置下流程发布,发布下一个流程 + DeploymentBuilder deploymentBuilder2 = processEngine.getModelService().createDeployment().name("测试发布"); + deploymentBuilder2.addClasspathResource("com/founder/fix/fixflow/test/engine/api/model/StartProcessInstanceTest.bpmn"); + //发布 + deploymentIdTemp = deploymentBuilder2.deploy().getId(); + assertNotNull(deploymentIdTemp); + + //取到用户可以启动的流程列表 + List> processList = modelService.getStartProcessByUserId("10691103"); + //判断含有startProcessByUser + boolean isHave = false; + //判断不含有Process_StartProcessInstanceTest + boolean isNotHave = true; + for(Map processMap :processList){ + //循环遍历取到的流程定义 + String process_key = processMap.get("processDefinitionKey"); + //如果含有startProcessByUser则测试通过 + if("startProcessByUser".equals(process_key)){ + isHave = true; + } + //如果含有Process_StartProcessInstanceTest则测试失败 + if("Process_StartProcessInstanceTest".equals(process_key)){ + isNotHave = false; + } + } + //如果含有startProcessByUser则测试通过 + assertTrue(isHave); + //如果含有Process_StartProcessInstanceTest则测试失败 + assertTrue(isNotHave); + } + + /** + * 测试通过zip文件发布流程,流程定义发布全部采用从设计器导出的.zip文件 发布.zip文件中包含xxx.bpmn、xxx.png + */ + public void testAddZipInputStream(){ + //创建一个发布 + DeploymentBuilder deploymentBuilder = processEngine.getModelService().createDeployment().name("测试名称"); + //获取zip文件的inputStream流 + InputStream inputStream = ReflectUtil.getResourceAsStream("com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest.zip"); + //发布流程定义 + deploymentBuilder.addZipInputStream(new ZipInputStream(inputStream)); + String deploymentId = deploymentBuilder.deploy().getId(); + //验证是否发布成功 + assertNotNull(deploymentId); + //创建流程定义查询 + ProcessDefinitionQuery processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询刚发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否查询到 + assertNotNull(processDefinitionBehavior); + } + + /** + * 测试获取流程图 + */ + public void testGetFlowGraphicsImgStream(){ + //创建一个发布 + DeploymentBuilder deploymentBuilder = processEngine.getModelService().createDeployment().name("测试名称"); + //获取zip文件的inputStream流 + InputStream inputStream = ReflectUtil.getResourceAsStream("com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest.zip"); + //发布流程定义 + deploymentBuilder.addZipInputStream(new ZipInputStream(inputStream)); + String deploymentId = deploymentBuilder.deploy().getId(); + //验证是否发布成功 + assertNotNull(deploymentId); + //创建流程定义查询 + ProcessDefinitionQuery processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询刚发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否查询到 + assertNotNull(processDefinitionBehavior); + + //获取流程定义编号 + String processDefinitionId = processDefinitionBehavior.getProcessDefinitionId(); + //获取流程定义key + String processDefinitionKey = processDefinitionBehavior.getProcessDefinitionKey(); + //通过流程定义编号获取流程图的文件流 + InputStream streamById = modelService.GetFlowGraphicsImgStreamByDefId(processDefinitionId); + //验证是否成功获取 + assertNotNull(streamById); + //通过流程定义key获取流程图的文件流 + InputStream streamByKey = modelService.GetFlowGraphicsImgStreamByDefKey(processDefinitionKey); + //验证是否成功获取 + assertNotNull(streamByKey); + } + + /** + * 测试通过zip文件发布流程,流程定义发布全部采用从设计器导出的.zip文件 发布.zip文件中包含xxx.bpmn、xxx.png + */ + public void testUpdateDeploymentId(){ + //创建一个发布 + DeploymentBuilder deploymentBuilder = processEngine.getModelService().createDeployment().name("测试名称"); + //获取zip文件的inputStream流 + InputStream inputStream = ReflectUtil.getResourceAsStream("com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest.zip"); + //发布流程定义 + deploymentBuilder.addZipInputStream(new ZipInputStream(inputStream)); + String deploymentId = deploymentBuilder.deploy().getId(); + //验证是否发布成功 + assertNotNull(deploymentId); + //创建流程定义查询 + ProcessDefinitionQuery processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询刚发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否查询到 + assertNotNull(processDefinitionBehavior); + + String deployId = processDefinitionBehavior.getDeploymentId(); + deploymentBuilder = processEngine.getModelService().createDeployment().name("测试名称"); + //获取zip文件的inputStream流 + inputStream = ReflectUtil.getResourceAsStream("com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest_new.zip"); + //发布流程定义 + deploymentBuilder.addZipInputStream(new ZipInputStream(inputStream)); + //设置需要更新的发布号 + deploymentBuilder.updateDeploymentId(deployId); + //更新流程定义 + deploymentId = deploymentBuilder.deploy().getId(); + //重置流程定义查询 + processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询刚发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + //获取查询到的流程定义 + processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否查询到 + assertNotNull(processDefinitionBehavior); + + //查询新的流程定义中有没有ScriptTask_1 + FlowElement flowElement = processDefinitionBehavior.getFlowElement("ScriptTask_1"); + //验证是否查询到此节点 + assertNotNull(flowElement); + + } + + /** + * 测试通过zip文件发布流程 + */ + public void testDeploymentByZip(){ + //通过zip文件的path发布流程 + String deploymentId = modelService.deploymentByZip("com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest.zip"); + assertNotNull(deploymentId); + //获取ZIP文件流 + ZipInputStream zipInputStream = new ZipInputStream(ReflectUtil.getResourceAsStream("com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest_new.zip")); + //通过zip文件流发布流程 + deploymentId = modelService.deploymentByZip(zipInputStream); + //验证是否发布成功 + assertNotNull(deploymentId); + } + + /** + * 测试通过zip文件更新流程 + */ + public void testUpdateDeploymentByZip(){ + //通过zip文件的path发布流程 + String deploymentId = modelService.deploymentByZip("com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest.zip"); + assertNotNull(deploymentId); + + //创建流程定义查询 + ProcessDefinitionQuery processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询刚发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + ProcessDefinitionBehavior processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否查询到 + assertNotNull(processDefinitionBehavior); + + String deployId = processDefinitionBehavior.getDeploymentId(); + + //更新流程定义 + deploymentId = modelService.updateDeploymentByZip("com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest_new.zip", deployId); + //重置流程定义查询 + processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询刚发布的流程定义 + processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest"); + //获取查询到的流程定义 + processDefinitionBehavior=processDefinitionQuery.singleResult(); + //验证是否查询到 + assertNotNull(processDefinitionBehavior); + + //查询新的流程定义中有没有ScriptTask_1 + FlowElement flowElement = processDefinitionBehavior.getFlowElement("ScriptTask_1"); + //验证是否查询到此节点 + assertNotNull(flowElement); + + } + + /** + * 测试获取发布实例 + */ + public void testGetDeploymentEntity(){ + //通过zip文件的path发布流程 + String deploymentId = modelService.deploymentByZip("com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest.zip"); + //验证是否发布成功 + assertNotNull(deploymentId); + //获取发布实例 + DeploymentEntity deploymentEntity = modelService.getDeploymentEntity(deploymentId); + //验证是否获取成功 + assertNotNull(deploymentEntity); + //获取发布的资源信息 + Map map = deploymentEntity.getResources(); + //验证是否获取成功 + assertNotNull(map); + //需要包含png文件和bpmn文件 + assertEquals(2, map.keySet().size()); + for(String key:map.keySet()){ + //获取资源文件 + ResourceEntity resourceEntity = map.get(key); + //验证资源文件的大字段不为空 + assertNotNull(resourceEntity.getBytes()); + } + } + /** + * 测试获取用户最近提交流程 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testGetUserSubmitProcess(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + //获取流程实例编号 + String processInstanceId = processInstance.getId(); + //获取流程定义编号 + String processDefinitionId = processInstance.getProcessDefinitionId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + //获取用户1200119390最近提交的第一个流程 + List> processDefinitonMap = modelService.getUserSubmitProcess("1200119390", 1); + //获取取到的流程定义编号 + String tmpProcessDefinitionId = processDefinitonMap.get(0).get("processDefinitionId"); + //验证是否为上面提交的定义编号 + assertEquals(processDefinitionId, tmpProcessDefinitionId); + } + +} + + diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/model/ProcessDefinitionQueryTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/model/ProcessDefinitionQueryTest.java new file mode 100644 index 00000000..84cc364a --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/model/ProcessDefinitionQueryTest.java @@ -0,0 +1,100 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine.api.model; + +import java.util.List; + +import com.founder.fix.fixflow.core.impl.bpmn.behavior.ProcessDefinitionBehavior; +import com.founder.fix.fixflow.core.model.DeploymentBuilder; +import com.founder.fix.fixflow.core.model.ProcessDefinitionQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +/** + * 流程定义查询测试类 + * @author Administrator + * + */ +public class ProcessDefinitionQueryTest extends AbstractFixFlowTestCase { + + /** + * 测试流程定义查询 + */ + public void testProcessDefinitionQuery(){ + DeploymentBuilder deploymentBuilder = processEngine.getModelService().createDeployment().name("测试名称"); + //添加你要发布的定义 + deploymentBuilder.addClasspathResource("com/founder/fix/fixflow/test/engine/api/model/startProcessByUser.bpmn"); + String deploymentIdTemp = deploymentBuilder.deploy().getId(); + assertNotNull(deploymentIdTemp); + //重置下流程发布,发布下一个流程 + DeploymentBuilder deploymentBuilder2 = processEngine.getModelService().createDeployment().name("测试发布"); + deploymentBuilder2.addClasspathResource("com/founder/fix/fixflow/test/engine/api/model/StartProcessInstanceTest.bpmn"); + //发布 + deploymentIdTemp = deploymentBuilder2.deploy().getId(); + assertNotNull(deploymentIdTemp); + + //创建流程定义查询 + ProcessDefinitionQuery processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询发布号为deploymentIdTemp的流程定义 + List processDefinitionBehaviors = processDefinitionQuery.deploymentId(deploymentIdTemp).list(); + //验证是否为1个 + assertEquals(1, processDefinitionBehaviors.size()); + + //创建流程定义查询 + processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询分类为测试流程定义分类的流程定义 + processDefinitionBehaviors = processDefinitionQuery.processDefinitionCategory("测试流程定义分类").list(); + //验证是否为1个 + assertEquals(1, processDefinitionBehaviors.size()); + + //创建流程定义查询 + processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询分类like测试流程定的流程定义 + processDefinitionBehaviors = processDefinitionQuery.processDefinitionCategoryLike("测试流程定").list(); + //验证是否为1个 + assertEquals(1, processDefinitionBehaviors.size()); + + //创建流程定义查询 + processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询startProcessByUser的版本号为1的流程定义 + processDefinitionBehaviors = processDefinitionQuery.processDefinitionKey("startProcessByUser").processDefinitionVersion(1).list(); + //验证是否为1个 + assertEquals(1, processDefinitionBehaviors.size()); + + //创建流程定义查询 + processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询流程名称等于指定启动人权限的StartProcessInstanceTest流程的流程定义 + processDefinitionBehaviors = processDefinitionQuery.processDefinitionName("指定启动人权限的StartProcessInstanceTest流程").list(); + //验证是否为1个 + assertEquals(1, processDefinitionBehaviors.size()); + + //创建流程定义查询 + processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询流程名称like StartProcessInstanceTest流程的的流程定义 + processDefinitionBehaviors = processDefinitionQuery.processDefinitionNameLike("StartProcessInstanceTest流程").list(); + //验证是否为2个 + assertEquals(2, processDefinitionBehaviors.size()); + + String processDefinitionId = processDefinitionBehaviors.get(0).getProcessDefinitionId(); + + //创建流程定义查询 + processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //查询processDefinitionId的流程定义 + processDefinitionBehaviors = processDefinitionQuery.processDefinitionId(processDefinitionId).list(); + //验证是否为1个 + assertEquals(1, processDefinitionBehaviors.size()); + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/HistoryServiceTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/HistoryServiceTest.java new file mode 100644 index 00000000..e34c7806 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/HistoryServiceTest.java @@ -0,0 +1,494 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine.api.runtime; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.runtime.ProcessInstanceQuery; +import com.founder.fix.fixflow.core.runtime.Token; +import com.founder.fix.fixflow.core.runtime.TokenQuery; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +/** + * 流程归档服务测试类 + * @author Administrator + * + */ +public class HistoryServiceTest extends AbstractFixFlowTestCase { + + /** + * 测试根据流程实例ID归档 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testArchiveByProcessInstanceId(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + //测试归档未结束的流程实例 + historyService.archiveByProcessInstanceId(processInstanceId); + + //创建流程实例查询 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询刚才启动的流程 + List processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").list(); + //验证运行表已经不存在这条流程 + assertEquals(1, processInstances.size()); + //验证归档时间为null + assertNull(processInstances.get(0).getArchiveTime()); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + //验证运行表中的归档时间不为空 + assertNull(taskInstance.getArchiveTime()); + //创建通用命令 + ExpandTaskCommand expandTaskCommandGeneral=new ExpandTaskCommand(); + //设置命令为领取任务 + expandTaskCommandGeneral.setCommandType("general"); + //设置命令的ID,需和节点上配置的按钮编号对应,会执行其中脚本 + expandTaskCommandGeneral.setUserCommandId("HandleCommand_2"); + //设置命令的处理任务号 + expandTaskCommandGeneral.setTaskId(taskInstance.getId()); + //执行通用按钮 + taskService.expandTaskComplete(expandTaskCommandGeneral, null); + + //将上面结束的流程进行归档 + historyService.archiveByProcessInstanceId(processInstanceId); + + //创建流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询刚才启动的流程 + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").list(); + //验证运行表已经不存在这条流程 + assertEquals(0, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").his().list(); + //验证历史表存在这条流程 + assertEquals(1, processInstances.size()); + //验证历史表查询出的实例归档时间不为空 + assertNotNull(processInstances.get(0).getArchiveTime()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").run().list(); + //验证运行表已经不存在这条流程 + assertEquals(0, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").run().his().list(); + //验证运行表和历史表集合中存在这条流程 + assertEquals(1, processInstances.size()); + + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询刚才流程的任务 + taskInstances = taskQuery.processDefinitionKey("TaskServiceNewTest").list(); + //验证任务已经不存在 + assertEquals(0, taskInstances.size()); + + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询归档表中的对应任务 + taskInstances = taskQuery.processDefinitionKey("TaskServiceNewTest").his().list(); + //验证归档表中可以到的任务个数不为0 + assertEquals(4, taskInstances.size()); + //验证历史表查询出来的数据归档时间不为空 + assertNotNull(taskInstances.get(0).getArchiveTime()); + + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询归档表中的对应任务 + taskInstances = taskQuery.processDefinitionKey("TaskServiceNewTest").run().list(); + //验证运行表中可以到的任务个数为0 + assertEquals(0, taskInstances.size()); + + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询归档表中的对应任务 + taskInstances = taskQuery.processDefinitionKey("TaskServiceNewTest").his().run().list(); + //验证归档表中可以到的任务个数不为0 + assertEquals(4, taskInstances.size()); + + //创建令牌查询 + TokenQuery tokenQuery = runtimeService.createTokenQuery(); + //查询run表的对应令牌 + List tokens = tokenQuery.processInstanceId(processInstanceId).list(); + //验证run表中令牌已经不存在 + assertEquals(0, tokens.size()); + + //重置令牌查询 + tokenQuery = runtimeService.createTokenQuery(); + //查his表中对应令牌 + tokens = tokenQuery.processInstanceId(processInstanceId).his().list(); + //验证令牌存在 + assertEquals(1, tokens.size()); + //验证历史表中的数据归档时间不为空 + assertNotNull(tokens.get(0).getArchiveTime()); + + //重置令牌查询 + tokenQuery = runtimeService.createTokenQuery(); + //查run表中对应令牌 + tokens = tokenQuery.processInstanceId(processInstanceId).run().list(); + //验证令牌存在 + assertEquals(0, tokens.size()); + + //重置令牌查询 + tokenQuery = runtimeService.createTokenQuery(); + //查his表和run表中对应令牌 + tokens = tokenQuery.processInstanceId(processInstanceId).his().run().list(); + //验证令牌存在 + assertEquals(1, tokens.size()); + + } + + /** + * 测试根据流程定义KEY归档 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testArchiveByProcessDefinitionKey(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + //测试归档未结束的流程实例 + historyService.archiveByProcessInstanceId(processInstanceId); + + //创建流程实例查询 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询刚才启动的流程 + List processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").list(); + //验证运行表还存在这条流程,说明未结束的流程是不会被归档的 + assertEquals(1, processInstances.size()); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + //创建通用命令 + ExpandTaskCommand expandTaskCommandGeneral=new ExpandTaskCommand(); + //设置命令为领取任务 + expandTaskCommandGeneral.setCommandType("general"); + //设置命令的ID,需和节点上配置的按钮编号对应,会执行其中脚本 + expandTaskCommandGeneral.setUserCommandId("HandleCommand_2"); + //设置命令的处理任务号 + expandTaskCommandGeneral.setTaskId(taskInstance.getId()); + //执行通用按钮 + taskService.expandTaskComplete(expandTaskCommandGeneral, null); + + //将上面结束的流程进行归档 + historyService.archiveByProcessDefinitionKey("TaskServiceNewTest"); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").his().list(); + //验证运行表已经不存在这条流程 + assertEquals(1, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").run().list(); + //验证运行表已经不存在这条流程 + assertEquals(0, processInstances.size()); + } + + /** + * 测试根据流程结束时间段归档 + * @throws InterruptedException + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testArchiveBetweenTime() throws InterruptedException{ + + Date begin = null; + Date end = null; + Date middle = null; + for(int i = 0; i<5;i++){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + //创建通用命令 + ExpandTaskCommand expandTaskCommandGeneral=new ExpandTaskCommand(); + //设置命令为领取任务 + expandTaskCommandGeneral.setCommandType("general"); + //设置命令的ID,需和节点上配置的按钮编号对应,会执行其中脚本 + expandTaskCommandGeneral.setUserCommandId("HandleCommand_2"); + //设置命令的处理任务号 + expandTaskCommandGeneral.setTaskId(taskInstance.getId()); + //执行通用按钮 + taskService.expandTaskComplete(expandTaskCommandGeneral, null); + + if(i == 1){ + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstance = processInstanceQuery.processInstanceId(processInstanceId).singleResult(); + begin = processInstance.getEndTime(); + } + + if(i == 3){ + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstance = processInstanceQuery.processInstanceId(processInstanceId).singleResult(); + middle = processInstance.getEndTime(); + } + + if(i == 4){ + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstance = processInstanceQuery.processInstanceId(processInstanceId).singleResult(); + end = processInstance.getEndTime(); + } + Thread.sleep(1000); + } + //将1和2归档 + historyService.archiveBetweenTime(null, begin); + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + List processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").list(); + //run表剩3个 + assertEquals(3, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").his().list(); + //his表剩2个 + assertEquals(2, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").his().run().list(); + //run和his表共3个 + assertEquals(5, processInstances.size()); + + //将大于5归档 + historyService.archiveBetweenTime(end, null); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").list(); + //run表剩2个 + assertEquals(2, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").his().list(); + //his表剩3个 + assertEquals(3, processInstances.size()); + + //将3、4、5归档 + historyService.archiveBetweenTime(middle, end); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").list(); + //run表剩1个 + assertEquals(1, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").his().list(); + //his表剩4个 + assertEquals(4, processInstances.size()); + } + + /** + * 测试归档已结束的全部流程 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testArchiveAll(){ + for(int i = 0; i<5;i++){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + //将4号和5号流程结束 + if(i>2){ + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + //创建通用命令 + ExpandTaskCommand expandTaskCommandGeneral=new ExpandTaskCommand(); + //设置命令为领取任务 + expandTaskCommandGeneral.setCommandType("general"); + //设置命令的ID,需和节点上配置的按钮编号对应,会执行其中脚本 + expandTaskCommandGeneral.setUserCommandId("HandleCommand_2"); + //设置命令的处理任务号 + expandTaskCommandGeneral.setTaskId(taskInstance.getId()); + //执行通用按钮 + taskService.expandTaskComplete(expandTaskCommandGeneral, null); + } + } + + //将已经结束的流程归档 + historyService.archiveAll(); + + //创建流程实例查询 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询运行表的流程实例 + List processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").list(); + //验证运行表剩3条 + assertEquals(3, processInstances.size()); + + //重置流程查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询历史表数据 + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").his().list(); + //验证历史表中有2条 + assertEquals(2, processInstances.size()); + + } + + /** + * 测试根据流程实例ID集合归档 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testArchiveByProcessInstanceIds(){ + List processInstanceIds = new ArrayList(); + for(int i = 0; i<5;i++){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + //创建通用命令 + ExpandTaskCommand expandTaskCommandGeneral=new ExpandTaskCommand(); + //设置命令为领取任务 + expandTaskCommandGeneral.setCommandType("general"); + //设置命令的ID,需和节点上配置的按钮编号对应,会执行其中脚本 + expandTaskCommandGeneral.setUserCommandId("HandleCommand_2"); + //设置命令的处理任务号 + expandTaskCommandGeneral.setTaskId(taskInstance.getId()); + //执行通用按钮 + taskService.expandTaskComplete(expandTaskCommandGeneral, null); + + //将3号和4号流程实例加入到需要归档的集合中 + if(i>2){ + processInstanceIds.add(processInstanceId); + } + } + + //将归档集合中的流程实例归档 + historyService.archiveByProcessInstanceIds(processInstanceIds); + + //创建流程实例查询 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询运行表的流程实例 + List processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").list(); + //验证运行表剩3条 + assertEquals(3, processInstances.size()); + + //重置流程查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询历史表数据 + processInstances = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").his().list(); + //验证历史表中有2条 + assertEquals(2, processInstances.size()); + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/ProcessEventTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/ProcessEventTest.java new file mode 100644 index 00000000..b8db7e5e --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/ProcessEventTest.java @@ -0,0 +1,152 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine.api.runtime; + +import java.util.List; + +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class ProcessEventTest extends AbstractFixFlowTestCase { + + /** + * 测试流程事件,在流程定义中配置连接器的各种事件。 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/processEventTest.bpmn"}) + public void testProcessEvent(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("processEventTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_processEventTest"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //获取流程变量 + Object variableValue = runtimeService.getProcessInstanceVariable(processInstanceId, "testEvent"); + //流程定义的启动事件中会将此变量设置为“启动” 详细请参考processEventTest.bpmn的流程定义 + assertEquals("启动", variableValue); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + //创建通用命令 + ExpandTaskCommand expandTaskCommandGeneral=new ExpandTaskCommand(); + //设置命令为领取任务 + expandTaskCommandGeneral.setCommandType("general"); + //设置命令的ID,需和节点上配置的按钮编号对应,会执行其中脚本 + expandTaskCommandGeneral.setUserCommandId("HandleCommand_2"); + //设置命令的处理任务号 + expandTaskCommandGeneral.setTaskId(taskInstance.getId()); + //领取任务 + taskService.expandTaskComplete(expandTaskCommandGeneral, null); + + //获取流程变量 + variableValue = runtimeService.getProcessInstanceVariable(processInstanceId, "testEvent"); + //在流程定义的结束事件中会将次变量的值设置为“结束” 详细请参考processEventTest.bpmn的流程定义 + assertEquals("结束", variableValue); + } + + /** + * 测试流程终止事件,在流程定义中配置连接器的各种事件。 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/processEventTest.bpmn"}) + public void testTermanitionEvent(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("processEventTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_processEventTest"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + + //获取testEvent变量的值 + Object variableValue = runtimeService.getProcessInstanceVariable(processInstanceId, "testEvent"); + //在此流程定义的启动事件中会将testEvent变量的值赋值为“启动”详细请参考processEventTest.bpmn的流程定义 + assertEquals("启动", variableValue); + + //终止流程 + runtimeService.terminatProcessInstance(processInstanceId); + + //获取流程变量 + variableValue = runtimeService.getProcessInstanceVariable(processInstanceId, "testEvent"); + //在此流程定义的终止事件中会将testEvent变量的值赋值为“终止”详细请参考processEventTest.bpmn的流程定义 + assertEquals("终止", variableValue); + + //创建一个通用命令 重新启动一个流程,用于测试按钮终止事件是否触发 + expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("processEventTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_processEventTest"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令 + processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + //获取流程实例编号 + processInstanceId = processInstance.getId(); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + //创建通用命令 + ExpandTaskCommand expandTaskCommandGeneral=new ExpandTaskCommand(); + //设置命令为领取任务 + expandTaskCommandGeneral.setCommandType("terminationProcess"); + //设置命令的ID,需和节点上配置的按钮编号对应,会执行其中脚本 + expandTaskCommandGeneral.setUserCommandId("HandleCommand_3"); + //设置命令的处理任务号 + expandTaskCommandGeneral.setTaskId(taskInstance.getId()); + //领取任务 + taskService.expandTaskComplete(expandTaskCommandGeneral, null); + //获取流程变量的值 + variableValue = runtimeService.getProcessInstanceVariable(processInstanceId, "testEvent"); + //在流程定义的终止事件中会将变量的值设置为“终止”详细请参考processEventTest.bpmn的流程定义 + assertEquals("终止", variableValue); + } + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/ProcessInstanceQueryTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/ProcessInstanceQueryTest.java new file mode 100644 index 00000000..9cccbf37 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/ProcessInstanceQueryTest.java @@ -0,0 +1,507 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine.api.runtime; + +import java.util.Date; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.impl.task.QueryExpandTo; +import com.founder.fix.fixflow.core.impl.util.QueryTableUtil; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.runtime.ProcessInstanceQuery; +import com.founder.fix.fixflow.core.runtime.ProcessInstanceType; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; +/** + * ProcessInstanceQuery的测试类 + */ +public class ProcessInstanceQueryTest extends AbstractFixFlowTestCase { + + /** + * 测试流程实例查询 + * @throws InterruptedException + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"}) + public void testProcessInstanceQuery() throws InterruptedException{ + + Date date = null; + for(int i = 0;i<10;i++){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("Process_TaskServiceTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + + + Map mapVariables = new HashMap(); + //设置变量,流程线条上用到,amount<300时走独占任务,否则都共享任务 + int amount = 280+i; + mapVariables.put("amount", amount); + expandTaskCommand.setTransientVariables(mapVariables); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //取得第六个流程启动时的时间,用来验证大于或小于开始时间的查询 + if(i == 6){ + date = processInstance.getStartTime(); + } + //验证是否成功启动 + assertNotNull(processInstanceId); + //暂停1000毫秒,用来验证order by + Thread.sleep(1000); + } + //流程实例查询 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //根据流程定义key查询 + List processInstances = processInstanceQuery.processDefinitionKey("Process_TaskServiceTest").list(); + //验证是10条流程实例 + assertEquals(10, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //流程实例key的集合 + List definitionKeys = new ArrayList(); + definitionKeys.add("Process_TaskServiceTest"); + //根据key的集合查询实例 + processInstances = processInstanceQuery.processDefinitionKey(definitionKeys).list(); + //验证10条查询结果 + assertEquals(10, processInstances.size()); + + //根据开始时间降序查询 + processInstanceQuery.orderByStartTime().desc(); + //获取第一页的0-5条结果 + processInstances = processInstanceQuery.listPage(1, 5); + //获取第二页5-10条结果 + List tmpProcessInstances = processInstanceQuery.listPage(6, 10); + //取得第一条结果 + Date firstStartTime = processInstances.get(0).getStartTime(); + //验证比本页所有的时间都大,表示降序排序正确 + for(int i = 1;i < processInstances.size();i++){ + Date tmpStartTime = processInstances.get(i).getStartTime(); + assertTrue(firstStartTime.after(tmpStartTime)); + } + //验证比第二页所有的时间都大,表示降序排序正确 + for(int i = 0;i list = processInstanceQuery.processDefinitionKey("TaskServiceNewTest").list(); + //验证是否为2 + assertEquals(2, list.size()); + + /**********************本例子通过扩展查询的方法获取TaskServiceNewTest流程的INSTANCE_STATUS = RUNNING的流程实例***************************/ + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //创建扩展查询 + QueryExpandTo queryExpandTo = new QueryExpandTo(); + //常见扩展查询的参数列表 + List whereSqlObj = new ArrayList(); + //添加扩展wheresql语句 (本例子扩展方法查询正在运行的流程实例) + queryExpandTo.setWhereSql("INSTANCE_STATUS = ?"); + //增加扩展wheresql的参数 + whereSqlObj.add("RUNNING"); + queryExpandTo.setWhereSqlObj(whereSqlObj); + //增加扩展查询 + processInstanceQuery.queryExpandTo(queryExpandTo); + //查询TaskServiceNewTest经过扩展查询后的结果 + processInstanceQuery.processDefinitionKey("TaskServiceNewTest"); + list = processInstanceQuery.list(); + //验证是否为1个 + assertEquals(1, list.size()); + + /**********************本例子通过扩展查询的方法获取流程定义表中的procecss_name和resource_name字段***************************/ + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //创建扩展查询 + queryExpandTo = new QueryExpandTo(); + //添加扩展的字段 + queryExpandTo.setFieldSql("fixflow_def_processdefinition.PROCESS_NAME,fixflow_def_processdefinition.RESOURCE_NAME"); + //增加扩展查询的left join语句 + queryExpandTo.setLeftJoinSql("left join fixflow_def_processdefinition on processdefinition_id = fixflow_def_processdefinition.process_id"); + //增加扩展查询 + processInstanceQuery.queryExpandTo(queryExpandTo); + //查询TaskServiceNewTest经过扩展查询后的结果 + processInstanceQuery.processDefinitionKey("TaskServiceNewTest"); + list = processInstanceQuery.list(); + //获取第一个流程实例结果 + ProcessInstance processInstance = list.get(0); + //获取扩展查询的字段 + String process_name = (String)processInstance.getExtensionField("PROCESS_NAME"); + String RESOURCE_NAME = (String)processInstance.getExtensionField("RESOURCE_NAME"); + //验证获得的扩展字段是否正确 + assertEquals("流程名称", process_name); + assertEquals("com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn", RESOURCE_NAME); + } + + /** + * 测试根据流程变量查询流程实例 + * @throws InterruptedException + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/ProcessVariablesTest.bpmn"}) + public void testProcessInstanceVariableData(){ + for(int i = 0;i<5;i++){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("ProcessVariablesTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + Map variableMap = new HashMap(); + if(i<3){ + variableMap.put("queryVariable", "查询变量1"); + }else{ + variableMap.put("queryVariable", "查询变量2"); + } + //expandTaskCommand.setVariables(variableMap); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + } + + //重置流程实例查询 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询ProcessVariablesTest查询变量值等于"查询变量"的流程实例 + List processInstances = processInstanceQuery.processDefinitionKey("ProcessVariablesTest").processInstanceVariableData("查询变量", false).list(); + //验证是否为0 + assertEquals(0, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询ProcessVariablesTest查询变量值等于"查询变量1"的流程实例 + processInstances = processInstanceQuery.processDefinitionKey("ProcessVariablesTest").processInstanceVariableData("查询变量1", false).list(); + //验证是否为5 + assertEquals(5, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询ProcessVariablesTest查询变量值 like "查询变量"的流程实例 + processInstances = processInstanceQuery.processDefinitionKey("ProcessVariablesTest").processInstanceVariableData("查询变量", true).list(); + //验证是否为5 + assertEquals(5, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询ProcessVariablesTest查询变量"queryVariable"值 like "查询变量"的流程实例 + processInstances = processInstanceQuery.processDefinitionKey("ProcessVariablesTest").processInstanceVariableData("queryVariable","查询变量1",false).list(); + //验证是否为5 + assertEquals(5, processInstances.size()); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询ProcessVariablesTest查询变量"queryVariable"值 like "查询变量"的流程实例 + processInstances = processInstanceQuery.processDefinitionKey("ProcessVariablesTest").processInstanceVariableData("queryVariable","查询变量",true).list(); + //验证是否为5 + assertEquals(5, processInstances.size()); + + /**********************本例子通过扩展查询的方法获取ProcessVariablesTest流程的查询变量queryVariable =查询变量1 的流程实例***************************/ + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //创建扩展查询 + QueryExpandTo queryExpandTo = new QueryExpandTo(); + //常见扩展查询的参数列表 + List whereSqlObj = new ArrayList(); + //添加扩展wheresql语句 (本例子扩展方法查询正在运行的流程实例) + queryExpandTo.setWhereSql("PROCESSINSTANCE_ID IN (SELECT PROCESSINSTANCE_ID FROM "+QueryTableUtil.getDefaultTableName("fixflow_run_variable")+" WHERE VARIABLE_KEY = ? AND BIZ_DATA = ?)"); + //增加扩展wheresql的参数 + whereSqlObj.add("queryVariable"); + whereSqlObj.add("查询变量1"); + queryExpandTo.setWhereSqlObj(whereSqlObj); + //增加扩展查询 + processInstanceQuery.queryExpandTo(queryExpandTo); + //查询TaskServiceNewTest经过扩展查询后的结果 + processInstanceQuery.processDefinitionKey("ProcessVariablesTest"); + processInstances = processInstanceQuery.list(); + //验证是否为5个 + assertEquals(5, processInstances.size()); + } + + + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/ProcessVariablesTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/ProcessVariablesTest.java new file mode 100644 index 00000000..56ec56c7 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/ProcessVariablesTest.java @@ -0,0 +1,98 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine.api.runtime; +import java.util.List; + +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +/** + * 流程变量测试类 + * @author Administrator + * + */ +public class ProcessVariablesTest extends AbstractFixFlowTestCase { + + /** + * 测试流程持久化变量,持久化变量是保存在数据库中,设置一次,在整个流程实例中均可使用 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/ProcessVariablesTest.bpmn"}) + public void testVariables(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("ProcessVariablesTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_ProcessVariablesTest"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + String variableValue = (String)runtimeService.getProcessInstanceVariable(processInstanceId, "variable"); + assertEquals("持久化变量", variableValue); + + } + + /** + * 测试流程瞬态变量,瞬态变量是存在线程副本里,在一个线程的生命周期内可以使用 流程排他网关设置如果瞬态变量可用则走User_Task3节点 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/ProcessVariablesTest.bpmn"}) + public void testTransientVariables(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("ProcessVariablesTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_ProcessVariablesTest"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + //验证这个待办是否为空 + assertNotNull(taskInstance); + String nodeId = taskInstance.getNodeId(); + //验证流程实例是否在第二个节点 + assertEquals(nodeId, "UserTask_3"); + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/RunTimeServiceTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/RunTimeServiceTest.java new file mode 100644 index 00000000..b19d4c3e --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/runtime/RunTimeServiceTest.java @@ -0,0 +1,296 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine.api.runtime; + +import java.util.HashMap; +import java.util.Map; + +import com.founder.fix.fixflow.core.exception.FixFlowException; +import com.founder.fix.fixflow.core.impl.command.StartProcessInstanceCommand; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.runtime.ProcessInstanceQuery; +import com.founder.fix.fixflow.core.runtime.ProcessInstanceType; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +/** + * 启动流程实例测试 + * + */ +public class RunTimeServiceTest extends AbstractFixFlowTestCase { + + public static String processDefinitionId; + /** + * 测试手工启动流程 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/StartProcessInstanceTest.bpmn" }) + public void testNoneStartProcessInstance(){ + //创建一个启动命令 + StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand(); + //设置需要启动的流程的KEY + startProcessInstanceCommand.setProcessDefinitionKey("Process_StartProcessInstanceTest"); + //设置业务关联键 + startProcessInstanceCommand.setBusinessKey("bk_StartProcessInstanceTest"); + //设置流程的启动人 + startProcessInstanceCommand.setStartAuthor("1200119390"); + //启动流程,返回流程实例 + ProcessInstance processInstance = runtimeService.noneStartProcessInstance(startProcessInstanceCommand); + //验证流程是否启动成功 + assertNotNull(processInstance); + } + /** + * 测试删除流程实例 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/StartProcessInstanceTest.bpmn" }) + public void testDeleteProcessInstance(){ + //创建一个启动命令 + StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand(); + //设置需要启动的流程的KEY + startProcessInstanceCommand.setProcessDefinitionKey("Process_StartProcessInstanceTest"); + //设置业务关联键 + startProcessInstanceCommand.setBusinessKey("bk_StartProcessInstanceTest"); + //设置流程的启动人 + startProcessInstanceCommand.setStartAuthor("1200119390"); + //启动流程,返回流程实例 + ProcessInstance processInstance = runtimeService.noneStartProcessInstance(startProcessInstanceCommand); + //验证流程是否启动成功 + assertNotNull(processInstance); + + //获得流程实例号 + String processInstanceId = processInstance.getId(); + //删除流程实例 + runtimeService.deleteProcessInstance(processInstanceId, true); + //删除后再查询此流程实例,则抛出异常,说明流程实例已经被删除 + try{ + processInstance = runtimeService.getProcessInstance(processInstanceId); + fail(); + }catch(Exception ex){ + //抛出FixFlowException异常 + assertTrue(ex instanceof FixFlowException); + } + } + + /** + * 测试获取流程实例 + */ + @SuppressWarnings("unused") + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/StartProcessInstanceTest.bpmn" }) + public void testGetProcessInstance(){ + try{ + //传一个不存的流程实例ID,则会抛出FixFlowException异常 + ProcessInstance processInstance = runtimeService.getProcessInstance("anbccbdbbddcdd"); + fail(); + }catch(Exception ex){ + //抛出FixFlowException异常 + assertTrue(ex instanceof FixFlowException); + } + + //创建一个启动命令 + StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand(); + //设置需要启动的流程的KEY + startProcessInstanceCommand.setProcessDefinitionKey("Process_StartProcessInstanceTest"); + //设置业务关联键 + startProcessInstanceCommand.setBusinessKey("bk_StartProcessInstanceTest"); + //设置流程的启动人 + startProcessInstanceCommand.setStartAuthor("1200119390"); + //启动流程,返回流程实例 + ProcessInstance processInstance = runtimeService.noneStartProcessInstance(startProcessInstanceCommand); + //验证流程是否启动成功 + assertNotNull(processInstance); + + //获得流程实例号 + String processInstanceId = processInstance.getId(); + //根据实例号查询到此流程实例 + processInstance=runtimeService.getProcessInstance(processInstanceId); + //验证是否查询到此流程实例 + assertNotNull(processInstance); + } + + /** + * 测试创建流程查询实例 + */ + public void testCreateProcessInstanceQuery(){ + //创建查询实例 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //验证是否创建成功 + assertNotNull(processInstanceQuery); + } + /** + * 测试更新流程关联键,----此方法暂未实现 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/StartProcessInstanceTest.bpmn" }) + public void testUpdateProcessInstanceBusinessKey(){ + //创建一个启动命令 + StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand(); + //设置需要启动的流程的KEY + startProcessInstanceCommand.setProcessDefinitionKey("Process_StartProcessInstanceTest"); + //设置业务关联键 + startProcessInstanceCommand.setBusinessKey("bk_StartProcessInstanceTest"); + //设置流程的启动人 + startProcessInstanceCommand.setStartAuthor("1200119390"); + //启动流程,返回流程实例 + ProcessInstance processInstance = runtimeService.noneStartProcessInstance(startProcessInstanceCommand); + //验证流程是否启动成功 + assertNotNull(processInstance); + + //获得流程实例号 + String processInstanceId = processInstance.getId(); + //将此流程实例的业务关联键更新为"bk_newbk"此方法暂未实现 + runtimeService.updateProcessInstanceBusinessKey(processInstanceId, "bk_newbk"); + processInstance = runtimeService.getProcessInstance(processInstanceId); + //此方法暂未实现 + //assertEquals(processInstance.getBizKey(), "bk_newbk"); + } + /** + * 测试增加流程实例持久化变量 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/StartProcessInstanceTest.bpmn" }) + public void testSetAndGetProcessInstanceVariable(){ + //创建一个启动命令 + StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand(); + //设置需要启动的流程的KEY + startProcessInstanceCommand.setProcessDefinitionKey("Process_StartProcessInstanceTest"); + //设置业务关联键 + startProcessInstanceCommand.setBusinessKey("bk_StartProcessInstanceTest"); + //设置流程的启动人 + startProcessInstanceCommand.setStartAuthor("1200119390"); + //启动流程,返回流程实例 + ProcessInstance processInstance = runtimeService.noneStartProcessInstance(startProcessInstanceCommand); + //验证流程是否启动成功 + assertNotNull(processInstance); + + //获得流程实例号 + String processInstanceId = processInstance.getId(); + //给流程实例添加一个名为“流程变量名称”值为“测试流程变量值” + runtimeService.setProcessInstanceVariable(processInstanceId, "流程变量名称", "测试流程变量值"); + //获取“流程变量名称”这个持久化变量的值 + String returnValue = (String)runtimeService.getProcessInstanceVariable(processInstanceId, "流程变量名称"); + //验证是否是刚添加的值 + assertEquals("测试流程变量值", returnValue); + } + + /** + * 测试增加流程实例持久化变量map + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/StartProcessInstanceTest.bpmn" }) + public void testSetAndGetProcessInstanceVariables(){ + //创建一个启动命令 + StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand(); + //设置需要启动的流程的KEY + startProcessInstanceCommand.setProcessDefinitionKey("Process_StartProcessInstanceTest"); + //设置业务关联键 + startProcessInstanceCommand.setBusinessKey("bk_StartProcessInstanceTest"); + //设置流程的启动人 + startProcessInstanceCommand.setStartAuthor("1200119390"); + //启动流程,返回流程实例 + ProcessInstance processInstance = runtimeService.noneStartProcessInstance(startProcessInstanceCommand); + //验证流程是否启动成功 + assertNotNull(processInstance); + + //获得流程实例号 + String processInstanceId = processInstance.getId(); + //新建一个变量的map + Map paramsMap = new HashMap(); + paramsMap.put("变量1", "变量1的值"); + paramsMap.put("变量2", "变量2的值"); + runtimeService.setProcessInstanceVariables(processInstanceId, paramsMap); + //获取这个持久化变量的值map + Map returnMap = (Map)runtimeService.getProcessInstanceVariables(processInstanceId); + //验证是否是刚添加的值 + assertEquals(2,returnMap.keySet().size()); + assertEquals("变量1的值", returnMap.get("变量1")); + assertEquals("变量2的值", returnMap.get("变量2")); + } + + /** + * 测试管理员暂停和恢复流程实例 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/StartProcessInstanceTest.bpmn" }) + public void testSuspendAndContinueProces(){ + //创建一个启动命令 + StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand(); + //设置需要启动的流程的KEY + startProcessInstanceCommand.setProcessDefinitionKey("Process_StartProcessInstanceTest"); + //设置业务关联键 + startProcessInstanceCommand.setBusinessKey("bk_StartProcessInstanceTest"); + //设置流程的启动人 + startProcessInstanceCommand.setStartAuthor("1200119390"); + //启动流程,返回流程实例 + ProcessInstance processInstance = runtimeService.noneStartProcessInstance(startProcessInstanceCommand); + //验证流程是否启动成功 + assertNotNull(processInstance); + + //获取流程实例号 + String processInstanceId = processInstance.getId(); + //暂停流程实例 + runtimeService.suspendProcessInstance(processInstanceId); + + //创建流程实例查询 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询刚才暂停的流程实例 + processInstanceQuery.processInstanceId(processInstanceId); + //获取流程实例 + processInstance = processInstanceQuery.singleResult(); + //验证流程实例已经暂停 + assertTrue(processInstance.isSuspended()); + + //恢复流程实例 + runtimeService.continueProcessInstance(processInstanceId); + + //重置流程实例查询 + processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询刚才的流程实例 + processInstanceQuery.processInstanceId(processInstanceId); + //获取流程实例 + processInstance = processInstanceQuery.singleResult(); + //验证不是暂停状态 + assertFalse(processInstance.isSuspended()); + } + + /** + * 测试管理员暂停和恢复流程实例 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/StartProcessInstanceTest.bpmn" }) + public void testTerminatProcessInstance(){ + //创建一个启动命令 + StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand(); + //设置需要启动的流程的KEY + startProcessInstanceCommand.setProcessDefinitionKey("Process_StartProcessInstanceTest"); + //设置业务关联键 + startProcessInstanceCommand.setBusinessKey("bk_StartProcessInstanceTest"); + //设置流程的启动人 + startProcessInstanceCommand.setStartAuthor("1200119390"); + //启动流程,返回流程实例 + ProcessInstance processInstance = runtimeService.noneStartProcessInstance(startProcessInstanceCommand); + //验证流程是否启动成功 + assertNotNull(processInstance); + + //获取流程实例号 + String processInstanceId = processInstance.getId(); + runtimeService.terminatProcessInstance(processInstanceId); + + //创建流程实例查询 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //查询刚才暂停的流程实例 + processInstanceQuery.processInstanceId(processInstanceId); + //获取流程实例 + processInstance = processInstanceQuery.singleResult(); + //验证流程实例为终止状态 + assertEquals(ProcessInstanceType.TERMINATION, processInstance.getInstanceType()); + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/schedule/ScheduleServiceTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/schedule/ScheduleServiceTest.java new file mode 100644 index 00000000..84467dac --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/schedule/ScheduleServiceTest.java @@ -0,0 +1,19 @@ +package com.founder.fix.fixflow.test.engine.api.schedule; + +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.SchedulerFactory; + +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; + +public class ScheduleServiceTest extends AbstractFixFlowTestCase { + + + public void testGetSchedulerFactory() throws SchedulerException{ + SchedulerFactory schedulerFactory=scheduleService.getSchedulerFactory(); + Scheduler scheduler=schedulerFactory.getScheduler(); + //获得到 scheduler 之后就能对定时任务框架进行操作 具体操作方式请参见 quartz 使用手册 + assertNotNull(scheduler); + } + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/task/ExternalTasksTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/task/ExternalTasksTest.java new file mode 100644 index 00000000..cc784bbc --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/task/ExternalTasksTest.java @@ -0,0 +1,252 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine.api.task; + +import com.founder.fix.fixflow.core.impl.util.GuidUtil; +import com.founder.fix.fixflow.core.task.IdentityLink; +import com.founder.fix.fixflow.core.task.IdentityLinkType; +import com.founder.fix.fixflow.core.task.IncludeExclusion; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskInstanceType; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; + +public class ExternalTasksTest extends AbstractFixFlowTestCase { + + // 添加一个任务 + public void testAddExternalTask() { + + // 创建一个guid + String taskIdString = GuidUtil.CreateGuid(); + // 创建一个任务(创建任务的时候createTime时间已经被自动设定) + TaskInstance taskInstance = taskService.newTask(taskIdString); + // 设置任务的独占处理者 + taskInstance.setAssignee("testAddExternalTask_admin"); + // 设置任务的表单 + taskInstance.setFormUri("http://www.google.com"); + // 设置任务关联键值 + taskInstance.setBizKey("1234567890"); + // 设置任务的主题 + taskInstance.setDescription("XXX系统的代办任务"); + // 设置任务的优先级 + taskInstance.setPriority(TaskInstance.PRIORITY_NORMAL); + // 设置任务的类型,其他系统的异构流程引擎 + taskInstance.setTaskInstanceType(TaskInstanceType.OTHERBPMTASK); + // 保存新创建的任务 + taskService.saveTask(taskInstance); + + TaskQuery taskQuery = taskService.createTaskQuery(); + + taskQuery.taskAssignee("testAddExternalTask_admin"); + taskQuery.addTaskType(TaskInstanceType.OTHERBPMTASK); + + TaskInstance taskInstanceReturn = taskQuery.singleResult(); + + assertNotNull(taskInstanceReturn); + + } + + // 任务持久化变量测试 + public void testTaskVariable() { + + // 创建一个guid + String taskIdString = GuidUtil.CreateGuid(); + // 创建一个任务(创建任务的时候createTime时间已经被自动设定) + TaskInstance taskInstance = taskService.newTask(taskIdString); + // 设置任务的独占处理者 + taskInstance.setAssignee("testAddExternalTask_admin"); + // 设置任务的表单 + taskInstance.setFormUri("http://www.google.com"); + // 设置任务关联键值 + taskInstance.setBizKey("1234567890"); + // 设置任务的主题 + taskInstance.setDescription("XXX系统的代办任务"); + // 设置任务的优先级 + taskInstance.setPriority(TaskInstance.PRIORITY_NORMAL); + // 设置任务的类型,其他系统的异构流程引擎 + taskInstance.setTaskInstanceType(TaskInstanceType.OTHERBPMTASK); + + // 保存新创建的任务 + taskService.saveTask(taskInstance); + + TaskQuery taskQuery = taskService.createTaskQuery(); + taskQuery.taskAssignee("testAddExternalTask_admin"); + taskQuery.addTaskType(TaskInstanceType.OTHERBPMTASK); + + TaskInstance taskInstanceReturn = taskQuery.singleResult(); + + assertNotNull(taskInstanceReturn); + + /* 任务变量 */ + + // 为任务创建变量 + taskService.setVariable(taskInstanceReturn.getId(), "变量", "变量值"); + // 查询任务的变量 + Object returnValue = taskService.getVariable(taskInstanceReturn.getId(), "变量"); + // 将取回的变量值比较 + assertEquals(returnValue, "变量值"); + + /* 流程实例变量 */ + + } + + /** + * 删除任务 + */ + public void testDeleteExternalTask() { + // 创建一个guid + String taskIdString = GuidUtil.CreateGuid(); + // 创建一个任务(创建任务的时候createTime时间已经被自动设定) + TaskInstance taskInstance = taskService.newTask(taskIdString); + // 设置任务的独占处理者 + taskInstance.setAssignee("testAddExternalTask_admin"); + // 设置任务的表单 + taskInstance.setFormUri("http://www.google.com"); + // 设置任务关联键值 + taskInstance.setBizKey("1234567890"); + // 设置任务的主题 + taskInstance.setDescription("XXX系统的代办任务"); + // 设置任务的优先级 + taskInstance.setPriority(TaskInstance.PRIORITY_NORMAL); + // 设置任务的类型,其他系统的异构流程引擎 + taskInstance.setTaskInstanceType(TaskInstanceType.OTHERBPMTASK); + + // 保存新创建的任务 + taskService.saveTask(taskInstance); + + // 查询任务 + TaskQuery taskQuery = taskService.createTaskQuery(); + taskQuery.taskAssignee("testAddExternalTask_admin"); + taskQuery.addTaskType(TaskInstanceType.OTHERBPMTASK); + + TaskInstance taskInstanceReturn = taskQuery.singleResult(); + + assertNotNull(taskInstanceReturn); + + // 级联删除任务信息 + taskService.deleteTask(taskInstanceReturn.getId(), true); + + // 再次查询任务 + + // 查询任务 + taskQuery = taskService.createTaskQuery(); + taskQuery.taskAssignee("testAddExternalTask_admin"); + taskQuery.addTaskType(TaskInstanceType.OTHERBPMTASK); + long rowNum = taskQuery.count(); + // 任务没有了 + assertEquals(rowNum, 0); + } + + /** + * 更新任务 + */ + public void testUpadteExternalTask() { + + // 创建一个guid + String taskIdString = GuidUtil.CreateGuid(); + // 创建一个任务(创建任务的时候createTime时间已经被自动设定) + TaskInstance taskInstance = taskService.newTask(taskIdString); + // 设置任务的独占处理者 + taskInstance.setAssignee("testAddExternalTask_admin"); + // 设置任务的表单 + taskInstance.setFormUri("http://www.google.com"); + // 设置任务关联键值 + taskInstance.setBizKey("1234567890"); + // 设置任务的主题 + taskInstance.setDescription("XXX系统的代办任务"); + // 设置任务的优先级 + taskInstance.setPriority(TaskInstance.PRIORITY_NORMAL); + // 设置任务的类型,其他系统的异构流程引擎 + taskInstance.setTaskInstanceType(TaskInstanceType.OTHERBPMTASK); + + // 保存新创建的任务 + taskService.saveTask(taskInstance); + + // 查询任务 + TaskQuery taskQuery = taskService.createTaskQuery(); + taskQuery.taskAssignee("testAddExternalTask_admin"); + taskQuery.addTaskType(TaskInstanceType.OTHERBPMTASK); + + TaskInstance taskInstanceReturn = taskQuery.singleResult(); + + assertNotNull(taskInstanceReturn); + + // 将任务处理者换为testAddExternalTask_test + taskInstanceReturn.setAssignee("testAddExternalTask_test"); + taskService.saveTask(taskInstanceReturn); + + // 再次查询任务 + taskQuery = taskService.createTaskQuery(); + taskQuery.taskAssignee("testAddExternalTask_test"); + taskQuery.addTaskType(TaskInstanceType.OTHERBPMTASK); + + taskInstanceReturn = taskQuery.singleResult(); + // 任务处理者的确被更新了 + assertNotNull(taskInstanceReturn); + } + + /** + * 添加候选身份 + */ + public void testAddIdentityLink() { + + // 创建一个guid + String taskIdString = GuidUtil.CreateGuid(); + // 创建一个任务(创建任务的时候createTime时间已经被自动设定) + TaskInstance taskInstance = taskService.newTask(taskIdString); + + // 设置任务的表单 + taskInstance.setFormUri("http://www.google.com"); + // 设置任务关联键值 + taskInstance.setBizKey("1234567890"); + // 设置任务的主题 + taskInstance.setDescription("XXX系统的代办任务"); + // 设置任务的优先级 + taskInstance.setPriority(TaskInstance.PRIORITY_NORMAL); + // 设置任务的类型,其他系统的异构流程引擎 + taskInstance.setTaskInstanceType(TaskInstanceType.OTHERBPMTASK); + + // 保存新创建的任务 + taskService.saveTask(taskInstance); + + // 创建候选用户链接 + IdentityLink identityLink = taskService.newIdentityLink(); + // 设置任务编号 + identityLink.setTaskId(taskIdString); + // 设置候选用户编号 + identityLink.setUserId("testAddExternalTask_admin"); + // 设置候选 包含 、排除类型 + identityLink.setIncludeExclusion(IncludeExclusion.INCLUDE); + // 设置候选类型 + identityLink.setType(IdentityLinkType.candidate); + // 保存候选身份 + taskService.saveIdentityLink(identityLink); + + // 查询任务 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查询候选任务 + taskQuery.taskCandidateUser("testAddExternalTask_admin"); + taskQuery.addTaskType(TaskInstanceType.OTHERBPMTASK); + + TaskInstance taskInstanceReturn = taskQuery.singleResult(); + + assertNotNull(taskInstanceReturn); + + } + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/task/TaskQueryTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/task/TaskQueryTest.java new file mode 100644 index 00000000..9e7d1828 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/task/TaskQueryTest.java @@ -0,0 +1,234 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine.api.task; + +import java.util.ArrayList; +import java.util.List; + +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.impl.task.QueryExpandTo; +import com.founder.fix.fixflow.core.impl.util.GuidUtil; +import com.founder.fix.fixflow.core.impl.util.QueryTableUtil; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskInstanceType; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class TaskQueryTest extends AbstractFixFlowTestCase { + + /** + * 测试任务实例扩展查询 + * @throws InterruptedException + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testTaskInstanceQueryExpandQuery(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + + /**********************本例子通过扩展查询的方法获取TaskServiceNewTest流程的nodeid = UserTask_1的任务实例***************************/ + QueryExpandTo queryExpandTo = new QueryExpandTo(); + //常见扩展查询的参数列表 + List whereSqlObj = new ArrayList(); + //添加扩展wheresql语句 (本例子扩展方法查询正在运行的流程实例) + queryExpandTo.setWhereSql("NODE_ID = ?"); + //增加扩展wheresql的参数 + whereSqlObj.add("UserTask_1"); + queryExpandTo.setWhereSqlObj(whereSqlObj); + //增加扩展查询 + taskQuery.queryExpandTo(queryExpandTo); + //查询TaskServiceNewTest经过扩展查询后的结果 + taskQuery.processDefinitionKey("TaskServiceNewTest"); + List list = taskQuery.list(); + //验证是否为1个 + assertEquals(1, list.size()); + //获取得到的任务实例 + TaskInstance taskInstance = list.get(0); + //验证得到的任务实例nodeid是否正确 + assertEquals("UserTask_1", taskInstance.getNodeId()); + + /**********************本例子通过扩展查询的方法获取流程定义表中的procecss_name和resource_name字段***************************/ + //重置流程实例查询 + taskQuery = taskService.createTaskQuery(); + //创建扩展查询 + queryExpandTo = new QueryExpandTo(); + //添加扩展的字段 + queryExpandTo.setFieldSql("fixflow_def_processdefinition.PROCESS_NAME,fixflow_def_processdefinition.RESOURCE_NAME"); + //增加扩展查询的left join语句(taskinstance持久化层的别名是“T”所以连接时需要加上,否则可能出现“未明确定义列”) + queryExpandTo.setLeftJoinSql("left join fixflow_def_processdefinition on T.processdefinition_id = fixflow_def_processdefinition.process_id"); + //增加扩展查询 + taskQuery.queryExpandTo(queryExpandTo); + //查询TaskServiceNewTest经过扩展查询后的结果 + taskQuery.processDefinitionKey("TaskServiceNewTest"); + list = taskQuery.list(); + //获取第一个流程实例结果 + taskInstance = list.get(0); + //获取扩展查询的字段 + String process_name = (String)taskInstance.getExtensionField("PROCESS_NAME"); + String RESOURCE_NAME = (String)taskInstance.getExtensionField("RESOURCE_NAME"); + //验证获得的扩展字段是否正确 + assertEquals("流程名称", process_name); + assertEquals("com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn", RESOURCE_NAME); + } + + /** + * 测试根据流程变量查询流程实例 + * @throws InterruptedException + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/runtime/ProcessVariablesTest.bpmn"}) + public void testProcessInstanceVariableData(){ + for(int i = 0;i<5;i++){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("ProcessVariablesTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + } + + //创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + //查询ProcessVariablesTest查询变量值等于"查询变量"的流程实例 + List taskInstances = taskQuery.processDefinitionKey("ProcessVariablesTest").processInstanceVariableData("查询变量", false).list(); + //验证是否为0 + assertEquals(0,taskInstances.size()); + + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询ProcessVariablesTest查询变量值等于"查询变量"的流程实例 + taskInstances = taskQuery.processDefinitionKey("ProcessVariablesTest").processInstanceVariableData("查询变量1", false).list(); + //验证是否为15 + assertEquals(15,taskInstances.size()); + + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询ProcessVariablesTest查询变量值等于"查询变量"的流程实例 + taskInstances = taskQuery.processDefinitionKey("ProcessVariablesTest").processInstanceVariableData("查询变量", true).list(); + //验证是否为15 + assertEquals(15,taskInstances.size()); + + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询ProcessVariablesTest查询变量query值等于"查询变量"的流程实例,应该为0 + taskInstances = taskQuery.processDefinitionKey("ProcessVariablesTest").processInstanceVariableData("query","查询变量1", false).list(); + //验证是否为0 + assertEquals(0,taskInstances.size()); + + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询ProcessVariablesTest查询变量queryVariable值等于"查询变量"的流程实例,应该为15 + taskInstances = taskQuery.processDefinitionKey("ProcessVariablesTest").processInstanceVariableData("queryVariable","查询变量1", false).list(); + //验证是否为15 + assertEquals(15,taskInstances.size()); + + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询ProcessVariablesTest查询变量queryVariable值like"查询变量"的流程实例,应该为15 + taskInstances = taskQuery.processDefinitionKey("ProcessVariablesTest").processInstanceVariableData("queryVariable","查询变量", true).list(); + //验证是否为15 + assertEquals(15,taskInstances.size()); + + /**********************本例子通过扩展查询的方法获取ProcessVariablesTest流程的查询变量queryVariable =查询变量1 的流程实例***************************/ + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //创建扩展查询 + QueryExpandTo queryExpandTo = new QueryExpandTo(); + //常见扩展查询的参数列表 + List whereSqlObj = new ArrayList(); + //添加扩展wheresql语句 (本例子扩展方法查询正在运行的流程实例) + queryExpandTo.setWhereSql("T.PROCESSINSTANCE_ID IN (SELECT PROCESSINSTANCE_ID FROM "+QueryTableUtil.getDefaultTableName("fixflow_run_variable")+" WHERE VARIABLE_KEY = ? AND BIZ_DATA = ?)"); + //增加扩展wheresql的参数 + whereSqlObj.add("queryVariable"); + whereSqlObj.add("查询变量1"); + queryExpandTo.setWhereSqlObj(whereSqlObj); + //增加扩展查询 + taskQuery.queryExpandTo(queryExpandTo); + //查询TaskServiceNewTest经过扩展查询后的结果 + taskQuery.processDefinitionKey("ProcessVariablesTest"); + taskInstances = taskQuery.list(); + //验证是否为5个 + assertEquals(15, taskInstances.size()); + + } + + /** + * 方法未实现 + */ + public void testVariableData(){ + // 创建一个guid + String taskIdString = GuidUtil.CreateGuid(); + // 创建一个任务(创建任务的时候createTime时间已经被自动设定) + TaskInstance taskInstance = taskService.newTask(taskIdString); + // 设置任务的独占处理者 + taskInstance.setAssignee("testAddExternalTask_admin"); + // 设置任务的表单 + taskInstance.setFormUri("http://www.google.com"); + // 设置任务关联键值 + taskInstance.setBizKey("1234567890"); + // 设置任务的主题 + taskInstance.setDescription("XXX系统的代办任务"); + // 设置任务的优先级 + taskInstance.setPriority(TaskInstance.PRIORITY_NORMAL); + // 设置任务的类型,其他系统的异构流程引擎 + taskInstance.setTaskInstanceType(TaskInstanceType.OTHERBPMTASK); + + // 保存新创建的任务 + taskService.saveTask(taskInstance); + + // 为任务创建变量 + taskService.setVariable(taskInstance.getId(), "变量", "变量值"); + //创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + //查询变量等于“变量”的任务实例 + List taskInstances = taskQuery.variableData("变量", false).list(); + assertEquals(0, taskInstances.size()); + + taskQuery = taskService.createTaskQuery(); + taskInstances = taskQuery.variableData("变量", true).list(); + assertEquals(0, taskInstances.size()); + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.java new file mode 100644 index 00000000..0cb73925 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.java @@ -0,0 +1,1451 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 yangchenhui + */ +package com.founder.fix.fixflow.test.engine.api.task; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.founder.fix.fixflow.core.impl.bpmn.behavior.ProcessDefinitionBehavior; +import com.founder.fix.fixflow.core.impl.bpmn.behavior.TaskCommandInst; +import com.founder.fix.fixflow.core.impl.bpmn.behavior.UserTaskBehavior; +import com.founder.fix.fixflow.core.impl.command.ExpandTaskCommand; +import com.founder.fix.fixflow.core.impl.command.StartProcessInstanceCommand; +import com.founder.fix.fixflow.core.model.ProcessDefinitionQuery; +import com.founder.fix.fixflow.core.runtime.ProcessInstance; +import com.founder.fix.fixflow.core.runtime.ProcessInstanceQuery; +import com.founder.fix.fixflow.core.runtime.ProcessInstanceType; +import com.founder.fix.fixflow.core.task.TaskInstance; +import com.founder.fix.fixflow.core.task.TaskInstanceType; +import com.founder.fix.fixflow.core.task.TaskQuery; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +public class TaskServiceTest extends AbstractFixFlowTestCase { + + /** + * 测试启动并提交,手工启动流程。 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testStartAndSubmit(){ + + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + //验证这个待办是否为空 + assertNotNull(taskInstance); + String nodeId = taskInstance.getNodeId(); + //验证流程实例是否在第二个节点 + assertEquals(nodeId, "UserTask_2"); + } + + /** + * 测试提交命令,提交和启动并提交的区别在于:1.第一个节点是共享:则启动并提交=启动+接收任务+提交 2.第一个节点是独占:则启动并提交=启动+提交 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testSubmit(){ + + //启动流程命令 + StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand(); + //设置流程编号 + startProcessInstanceCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置业务关联键 + startProcessInstanceCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //设置流程启动人 + startProcessInstanceCommand.setStartAuthor("1200119390"); + //启动流程,只启动流程 ,流程停在第一步 + ProcessInstance processInstanceQueryTo = runtimeService + .noneStartProcessInstance(startProcessInstanceCommand); + String processInstanceId = processInstanceQueryTo.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + String nodeId = taskInstance.getNodeId(); + //验证流程实例是否在第一个节点 + assertEquals(nodeId, "UserTask_1"); + + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置命令类型 + expandTaskCommand.setCommandType("submit"); + //设置任务号 + expandTaskCommand.setTaskId(taskInstance.getId()); + //设置命令ID 与节点上处理命令中一致,会执行按钮脚本 + expandTaskCommand.setUserCommandId("HandleCommand_3"); + //设置业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //执行这个启动并提交的命令,返回启动的流程实例 + taskService.expandTaskComplete(expandTaskCommand, null); + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //验证是否成功启动 + taskInstance = taskInstances.get(0); + nodeId = taskInstance.getNodeId(); + //验证当前任务是否在第二个节点 + assertEquals(nodeId, "UserTask_2"); + } + + /** + * 测试通用命令 通用按钮只会驱动流程令牌离开,执行表达式命令,不做额外操作 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testGeneral(){ + + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + // 获取一条任务 + TaskInstance taskInstance = taskInstances.get(0); + //验证这个待办是否为空 + assertNotNull(taskInstance); + String nodeId = taskInstance.getNodeId(); + //验证流程实例是否在第二个节点 + assertEquals(nodeId, "UserTask_2"); + + //创建通用命令 + ExpandTaskCommand expandTaskCommandGeneral=new ExpandTaskCommand(); + //设置命令为领取任务 + expandTaskCommandGeneral.setCommandType("general"); + //设置命令的ID,需和节点上配置的按钮编号对应,会执行其中脚本 + expandTaskCommandGeneral.setUserCommandId("HandleCommand_2"); + //设置命令的处理任务号 + expandTaskCommandGeneral.setTaskId(taskInstance.getId()); + //领取任务 + taskService.expandTaskComplete(expandTaskCommandGeneral, null); + + //创建流程实例查询 + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + //获得上面的流程实例 + ProcessInstance process = processInstanceQuery.processInstanceId(processInstanceId).singleResult(); + //验证流程实例是否已经结束,结束说明通用按钮已经驱动流程离开当前节点。 + assertTrue(process.hasEnded()); + } + /** + * 测试接收任务和释放任务,TaskServiceCandidateTest流程中的任务分配类型为共享模式 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceCandidateTest.bpmn"}) + public void testClaim(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceCandidateTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //未领任务前 独占任务应该为0 + assertEquals(taskInstances.size(), 0); + //获取1200119390的本流程实例的共享任务 + taskInstances = taskQuery.taskCandidateUser("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //验证此时的共享任务为1 + assertEquals(taskInstances.size(), 1); + + //获取当前任务节点 + TaskInstance taskInstance = taskInstances.get(0); + //创建通用命令 + ExpandTaskCommand expandTaskCommandClaim=new ExpandTaskCommand(); + //设置命令为领取任务 + expandTaskCommandClaim.setCommandType("claim"); + //设置命令的ID,需和节点上配置的按钮编号对应,会执行其中脚本 + expandTaskCommandClaim.setUserCommandId("HandleCommand_3"); + //设置命令的处理任务号 + expandTaskCommandClaim.setTaskId(taskInstance.getId()); + //领取任务 + taskService.expandTaskComplete(expandTaskCommandClaim, null); + + //重置任务查询 查询共享 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前共享任务 + taskInstances = taskQuery.taskCandidateUser("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //领取任务后,共享任务数为0 + assertEquals(taskInstances.size(), 0); + //重置任务查询 查询独占 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //领取任务后,独占任务数为1 + assertEquals(taskInstances.size(), 1); + + //取得当前任务 + taskInstance = taskInstances.get(0); + //取得任务所在节点 + String nodeId = taskInstance.getNodeId(); + //验证当前任务是否在第二个节点 + assertEquals(nodeId, "UserTask_4"); + + //创建通用命令 + ExpandTaskCommand expandTaskCommandRelease=new ExpandTaskCommand(); + //设置命令为释放任务 + expandTaskCommandRelease.setCommandType("releaseTask"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommandRelease.setUserCommandId("HandleCommand_4"); + //设置命令的处理任务号 + expandTaskCommandRelease.setTaskId(taskInstance.getId()); + //领取任务 + taskService.expandTaskComplete(expandTaskCommandRelease, null); + + //重置任务查询 查询独占 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //释放任务后,独占任务数为0 + assertEquals(taskInstances.size(), 0); + //重置任务查询 查询共享 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前共享任务 + taskInstances = taskQuery.taskCandidateUser("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //释放任务后,共享任务数为1 + assertEquals(taskInstances.size(), 1); + //取得当前任务 + taskInstance = taskInstances.get(0); + //取得任务所在节点 + nodeId = taskInstance.getNodeId(); + //验证当前任务是否在第二个节点 + assertEquals(nodeId, "UserTask_4"); + + } + /** + * 测试退回上一步 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testRollBackTaskPreviousStep(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //验证此时的独占任务为1 + assertEquals(taskInstances.size(), 1); + TaskInstance taskInstance = taskInstances.get(0); + String nodeId = taskInstance.getNodeId(); + assertEquals(nodeId, "UserTask_2"); + + //创建通用命令 + ExpandTaskCommand expandTaskCommandRollBack=new ExpandTaskCommand(); + //设置命令为退回上一步 + expandTaskCommandRollBack.setCommandType("rollBackTaskPreviousStep"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandRollBack.setUserCommandId("HandleCommand_3"); + //设置命令的处理任务号 + expandTaskCommandRollBack.setTaskId(taskInstance.getId()); + //执行退回操作 + taskService.expandTaskComplete(expandTaskCommandRollBack, null); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + // 查询此流程实例的当前任务号 + taskInstances = taskQuery.processInstanceId(processInstanceId).taskNotEnd().list(); + taskInstance = taskInstances.get(0); + //查询当前任务号的节点名称 + nodeId = taskInstance.getNodeId(); + //验证退回操作后任务是否回到UserTask_1节点 + assertEquals(nodeId, "UserTask_1"); + } + /** + * 测试退回指定步骤 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testRollBackTaskByExpression(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //验证此时的独占任务为1 + assertEquals(taskInstances.size(), 1); + //取得当前任务 + TaskInstance taskInstance = taskInstances.get(0); + //取得当前任务节点 + String nodeId = taskInstance.getNodeId(); + //验证是否在第二个节点 + assertEquals(nodeId, "UserTask_2"); + + //创建通用命令 + ExpandTaskCommand expandTaskCommandRollBack=new ExpandTaskCommand(); + //设置命令为退回制定步骤 + expandTaskCommandRollBack.setCommandType("rollBackTaskByExpression"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandRollBack.setUserCommandId("HandleCommand_4"); + //设置命令的处理任务号 + expandTaskCommandRollBack.setTaskId(taskInstance.getId()); + //执行退回操作 + taskService.expandTaskComplete(expandTaskCommandRollBack, null); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + // 查询此流程实例的当前任务号 + taskInstances = taskQuery.processInstanceId(processInstanceId).taskNotEnd().list(); + taskInstance = taskInstances.get(0); + //查询当前任务号的节点名称 + nodeId = taskInstance.getNodeId(); + //验证退回操作后任务是否回到UserTask_1节点 + assertEquals(nodeId, "UserTask_1"); + } + /** + * 测试退回-节点 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testRollBack(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //验证此时的独占任务为1 + assertEquals(taskInstances.size(), 1); + //获得当前任务 + TaskInstance taskInstance = taskInstances.get(0); + //获得任务节点 + String nodeId = taskInstance.getNodeId(); + //验证是否在第二个节点 + assertEquals(nodeId, "UserTask_2"); + + //创建通用命令 + ExpandTaskCommand expandTaskCommandRollBack=new ExpandTaskCommand(); + //设置命令为退回-节点 + expandTaskCommandRollBack.setCommandType("rollBack"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandRollBack.setUserCommandId("HandleCommand_5"); + //设置命令的处理任务号 + expandTaskCommandRollBack.setTaskId(taskInstance.getId()); + //设置命令所需的额外参数 rollBackNodeId + Map paraMap = new HashMap(); + paraMap.put("rollBackNodeId", "UserTask_1"); + //设置命令参数 + expandTaskCommandRollBack.setParamMap(paraMap); + //执行退回操作 + taskService.expandTaskComplete(expandTaskCommandRollBack, null); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + // 查询此流程实例的当前任务号 + taskInstances = taskQuery.processInstanceId(processInstanceId).taskNotEnd().list(); + taskInstance = taskInstances.get(0); + //查询当前任务号的节点名称 + nodeId = taskInstance.getNodeId(); + //验证退回操作后任务是否回到UserTask_1节点 + assertEquals(nodeId, "UserTask_1"); + } + /** + * 测试退回-任务 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testRollBackTaskByTaskId(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //验证此时的独占任务为1 + assertEquals(taskInstances.size(), 1); + //获得当前任务 + TaskInstance taskInstance = taskInstances.get(0); + //获得当前任务节点 + String nodeId = taskInstance.getNodeId(); + //验证是否在第二个节点 + assertEquals(nodeId, "UserTask_2"); + + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + // 查询此流程实例的已经处理过的 UserTask_1节点的任务编号 + taskInstances = taskQuery.processInstanceId(processInstanceId).taskIsEnd().nodeId("UserTask_1").list(); + //处理过的 UserTask_1节点的任务编号 + String taskId = taskInstances.get(0).getId(); + + //创建通用命令 + ExpandTaskCommand expandTaskCommandRollBack=new ExpandTaskCommand(); + //设置命令为退回-节点 + expandTaskCommandRollBack.setCommandType("rollBackTaskByTaskId"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandRollBack.setUserCommandId("HandleCommand_6"); + //设置命令的处理任务号 + expandTaskCommandRollBack.setTaskId(taskInstance.getId()); + //设置命令所需的额外参数 rollBackTaskId--需要退回的任务号 + Map paraMap = new HashMap(); + paraMap.put("rollBackTaskId", taskId); + //设置命令参数 + expandTaskCommandRollBack.setParamMap(paraMap); + //执行退回操作 + taskService.expandTaskComplete(expandTaskCommandRollBack, null); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + // 查询此流程实例的当前任务号 + taskInstances = taskQuery.processInstanceId(processInstanceId).taskNotEnd().list(); + taskInstance = taskInstances.get(0); + //查询当前任务号的节点名称 + nodeId = taskInstance.getNodeId(); + //验证退回操作后任务是否回到UserTask_1节点 + assertEquals(nodeId, "UserTask_1"); + } + + /** + * 测试保存草稿 , 保存草稿后,会将当前任务存为草稿状态 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testSaveTaskDraft(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //获得任务实例 + TaskInstance taskInstance = taskInstances.get(0); + //获得当前任务节点 + String nodeId = taskInstance.getNodeId(); + //验证是否在第二个节点 + assertEquals(nodeId, "UserTask_2"); + + //保存草稿操作前,验证任务为非草稿状态 + assertEquals(taskInstance.isDraft(),false); + //创建通用命令 + ExpandTaskCommand expandTaskCommandSaveTaskDraft=new ExpandTaskCommand(); + //设置命令为保存草稿 + expandTaskCommandSaveTaskDraft.setCommandType("saveTaskDraft"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandSaveTaskDraft.setUserCommandId("HandleCommand_7"); + //设置命令的处理任务号 + expandTaskCommandSaveTaskDraft.setTaskId(taskInstance.getId()); + //执行这个启动并提交的命令,返回启动的流程实例 + taskService.expandTaskComplete(expandTaskCommandSaveTaskDraft, null); + + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstance = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //保存草稿操作后,验证任务为草稿状态 + assertEquals(taskInstance.isDraft(),true); + } + + /** + * 测试删除实例 ---该命令尚未完善 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testDeleteProcessInstance(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是流程实例是否存在 + assertNotNull(processInstanceId); + + +// // 创建任务查询 +// TaskQuery taskQuery = taskService.createTaskQuery(); +// // 查找 1200119390 的这个流程实例的当前独占任务 +// List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); +// //取得当前任务 +// TaskInstance taskInstance = taskInstances.get(0); +// //创建通用命令 +// ExpandTaskCommand expandTaskCommandSaveTaskDraft=new ExpandTaskCommand(); +// //设置命令为删除实例 +// expandTaskCommandSaveTaskDraft.setCommandType("deleteProcessInstance"); +// //设置命令按钮的iD,与节点上处理命令设置一致 +// expandTaskCommandSaveTaskDraft.setUserCommandId("HandleCommand_8"); +// //设置命令的处理任务号 +// expandTaskCommandSaveTaskDraft.setTaskId(taskInstance.getId()); +// //执行这个启动并提交的命令,返回启动的流程实例 +// taskService.expandTaskComplete(expandTaskCommandSaveTaskDraft, null); + +// // 重置任务查询 +// taskQuery = taskService.createTaskQuery(); +// //获取此任务实例的任务数 +// int taskCount = taskQuery.processInstanceId(processInstanceId).list().size(); + //验证实例相关任务被删除 +// assertEquals(taskCount,0); + } + /** + * 测试暂停和恢复任务,暂停和恢复需成对出现,暂停任务后,任务为暂停状态,只可以有恢复按钮 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testSuspendAndContinueTask(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是流程实例是否存在 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //取得当前任务 + TaskInstance taskInstance = taskInstances.get(0); + + //暂停任务前,任务为非暂停状态 + assertEquals(taskInstance.isSuspended(),false); + //创建通用命令 + ExpandTaskCommand expandTaskCommandSuspendTask=new ExpandTaskCommand(); + //设置命令为暂停任务 + expandTaskCommandSuspendTask.setCommandType("suspendTask"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandSuspendTask.setUserCommandId("HandleCommand_9"); + //设置命令的处理任务号 + expandTaskCommandSuspendTask.setTaskId(taskInstance.getId()); + //执行这个暂停任务的命令 + taskService.expandTaskComplete(expandTaskCommandSuspendTask, null); + + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstance = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //暂停任务后,验证任务为暂停状态 + assertEquals(taskInstance.isSuspended(),true); + + + //创建通用命令 + ExpandTaskCommand expandTaskCommandContinueTask=new ExpandTaskCommand(); + //设置命令为恢复任务 + expandTaskCommandContinueTask.setCommandType("continueTask"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandContinueTask.setUserCommandId("HandleCommand_10"); + //设置命令的处理任务号 + expandTaskCommandContinueTask.setTaskId(taskInstance.getId()); + //执行这个恢复任务的命令 + taskService.expandTaskComplete(expandTaskCommandContinueTask, null); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstance = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //恢复任务操作后,验证任务为未暂停状态 + assertEquals(taskInstance.isSuspended(),false); + } + /** + * 测试转办和还回操作,转办和还回操作需成对出现,转办后,任务会到选择的人待办中,并且只有还回按钮使流程回到转办人 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testPendingAndResolved(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是流程实例是否存在 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + TaskInstance taskInstance = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //暂停任务后,验证任务为暂停状态 + assertEquals(taskInstance.getNodeId(),"UserTask_2"); + + + //创建通用命令 + ExpandTaskCommand expandTaskCommandPending=new ExpandTaskCommand(); + //设置命令为转办任务 + expandTaskCommandPending.setCommandType("pending"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandPending.setUserCommandId("HandleCommand_11"); + + Map paramsMap = new HashMap(); + //设置转办的用户号 + paramsMap.put("pendingUserId", "13223212313"); + expandTaskCommandPending.setParamMap(paramsMap); + //设置命令的处理任务号 + expandTaskCommandPending.setTaskId(taskInstance.getId()); + //执行这个转办的命令 + taskService.expandTaskComplete(expandTaskCommandPending, null); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + // 查找 13223212313 的这个流程实例的当前独占任务 + taskInstance = taskQuery.taskAssignee("13223212313").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //转办操作后,转办接收人的待办中存在这条任务 + assertNotNull(taskInstance); + + //查询是否有还回命令 + List taskCommandInsts=taskService.GetTaskCommandByTaskInstance(taskInstance,false); + boolean isHaveResolvedCommand = false; + //循环查找是否有还回命令 + for(TaskCommandInst taskCommandInst:taskCommandInsts){ + if("resolved".equals(taskCommandInst.getTaskCommandType())){ + isHaveResolvedCommand = true; + break; + } + } + //验证存在还回命令 + assertEquals(isHaveResolvedCommand,true); + + //创建通用命令 + ExpandTaskCommand expandTaskCommandResolved=new ExpandTaskCommand(); + //设置命令为还回任务 + expandTaskCommandResolved.setCommandType("resolved"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandResolved.setUserCommandId("HandleCommand_12"); + //设置命令的处理任务号 + expandTaskCommandResolved.setTaskId(taskInstance.getId()); + //执行这个还回任务的命令 + taskService.expandTaskComplete(expandTaskCommandResolved, null); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstance = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //还回操作后,任务回到换来的处理人 + assertNotNull(taskInstance); + + //查询是否有还回命令 + taskCommandInsts=taskService.GetTaskCommandByTaskInstance(taskInstance,false); + isHaveResolvedCommand = false; + //循环查找是否有还回命令 + for(TaskCommandInst taskCommandInst:taskCommandInsts){ + //如果存在类型为还回的按钮则结束 + if("resolved".equals(taskCommandInst.getTaskCommandType())){ + isHaveResolvedCommand = true; + break; + } + } + //验证不存在还回命令 + assertEquals(isHaveResolvedCommand,false); + } + + /** + * 测试追回操作 追回按钮需要配置在可以被追回的节点上,表达式中配置可以有追回操作的的节点编号,不配置则前面所有节点均可追回 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testRecover(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是流程实例是否存在 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + TaskInstance taskInstance = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //查询是否有追回命令 + List taskCommandInsts=taskService.GetTaskCommandByTaskInstance(taskInstance,true); + boolean isHaveRecoverCommand = false; + //循环查找是否有追回命令 + for(TaskCommandInst taskCommandInst:taskCommandInsts){ + //如果存在类型为追回的按钮则结束 + if("recover".equals(taskCommandInst.getTaskCommandType())){ + isHaveRecoverCommand = true; + break; + } + } + //验证存在追回命令 + assertEquals(isHaveRecoverCommand,true); + + //创建通用命令 + ExpandTaskCommand expandTaskCommandRecover=new ExpandTaskCommand(); + //设置命令为暂停实例 + expandTaskCommandRecover.setCommandType("recover"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandRecover.setUserCommandId("HandleCommand_13"); + //设置命令的处理任务号 + expandTaskCommandRecover.setTaskId(taskInstance.getId()); + //设置追回命令必须的参数recoverNodeId + Map map = new HashMap(); + map.put("recoverNodeId", "UserTask_1"); + expandTaskCommandRecover.setParamMap(map); + //执行这个追回的命令 + taskService.expandTaskComplete(expandTaskCommandRecover, null); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + // 查找当前流程实例的当前处理任务 + taskInstance = taskQuery.processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //验证任务是否被追回到UserTask_1节点 + assertEquals("UserTask_1", taskInstance.getNodeId()); + } + + /** + * 测试暂停和恢复流程实例 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testSuspendProcessInstance(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是流程实例是否存在 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + TaskInstance taskInstance = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //创建通用命令 + ExpandTaskCommand expandTaskCommandSuspendProcessInstance=new ExpandTaskCommand(); + //设置命令为暂停实例 + expandTaskCommandSuspendProcessInstance.setCommandType("suspendProcessInstance"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandSuspendProcessInstance.setUserCommandId("HandleCommand_14"); + //设置命令的处理任务号 + expandTaskCommandSuspendProcessInstance.setTaskId(taskInstance.getId()); + //执行这个暂停实例的命令 + taskService.expandTaskComplete(expandTaskCommandSuspendProcessInstance, null); + //根据实例号得到流程实例 + processInstance = runtimeService.getProcessInstance(processInstanceId); + + //验证实例处理暂停状态 + assertEquals(processInstance.isSuspended(),true); + + //创建通用命令 + ExpandTaskCommand expandTaskCommandContinueProcessInstance=new ExpandTaskCommand(); + //设置命令为恢复实例 + expandTaskCommandContinueProcessInstance.setCommandType("continueProcessInstance"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandContinueProcessInstance.setUserCommandId("HandleCommand_15"); + //设置命令的处理任务号 + expandTaskCommandContinueProcessInstance.setTaskId(taskInstance.getId()); + //执行这个恢复实例的命令 + taskService.expandTaskComplete(expandTaskCommandContinueProcessInstance, null); + //根据实例号得到流程实例 + processInstance = runtimeService.getProcessInstance(processInstanceId); + + //验证流程实例已处于非暂停状态 + assertEquals(processInstance.isSuspended(),false); + + } + + /** + * 测试暂停和恢复流程实例 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"}) + public void testTermination(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("Process_TaskServiceTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + Map mapVariables = new HashMap(); + //设置变量,流程线条上用到,amount<300时走独占任务,否则都共享任务 + mapVariables.put("amount", 280); + expandTaskCommand.setTransientVariables(mapVariables); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + //验证流程启动后实例状态为running(运行中) + assertEquals(ProcessInstanceType.RUNNING, processInstance.getInstanceType()); + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //验证更新时间不为空 + assertNotNull(processInstance.getUpdateTime()); + TaskInstance taskInstance = taskInstances.get(0); + //创建通用命令 + ExpandTaskCommand expandTaskCommandSuspendProcessInstance=new ExpandTaskCommand(); + //设置命令为暂停实例 + expandTaskCommandSuspendProcessInstance.setCommandType("terminationProcess"); + //设置命令按钮的iD,与节点上处理命令设置一致 + expandTaskCommandSuspendProcessInstance.setUserCommandId("HandleCommand_2"); + //设置命令的处理任务号 + expandTaskCommandSuspendProcessInstance.setTaskId(taskInstance.getId()); + //执行这个暂停实例的命令 + taskService.expandTaskComplete(expandTaskCommandSuspendProcessInstance, null); + //根据实例号得到流程实例 + processInstance = runtimeService.getProcessInstance(processInstanceId); + //验证实例状态为TERMINATION(终止) + assertEquals(ProcessInstanceType.TERMINATION, processInstance.getInstanceType()); + //验证更新时间不为空 + assertNotNull(processInstance.getUpdateTime()); + //验证流程实例已经结束 + assertTrue(processInstance.hasEnded()); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //验证任务已经被结束 + assertEquals(0, taskInstances.size()); + } + /** + * 测试接收任务和释放任务的taskService中的现有方法,不 以命令的形式,TaskServiceCandidateTest流程中的任务分配类型为共享模式 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceCandidateTest.bpmn"}) + public void testClaimMethod(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceCandidateTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + // 创建任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + List taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //未领任务前 独占任务应该为0 + assertEquals(taskInstances.size(), 0); + //获取1200119390的本流程实例的共享任务 + taskInstances = taskQuery.taskCandidateUser("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //验证此时的共享任务为1 + assertEquals(taskInstances.size(), 1); + + //获取当前任务节点 + TaskInstance taskInstance = taskInstances.get(0); + //接收任务,userid不传的话将会去线程副本中获取 + taskService.claim(taskInstance.getId(), null); + + //重置任务查询 查询共享 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前共享任务 + taskInstances = taskQuery.taskCandidateUser("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //领取任务后,共享任务数为0 + assertEquals(taskInstances.size(), 0); + //重置任务查询 查询独占 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //领取任务后,独占任务数为1 + assertEquals(taskInstances.size(), 1); + + //取得当前任务 + taskInstance = taskInstances.get(0); + //取得任务所在节点 + String nodeId = taskInstance.getNodeId(); + //验证当前任务是否在第二个节点 + assertEquals(nodeId, "UserTask_4"); + //释放任务 + taskService.release(taskInstance.getId()); + //重置任务查询 查询独占 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstances = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //释放任务后,独占任务数为0 + assertEquals(taskInstances.size(), 0); + //重置任务查询 查询共享 + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前共享任务 + taskInstances = taskQuery.taskCandidateUser("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); + //释放任务后,共享任务数为1 + assertEquals(taskInstances.size(), 1); + //取得当前任务 + taskInstance = taskInstances.get(0); + //取得任务所在节点 + nodeId = taskInstance.getNodeId(); + //验证当前任务是否在第二个节点 + assertEquals(nodeId, "UserTask_4"); + + } + /** + * 测试设置代理人---该命令尚未实现 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testSetAssignee(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + TaskInstance taskInstance = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + + String taskId = taskInstance.getId(); + taskService.setAssignee(taskId, "121231231"); + taskQuery = taskService.createTaskQuery(); + taskInstance = taskQuery.taskId(taskId).singleResult(); + //assertEquals("121231231", taskInstance.getAssignee()); + } + /** + * 测试查询可退回的任务 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testGetRollBackTask(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + TaskInstance taskInstance = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //查询可退回的任务 + List taskInstances = taskService.getRollBackTask(taskInstance.getId()); + //验证可退回任务数为1 + assertEquals(1, taskInstances.size()); + //获得可退回的任务 + taskInstance = taskInstances.get(0); + //验证是否是第一个节点 + assertEquals("UserTask_1",taskInstance.getNodeId()); + } + + /** + * 测试查询可退回的节点 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testGetRollBackNode(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + TaskInstance taskInstance = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //查询可退回的节点 + List userTaskBehaviors = taskService.getRollBackNode(taskInstance.getId()); + //验证可退回节点数为1 + assertEquals(1, userTaskBehaviors.size()); + //获得可退回的节点 + UserTaskBehavior userTaskBehavior = userTaskBehaviors.get(0); + //验证是否是第一个节点 + assertEquals("UserTask_1",userTaskBehavior.getId()); + } + /** + * 测试查询获取任务的上一步骤任务对象(非会签情况下上一步骤只有一个任务,会签情况下可能会有多个任务) + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testGetPreviousStepTaskByTaskId(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("TaskServiceNewTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + TaskQuery taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + TaskInstance taskInstance = taskQuery.taskAssignee("1200119390").processInstanceId(processInstanceId).taskNotEnd().list().get(0); + //获取任务的上一步骤任务对象(非会签情况下上一步骤只有一个任务,会签情况下可能会有多个任务) + List taskInstances = taskService.getPreviousStepTaskByTaskId(taskInstance.getId()); + //验证任务数是否为1 + assertEquals(1, taskInstances.size()); + //获得任务 + taskInstance = taskInstances.get(0); + //验证是否是第一个节点 + assertEquals("UserTask_1",taskInstance.getNodeId()); + } + + + /** + * 测试任务的各种查询,任务查询中,除了(共享,独占)和(类别)分别为or关系,其他查询之间均为and关系,taskQuery每次查询都会保存一个条件,所以需要时注意重置查询 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"}) + public void testTaskQuery(){ + + TaskQuery taskQuery = taskService.createTaskQuery(); + List taskInstances = taskQuery.taskAssignee("1200119390").processDefinitionKey("Process_TaskServiceTest").taskNotEnd().list(); + for(int i = 0;i<50;i++){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("Process_TaskServiceTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + + + Map mapVariables = new HashMap(); + //设置变量,流程线条上用到,amount<300时走独占任务,否则都共享任务 + int amount = 280+i; + mapVariables.put("amount", amount); + expandTaskCommand.setTransientVariables(mapVariables); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + } + + taskQuery = taskService.createTaskQuery(); + // 查找 1200119390 的这个流程实例的当前独占任务 + taskInstances = taskQuery.taskAssignee("1200119390").processDefinitionKey("Process_TaskServiceTest").taskNotEnd().list(); + //验证独占任务为20 + assertEquals(20, taskInstances.size()); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //取得此流程,此用户的共享任务 + List taskInstancesCandidate = taskQuery.taskCandidateUser("1200119390").processDefinitionKey("Process_TaskServiceTest").taskNotEnd().list(); + //验证共享任务为30 + assertEquals(30, taskInstancesCandidate.size()); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询 1200119390 的这个流程定义的共享和独占任务(此流程的待办事项) + List taskAssigneeAndCandidate = taskQuery.taskCandidateUser("1200119390").taskAssignee("1200119390").processDefinitionKey("Process_TaskServiceTest").taskNotEnd().list(); + //验证共享和独占任务的总和为50 + assertEquals(50, taskAssigneeAndCandidate.size()); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询1200119390 的这个流程定义的已办任务 + List taskEnd = taskQuery.processDefinitionKey("Process_TaskServiceTest").taskAssignee("1200119390").taskIsEnd().addTaskType(TaskInstanceType.FIXFLOWTASK).list(); + //验证已办任务是否为50 + assertEquals(50, taskEnd.size()); + //取得第一条任务 + TaskInstance taskInstance = taskEnd.get(0); + //验证任务中的流程定义名称不为空 + assertNotNull(taskInstance.getProcessDefinitionName()); + //测试分页 取1-9条 + taskEnd = taskQuery.listPage(1, 9); + //验证取到9条任务 + assertEquals(9, taskEnd.size()); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //获取流程定义名称等于TaskServiceTest的任务实例 + long count = taskQuery.processDefinitionName("TaskServiceTest").count(); + //验证是否为150个 + assertEquals(150, count); + + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //获取流程定义名称likeTaskServiceTest的人物实例 + count = taskQuery.processDefinitionNameLike("TaskServiceTest").count(); + //验证是否为150个 + assertEquals(150, count); + + } + + /** + * 测试开始节点的toolbar + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"}) + public void testStartToolBar(){ + //获取此流程的开始节点可显示的命令 + List commands = taskService.getSubTaskTaskCommandByKey("Process_TaskServiceTest"); + //验证是否为1个命令,开始节点只配了一个,详见流程定义 + assertEquals(1, commands.size()); + //获取这个命令 + TaskCommandInst taskCommandInst = commands.get(0); + //验证这个命令是否为启动并提交 + assertEquals("startandsubmit", taskCommandInst.getTaskCommandType()); + } + + /** + * 测试非开始节点的toolbar + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"}) + public void testUserTaskToolBar(){ + //获取流程定义查询 + ProcessDefinitionQuery processDefinitionQuery = modelService.createProcessDefinitionQuery(); + //获得发布的流程定义 + ProcessDefinitionBehavior processDefinitionBehavior = processDefinitionQuery.processDefinitionKey("Process_TaskServiceTest").singleResult(); + //获取此流程的开始节点可显示的命令 + List commands = taskService.getTaskCommandById(processDefinitionBehavior.getProcessDefinitionId(), "UserTask_3"); + //验证是否为7个命令,详见流程定义 + assertEquals(7, commands.size()); + } + + /** + * 测试流程追踪的toolbar + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"}) + public void testProcessTrackingToolBar(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("Process_TaskServiceTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + + + Map mapVariables = new HashMap(); + //设置变量,流程线条上用到,amount>300时走共享任务 + mapVariables.put("amount", 320); + expandTaskCommand.setTransientVariables(mapVariables); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + //创建一个任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + //查询上面启动的流程实例 + taskQuery.processInstanceId(processInstanceId); + //查询已完成的任务,(处理过程) + TaskInstance taskDone = taskQuery.taskNotEnd().singleResult(); + //获取流程追踪情况下的按钮 + List commands = taskService.GetTaskCommandByTaskInstance(taskDone, true); + //验证按钮个数是否为1 + assertEquals(1, commands.size()); + //取得按钮对象 + TaskCommandInst command = commands.get(0); + //验证按钮是否为追回按钮 + assertEquals("recover",command.getTaskCommandType()); + } + + /** + * 测试获取处理过程 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn"}) + public void testProcList(){ + //创建一个通用命令 + ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); + //设置流程名 + expandTaskCommand.setProcessDefinitionKey("Process_TaskServiceTest"); + //设置流程的业务关联键 + expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"); + //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit + expandTaskCommand.setCommandType("startandsubmit"); + //设置提交人 + expandTaskCommand.setInitiator("1200119390"); + //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 + expandTaskCommand.setUserCommandId("HandleCommand_2"); + + + Map mapVariables = new HashMap(); + //设置变量,流程线条上用到,amount<300时走独占任务,否则都共享任务 + mapVariables.put("amount", 280); + expandTaskCommand.setTransientVariables(mapVariables); + //执行这个启动并提交的命令,返回启动的流程实例 + ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); + String processInstanceId = processInstance.getId(); + //验证是否成功启动 + assertNotNull(processInstanceId); + + //创建一个任务查询 + TaskQuery taskQuery = taskService.createTaskQuery(); + //查询上面启动的流程实例 + taskQuery.processInstanceId(processInstanceId); + //查询已完成的任务,(处理过程) + List taskDone = taskQuery.taskIsEnd().list(); + //验证任务数是否为2,启动和开始是两个任务 + assertEquals(2, taskDone.size()); + //重置任务查询 + taskQuery = taskService.createTaskQuery(); + //查询未完成的任务,(当前处理) + List taskNotEnd = taskQuery.processInstanceId(processInstanceId).taskNotEnd().list(); + //验证当前处理任务是否为1 + assertEquals(1, taskNotEnd.size()); + } + +// //给邵帅造数据用 +// +// public void testAdd(){ +// for(int i=0;i<5;i++){ +// //创建一个通用命令 +// ExpandTaskCommand expandTaskCommand = new ExpandTaskCommand(); +// //设置流程名 +// expandTaskCommand.setProcessDefinitionKey("process_TestToolbar"); +// //设置流程的业务关联键 +// expandTaskCommand.setBusinessKey("BK_testStartProcessInstanceByKey"+i); +// //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit +// expandTaskCommand.setCommandType("startandsubmit"); +// //设置提交人 +// expandTaskCommand.setInitiator("1200119390"); +// //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 +// expandTaskCommand.setUserCommandId("HandleCommand_2"); +// ProcessInstance processInstance = (ProcessInstance)taskService.expandTaskComplete(expandTaskCommand, null); +// String processInstanceId = processInstance.getId(); +// //验证是否成功启动 +// assertNotNull(processInstanceId); +// +// /**************下面代码自动执行通用按钮,使流程结束,如果生成待办则下面不需要****************************/ +// +// // 创建任务查询 +// TaskQuery taskQuery = taskService.createTaskQuery(); +// // 查找 1200119390 的这个流程实例的当前独占任务 +// List taskInstances = taskQuery.taskCandidateUser("1200119390").processInstanceId(processInstanceId).taskNotEnd().list(); +// // 获取一条任务 +// TaskInstance taskInstance = taskInstances.get(0); +// //验证这个待办是否为空 +// assertNotNull(taskInstance); +// String nodeId = taskInstance.getNodeId(); +// //验证流程实例是否在第二个节点 +// assertEquals(nodeId, "UserTask_2"); +// //创建一个通用命令 +// expandTaskCommand = new ExpandTaskCommand(); +// //设置流程名 +// expandTaskCommand.setProcessDefinitionKey("process_TestToolbar"); +// //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit +// expandTaskCommand.setCommandType("claim"); +// expandTaskCommand.setTaskId(taskInstance.getId()); +// //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 +// expandTaskCommand.setUserCommandId("HandleCommand_3"); +// taskService.expandTaskComplete(expandTaskCommand, null); +// +// //创建一个通用命令 +// expandTaskCommand = new ExpandTaskCommand(); +// //设置流程名 +// expandTaskCommand.setProcessDefinitionKey("process_TestToolbar"); +// //命令类型,可以从流程引擎配置中查询 启动并提交为startandsubmit +// expandTaskCommand.setCommandType("general"); +// expandTaskCommand.setTaskId(taskInstance.getId()); +// //设置命令的id,需和节点上配置的按钮编号对应,会执行按钮中的脚本。 +// expandTaskCommand.setUserCommandId("HandleCommand_2"); +// taskService.expandTaskComplete(expandTaskCommand, null); +// } +// +// } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/entity/TaskInstanceEntityTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/entity/TaskInstanceEntityTest.java new file mode 100644 index 00000000..8bbc1c4a --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/entity/TaskInstanceEntityTest.java @@ -0,0 +1,103 @@ +package com.founder.fix.fixflow.test.engine.entity; + +import java.beans.PropertyDescriptor; +import java.lang.reflect.Method; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.founder.fix.bpmn2extensions.sqlmappingconfig.Result; +import com.founder.fix.bpmn2extensions.sqlmappingconfig.ResultMap; +import com.founder.fix.fixflow.core.impl.db.AbstractPersistentObject; +import com.founder.fix.fixflow.core.impl.task.TaskInstanceEntity; +import com.founder.fix.fixflow.core.impl.util.ReflectUtil; +import com.founder.fix.fixflow.core.impl.util.StringUtil; +import com.founder.fix.fixflow.core.task.DelegationState; +import com.founder.fix.fixflow.core.task.TaskInstanceType; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; + +public class TaskInstanceEntityTest extends AbstractFixFlowTestCase { + + @SuppressWarnings("unchecked") + public void testTaskInstanceEntityMapping() throws Exception { + + + Map dataMap=getDataMap(); + + ResultMap resultMap = processEngineConfiguration.getResultMap("taskResultMap"); + + + + + AbstractPersistentObject persistentObject = (AbstractPersistentObject) ReflectUtil.instantiate(resultMap.getType()); + persistentObject.persistentInit(resultMap,dataMap); + + TaskInstanceEntity task=(TaskInstanceEntity)persistentObject; + + + + } + + private Map getDataMap() { + + Map dataMap = new HashMap(); + try { + dataMap.put("TASKINSTANCE_ID", "任务编号"); + dataMap.put("NAME", "任务名称"); + dataMap.put("DESCRIPTION", "任务主题"); + dataMap.put("PROCESSINSTANCE_ID", "流程实例编号"); + dataMap.put("PROCESSDEFINITION_ID", "流程定义唯一编号"); + dataMap.put("PROCESSDEFINITION_KEY", "流程定义编号"); + dataMap.put("PROCESSDEFINITION_NAME", "流程定义名称"); + dataMap.put("VERSION", 1); + dataMap.put("TOKEN_ID", "令牌编号"); + dataMap.put("NODE_ID", "节点编号"); + dataMap.put("NODE_NAME", "节点名称"); + dataMap.put("PARENTTASK_ID", "父任务编号"); + dataMap.put("ASSIGNEE", "处理者"); + + dataMap.put("CLAIM_TIME", new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-25")); + + dataMap.put("CREATE_TIME", new SimpleDateFormat("yyyy-MM-dd").parse("1985-09-18")); + dataMap.put("START_TIME", new SimpleDateFormat("yyyy-MM-dd").parse("1985-09-19")); + dataMap.put("END_TIME", new SimpleDateFormat("yyyy-MM-dd").parse("2100-09-19")); + dataMap.put("DUEDATE", new SimpleDateFormat("yyyy-MM-dd").parse("1956-05-02")); + dataMap.put("PRIORITY", 50); + dataMap.put("CATEGORY", "分类"); + dataMap.put("OWNER", "拥有人"); + dataMap.put("DELEGATIONSTATESTRING", StringUtil.getString(DelegationState.PENDING)); + dataMap.put("BIZKEY", "业务关联值"); + dataMap.put("TASK_COMMENT", "任务意见"); + dataMap.put("FORMURI", "表单"); + dataMap.put("FORMURIVIEW", "浏览编号"); + dataMap.put("TASKGROUP", "会签任务组"); + dataMap.put("TASKTYPE", TaskInstanceType.FIXFLOWTASK); + dataMap.put("ISBLOCKING", String.valueOf(false)); + dataMap.put("ISCANCELLED", String.valueOf(false)); + dataMap.put("ISSUSPENDED", String.valueOf(false)); + dataMap.put("ISOPEN", String.valueOf(false)); + dataMap.put("ISDRAFT", String.valueOf(false)); + dataMap.put("EXPECTED_EXECUTIONTIME", 112233); + dataMap.put("AGENT", "代理人"); + dataMap.put("ADMIN", "管理操作"); + dataMap.put("CALLACTIVITY_INSTANCE_ID", "调用子流程实例编号"); + dataMap.put("PENDINGTASKID", "转办任务"); + dataMap.put("ARCHIVE_TIME", new SimpleDateFormat("yyyy-MM-dd").parse("1911-05-02")); + dataMap.put("COMMAND_ID", "任务命令编号"); + dataMap.put("COMMAND_TYPE", "任务命令类型"); + dataMap.put("COMMAND_MESSAGE", "任务命令显示名称"); + + // 扩展字段 + dataMap.put("EXTENSION_FIELD", "扩展字段"); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return dataMap; + + } + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/manager/IdentityManagerTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/manager/IdentityManagerTest.java new file mode 100644 index 00000000..9c74dd1b --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/manager/IdentityManagerTest.java @@ -0,0 +1,102 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 ych + */ +package com.founder.fix.fixflow.test.engine.manager; + +import com.founder.fix.fixflow.core.impl.Context; +import com.founder.fix.fixflow.core.impl.task.IdentityLinkEntity; +import com.founder.fix.fixflow.core.impl.task.TaskInstanceEntity; +import com.founder.fix.fixflow.core.impl.util.GuidUtil; +import com.founder.fix.fixflow.core.task.IdentityLinkType; +import com.founder.fix.fixflow.core.task.IncludeExclusion; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +/** + * identityLinkManager的测试类 + * @author ych + * + */ +public class IdentityManagerTest extends AbstractFixFlowTestCase{ + + /** + * 测试保存identityLinkEntity + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testSaveIdentityLink(){ + + //创建任务候选人实体 + String identityLinkId = GuidUtil.CreateGuid(); + IdentityLinkEntity identityLinkEntity = new IdentityLinkEntity(); + identityLinkEntity.setId(identityLinkId); + identityLinkEntity.setGroupId("groupId"); + identityLinkEntity.setUserId("userId"); + identityLinkEntity.setGroupType("groupType"); + identityLinkEntity.setType(IdentityLinkType.candidate); + identityLinkEntity.setIncludeExclusion(IncludeExclusion.EXCLUSION); + identityLinkEntity.setTaskId("taskId"); + + //保存identityLinkEntity + Context.getCommandContext().getIdentityLinkManager().saveIdentityLink(identityLinkEntity); + //根据编号查询保存的identityLinkEntity + IdentityLinkEntity identityLinkEntity2 = Context.getCommandContext().getIdentityLinkManager().selectIdentifyLinkById(identityLinkId); + //验证查询出来的实体属性正确 + assertEquals(identityLinkId, identityLinkEntity2.getId()); + assertEquals("groupId",identityLinkEntity2.getGroupId()); + assertEquals("userId", identityLinkEntity2.getUserId()); + assertEquals("groupType", identityLinkEntity2.getGroupType()); + assertEquals("taskId", identityLinkEntity2.getTaskId()); + assertEquals(IdentityLinkType.candidate, identityLinkEntity2.getType()); + assertEquals(IncludeExclusion.EXCLUSION, identityLinkEntity2.getIncludeExclusion()); + } + + /** + * 测试根据流程实例编号删除任务候选人 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testDeleteIdentityLinkByProcessInstanceId(){ + //创建任务候选人实体 + String identityLinkId = GuidUtil.CreateGuid(); + IdentityLinkEntity identityLinkEntity = new IdentityLinkEntity(); + identityLinkEntity.setId(identityLinkId); + identityLinkEntity.setTaskId("taskId"); + //保存实体 + Context.getCommandContext().getIdentityLinkManager().saveIdentityLink(identityLinkEntity); + + //根据编号查询实体 + IdentityLinkEntity identityLinkEntity2 = Context.getCommandContext().getIdentityLinkManager().selectIdentifyLinkById(identityLinkId); + //验证保存成功 + assertEquals(identityLinkId, identityLinkEntity2.getId()); + //创建任务实例 + TaskInstanceEntity taskInstanceEntity = new TaskInstanceEntity(); + //将任务实体与identityLink关联 + taskInstanceEntity.setId("taskId"); + taskInstanceEntity.setName("name"); + //将任务实体与processInstanceId关联 + taskInstanceEntity.setProcessInstanceId("processInstanceId"); + //保存任务实体 + Context.getCommandContext().getTaskManager().saveTaskInstanceEntity(taskInstanceEntity); + + //根据processInstanceId删除任务候选人 + Context.getCommandContext().getIdentityLinkManager().deleteIdentityLinkByProcessInstanceId("processInstanceId"); + + //查询人物候选人 + identityLinkEntity2 = Context.getCommandContext().getIdentityLinkManager().selectIdentifyLinkById(identityLinkId); + //验证查询结果为null,表示删除成功 + assertNull(identityLinkEntity2); + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/manager/TaskManagerTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/manager/TaskManagerTest.java new file mode 100644 index 00000000..85e02630 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/manager/TaskManagerTest.java @@ -0,0 +1,189 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 ych + */ +package com.founder.fix.fixflow.test.engine.manager; + +import java.text.ParseException; +import java.text.SimpleDateFormat; + +import com.founder.fix.fixflow.core.impl.Context; +import com.founder.fix.fixflow.core.impl.task.TaskInstanceEntity; +import com.founder.fix.fixflow.core.impl.util.GuidUtil; +import com.founder.fix.fixflow.core.task.DelegationState; +import com.founder.fix.fixflow.core.task.TaskInstanceType; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +/** + * TaskManager测试类 + * @author ych + * + */ +public class TaskManagerTest extends AbstractFixFlowTestCase{ + + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testSaveTask() throws ParseException{ + String taskId = GuidUtil.CreateGuid(); + + //创建任务实例 + TaskInstanceEntity taskInstanceEntity = new TaskInstanceEntity(); + taskInstanceEntity.setId(taskId); + taskInstanceEntity.setName("name"); + taskInstanceEntity.setDescription("description"); + taskInstanceEntity.setProcessInstanceId("processInstanceId"); + taskInstanceEntity.setProcessDefinitionId("processDefinitionId"); + taskInstanceEntity.setProcessDefinitionKey("processDefinitionKey"); + taskInstanceEntity.setVersion(0); + taskInstanceEntity.setTokenId("tokenId"); + taskInstanceEntity.setNodeId("nodeId"); + taskInstanceEntity.setNodeName("nodeName"); + taskInstanceEntity.setParentTaskInstanceId("parentTaskInstanceId"); + taskInstanceEntity.setAssignee("assignee"); + taskInstanceEntity.setClaimTime(new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-25")); + taskInstanceEntity.setCreateTime(new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-25")); + taskInstanceEntity.setStartTime(new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-25")); + taskInstanceEntity.setEndTime(new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-25")); + taskInstanceEntity.setDueDate(new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-25")); + taskInstanceEntity.setArchiveTime(new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-25")); + taskInstanceEntity.setBlocking(true); + taskInstanceEntity.setPriority(2); + taskInstanceEntity.setCategory("category"); + taskInstanceEntity.setOwner("owner"); + taskInstanceEntity.setDelegationState(DelegationState.PENDING); + taskInstanceEntity.setBizKey("bizKey"); + taskInstanceEntity.setTaskComment("taskComment"); + taskInstanceEntity.setFormUri("formUri"); + taskInstanceEntity.setFormUriView("formUriView"); + taskInstanceEntity.setTaskGroup("taskGroup"); + taskInstanceEntity.setTaskInstanceType(TaskInstanceType.FIXBPMTASK); + taskInstanceEntity.setCancelled(true); + taskInstanceEntity.setSuspended(true); + taskInstanceEntity.setOpen(false); + taskInstanceEntity.setDraft(true); + taskInstanceEntity.setExpectedExecutionTime(3); + taskInstanceEntity.setAgent("agent"); + taskInstanceEntity.setAdmin("admin"); + taskInstanceEntity.setCallActivityInstanceId("callActivitiProcessInstanceId"); + taskInstanceEntity.setPendingTaskId("pendingTaskId"); + taskInstanceEntity.setCommandId("commandId"); + taskInstanceEntity.setCommandType("commandType"); + taskInstanceEntity.setCommandMessage("commandMessage"); + ////////测试保存方法 + //保存任务实例 + Context.getCommandContext().getTaskManager().saveTaskInstanceEntity(taskInstanceEntity); + + //查询任务实例 + TaskInstanceEntity taskInstanceEntity2 = Context.getCommandContext().getTaskManager().findTaskById(taskId); + //验证查询结果正确 + assertEquals(taskId, taskInstanceEntity2.getId()); + assertEquals("name", taskInstanceEntity2.getName()); + assertEquals("description", taskInstanceEntity2.getDescription()); + assertEquals("processInstanceId", taskInstanceEntity2.getProcessInstanceId()); + assertEquals("processDefinitionId", taskInstanceEntity2.getProcessDefinitionId()); + assertEquals("processDefinitionKey", taskInstanceEntity2.getProcessDefinitionKey()); + assertEquals(0, taskInstanceEntity2.getVersion()); + assertEquals("tokenId", taskInstanceEntity2.getTokenId()); + assertEquals("nodeId",taskInstanceEntity2.getNodeId()); + assertEquals("nodeName", taskInstanceEntity2.getNodeName()); + + //根据processInstanceId删除保存的任务实例 + Context.getCommandContext().getTaskManager().deleteTaskByProcessInstanceId("processInstanceId"); + //查询任务实例 + taskInstanceEntity2 = Context.getCommandContext().getTaskManager().findTaskById(taskId); + //验证任务已经被删除 + assertNull(taskInstanceEntity2); + + //设置为新增状态 + taskInstanceEntity.setAdd(true); + + //重新保存任务实例 + Context.getCommandContext().getTaskManager().saveTaskInstanceEntity(taskInstanceEntity); + //查询任务实例 + taskInstanceEntity2 = Context.getCommandContext().getTaskManager().findTaskById(taskId); + + + //验证查询结果正确。验证保存成功 + assertEquals(taskId, taskInstanceEntity2.getId()); + //根据任务编号删除任务实例 + Context.getCommandContext().getTaskManager().deleteTaskById(taskId, false); + //查询任务实例 + taskInstanceEntity2 = Context.getCommandContext().getTaskManager().findTaskById(taskId); + //验证任务已经被删除 + assertNull(taskInstanceEntity2); + + taskInstanceEntity.setAdd(true); + + //重新保存任务实例 + Context.getCommandContext().getTaskManager().saveTaskInstanceEntity(taskInstanceEntity); + //查询任务实例 + taskInstanceEntity2 = Context.getCommandContext().getTaskManager().findTaskById(taskId); + //验证查询结果正确。验证保存成功 + assertEquals(taskId, taskInstanceEntity2.getId()); + //根据任务编号级联删除任务实例 + Context.getCommandContext().getTaskManager().deleteTaskById(taskId, true); + //查询任务实例 + taskInstanceEntity2 = Context.getCommandContext().getTaskManager().findTaskById(taskId); + //验证任务已经被删除 + assertNull(taskInstanceEntity2); + + } + + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testDeleteTaskByProcessInstanceId(){ + String taskId = GuidUtil.CreateGuid(); + //创建任务实例 + TaskInstanceEntity taskInstanceEntity = new TaskInstanceEntity(); + taskInstanceEntity.setId(taskId); + taskInstanceEntity.setProcessInstanceId("processInstanceId"); + //保存任务实例 + Context.getCommandContext().getTaskManager().saveTaskInstanceEntity(taskInstanceEntity); + //查询任务实例 + TaskInstanceEntity taskInstanceEntity2 = Context.getCommandContext().getTaskManager().findTaskById(taskId); + assertEquals(taskId, taskInstanceEntity2.getId()); + //根据processInstanceId删除保存的任务实例 + Context.getCommandContext().getTaskManager().deleteTaskByProcessInstanceId("processInstanceId"); + //查询任务实例 + taskInstanceEntity2 = Context.getCommandContext().getTaskManager().findTaskById(taskId); + //验证任务已经被删除 + assertNull(taskInstanceEntity2); + + } + + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testUpdate(){ + String taskId = GuidUtil.CreateGuid(); + //创建任务实例 + TaskInstanceEntity taskInstanceEntity = new TaskInstanceEntity(); + taskInstanceEntity.setId(taskId); + taskInstanceEntity.setName("name"); + taskInstanceEntity.setDescription("description"); + taskInstanceEntity.setProcessInstanceId("processInstanceId"); + taskInstanceEntity.setProcessDefinitionId("processDefinitionId"); + taskInstanceEntity.setProcessDefinitionKey("processDefinitionKey"); + taskInstanceEntity.setVersion(0); + taskInstanceEntity.setTokenId("tokenId"); + taskInstanceEntity.setNodeId("nodeId"); + //保存任务实例 + Context.getCommandContext().getTaskManager().saveTaskInstanceEntity(taskInstanceEntity); + + //查询任务实例 + TaskInstanceEntity taskInstanceEntity2 = Context.getCommandContext().getTaskManager().findTaskById(taskId); + //验证查询结果正确 + assertEquals(taskId, taskInstanceEntity2.getId()); + } + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/manager/TokenManagerTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/manager/TokenManagerTest.java new file mode 100644 index 00000000..cb0f9e81 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/engine/manager/TokenManagerTest.java @@ -0,0 +1,108 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 ych + */ +package com.founder.fix.fixflow.test.engine.manager; + +import java.text.SimpleDateFormat; + +import com.founder.fix.fixflow.core.impl.Context; +import com.founder.fix.fixflow.core.impl.runtime.TokenEntity; +import com.founder.fix.fixflow.core.impl.util.GuidUtil; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; +import com.founder.fix.fixflow.test.Deployment; + +/** + * 令牌manager的测试类 + * @author ych + * + */ +public class TokenManagerTest extends AbstractFixFlowTestCase{ + + /** + * 测试保存令牌 + * @throws Exception + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testSaveToken() throws Exception{ + //创建实体 + String guid = GuidUtil.CreateGuid(); + TokenEntity tokenEntity = new TokenEntity(); + tokenEntity.setId(guid); + tokenEntity.setName("测试令牌"); + tokenEntity.setProcessInstanceId("流程实例编号"); + tokenEntity.setNodeId("节点编号"); + tokenEntity.setParentTokenId("父令牌编号"); + tokenEntity.setParentFreeTokenId("父自由令牌编号"); + tokenEntity.setStartTime(new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-25")); + tokenEntity.setEndTime(new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-30")); + tokenEntity.setNodeEnterTime(new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-26")); + tokenEntity.setLockedString("true"); + tokenEntity.setSuspendedString("true"); + tokenEntity.setSubProcessRootTokenString("true"); + tokenEntity.setAbleToReactivateParentString("true"); + tokenEntity.setFreeTokenString("true"); + + //保存实体 + Context.getCommandContext().getTokenManager().saveToken(tokenEntity); + + //查询实体 + TokenEntity token = Context.getCommandContext().getTokenManager().findTokenById(guid); + + //验证属性正确 + assertEquals(guid, token.getId()); + assertEquals("测试令牌", token.getName()); + assertEquals("流程实例编号", token.getProcessInstanceId()); + assertEquals("节点编号", token.getNodeId()); + assertEquals("父令牌编号", token.getParentTokenId()); + assertEquals("父自由令牌编号", token.getParentFreeTokenId()); + assertEquals(new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-25"), token.getStartTime()); + assertTrue(token.getlock()); + assertTrue(token.isSuspended()); + assertTrue(token.isSubProcessRootToken()); + assertTrue(token.isAbleToReactivateParent()); + assertTrue(token.isFreeToken()); + } + + /** + * 测试根据流程编号删除令牌 + */ + @Deployment(resources = { "com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn"}) + public void testDeleteTokenByProcessInstanceId(){ + //创建实体 + String guid = GuidUtil.CreateGuid(); + TokenEntity tokenEntity = new TokenEntity(); + tokenEntity.setId(guid); + tokenEntity.setName("测试令牌"); + //设置processinstanceId的关联 + tokenEntity.setProcessInstanceId("processInstanceId"); + //保存实体 + Context.getCommandContext().getTokenManager().saveToken(tokenEntity); + //查询实体 + TokenEntity token = Context.getCommandContext().getTokenManager().findTokenById(guid); + //验证保存成功 + assertEquals(guid, token.getId()); + + //根据processInstanceId删除实体 + Context.getCommandContext().getTokenManager().deleteTokenByProcessInstanceId("processInstanceId"); + + //查询实体 + token = Context.getCommandContext().getTokenManager().findTokenById(guid); + //验证已经删除成功 + assertNull(token); + + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/DbConnectionPool.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/DbConnectionPool.java new file mode 100644 index 00000000..546c1778 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/DbConnectionPool.java @@ -0,0 +1,92 @@ +package com.founder.fix.fixflow.test.parallel; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + + +public class DbConnectionPool { + private List pool; + private int poolSize = 1; + private Connection conn = null; + private static DbConnectionPool instance = null; + /** + *单粒模式私有构造方法,获得本类的对象,通过getIstance方法。 + */ + private DbConnectionPool() { + pool = new ArrayList(); + this.createConnection(); + } + /** + *得到当前连接池的一个实例 + */ + public static DbConnectionPool getInstance() { + if (instance == null) { + instance = new DbConnectionPool(); + } + return instance; + } + /** + *得到连接池中的一个连接 + */ + public synchronized Connection getConnection() { + if (pool.size() > 0) { + Connection conn = pool.get(0); + pool.remove(conn); + return conn; + } else { + try { + wait(50000); + return getConnection(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + return null; + } // 等 5 秒 + } + } + /** + *创建初始的数据库连接 + */ + private void createConnection() { + int temp = ResourceManager.getPoolSize(); + if(temp > 0){ + this.poolSize = temp; + } + for (int i = 0; i < poolSize; i++) { + try { + Class.forName(ResourceManager.getDriverClass()); + conn = DriverManager.getConnection(ResourceManager.getUrl(),ResourceManager.getUsername(),ResourceManager.getPassword()); + pool.add(conn); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + /** + *用完将连接放回到连接池中 + * + *@paramconn + */ + public synchronized void release(Connection conn) { + pool.add(conn); + } + + /** + *关闭连接池中的所有连接 + */ + public synchronized void closePool() { + for (int i = 0; i < pool.size(); i++) { + try { + conn = ((Connection) pool.get(i)); + conn.close(); + pool.remove(i); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } +} \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/MiniConnectionPoolManager.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/MiniConnectionPoolManager.java new file mode 100644 index 00000000..c23cd4c6 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/MiniConnectionPoolManager.java @@ -0,0 +1,386 @@ +package com.founder.fix.fixflow.test.parallel; + +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; +import java.util.LinkedList; + +import javax.sql.ConnectionEvent; +import javax.sql.ConnectionEventListener; +import javax.sql.ConnectionPoolDataSource; +import javax.sql.PooledConnection; + +/** + * A lightweight standalone JDBC connection pool manager. + * + *

+ * The public methods of this class are thread-safe. + * + *

+ * Home page: www. + * source-code.biz/miniconnectionpoolmanager
+ * Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
+ * Multi-licensed: EPL / LGPL / MPL. + */ +public class MiniConnectionPoolManager { + + private ConnectionPoolDataSource dataSource; + private int maxConnections; + private long timeoutMs; + private PrintWriter logWriter; + private Semaphore semaphore; + private LinkedList recycledConnections; + private int activeConnections; + private PoolConnectionEventListener poolConnectionEventListener; + private boolean isDisposed; + private boolean doPurgeConnection; + + /** + * Thrown in {@link #getConnection()} or {@link #getValidConnection()} when + * no free connection becomes available within timeout seconds. + */ + public static class TimeoutException extends RuntimeException { + private static final long serialVersionUID = 1; + + public TimeoutException() { + super("Timeout while waiting for a free database connection."); + } + + public TimeoutException(String msg) { + super(msg); + } + } + + /** + * Constructs a MiniConnectionPoolManager object with a timeout of 60 + * seconds. + * + * @param dataSource + * the data source for the connections. + * @param maxConnections + * the maximum number of connections. + */ + public MiniConnectionPoolManager(ConnectionPoolDataSource dataSource, int maxConnections) { + this(dataSource, maxConnections, 60); + } + + /** + * Constructs a MiniConnectionPoolManager object. + * + * @param dataSource + * the data source for the connections. + * @param maxConnections + * the maximum number of connections. + * @param timeout + * the maximum time in seconds to wait for a free connection. + */ + public MiniConnectionPoolManager(ConnectionPoolDataSource dataSource, int maxConnections, int timeout) { + this.dataSource = dataSource; + this.maxConnections = maxConnections; + this.timeoutMs = timeout * 1000L; + try { + logWriter = dataSource.getLogWriter(); + } catch (SQLException e) { + } + if (maxConnections < 1) { + throw new IllegalArgumentException("Invalid maxConnections value."); + } + semaphore = new Semaphore(maxConnections, true); + recycledConnections = new LinkedList(); + poolConnectionEventListener = new PoolConnectionEventListener(); + } + + /** + * Closes all unused pooled connections. + */ + public synchronized void dispose() throws SQLException { + if (isDisposed) { + return; + } + isDisposed = true; + SQLException e = null; + while (!recycledConnections.isEmpty()) { + PooledConnection pconn = recycledConnections.remove(); + try { + pconn.close(); + } catch (SQLException e2) { + if (e == null) { + e = e2; + } + } + } + if (e != null) { + throw e; + } + } + + /** + * Retrieves a connection from the connection pool. + * + *

+ * If maxConnections connections are already in use, the method + * waits until a connection becomes available or timeout + * seconds elapsed. When the application is finished using the connection, + * it must close it in order to return it to the pool. + * + * @return a new Connection object. + * @throws TimeoutException + * when no connection becomes available within + * timeout seconds. + */ + public Connection getConnection() throws SQLException { + return getConnection2(timeoutMs); + } + + private Connection getConnection2(long timeoutMs) throws SQLException { + // This routine is unsynchronized, because semaphore.tryAcquire() may + // block. + synchronized (this) { + if (isDisposed) { + throw new IllegalStateException("Connection pool has been disposed."); + } + } + try { + if (!semaphore.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS)) { + throw new TimeoutException(); + } + } catch (InterruptedException e) { + throw new RuntimeException("Interrupted while waiting for a database connection.", e); + } + boolean ok = false; + try { + Connection conn = getConnection3(); + ok = true; + return conn; + } finally { + if (!ok) { + semaphore.release(); + } + } + } + + private synchronized Connection getConnection3() throws SQLException { + if (isDisposed) { + throw new IllegalStateException("Connection pool has been disposed."); + } // test again with lock + PooledConnection pconn; + if (!recycledConnections.isEmpty()) { + pconn = recycledConnections.remove(); + } else { + pconn = dataSource.getPooledConnection(); + pconn.addConnectionEventListener(poolConnectionEventListener); + } + Connection conn = pconn.getConnection(); + activeConnections++; + assertInnerState(); + return conn; + } + + /** + * Retrieves a connection from the connection pool and ensures that it is + * valid by calling {@link Connection#isValid(int)}. + * + *

+ * If a connection is not valid, the method tries to get another connection + * until one is valid (or a timeout occurs). + * + *

+ * Pooled connections may become invalid when e.g. the database server is + * restarted. + * + *

+ * This method is slower than {@link #getConnection()} because the JDBC + * driver has to send an extra command to the database server to test the + * connection. + * + * + *

+ * This method requires Java 1.6 or newer. + * + * @throws TimeoutException + * when no valid connection becomes available within + * timeout seconds. + */ + public Connection getValidConnection() { + long time = System.currentTimeMillis(); + long timeoutTime = time + timeoutMs; + int triesWithoutDelay = getInactiveConnections() + 1; + while (true) { + Connection conn = getValidConnection2(time, timeoutTime); + if (conn != null) { + return conn; + } + triesWithoutDelay--; + if (triesWithoutDelay <= 0) { + triesWithoutDelay = 0; + try { + Thread.sleep(250); + } catch (InterruptedException e) { + throw new RuntimeException("Interrupted while waiting for a valid database connection.", e); + } + } + time = System.currentTimeMillis(); + if (time >= timeoutTime) { + throw new TimeoutException("Timeout while waiting for a valid database connection."); + } + } + } + + private Connection getValidConnection2(long time, long timeoutTime) { + long rtime = Math.max(1, timeoutTime - time); + Connection conn; + try { + conn = getConnection2(rtime); + } catch (SQLException e) { + return null; + } + rtime = timeoutTime - System.currentTimeMillis(); + @SuppressWarnings("unused") + int rtimeSecs = Math.max(1, (int) ((rtime + 999) / 1000)); + try { + if (conn!=null) { + return conn; + } + } catch (Exception e) { + + } + // This Exception should never occur. If it nevertheless occurs, it's + // because of an error in the + // JDBC driver which we ignore and assume that the connection is not + // valid. + // When isValid() returns false, the JDBC driver should have already + // called connectionErrorOccurred() + // and the PooledConnection has been removed from the pool, i.e. the + // PooledConnection will + // not be added to recycledConnections when Connection.close() is + // called. + // But to be sure that this works even with a faulty JDBC driver, we + // call purgeConnection(). + purgeConnection(conn); + return null; + } + + // Purges the PooledConnection associated with the passed Connection from + // the connection pool. + private synchronized void purgeConnection(Connection conn) { + try { + doPurgeConnection = true; + // (A potential problem of this program logic is that setting the + // doPurgeConnection flag + // has an effect only if the JDBC driver calls connectionClosed() + // synchronously within + // Connection.close().) + conn.close(); + } catch (SQLException e) { + } + // ignore exception from close() + finally { + doPurgeConnection = false; + } + } + + private synchronized void recycleConnection(PooledConnection pconn) { + if (isDisposed || doPurgeConnection) { + disposeConnection(pconn); + return; + } + if (activeConnections <= 0) { + throw new AssertionError(); + } + activeConnections--; + semaphore.release(); + recycledConnections.add(pconn); + assertInnerState(); + } + + private synchronized void disposeConnection(PooledConnection pconn) { + pconn.removeConnectionEventListener(poolConnectionEventListener); + if (!recycledConnections.remove(pconn)) { + // If the PooledConnection is not in the recycledConnections list, + // we assume that the connection was active. + if (activeConnections <= 0) { + throw new AssertionError(); + } + activeConnections--; + semaphore.release(); + } + closeConnectionAndIgnoreException(pconn); + assertInnerState(); + } + + private void closeConnectionAndIgnoreException(PooledConnection pconn) { + try { + pconn.close(); + } catch (SQLException e) { + log("Error while closing database connection: " + e.toString()); + } + } + + private void log(String msg) { + String s = "MiniConnectionPoolManager: " + msg; + try { + if (logWriter == null) { + System.err.println(s); + } else { + logWriter.println(s); + } + } catch (Exception e) { + } + } + + private void assertInnerState() { + if (activeConnections < 0) { + throw new AssertionError(); + } + if (activeConnections + recycledConnections.size() > maxConnections) { + throw new AssertionError(); + } + if (activeConnections + semaphore.availablePermits() > maxConnections) { + throw new AssertionError(); + } + } + + private class PoolConnectionEventListener implements ConnectionEventListener { + public void connectionClosed(ConnectionEvent event) { + PooledConnection pconn = (PooledConnection) event.getSource(); + recycleConnection(pconn); + } + + public void connectionErrorOccurred(ConnectionEvent event) { + PooledConnection pconn = (PooledConnection) event.getSource(); + disposeConnection(pconn); + } + } + + /** + * Returns the number of active (open) connections of this pool. + * + *

+ * This is the number of Connection objects that have been + * issued by {@link #getConnection()}, for which + * Connection.close() has not yet been called. + * + * @return the number of active connections. + **/ + public synchronized int getActiveConnections() { + return activeConnections; + } + + /** + * Returns the number of inactive (unused) connections in this pool. + * + *

+ * This is the number of internally kept recycled connections, for which + * Connection.close() has been called and which have not yet + * been reused. + * + * @return the number of inactive connections. + **/ + public synchronized int getInactiveConnections() { + return recycledConnections.size(); + } + +} // end class MiniConnectionPoolManager \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/ResourceManager.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/ResourceManager.java new file mode 100644 index 00000000..627b39ef --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/ResourceManager.java @@ -0,0 +1,36 @@ +package com.founder.fix.fixflow.test.parallel; + +public class ResourceManager { + + + + public static int getPoolSize() { + // TODO Auto-generated method stub + return 40; + } + + public static String getDriverClass() { + // TODO Auto-generated method stub + return "oracle.jdbc.driver.OracleDriver"; + } + + public static String getUrl() { + // TODO Auto-generated method stub + return "jdbc:oracle:thin:@172.29.128.91:1521:orcl"; + } + + public static String getUsername() { + // TODO Auto-generated method stub + return "idbase"; + } + + public static String getPassword() { + // TODO Auto-generated method stub + return "idbase"; + } + + + + + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/SimpleTestClass.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/SimpleTestClass.java new file mode 100644 index 00000000..233671a5 --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/parallel/SimpleTestClass.java @@ -0,0 +1,88 @@ +//package com.founder.fix.fixflow.test.parallel; +// +//import java.sql.Connection; +//import java.sql.SQLException; +// +//import org.punit.runner.ConcurrentRunner; +// +//import com.founder.fix.fixflow.core.ProcessEngine; +//import com.founder.fix.fixflow.core.ProcessEngineManagement; +//import com.founder.fix.fixflow.core.impl.ExternalContent; +//import com.founder.fix.fixflow.core.impl.command.StartProcessInstanceCommand; +//import com.founder.fix.fixflow.core.impl.db.DbType; +// +// +//public class SimpleTestClass { +// +// public static MiniConnectionPoolManager poolMgr; +// public static void main(String[] args) { +// +// +// oracle.jdbc.pool.OracleConnectionPoolDataSource dataSource=null; +// try { +// dataSource = new oracle.jdbc.pool.OracleConnectionPoolDataSource(); +// } catch (SQLException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// dataSource.setDriverType ("thin"); +// dataSource.setServerName ("172.29.128.91"); +// dataSource.setPortNumber (1521); +// dataSource.setServiceName ("orcl"); +// dataSource.setUser ("idbase"); +// dataSource.setPassword ("idbase"); +// poolMgr = new MiniConnectionPoolManager(dataSource, 40); +// +// +// +// new ConcurrentRunner(50).run(SimpleTestClass.class); +// try { +// poolMgr.dispose(); +// } catch (SQLException e) { +// // TODO Auto-generated catch block +//// e.printStackTrace(); +// } +// +// } +// +// public void testA() { +// +// +// Connection connection=null; +// try { +// connection = poolMgr.getConnection(); +// } catch (SQLException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// +// +// ProcessEngineManagement.dbType = DbType.ORACLE; +// ProcessEngine processEngine = ProcessEngineManagement.getDefaultProcessEngine(); +// +// ExternalContent externalContent = new ExternalContent(); +// externalContent.setAuthenticatedUserId("1200119390"); +// +// externalContent.setConnection(connection); +// processEngine.setExternalContent(externalContent); +// +// //RuntimeService runtimeService = processEngine.getRuntimeService(); +// +// StartProcessInstanceCommand startProcessInstanceCommand = new StartProcessInstanceCommand(); +// startProcessInstanceCommand.setProcessDefinitionKey("Process_101"); +// startProcessInstanceCommand.setBusinessKey("1234567890"); +// startProcessInstanceCommand.setStartAuthor("1200119390"); +// //ProcessInstanceQueryTo processInstance = runtimeService.startProcessInstanceByKey(startProcessInstanceCommand); +// +// +// +// try { +// connection.close(); +// } catch (SQLException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// +// } +// +//} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/util/QuartzTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/util/QuartzTest.java new file mode 100644 index 00000000..8c5a15db --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/util/QuartzTest.java @@ -0,0 +1,101 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 Administrator + */ +package com.founder.fix.fixflow.test.util; + +import static org.quartz.CronScheduleBuilder.cronSchedule; +import static org.quartz.JobBuilder.newJob; +import static org.quartz.TriggerBuilder.newTrigger; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +import org.quartz.CronTrigger; +import org.quartz.JobDetail; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.impl.StdSchedulerFactory; + +import com.founder.fix.fixflow.core.impl.schedule.SimpleJob; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; + +/** + * @ClassName: QuartzTest + * @Description: TODO + * @author Administrator + * @date 2013-8-20 上午10:31:34 + * + */ +public class QuartzTest extends AbstractFixFlowTestCase { + @Override + protected void setUp() throws Exception { + + // 初始化测试方法 + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + // 测试完毕清理方法 + super.tearDown(); + + } + + public void testCronTrigger() throws SchedulerException { + // SchedulerFactory + // schedulerFactory=scheduleService.getSchedulerFactory(); + // Scheduler scheduler=schedulerFactory.getScheduler(); + Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); + assertNotNull(scheduler); + scheduler.start(); + + JobDetail job = newJob(SimpleJob.class).withIdentity("job1", "group1") + .build(); + + Date nowDate = new Date(); + long startDate = nowDate.getTime() + (24 * 60 * 60 * 1000); + Date triggerStartTime = new Date(startDate); + @SuppressWarnings("deprecation") + int hour = nowDate.getHours(); + + String cronExpr = "* * 7/24 * * ?"; + cronExpr = "* * "+hour+"/24 ? * 2-6"; + System.out.println("cronExpr:" + cronExpr); + CronTrigger trigger = newTrigger().withIdentity("trigger3", "group1") + .withSchedule(cronSchedule(cronExpr)).startAt(triggerStartTime) + .forJob("job1", "group1").build(); + scheduler.scheduleJob(job, trigger); + // trigger. + Date date = trigger.getNextFireTime(); + + // trigger. + // trigger.get + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + System.out.println("下次执行时间:" + df.format(date)); + + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.HOUR_OF_DAY, +24); + System.out.println("Calendar:" + cal.get(Calendar.HOUR_OF_DAY)); + + scheduler.shutdown(); + + assertTrue(true); + } + +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/util/QueryTableUtilTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/util/QueryTableUtilTest.java new file mode 100644 index 00000000..c43ad26d --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/util/QueryTableUtilTest.java @@ -0,0 +1,58 @@ +/** + * Copyright 1996-2013 Founder International Co.,Ltd. + * + * 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 ych + */ +package com.founder.fix.fixflow.test.util; + +import com.founder.fix.fixflow.core.exception.FixFlowException; +import com.founder.fix.fixflow.core.impl.util.QueryTableUtil; +import com.founder.fix.fixflow.core.impl.util.StringUtil; +import com.founder.fix.fixflow.core.runtime.QueryLocation; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; + +/** + * 查询数据来源工具类测试 + * @author Administrator + * + */ +public class QueryTableUtilTest extends AbstractFixFlowTestCase{ + + public void testGetTableName(){ + boolean pigeOnHole = StringUtil.getBoolean(processEngineConfiguration.getPigeonholeConfig().getIsEnable()); + String tableName = QueryTableUtil.getTableSelect("fixflow_run_processinstance", QueryLocation.RUN); + assertEquals("FIXFLOW_RUN_PROCESSINSTANCE", tableName); + if(pigeOnHole){ + String hisTableName = QueryTableUtil.getTableSelect("fixflow_run_processinstance", QueryLocation.HIS); + assertEquals("FIXFLOW_HIS_PROCESSINSTANCE", hisTableName); + String runHisTableName = QueryTableUtil.getTableSelect("fixflow_run_processinstance", QueryLocation.RUN_HIS); + assertNotNull(runHisTableName); + }else{ + String hisTableName = QueryTableUtil.getTableSelect("fixflow_run_processinstance", QueryLocation.HIS); + assertEquals("FIXFLOW_RUN_PROCESSINSTANCE", hisTableName); + String runHisTableName = QueryTableUtil.getTableSelect("fixflow_run_processinstance", QueryLocation.RUN_HIS); + assertEquals("FIXFLOW_RUN_PROCESSINSTANCE", runHisTableName); + } + try{ + tableName = QueryTableUtil.getTableSelect("fixflow_run_processinstance11", QueryLocation.RUN); + fail(); + }catch(Exception ex){ + if(ex instanceof FixFlowException){ + return; + } + } + fail(); + } +} diff --git a/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/util/UtilTest.java b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/util/UtilTest.java new file mode 100644 index 00000000..ac3ae45a --- /dev/null +++ b/modules/fixflow-expand/src/test/java/com/founder/fix/fixflow/test/util/UtilTest.java @@ -0,0 +1,39 @@ +package com.founder.fix.fixflow.test.util; + +import com.founder.fix.fixflow.core.db.pagination.Pagination; +import com.founder.fix.fixflow.core.impl.util.ReflectUtil; +import com.founder.fix.fixflow.test.AbstractFixFlowTestCase; + +/** + * 引擎工具测试类 + * @author kenshin + * + */ +public class UtilTest extends AbstractFixFlowTestCase{ + + + @Override + protected void setUp() throws Exception { + + // 初始化测试方法 + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + // 测试完毕清理方法 + super.tearDown(); + + } + + /** + * 反射工具类测试 + */ + public void testReflectUtil() + { + Pagination pagination=(Pagination)ReflectUtil.instantiate("com.founder.fix.fixflow.expand.database.pagination.OraclePaginationImpl"); + assertNotNull(pagination); + } + + +} diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/bpmndiagram/bpmndiagram.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/bpmndiagram/bpmndiagram.bpmn new file mode 100644 index 00000000..407eef98 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/bpmndiagram/bpmndiagram.bpmn @@ -0,0 +1,31 @@ + + + + + + + + SequenceFlow1 + + + + + + SequenceFlow1 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/callactivity/CallActivityTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/callactivity/CallActivityTest.bpmn new file mode 100644 index 00000000..f5d578ec --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/callactivity/CallActivityTest.bpmn @@ -0,0 +1,103 @@ + + + + + + "调用任务测试流程" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_2 + + + processInfo.getStartAuthor() + + + + + + SequenceFlow_4 + + + + SequenceFlow_2 + SequenceFlow_3 + + + + + + + + + + SequenceFlow_3 + SequenceFlow_4 + + + processInfo.getStartAuthor() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/connector/ConnectorTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/connector/ConnectorTest.bpmn new file mode 100644 index 00000000..f7d47c2a --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/connector/ConnectorTest.bpmn @@ -0,0 +1,133 @@ + + + + + + "连接器测试流程" + + + "add" + + + + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_2 + + + processInfo.getStartAuthor() + + + + + + SequenceFlow_4 + + + + + + + + + + + + + println(测试变量); +测试变量="我是赋值后的测试变量"; +println(测试变量); +return 测试变量; + + + outputObj + + + + + SequenceFlow_2 + SequenceFlow_3 + + + processInfo.getStartAuthor() + + + + + + + + + + + + SequenceFlow_3 + SequenceFlow_4 + + + processInfo.getStartAuthor() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/ComplexGatewayTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/ComplexGatewayTest.bpmn new file mode 100644 index 00000000..3eb85750 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/ComplexGatewayTest.bpmn @@ -0,0 +1,137 @@ + + + + + + "复杂网关测试流程" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_9 + + + processInfo.getStartAuthor() + + + + + + SequenceFlow_12 + SequenceFlow_13 + + + + + + + + + SequenceFlow_10 + SequenceFlow_13 + + + processInfo.getStartAuthor() + + + + + + + + + + + + SequenceFlow_11 + SequenceFlow_12 + + + processInfo.getStartAuthor() + + + + + SequenceFlow_9 + SequenceFlow_10 + SequenceFlow_11 + 条件网关条件 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/ExclusiveGatewayTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/ExclusiveGatewayTest.bpmn new file mode 100644 index 00000000..96bde8ca --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/ExclusiveGatewayTest.bpmn @@ -0,0 +1,172 @@ + + + + + + "排他网关测试流程" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_2 + + + processInfo.getStartAuthor() + + + + + + SequenceFlow_6 + SequenceFlow_7 + SequenceFlow_8 + + + + SequenceFlow_2 + SequenceFlow_3 + SequenceFlow_4 + SequenceFlow_5 + + + + + + + + SequenceFlow_3 + SequenceFlow_6 + + + processInfo.getStartAuthor() + + + + + + + + + + SequenceFlow_4 + SequenceFlow_7 + + + processInfo.getStartAuthor() + + + + + + + + + + SequenceFlow_5 + SequenceFlow_8 + + + processInfo.getStartAuthor() + + + + + 金额>1000 + + + 金额>=500 && 金额<=1000 + + + 金额<500 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/InclusiveGatewayTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/InclusiveGatewayTest.bpmn new file mode 100644 index 00000000..264b9cc3 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/InclusiveGatewayTest.bpmn @@ -0,0 +1,198 @@ + + + + + + "包容网关测试流程" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_2 + + + processInfo.getStartAuthor() + + + + + + SequenceFlow_7 + + + + SequenceFlow_2 + SequenceFlow_3 + SequenceFlow_4 + SequenceFlow_5 + + + + + + + + + SequenceFlow_3 + SequenceFlow_8 + + + processInfo.getStartAuthor() + + + + + + + + + + + SequenceFlow_4 + SequenceFlow_6 + + + processInfo.getStartAuthor() + + + + + + + + + + + SequenceFlow_5 + SequenceFlow_9 + + + processInfo.getStartAuthor() + + + + + 金额>500 + + + 金额>1000 + + + 金额>1500 + + + + + + + + SequenceFlow_6 + SequenceFlow_8 + SequenceFlow_9 + SequenceFlow_7 + + + processInfo.getStartAuthor() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/ParallelGatewayTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/ParallelGatewayTest.bpmn new file mode 100644 index 00000000..7d8b9cd4 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/gateway/ParallelGatewayTest.bpmn @@ -0,0 +1,174 @@ + + + + + + "并行网关测试流程" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_2 + + + processInfo.getStartAuthor() + + + + + + SequenceFlow_8 + + + + SequenceFlow_2 + SequenceFlow_3 + SequenceFlow_5 + + + + + + + + + SequenceFlow_3 + SequenceFlow_4 + + + processInfo.getStartAuthor() + + + + + + + + + + + + SequenceFlow_5 + SequenceFlow_6 + + + processInfo.getStartAuthor() + + + + + SequenceFlow_4 + SequenceFlow_6 + SequenceFlow_7 + + + + + + + + + + + + + SequenceFlow_7 + SequenceFlow_8 + + + processInfo.getStartAuthor() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/scripttask/ScriptTaskTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/scripttask/ScriptTaskTest.bpmn new file mode 100644 index 00000000..04a2d221 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/scripttask/ScriptTaskTest.bpmn @@ -0,0 +1,79 @@ + + + + + + "脚本任务测试流程" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_2 + + + processInfo.getStartAuthor() + + + + + + SequenceFlow_3 + + + + SequenceFlow_2 + SequenceFlow_3 + println (打印语句); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/sequenceflow/SequenceFlowTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/sequenceflow/SequenceFlowTest.bpmn new file mode 100644 index 00000000..a6d3c153 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/sequenceflow/SequenceFlowTest.bpmn @@ -0,0 +1,101 @@ + + + + + + "顺序流测试流程" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_2 + SequenceFlow_3 + + + processInfo.getStartAuthor() + + + + + + SequenceFlow_2 + SequenceFlow_4 + + + test.equals("123"); + + + + + + + + + SequenceFlow_3 + SequenceFlow_4 + + + processInfo.getStartAuthor() + + + + + !test.equals("123"); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/subprocess/SubProcessTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/subprocess/SubProcessTest.bpmn new file mode 100644 index 00000000..8c9d8cb9 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/subprocess/SubProcessTest.bpmn @@ -0,0 +1,174 @@ + + + + + + "内部子流程测试流程" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_3 + + + processInfo.getStartAuthor() + + + + + + SequenceFlow_2 + + + SequenceFlow_3 + SequenceFlow_4 + + SequenceFlow_5 + + + + + + + + + SequenceFlow_5 + SequenceFlow_6 + + + processInfo.getStartAuthor() + + + + + + + + + + + SequenceFlow_6 + SequenceFlow_7 + + + processInfo.getStartAuthor() + + + + + + + + SequenceFlow_7 + + + + + + + + + + + + SequenceFlow_4 + SequenceFlow_2 + + + processInfo.getStartAuthor() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/subprocess/SubTerminationSubProcessReturnTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/subprocess/SubTerminationSubProcessReturnTest.bpmn new file mode 100644 index 00000000..dd6fb61c --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/subprocess/SubTerminationSubProcessReturnTest.bpmn @@ -0,0 +1,98 @@ + + + + + + "子流程主题" + + + "DemoServlet?action=doTask" + + + + SequenceFlow_1 + + + + + + + + + + + "DemoServlet?action=startOneTask" + + + + + SequenceFlow_1 + SequenceFlow_3 + + + "fixflow_allusers" + + + + + + SequenceFlow_4 + + + + + + + + + "UserTask_1" + + + + SequenceFlow_3 + SequenceFlow_4 + + + "fixflow_allusers" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/subprocess/TerminationSubProcessReturnTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/subprocess/TerminationSubProcessReturnTest.bpmn new file mode 100644 index 00000000..9d203128 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/subprocess/TerminationSubProcessReturnTest.bpmn @@ -0,0 +1,88 @@ + + + + + + "DemoServlet?action=doTask" + + + "测试主流程" + + + + SequenceFlow_1 + + + + + + + + + + + "DemoServlet?action=startOneTask" + + + + + SequenceFlow_1 + SequenceFlow_3 + + + "fixflow_allusers" + + + + + + SequenceFlow_4 + + + + + + + + SequenceFlow_3 + SequenceFlow_4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/usertask/UserTaskTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/usertask/UserTaskTest.bpmn new file mode 100644 index 00000000..eae4be7b --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/bpmn/usertask/UserTaskTest.bpmn @@ -0,0 +1,225 @@ + + + + + + "人工任务测试流程" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_2 + + + processInfo.getStartAuthor() + + + + + + SequenceFlow_4 + SequenceFlow_6 + SequenceFlow_8 + + + + + + + + 跳过策略条件 + + "1200119390" + + + "同意跳过" + + + + + 输出项="同意"; + + + 输出项="不同意"; + + + "节点主题" + + + SequenceFlow_2 + SequenceFlow_3 + + + processInfo.getStartAuthor() + + + + + + 输入数据集 + + + 输出数据集 + + + + + 输入项 + + + + + 输出项 + + + 输入数据集.length==输出数据集.size(); + + + + + SequenceFlow_3 + SequenceFlow_4 + SequenceFlow_5 + SequenceFlow_7 + + + y=Collections.frequency(输出数据集, "不同意"); +if(y>2){ +return true; +} +else{ +return false; +} + + + + + + + + + + SequenceFlow_5 + SequenceFlow_6 + + + processInfo.getStartAuthor() + + + + + y=Collections.frequency(输出数据集, "同意"); +if(y>2){ +return true; +} +else{ +return false; +} + + + + + + + + + + + SequenceFlow_7 + SequenceFlow_8 + + + processInfo.getStartAuthor() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest.zip b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest.zip new file mode 100644 index 00000000..2ee935b5 Binary files /dev/null and b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest.zip differ diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest_new.zip b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest_new.zip new file mode 100644 index 00000000..f62c1f8d Binary files /dev/null and b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/Process_TaskServiceTest_new.zip differ diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/StartProcessInstanceTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/StartProcessInstanceTest.bpmn new file mode 100644 index 00000000..927620fa --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/StartProcessInstanceTest.bpmn @@ -0,0 +1,84 @@ + + + + + + + + + "StartProcessInstanceTest任务主题" + + + "test.html" + + + + SequenceFlow_2 + + + + + + + + + SequenceFlow_2 + SequenceFlow_6 + + + "1035555" + + + + + + + SequenceFlow_8 + + + + + + SequenceFlow_6 + SequenceFlow_8 + + + processInfo.getInitiator() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/startProcessByUser.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/startProcessByUser.bpmn new file mode 100644 index 00000000..7e06de64 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/model/startProcessByUser.bpmn @@ -0,0 +1,64 @@ + + + + + + "任务主题" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_2 + + + "fixflow_allusers" + + + + + + SequenceFlow_2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/runtime/ProcessVariablesTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/runtime/ProcessVariablesTest.bpmn new file mode 100644 index 00000000..d3151bd0 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/runtime/ProcessVariablesTest.bpmn @@ -0,0 +1,163 @@ + + + + + + "瞬态默认值" + + + + "默认值" + + + + "测试流程变量" + + + "add" + + + "查询变量默认值" + + + + + SequenceFlow_1 + + + + + ${variable}="持久化变量"; +${tranVariable}="瞬态变量"; +${queryVariable}="查询变量1"; + + + + + + + + SequenceFlow_1 + SequenceFlow_5 + + + "fixflow_allusers" + + + + + + SequenceFlow_4 + SequenceFlow_8 + + + + + + + + + SequenceFlow_6 + SequenceFlow_4 + + + "1200119390" + + + + + + + + + + + SequenceFlow_7 + SequenceFlow_8 + + + "1200119390" + + + + + SequenceFlow_5 + SequenceFlow_6 + SequenceFlow_7 + + + + if("默认值".equals(${tranVariable})){ + return true; +}else{ + return false; +} + + + if("瞬态变量".equals(${tranVariable})){ + return true; +}else{ + return false; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/runtime/StartProcessInstanceTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/runtime/StartProcessInstanceTest.bpmn new file mode 100644 index 00000000..d25ccf2d --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/runtime/StartProcessInstanceTest.bpmn @@ -0,0 +1,84 @@ + + + + + + + + + "StartProcessInstanceTest任务主题" + + + "test.html" + + + + SequenceFlow_2 + + + + + + + + + SequenceFlow_2 + SequenceFlow_6 + + + processInfo.getStartAuthor() + + + + + + + SequenceFlow_8 + + + + + + SequenceFlow_6 + SequenceFlow_8 + + + processInfo.getInitiator() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/runtime/processEventTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/runtime/processEventTest.bpmn new file mode 100644 index 00000000..cfcd3a44 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/runtime/processEventTest.bpmn @@ -0,0 +1,127 @@ + + + + + + "测试流程事件" + + + "add" + + + + + ${testEvent}="启动" + + + outputObj + + + + + "默认值" + + + + + + ${testEvent}="结束" + + + outputObj + + + + + + + ${testEvent}="终止" + + + outputObj + + + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_3 + + + "fixflow_allusers" + + + + + + SequenceFlow_4 + + + + + + + + + + + SequenceFlow_3 + SequenceFlow_4 + + + "1200119390" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/TaskServiceCandidateTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/TaskServiceCandidateTest.bpmn new file mode 100644 index 00000000..6a499be4 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/TaskServiceCandidateTest.bpmn @@ -0,0 +1,99 @@ + + + + + + "测试taskService的流程" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + "add" + + + "add" + + + SequenceFlow_1 + SequenceFlow_3 + + + "fixflow_allusers" + + + + + + SequenceFlow_4 + + + + + + + + + + + SequenceFlow_3 + SequenceFlow_4 + + + "fixflow_allusers" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn new file mode 100644 index 00000000..7ba4c955 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/TaskServiceNewTest.bpmn @@ -0,0 +1,109 @@ + + + + + + "taskService的测试流程" + + + "add" + + + + SequenceFlow_1 + + + + + + + + + + + SequenceFlow_1 + SequenceFlow_3 + + + processInfo.getStartAuthor() + + + + + + SequenceFlow_4 + + + + + + + + "UserTask_1" + + + + + + + + "UserTask_1" + + + + + + + + + + + SequenceFlow_3 + SequenceFlow_4 + + + processInfo.getInitiator() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn new file mode 100644 index 00000000..d2197dd4 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/TaskServiceTest.bpmn @@ -0,0 +1,137 @@ + + + + + + + + + "TaskServiceTest任务" + + + "aaa.html" + + + + + + + SequenceFlow_12 + + + + + + + SequenceFlow_12 + SequenceFlow_10 + + + processInfo.getStartAuthor() + + + + + SequenceFlow_10 + SequenceFlow_6 + SequenceFlow_8 + + + amount>=300 + + + amount<300 + + + + + SequenceFlow_4 + SequenceFlow_2 + + + + + + + + SequenceFlow_8 + SequenceFlow_4 + + + processInfo.getInitiator() + + + + + + + + + + + + + "UserTask_1" + + + "UserTask_1" + + + + SequenceFlow_6 + SequenceFlow_2 + + + processInfo.getInitiator() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/process_TestToolbar.bpmn b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/process_TestToolbar.bpmn new file mode 100644 index 00000000..1079a704 --- /dev/null +++ b/modules/fixflow-expand/src/test/resources/com/founder/fix/fixflow/test/engine/api/task/process_TestToolbar.bpmn @@ -0,0 +1,98 @@ + + + + + + "add" + + + "默认任务主题" + + + + SequenceFlow_1 + + + + + + + + + + + "FlowCenter?action=doTask" + + + SequenceFlow_1 + SequenceFlow_3 + + + "fixflow_allusers" + + + + + + SequenceFlow_4 + + + + + + + + + + "FlowCenter?action=doTask" + + + SequenceFlow_3 + SequenceFlow_4 + + + "fixflow_allusers" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fixflow-webapp-common/src/main/resources/jdbc.properties b/modules/fixflow-webapp-common/src/main/resources/jdbc.properties index baa1a844..d3090dbe 100644 --- a/modules/fixflow-webapp-common/src/main/resources/jdbc.properties +++ b/modules/fixflow-webapp-common/src/main/resources/jdbc.properties @@ -9,15 +9,15 @@ ########## # MySql # ########## -#idbase.driverClassName=com.mysql.jdbc.Driver -#idbase.url=jdbc:mysql://172.16.40.89/idbase?characterEncoding=UTF-8 -#idbase.username=root -#idbase.password=fixflow +idbase.driverClassName=com.mysql.jdbc.Driver +idbase.url=jdbc:mysql://127.0.0.1/fixflow?characterEncoding=UTF-8 +idbase.username=root +idbase.password=root ############# # SqlServer # ############# -idbase.driverClassName=net.sourceforge.jtds.jdbc.Driver -idbase.url=jdbc:jtds:sqlserver://172.16.40.89:1433/fixflow -idbase.username=sa -idbase.password=sa123456 \ No newline at end of file +#idbase.driverClassName=net.sourceforge.jtds.jdbc.Driver +#idbase.url=jdbc:jtds:sqlserver://172.16.40.89:1433/fixflow +#idbase.username=sa +#idbase.password=sa123456 \ No newline at end of file