/** * Copyright 2007-2010 非也 * All rights reserved. * * This library is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License v3 as published by the Free Software * Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along * with this library; if not, see http://www.gnu.org/licenses/lgpl.html. * */ package org.fireflow.client.impl; import java.io.IOException; import java.io.InputStream; import org.fireflow.FireWorkflowJunitEnviroment; import org.fireflow.client.WorkflowSession; import org.fireflow.client.WorkflowSessionFactory; import org.fireflow.client.WorkflowStatement; import org.fireflow.engine.entity.runtime.ProcessInstance; import org.fireflow.engine.exception.InvalidOperationException; import org.fireflow.engine.exception.WorkflowProcessNotFoundException; import org.fireflow.engine.modules.ousystem.impl.FireWorkflowSystem; import org.fireflow.model.InvalidModelException; import org.fireflow.model.io.DeserializerException; import org.fireflow.pdl.fpdl.io.FPDLDeserializer; import org.fireflow.pdl.fpdl.misc.FpdlConstants; import org.fireflow.pdl.fpdl.process.WorkflowProcess; import org.junit.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; /** * * @author 非也 nychen2000@163.com * Fire Workflow 官方网站:www.firesoa.com 或者 www.fireflow.org * */ public class WorkflowStatementSetVariableValueTest extends FireWorkflowJunitEnviroment { @SuppressWarnings("unchecked") @Test public void testSetVariableValue() { final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(fireflowRuntimeContext,FireWorkflowSystem.getInstance()); final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20); final ProcessInstance procInst = (ProcessInstance)transactionTemplate.execute(new TransactionCallback(){ public Object doInTransaction(TransactionStatus arg0) { //构建流程定义 WorkflowProcess process = getWorkflowProcess(); //启动流程 ProcessInstance processInstance = null; try { processInstance = stmt.createProcessInstance(process); if (processInstance!=null){ processInstanceId = processInstance.getId(); } return processInstance; } catch (InvalidModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }); //设置流程变量 transactionTemplate.execute(new TransactionCallback(){ public Object doInTransaction(TransactionStatus arg0) { try { stmt.setVariableValue(procInst, "result", 24); } catch (InvalidOperationException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }); } /* (non-Javadoc) * @see org.fireflow.FireWorkflowJunitEnviroment#createWorkflowProcess() */ @Override public WorkflowProcess createWorkflowProcess() { InputStream instream = WorkflowStatementSetVariableValueTest.class.getResourceAsStream("WorkflowStatementSetVariableValueTest.f20.xml"); FPDLDeserializer des = new FPDLDeserializer(); WorkflowProcess process = null; try { process = des.deserialize(instream); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DeserializerException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return process; } }