gpt4 book ai didi

org.mozilla.zest.core.v1.ZestResponse类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 09:34:08 26 4
gpt4 key购买 nike

本文整理了Java中org.mozilla.zest.core.v1.ZestResponse类的一些代码示例,展示了ZestResponse类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZestResponse类的具体详情如下:
包路径:org.mozilla.zest.core.v1.ZestResponse
类名称:ZestResponse

ZestResponse介绍

[英]The Class ZestResponse.
[中]全班同学都很热情。

代码示例

代码示例来源:origin: mozilla/zest

@Override
public ZestResponse deepCopy() {
  ZestResponse zr =
      new ZestResponse(
          this.url, this.headers, this.body, this.statusCode, this.responseTimeInMs);
  return zr;
}

代码示例来源:origin: mozilla/zest

public static List<String> getForms(ZestResponse response) {
  List<String> list = new ArrayList<String>();
  Source src = new Source(response.getHeaders() + response.getBody());
  List<Element> formElements = src.getAllElements(HTMLElementName.FORM);
  int formId = 0;
  while (formElements != null && formId < formElements.size()) {
    // TODO support form names
    // Element form = formElements.get(formId);
    list.add(Integer.toString(formId));
    formId++;
  }
  return list;
}

代码示例来源:origin: mozilla/zest

@Override
public boolean isTrue(ZestRuntime runtime) {
  ZestResponse response = runtime.getLastResponse();
  if (response == null) {
    return false;
  }
  return code == response.getStatusCode();
}

代码示例来源:origin: mozilla/zest

/**
 * Sets the standard variables for a response.
 *
 * @param response the new standard variables
 */
@Override
public void setStandardVariables(ZestResponse response) {
  if (response != null) {
    if (response.getUrl() != null) {
      this.setVariable(ZestVariables.RESPONSE_URL, response.getUrl().toString());
    }
    this.setVariable(ZestVariables.RESPONSE_HEADER, response.getHeaders());
    this.setVariable(ZestVariables.RESPONSE_BODY, response.getBody());
  }
}

代码示例来源:origin: mozilla/zest

assertThat(response.getStatusCode()).isEqualTo(404);
assertThat(response.getUrl()).isEqualTo(url);
assertThat(response.getHeaders())
    .isEqualTo(
        "HTTP/1.1 404 Not Found\r\n"
            + "Server: abc\r\n"
            + "Transfer-Encoding: chunked\r\n");
assertThat(response.getBody()).isEqualTo("This is the response");

代码示例来源:origin: mozilla/zest

@Override
public String assign(ZestResponse response, ZestRuntime runtime)
    throws ZestAssignFailException {
  if (response == null) {
    throw new ZestAssignFailException(this, "Null response");
  }
  Source src = new Source(response.getBody());
  List<Element> elementsFilteredByElementName = filterByElementNameIfConfigured(src);
  List<Element> elementsFilteredByAttributeValue =
      filterByAttributeValueIfConfigured(elementsFilteredByElementName);
  List<Element> elements = reverseIfConfigured(elementsFilteredByAttributeValue);
  Element element = findElementAtIndex(elements);
  if (element == null) {
    return null;
  }
  return getReturnValue(element);
}

代码示例来源:origin: mozilla/zest

@Override
public boolean isTrue(ZestRuntime runtime) {
  ZestResponse response = runtime.getLastResponse();
  if (response == null) {
    return false;
  }
  if (greaterThan) {
    return response.getResponseTimeInMs() > this.timeInMs;
  } else {
    return response.getResponseTimeInMs() < this.timeInMs;
  }
}

代码示例来源:origin: mozilla/zest

@Override
public ZestRequest deepCopy() {
  ZestRequest zr = new ZestRequest(this.getIndex());
  zr.setUrl(this.url);
  zr.setUrlToken(this.urlToken);
  zr.setData(this.data);
  zr.setMethod(this.method);
  zr.setHeaders(this.headers);
  zr.setFollowRedirects(this.followRedirects);
  zr.setTimestamp(this.timestamp);
  if (this.getResponse() != null) {
    zr.setResponse(this.getResponse().deepCopy());
  }
  for (ZestAssertion zt : this.getAssertions()) {
    zr.addAssertion((ZestAssertion) zt.deepCopy());
  }
  for (ZestCookie cookie : this.cookies) {
    zr.addCookie(
        new ZestCookie(
            cookie.getDomain(),
            cookie.getName(),
            cookie.getValue(),
            cookie.getPath(),
            cookie.getExpiryDate(),
            cookie.isSecure()));
  }
  zr.setEnabled(this.isEnabled());
  return zr;
}

代码示例来源:origin: mozilla/zest

@Override
public void setStandardVariables(ZestResponse response) {
  if (response != null) {
    if (response.getUrl() != null) {
      this.setVariable(ZestVariables.RESPONSE_URL, response.getUrl().toString());
    }
    this.setVariable(ZestVariables.RESPONSE_HEADER, response.getHeaders());
    this.setVariable(ZestVariables.RESPONSE_BODY, response.getBody());
  }
}

代码示例来源:origin: mozilla/zest

private ZestResponse makeZestResponse(String pageContent) {
    String html = String.format(htmlScaffold, pageContent);
    String notRelevantHeader = "Header not relevant";
    URL notRelevantUrl = null;
    return new ZestResponse(notRelevantUrl, notRelevantHeader, html, 200, 0);
  }
}

代码示例来源:origin: mozilla/zest

public static List<String> getFields(ZestResponse response, int formId) {
    List<String> list = new ArrayList<String>();

    Source src = new Source(response.getHeaders() + response.getBody());
    List<Element> formElements = src.getAllElements(HTMLElementName.FORM);
    if (formElements != null && formId < formElements.size()) {
      Element form = formElements.get(formId);
      List<Element> inputElements = form.getAllElements(HTMLElementName.INPUT);
      String field;

      for (Element inputElement : inputElements) {
        field = inputElement.getAttributeValue("ID");
        if (field == null || field.length() == 0) {
          field = inputElement.getAttributeValue("NAME");
        }
        if (field != null && field.length() > 0) {
          list.add(field);
        }
      }
    }
    return list;
  }
}

代码示例来源:origin: mozilla/zest

private static ZestResponse createResponse(int statusCode) throws Exception {
    return new ZestResponse(new URL("http://localhost/"), "", "", statusCode, 0);
  }
}

代码示例来源:origin: mozilla/zest

value = this.getTokenValue(response.getHeaders());
} else if (LOC_BODY.equals(this.location)) {
  value = this.getTokenValue(response.getBody());
} else {
  value = this.getTokenValue(response.getHeaders());
  if (value == null) {
    value = this.getTokenValue(response.getBody());

代码示例来源:origin: mozilla/zest

@Test
public void testSimpleCaseExact() throws Exception {
  ZestExpressionRegex regex =
      new ZestExpressionRegex(ZestVariables.RESPONSE_BODY, "test123", true, false);
  ZestAssertion ze = new ZestAssertion(regex);
  assertTrue(ze.isValid(new TestRuntime(new ZestResponse(null, "", "aaaatest123", 200, 0))));
  assertFalse(ze.isValid(new TestRuntime(new ZestResponse(null, "", "aaaaTest123", 200, 0))));
}

代码示例来源:origin: mozilla/zest

value = this.getVariableValue(response.getHeaders());
} else if (LOC_BODY.equals(this.location)) {
  value = this.getVariableValue(response.getBody());
} else {
  value = this.getVariableValue(response.getHeaders());
  if (value == null) {
    value = this.getVariableValue(response.getBody());

代码示例来源:origin: mozilla/zest

@Test
public void testSimpleCaseIgnore() throws Exception {
  ZestExpressionRegex regex =
      new ZestExpressionRegex(ZestVariables.RESPONSE_BODY, "test123", false, false);
  ZestAssertion ze = new ZestAssertion(regex);
  assertTrue(ze.isValid(new TestRuntime(new ZestResponse(null, "", "aaaatest123", 200, 0))));
  assertTrue(ze.isValid(new TestRuntime(new ZestResponse(null, "", "aaaaTest123", 200, 0))));
}

代码示例来源:origin: mozilla/zest

@Override
  public String assign(ZestResponse response, ZestRuntime runtime)
      throws ZestAssignFailException {
    if (response == null) {
      throw new ZestAssignFailException(this, "Null response");
    }

    Source src = new Source(response.getHeaders() + response.getBody());
    List<Element> formElements = src.getAllElements(HTMLElementName.FORM);

    if (formElements != null && fieldDefinition.getFormIndex() < formElements.size()) {
      Element form = formElements.get(fieldDefinition.getFormIndex());

      List<Element> inputElements = form.getAllElements(HTMLElementName.INPUT);
      for (Element inputElement : inputElements) {
        if (fieldDefinition.getFieldName().equals(inputElement.getAttributeValue("ID"))
            || fieldDefinition
                .getFieldName()
                .equals(inputElement.getAttributeValue("NAME"))) {
          // Got it
          return inputElement.getAttributeValue("VALUE");
        }
      }
    }

    return null;
  }
}

代码示例来源:origin: mozilla/zest

@Test
  public void testIsTrueExcludePattern() {
    try {
      ZestResponse response =
          new ZestResponse(new URL("http://www.PONG19874.com"), "", "", 200, 100);
      ZestExpressionURL urlExpr = new ZestExpressionURL(includeStrings, excludeStrings);
      assertFalse(urlExpr.isTrue(new TestRuntime(response)));
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: mozilla/zest

/**
 * Method testSimpleIncRegex.
 *
 * @throws Exception
 */
@Test
public void testSimpleIncRegex() throws Exception {
  ZestExpressionRegex regex = new ZestExpressionRegex(ZestVariables.RESPONSE_BODY, "test123");
  ZestAssertion ze = new ZestAssertion(regex);
  assertTrue(ze.isValid(new TestRuntime(new ZestResponse(null, "", "aaaatest123", 200, 0))));
}

代码示例来源:origin: mozilla/zest

/**
 * Method testSimpleIncInvRegex.
 *
 * @throws Exception
 */
@Test
public void testSimpleIncInvRegex() throws Exception {
  ZestExpressionRegex regex =
      new ZestExpressionRegex(ZestVariables.RESPONSE_BODY, "test123", false, true);
  ZestAssertion ze = new ZestAssertion(regex);
  assertFalse(ze.isValid(new TestRuntime(new ZestResponse(null, "", "aaaatest123", 200, 0))));
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com