Commit 4cb9ae4a authored by Quxl's avatar Quxl

添加测试代码

parent 1ae9602c
......@@ -16,6 +16,38 @@
<artifactId>fastjson</artifactId>
<version>1.2.38</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -12,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
import com.egolm.common.StringUtil;
import com.egolm.common.Util;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.Page;
import com.egolm.workflow.bean.TFlow;
......@@ -74,7 +75,9 @@ public abstract class AbstractOpenApi implements WorkflowEngine, WorkflowService
public TFlowTask start(String sFlowName, String sUserID, Map<String, Object> vars) {
JdbcTemplate jdbcTemplate = this.getFlowDBTemplate();
Date now = new Date();
TFlow flow = jdbcTemplate.queryForBean("select * from t_flow where nDelFlag = 0 and sFlowName = ? order by dCreate desc limit 1", TFlow.class, sFlowName);
Page page = new Page(1L, 1L, "dCreate desc");
List<Map<String, Object>> list = jdbcTemplate.limit("select * from t_flow where nDelFlag = 0 and sFlowName = ?", page, sFlowName);
TFlow flow = Util.mapTo(list.get(0), TFlow.class);
String settings = flow.getsFlowSettings();
Map<?, ?> settongsMap = JSON.parseObject(settings);
Map<?, ?> nodesMap = (Map<?, ?>)settongsMap.get("nodes");
......@@ -117,6 +120,9 @@ public abstract class AbstractOpenApi implements WorkflowEngine, WorkflowService
@Override
@Transactional
public TFlowTask commit(String sTaskID, String sTransferName, String sRemark, String sUserID, Map<String, Object> vars) {
if(vars == null) {
vars = new HashMap<String, Object>();
}
Date now = new Date();
if(StringUtil.isNotBlank(sUserID)) {
this.accept(sTaskID, sUserID);
......
......@@ -15,7 +15,7 @@ public interface WorkflowCallback {
* @param args 回调参数
* @return
*/
Map<String, Object> runApi(String api, Map<String, Object> args);
Object runApi(String api, Map<String, Object> args);
/**
* 判断是否是指向业务处理逻辑的地址或指针
......
{
"title": "测试流程",
"start": "开始",
"nodes": {
"开始": {
"name": "开始", "type": "start",
"transfers": {"转到提交请假单": {"name": "转到提交请假单", "action": null, "to": "提交请假单"}}
"transfers": {
"转到提交请假单": {
"name": "转到提交请假单",
"action": "",
"to": "提交请假单"
}
},
"name": "开始",
"type": "start"
},
"提交请假单": {
"form": "/leave.html", "name": "提交请假单", "type": "task", "user": "owner",
"form": "/leave.html",
"transfers": {
"提交请假单": { "name": "提交请假单", "action": null, "to": "自动审批" }
}
"提交请假单": {
"name": "提交请假单",
"to": "自动审批"
}
},
"name": "提交请假单",
"type": "task",
"user": "owner"
},
"请假成功": {
"name": "请假成功",
"type": "end"
},
"自动审批": {
"name": "自动审批", "type": "auto", "target": "test.xjson",
"transfers": {
"请假天数小于3天": { "name": "请假天数小于3天", "action": null, "to": "经理审批" },
"请假天数大于等于3天": { "name": "请假天数大于等于3天", "action": null, "to": "老板审批" }
}
"请假天数小于3天": {
"name": "请假天数小于3天",
"to": "经理审批"
},
"请假天数大于等于3天": {
"name": "请假天数大于等于3天",
"to": "老板审批"
}
},
"name": "自动审批",
"type": "auto",
"target": "auto.xjson"
},
"老板审批": {
"form": "/boss.htnl", "name": "老板审批", "type": "task", "user": "owner",
"form": "/boss.htnl",
"transfers": {
"拒绝": { "name": "拒绝", "action": null, "to": "请假失败" },
"驳回": { "name": "驳回", "action": null, "to": "提交请假单" },
"同意": { "name": "同意", "action": null, "to": "请假成功" }
}
"拒绝": {
"name": "拒绝",
"to": "请假失败"
},
"驳回": {
"name": "驳回",
"to": "提交请假单"
},
"同意": {
"name": "同意",
"to": "请假成功"
}
},
"name": "老板审批",
"type": "task",
"user": "boss"
},
"请假失败": {
"name": "请假失败",
"type": "end"
},
"经理审批": {
"form": "manager.html", "name": "经理审批", "type": "task", "user": "owner",
"form": "manager.html",
"transfers": {
"拒绝": { "name": "拒绝", "action": null, "to": "请假失败" },
"驳回": { "name": "驳回", "action": null, "to": "提交请假单" },
"同意": { "name": "同意", "action": null, "to": "请假成功" }
}
},
"请假成功": { "name": "请假成功", "type": "end" },
"请假失败": { "name": "请假失败", "type": "end" }
}
"拒绝": {
"name": "拒绝",
"to": "请假失败"
},
"驳回": {
"name": "驳回",
"to": "提交请假单"
},
"同意": {
"name": "同意",
"to": "请假成功"
}
},
"name": "经理审批",
"type": "task",
"user": "manager"
}
},
"start": "开始",
"title": "测试4"
}
\ No newline at end of file
package com.egolm.workflow;
package com.egolm.workflow.test;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.workflow.AbstractOpenApi;
@Service
public class TestApiImpl extends AbstractOpenApi {
@Autowired
private JdbcTemplate jdbcTemplate;
public TestApiImpl(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public JdbcTemplate getFlowDBTemplate() {
return this.jdbcTemplate;
}
@Override
public Map<String, Object> runApi(String api, Map<String, Object> args) {
// TODO Auto-generated method stub
return null;
public Object runApi(String api, Map<String, Object> args) {
Object result = null;
if(api.equals("auto.xjson")) {
result = "请假天数小于3天";
}
return result;
}
@Override
public boolean isReferenceApi(String string) {
// TODO Auto-generated method stub
return false;
}
@Override
public String parseFlowSettings(String jsonData) {
// TODO Auto-generated method stub
return null;
}
......
package com.egolm.workflow.test;
import java.beans.PropertyVetoException;
import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import com.egolm.workflow.AbstractOpenApi;
import com.egolm.workflow.bean.TFlowTask;
public class TestApplication {
private final String flowName = "测试4";
private final String owner = "quxinliang";
private final String manager = "hanxu";
private final String formId = "Leave_001";
private AbstractOpenApi openApi = null;
@Before
public void init() throws PropertyVetoException, SQLException {
openApi = new TestApiImpl(TestConfig.getJdbcTemplate());
}
@Test
public void exec(){
TFlowTask task = openApi.start(flowName, owner, null);
Map<String, Object> vars = new LinkedHashMap<String, Object>();
vars.put("id", formId);
openApi.accept(task.getsTaskID(), owner);
task = openApi.commit(task.getsTaskID(), "提交请假单", "流程发起人提交请假单", owner, vars);
openApi.accept(task.getsTaskID(), manager);
task = openApi.commit(task.getsTaskID(), "同意", "经理批准请假", manager, null);
}
}
package com.egolm.workflow.test;
import java.beans.PropertyVetoException;
import java.sql.SQLException;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.dialect.SqlServerDialect;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class TestConfig {
private static JdbcTemplate jdbcTemplate;
public static JdbcTemplate getJdbcTemplate() throws PropertyVetoException, SQLException {
if(jdbcTemplate == null) {
ComboPooledDataSource ds = new ComboPooledDataSource("db");
jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setDataSource(ds);
jdbcTemplate.setDialect(new SqlServerDialect());
jdbcTemplate.setSql_level(3);
}
return jdbcTemplate;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<default-config>
<property name="checkoutTimeout">30000</property>
<property name="initialPoolSize">10</property>
<property name="maxIdleTime">30</property>
<property name="maxPoolSize">100</property>
<property name="minPoolSize">10</property>
<property name="maxStatements">200</property>
</default-config>
<named-config name="db">
<property name="driverClass">net.sourceforge.jtds.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:jtds:sqlserver://10.10.0.51:56443;instanceName=SQLSERVER;DatabaseName=Maven</property>
<property name="user">sa</property>
<property name="password">qiyang</property>
</named-config>
</c3p0-config>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_BASE_PATH" value="/data/logs/xflow" />
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="cn" level="DEBUG" />
<logger name="org" level="DEBUG" />
<logger name="com" level="DEBUG" />
<logger name="com.egolm" level="DEBUG" />
<appender name="siftingAppender" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator>
<key>CTX_PATH</key>
<DefaultValue>logback</DefaultValue>
</discriminator>
<sift>
<appender name="rollingFileAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_BASE_PATH}/${CTX_PATH}-%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
</sift>
</appender>
<root level="INFO">
<appender-ref ref="siftingAppender" />
</root>
</configuration>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment