Пример #1
0
  @Test(
      description = "Verify the downloads links return 200 rather than 404",
      groups = {"functional"})
  public void DownloadsTab_02() throws HarnessException {

    // Determine which links should be present
    List<String> locators = new ArrayList<String>();

    if (ZimbraSeleniumProperties.zimbraGetVersionString().contains("NETWORK")) {

      locators.addAll(Arrays.asList(NetworkOnlyLocators));
      locators.addAll(Arrays.asList(CommonLocators));

    } else if (ZimbraSeleniumProperties.zimbraGetVersionString().contains("FOSS")) {

      locators.addAll(Arrays.asList(FossOnlyLocators));
      locators.addAll(Arrays.asList(CommonLocators));

    } else {
      throw new HarnessException(
          "Unable to find NETWORK or FOSS in version string: "
              + ZimbraSeleniumProperties.zimbraGetVersionString());
    }

    for (String locator : locators) {
      String href = app.zPageDownloads.sGetAttribute("xpath=" + locator + "@href");
      String page = ZimbraSeleniumProperties.getBaseURL() + href;

      HttpURLConnection connection = null;
      try {

        URL url = new URL(page);
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("HEAD");
        int code = connection.getResponseCode();

        // TODO: why is 400 returned for the PDF links?
        // 200 and 400 are acceptable
        ZAssert.assertStringContains(
            "200 400", "" + code, "Verify the download URL is valid: " + url.toString());

      } catch (MalformedURLException e) {
        throw new HarnessException(e);
      } catch (IOException e) {
        throw new HarnessException(e);
      } finally {
        if (connection != null) {
          connection.disconnect();
          connection = null;
        }
      }
    }
  }