⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractfunctionalworkflowtest.java

📁 Java编译osworkflow工作流系统的安装和源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2002-2003 by OpenSymphony * All rights reserved. */package com.opensymphony.workflow.spi;import com.opensymphony.user.EntityNotFoundException;import com.opensymphony.user.Group;import com.opensymphony.user.User;import com.opensymphony.user.UserManager;import com.opensymphony.workflow.AbstractWorkflow;import com.opensymphony.workflow.QueryNotSupportedException;import com.opensymphony.workflow.Workflow;import com.opensymphony.workflow.WorkflowException;import com.opensymphony.workflow.basic.BasicWorkflow;import com.opensymphony.workflow.loader.WorkflowDescriptor;import com.opensymphony.workflow.query.Expression;import com.opensymphony.workflow.query.FieldExpression;import com.opensymphony.workflow.query.NestedExpression;import com.opensymphony.workflow.query.WorkflowExpressionQuery;import com.opensymphony.workflow.query.WorkflowQuery;import junit.framework.TestCase;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import java.util.Collections;import java.util.Date;import java.util.HashMap;import java.util.List;import java.util.Map;/** * This test case is functional in that it attempts to validate the entire * lifecycle of a workflow.  This is also a good resource for beginners * to OSWorkflow.  This class is extended to for various SPI's. * * @author Eric Pugh (epugh@upstate.com) */public abstract class AbstractFunctionalWorkflowTest extends TestCase {    //~ Static fields/initializers /////////////////////////////////////////////    private static final String USER_TEST = "test";    //~ Instance fields ////////////////////////////////////////////////////////    protected Log log;    protected Workflow workflow;    protected WorkflowDescriptor workflowDescriptor;    //~ Constructors ///////////////////////////////////////////////////////////    public AbstractFunctionalWorkflowTest(String s) {        super(s);        log = LogFactory.getLog(getClass());    }    //~ Methods ////////////////////////////////////////////////////////////////    public void testExampleWorkflow() throws Exception {        WorkflowQuery query;        String workflowName = getWorkflowName();        assertTrue("canInitialize for workflow " + workflowName + " is false", workflow.canInitialize(workflowName, 100));        long workflowId = workflow.initialize(workflowName, 100, new HashMap());        String workorderName = workflow.getWorkflowName(workflowId);        workflowDescriptor = workflow.getWorkflowDescriptor(workorderName);        if (log.isDebugEnabled()) {            log.debug("Name of workorder:" + workorderName);        }        assertTrue("Expected external-permission permA in step 1 not found", workflow.getSecurityPermissions(workflowId, null).contains("permA"));        List currentSteps = workflow.getCurrentSteps(workflowId);        assertEquals("Unexpected number of current steps", 1, currentSteps.size());        assertEquals("Unexpected current step", 1, ((Step) currentSteps.get(0)).getStepId());        List historySteps = workflow.getHistorySteps(workflowId);        assertEquals("Unexpected number of history steps", 0, historySteps.size());        if (log.isDebugEnabled()) {            log.debug("Perform Finish First Draft");        }        workflow.doAction(workflowId, 1, Collections.EMPTY_MAP);        int[] actions = workflow.getAvailableActions(workflowId, Collections.EMPTY_MAP);        assertEquals(3, actions.length);        historySteps = workflow.getHistorySteps(workflowId);        assertEquals("Unexpected number of history steps", 1, historySteps.size());        Step historyStep = (Step) historySteps.get(0);        assertEquals(USER_TEST, historyStep.getCaller());        assertNull(historyStep.getDueDate());        // check system date, add in a 1 second fudgefactor.        assertTrue("history step finish date " + historyStep.getFinishDate() + " is in the future!", (historyStep.getFinishDate().getTime() - 1000) < System.currentTimeMillis());        logActions(actions);        if (log.isDebugEnabled()) {            log.debug("Perform Finish Foo");        }        workflow.doAction(workflowId, 12, Collections.EMPTY_MAP);        //Step lastHistoryStep = historyStep;        historySteps = workflow.getHistorySteps(workflowId);        assertEquals("Unexpected number of history steps", 2, historySteps.size());        if (log.isDebugEnabled()) {            log.debug("Perform Stay in Bar");        }        workflow.doAction(workflowId, 113, Collections.EMPTY_MAP);        actions = workflow.getAvailableActions(workflowId, Collections.EMPTY_MAP);        assertEquals(2, actions.length);        assertTrue((actions[0] == 13) && (actions[1] == 113));        logActions(actions);        //historyStep = (Step) historySteps.get(0);        //assertEquals(lastHistoryStep.getId(), historyStep.getId());        if (log.isDebugEnabled()) {            log.debug("Perform Finish Bar");        }        workflow.doAction(workflowId, 13, Collections.EMPTY_MAP);        actions = workflow.getAvailableActions(workflowId, Collections.EMPTY_MAP);        assertEquals(1, actions.length);        logActions(actions);        if (log.isDebugEnabled()) {            log.debug("Perform Finish Baz");        }        workflow.doAction(workflowId, 14, Collections.EMPTY_MAP);        actions = workflow.getAvailableActions(workflowId, Collections.EMPTY_MAP);        logActions(actions);        historySteps = workflow.getHistorySteps(workflowId);        assertEquals("Unexpected number of history steps", 5, historySteps.size());        if (log.isDebugEnabled()) {            log.debug("Perform Finish Editing");        }        workflow.doAction(workflowId, 3, Collections.EMPTY_MAP);        actions = workflow.getAvailableActions(workflowId, Collections.EMPTY_MAP);        assertEquals(3, actions.length);        logActions(actions);        if (log.isDebugEnabled()) {            log.debug("Perform Publish Doc");        }        workflow.doAction(workflowId, 7, Collections.EMPTY_MAP);        actions = workflow.getAvailableActions(workflowId, Collections.EMPTY_MAP);        assertEquals(1, actions.length);        logActions(actions);        if (log.isDebugEnabled()) {            log.debug("Perform Publish Document");        }        workflow.doAction(workflowId, 11, Collections.EMPTY_MAP);        actions = workflow.getAvailableActions(workflowId, Collections.EMPTY_MAP);        assertEquals(0, actions.length);        historySteps = workflow.getHistorySteps(workflowId);        assertEquals("Unexpected number of history steps", 8, historySteps.size());        query = new WorkflowQuery(WorkflowQuery.OWNER, WorkflowQuery.CURRENT, WorkflowQuery.EQUALS, USER_TEST);        try {            List workflows = workflow.query(query);            assertEquals("Unexpected number of workflow query results", 1, workflows.size());            WorkflowQuery queryLeft = new WorkflowQuery(WorkflowQuery.OWNER, WorkflowQuery.CURRENT, WorkflowQuery.EQUALS, USER_TEST);            WorkflowQuery queryRight = new WorkflowQuery(WorkflowQuery.STATUS, WorkflowQuery.CURRENT, WorkflowQuery.EQUALS, "Finished");            query = new WorkflowQuery(queryLeft, WorkflowQuery.AND, queryRight);            workflows = workflow.query(query);            assertEquals("Unexpected number of workflow query results", 1, workflows.size());        } catch (QueryNotSupportedException ex) {            System.out.println("query not supported");        }    }    public void testExceptionOnIllegalStayInCurrentStep() throws Exception {        String workflowName = getWorkflowName();        assertTrue("canInitialize for workflow " + workflowName + " is false", workflow.canInitialize(workflowName, 100));        try {            long workflowId = workflow.initialize(workflowName, 200, new HashMap());            fail("initial action result specified target step of current step. Succeeded but should not have.");        } catch (WorkflowException e) {            // expected, no such thing as current step for initial action        }    }    public void testMetadataAccess() throws Exception {        String workflowName = getWorkflowName();        long workflowId = workflow.initialize(workflowName, 100, new HashMap());        WorkflowDescriptor wfDesc = workflow.getWorkflowDescriptor(workflowName);        Map meta = wfDesc.getMetaAttributes();        assertTrue("missing metadata", (meta.get("workflow-meta1")).equals("workflow-meta1-value"));        assertTrue("missing metadata", (meta.get("workflow-meta2")).equals("workflow-meta2-value"));        meta = wfDesc.getStep(1).getMetaAttributes();        assertTrue("missing metadata", (meta.get("step-meta1")).equals("step-meta1-value"));        assertTrue("missing metadata", (meta.get("step-meta2")).equals("step-meta2-value"));        meta = wfDesc.getAction(1).getMetaAttributes();        assertTrue("missing metadata", (meta.get("action-meta1")).equals("action-meta1-value"));        assertTrue("missing metadata", (meta.get("action-meta2")).equals("action-meta2-value"));    }    public void testWorkflowExpressionQuery() throws Exception {        List workflows;        WorkflowExpressionQuery query;        String workflowName = getWorkflowName();        assertTrue("canInitialize for workflow " + workflowName + " is false", workflow.canInitialize(workflowName, 100));        //-------------------   FieldExpression.OWNER  +  FieldExpression.CURRENT_STEPS ----------------------        query = new WorkflowExpressionQuery(new FieldExpression(FieldExpression.OWNER, FieldExpression.CURRENT_STEPS, FieldExpression.EQUALS, USER_TEST));        try {            workflows = workflow.query(query);            assertEquals("empty OWNER+CURRENT_STEPS", 0, workflows.size());        } catch (QueryNotSupportedException e) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -