// there should be 1 task instance created in the business process
Collection allTaskInstances = businessProcessInstance.getTaskMgmtInstance().getTaskInstances();
assertNotNull(allTaskInstances);
assertEquals(1, allTaskInstances.size());
TaskInstance taskInstance = (TaskInstance) allTaskInstances.iterator().next();
document = (Document) taskInstance.getVariable("document");
assertEquals("blablabla", document.getText());
// Now SEAM will handle the page flow that is specified here:
ProcessDefinition pageFlowDefinition = ProcessDefinition.parseXmlString(
"<process-definition name='approve document task'>" +
" <start-state name='start page flow'>" +
" <transition to='review' />" +
" </start-state>" +
" <page name='review' url='review.jsp'>" +
" <transition name='approve' to='approved' />" +
" <transition name='reject' to='rejected' />" +
" </page>" +
" <page name='approved' url='approved.jsp'>" +
" <conversation-end outcome='approveDocument' />" +
" </page>" +
" <page name='rejected' url='rejected.jsp'>" +
" <conversation-end outcome='rejectDocument' />" +
" </page>" +
"</process-definition>"
);
// A new page flow process is started
ProcessInstance pageFlowInstance = new ProcessInstance(pageFlowDefinition);
Token pageFlowToken = pageFlowInstance.getRootToken();
// This page flow is in the context of a specific user that
// clicked an entry in his task list. The task instance is
// injected as a process context variable
contextInstance = pageFlowInstance.getContextInstance();
contextInstance.setVariable("taskInstance", taskInstance);
// With the task instance information, the page flow process is started
// and can now decide which is the first page to show the user
pageFlowInstance.signal();
// SEAM can expect that when a wait state is entered, the main
// path of execution is positioned in a page. That page
// contains the url that SEAM should render.
// In this simple page flow process, we always start with the
// review page.
Page page = (Page) pageFlowToken.getNode();
assertNotNull(page);
assertEquals("review", page.getName());
assertEquals("review.jsp", page.getUrl());
// so now, the SEAM page flow renders the review page.
// in review.jsp, the EL expression "taskInstance[document].text" should resolve
// to 'blablabla'
taskInstance = (TaskInstance) contextInstance.getVariable("taskInstance");
document = (Document) taskInstance.getVariable("document");
assertEquals("blablabla", document.getText());
assertEquals("business process review task", taskInstance.getName());
// suppose the user presses the approve button
pageFlowToken.signal("approve");
// now the page flow process should have moved to the
// approved page with the approved.jsp
page = (Page) pageFlowToken.getNode();
assertNotNull(page);
assertEquals("approved", page.getName());
assertEquals("approved.jsp", page.getUrl());
// ...and, the business process task instance should have ended.
assertTrue(taskInstance.hasEnded());
// causing the business process to move to the next state
assertEquals("file horizontally", businessToken.getNode().getName());
}