// Path: modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/es/integration/common/utils/subscription/WorkItemClient.java
// public class WorkItemClient {
//     private static Log log = LogFactory.getLog(WorkItemClient.class);
// 
//     private WorkItemClient() {
//     }
// 
//     /**
//      * get the existing management console notifications
//      *
//      * @param humanTaskAdminClient
//      * @return
//      * @throws java.rmi.RemoteException
//      * @throws IllegalStateFault
//      * @throws IllegalAccessFault
//      * @throws IllegalArgumentFault
//      * @throws InterruptedException
//      */
//     public static WorkItem[] getWorkItems(HumanTaskAdminClient humanTaskAdminClient)
//             throws RemoteException, IllegalStateFault, IllegalAccessFault, IllegalArgumentFault,
//                    InterruptedException {
//         long startTime = new Date().getTime();
//         long endTime = startTime + 2 * 60 * 1000;
//         WorkItem[] workItems = null;
//         // try for a minute to get all the notifications
//         while ((new Date().getTime()) < endTime) {
//             workItems = humanTaskAdminClient.getWorkItems();
//             if (workItems.length > 0) {
//                 break;
//             }
//             Thread.sleep(5000);
//         }
//         return workItems;
//     }
// 
//     public static WorkItem[] waitForWorkItems(HumanTaskAdminClient humanTaskAdminClient)
//             throws RemoteException, InterruptedException,
//                    SearchAdminServiceRegistryExceptionException {
//         Calendar startTime = Calendar.getInstance();
//         WorkItem[] workItems = null;
//         while (((Calendar.getInstance().getTimeInMillis() - startTime.getTimeInMillis())) < 30000) {
//             log.info("waiting for work items ..... ");
//             try {
//                 workItems = WorkItemClient.getWorkItems(humanTaskAdminClient);
//             } catch (Exception e) {
//                 log.error("Error while getting work items... ", e);
//                 return workItems;
//             }
//             if (workItems != null) {
//                 return workItems;
//             }
//             Thread.sleep(5000);
//         }
//         return workItems;
//     }
// 
// }


import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil;
import org.wso2.carbon.automation.test.utils.common.FileManager;
import org.wso2.carbon.governance.custom.lifecycles.checklist.stub.CustomLifecyclesChecklistAdminServiceExceptionException;
import org.wso2.carbon.governance.custom.lifecycles.checklist.stub.beans.xsd.LifecycleBean;
import org.wso2.carbon.governance.custom.lifecycles.checklist.stub.util.xsd.Property;
import org.wso2.carbon.humantask.stub.ui.task.client.api.IllegalAccessFault;
import org.wso2.carbon.humantask.stub.ui.task.client.api.IllegalArgumentFault;
import org.wso2.carbon.humantask.stub.ui.task.client.api.IllegalStateFault;
import org.wso2.carbon.integration.common.admin.client.UserManagementClient;
import org.wso2.carbon.integration.common.utils.LoginLogoutClient;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.info.stub.beans.xsd.SubscriptionBean;
import org.wso2.carbon.registry.properties.stub.PropertiesAdminServiceRegistryExceptionException;
import org.wso2.carbon.registry.resource.stub.ResourceAdminServiceExceptionException;
import org.wso2.carbon.registry.ws.client.registry.WSRegistryServiceClient;
import org.wso2.es.integration.common.clients.*;
import org.wso2.es.integration.common.utils.RegistryProviderUtil;
import org.wso2.es.integration.common.utils.subscription.WorkItemClient;
import javax.activation.DataHandler;
import java.io.File;
import java.net.URL;
import java.rmi.RemoteException;
     */
    private boolean consoleSubscribe(String path, String eventType) throws RemoteException,
                                                                           RegistryException {

        // subscribe for management console notifications
        SubscriptionBean bean =
                infoServiceAdminClient.subscribe(path, "work://RoleSubscriptionTest", eventType,
                                                 sessionCookie);
        return bean.getSubscriptionInstances() != null;

    }

    /**
     * get management console subscriptions
     *
     * @param type type of the element
     * @return true if the required notification is generated, false otherwise
     * @throws java.rmi.RemoteException
     * @throws IllegalStateFault
     * @throws IllegalAccessFault
     * @throws IllegalArgumentFault
     * @throws InterruptedException
     */
    private boolean getNotification(String type) throws RemoteException, IllegalStateFault,
                                                        IllegalAccessFault,
                                                        IllegalArgumentFault,
                                                        InterruptedException {
        boolean success = false;
        Thread.sleep(3000);//force delay otherwise getWorkItems return null
        // get all the management console notifications
// Path: modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/es/integration/common/utils/subscription/WorkItemClient.java
// public class WorkItemClient {
//     private static Log log = LogFactory.getLog(WorkItemClient.class);
// 
//     private WorkItemClient() {
//     }
// 
//     /**
//      * get the existing management console notifications
//      *
//      * @param humanTaskAdminClient
//      * @return
//      * @throws java.rmi.RemoteException
//      * @throws IllegalStateFault
//      * @throws IllegalAccessFault
//      * @throws IllegalArgumentFault
//      * @throws InterruptedException
//      */
//     public static WorkItem[] getWorkItems(HumanTaskAdminClient humanTaskAdminClient)
//             throws RemoteException, IllegalStateFault, IllegalAccessFault, IllegalArgumentFault,
//                    InterruptedException {
//         long startTime = new Date().getTime();
//         long endTime = startTime + 2 * 60 * 1000;
//         WorkItem[] workItems = null;
//         // try for a minute to get all the notifications
//         while ((new Date().getTime()) < endTime) {
//             workItems = humanTaskAdminClient.getWorkItems();
//             if (workItems.length > 0) {
//                 break;
//             }
//             Thread.sleep(5000);
//         }
//         return workItems;
//     }
// 
//     public static WorkItem[] waitForWorkItems(HumanTaskAdminClient humanTaskAdminClient)
//             throws RemoteException, InterruptedException,
//                    SearchAdminServiceRegistryExceptionException {
//         Calendar startTime = Calendar.getInstance();
//         WorkItem[] workItems = null;
//         while (((Calendar.getInstance().getTimeInMillis() - startTime.getTimeInMillis())) < 30000) {
//             log.info("waiting for work items ..... ");
//             try {
//                 workItems = WorkItemClient.getWorkItems(humanTaskAdminClient);
//             } catch (Exception e) {
//                 log.error("Error while getting work items... ", e);
//                 return workItems;
//             }
//             if (workItems != null) {
//                 return workItems;
//             }
//             Thread.sleep(5000);
//         }
//         return workItems;
//     }
// 
// }


// Path: modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/es/integration/common/utils/lifecycle/LifecycleUtil.java
import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil;
import org.wso2.carbon.automation.test.utils.common.FileManager;
import org.wso2.carbon.governance.custom.lifecycles.checklist.stub.CustomLifecyclesChecklistAdminServiceExceptionException;
import org.wso2.carbon.governance.custom.lifecycles.checklist.stub.beans.xsd.LifecycleBean;
import org.wso2.carbon.governance.custom.lifecycles.checklist.stub.util.xsd.Property;
import org.wso2.carbon.humantask.stub.ui.task.client.api.IllegalAccessFault;
import org.wso2.carbon.humantask.stub.ui.task.client.api.IllegalArgumentFault;
import org.wso2.carbon.humantask.stub.ui.task.client.api.IllegalStateFault;
import org.wso2.carbon.integration.common.admin.client.UserManagementClient;
import org.wso2.carbon.integration.common.utils.LoginLogoutClient;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.info.stub.beans.xsd.SubscriptionBean;
import org.wso2.carbon.registry.properties.stub.PropertiesAdminServiceRegistryExceptionException;
import org.wso2.carbon.registry.resource.stub.ResourceAdminServiceExceptionException;
import org.wso2.carbon.registry.ws.client.registry.WSRegistryServiceClient;
import org.wso2.es.integration.common.clients.*;
import org.wso2.es.integration.common.utils.RegistryProviderUtil;
import org.wso2.es.integration.common.utils.subscription.WorkItemClient;
import javax.activation.DataHandler;
import java.io.File;
import java.net.URL;
import java.rmi.RemoteException;

     */
    private boolean consoleSubscribe(String path, String eventType) throws RemoteException,
                                                                           RegistryException {

        // subscribe for management console notifications
        SubscriptionBean bean =
                infoServiceAdminClient.subscribe(path, "work://RoleSubscriptionTest", eventType,
                                                 sessionCookie);
        return bean.getSubscriptionInstances() != null;

    }

    /**
     * get management console subscriptions
     *
     * @param type type of the element
     * @return true if the required notification is generated, false otherwise
     * @throws java.rmi.RemoteException
     * @throws IllegalStateFault
     * @throws IllegalAccessFault
     * @throws IllegalArgumentFault
     * @throws InterruptedException
     */
    private boolean getNotification(String type) throws RemoteException, IllegalStateFault,
                                                        IllegalAccessFault,
                                                        IllegalArgumentFault,
                                                        InterruptedException {
        boolean success = false;
        Thread.sleep(3000);//force delay otherwise getWorkItems return null
        // get all the management console notifications
        WorkItem[] workItems = WorkItemClient.getWorkItems(humanTaskAdminClient);