public void testBuildApprovalWorkflow() throws WikiException
{
Principal submitter = new WikiPrincipal( "Submitter" );
String workflowApproverKey = "workflow.approvalWorkflow";
Task prepTask = new TestPrepTask( "task.preSaveWikiPage" );
String decisionKey = "decision.saveWikiPage";
Fact[] facts = new Fact[3];
facts[0] = new Fact("fact1",new Integer(1));
facts[1] = new Fact("fact2","A factual String");
facts[2] = new Fact("fact3",Outcome.DECISION_ACKNOWLEDGE);
Task completionTask = new TestPrepTask( "task.saveWikiPage" );
String rejectedMessageKey = "notification.saveWikiPage.reject";
Workflow w = m_builder.buildApprovalWorkflow(submitter, workflowApproverKey,
prepTask, decisionKey, facts,
completionTask, rejectedMessageKey);
w.setWorkflowManager( m_engine.getWorkflowManager() );
// Check to see if the workflow built correctly
assertFalse( w.isStarted() || w.isCompleted() || w.isAborted() );
assertNull( w.getCurrentStep() );
assertEquals( "workflow.approvalWorkflow", w.getMessageKey() );
assertEquals( Workflow.CREATED, w.getCurrentState() );
assertEquals( new WikiPrincipal("Submitter"), w.getOwner() );
assertEquals( m_engine.getWorkflowManager(), w.getWorkflowManager() );
assertEquals( 0, w.getHistory().size() );
// Our dummy "task complete" attributes should still be null
assertNull( w.getAttribute( "task.preSaveWikiPage") );
assertNull( w.getAttribute( "task.saveWikiPage") );
// Start the workflow
w.start();
// Presave complete attribute should be set now, and current step should be Decision
Step decision = w.getCurrentStep();
assertTrue( decision instanceof Decision );
assertEquals( 2, w.getHistory().size() );
assertEquals( prepTask, w.getHistory().get( 0 ) );
assertTrue( w.getHistory().get( 1 ) instanceof Decision );
assertNotNull( w.getAttribute( "task.preSaveWikiPage") );
assertEquals( new WikiPrincipal( Users.JANNE ), decision.getActor() );
assertEquals( decisionKey, decision.getMessageKey() );
List decisionFacts = ((Decision)decision).getFacts();
assertEquals( 3, decisionFacts.size() );
assertEquals( facts[0], decisionFacts.get(0) );
assertEquals( facts[1], decisionFacts.get(1) );