org.infoglue.cms.util
Class WorkflowTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.infoglue.cms.util.InfoGlueTestCase
              extended by org.infoglue.cms.util.WorkflowTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
NewsWorkflowTestCase

public abstract class WorkflowTestCase
extends InfoGlueTestCase

Base class for workflow tests. Uses the "Create News" sample workflow. We don't do the "Preview news and approve" step because we don't want to deal with saving content that we have to clean up later. Going through the first step should suffice to demonstrate that the right things are happening as far as the workflow is concerned. It is easy enough to hook up "Preview news and approve" if it turns out that testing the step is worth the headache of figuring out which content to remove when the test finishes.

Author:
Jed Prentice

Field Summary
static int FINISH_WORKFLOW
          The ID of the global action "Finish Workflow".
 
Constructor Summary
WorkflowTestCase()
           
 
Method Summary
protected  void assertWorkflowFinished()
          Asserts the the current workflow is finished by verifying that no workflow with workflowId is in the list of current workflows.
protected  void checkActions(int expectedSize, java.util.List actions)
          Verifies that each action in the list has at least a couple of critical properties defined
protected  void checkWorkflow(int currentSteps, int historySteps, int availableActions)
          Verifies that workflow is what we expect
protected  WorkflowVO findCurrentWorkflow()
          Finds the current workflow that matches workflowId
protected  WorkflowVO findWorkflow(java.util.List workflows)
          Finds the workflow in the given list that matches workflowId.
protected  WorkflowVO findWorkflowByName(java.util.List workflows)
          Finds the workflow in the given list that matches the name of the workflow under test
protected  void finishWorkflow()
          Invokes the "Finish Workflow" action.
protected  int getNumberOfGlobalActions()
          Returns the number of global actions.
protected  int getNumberOfInitialActions()
          Returns the number of initial actions.
protected  com.opensymphony.module.propertyset.PropertySet getPropertySet()
           
protected  InfoGluePrincipal getUserPrincipal()
           
protected  WorkflowVO getWorkflow()
           
protected  long getWorkflowId()
           
protected abstract  java.lang.String getWorkflowName()
          Subclasses must supply the workflow name
protected  void invokeAction(javax.servlet.http.HttpServletRequest request, int actionId)
          Invokes a workflow action
protected static void printActions(java.util.List actions)
          Prints the given list of actions to stdout
protected static void printAvailableActions(WorkflowVO workflow)
          Prints all available actions for the give workflow to stdout
protected static void printSteps(java.util.List steps)
          Prints a list of steps to stdout
protected static void printWorkflows(java.util.List workflows)
          Prints the workflows in the list to stdout.
protected  void setUserPrincipal(InfoGluePrincipal userPrincipal)
           
protected  void setWorkflow(WorkflowVO workflow)
           
protected  void startWorkflow(int initialAction)
          Starts the workflow by creating a new workflow instance and assigning it to workflow
 
Methods inherited from class org.infoglue.cms.util.InfoGlueTestCase
changeDate, changeDate, createRole, getAdminPrincipal, getAnonPrincipal, getCmsUserPrincipal, getLanguageId, getLanguageId, getRepoId, getSiteNodeId, getSiteNodeId, initializeInfoGlue, setUp
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FINISH_WORKFLOW

public static final int FINISH_WORKFLOW
The ID of the global action "Finish Workflow". Since this ID is the same for both Create News and Create User, we can get away with hard-coding it for now.

See Also:
Constant Field Values
Constructor Detail

WorkflowTestCase

public WorkflowTestCase()
Method Detail

getWorkflowName

protected abstract java.lang.String getWorkflowName()
Subclasses must supply the workflow name

Returns:
the name of the workflow under test

getNumberOfInitialActions

protected int getNumberOfInitialActions()
Returns the number of initial actions. Since there must be at least one intial action, this implementation returns 1. Subclasses should override if the workflow under test has multiple initial actions.

Returns:
the number of initial actions

getNumberOfGlobalActions

protected int getNumberOfGlobalActions()
Returns the number of global actions. Subclasses should override if the workflow under test has global actions; this default implementation returns zero.

Returns:
the number of global actions

getWorkflow

protected WorkflowVO getWorkflow()

setWorkflow

protected void setWorkflow(WorkflowVO workflow)

getWorkflowId

protected long getWorkflowId()

getPropertySet

protected com.opensymphony.module.propertyset.PropertySet getPropertySet()

getUserPrincipal

protected InfoGluePrincipal getUserPrincipal()

setUserPrincipal

protected void setUserPrincipal(InfoGluePrincipal userPrincipal)

startWorkflow

protected void startWorkflow(int initialAction)
                      throws java.lang.Exception
Starts the workflow by creating a new workflow instance and assigning it to workflow

Throws:
java.lang.Exception
See Also:
setWorkflow(org.infoglue.cms.entities.mydesktop.WorkflowVO)

finishWorkflow

protected void finishWorkflow()
                       throws java.lang.Exception
Invokes the "Finish Workflow" action. Does not delete. Clearing the tables is tricky due to FK constraints in the OSWorkflow tables, although we should eventually figure out how to do it. For now we'll have to live with finishing the workflow but leaving all the dead ones we create behind in the DB. For mysql, periodically use the script testsrc/etc/clean-workflows.sql to clean up.

Throws:
java.lang.Exception - if an error occurs

invokeAction

protected void invokeAction(javax.servlet.http.HttpServletRequest request,
                            int actionId)
                     throws java.lang.Exception
Invokes a workflow action

Parameters:
request - the HTTP request (or simulation thereof)
actionId - the ID of the desired workflow action
Throws:
java.lang.Exception - if an error occurs

checkWorkflow

protected void checkWorkflow(int currentSteps,
                             int historySteps,
                             int availableActions)
Verifies that workflow is what we expect

Parameters:
currentSteps - the expected number of current steps
historySteps - the expected number of history steps
availableActions - the expected number of available actions

checkActions

protected void checkActions(int expectedSize,
                            java.util.List actions)
Verifies that each action in the list has at least a couple of critical properties defined

Parameters:
expectedSize - the expected size of the list
actions - a list of WorkflowActionVOs

assertWorkflowFinished

protected void assertWorkflowFinished()
                               throws java.lang.Exception
Asserts the the current workflow is finished by verifying that no workflow with workflowId is in the list of current workflows.

Throws:
java.lang.Exception - if an error occurs.

findCurrentWorkflow

protected WorkflowVO findCurrentWorkflow()
                                  throws java.lang.Exception
Finds the current workflow that matches workflowId

Returns:
the WorkflowVO whose ID matches workflowId, or null if no match is found
Throws:
java.lang.Exception - if an error occurs

findWorkflow

protected WorkflowVO findWorkflow(java.util.List workflows)
Finds the workflow in the given list that matches workflowId.

Parameters:
workflows - a list of WorkflowVOs
Returns:
the WorkflowVO whose ID matches workflowId, or null if no match is found

findWorkflowByName

protected WorkflowVO findWorkflowByName(java.util.List workflows)
Finds the workflow in the given list that matches the name of the workflow under test

Parameters:
workflows - a list of WorkflowVOs
Returns:
the WorkflowVO whose ID matches workflowId, or null if no match is found

printWorkflows

protected static void printWorkflows(java.util.List workflows)
Prints the workflows in the list to stdout.

Parameters:
workflows - a list of WorkflowVOs

printSteps

protected static void printSteps(java.util.List steps)
Prints a list of steps to stdout

Parameters:
steps - a list of WorkflowStepVOs to print

printAvailableActions

protected static void printAvailableActions(WorkflowVO workflow)
Prints all available actions for the give workflow to stdout

Parameters:
workflow - the workflow whoise actions will be printed

printActions

protected static void printActions(java.util.List actions)
Prints the given list of actions to stdout

Parameters:
actions - a list of WorkflowActionVOs


Copyright © 2005 InfoGlue.org All Rights Reserved.