assertEquals("Unexpected number of history steps", 7, historySteps.size());
assertEquals("Unexpected number of history steps", 8, historySteps.size());
    public void testExampleWorkflow() throws Exception {        WorkflowQuery query;        String workflowName = getClass().getResource("/samples/example.xml").toString();        assertTrue("canInitialize for workflow " + workflowName + " is false", workflow.canInitialize(workflowName, 1));        long workflowId = workflow.initialize(workflowName, 1, 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).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(2, 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());        //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", 4, 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", 7, 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");        }    }