/**
   * @throws Exception Expected exception because user is not allowed to promote LC without
   *     permission(ex: using WS)
   */
  @Test(
      groups = "wso2.greg",
      description = "Promote from Commencement to Creation without permission",
      dependsOnMethods = "testDemoteFromCreationAgain",
      expectedExceptions = org.apache.axis2.AxisFault.class)
  public void testPromoteToCreationAgain() throws Exception, GovernanceException {
    lifeCycle = lifeCycleAdminServiceClient.getLifecycleBean(absPath);
    boolean isPermitted = false;
    for (String action : lifeCycle.getAvailableActions()[0].getActions()) {
      if (action.equalsIgnoreCase(ACTION_PROMOTE)) {
        isPermitted = true;
      }
    }
    assertFalse(isPermitted, "Allowed to promote without permission");

    lifeCycleAdminServiceClient.invokeAspect(
        absPath,
        LC_NAME,
        ACTION_ITEM_CLICK,
        new String[] {"false", "false", "false", "false", "false", "false"});

    lifeCycleAdminServiceClient.invokeAspect(absPath, LC_NAME, ACTION_PROMOTE, null);

    lifeCycle = lifeCycleAdminServiceClient.getLifecycleBean(absPath);

    for (Property prop : lifeCycle.getLifecycleProperties()) {
      if (("registry.lifecycle." + LC_NAME + ".state").equalsIgnoreCase(prop.getKey())) {
        assertNotNull(prop.getValues(), "State Value Not Found");
        assertTrue(prop.getValues()[0].equalsIgnoreCase(LC_STATE0), "Promoted without permission");
      }
    }
  }
  /** @throws Exception */
  @Test(
      groups = "wso2.greg",
      description = "Demote  from Creation with permission",
      dependsOnMethods = "testSetNewUser")
  public void testDemoteFromCreationAgain() throws Exception {
    addRole("archrole", user2Info.getUserNameWithoutDomain());
    lifeCycle = lifeCycleAdminServiceClient.getLifecycleBean(absPath);
    boolean isPermitted = false;
    for (String action : lifeCycle.getAvailableActions()[0].getActions()) {
      if (action.equalsIgnoreCase(ACTION_DEMOTE)) {
        isPermitted = true;
      }
    }
    assertTrue(isPermitted, "Not allowed to demote with permission");

    lifeCycleAdminServiceClient.invokeAspect(absPath, LC_NAME, ACTION_DEMOTE, null);
    lifeCycle = lifeCycleAdminServiceClient.getLifecycleBean(absPath);

    for (Property prop : lifeCycle.getLifecycleProperties()) {
      if (("registry.lifecycle." + LC_NAME + ".state").equalsIgnoreCase(prop.getKey())) {
        assertNotNull(prop.getValues(), "State Value Not Found");
        assertTrue(
            prop.getValues()[0].equalsIgnoreCase(LC_STATE0),
            "Not promoted to Creation with permission");
      }
    }
  }
  /** @throws Exception */
  @Test(
      groups = "wso2.greg",
      description = "Promote from Commencement to Creation",
      dependsOnMethods = "testAddLcToService")
  public void testPromoteToCreation() throws Exception {

    addRole("managerrole", userInfo.getUserNameWithoutDomain());
    lifeCycle = lifeCycleAdminServiceClient.getLifecycleBean(absPath);
    boolean isPermitted = false;
    for (String action : lifeCycle.getAvailableActions()[0].getActions()) {
      if (action.equalsIgnoreCase(ACTION_PROMOTE)) {
        isPermitted = true;
      }
    }
    assertTrue(isPermitted, "Not allowed to promote with permission");

    lifeCycleAdminServiceClient.invokeAspect(absPath, LC_NAME, ACTION_PROMOTE, null);

    Service[] services = serviceManager.getAllServices();

    for (Service service : services) {
      String path = service.getPath();
      if (path.contains("IntergalacticService13")) {
        serviceString = path;
      }
    }
    lifeCycle = lifeCycleAdminServiceClient.getLifecycleBean(absPath);

    for (Property prop : lifeCycle.getLifecycleProperties()) {
      if (("registry.lifecycle." + LC_NAME + ".state").equalsIgnoreCase(prop.getKey())) {
        assertNotNull(prop.getValues(), "State Value Not Found");
        assertTrue(
            prop.getValues()[0].equalsIgnoreCase(LC_STATE1),
            "Not promoted to Creation with permission");
      }
    }
  }
  /**
   * @throws RegistryException
   * @throws RemoteException
   * @throws CustomLifecyclesChecklistAdminServiceExceptionException
   * @throws ListMetadataServiceRegistryExceptionException
   * @throws ResourceAdminServiceExceptionException
   */
  @Test(
      groups = "wso2.greg",
      description = "Add lifecycle to a service",
      dependsOnMethods = "testCreateNewLifeCycle")
  public void testAddLcToService()
      throws RegistryException, RemoteException,
          CustomLifecyclesChecklistAdminServiceExceptionException,
          ListMetadataServiceRegistryExceptionException, ResourceAdminServiceExceptionException {

    wsRegistryServiceClient.associateAspect(absPath, LC_NAME);
    lifeCycle = lifeCycleAdminServiceClient.getLifecycleBean(absPath);

    Property[] properties = lifeCycle.getLifecycleProperties();

    boolean lcStatus = false;
    for (Property prop : properties) {
      if (prop.getKey().contains(LC_NAME)) {
        lcStatus = true;
      }
    }
    assertTrue(lcStatus, "LifeCycle not added to service");
  }