package com.fujitsu.iflowqa.testframe;

import java.awt.Point;

import com.fujitsu.iflow.model.workflow.BranchSpec;
import com.fujitsu.iflow.model.workflow.ConditionSpec;
import com.fujitsu.iflow.model.workflow.DataItemMappingElement;
import com.fujitsu.iflow.model.workflow.Filter;
import com.fujitsu.iflow.model.workflow.JavaAction;
import com.fujitsu.iflow.model.workflow.JavaActionSet;
import com.fujitsu.iflow.model.workflow.Node;
import com.fujitsu.iflow.model.workflow.Plan;
import com.fujitsu.iflow.model.workflow.PlanVersionHistoryElement;
import com.fujitsu.iflow.model.workflow.ProcessInstance;
import com.fujitsu.iflow.model.workflow.TimerAction;
import com.fujitsu.iflow.model.workflow.TimerDef;
import com.fujitsu.iflow.model.workflow.WFObjectFactory;
import com.fujitsu.iflow.model.workflow.WFObjectList;
import com.fujitsu.iflow.model.workflow.WorkItem;

public class APITest extends BPMTestBase {

    ConditionSpec condSpec = null;
    TimerDef td = null;
    TimerDef td1 = null;
    Plan resultPlan = null;
    static final String APITEST = "IFLOW_API_TEST";
    String transPortType = null;
    String LE_TRANSPORT_TYPE = "LE";
    long piId;

    public APITest()
    {
    }

    public void runTests(TestRecorder ntr) throws Exception
    {
        init(ntr);

        transPortType = tr.getProperty("TWFTransportType", "RMI");
        tr.log("Using Transport Type = " + transPortType);

        try {

// Method for login with wrong user password (test the existance of ErrorMessage.properties)
            testErrorMessage();

// Method for login
            login();
// Method for clean up templates and processes from previous test run
            cleanup();

//first make sure that things are set up correctly
//group TWFAdminRole must have the user ibpm_server1 in it to work correctly
            assertUserInGroup(wfSession.getUserName(), "TWFAdminRole");


// Method to create Sub template
            createSubTemplate();

// Method to create template with java actions
            createTemplate(tr);
            getJavaActions();


            createOneInstance();

// Method to test API Filter.FILTER_FIRST
            getFirstList(tr);

// Method to test API Filter.MyActiveProcesses
        if(!LE_TRANSPORT_TYPE.equalsIgnoreCase(transPortType))
            suspendMyActiveProcesses(tr);

// Method to test API Filter.MyInactiveProcesses
            getMyInactiveProcesses(tr);

// Method to test API Filter.AllInactiveProcesses
            getAllInactiveProcesses(tr);

// Method to test API Filter.MyProcesses
            getMyProcessesAndResumeThemIfSuspended(tr);

// Method to test API Filter.AllProcesses
            getAllProcesses(tr);

// Method to test API Filter.AllActiveProcesses
            getAllActiveProcesses(tr);

// Method to test API Filter.AllArchivedProcesses
            getAllArchivedProcesses(tr);

// Method to test API Filter.AllWorkItems
            getAllWorkItems(tr);

// Method to test WFAdminSession.reassign()
            reassignWorkItems(tr);
            reassignWorkItemsToOriginalUser(tr);

// Method to test API Filter.MyWorkItems
            acceptMyWorkItems(tr);

// Method to test API Filter.MyAcceptedWorkItems
            getMyAcceptedWorkItems(tr);

// Method to test API Filter.AllInactiveWorkItems
            getAllInactiveWorkItems(tr);

// Method to test API Filter.MyActiveWorkItems
            getMyActiveWorkItems1(tr);

// Method to test API Filter.MyCompletedWorkItems
            getMyCompletedWorkItems(tr);

            completeMyActiveWorkItems(tr);

// Method to test API Filter.MyDeclinedWorkItems
            getMyDeclinedWorkItems(tr);

// Method to test API Filter.MyPlans
            getMyPlans(tr);

// Method to test API Filter.MyInactivePlans
            getMyInactivePlans(tr);

// Method to test API Filter.AllPlans
            getAllPlans(tr);

// Method to test API Filter.AllArchivedPlans
if(!LE_TRANSPORT_TYPE.equalsIgnoreCase(transPortType))
            getAllArchivedPlans(tr);

// Method to test creation plan version
if(!LE_TRANSPORT_TYPE.equalsIgnoreCase(transPortType)){
            getPlanVersionInfo(tr);
}
// Method to test the execution of java action
            checkJavaActionExecution(tr);

// Method to logOut
            logOut();
        } catch (Exception e) {
            logAndRethrow("Exception caught in APITest.runTests, test aborted", e);
        }
    }


    public boolean createSubTemplate()
        throws Exception
    {

        try {
                String planName = "IFLOW_API_TEST_SUBPLAN";

                Plan plan = WFObjectFactory.getPlan();
                plan.setWFSession(wfSession);
                plan.startEdit();

                plan.addDataItemRef("SubprocessPrologueJAS", "STRING", "TEST");
                plan.addDataItemRef("SubprocessEpilogueJAS", "STRING", "TEST");

                plan.setName( planName );
                plan.setTitle( planName + " title" );
                plan.setDesc( planName + " description" );
                plan.setPlanIdentifier("Global");

                Node startNode = plan.addNode( "Start", Node.TYPE_START );
                int startX = 50;
                int startY = 100;
                startNode.setPosition( new Point( startX, startY ) );


                Node exitNode = plan.addNode( "EXIT", Node.TYPE_EXIT );
                exitNode.setPosition( new Point( startX + 100, startY) );
                startNode.addArrow( "DONE", exitNode );

                resultPlan = plan.createProcessDef();
                debug("Sub template with id " + resultPlan.getId() + " created");
        }

        catch (Exception e) {
            logAndRethrow("Failed in createSubTemplate", e);
        }
        return true;
    }


    public boolean createTemplate(TestRecorder tr)
        throws Exception
    {
        try {
                String planName = APITEST;

                JavaActionSet actionSet =null;
                JavaAction[] actions = null;
                JavaActionSet actionSet1 =null;
                JavaAction[] actions1 = null;
                JavaActionSet actionSet2 =null;
                JavaAction[] actions2 = null;
                JavaActionSet actionSet3 =null;
                JavaAction[] actions3 = null;
                JavaActionSet actionSet4 =null;
                JavaAction[] actions4 = null;
                JavaActionSet actionSet5 =null;
                JavaAction[] actions5 = null;
                JavaActionSet actionSet6 =null;
                JavaAction[] actions6 = null;
                JavaActionSet actionSet7 =null;
                JavaAction[] actions7 = null;
                JavaActionSet actionSet8 =null;
                JavaAction[] actions8 = null;
                JavaActionSet actionSet9 =null;
                JavaAction[] actions9 = null;
                JavaActionSet actionSet10 =null;
                JavaAction[] actions10 = null;
                JavaActionSet actionSet11 =null;
                JavaAction[] actions11 = null;
                JavaActionSet actionSet12 =null;
                JavaAction[] actions12 = null;
                JavaActionSet actionSet13 =null;
                JavaAction[] actions13 = null;
                JavaActionSet actionSet14 =null;
                JavaAction[] actions14 = null;
                JavaActionSet actionSet15 =null;
                JavaAction[] actions15 = null;

                Plan plan = WFObjectFactory.getPlan();
                plan.setWFSession(wfSession);
                plan.startEdit();

                plan.addDataItemRef("PlanInitJAS", "STRING", "TEST");
                plan.addDataItemRef("PlanCommitJAS", "STRING", "TEST");
                plan.addDataItemRef("ActPrologueJAS", "STRING", "TEST");
                plan.addDataItemRef("ActEpilogueJAS", "STRING", "TEST");
                plan.addDataItemRef("ActRoleJAS", "STRING", "TEST");

                plan.addDataItemRef("ConditionPrologueJAS", "STRING", "TEST");
                plan.addDataItemRef("ConditionEpilogueJAS", "STRING", "TEST");
                plan.addDataItemRef("OrEpilogueJAS", "STRING", "TEST");
                plan.addDataItemRef("AndEpilogueJAS", "STRING", "TEST");
                plan.addDataItemRef("DelayPrologueJAS", "STRING", "TEST");
                plan.addDataItemRef("DelayEpilogueJAS", "STRING", "TEST");
                plan.addDataItemRef("TimerJAS", "STRING", "TEST");
                plan.addDataItemRef("SubprocessPrologueJAS", "STRING", "TEST");
                plan.addDataItemRef("SubprocessEpilogueJAS", "STRING", "TEST");
                plan.addDataItemRef("nameListAtt", "STRING", "iflow");

                plan.addDataItemRef("groupListAtt", "STRING", "TWFAdminRole");
                plan.addDataItemRef("EjbUDA", "STRING", "TEST");


                plan.setName( planName );
                testAndReport("Plan Name", plan.getName(), planName);

                plan.setTitle( planName + " title" );
                testAndReport("Plan Title", plan.getTitle(), planName + " title");

                plan.setDesc( planName + " description" );
                testAndReport("Plan Desc", plan.getDesc(), planName + " description");

                plan.setPlanIdentifier("Global");
                testAndReport("Plan Desc", plan.getPlanIdentifier(), "Global");


                Node startNode = plan.addNode( "Start", Node.TYPE_START );
                int startX = 50;
                int startY = 100;
                startNode.setPosition( new Point( startX, startY ) );


                Node firstActNode = plan.addNode( "ACTIVITY1", Node.TYPE_ACTIVITY );
                firstActNode.setPosition( new Point( startX + 200, startY ) );
                firstActNode.setRole( "TWFAdminRole" );
                firstActNode.setDesc("ACTIVITY1DESC");
                startNode.addArrow( "START", firstActNode );


                Node conditionNode = plan.addNode( "CONDITION1", Node.TYPE_CONDITION );
                conditionNode.setPosition( new Point( startX + 350, startY -15 ) );
                firstActNode.addArrow( "CHECK", conditionNode );


                Node orNode1 = plan.addNode( "OR1", Node.TYPE_OR );

                orNode1.setPosition( new Point( startX + 150, startY + 150 ) );

                conditionNode.addArrow( "OR1", orNode1 );



                Node orNode2 = plan.addNode( "OR2", Node.TYPE_OR );

                orNode2.setPosition( new Point( startX + 550, startY + 150 ) );

                conditionNode.addArrow( "OR2", orNode2 );


                // Adding the condition specifics to the condition node

                condSpec = conditionNode.getConditionSpec();
                condSpec.setConditionAttribute("ConditionPrologueJAS");
                condSpec.setCondBranchSpecInfo("OR1",BranchSpec.EQUAL_OP, "ConditionNodeInitalized",false);
                condSpec.setCondBranchSpecInfo("OR2",BranchSpec.NOT_EQUALS_OP , "ConditionNodeInitalized",true);
                conditionNode.setConditionSpec(condSpec);

                Node ActNode1 = plan.addNode( "ACTIVITY2", Node.TYPE_ACTIVITY );
                ActNode1.setPosition( new Point( startX + 50, startY + 350) );
                ActNode1.setRole( "TWFAdminRole" );
                ActNode1.setDesc("ACTIVITY2DESC");
                orNode1.addArrow( "COMPLETEACT2", ActNode1 );


                Node ActNode2 = plan.addNode( "ACTIVITY3", Node.TYPE_ACTIVITY );
                ActNode2.setPosition( new Point( startX + 300, startY + 350 ) );
                ActNode2.setRole( "TWFAdminRole" );
                ActNode2.setDesc("ACTIVITY3DESC");
                orNode1.addArrow( "COMPLETEACT3", ActNode2 );

                Node ActNode3 = plan.addNode( "ACTIVITY4", Node.TYPE_ACTIVITY );
                ActNode3.setPosition( new Point( startX + 450, startY + 350 ) );
                ActNode3.setRole( "TWFAdminRole" );
                ActNode3.setDesc("ACTIVITY4DESC");
                orNode2.addArrow( "COMPLETEACT4", ActNode3 );


                Node ActNode4 = plan.addNode( "ACTIVITY5", Node.TYPE_ACTIVITY );
                ActNode4.setPosition( new Point( startX + 700, startY + 350 ) );
                ActNode4.setRole( "TWFAdminRole" );
                ActNode4.setDesc("ACTIVITY5DESC");
                orNode2.addArrow( "COMPLETEACT5", ActNode4 );


                Node andNode1 = plan.addNode( "AND1", Node.TYPE_AND );
                andNode1.setPosition( new Point( startX + 150, startY + 500 ) );
                ActNode1.addArrow( "DONE", andNode1 );
                ActNode2.addArrow( "DONE", andNode1 );


                Node andNode2 = plan.addNode( "AND2", Node.TYPE_AND );
                andNode2.setPosition( new Point( startX + 550, startY + 500 ) );
                ActNode3.addArrow( "DONE", andNode2 );
                ActNode4.addArrow( "DONE", andNode2 );



                Node delayNode1 = plan.addNode( "DELAY1", Node.TYPE_DELAY );
                delayNode1.setPosition( new Point( startX + 150, startY + 650 ) );
                andNode1.addArrow( "DONE", delayNode1 );



                Node subprocess = plan.addNode( "SUBPROCESS1", Node.TYPE_SUB_PROCESS );
                subprocess.setPosition( new Point( startX + 300, startY + 650 ) );
                delayNode1.addArrow( "SUBPROCESS", subprocess );
                subprocess.setSubPlanName("IFLOW_API_TEST_SUBPLAN");


                subprocess.addDataMappingElement("SubprocessPrologueJAS", "SubprocessPrologueJAS", DataItemMappingElement.INOUT);
                subprocess.addDataMappingElement("SubprocessEpilogueJAS", "SubprocessEpilogueJAS", DataItemMappingElement.INOUT);


                Node delayNode2 = plan.addNode( "DELAY2", Node.TYPE_DELAY );
                delayNode2.setPosition( new Point( startX + 550, startY + 650 ) );
                andNode2.addArrow( "DONE", delayNode2 );



                Node exitNode = plan.addNode( "EXIT", Node.TYPE_EXIT );
                exitNode.setPosition( new Point( startX + 475, startY + 670) );
                subprocess.addArrow( "DONE", exitNode );
                delayNode2.addArrow( "DONE", exitNode );

// Creating Java Action to execute at Plan Init Time
                actionSet = WFObjectFactory.getJavaActionSet();
                if (actionSet != null) {
                    tr.markPassed("WFObjectFactory.getJavaActionSet()");
                }
                else {
                    tr.markFailed("WFObjectFactory.getJavaActionSet()","Possibly an error");
                }

                try {
                    actionSet.setActionSetName("PlanInitTest");
                    tr.markPassed("JavaActionSet.setActionSetName()");

                }
                catch (Exception ex) {
                    tr.markFailed("JavaActionSet.setActionSetName()","Possibly an error");
                }


                try {
                    actionSet.setActionSetDescription("Invokes java action at init time");
                    tr.markPassed("JavaActionSet.setActionSetDescription()");
                }
                catch (Exception ex) {
                    tr.markFailed("JavaActionSet.setActionSetDescription()","Possibly an error");
                }
                try {
                    actions = actionSet.createJavaActions(1);
                    tr.markPassed("JavaActionSet.createJavaActions()");
                }
                catch (Exception ex) {
                    tr.markFailed("JavaActionSet.createJavaActions()","Possibly an error");
                }


                try {
                    actions[0].setActionName("PlanInitJAS") ;
                    tr.markPassed("JavaAction.setActionName()");
                }

                catch (Exception ex) {
                    tr.markFailed("JavaAction.setActionName()","Possibly an error");
                }

                try {
                    actions[0].setActionDescription ("Executing Java action on Plan init") ;
                    tr.markPassed("JavaAction.setActionDescription()");
                }

                catch (Exception ex) {
                    tr.markFailed("JavaAction.setActionDescription()","Possibly an error");
                }

                try {
                    actions[0].setActionTechDescription("Plan Init Java Action Set");
                    tr.markPassed("JavaAction.setActionTechDescription()");
                }
                catch (Exception ex) {
                    tr.markFailed("JavaAction.setActionTechDescription()","Possibly an error");
                }

                try  {
                    actions[0].setMethodName("getPlanInitJAS");
                    tr.markPassed("JavaAction.setMethodName()");
                }
                catch (Exception ex) {
                    tr.markFailed("JavaAction.setMethodName()","Possibly an error");
                }

                try {
                    actions[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                    tr.markPassed("JavaAction.setClassName()");
                }
                catch (Exception ex) {
                    tr.markFailed("JavaAction.setClassName()","Possibly an error");
                }

                try {
                    actions[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                    tr.markPassed("JavaAction.setFactoryClassName()");
                }
                catch (Exception ex) {
                    tr.markFailed("JavaAction.setFactoryClassName()","Possibly an error");
                }

                try {
                    actions[0].setArgumentsUDANames("PlanInitJAS" );
                    tr.markPassed("JavaAction.setArgumentsUDANames()");
                }
                catch (Exception ex) {
                    tr.markFailed("JavaAction.setArgumentsUDANames()","Possibly an error");
                }

                try {
                    actions[0].setReturnValueUDAName("PlanInitJAS");
                    tr.markPassed("JavaAction.setReturnValueUDAName()");
                }
                catch (Exception ex) {
                    tr.markFailed("JavaAction.setReturnValueUDAName()","Possibly an error");
                }

                try {
                    actions[0].setAbortSequenceOnError(false);
                    tr.markPassed("JavaAction.setAbortSequenceOnError()");
                }
                catch (Exception ex) {
                    tr.markFailed("JavaAction.setAbortSequenceOnError()","Possibly an error");
                }

                try {
                    actionSet.setJavaActions(actions);
                    tr.markPassed("JavaActionSet.setJavaActions()");
                }
                catch (Exception ex) {
                    tr.markFailed("JavaActionSet.setJavaActions()","Possibly an error");
                }

//sets this JavaActionSet as  the Plan Initialization JavaActionSet
                try {

                    plan.setInitJavaActionSet(actionSet);

                    tr.markPassed("Plan.setInitJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("Plan.setInitJavaActionSet()","Possibly an error");
                }

                if(tr.getProperty("ExampleJABeanDeployed", "no").equalsIgnoreCase("yes"))
                {
                    actionSet1 = WFObjectFactory.getJavaActionSet();
                    actionSet1.setActionSetName("BeanTest");
                    actionSet1.setActionSetDescription("Invokes bean at process completion time");
                    actions1 = actionSet1.createJavaActions(1);
                    actions1[0].setActionName("PlanCommitJAS") ;
                    actions1[0].setActionDescription ("Executing Java action as bean on Plan commit") ;
                    actions1[0].setActionTechDescription("Plan Commit Java Action Set");

                    actions1[0].setBeanName("com.fujitsu.iflow.test.EjbProxyExample");
                    tr.markPassed("JavaAction.setBeanName()");

                    actions1[0].setBeanMethodName("hello");
                    tr.markPassed("JavaAction.setBeanMethodName()");

                    actions1[0].setBeanMethodArgumentsUDANames("EjbUDA");
                    tr.markPassed("JavaAction.setBeanMethodArgumentsUDANames()");

                    actions1[0].setReturnValueUDAName("PlanCommitJAS");
                    actions1[0].setAbortSequenceOnError(false);
                    actionSet1.setJavaActions(actions1);
                    try {

                        plan.setCommitJavaActionSet(actionSet1);
                        tr.markPassed("Plan.setCommitJavaActionSet()");
                    }
                    catch (Exception ex) {
                        tr.markFailed("Plan.setCommitJavaActionSet()","Possibly an error");
                    }
                }

// Creating Java Action to execute at Activity Initialization Time
                actionSet2 = WFObjectFactory.getJavaActionSet();
                actionSet2.setActionSetName("ActivityPrologueTest");
                actionSet2.setActionSetDescription("Invokes java action at activity init time");
                actions2 = actionSet2.createJavaActions(1);

                actions2[0].setActionName("ActivityPrologueJAS") ;
                actions2[0].setActionDescription ("Executing Java action on Activity init") ;
                actions2[0].setActionTechDescription("Activity Init Java Action Set");
                actions2[0].setMethodName("getActPrologueJAS");
                actions2[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions2[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions2[0].setArgumentsUDANames("ActPrologueJAS" );
                actions2[0].setReturnValueUDAName("ActPrologueJAS");
                actions2[0].setAbortSequenceOnError(false);
                actionSet2.setJavaActions(actions2);

//sets this JavaActionSet as the Activity Prologue JavaActionSet

                try {
                    firstActNode.setPrologueJavaActionSet(actionSet2);
                    tr.markPassed("ActivityNode.setPrologueJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("ActivityNode.setPrologueJavaActionSet()","Possibly an error");
                }

// Creating Java Action to execute at Activity Commit Time
                actionSet3 = WFObjectFactory.getJavaActionSet();
                actionSet3.setActionSetName("ActivityEpilogueTest");
                actionSet3.setActionSetDescription("Invokes java action at activity commit time");
                actions3 = actionSet3.createJavaActions(1);

                actions3[0].setActionName("ActivityEpilogueJAS") ;
                actions3[0].setActionDescription ("Executing Java action on Activity commit") ;
                actions3[0].setActionTechDescription("Activity Commit Java Action Set");
                actions3[0].setMethodName("getActEpilogueJAS");
                actions3[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions3[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions3[0].setArgumentsUDANames("ActEpilogueJAS" );
                actions3[0].setReturnValueUDAName("ActEpilogueJAS");
                actions3[0].setAbortSequenceOnError(false);
                actionSet3.setJavaActions(actions3);

//sets this JavaActionSet as the Activity Epilogue JavaActionSet
                try {
                    firstActNode.setEpilogueJavaActionSet(actionSet3);
                    tr.markPassed("ActivityNode.setEpilogueJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("ActivityNode.setEpilogueJavaActionSet()","Possibly an error");
                }


// Creating Java Action to execute at Activity role resolution Time
                actionSet4 = WFObjectFactory.getJavaActionSet();
                actionSet4.setActionSetName("ActivityRoleTest");
                actionSet4.setActionSetDescription("Invokes java action at activity role resolution time");
                actions4 = actionSet4.createJavaActions(1);

                actions4[0].setActionName("ActivityRoleJAS") ;
                actions4[0].setActionDescription ("Executing Java action on Activity at role resolution time") ;
                actions4[0].setActionTechDescription("Activity Role Java Action Set");
                actions4[0].setMethodName("getActRoleJAS");
                actions4[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions4[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions4[0].setArgumentsUDANames("ActRoleJAS" );
                actions4[0].setReturnValueUDAName("ActRoleJAS");
                actions4[0].setAbortSequenceOnError(false);
                actionSet4.setJavaActions(actions4);

//sets this JavaActionSet as  the Activity Role JavaActionSet
                try {
                    firstActNode.setRoleJavaActionSet(actionSet4);
                    tr.markPassed("ActivityNode.setRoleJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("ActivityNode.setRoleJavaActionSet()","Possibly an error");
                }


// Creating Java Action to execute at Condition node initialization time
                actionSet5 = WFObjectFactory.getJavaActionSet();
                actionSet5.setActionSetName("ConditionPrologueTest");
                actionSet5.setActionSetDescription("Invokes java action at condition node");
                actions5 = actionSet5.createJavaActions(1);

                actions5[0].setActionName("conditionPrologueJAS") ;
                actions5[0].setActionDescription ("Executing Java action on condition node initialization") ;
                actions5[0].setActionTechDescription("Condition Node Prologue Java Action Set");
                actions5[0].setMethodName("getConditionPrologueJAS");
                actions5[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions5[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions5[0].setArgumentsUDANames("ConditionPrologueJAS" );
                actions5[0].setReturnValueUDAName("ConditionPrologueJAS");
                actions5[0].setAbortSequenceOnError(false);
                actionSet5.setJavaActions(actions5);

//sets this JavaActionSet as the Condition Prologue JavaActionSet
                try {
                    conditionNode.setPrologueJavaActionSet(actionSet5);
                    tr.markPassed("ConditionNode.setPrologueJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("ConditionNode.setPrologueJavaActionSet()","Possibly an error");
                }


// Creating Java Action to execute at Condition node completion time
                actionSet6 = WFObjectFactory.getJavaActionSet();
                actionSet6.setActionSetName("ConditionEpilogueTest");
                actionSet6.setActionSetDescription("Invokes java action at condition node completion");
                actions6 = actionSet6.createJavaActions(1);

                actions6[0].setActionName("conditionEpilogueJAS") ;
                actions6[0].setActionDescription ("Executing Java action on condition node initialization") ;
                actions6[0].setActionTechDescription("Condition Node Epilogue Java Action Set");
                actions6[0].setMethodName("getConditionEpilogueJAS");
                actions6[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions6[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions6[0].setArgumentsUDANames("ConditionEpilogueJAS" );
                actions6[0].setReturnValueUDAName("ConditionEpilogueJAS");
                actions6[0].setAbortSequenceOnError(false);
                actionSet6.setJavaActions(actions6);

//sets this JavaActionSet as  the Condition Epilogue Role JavaActionSet
                try {
                    conditionNode.setEpilogueJavaActionSet(actionSet6);
                    tr.markPassed("ConditionNode.setEpilogueJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("ConditionNode.setEpilogueJavaActionSet()","Possibly an error");
                }


// Creating Java Action to execute after the first incoming arrow reaches the OR node
                actionSet7 = WFObjectFactory.getJavaActionSet();
                actionSet7.setActionSetName("OrEpilogueTest");
                actionSet7.setActionSetDescription("Invokes java action at epilogue time");
                actions7 = actionSet7.createJavaActions(1);

                actions7[0].setActionName("OrEpilogueJAS") ;
                actions7[0].setActionDescription ("Executing Java action on OR epilogue") ;
                actions7[0].setActionTechDescription("Or Node Epilogue Java Action Set");
                actions7[0].setMethodName("getOrEpilogueJAS");
                actions7[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions7[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions7[0].setArgumentsUDANames("OrEpilogueJAS" );
                actions7[0].setReturnValueUDAName("OrEpilogueJAS");
                actions7[0].setAbortSequenceOnError(false);
                actionSet7.setJavaActions(actions7);

//sets this JavaActionSet as  the OR Node Epilogue JavaActionSet
                try {
                    orNode1.setEpilogueJavaActionSet(actionSet7);
                    tr.markPassed("OrNode.setEpilogueJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("OrNode.setEpilogueJavaActionSet()","Possibly an error");
                }



// Creating Java Action to execute after all the first incoming arrows reach the AND node
                actionSet8 = WFObjectFactory.getJavaActionSet();
                actionSet8.setActionSetName("AndEpilogueTest");
                actionSet8.setActionSetDescription("Invokes java action at epilogue time");
                actions8 = actionSet8.createJavaActions(1);

                actions8[0].setActionName("AndEpiloueJAS") ;
                actions8[0].setActionDescription ("Executing Java action on AND epilogue") ;
                actions8[0].setActionTechDescription("And Node Epilogue Java Action Set");
                actions8[0].setMethodName("getAndEpilogueJAS");
                actions8[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions8[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions8[0].setArgumentsUDANames("AndEpilogueJAS" );
                actions8[0].setReturnValueUDAName("AndEpilogueJAS");
                actions8[0].setAbortSequenceOnError(false);
                actionSet8.setJavaActions(actions8);

//sets this JavaActionSet as the AND Node Epilogue JavaActionSet
                try {
                    andNode1.setEpilogueJavaActionSet(actionSet8);
                    tr.markPassed("AndNode.setEpilogueJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("AndNode.setEpilogueJavaActionSet()","Possibly an error");
                }



// Creating Java Action to execute before the delay node execution
                actionSet9 = WFObjectFactory.getJavaActionSet();
                actionSet9.setActionSetName("DelayPrologueTest");
                actionSet9.setActionSetDescription("Invokes java action at delay prologue time");
                actions9 = actionSet9.createJavaActions(1);

                actions9[0].setActionName("DelayPrologueJAS") ;
                actions9[0].setActionDescription ("Executing Java action on DELAY prologue") ;
                actions9[0].setActionTechDescription("Delay Node Prologue Java Action Set");
                actions9[0].setMethodName("getDelayPrologueJAS");
                actions9[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions9[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions9[0].setArgumentsUDANames("DelayPrologueJAS" );
                actions9[0].setReturnValueUDAName("DelayPrologueJAS");
                actions9[0].setAbortSequenceOnError(false);
                actionSet9.setJavaActions(actions9);

//sets this JavaActionSet as the Delay Node Prologue JavaActionSet
                try {
                    delayNode1.setPrologueJavaActionSet(actionSet9);
                    tr.markPassed("DelayNode.setPrologueJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("DelayNode.setPrologueJavaActionSet()","Possibly an error");
                }




// Creating Java Action to execute before the delay node execution
                actionSet10 = WFObjectFactory.getJavaActionSet();
                actionSet10.setActionSetName("DelayEpilogueTest");
                actionSet10.setActionSetDescription("Invokes java action delay epilogue time");
                actions10 = actionSet10.createJavaActions(1);

                actions10[0].setActionName("DelayEpilogueJAS") ;
                actions10[0].setActionDescription ("Executing Java action on DELAY epilogue") ;
                actions10[0].setActionTechDescription("Delay Node Epilogue Java Action Set");
                actions10[0].setMethodName("getDelayEpilogueJAS");
                actions10[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions10[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions10[0].setArgumentsUDANames("DelayEpilogueJAS" );
                actions10[0].setReturnValueUDAName("DelayEpilogueJAS");
                actions10[0].setAbortSequenceOnError(false);
                actionSet10.setJavaActions(actions10);

//sets this JavaActionSet as the Delay Node Epilogue JavaActionSet
                try {
                    delayNode1.setEpilogueJavaActionSet(actionSet10);
                    tr.markPassed("DelayNode.setEpilogueJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("DelayNode.setEpilogueJavaActionSet()","Possibly an error");
                }

// Creating Java Action to execute after the timer expires
                actionSet11 = WFObjectFactory.getJavaActionSet();
                actionSet11.setActionSetName("TimerTest");
                actionSet11.setActionSetDescription("Invokes java action after the timer expires");
                actions11 = actionSet11.createJavaActions(1);

                actions11[0].setActionName("TimerJAS") ;
                actions11[0].setActionDescription ("Executing Java action after timer expires") ;
                actions11[0].setActionTechDescription("Timer Java Action Set");
                actions11[0].setMethodName("getTimerJAS");
                actions11[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions11[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions11[0].setArgumentsUDANames("TimerJAS" );
                actions11[0].setReturnValueUDAName("TimerJAS");
                actions11[0].setAbortSequenceOnError(false);
                actionSet11.setJavaActions(actions11);
                String ptrXMLString = actionSet11.toString();
                plan.addDataItemRef("timer", "STRING", ptrXMLString);

                td = WFObjectFactory.getTimerDef();
                td.setName("Act2TIMER");
                td.setDescription("TimerAtActivity2Node");
                td.setType(TimerDef.RELATIVE);
                td.setTime("1000");
                td1 = WFObjectFactory.getTimerDef();
                td1.setName("Act3TIMER");
                td1.setDescription("TimerAtActivity3Node");
                td1.setType(TimerDef.RELATIVE);
                td1.setTime("1000");

                TimerAction timerAction = WFObjectFactory.getTimerAction();
                TimerAction timerAction1 = WFObjectFactory.getTimerAction();

                timerAction.setType(TimerAction.ESCALATE);
                try {
                    timerAction.setEscalateActionNameList("nameListAtt");
                    tr.markPassed("TimerAction.setEscalateActionNameList()");
                }
                catch (Exception ex) {
                    tr.markFailed("TimerAction.setEscalateActionNameList()","Possibly an error");
                }

                try {
                    timerAction.setEscalateActionGroupList("groupListAtt");
                    tr.markPassed("TimerAction.setEscalateActionGroupList()");
                }
                catch (Exception ex) {
                    tr.markFailed("TimerAction.setEscalateActionGroupList()","Possibly an error");
                }

//sets this JavaActionSet as the Timer Java Action Set

                timerAction1.setType(TimerAction.JAVAACTIONSET);
                try {
                    timerAction1.setJavaActionSet("timer");
                    tr.markPassed("TimerAction.setJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("TimerAction.setJavaActionSet()","Possibly an error");
                }
                td.addTimerAction(timerAction);
                td1.addTimerAction(timerAction1);
                ActNode1.addTimer(td);
                ActNode2.addTimer(td1);



// Creating Java Action to execute before the Subepicess node execution
                actionSet12 = WFObjectFactory.getJavaActionSet();
                actionSet12.setActionSetName("SubprocessPrologueTest");
                actionSet12.setActionSetDescription("Invokes java action at subprocess prologue time");
                actions12 = actionSet12.createJavaActions(1);
                actions12[0].setActionName("SubprocessPrologueJAS") ;
                actions12[0].setActionDescription ("Executing Java action on Subprocess prologue") ;
                actions12[0].setActionTechDescription("Subprocess Node Prologue Java Action Set");
                actions12[0].setMethodName("getSubprocessPrologueJAS");
                actions12[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions12[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");

                actions12[0].setArgumentsUDANames("SubprocessPrologueJAS" );
                actions12[0].setReturnValueUDAName("SubprocessPrologueJAS");
                actions12[0].setAbortSequenceOnError(false);
                actionSet12.setJavaActions(actions12);

//sets this JavaActionSet as the Subepicess Node Epilogue JavaActionSet
                try {
                    subprocess.setPrologueJavaActionSet(actionSet12);
                    tr.markPassed("SubProcessNode.setPrologueJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("SubProcessNode.setPrologueJavaActionSet()","Possibly an error");
                }


// Creating Java Action to execute before the Subprocess node execution
                actionSet13 = WFObjectFactory.getJavaActionSet();
                actionSet13.setActionSetName("SubprocessEpilogueTest");
                actionSet13.setActionSetDescription("Invokes java action at subprocess epilogue time");
                actions13 = actionSet13.createJavaActions(1);

                actions13[0].setActionName("SubprocessEpilogueJAS") ;
                actions13[0].setActionDescription ("Executing Java action on Subprocess epilogue") ;
                actions13[0].setActionTechDescription("Subprocess Node Epilogue Java Action Set");
                actions13[0].setMethodName("getSubprocessEpilogueJAS");
                actions13[0].setClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions13[0].setFactoryClassName("com.fujitsu.iflowqa.testframe.javaActionSet");
                actions13[0].setArgumentsUDANames("SubprocessEpilogueJAS" );
                actions13[0].setReturnValueUDAName("SubprocessEpilogueJAS");
                actions13[0].setAbortSequenceOnError(false);
                actionSet13.setJavaActions(actions13);

//sets this JavaActionSet as the Subprocess Node Epilogue JavaActionSet
                try {
                    subprocess.setEpilogueJavaActionSet(actionSet13);
                    tr.markPassed("SubProcessNode.setEpilogueJavaActionSet()");
                }
                catch (Exception ex) {
                    tr.markFailed("SubProcessNode.setEpilogueJavaActionSet()","Possibly an error");
                }

// Creating Java Action to test classapth in java action
                actionSet15 = WFObjectFactory.getJavaActionSet();
                actionSet15.setActionSetName("ClasspathTest");
                actions15 = actionSet15.createJavaActions(1);

                actions15[0].setActionName("ClasspathTest") ;
                actions15[0].setActionDescription ("To test setClasspath() API") ;

                try {
                    actions15[0].setClassPath("C:\\training1");
                    tr.markPassed("JavaAction.setClassPath()");
                }
                catch (Exception ex) {
                    tr.markFailed("JavaAction.setClassPath()","Possibly an error");
                }

                actions15[0].setClassPath("C:\\training");
                actionSet15.setJavaActions(actions15);

//sets this JavaActionSet as  the Activity Role JavaActionSet
                ActNode3.setRoleJavaActionSet(actionSet15);



                resultPlan = plan.createProcessDef();
        }
        catch (Exception e) {
            logAndRethrow("Error while creating Plan ", e);
        }
        return true;
    }

    public void createOneInstance()
        throws Exception
    {
        try {
            ProcessInstance pi = resultPlan.createProcessInstance();
            pi.start();
            piId = pi.getId();
        }
        catch (Exception e) {
            logAndRethrow("Error while creating one instance ", e);
        }
    }


    public void getJavaActions()
        throws Exception
    {
        try {

            Plan plan1 = WFObjectFactory.getPlan(resultPlan.getId(),wfSession);
            plan1.startEdit();

            JavaActionSet jas = plan1.getInitJavaActionSet();

            testAndReport("JavaActionSet.getActionCount()", jas.getActionCount(), 1);
            testAndReport("JavaActionSet.getActionSetDescription()", jas.getActionSetDescription(), "Invokes java action at init time");
            testAndReport("JavaActionSet.getActionSetName()", jas.getActionSetName(),"PlanInitTest");

            JavaAction ja[] = jas.getJavaActions();
            AssertObjectArrayNotEmpty(ja);
            if (ja[0] != null) {
                tr.markPassed("JavaActionSet.getJavaActions()");
            }
            else {
                tr.markFailed("JavaActionSet.getJavaActions()", " Possibly an error ");
            }

            testAndReport("JavaAction.getActionName()", ja[0].getActionName(),"PlanInitJAS");
            testAndReport("JavaAction.getActionDescription()", ja[0].getActionDescription(),"Executing Java action on Plan init");
            testAndReport("JavaAction.getActionTechDescription()", ja[0].getActionTechDescription(),"Plan Init Java Action Set");
            testAndReport("JavaAction.getMethodName()", ja[0].getMethodName(),"getPlanInitJAS");
            testAndReport("JavaAction.getClassName()", ja[0].getClassName(),"com.fujitsu.iflowqa.testframe.javaActionSet");
            testAndReport("JavaAction.getFactoryClassName()", ja[0].getFactoryClassName(),"com.fujitsu.iflowqa.testframe.javaActionSet");
            testAndReport("JavaAction.getArgumentsUDANames()", ja[0].getArgumentsUDANames(),"PlanInitJAS");
            testAndReport("JavaAction.getReturnValueUDAName()", ja[0].getReturnValueUDAName(),"PlanInitJAS");

            if ((ja[0].getAbortSequenceOnError()==false)) {
                tr.markPassed("JavaAction.getAbortSequenceOnError()");
            }
            else {
                tr.markFailed("JavaAction.getAbortSequenceOnError()", "Got a 'true' when expecting 'false'");
            }

            if(tr.getProperty("ExampleJABeanDeployed", "no").equalsIgnoreCase("yes"))
            {
                JavaActionSet jaset = plan1.getCommitJavaActionSet();
                if(jaset != null)
                {
                    JavaAction jaction[] = jaset.getJavaActions();
                    AssertObjectArrayNotEmpty(jaction);
                    testAndReport("JavaAction.getBeanName()", jaction[0].getBeanName(),"com.fujitsu.iflow.test.EjbProxyExample");
                    testAndReport("JavaAction.getBeanMethodName()", jaction[0].getBeanMethodName(),"hello");
                    testAndReport("JavaAction.getBeanMethodArgumentsUDANames()", jaction[0].getBeanMethodArgumentsUDANames(),"EjbUDA");
                }
                else
                    logAndRethrow("Exception caught while retrieving Java Action",
                        new Exception("getCommitJavaActionSet() returned 'null' Java Action set"));
            }

            Node nodes[] = resultPlan.getNodes();
            AssertObjectArrayNotEmpty(nodes);
            for(int j=0;j<nodes.length;j++) {
                Node theNode = nodes[j];
                String nodeName = theNode.getName();
                if((theNode.getType() == Node.TYPE_ACTIVITY) && nodeName.equals("ACTIVITY1")) {
                    testAndReport("ActivityNode.getEpilogueJavaActionSet()", theNode.getEpilogueJavaActionSet().getActionSetName(),"ActivityEpilogueTest");
                    testAndReport("ActivityNode.getPrologueJavaActionSet()", theNode.getPrologueJavaActionSet().getActionSetName(),"ActivityPrologueTest");
                    testAndReport("ActivityNode.getRoleJavaActionSet()", theNode.getRoleJavaActionSet().getActionSetName(),"ActivityRoleTest");
                }

                if((theNode.getType() == Node.TYPE_ACTIVITY) && nodeName.equals("ACTIVITY2")) {
                    TimerDef td1[] = theNode.getTimers();
                    AssertObjectArrayNotEmpty(td1);
                    for(int k=0; k<td1.length;k++) {
                        TimerAction ta1[] = td1[k].getTimerActions();
                        testAndReport("TimerAction.getEscalateActionGroupList()", ta1[0].getEscalateActionGroupList(),"groupListAtt");
                        testAndReport("TimerAction.getEscalateActionNameList()", ta1[0].getEscalateActionNameList(),"nameListAtt");
                    }
                }

                if((theNode.getType() == Node.TYPE_ACTIVITY) && nodeName.equals("ACTIVITY3")) {
                    TimerDef td1[] = theNode.getTimers();
                    AssertObjectArrayNotEmpty(td1);
                    for(int k=0; k<td1.length;k++) {
                        TimerAction ta1[] = td1[k].getTimerActions();
                        testAndReport("TimerAction.getJavaActionSet()", ta1[0].getJavaActionSet(),"timer");
                    }
                }

                if((theNode.getType() == Node.TYPE_ACTIVITY) && nodeName.equals("ACTIVITY4")) {
                    JavaAction ja2[] = theNode.getRoleJavaActionSet().getJavaActions();
                    AssertObjectArrayNotEmpty(ja2);
                    testAndReport("JavaAction.getClassPath()", ja2[0].getClassPath(),"C:/training");
                }

                if((theNode.getType() == Node.TYPE_AND) && nodeName.equals("AND1")) {
                    testAndReport("AndNode.getEpilogueJavaActionSet()", theNode.getEpilogueJavaActionSet().getActionSetName(),"AndEpilogueTest");
                }

                if((theNode.getType() == Node.TYPE_CONDITION) && nodeName.equals("CONDITION1")) {
                    testAndReport("ConditionNode.getEpilogueJavaActionSet()", theNode.getEpilogueJavaActionSet().getActionSetName(),"ConditionEpilogueTest");
                    testAndReport("ConditionNode.getPrologueJavaActionSet()", theNode.getPrologueJavaActionSet().getActionSetName(),"ConditionPrologueTest");
                }

                if((theNode.getType() == Node.TYPE_DELAY) && nodeName.equals("DELAY1")) {
                    testAndReport("DelayNode.getEpilogueJavaActionSet()", theNode.getEpilogueJavaActionSet().getActionSetName(),"DelayEpilogueTest");
                    testAndReport("DelayNode.getPrologueJavaActionSet()", theNode.getPrologueJavaActionSet().getActionSetName(),"DelayPrologueTest");
                }

                if((theNode.getType() == Node.TYPE_OR) && nodeName.equals("OR1")) {
                    testAndReport("OrNode.getEpilogueJavaActionSet()", theNode.getEpilogueJavaActionSet().getActionSetName(),"OrEpilogueTest");
                }

                if((theNode.getType() == Node.TYPE_SUB_PROCESS) && nodeName.equals("SUBPROCESS1")) {
                    checkNodeActions(theNode, "SubProcessNode", "SubprocessPrologueTest", "SubprocessEpilogueTest");
                }
            }
            plan1.commitEdit();

        }
        catch (Exception e) {
            logAndRethrow("Exception caught while editing Java Action", e);
        }
    }


    // call this when in edit mode, attempts to change things on the java action set
    // it is a bit of overkill to try to set everything, and then set back
    // but we need to be SURE
    private void checkNodeActions(Node aNode, String whichNode, String expPrologue, String expEpilogue)
        throws Exception
    {
        if (aNode.supportPrologueJavaActionSet()) {
            JavaActionSet jas = aNode.getPrologueJavaActionSet();
            testAndReport(whichNode + "<->PrologueJavaActionSet expName",
                jas.getActionSetName(), expPrologue);

            //now set the name to something else
            jas.setActionSetName("New Value \u6543\u4321");
            aNode.setPrologueJavaActionSet(jas);

            jas = aNode.getPrologueJavaActionSet();
            testAndReport(whichNode + "<->PrologueJavaActionSet newName",
                jas.getActionSetName(),"New Value \u6543\u4321");

            //ok, now set the name back
            jas.setActionSetName(expPrologue);
            aNode.setPrologueJavaActionSet(jas);

            jas = aNode.getPrologueJavaActionSet();
            testAndReport(whichNode + "<->PrologueJavaActionSet oldName",
                jas.getActionSetName(), expPrologue);
        }
        if (aNode.supportEpilogueJavaActionSet()) {
            JavaActionSet jas = aNode.getEpilogueJavaActionSet();
            testAndReport(whichNode + "<->EpilogueJavaActionSet expName",
                jas.getActionSetName(), expEpilogue);

            //now set the name to something else
            jas.setActionSetName("New Value \u6543\u4321");
            aNode.setEpilogueJavaActionSet(jas);

            jas = aNode.getEpilogueJavaActionSet();
            testAndReport(whichNode + "<->EpilogueJavaActionSet newName",
                jas.getActionSetName(),"New Value \u6543\u4321");

            //ok, now set the name back
            jas.setActionSetName(expEpilogue);
            aNode.setEpilogueJavaActionSet(jas);

            jas = aNode.getEpilogueJavaActionSet();
            testAndReport(whichNode + "<->EpilogueJavaActionSet oldName",
                jas.getActionSetName(), expEpilogue);
        }
    }


    public void getFirstList(TestRecorder tr)
        throws Exception
    {
        try {

            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.FILTER_FIRST);
            Object[] wiList = wfObjectList.getNextBatch(10);
    //          wfObjectList.openList(Filter.FILTER_FIRST);
    //      Object[] wiList = wfObjectList.getAllObjects();
            if (wiList != null) {
                if (wiList.length > 0) {
                    for(int i = 0; i < wiList.length; i++) {
                        ProcessInstance pi = (ProcessInstance) wiList[i];
                        debug(" Process Instance ID is ::: " + pi.getId() + " Name is ::: " + pi.getName());
                    }
                    tr.markPassed("Filter.FILTER_FIRST");
                    debug("Total Number of Processes using FILTER_FIRST retrieved is/are ::: " + wiList.length);
                }
            }
            else {
                tr.markPassed("Filter.FILTER_FIRST");
                debug("No processes retrieved for FILTER_FIRST Filter");
            }
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in Filter.FILTER_FIRST", e);
        }
    }



    public void suspendMyActiveProcesses(TestRecorder tr)
        throws Exception
    {
        try {

            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.MyActiveProcesses);
            Object[] wiList = wfObjectList.getNextBatch(10);
            if (wiList != null) {
                if (wiList.length > 0) {
                    for(int i = 0; i < wiList.length; i++) {
                        ProcessInstance pi = (ProcessInstance) wiList[i];
                        debug(" Process Instance ID is ::: " + pi.getId() + " Name is ::: " + pi.getName());
                        try {
                            pi.suspend();
                            tr.markPassed("ProcessInstance.suspend()");
                        }
                        catch (Exception ex) {
                            tr.markFailed("ProcessInstance.suspend()", "Process with ID" + pi.getId() + " not able to suspend ");
                            logAndRethrow("ProcessInstance.suspend()", ex);
                        }
                        debug(" Process Instance ID is ::: " + pi.getId() + " State changed to Suspended from Activated" );
                    }
                    tr.markPassed("Filter.MyActiveProcesses - Total Number of Processes retrieved = " + wiList.length);
                }
            }
            else {
                // this should probably throw an exception if wiList is NULL
                // it should never return a null value in a real test
                tr.markPassed("Filter.MyActiveProcesses - No processes retrieved for MyActiveProcesses Filter");
            }

        }
        catch (Exception e) {
            logAndRethrow("Exception caught in Filter.MyActiveProcesses", e);
        }
    }



    public void getMyInactiveProcesses(TestRecorder tr)
        throws Exception
    {
        try {

            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.MyInactiveProcesses);
            Object[] wiList = wfObjectList.getNextBatch(10);
            IterateProcessInstanceArrayIfNotEmpty(wiList, "Filter.MyInactiveProcesses");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in Filter.MyInactiveProcesses", e);
        }
    }



    public void getAllInactiveProcesses(TestRecorder tr)
        throws Exception
    {
        try {

            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.AllInactiveProcesses);
            Object[] wiList = wfObjectList.getNextBatch(10);
            IterateProcessInstanceArrayIfNotEmpty(wiList, "Filter.AllInactiveProcesses");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in Filter.AllInactiveProcesses", e);
        }
    }


    public void getMyProcessesAndResumeThemIfSuspended(TestRecorder tr)
        throws Exception
    {
        try {

            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.MyProcesses);
            Object[] wiList = wfObjectList.getNextBatch(10);
            //AssertObjectArrayNotEmpty(wiList);
            if (wiList != null) {
                if (wiList.length > 0) {
                    for(int i = 0; i < wiList.length; i++) {
                        ProcessInstance pi = (ProcessInstance) wiList[i];
                        debug(" Process Instance ID is ::: " + pi.getId() + " Name is ::: " + pi.getName());
                        if (pi.getState()==ProcessInstance.STATE_SUSPENDED) {
                            pi.resume();
                            tr.markPassed("ProcessInstance.resume()");
                            debug(" Process Instance ID is ::: " + pi.getId() + " State changed to Activated from Suspended" );
                        }
                    }
                    tr.markPassed("Filter.MyProcesses");
                    debug("Total Number of Processes using MyProcesses Filter retrieved is/are ::: " + wiList.length);
                }
            }
            else {
                tr.markPassed("Filter.MyProcesses");
                debug("No processes retrieved for MyProcesses Filter");
            }
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in Filter.MyProcesses", e);
        }
    }

    public void getAllProcesses(TestRecorder tr)
        throws Exception
    {
        try {

            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.AllProcesses);
            Object[] wiList = wfObjectList.getNextBatch(10);
            IterateProcessInstanceArrayIfNotEmpty(wiList, "Filter.AllProcesses");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in Filter.AllProcesses", e);
        }
    }


    public void getAllActiveProcesses(TestRecorder tr)
        throws Exception
    {
        try {

            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.AllActiveProcesses);
            Object[] wiList = wfObjectList.getNextBatch(10);
            IterateProcessInstanceArrayIfNotEmpty(wiList, "Filter.AllActiveProcesses");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in Filter.AllActiveProcesses", e);
        }
    }



    public void getAllArchivedProcesses(TestRecorder tr)
        throws Exception
    {
        try {

            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.openList(Filter.AllArchivedProcesses);
            Object[] wiList = wfObjectList.getAllObjects();
            IterateProcessInstanceArrayIfNotEmpty(wiList, "Filter.AllArchivedProcesses");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in Filter.AllArchivedProcesses", e);
        }
    }



    public void getAllWorkItems(TestRecorder tr)
        throws Exception
    {
        try {
            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.AllWorkItems);
            Object[] wiList = wfObjectList.getNextBatch(200);
            IterateWorkItemArrayIfNotEmpty(wiList, "Filter.AllWorkItems");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in Filter.AllWorkItems", e);
        }
    }

    public void reassignWorkItems(TestRecorder tr)
        throws Exception
    {
        WorkItem wi = null;
        long wiId = -1;
        try {
            //why do we believe that there will be a workitem with ACTIVITY1 in it?
            wi = waitForWorkItem("ACTIVITY1", wfSession.getUserName(), Filter.MyActiveWorkItems, "'IFLOW_API_TEST'", -1, tr);
            wiId = wi.getId();
            wfSession.reassign(wi.getAssignee(),"twfserver",wi.getProcessInstanceId(), wi.getId(), false);
            debug("WorkItem ID ::: " + wi.getId() + " reassigned to twfserver  ");
            tr.markPassed("WFAdminSession.reassign()");
        }
        catch (Exception e) {
            e.printStackTrace();
            tr.markFailed("WFAdminSession.reassign()", "Exception while reassigning workitem id " + wiId + "to user twfserver: " + e.toString());
            logAndRethrow("Exception caught in reassignWorkItems while reassigning workitem id " + wiId + "to user twfserver", e);
        }
    }


    public void reassignWorkItemsToOriginalUser(TestRecorder tr)
        throws Exception
    {
        WorkItem wi = null;
        long wiId = -1;
        try {
            wi = waitForWorkItem("ACTIVITY1", "twfserver", Filter.AllWorkItems,
                                 "'IFLOW_API_TEST'", -1, tr);
            wiId = wi.getId();
            wfSession.reassign("twfserver" , wi.getInitiator(), wi.getProcessInstanceId(), wi.getId(), false);
            debug("WorkItem ID ::: " + wi.getId() + " reassigned to original user");
            tr.markPassed("WFAdminSession.reassign()");
        }
        catch (Exception e) {
            tr.markFailed("WFAdminSession.reassign()", "Exception while reassigning workitem id " + wiId + "to original user: " + e.toString());
            logAndRethrow("Exception caught in reassignWorkItemsToOriginalUser while reassigning workitem id " + wiId + "to original user", e);
        }
    }

    public void acceptMyWorkItems(TestRecorder tr)
        throws Exception
    {
        WorkItem wi = null;
        long wiId = -1;
        try {
            wi = waitForWorkItem("ACTIVITY1", wfSession.getUserName(), Filter.MyActiveWorkItems,
                                 "'IFLOW_API_TEST'", -1, tr);
            wiId = wi.getId();
            wi.accept();
            debug("acceptMyWorkItems : Accepted ACTIVITY1 workitem id " + wi.getId());
            tr.markPassed("acceptMyWorkItems");
        }
        catch (Exception e) {
            tr.markFailed("acceptMyWorkItems", "Exception while making choice on ACTIVITY1 workitem id " + wiId + ": " + e.toString());
            logAndRethrow("Exception caught in acceptMyWorkItems while making choice on ACTIVITY1 workitem id " + wiId, e);
        }
    }

    public void getMyAcceptedWorkItems(TestRecorder tr)
        throws Exception
    {
        WorkItem wi = null;
        long wiId = -1;
        try {
            wi = waitForWorkItem("ACTIVITY1", wfSession.getUserName(), Filter.MyAcceptedWorkItems,
                                 "'IFLOW_API_TEST'", -1, tr);
            wiId = wi.getId();
            wi.makeChoice("CHECK");
            debug("getMyAcceptedWorkItems : made choice 'CHECK' on workitem id " + wi.getId());
            tr.markPassed("Filter.MyAcceptedWorkItems");
        }
        catch (Exception e) {
            tr.markFailed("Filter.MyAcceptedWorkItems", "Exception while making choice on ACTIVITY1 workitem id " + wiId + ": " + e.toString());
            logAndRethrow("Exception caught in getMyAcceptedWorkItems while making choice on ACTIVITY1 workitem id " + wiId, e);
        }
    }

    public void getAllInactiveWorkItems(TestRecorder tr)
        throws Exception
    {
        try {
            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.AllInactiveWorkItems);
            Object[] wiList = wfObjectList.getNextBatch(200);
            //test should be designed to always have something in the list, otherwise you are not testing anything!
            //AssertObjectArrayNotEmpty(wiList);
            if (wiList != null) {
                if (wiList.length > 0) {
                    for(int i = 0; i < wiList.length; i++) {
                        WorkItem wi = (WorkItem) wiList[i];
                        debug(" WorkItem ID is ::: " + wi.getId() + " Name is ::: " + wi.getName() + " Assignee is ::: " + wi.getAssignee());
                    }
                    tr.markPassed("Filter.AllInactiveWorkItems - Number of WorkItems retrieved = " + wiList.length);
                }
            }
            else {
                tr.markPassed("Filter.AllInactiveWorkItems - No workitems retrieved for AllInactiveWorkItems Filter.");
            }
        }
        catch (Exception e) {
            tr.markFailed("Filter.AllInactiveWorkItems - exeption", e.toString());
            logAndRethrow("Exception caught in getAllInactiveWorkItems", e);
        }
    }

    public void completeMyActiveWorkItems(TestRecorder tr)
        throws Exception
    {
        WorkItem wi = null;
        long wiId = -1;
        try {
            wi = waitForWorkItem("ACTIVITY2", wfSession.getUserName(), Filter.MyActiveWorkItems,
                                 "'IFLOW_API_TEST'", -1, tr);
            wiId = wi.getId();
            wi.accept();
            wi.makeChoice("DONE");
            debug("completeMyActiveWorkItems : made choice 'DONE' on ACTIVITY2 workitem id " + wi.getId());
            tr.markPassed("Filter.MyActiveWorkItems");
        }
        catch (Exception e) {
            tr.markFailed("Filter.MyActiveWorkItems", "Exception while making choice on ACTIVITY2 workitem id " + wiId + ": " + e.toString());
            logAndRethrow("Exception caught in completeMyActiveWorkItems while making choice on ACTIVITY2 workitem id " + wiId, e);
        }
    }


    public void getMyCompletedWorkItems(TestRecorder tr)
        throws Exception
    {
        try {
            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.openBatchedList(Filter.MyCompletedWorkItems);
            Object[] wiList = wfObjectList.getNextBatch(100);
            IterateWorkItemArrayIfNotEmpty(wiList, "Filter.MyCompletedWorkItems");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in getMyCompletedWorkItems", e);
        }
    }



    public void getMyActiveWorkItems1(TestRecorder tr)
        throws Exception
    {
        WorkItem wi = null;
        long wiId = -1;
        try {
            wi = waitForWorkItem("ACTIVITY3", wfSession.getUserName(), Filter.MyActiveWorkItems,
                                 "'IFLOW_API_TEST'", -1, tr);
            wiId = wi.getId();
            wi.accept();
            // This activity has a 1 second timer. We need that timer to expire and the JavaAction to execute
            // in order to get proper test results. MakeChoice should not be done before the timer expires.
            // Sleep 3 seconds before making choice.
            Thread.sleep(3000);
            wi.makeChoice("DONE");
            debug("getMyActiveWorkItems : made choice 'DONE' on ACTIVITY3 workitem id " + wi.getId());
            tr.markPassed("Filter.MyActiveWorkItems");
        }
        catch (Exception e) {
            tr.markFailed("Filter.MyActiveWorkItems", "Exception while making choice on ACTIVITY3 workitem id " + wiId + ": " + e.toString());
            logAndRethrow("Exception caught in getMyActiveWorkItems while making choice on ACTIVITY3 workitem id " + wiId, e);
        }
    }



    public void getMyDeclinedWorkItems(TestRecorder tr)
        throws Exception
    {
        try {
            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.MyDeclinedWorkItems);
            Object[] wiList = wfObjectList.getNextBatch(10);
            //test should be designed to always have something in the list, otherwise you are not testing anything!
            IterateWorkItemArrayIfNotEmpty(wiList, "Filter.MyDeclinedWorkItems");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in getMyDeclinedWorkItems", e);
        }
    }



    public void getMyPlans(TestRecorder tr)
        throws Exception
    {
        try {
            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.MyPlans);
            Object[] wiList = wfObjectList.getNextBatch(50);
            IteratePlanArrayIfNotEmpty(wiList, "Filter.MyPlans");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in getMyPlans", e);
        }
    }


    public void getMyInactivePlans(TestRecorder tr)
        throws Exception
    {
        try {
            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.MyInactivePlans);
            Object[] wiList = wfObjectList.getNextBatch(50);
            //test should be designed to always have something in the list, otherwise you are not testing anything!
            IteratePlanArrayIfNotEmpty(wiList, "Filter.MyInactivePlans");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in getMyInactivePlans", e);
        }
    }


    public void getAllPlans(TestRecorder tr)
        throws Exception
    {
        try {
            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.AllPlans);
            Object[] wiList = wfObjectList.getNextBatch(50);
            IteratePlanArrayIfNotEmpty(wiList, "Filter.AllPlans");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in getAllPlans", e);
        }
    }



    public void getAllArchivedPlans(TestRecorder tr)
        throws Exception
    {
        try {
            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.openList(Filter.AllArchivedPlans);
            Object[] wiList = wfObjectList.getAllObjects();
            IteratePlanArrayIfNotEmpty(wiList, "Filter.AllArchivedPlans");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in getAllArchivedPlans", e);
        }
    }



    public void getLastList(TestRecorder tr)
        throws Exception
    {
        try {
            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.openList(Filter.FILTER_LAST);
            Object[] wiList = wfObjectList.getAllObjects();
            //test should be designed to always have something in the list, otherwise you are not testing anything!
            IterateObjectArrayIfNotEmpty(wiList, "Filter.FILTER_LAST");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in getLastList", e);
        }
    }



    public void getPlanVersionInfo(TestRecorder tr)
        throws Exception
    {
        try {

            try {
                wfSession.createPlanVersion(APITEST,"TestingPlanVersion API's", resultPlan);
                tr.markPassed("WFAdminSession.createPlanVersion(planName, versionComment, Plan)");
            }
            catch (Exception e) {
                tr.markFailed("WFAdminSession.createPlanVersion(planName, versionComment, Plan)", " Failed while creating Plan version ");
                logAndRethrow("WFAdminSession.createPlanVersion(planName, versionComment, Plan)" , e);
            }
            PlanVersionHistoryElement[] planVersionHistory = null;
            try {
                planVersionHistory = wfSession.getPlanVersionHistory(APITEST);
                tr.markPassed("WFAdminSession.getPlanVersionHistory()");
            }
            catch (Exception e) {
                tr.markFailed("WFAdminSession.getPlanVersionHistory()", " Failed while retrieving Plan version history");
                logAndRethrow("WFAdminSession.getPlanVersionHistory()" , e);
            }

            for (int i=0;i<planVersionHistory.length;i++) {
                if (i==0) {
                    continue;
                }
                else {

                try {
                    long creationTime = planVersionHistory[i].getCreationTime();
                    tr.markPassed("PlanVersionHistoryElement.getCreationTime()");
                }
                catch (Exception e) {
                    tr.markFailed("PlanVersionHistoryElement.getCreationTime()"," Possibly an error");
                    logAndRethrow("PlanVersionHistoryElement.getCreationTime()" , e);
                }
                int majorVersion = planVersionHistory[i].getMajorVersion();
                if (majorVersion>0) {
                    tr.markPassed("PlanVersionHistoryElement.getMajorVersion()");
                }
                else {
                    tr.markFailed("PlanVersionHistoryElement.getMajorVersion()"," Possibly an error");
                }
                testAndReport("PlanVersionHistoryElement.getMinorVersion()", planVersionHistory[i].getMinorVersion(), 0);
                testAndReport("PlanVersionHistoryElement.getOwner()", planVersionHistory[i].getOwner(), tr.getRequiredProperty("username"));

                String parentVersion = planVersionHistory[i].getParentVersion();
                if (parentVersion == null) {
                    tr.markPassed("PlanVersionHistoryElement.getParentVersion() Excpected 'null' ");
                }
                else if((parentVersion != null) && (parentVersion.trim().length() == 0))
                {
                    tr.markPassed("PlanVersionHistoryElement.getParentVersion() Excpected 'null' ");
                }
                else {
                    tr.markFailed("PlanVersionHistoryElement.getParentVersion()","Excpected 'null' but got a " + parentVersion + " value " );
                }

                long planId = planVersionHistory[i].getPlanId();
                if (planId>0) {
                    tr.markPassed("PlanVersionHistoryElement.getPlanId()");
                }
                else {
                    tr.markFailed("PlanVersionHistoryElement.getPlanId()","Expected a value grater than zero, but got '"+planId+"' instead.");
                }
                testAndReport("PlanVersionHistoryElement.getState()", planVersionHistory[i].getState(), 0);

                testAndReport("PlanVersionHistoryElement.getVersionComment()",
                              planVersionHistory[i].getVersionComment(),
                              "TestingPlanVersion API's");
                }
            }

            try {
                wfSession.createPlanVersion(APITEST,"TestingPlanVersion API's");
                tr.markPassed("WFAdminSession.createPlanVersion(planName, versionComment)");
            }
            catch (Exception e) {
                tr.markFailed("WFAdminSession.createPlanVersion(planName, versionComment)", " Failed while creating Plan version ");
                logAndRethrow("WFAdminSession.createPlanVersion(planName, versionComment)" , e);
            }

            try {
                wfSession.createPlanVersion(APITEST,"TestingPlanVersion API's", "1.0");
                tr.markPassed("WFAdminSession.createPlanVersion(planName, versionComment, versionFrom)");
            }
            catch (Exception e) {
                tr.markFailed("WFAdminSession.createPlanVersion(planName, versionComment, versionFrom)", " Failed while creating Plan version ");
                logAndRethrow("WFAdminSession.createPlanVersion(planName, versionComment, versionFrom)" , e);
            }

        }
        catch (Exception e) {
            logAndRethrow("Exception caught in getPlanVersionInfo", e);
        }
    }

    private ProcessInstance waitForProcessCompletion(TestRecorder tr)
        throws Exception
    {
        String msg = "Waiting for process id " + piId + " to complete";
        debug(msg);
        SafeSleep sleeper = new SafeSleep(msg);
        ProcessInstance pi = WFObjectFactory.getProcessInstance(piId, wfSession);;
        while(pi.getState() != ProcessInstance.STATE_CLOSED)
        {
            sleeper.nap();
            pi = WFObjectFactory.getProcessInstance(piId, wfSession);
        }
        return pi;
    }

    public void checkJavaActionExecution(TestRecorder tr)
        throws Exception
    {
        try {
            ProcessInstance pi = waitForProcessCompletion(tr);
            testAndReport("UDA value of PlanInitJAS", pi.getDataItem("PlanInitJAS").getValue(), "ProcessInitialized");
            if(tr.getProperty("ExampleJABeanDeployed", "no").equalsIgnoreCase("yes"))
                testAndReport("UDA value of PlanCommitJAS", pi.getDataItem("PlanCommitJAS").getValue(), "Hello, TEST!");
            testAndReport("UDA value of ActPrologueJAS", pi.getDataItem("ActPrologueJAS").getValue(),"ActivityInitialized");
            testAndReport("UDA value of ActEpilogueJAS", pi.getDataItem("ActEpilogueJAS").getValue(),"ActivityCompleted");
            testAndReport("UDA value of ActRoleJAS", pi.getDataItem("ActRoleJAS").getValue(),"RoleChanged");
            testAndReport("UDA value of ConditionPrologueJAS", pi.getDataItem("ConditionPrologueJAS").getValue(),"ConditionNodeInitalized");
            testAndReport("UDA value of ConditionEpilogueJAS", pi.getDataItem("ConditionEpilogueJAS").getValue(),"ConditionNodeEvaluated");
            testAndReport("UDA value of OrEpilogueJAS", pi.getDataItem("OrEpilogueJAS").getValue(),"OrNodeEvaluated");
            testAndReport("UDA value of AndEpilogueJAS", pi.getDataItem("AndEpilogueJAS").getValue(),"AndNodeEvaluated");
            testAndReport("UDA value of DelayPrologueJAS", pi.getDataItem("DelayPrologueJAS").getValue(),"DelayNodeInitialized");
            testAndReport("UDA value of DelayEpilogueJAS", pi.getDataItem("DelayEpilogueJAS").getValue(),"DelayNodeEvaluated");
            testAndReport("UDA value of nameListAtt", pi.getDataItem("nameListAtt").getValue(),"iflow");
            testAndReport("UDA value of groupListAtt", pi.getDataItem("groupListAtt").getValue(),"TWFAdminRole");
            testAndReport("UDA value of TimerJAS", pi.getDataItem("TimerJAS").getValue(),"TimerExecuted");
            testAndReport("UDA value of SubprocessPrologueJAS", pi.getDataItem("SubprocessPrologueJAS").getValue(),"SubprocessNodeInitalized");
            testAndReport("UDA value of SubprocessEpilogueJAS", pi.getDataItem("SubprocessEpilogueJAS").getValue(),"SubprocessNodeCompleted");
        }
        catch (Exception e) {
            logAndRethrow("Exception caught in checkJavaActionExecution", e);
        }
    }

    private void
    IterateObjectArrayIfNotEmpty(Object [] wiList, String testSetting)
        throws Exception
    {
        if (wiList == null) {
            return;
        }
        if (wiList.length == 0) {
            return;
        }
        for(int i = 0; i < wiList.length; i++) {
            if (wiList[i] == null) {
                tr.markFailed(testSetting, "array of objects had a null at index="+i);
                return;
            }
        }
        tr.markPassed(testSetting);
    }

    private void
    IterateProcessInstanceArrayIfNotEmpty(Object [] piList, String testSetting)
        throws Exception
    {
        tr.log("Looking for "+testSetting+".  There might not be any, in which case this test will not really test them.");
        if (piList == null) {
            return;
        }
        if (piList.length == 0) {
            return;
        }
        for(int i = 0; i < piList.length; i++) {
            ProcessInstance pi = (ProcessInstance) piList[i];
            if (pi== null) {
                tr.markFailed(testSetting, "array had no ProcessInstance at index="+i);
                return;
            }
        }
        tr.markPassed(testSetting);
    }

    private void
    IterateWorkItemArrayIfNotEmpty(Object [] wiList, String testSetting)
        throws Exception
    {
        if (wiList == null) {
            return;
        }
        if (wiList.length == 0) {
            return;
        }
        for(int i = 0; i < wiList.length; i++) {
            WorkItem wi = (WorkItem) wiList[i];
            if (wi== null) {
                tr.markFailed(testSetting, "array had no WorkItem at index="+i);
                return;
            }
        }
        tr.markPassed(testSetting);
    }


    private void
    IteratePlanArrayIfNotEmpty(Object [] plList, String testSetting)
        throws Exception
    {
        if (plList == null) {
            return;
        }
        if (plList.length == 0) {
            return;
        }
        for(int i = 0; i < plList.length; i++) {
            Plan pl = (Plan) plList[i];
            if (pl== null) {
                tr.markFailed(testSetting, "array had no Plan at index="+i);
                return;
            }
        }
        tr.markPassed(testSetting);
    }

    public void testErrorMessage()
    {

        String error = "Unable to authenticate user";
        String error2 = "Unable to complete the login request";
        try {
            String username = "api_bogus_username";
            String password = "api_bogus_password_xx";
            wfSession = WFObjectFactory.getWFAdminSession();
            wfSession.initForApplication(null,tr.getProps());
            wfSession.logIn(tr.getRequiredProperty("servername") +"Flow", username, password);
            tr.markFailed("Login error message", "Expected '"+error + " or " +error2+"' but got '"+"no error message"+"' instead.");
        }
        catch (Exception e) {
            if(e.toString().indexOf(error)>=0 || e.toString().indexOf(error2)>=0) {
                tr.markPassed("ErrorMessage.properties file exists inside i-Flow model");
            }
            else {
               tr.markFailed("ErrorMessage.properties file exists inside i-Flow model",
                             "Expected '"+error+ " or " + error2 + "' but got '"+e.toString()+"' instead.");
            }
        }
    }


    public void logOut()
        throws Exception
    {
        try {
            if (wfSession != null) {
                wfSession.logOut();
                wfSession = null;
            }
        } catch (Exception e) {
            logAndRethrow("Exception caught while trying to logOut", e);
        }
    }

    public void cleanup() throws Exception
    {
       try {

            WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST_SUBPLAN'");
            wfObjectList.openBatchedList(Filter.AllProcesses);
            Object[] wiList = wfObjectList.getNextBatch(10);
            if (wiList != null) {
                if (wiList.length > 0) {
                    for(int i = 0; i < wiList.length; i++) {
                        ProcessInstance pi = (ProcessInstance) wiList[i];
                        wfSession.deleteProcessInstance(pi.getId());
                    }
               }
            }


            wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.AllProcesses);
            wiList = wfObjectList.getNextBatch(10);
            if (wiList != null) {
                if (wiList.length > 0) {
                    for(int i = 0; i < wiList.length; i++) {
                        ProcessInstance pi = (ProcessInstance) wiList[i];
                        wfSession.deleteProcessInstance(pi.getId());
                    }
               }
            }

            wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_NAME,"=","'IFLOW_API_TEST_SUBPLAN'");
            wfObjectList.openBatchedList(Filter.AllPlans);
            wiList = wfObjectList.getNextBatch(50);
            if (wiList != null) {
                if (wiList.length > 0) {
                    for(int i = 0; i < wiList.length; i++) {
                        Plan pl = (Plan) wiList[i];
                        wfSession.deletePlan(pl.getId());
                    }
                }
            }

            wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
            wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_NAME,"=","'IFLOW_API_TEST'");
            wfObjectList.openBatchedList(Filter.AllPlans);
            wiList = wfObjectList.getNextBatch(50);
            if (wiList != null) {
                if (wiList.length > 0) {
                    for(int i = 0; i < wiList.length; i++) {
                        Plan pl = (Plan) wiList[i];
                        wfSession.deletePlan(pl.getId());
                    }
                }
            }
            tr.markPassed("Clean up processes and templates from previous test run");
        }
        catch (Exception e)
        {
            logAndRethrow("Exception caught in cleanup", e);
        }


    }

    public
    void
    logAndRethrow(
        String message,
        Exception e)
            throws Exception
    {
        throw new ExceptionWrapper(message, e);
    }

    /**
    * TestDriver is the class that knows how to run these tests.
    * So just call it with the name of this class in there.
    */
    public
    static
    void
    main(String[] args) {
        String[] newArgs = new String[1];
        newArgs[0] = "com.fujitsu.iflowqa.testframe.APITest";
        TestDriver.main(newArgs);
        System.exit(0);
    }
}

