/*
* Copyright 2007-2009 非也
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License 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 General Public License
* along with this program. If not, see http://www.gnu.org/licenses.
*/
package org.fireflow.engine;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.fireflow.engine.persistence.IPersistenceService;
import org.fireflow.engine.taskinstance.CurrentUserAssignmentHandlerMock;
import org.fireflow.engine.test.support.FireFlowAbstractTests;
import org.fireflow.kernel.IToken;
import org.fireflow.kernel.KernelException;
import org.junit.Test;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
/**
*
* @author 非也
* @version 1.0
* Created on Apr 11, 2009
*/
public class WithdrawAndRejectTest extends FireFlowAbstractTests {
//--------constant----------------------
//本流程用到
private final static Integer flag = 0;//"123123123123";
//-----variables-----------------
static IProcessInstance currentProcessInstance = null;
static String workItem1Id = null;
static String workItem2Id = null;
static String workItem3Id = null;
static String workItem4Id = null;
static String workItem5Id = null;
static String workItem6Id = null;
static String workItem7Id = null;
static String workItem8Id = null;
static String workItem9Id = null;
@Test
public void testStartProcessAndCompleteWorkItem1() {
currentProcessInstance = (IProcessInstance) transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IProcessInstance processInstance = workflowSession.createProcessInstance("WithdrawAndReject","fireflowTester");
processInstance.run();
return processInstance;
} catch (EngineException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (KernelException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
});
assertNotNull(currentProcessInstance);
IPersistenceService persistenceService = runtimeContext.getPersistenceService();
List taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity1");
assertNotNull(taskInstanceList);
assertEquals(1, taskInstanceList.size());
assertEquals(new Integer(ITaskInstance.RUNNING), ((ITaskInstance) taskInstanceList.get(0)).getState());
assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());
List tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
assertNotNull(tokenList);
assertEquals(1, tokenList.size());
IToken token = (IToken) tokenList.get(0);
assertEquals(1, token.getStepNumber().intValue());
List workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity1.Task1");
assertNotNull(workItemList);
assertEquals(1, workItemList.size());
assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());
workItem1Id = ((IWorkItem) workItemList.get(0)).getId();
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IWorkItem workItem = workflowSession.findWorkItemById(workItem1Id);
workItem.claim();
workItem.complete();
} catch (EngineException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (KernelException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
});
workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity2.Task2");
assertNotNull(workItemList);
assertEquals(1, workItemList.size());
assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());
workItem2Id = ((IWorkItem) workItemList.get(0)).getId();
}
/**
*
*/
@Test
public void testWithdrawFromWorkItem1() {
currentProcessInstance = (IProcessInstance) transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IProcessInstance processInstance = workflowSession.createProcessInstance("WithdrawAndReject","fireflowTester");
processInstance.run();
return processInstance;
} catch (EngineException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (KernelException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
});
assertNotNull(currentProcessInstance);
IPersistenceService persistenceService = runtimeContext.getPersistenceService();
List taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "WithdrawAndReject.Activity1");
assertNotNull(taskInstanceList);
assertEquals(1, taskInstanceList.size());
assertEquals(new Integer(ITaskInstance.RUNNING), ((ITaskInstance) taskInstanceList.get(0)).getState());
assertEquals(1, ((ITaskInstance) taskInstanceList.get(0)).getStepNumber().intValue());
List tokenList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
assertNotNull(tokenList);
assertEquals(1, tokenList.size());
IToken token = (IToken) tokenList.get(0);
assertEquals(1, token.getStepNumber().intValue());
List workItemList = persistenceService.findTodoWorkItems(CurrentUserAssignmentHandlerMock.ACTOR_ID, "WithdrawAndReject", "WithdrawAndReject.Activity1.Task1");
assertNotNull(workItemList);
assertEquals(1, workItemList.size());
assertEquals(new Integer(IWorkItem.INITIALIZED), ((IWorkItem) workItemList.get(0)).getState());
workItem1Id = ((IWorkItem) workItemList.get(0)).getId();
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWor