long workflowId2 = workflow.initialize(workflowName, 1, Collections.EMPTY_MAP); workflow.changeEntryState(workflowId, WorkflowEntry.SUSPENDED); queryRight = new FieldExpression(FieldExpression.STATE, FieldExpression.ENTRY, FieldExpression.EQUALS, new Integer(WorkflowEntry.ACTIVATED)); queryLeft = new FieldExpression(FieldExpression.STATE, FieldExpression.ENTRY, FieldExpression.EQUALS, new Integer(WorkflowEntry.SUSPENDED)); query = new WorkflowExpressionQuery(new NestedExpression(new Expression[] { queryLeft, queryRight }, NestedExpression.OR)); workflows = workflow.query(query); assertEquals(2, workflows.size());
    public void testWorkflowExpressionQuery() throws Exception {        WorkflowExpressionQuery query = new WorkflowExpressionQuery(new FieldExpression(FieldExpression.OWNER, FieldExpression.CURRENT_STEPS, FieldExpression.EQUALS, USER_TEST));        List workflows;        String workflowName = getClass().getResource("/samples/example.xml").toString();        assertTrue("canInitialize for workflow " + workflowName + " is false", workflow.canInitialize(workflowName, 1));        try {            workflows = workflow.query(query);            assertEquals(0, workflows.size());        } catch (QueryNotSupportedException e) {            log.error("Store does not support query");            return;        }        long workflowId = workflow.initialize(workflowName, 1, new HashMap());        workflows = workflow.query(query);        assertEquals(1, workflows.size());        Expression queryLeft = new FieldExpression(FieldExpression.OWNER, FieldExpression.CURRENT_STEPS, FieldExpression.EQUALS, USER_TEST);        Expression queryRight = new FieldExpression(FieldExpression.STATUS, FieldExpression.CURRENT_STEPS, FieldExpression.EQUALS, "Finished");        query = new WorkflowExpressionQuery(new NestedExpression(new Expression[] {                        queryLeft, queryRight                    }, NestedExpression.AND));        try {            workflows = workflow.query(query);            assertEquals(0, workflows.size());        } catch (QueryNotSupportedException e) {            log.error("Store does not support query");            return;        }        queryRight = new FieldExpression(FieldExpression.STATUS, FieldExpression.CURRENT_STEPS, FieldExpression.EQUALS, "Underway");        query = new WorkflowExpressionQuery(new NestedExpression(new Expression[] {                        queryLeft, queryRight                    }, NestedExpression.AND));        workflows = workflow.query(query);        assertEquals(1, workflows.size());        //there should be one step that has been started        workflows = workflow.query(new WorkflowExpressionQuery(new FieldExpression(FieldExpression.START_DATE, FieldExpression.CURRENT_STEPS, FieldExpression.LT, new Date())));        assertEquals("Expected to find one workflow step that was started", 1, workflows.size());        //there should be no steps that have been completed        workflows = workflow.query(new WorkflowExpressionQuery(new FieldExpression(FieldExpression.FINISH_DATE, FieldExpression.HISTORY_STEPS, FieldExpression.LT, new Date())));        assertEquals("Expected to find no history steps that were completed", 0, workflows.size());        workflow.doAction(workflowId, 1, Collections.EMPTY_MAP);        //there should be two step that have been started        workflows = workflow.query(new WorkflowExpressionQuery(new FieldExpression(FieldExpression.START_DATE, FieldExpression.HISTORY_STEPS, FieldExpression.LT, new Date())));        assertEquals("Expected to find 2 workflow steps that were started", 1, workflows.size());        //there should be 1 steps that has been completed        workflows = workflow.query(new WorkflowExpressionQuery(new FieldExpression(FieldExpression.FINISH_DATE, FieldExpression.HISTORY_STEPS, FieldExpression.LT, new Date())));        assertEquals("Expected to find 1 history steps that was completed", 1, workflows.size());    }