package com.fujitsu.iflowqa.testframe;

import com.fujitsu.iflow.model.workflow.DataItemRef;
import com.fujitsu.iflow.model.workflow.Filter;
import com.fujitsu.iflow.model.workflow.Plan;
import com.fujitsu.iflow.model.workflow.ProcessInstance;
import com.fujitsu.iflow.model.workflow.ProcessInstantiator;
import com.fujitsu.iflow.model.workflow.WFObjectFactory;
import com.fujitsu.iflow.model.workflow.WFObjectList;
import com.fujitsu.iflow.model.workflow.WorkItem;
import com.fujitsu.iflowqa.testframe.BPMTestBase;
import com.fujitsu.iflowqa.testframe.TestDriver;
import com.fujitsu.iflowqa.testframe.TestRecorder;

public class TestEstimateCount extends BPMTestBase {

    private String xpdlFileName = "TestEstimateCount.xpdl";
    
	public TestEstimateCount() {
	}

	public void runTests(TestRecorder tr) throws Exception {
		init(tr);
		login();

		// Loading xpdl and creating process instances
		// New Tests

	    loadFiles(tr);

		ELC01_getAllProcessDefinitions(tr);
		ELC02_getAllProcessInstance(tr);
		ELC03_getAllWorkitemsQuery(tr);
		ELC06_getAllPlansQuery(tr);
		ELC09_getProcessInstanceQuery(tr);
		ELC11_getWorkItemQuery(tr);
		ELC13_getPlanIDAscOrder(tr);
		ELC14_getProcessInstanceIDAscOrder(tr);
        ELC15_getAllWorkitems(tr);
		ELC23_getAllWorkitemsAscOrder(tr);
		ELC29_getAllPlanQuery(tr);
		ELC31_getAllActiveProcessQuery(tr);
		ELC33_getActiveWorkitemQuery(tr);
		ELC38and39_getAllWorkListItems(tr);
		ELC40_getMyActiveProcessInstanceOrderAndUDA(tr);

        ELC41_getAllWorkItemsAndUDA(tr);
		ELC42_getAllPlansAndUDA(tr);
		ELC43_getAllProcessesAndUDA(tr);


        ELC44_getAllWorkItemAndUDA(tr);
		ELC45_getAllWorkListItems(tr);

	    ELC51_comparePDCount(tr);
//	    ELC52_compareWorkItemCount(tr);
	    ELC53_compareProcessInstanceCount(tr);
		ELC54_getAllInActiveProcess(tr);
		ELC55_getAllProcessesInErrorState(tr);
		ELC56_getMyInActiveProcess(tr);
		ELC57_getAllInActiveWorkItems(tr);
		ELC58_getMyAcceptedWorkItems(tr);
		ELC59_getMyDeclinedWorkItems(tr);
		ELC60_getAllArchievedPlan(tr);
		ELC61_getAllArchievedProcesses(tr);
		ELC62_getAllInactiveWorkItem(tr);

		logOut();
	}

    void
    change(boolean b) 
    {
        b = true;
        tr.log("b="+b);
    }

	/*
	 * If No advanced filter is specified correct count should be return of
	 * process definition
	 */

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

			WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);

			wfObjectList.openBatchedList(Filter.AllPlans);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;

			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC01_getAllProcessDefinitions()");
				tr.log("Passed ELC01_getAllProcessDefinitions()");
			} else {
				markFailed("ELC01_getAllProcessDefinitions()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC01_getAllProcessDefinitions()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC01_getUserPlans Testing Failed");
		}
	} // end of the method ELC01_getUserPlans

	/*
	 * If No advanced filter is specified, correct count should be return for
	 * the Process instance
	 */
	public void ELC02_getAllProcessInstance(TestRecorder tr) throws Exception {
		try {

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);

			wfObjectList.openBatchedList(Filter.AllProcesses);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}
            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC02_getAllProcessInstance()");
				tr.log("Passed ELC02_getAllProcessInstance()");
			} else {
				markFailed("ELC02_getAllProcessInstance()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC02_getAllProcessInstance()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC02_getAllProcessInstance Testing Failed");
		}
	} // end of the method ELC01_getUserPlans

	/*
	 * If No advanced filter is specified, correct count should be return for
	 * the Workitem
	 */

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

			WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);

			wfObjectList.openBatchedList(Filter.MyActiveWorkItems);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC03_getAllWorkitemsQuery()");
				tr.log("Passed ELC03_getUserPlansQuery()");
			} else {
				markFailed("ELC03_getAllWorkitemsQuery()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC03_getAllWorkitemsQuery()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC03_getAllWorkitems() Testing Failed");
		}
	} // end of the method ELC01_getUserPlans

	/*
	 * : If Advanced filter is specified correct count should be return for the
	 * Process definition, Condition is process definition id<500.
	 */

	public void ELC06_getAllPlansQuery(TestRecorder tr) throws Exception {
		WFObjectList wfObjectList = null;
		try {

			wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_NAME, WFObjectList.SQLOP_GREATERTHAN, "'500'");
			wfObjectList.openBatchedList(Filter.MyPlans);
			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);

			if (countFromIteration == estimatedCount) {
				markPassed("ELC06_getAllPlansQuery()");
				tr.log("Passed ELC06_getAllPlansQuery()");
			} else {
				markFailed("ELC06_getAllPlansQuery",
						"estimatedCount and PlanID Count greater than 500 do not match");
				tr.log("Failed ELC06_getAllPlansQuery()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC06_getAllPlansQuery Testing Failed");
		}
	} // end of the method ELC01_getUserPlans

	/*
	 * If Advanced filter is specified correct count should be return for the
	 * Process instance. Condition is processinstance id<2000
	 *
	 */
	public void ELC09_getProcessInstanceQuery(TestRecorder tr) {
		WFObjectList wfObjectList = null;

		try {

			wfObjectList = WFObjectFactory.getWFObjectList(wfSession);

			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_INITIATOR,
					WFObjectList.SQLOP_EQUALTO, "'" + username + "'");

			wfObjectList.openBatchedList(Filter.MyProcesses);
			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC09_getProcessInstanceQuery()");
				tr.log("Passed ELC09_getProcessInstanceQuery()");
			} else {
				markFailed("ELC09_getProcessInstanceQuery",
						"estimatedCount and PlanID Count greater than 500 do not match");
				tr.log("Failed ELC09_getProcessInstanceQuery()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC09_getProcessInstanceQuery() Testing Failed");
		}
	}

	/*
	 * If Advanced filter is specified correct count should be return for the
	 * Work item. Condition is workitem id>1000
	 */

	public void ELC11_getWorkItemQuery(TestRecorder tr) {
		WFObjectList wfObjectList = null;
		try {
			wfObjectList = WFObjectFactory.getWFObjectList(wfSession);

			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_ID,
					WFObjectList.SQLOP_LESSTHAN, "'1000'");
			wfObjectList.openBatchedList(Filter.MyActiveWorkItems);
			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC11_getWorkItemQuery()");
				tr.log("Passed ELC11_getWorkItemQuery()");
			} else {
				markFailed("ELC11_getWorkItemQuery", "Counts Do not match");
				tr.log("Failed ELC11_getWorkItemQuery()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC11_getWorkItemQuery Testing Failed");
		}
	}

	/*
	 * If Sorting not specified on id field in ascending order for the process
	 * definition
	 */

	public void ELC13_getPlanIDAscOrder(TestRecorder tr) {
		WFObjectList wfObjectList = null;
		try {
			wfObjectList = WFObjectFactory.getWFObjectList(wfSession);

			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_ID, WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.openBatchedList(Filter.AllPlans);
			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC13_getPlanIDAscOrder()");
				tr.log("Passed ELC13_getPlanIDAscOrder()");
			} else {
				markFailed("ELC13_getPlanIDAscOrder()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC13_getPlanIDAscOrder()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC13_getPlanIDAscOrder() Testing Failed");
		}
	}

	/*
	 * If Sorting not specified on id field in ascending order for the process
	 * instance, correct count should be return.
	 */
	public void ELC14_getProcessInstanceIDAscOrder(TestRecorder tr) {
		WFObjectList wfObjectList = null;
		try {
			wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
			
            //wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_ID, WFObjectList.SQLOP_EQUALTO, "'20772'");
            wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PROCESSINSTANCE_ID, WFObjectList.SORTORDER_ASCENDING);

			wfObjectList.openBatchedList(Filter.MyActiveProcesses);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC14_getProcessInstanceIDAscOrder()");
				tr.log("Passed ELC14_getProcessInstanceIDAscOrder()");
			} else {
				markFailed("ELC14_getProcessInstanceIDAscOrder()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC14_getProcessInstanceIDAscOrder()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC14_getProcessInstanceIDAscOrder() Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);

			wfObjectList.openBatchedList(Filter.MyActiveWorkItems);
			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC15_getAllWorkitems()");
				tr.log("Passed ELC15_getUserPlans()");
			} else {
				markFailed("ELC15_getAllWorkitems()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC15_getAllWorkitems()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC15_getAllWorkitems() Testing Failed");
		}
	} // end of the method ELC01_getUserPlans

	/*
	 * If sorting is specified on id field in the ascending order for the
	 * process definition where process definition id >500
	 */
	public void ELC17_getAllPlanIDQueryAscOrder(TestRecorder tr)
			throws Exception {
		try {
			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_ID,
					WFObjectList.SQLOP_GREATERTHAN, "'500'");
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_ID,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.openBatchedList(Filter.AllPlans);
			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC17_getAllPlanIDQueryAscOrder()");
				tr.log("Passed ELC17_getAllPlanIDQueryAscOrder()");
			} else {
				markFailed("ELC17_getAllPlanIDQueryAscOrder()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC17_getAllPlanIDQueryAscOrder()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC17_getAllPlanIDQueryAscOrder() Testing Failed");
		}
	} // end of the method ELC01_getUserPlans

	public void ELC19_getProcessInstanceIDQueryAscOrder(TestRecorder tr) {
		WFObjectList wfObjectList = null;
		try {
			wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_ID,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.openBatchedList(Filter.AllProcesses); // or

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC19_getProcessInstanceIDQueryAscOrder()");
				tr.log("Passed ELC19_getProcessInstanceIDQueryAscOrder()");
			} else {
				markFailed("ELC19_getProcessInstanceIDQueryAscOrder()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC19_getProcessInstanceIDQueryAscOrder()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC19_getProcessInstanceIDQueryAscOrder() Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_WORKITEM_ID,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.openBatchedList(Filter.MyWorkItems);
			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC23_getAllWorkitemsAscOrder()");
				tr.log("Passed ELC23_getAllWorkitemsAscOrder()");
			} else {
				markFailed("ELC23_getAllWorkitemsAscOrder()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC23_getAllWorkitemsAscOrder()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC23_getAllWorkitemsAscOrder() Testing Failed");
		}
	} // end of the method ELC23_getAllWorkitemsAscOrder

	// Some problems due to compound condition
	public void ELC26_getAllWorkitemsQuery(TestRecorder tr) throws Exception {
		try {

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);

			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE,
					WFObjectList.SQLOP_EQUALTO, "'ibpm_server1'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_STATE,
					WFObjectList.SQLOP_EQUALTO, "'3'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_NAME,
					WFObjectList.SQLOP_EQUALTO, "'Activity11'");

			wfObjectList.openBatchedList(Filter.MyActiveWorkItems);
			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}
            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC26_getAllWorkitemsQuery()");
				tr.log("Passed ELC26_getAllWorkitemsQuery()");
			} else {
				markFailed("ELC26_getAllWorkitemsQuery()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC26_getAllWorkitemsQuery()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC26_getAllWorkitemsQuery() Testing Failed");
		}
	} // end of the method ELC26_getAllWorkitemsQuery

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);

			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_OWNER,
					WFObjectList.SQLOP_EQUALTO, "'"+username+"'");

			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_ID,
					WFObjectList.SORTORDER_DESCENDING);

			wfObjectList.openBatchedList(Filter.AllPlans);
			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC29_getAllPlanQuery()");
				tr.log("Passed ELC29_getAllPlanQuery()");
			} else {
				markFailed("ELC29_getAllPlanQuery()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC29_getAllPlanQuery()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC29_getAllPlanQuery() Testing Failed");
		}
	} // end of the method ELC29_getAllPlanQuery

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);

			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_ID, WFObjectList.SORTORDER_DESCENDING);

			wfObjectList.openBatchedList(Filter.MyActiveProcesses);
			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC31_getAllActiveProcessQuery()");
				tr.log("Passed ELC31_getAllActiveProcessQuery()");
			} else {
				markFailed("ELC31_getAllActiveProcessQuery()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC31_getAllActiveProcessQuery()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC31_getAllActiveProcessQuery() Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_ID,
					WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.openBatchedList(Filter.MyActiveWorkItems);
			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC33_getActiveWorkitemQuery()");
				tr.log("Passed ELC33_getActiveWorkitemQuery()");
			} else {
				markFailed("ELC33_getActiveWorkitemQuery()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC33_getActiveWorkitemQuery()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC33_getActiveWorkitemQuery() Testing Failed");
		}
	} // end of the method ELC33_getActiveWorkitemQuery

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);


//			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE, WFObjectList.SQLOP_EQUALTO, "'ibpm_server1'");
//			wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_ID, WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");
//			wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_TITLE, WFObjectList.SQLOP_EQUALTO, "'First'");
//			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_NAME, WFObjectList.SQLOP_EQUALTO, "'Activity1'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE, WFObjectList.SQLOP_EQUALTO, "'"+username+"'");
///			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_STATE, WFObjectList.SQLOP_EQUALTO, "'3'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_NAME, WFObjectList.SQLOP_EQUALTO, "'TestEstimateCount'");

			// Sort order based on field

//			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_ID, WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PROCESSINSTANCE_ID, WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PROCESSINSTANCE_TITLE, WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_WORKITEM_NAME, WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE, WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_NAME, WFObjectList.SORTORDER_ASCENDING);

			// sort order based on UDA

			wfObjectList.addSortOrder("varBigDecimal", "BIGDECIMAL",
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder("varBoolean", "BOOLEAN",
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder("varDate", "DATE",
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder("varFloat", "FLOAT",
					WFObjectList.SORTORDER_ASCENDING);
                  
			wfObjectList.addSortOrder("varInteger", "INTEGER",
					WFObjectList.SORTORDER_ASCENDING);

			wfObjectList.addSortOrder("varLong", "LONG",
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder("varString1", "STRING",
					WFObjectList.SORTORDER_ASCENDING);

			wfObjectList.openBatchedList(Filter.AllWorkItems);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC38and39_getAllWorkListItems()");
				tr.log("Passed ELC38and39_getAllWorkListItems()");
			} else {
				markFailed("ELC38and39_getAllWorkListItems()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC38and39_getAllWorkListItems()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC38and39_getAllWorkListItems() Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);

			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_INITIATOR,
					WFObjectList.SQLOP_EQUALTO, "'" + username + "'");

			// added for facilating where clause for estimateCount()

			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_ID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_ID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");
			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_STATE,
					WFObjectList.SQLOP_GREATERTHAN, "'0'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_IDENTIFIER,
					WFObjectList.SQLOP_EQUALTO, "''");

			// sort order based on field

			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,
					WFObjectList.SORTORDER_ASCENDING);

			// sort order based on UDA

			wfObjectList.addSortOrder("varBigDecimal", "BIGDECIMAL",
					WFObjectList.SORTORDER_ASCENDING);

            wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE,WFObjectList.SQLOP_EQUALTO,"'"+username+"'");

			wfObjectList.openBatchedList(Filter.AllWorkItems);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC40_getMyActiveProcessInstanceOrderAndUDA()");
				tr.log("Passed ELC40_getMyActiveProcessInstanceOrderAndUDA()");
			} else {
				markFailed("ELC40_getMyActiveProcessInstanceOrderAndUDA()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC40_getMyActiveProcessInstanceOrderAndUDA()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC40_getMyActiveProcessInstanceOrderAndUDA() Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);

/*
			// added for facilating where clause for estimateCount()
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_ID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_NAME,
					WFObjectList.SQLOP_EQUALTO, "'TestEstimateCount'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_IDENTIFIER,
					WFObjectList.SQLOP_NOTEQUALTO, "''");
			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_INITIATOR,
					WFObjectList.SQLOP_EQUALTO, "'" + username + "'");
*/
            // sort order based on UDA
			wfObjectList.addSortOrder("varBigDecimal", "BIGDECIMAL",
					WFObjectList.SORTORDER_ASCENDING);

			// sort order based on field
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_CREATEDTIME,
					WFObjectList.SORTORDER_ASCENDING);

			wfObjectList.openBatchedList(Filter.AllActiveProcesses);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC41_getAllWorkItemsAndUDA()");
				tr.log("Passed ELC41_getAllWorkItemsAndUDA()");
			} else {
				markFailed("ELC41_getAllWorkItemsAndUDA()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC41_getAllWorkItemsAndUDA()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC41_getAllWorkItemsAndUDA() Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			// added for facilating where clause for estimateCount()
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_ID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_NAME,
					WFObjectList.SQLOP_LIKE, "'TestEstimateCount%'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_OWNER,
					WFObjectList.SQLOP_IN, "('"+username+"','usera')");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_STATE,
					WFObjectList.SQLOP_NOTEQUALTO, "'1'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_IDENTIFIER,
					WFObjectList.SQLOP_EQUALTO, "''");

			// sort order based on field
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_NAME,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_ID,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_OWNER,
					WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_STATE,
					WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_IDENTIFIER,
					WFObjectList.SORTORDER_DESCENDING);

			wfObjectList.openBatchedList(Filter.AllPlans);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

            tr.log("Estimated Count: " + estimatedCount + "\tIteration Count: " + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC42_getAllPlansAndUDA()");
				tr.log("Passed ELC42_getAllPlansAndUDA()");
			} else {
				markFailed("ELC42_getAllPlansAndUDA()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC42_getAllPlansAndUDA()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC42_getAllPlansAndUDA() Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);

			// added for facilating where clause for estimateCount()
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_ID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");

			wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_ID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");

			wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_INITIATOR,
					WFObjectList.SQLOP_EQUALTO, "'"+username+"'");

			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_NAME,
					WFObjectList.SQLOP_LIKE, "'TestEstimateCount'");

			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_IDENTIFIER,
					WFObjectList.SQLOP_NOTEQUALTO, "''");

			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_STATE,
					WFObjectList.SQLOP_EQUALTO, "'3'");

			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_PRIORITY,
					WFObjectList.SQLOP_GREATERTHAN, "'0'");

			wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,
					WFObjectList.SQLOP_EQUALTO, "'TestEstimateCount'");

			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_TITLE,
					WFObjectList.SQLOP_NOTEQUALTO, "'First'");


			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_PARENTID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");

//			wfObjectList.addFilter(
//					WFObjectList.LISTFIELD_PROCESSINSTANCE_CREATEDTIME,
//					WFObjectList.SQLOP_LESSTHAN, "'Feb 21, 2007 6:38 PM'");
//			wfObjectList.addFilter(
//					WFObjectList.LISTFIELD_PROCESSINSTANCE_CLOSEDTIME,
//					WFObjectList.SQLOP_GREATERTHANOREQUALTO,
//					"'Feb 21, 2007 6:38 PM'");

			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_OWNER,
					WFObjectList.SQLOP_EQUALTO, "'"+username+"'");

			wfObjectList.addFilter("varBigDecimal",
					DataItemRef.TYPE_BIGDECIMAL, WFObjectList.SQLOP_EQUALTO,
					"'0.00'");
			wfObjectList.addFilter("varBoolean", DataItemRef.TYPE_BOOLEAN,
					WFObjectList.SQLOP_EQUALTO, "'false'");
//			wfObjectList.addFilter("varDate", DataItemRef.TYPE_DATE,
//					WFObjectList.SQLOP_EQUALTO, "'Feb 22, 2007 2:59 PM '");
			wfObjectList.addFilter("varFloat", DataItemRef.TYPE_FLOAT,
					WFObjectList.SQLOP_EQUALTO, "'0.0'");
			wfObjectList.addFilter("varInteger", DataItemRef.TYPE_INTEGER,
					WFObjectList.SQLOP_EQUALTO, "'0'");
			wfObjectList.addFilter("varLong", DataItemRef.TYPE_LONG,
					WFObjectList.SQLOP_EQUALTO, "'0'");
			wfObjectList.addFilter("varString1", DataItemRef.TYPE_STRING,
					WFObjectList.SQLOP_EQUALTO, "''");

			// Sort order based on field
			// Code below showing error - WFObjectListImpl.openBatchedList: Invalid Filter or Invalid Sort Field (Filter = 0)
//			 wfObjectList.addSortOrder(
//					WFObjectList.LISTFIELD_PROCESSINSTANCE_OWNER,
//					WFObjectList.SORTORDER_ASCENDING);
//			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_ID,
//					WFObjectList.SORTORDER_DESCENDING);

			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_NAME,
				WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_IDENTIFIER,
					WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_ID,
					WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_STATE,
					WFObjectList.SORTORDER_DESCENDING);

			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_PRIORITY,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,
					WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_TITLE,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_PARENTID,
					WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_CREATEDTIME,
					WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_CLOSEDTIME,
					WFObjectList.SORTORDER_DESCENDING);


			wfObjectList.openBatchedList(Filter.AllProcesses);

			int estimatedCount = wfObjectList.estimateCount();
			System.out.println("Estimated Count:" + estimatedCount);

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}
			System.out.println("Count :" + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC43_getAllProcessesAndUDA()");
				tr.log("Passed ELC43_getAllProcessesAndUDA()");
			} else {
				markFailed("ELC43_getAllProcessesAndUDA()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC43_getAllProcessesAndUDA()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC43_getAllProcessesAndUDA() Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			// added for facilating where clause for estimateCount()

//			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_ID,
//					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");

			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_NAME,
					WFObjectList.SQLOP_LIKE, "'TestEstimateCount'");

			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_IDENTIFIER,
					WFObjectList.SQLOP_NOTEQUALTO, "''");

			wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_ID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");
			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_STATE,
					WFObjectList.SQLOP_EQUALTO, "'3'");
			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_PRIORITY,
					WFObjectList.SQLOP_GREATERTHAN, "'0'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,
					WFObjectList.SQLOP_EQUALTO, "'TestEstimateCount'");
			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_TITLE,
					WFObjectList.SQLOP_EQUALTO, "'First'");
//			wfObjectList.addFilter(
//					WFObjectList.LISTFIELD_PROCESSINSTANCE_CREATEDTIME,
//					WFObjectList.SQLOP_LESSTHAN, "'Feb 21, 2007 6:38 PM'");

//			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_CREATEDTIME,
//					WFObjectList.SQLOP_EQUALTO, "'6:38 PM'");
//			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_DUEDATE,
//					WFObjectList.SQLOP_EQUALTO, "'Feb 26, 2007'");
			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_INITIATOR,
					WFObjectList.SQLOP_EQUALTO, "'" + username + "'");

			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE,
					WFObjectList.SQLOP_EQUALTO, "'ibpm_server1'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_STATE,
					WFObjectList.SQLOP_EQUALTO, "'3'");


			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_PRIORITY,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");
			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_NAME,
					WFObjectList.SQLOP_EQUALTO, "'Activity1'");
			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_WORKITEM_ACTIVITYINSTANCEID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");
//

			// sort order for all allowed fields
			// when uncomment below code it throws an exception
//			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_ID,
//					WFObjectList.SORTORDER_ASCENDING);

			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_NAME,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_PLAN_IDENTIFIER,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_ID,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_STATE,
					WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_PRIORITY,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_TITLE,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_CREATEDTIME,
					WFObjectList.SORTORDER_DESCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_INITIATOR,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_WORKITEM_ID,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_WORKITEM_STATE,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_WORKITEM_CREATEDTIME,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_WORKITEM_DUEDATE,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_WORKITEM_PRIORITY,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(WFObjectList.LISTFIELD_WORKITEM_NAME,
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder(
					WFObjectList.LISTFIELD_WORKITEM_ACTIVITYINSTANCEID,
					WFObjectList.SORTORDER_ASCENDING);
//
//			// Sort order based on UDA
//
			wfObjectList.addSortOrder("varBigDecimal", "BIGDECIMAL",
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder("varBoolean", "BOOLEAN",
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder("varDate", "DATE",
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder("varFloat", "FLOAT",
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder("varInteger", "INTEGER",
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder("varLong", "LONG",
					WFObjectList.SORTORDER_ASCENDING);
			wfObjectList.addSortOrder("varString1", "STRING",
					WFObjectList.SORTORDER_ASCENDING);

			wfObjectList.openBatchedList(Filter.AllWorkItems);

			int estimatedCount = wfObjectList.estimateCount();
			System.out.println("Estimated Count:" + estimatedCount);

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}
			System.out.println("Count :" + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("ELC44_getAllWorkItemAndUDA()");
				tr.log("Passed ELC44_getAllWorkItemAndUDA()");
			} else {
				markFailed("ELC44_getAllWorkItemAndUDA()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC44_getAllWorkItemAndUDA()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC44_getAllWorkItemAndUDA() Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			// added for facilating where clause for estimateCount()
			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE,
					WFObjectList.SQLOP_EQUALTO, "'ibpm_server1'");

			// Advanced Filter for non worklist UDA
			wfObjectList.addFilter("varString2", "STRING", "=", "''");

			wfObjectList.openBatchedList(Filter.AllWorkItems);

			int estimatedCount = wfObjectList.estimateCount();
			// System.out.println("Estimated Count:" + estimatedCount);

			Object[] wiList = null;
			int countFromIteration = 0;
			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}
			// System.out.println("Count :" + countFromIteration);
			if (countFromIteration == estimatedCount) {
				markPassed("EL45_getAllWorkListItems()");
				tr.log("Passed EL45_getAllWorkListItems()");
			} else {
				markFailed("EL45_getAllWorkListItems()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed EL45_getAllWorkListItems()");
			}
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("EL45_getAllWorkListItems() Testing Failed");
		}
	}

	public void ELC51_comparePDCount(TestRecorder tr) throws Exception {
		WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
		wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_ID,
				WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");
		wfObjectList.openBatchedList(Filter.AllPlans);
		int initialCount = wfObjectList.estimateCount();

		// Adding a new plan
		Plan p = importXPDL(xpdlFileName);
		int countAfterImport = wfObjectList.estimateCount();
		// System.out.println(countAfterImport);
		wfSession.deletePlan(p.getId());
		// Removing Plan from Database
		int countAfterDeletion = wfObjectList.estimateCount();
		// System.out.println(countAfterDeletion);

		if (countAfterImport > initialCount) {
			if (countAfterDeletion < countAfterImport)
				tr.markPassed("ELC51_comparePDCount()");
			else
				tr.markFailed("ELC51_comparePDCount()", "");
		} else {
			tr.markFailed("ELC51_comparePDCount()", "");
		}
	}

	public void ELC52_compareWorkItemCount(TestRecorder tr) throws Exception {
		WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
//		wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE,
//				WFObjectList.SQLOP_EQUALTO, "'ibpm_server1'");
		wfObjectList.openBatchedList(Filter.MyActiveWorkItems);
		int initialCount = wfObjectList.estimateCount();
		 System.out.println("initial count :"+initialCount);

		// Adding a new plan
		Plan p = importXPDL(xpdlFileName);

		ProcessInstantiator pp = WFObjectFactory.getProcessInstantiator(p
				.getId(), wfSession);
		pp.setName(p.getName() + "6");
		ProcessInstance pp1 = pp.startNewProcess();

		int countAfterCreatingWorkItem = wfObjectList.estimateCount();
		 System.out.println("Creating workitem :"+countAfterCreatingWorkItem);

		Object obj[] = null;
		while ((obj = wfObjectList.getNextBatch(20)) != null) {
			for (int i = 0; i < obj.length; i++) {
				WorkItem wObject = (WorkItem) obj[i];
				if (wObject.getProcessInstanceId() == pp1.getId()) {
					wObject.makeChoice("finish");
				}
			}
		}

		int countAfterWorkItemDeletion = wfObjectList.estimateCount();
		 System.out.println("Deletion count :"+countAfterWorkItemDeletion);
		if (countAfterCreatingWorkItem > initialCount) {
			if (countAfterWorkItemDeletion < countAfterCreatingWorkItem) {
				tr.markPassed("ELC52_compareWorkItemCount()");
				tr.log("Passed ELC52_compareWorkItemCount()");
			} else {
				tr.markFailed("ELC52_compareWorkItemCount()", "");
				tr.log("Failed ELC52_compareWorkItemCount()");
			}
		} else {
			tr.markFailed("ELC52_compareWorkItemCount()", "");
			tr.log("Failed ELC52_compareWorkItemCount()");
		}
	}

	public void ELC53_compareProcessInstanceCount(TestRecorder tr)
			throws Exception {
		WFObjectList wfObjectList = WFObjectFactory.getWFObjectList(wfSession);
		wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_ID,
				WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");
		wfObjectList.openBatchedList(Filter.AllProcesses);
		int initialCount = wfObjectList.estimateCount();
		// System.out.println(initialCount);

		// Adding a new plan
		Plan p = importXPDL(xpdlFileName);

		ProcessInstantiator pinst1 = WFObjectFactory.getProcessInstantiator(p
				.getId(), wfSession);
		pinst1.setName(p.getName() + "1");
		ProcessInstance p1 = pinst1.startNewProcess();

		ProcessInstantiator pinst2 = WFObjectFactory.getProcessInstantiator(p
				.getId(), wfSession);
		pinst2.setName(p.getName() + "2");
		ProcessInstance p2 = pinst2.startNewProcess();

		ProcessInstantiator pinst3 = WFObjectFactory.getProcessInstantiator(p
				.getId(), wfSession);
		pinst3.setName(p.getName() + "3");
		ProcessInstance p3 = pinst3.startNewProcess();

		ProcessInstantiator pinst4 = WFObjectFactory.getProcessInstantiator(p
				.getId(), wfSession);
		pinst4.setName(p.getName() + "4");
		ProcessInstance p4 = pinst4.startNewProcess();

		ProcessInstantiator pinst5 = WFObjectFactory.getProcessInstantiator(p
				.getId(), wfSession);
		pinst5.setName(p.getName() + "5");
		ProcessInstance p5 = pinst5.startNewProcess();

		int countAfterInstantiation = wfObjectList.estimateCount();
		System.out.println(countAfterInstantiation);

		wfSession.deleteProcessInstance(p1.getId());
		wfSession.deleteProcessInstance(p2.getId());
		wfSession.deleteProcessInstance(p3.getId());
		wfSession.deleteProcessInstance(p4.getId());
		wfSession.deleteProcessInstance(p5.getId());

		// Removing Process Instances from Database
		int countAfterDeletion = wfObjectList.estimateCount();

		System.out.println(countAfterDeletion);

		if (countAfterInstantiation > initialCount) {
			if (countAfterDeletion < countAfterInstantiation) {
				tr.markPassed("ELC53_compareProcessInstanceCount()");
				tr.log("Passed ELC53_compareProcessInstanceCount()");
			} else {
				tr.markFailed("ELC53_compareProcessInstanceCount()", "");
                tr.log("Failed ELC53_compareProcessInstanceCount()");
            }
		} else {
			tr.markFailed("ELC53_compareProcessInstanceCount()", "");
			tr.log("Passed ELC53_compareProcessInstanceCount()");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);

			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_OWNER,
					WFObjectList.SQLOP_EQUALTO, "'ibpm_server1'");
			wfObjectList.openBatchedList(Filter.AllInactiveProcesses);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;

			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

			if (countFromIteration == estimatedCount) {
				markPassed("ELC54_getAllInActiveProcess()");
				tr.log("Passed ELC54_getAllInActiveProcess()");
			} else {
				markFailed("ELC54_getAllInActiveProcess()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC54_getAllInActiveProcess()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC54_getAllInActiveProcess Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_OWNER,
					WFObjectList.SQLOP_EQUALTO, "'ibpm_server1'");
			wfObjectList.openBatchedList(Filter.AllProcessesInErrorState);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;

			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

			if (countFromIteration == estimatedCount) {
				markPassed("ELC55_getAllProcessesInErrorState()");
				tr.log("Passed ELC55_getAllProcessesInErrorState()");
			} else {
				markFailed("ELC55_getAllProcessesInErrorState()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC55_getAllProcessesInErrorState()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC55_getAllProcessesInErrorState Testing Failed");
		}
	} // end of the method ELC01_getUserPlans

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			wfObjectList.addFilter(
					WFObjectList.LISTFIELD_PROCESSINSTANCE_OWNER,
					WFObjectList.SQLOP_EQUALTO, "'ibpm_server1'");

			wfObjectList.openBatchedList(Filter.MyInactiveProcesses);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;

			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

			if (countFromIteration == estimatedCount) {
				markPassed("ELC56_getMyInActiveProcess()");
				tr.log("Passed ELC56_getMyInActiveProcess()");
			} else {
				markFailed("ELC56_getMyInActiveProcess()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC56_getMyInActiveProcess()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC56_getMyInActiveProcess Testing Failed");

		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE,
					WFObjectList.SQLOP_EQUALTO, "'" + username + "'");

			wfObjectList.openBatchedList(Filter.AllInactiveWorkItems);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;

			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

			if (countFromIteration == estimatedCount) {
				markPassed("ELC57_getAllInActiveWorkItems()");
				tr.log("Passed ELC57_getAllInActiveWorkItems()");
			} else {
				markFailed("ELC57_getAllInActiveWorkItems()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC57_getAllInActiveWorkItems()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC57_getAllInActiveWorkItems Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE,
					WFObjectList.SQLOP_EQUALTO, "'" + username + "'");

			wfObjectList.openBatchedList(Filter.MyAcceptedWorkItems);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;

			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

			if (countFromIteration == estimatedCount) {
				markPassed("ELC58_getMyAcceptedWorkItems()");
				tr.log("Passed ELC58_getMyAcceptedWorkItems()");
			} else {
				markFailed("ELC58_getMyAcceptedWorkItems()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC58_getMyAcceptedWorkItems()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC58_getMyAcceptedWorkItems Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE,
					WFObjectList.SQLOP_EQUALTO, "'" + username + "'");

			wfObjectList.openBatchedList(Filter.MyDeclinedWorkItems);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;

			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

			if (countFromIteration == estimatedCount) {
				markPassed("ELC59_getMyDeclinedWorkItems()");
				tr.log("Passed ELC59_getMyDeclinedWorkItems()");
			} else {
				markFailed("ELC59_getMyDeclinedWorkItems()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC59_getMyDeclinedWorkItems()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC59_getMyDeclinedWorkItems Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_ID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");

			wfObjectList.openBatchedList(Filter.AllArchivedPlans);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;

			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

			if (countFromIteration == estimatedCount) {
				markPassed("ELC60_getAllArchievedPlan()");
				tr.log("Passed ELC60_getAllArchievedPlan()");
			} else {
				markFailed("ELC60_getAllArchievedPlan()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC60_getAllArchievedPlan()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC60_getAllArchievedPlan Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			wfObjectList.addFilter(WFObjectList.LISTFIELD_PLAN_ID,
					WFObjectList.SQLOP_GREATERTHANOREQUALTO, "'0'");

			wfObjectList.openBatchedList(Filter.AllArchivedProcesses);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;

			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

			if (countFromIteration == estimatedCount) {
				markPassed("ELC61_getAllArchievedProcesses()");
				tr.log("Passed ELC61_getAllArchievedProcesses()");
			} else {
				markFailed("ELC61_getAllArchievedProcesses()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC61_getAllArchievedProcesses()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC61_getAllArchievedProcesses Testing Failed");
		}
	}

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

			WFObjectList wfObjectList = WFObjectFactory
					.getWFObjectList(wfSession);
			wfObjectList.addFilter(WFObjectList.LISTFIELD_WORKITEM_ASSIGNEE,
					WFObjectList.SQLOP_EQUALTO, "'"+username+"'");

			wfObjectList.openBatchedList(Filter.AllInactiveWorkItems);

			int estimatedCount = wfObjectList.estimateCount();

			Object[] wiList = null;
			int countFromIteration = 0;

			while ((wiList = wfObjectList.getNextBatch(10)) != null) {
				countFromIteration = countFromIteration + wiList.length;
			}

			if (countFromIteration == estimatedCount) {
				markPassed("ELC62_getAllInactiveWorkItem()");
				tr.log("Passed ELC62_getAllInactiveWorkItem()");
			} else {
				markFailed("ELC62_getAllInactiveWorkItem()",
						"estimatedCount and ListCount do not match");
				tr.log("Failed ELC62_getAllInactiveWorkItem()");
			}
			wfObjectList.closeList();
		} catch (Exception e) {
			e.printStackTrace();
			tr.log("ELC62_getAllInactiveWorkItem Testing Failed");
		}
	}

	public void loadFiles(TestRecorder tr) throws Exception {
		// importing XPDL from AITS directory
		Plan p = importXPDL(xpdlFileName);

		// creating five process instances

		ProcessInstantiator pinst1 = WFObjectFactory.getProcessInstantiator(p
				.getId(), wfSession);
		pinst1.setName(p.getName() + "1");
		pinst1.startNewProcess();

		ProcessInstantiator pinst2 = WFObjectFactory.getProcessInstantiator(p
				.getId(), wfSession);
		pinst2.setName(p.getName() + "2");
		pinst2.startNewProcess();

		ProcessInstantiator pinst3 = WFObjectFactory.getProcessInstantiator(p
				.getId(), wfSession);
		pinst3.setName(p.getName() + "3");
		pinst3.startNewProcess();

		ProcessInstantiator pinst4 = WFObjectFactory.getProcessInstantiator(p
				.getId(), wfSession);
		pinst4.setName(p.getName() + "4");
		pinst4.startNewProcess();

		ProcessInstantiator pinst5 = WFObjectFactory.getProcessInstantiator(p
				.getId(), wfSession);
		pinst5.setName(p.getName() + "5");
		pinst5.startNewProcess();
	}

	public static void main(String args[]) {
		String s[] = { "com.fujitsu.iflowqa.testframe.TestEstimateCount" };
		TestDriver.main(s);
	}
}

