.addInputStream("hello.drl", new FileInputStream(ruleFile))
.deploy();
RuntimeService runtimeService = activitiRule.getRuntimeService();
Map<String, Object> variableMap = new HashMap<String, Object>();
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
variableMap.put("m", message);
ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey("drools", variableMap);
assertNotNull(processInstance.getId());
System.out.println("id " + processInstance.getId() + " "
+ processInstance.getProcessDefinitionId());
/*
// 从运行中查询
Object variable = runtimeService.getVariable(processInstance.getId(),
"rulesOutput");
assertNotNull(variable);
List<Object> varList = (List<Object>) variable;
assertEquals(1, varList.size());
Message ruledMessage = (Message) varList.get(0);
assertEquals(1, ruledMessage.getStatus());*/
HistoryService historyService = activitiRule.getHistoryService();
long count = historyService.createHistoricProcessInstanceQuery()
.finished().count();
assert count == 1;
// 从history查询变量
List<HistoricDetail> list = historyService.createHistoricDetailQuery()
.processInstanceId(processInstance.getId()).list();
for (HistoricDetail historicDetail : list) {
HistoricVariableUpdate variableDetail = (HistoricVariableUpdate) historicDetail;
System.out.println(variableDetail.getVariableName() + " = "
+ variableDetail.getValue());
if (variableDetail.getVariableName().equals("rulesOutput")) {
@SuppressWarnings("unchecked")
List<Object> varList = (List<Object>) variableDetail.getValue();
assertEquals(1, varList.size());
Message ruledMessage = (Message) varList.get(0);
assertEquals(1, ruledMessage.getStatus());
}
}
}