/**
   * Test Case Name: Adding/Modeling - Authentication - Wrong username/password
   *
   * <p>Summary: This is a negative test This test case verifies whether the user is given proper
   * message when user tries to add a Windows Device that has incorrect username and/or password
   *
   * <p>Pre-requisites: Python Collector ZenPack is installed Microsoft Windows ZenPack is installed
   * Target Device is configured with WinRM
   *
   * <p>Post-requisites: The added devices must be deleted
   *
   * <p>Author Alexander Sanchez
   *
   * @param testCaseId The id of the test case
   * @param username User name of the application to test
   * @param password User password of the application to test
   * @param deviceName Name of the win 2008 device to add
   * @param deviceClass the device class of the windows device
   * @param windowsUserCorrect the correct windows user credential needed to model the device
   * @param windowsUserIncorrect the incorrect windows user credential needed to model the device
   * @param windowsPasswordCorrect the correct windows password credential needed to model the
   *     device
   * @param windowsPasswordIncorrect the incorrect windows us credential needed to model the device
   * @param zenPackName the name of the zenpack that is being evaulated
   * @param expectedComponents The list of components that need to be checked
   * @throws Exception Exception
   */
  @Test(groups = {"tc_32430"})
  @Parameters({
    "tc_32430_testcaseid",
    "tc_32430_username",
    "tc_32430_password",
    "tc_ps_win_devicename",
    "tc_ps_win_deviceclass",
    "tc_32430_windowsusercorrect",
    "tc_32430_windowsuserincorrect",
    "tc_32430_windowspasswordcorrect",
    "tc_32430_windowspasswordincorrect",
    "zenpack_microsoftwindowsname",
    "tc_win2008_expected_components"
  })
  public void verifyWrongUsernamesAndPasswordsBlockModeling(
      String testCaseId,
      String username,
      String password,
      String deviceName,
      String deviceClass,
      String windowsUserCorrect,
      String windowsUserIncorrect,
      String windowsPasswordCorrect,
      String windowsPasswordIncorrect,
      String zenPackName,
      String expectedComponents) {

    Autoinstall autoinstall = new Autoinstall();
    CommonPage commonPage = new CommonPage();

    String host = getHostName();
    String endPoint = getEndPoint();
    String targetNameSpace = getTargetNameSpace();

    TestlinkCommands.setTestCaseID(testCaseId);

    // ***Pre-Test
    setTestCaseSection(TEST_CASE_SECTION_PRETEST);
    ZenPacksCommon.validateZenpackInstalledCompleteWorkFlow(username, password, zenPackName);
    Utilities.waitTime(ConstantsClass.TIMEOUT_2_SECONDS);

    DevicesPage devicesPage =
        (DevicesPage) commonPage.navigateTo(ConstantsClass.INFRASTRUCTURE_PAGE);
    Assert.assertTrue(devicesPage.checkPage(), "Infrastructure page is not displayed");
    // Utilities.waitTime(TIMEOUT_5_SECONDS);

    if (DevicesCommon.selectDeviceInList(devicesPage, deviceName, ConstantsClass.DEVICE_FILTER))
      Assert.assertTrue(
          autoinstall.deleteDevice(endPoint, targetNameSpace, host, deviceName),
          String.format("[WebService] Device %s can't be deleted", deviceName));

    // ***Test
    setTestCaseSection(TEST_CASE_SECTION_TEST);
    DevicesCommon.addSingleDevice(
        devicesPage, deviceName, deviceClass, "", "", "", "", false, "", "");

    DevicesCommon.selectDeviceInList(devicesPage, deviceName, ConstantsClass.DEVICE_FILTER);
    DeviceDetailPage deviceDetailPage = devicesPage.clickDeviceLink(deviceName);

    // The device hasn't been modeled yet
    String[] components = expectedComponents.split(",");
    Assert.assertFalse(
        deviceDetailPage.areExpectedComponentsDisplayed(components),
        "After manually changing the creds, the components were not modeled correctly");

    Map configPropertyMap = new HashMap();
    configPropertyMap.put(ConstantsClass.FILTER_CONFIGURATION_PAGE_WINRM_USER, windowsUserCorrect);
    configPropertyMap.put(
        ConstantsClass.FILTER_CONFIGURATION_PAGE_WINRM_PASSWORD, windowsPasswordIncorrect);
    ConfigurationPropertiesCommon.editConfigurationPropertyDeviceWinFailure(
        deviceDetailPage, configPropertyMap);

    // Should not show components
    Assert.assertFalse(
        deviceDetailPage.areExpectedComponentsDisplayed(components),
        "After manually changing the creds, the components were not modeled correctly");

    configPropertyMap.clear();
    configPropertyMap.put(
        ConstantsClass.FILTER_CONFIGURATION_PAGE_WINRM_USER, windowsUserIncorrect);
    configPropertyMap.put(
        ConstantsClass.FILTER_CONFIGURATION_PAGE_WINRM_PASSWORD, windowsPasswordCorrect);
    ConfigurationPropertiesCommon.editConfigurationPropertyDeviceWinFailure(
        deviceDetailPage, configPropertyMap);

    // Should not show components
    Assert.assertFalse(
        deviceDetailPage.areExpectedComponentsDisplayed(components),
        "After manually changing the creds, the components were not modeled correctly");

    // Post Test
    setTestCaseSection(TEST_CASE_SECTION_POSTTEST);
    Assert.assertTrue(
        autoinstall.deleteDevice(endPoint, targetNameSpace, host, deviceName),
        String.format("[WebService] Device %s can't be deleted", deviceName));
  }
  /**
   * Test Case Name: Verify multiple Windows Servers can be added and modeled correctly
   *
   * <p>Summary: This test case verifies the ability to add and model multiple Server Window targets
   * simultaneously to discover the windows device components.
   *
   * <p>Pre-requisites: Zenoss instance is running Python Collector ZenPack is installed Microsoft
   * Windows ZenPack is installed
   *
   * <p>Post-requisites: The added devices must be deleted
   *
   * <p>Author Alexander Sanchez
   *
   * @param testCaseId The id of the test case
   * @param username User name of the application to test
   * @param password User password of the application to test
   * @param deviceName Name of the win 2008 device to add
   * @param windowsUser the windows user credential needed to model the windows 2003 device
   * @param windowsPassword the windows password credential needed to model the device
   * @param zenPackName the zenpack name
   * @param expectedComponents The list of components that need to be checked
   * @throws Exception Exception
   */
  @Test(groups = {"tc_32428"})
  @Parameters({
    "tc_32428_testcaseid",
    "tc_32428_username",
    "tc_32428_password",
    "tc_ps_win_devicename",
    "tc_32428_windowsuser",
    "tc_32428_windowspassword",
    "zenpack_microsoftwindowsname",
    "tc_win2008_expected_components"
  })
  public void verifyAddMultipleDevicesFunctionalityForWindowsZenpack(
      String testCaseId,
      String username,
      String password,
      String deviceName,
      String windowsUser,
      String windowsPassword,
      String zenPackName,
      String expectedComponents) {
    // ***Pre-Test
    setTestCaseSection(TEST_CASE_SECTION_PRETEST);
    TestlinkCommands.addStepDescription(TEST_CASE_SECTION_PRETEST_LABEL);
    TestlinkCommands.setTestCaseID(testCaseId);
    CommonPage commonPage = new CommonPage();
    String endPoint = getEndPoint();
    String targetNameSpace = getTargetNameSpace();
    String host = getHostName();
    Autoinstall autoinstall = new Autoinstall();

    ZenPacksCommon.validateZenpackInstalledCompleteWorkFlow(username, password, zenPackName);
    Utilities.waitTime(ConstantsClass.TIMEOUT_2_SECONDS);

    DevicesPage devicesPage =
        (DevicesPage) commonPage.navigateTo(ConstantsClass.INFRASTRUCTURE_PAGE);
    Assert.assertTrue(devicesPage.checkPage(), "Infrastructure page is not displayed");

    if (DevicesCommon.selectDeviceInList(devicesPage, deviceName, ConstantsClass.DEVICE_FILTER))
      Assert.assertTrue(
          autoinstall.deleteDevice(endPoint, targetNameSpace, host, deviceName),
          String.format("Device can't be deleted"));

    // ***Test
    setTestCaseSection(TEST_CASE_SECTION_TEST);
    Assert.assertTrue(
        devicesPage.clickOnAddDeviceButton(),
        "The list with options to add device is not displayed");
    devicesPage.clickOnAddDeviceOption(ConstantsClass.ADD_MULTIPLE_DEVICES_OPTION_NAME);

    // These parameters are quite cumbersome, but are needed for the following method. Said method
    // will need to be optimized in the future
    String parameters =
        ConstantsClass.ADD_INFRASTRUCTURE_CATEGORY_SERVER
            + ","
            + ConstantsClass.ADD_INFRASTRUCTURE_TYPE_WIN_SERVER_RM
            + ","
            + deviceName
            + ","
            + windowsUser
            + ","
            + windowsPassword;
    DevicesCommon.addMultipleDevices(new AddMultipleDevicesPage(), parameters);
    devicesPage = (DevicesPage) commonPage.navigateTo(ConstantsClass.INFRASTRUCTURE_PAGE);
    Assert.assertTrue(devicesPage.checkPage(), "Infrastructure page is not displayed");
    Utilities.waitTime(TIMEOUT_5_SECONDS);
    OverviewPage overviewPage = devicesPage.clickDeviceLink(deviceName);
    String[] components = expectedComponents.split(",");
    Assert.assertTrue(
        overviewPage.areExpectedComponentsDisplayed(components),
        "After manually changing the creds, the components were not modeled correctly");

    // Post Test
    setTestCaseSection(TEST_CASE_SECTION_POSTTEST);
    // Delete the device
    Assert.assertTrue(
        autoinstall.deleteDevice(endPoint, targetNameSpace, host, deviceName),
        String.format("Device [%s] can't be deleted", deviceName));
  }
  /**
   * Test Case Name: Verify VIC vHBAs components
   *
   * <p>Summary: This test case verifies details of VIC vHBAs component of CiscoUCS/C- Series
   * device.
   *
   * <p>Pre-requisites: Add a new ucs device
   *
   * <p>Post-requisites: Remove the UCS device
   *
   * <p>Author Oscar Valerio
   *
   * @param testCaseId The TC id
   * @param adminUserName The admin user
   * @param adminUserPassword The admin password
   * @param deviceName The UCS device name to use
   * @param ucsType The ucs type
   * @param ucsUserName The ucs user name
   * @param ucsPass The ucs user pass
   * @param ucsCollectorName The ucs collector to assign
   * @throws Exception
   */
  @Test(
      groups = {"tc_1259"},
      priority = 0)
  @Parameters({
    "tc_1259_testcaseid", "tc_1259_username", "tc_1259_password", "tc_1259_device",
    "tc_1259_ucstype", "tc_1259_ucsusername", "tc_1259_ucsuserpass", "tc_1259_ucscollector",
    "tc_1259_ucscomponenttoverify", "tc_1259_ucsexpectdheaders", "tc_1259_ucsexpectddisplayoptions"
  })
  public void verifyVirtualHBAComponents(
      String testCaseId,
      String adminUserName,
      String adminUserPassword,
      String deviceName,
      String ucsType,
      String ucsUserName,
      String ucsPass,
      String ucsCollectorName,
      String ucsComponentToVerify,
      String ucsExpectedHeaders,
      String ucsexpectedDisplayOptions)
      throws Exception {

    CommonPage commonPage = new CommonPage();
    Autoinstall autoinstall = new Autoinstall();
    String[] expectedHeaders = ucsExpectedHeaders.split(ConstantsClass.CHAR_SEPARATOR_ARRAY);
    String[] expectedDisplayOptions =
        ucsexpectedDisplayOptions.split(ConstantsClass.CHAR_SEPARATOR_ARRAY);

    // ** Pre-test
    TestlinkCommands.setTestCaseID(testCaseId);
    setTestCaseSection(TEST_CASE_SECTION_PRETEST);
    LoginCommon.login(adminUserName, adminUserPassword);

    // Remove UCS device if exists
    Assert.assertTrue(
        autoinstall.deleteDevice(getEndPoint(), getTargetNameSpace(), getHostName(), deviceName),
        String.format("[WebService] Error. Device %s was NOT deleted", deviceName));

    // Go to infrastructure page
    DevicesPage devicesPage =
        (DevicesPage) commonPage.navigateTo(ConstantsClass.INFRASTRUCTURE_PAGE);
    Assert.assertTrue(
        devicesPage.checkPage(), "Infrastructure page was not displayed as expected.");

    // Add an UCS device
    DevicesCommon.addUCSDeviceAndWaitForJobToFinish(
        devicesPage, ucsType, deviceName, ucsUserName, ucsPass, ucsCollectorName);
    devicesPage.clickOnRefreshButton();

    // Select the ucs device
    DevicesCommon.selectDeviceInList(devicesPage, deviceName, ConstantsClass.DEVICE_FILTER);
    OverviewPage overviewPage = devicesPage.clickDeviceLink(deviceName);
    Assert.assertTrue(
        overviewPage.checkPage(deviceName), "Overview page was not displayed as expected");

    // Check values
    DeviceDetailPage deviceDetailPage = new DeviceDetailPage();
    Assert.assertEquals(
        deviceDetailPage.getDeviceStatus(),
        ConstantsClass.DEVICE_STATUS_UP,
        "The device status is not Up");

    // ** Test
    setTestCaseSection(TEST_CASE_SECTION_TEST);

    // Select component
    VirtualHBAsPage virtualHBAsPage =
        (VirtualHBAsPage) deviceDetailPage.clickOnDeviceComponents(ucsComponentToVerify);

    // Check headers
    VirtualHBAsCommons.checkComponentTableColumnValues(virtualHBAsPage, expectedHeaders);

    // Check display options
    VirtualHBAsCommons.checkComponentDisplayOPtions(virtualHBAsPage, expectedDisplayOptions);

    // Check collected data
    List<String> VirtualHBANames = virtualHBAsPage.getVirtualHBAColumnValues();
    Assert.assertTrue(VirtualHBANames.size() > 0, "The Virtual HBA table is not displaying data");

    for (String name : VirtualHBANames) {
      softAssert.assertTrue(!name.isEmpty(), "The Virtual HBA name is not defined. It is empty");
    }
    softAssert.assertAll();
    softAssert.clear();

    // *** Post Test
    setTestCaseSection(TEST_CASE_SECTION_POSTTEST);
    Assert.assertTrue(
        autoinstall.deleteDevice(getEndPoint(), getTargetNameSpace(), getHostName(), deviceName),
        String.format("[WebService] Error. Device %s was NOT deleted", deviceName));
  }