/**
   * Test Case Name: Service actions for zenoperator role (Edit a Dynamic service)
   *
   * <p>Summary: This test case is intended to verify that user with zenOperator role can view
   * services but cannot execute basicpage actions in the Services page, in this case, editing a
   * service.
   *
   * <p>Pre-requisites: Create a user "zenoperator_user" with "zenoperator" as role Login as
   * zenoperator_user Service "TestService" must be created
   *
   * <p>Post-requisites: User named "zenoperator_user" should be deleted Service "TestService" must
   * be deleted
   *
   * <p>Author: Jennifer Castro
   *
   * @param testCaseId Test case ID
   * @param username Username to login
   * @param password Password of the user to login
   * @param newUsername Username of the user to add
   * @param newUserPassword Password of the user to add
   * @param userRole Type of the user to add e.g: manager
   * @param userEmail Email of the user
   * @param testService Logical node name
   */
  @Test(groups = {"tc_21018", "impact_services_tests"})
  @Parameters({
    "tc_21018_testcaseid",
    "tc_21018_username",
    "tc_21018_password",
    "tc_21018_newusername",
    "tc_21018_newuserpassword",
    "tc_21018_userrole",
    "tc_21018_useremail",
    "tc_21018_testservice",
    "ds_root_tree_node_name"
  })
  public void editDynamicServiceAsZenoperator(
      String testCaseId,
      String username,
      String password,
      String newUsername,
      String newUserPassword,
      String userRole,
      String userEmail,
      String testService,
      String dsTreeNodeName)
      throws Exception {

    TestlinkCommands.setTestCaseID(testCaseId);

    CommonPage commonPage = new CommonPage();
    DynamicServicesCommon dynamicServicesCommon = new DynamicServicesCommon();
    testService = String.format("%s %d", testService, Utilities.getRandomNumber(1000));
    List<String> path = new ArrayList<String>();
    path.add(0, testService);

    setTestCaseSection(TEST_CASE_SECTION_PRETEST);
    TestlinkCommands.addStepDescription(TEST_CASE_SECTION_PRETEST_LABEL);
    addUserPreTestSteps(
        commonPage, username, password, newUsername, newUserPassword, userRole, userEmail);
    dynamicServicesCommon.addDynamicServicePreTestSteps(
        commonPage, username, password, testService);
    LoginCommon.login(newUsername, newUserPassword);

    setTestCaseSection(TEST_CASE_SECTION_TEST);
    TestlinkCommands.addStepDescription(TEST_CASE_SECTION_TEST_LABEL);

    TestlinkCommands.addStepDescription("- Go to Services Page");
    DynamicServicesPage dynamicServicesPage =
        (DynamicServicesPage) commonPage.navigateTo(SERVICES_PAGE);
    Assert.assertTrue(dynamicServicesPage.checkPage(), "Dynamic Service page is not displayed");

    Assert.assertTrue(
        dynamicServicesPage.isItemInDynamicServiceTreeHighlighted(dsTreeNodeName),
        String.format("Dynamic service root node: %s is not highlighted", dsTreeNodeName));
    functions.waitTime(TIMEOUT_2_SECONDS);

    TestlinkCommands.addStepDescription(
        String.format("- Click on the service called \"%s\"", testService));
    DynamicServicesCommon.reachElementInsideTree(path, dynamicServicesPage, true, true);
    functions.waitTime(TIMEOUT_2_SECONDS);

    // Validation: Service "TestService" is highlighted to show that it is selected.
    Assert.assertTrue(
        dynamicServicesPage.isItemInDynamicServiceTreeHighlighted(testService),
        String.format("Dynamic service: %s is not highlighted", testService));
    functions.waitTime(TIMEOUT_2_SECONDS);

    // Validation: Add and delete buttons are disabled on the right frame.
    Assert.assertFalse(
        dynamicServicesPage.isAddToServiceButtonEnabled(),
        "Add to service (+) button is NOT disabled");

    Assert.assertFalse(
        dynamicServicesPage.isDeleteToServiceButtonEnabled(),
        "Delete to service (-) button is NOT disabled");

    setTestCaseSection(TEST_CASE_SECTION_POSTTEST);
    TestlinkCommands.addStepDescription(TEST_CASE_SECTION_POSTTEST_LABEL);
    LoginPage loginPage = commonPage.signOut();
    Assert.assertTrue(loginPage.checkPage(), "Login page is not displayed");
    dynamicServicesCommon.deleteDynamicServicePostTestSteps(
        commonPage, username, password, testService, path);
    deleteUserPostTestSteps(commonPage, username, password, newUsername);
  }
  /**
   * Test Case Name: Actions for zenoperator role (Add a service)
   *
   * <p>Summary: This test case is intended to verify that user with zenOperator role can view
   * services but cannot execute basicpage actions in the Services page, in this case, adding a
   * service.
   *
   * <p>Pre-requisites: Create a user "zenoperator_user" with "zenoperator" as role Login as
   * zenoperator_user Service "TestService" must be created
   *
   * <p>Post-requisites: User named "zenoperator_user" should be deleted Service "TestService" must
   * be deleted
   *
   * <p>Author: Juan Polanco
   *
   * @param testCaseId testlink ID
   * @param username zenoss username
   * @param password zenoss password
   * @param userRole User role
   * @param newUser New user name
   * @param newUserPassword New user password user
   * @param managerEmail New user email
   * @param serviceName Dynamic service name
   */
  @Test(groups = {"tc_21016", "impact_services_tests"})
  @Parameters({
    "tc_21016_testcaseid",
    "tc_21016_username",
    "tc_21016_password",
    "tc_21016_userrole",
    "tc_21016_newusername",
    "tc_21016_newuserpassword",
    "tc_21016_useremail",
    "tc_21016_servicename"
  })
  public void zenOperatorRoleActionAddService(
      String testCaseId,
      String username,
      String password,
      String userRole,
      String newUser,
      String newUserPassword,
      String managerEmail,
      String serviceName) {

    TestlinkCommands.setTestCaseID(testCaseId);
    CommonPage commonPage = new CommonPage();
    LoginPage loginPage = new LoginPage();
    DynamicServicesCommon dynamicServicesCommon = new DynamicServicesCommon();
    serviceName = String.format("%s %d", serviceName, Utilities.getRandomNumber(1000));
    List<String> path = new ArrayList<String>();
    path.add(0, serviceName);

    setTestCaseSection(TEST_CASE_SECTION_PRETEST);
    TestlinkCommands.addStepDescription(TEST_CASE_SECTION_PRETEST_LABEL);
    addUserPreTestSteps(
        commonPage, username, password, newUser, newUserPassword, userRole, managerEmail);
    dynamicServicesCommon.addDynamicServicePreTestSteps(
        commonPage, username, password, serviceName);
    LoginCommon.login(newUser, newUserPassword);

    setTestCaseSection(TEST_CASE_SECTION_TEST);
    TestlinkCommands.addStepDescription(TEST_CASE_SECTION_TEST_LABEL);

    TestlinkCommands.addStepDescription("-Go to Dynamic Services ");
    DynamicServicesPage dynamicServicesPage =
        (DynamicServicesPage) commonPage.navigateTo(SERVICES_PAGE);
    Assert.assertTrue(dynamicServicesPage.checkPage(), "Dynamic Service page is not displayed");

    Assert.assertFalse(
        dynamicServicesPage.isAddDynamicServicesButtonDisplayed(),
        "Add dynamic services button is displayed");
    Assert.assertFalse(
        dynamicServicesPage.isDynamicServicesGearButtonDisplayed(), "Gears button is displayed");
    Assert.assertFalse(
        dynamicServicesPage.isRemoveDynamicServicesButtonDisplayed(),
        "Remove dynamic services button is displayed");

    setTestCaseSection(TEST_CASE_SECTION_POSTTEST);
    TestlinkCommands.addStepDescription(TEST_CASE_SECTION_POSTTEST_LABEL);
    TestlinkCommands.addStepDescription(String.format("- Logout as a [%s]", newUser));
    commonPage.signOut();
    Assert.assertTrue(loginPage.checkPage(), "Login page is not displayed");
    dynamicServicesCommon.deleteDynamicServicePostTestSteps(
        commonPage, username, password, serviceName, path);
    deleteUserPostTestSteps(commonPage, username, password, newUser);
  }