io.restassured.response.Response.getStatusCode()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(162)

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

Response.getStatusCode介绍

暂无

代码示例

代码示例来源:origin: rest-assured/rest-assured

/**
 * Clone an already existing response.
 *
 * @return Builder.
 */
public ResponseBuilder clone(Response response) {
  if (isRestAssuredResponse(response)) {
    final RestAssuredResponseImpl raResponse = raResponse(response);
    restAssuredResponse.setContent(raResponse.getContent());
    restAssuredResponse.setHasExpectations(raResponse.getHasExpectations());
    restAssuredResponse.setDefaultContentType(raResponse.getDefaultContentType());
    restAssuredResponse.setDecoderConfig(raResponse.getDecoderConfig());
    restAssuredResponse.setSessionIdName(raResponse.getSessionIdName());
    restAssuredResponse.setConnectionManager(raResponse.getConnectionManager());
    restAssuredResponse.setConfig(raResponse.getConfig());
    restAssuredResponse.setRpr(raResponse.getRpr());
    restAssuredResponse.setLogRepository(raResponse.getLogRepository());
    restAssuredResponse.setFilterContextProperties(raResponse.getFilterContextProperties());
  } else {
    restAssuredResponse.setContent(response.asInputStream());
  }
  restAssuredResponse.setContentType(response.getContentType());
  restAssuredResponse.setCookies(response.getDetailedCookies());
  restAssuredResponse.setResponseHeaders(response.getHeaders());
  restAssuredResponse.setStatusCode(response.getStatusCode());
  restAssuredResponse.setStatusLine(response.getStatusLine());
  return this;
}

代码示例来源:origin: spring-projects/spring-restdocs

@Override
public OperationResponse convert(Response response) {
  return new OperationResponseFactory().create(
      HttpStatus.valueOf(response.getStatusCode()), extractHeaders(response),
      extractContent(response));
}

代码示例来源:origin: alfa-laboratory/akita

/**
 * Сравнение кода http ответа с ожидаемым
 *
 * @param response           ответ от сервиса
 * @param expectedStatusCode ожидаемый http статус код
 * @return возвращает true или false в зависимости от ожидаемого и полученного http кодов
 */
public boolean checkStatusCode(Response response, int expectedStatusCode) {
  int statusCode = response.getStatusCode();
  if (statusCode != expectedStatusCode) {
    akitaScenario.write("Получен неверный статус код ответа " + statusCode + ". Ожидаемый статус код " + expectedStatusCode);
  }
  return statusCode == expectedStatusCode;
}

代码示例来源:origin: Frameworkium/frameworkium-core

/**
   * @param url the url to GET
   * @param maxTries max number of tries to GET url
   * @return the bytes from the downloaded URL
   * @throws TimeoutException if download fails and max tries have been exceeded
   */
  public byte[] fetchWithRetry(URL url, int maxTries) throws TimeoutException {
    logger.debug("Downloading: " + url);
    for (int i = 0; i < maxTries; i++) {
      Response response = RestAssured.get(url);
      if (response.getStatusCode() == HttpStatus.SC_OK) {
        return response.asByteArray();
      }
      logger.debug("Retrying download: " + url);

      try {
        TimeUnit.SECONDS.sleep(2);
      } catch (InterruptedException e) {
        throw new IllegalStateException(e);
      }
    }
    throw new TimeoutException();
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-rest

private void logResponse(Response response) {
  StringBuilder builder = new StringBuilder("RESPONSE:\n\n");
  String body = response.getBody().prettyPrint();
  createLog(builder, "STATUS", String.valueOf(response.getStatusCode()), false);
  createLog(builder, "HEADERS", response.getHeaders().toString(), true);
  if (body.length() > 0) createLog(builder, "BODY", response.getBody().prettyPrint(), true);
  scenarioWrite(builder.toString());
}

代码示例来源:origin: com.atlassian.oai/swagger-request-validator-restassured

/**
   * Builds a {@link Response} for the OpenAPI validator out of the
   * original {@link io.restassured.response.Response}.
   *
   * @param originalResponse the original {@link io.restassured.response.Response}
   */
  @Nonnull
  public static Response of(@Nonnull final io.restassured.response.Response originalResponse) {
    requireNonNull(originalResponse, "An original response is required");
    final SimpleResponse.Builder builder = new SimpleResponse.Builder(originalResponse.getStatusCode())
        .withBody(originalResponse.getBody().asString());
    if (originalResponse.getHeaders() != null) {
      originalResponse.getHeaders().forEach(header -> builder.withHeader(header.getName(), header.getValue()));
    }
    return builder.build();
  }
}

代码示例来源:origin: HotelsDotCom/heat

/**
 * Check of the responses code of the retrieved responses.
 * @param testCaseParams it is a map retrieved from the json input file with
 * all input test data
 * @return true if the check is ok, false otherwise
 */
public boolean checkResponseCode(Map testCaseParams) {
  boolean isCheckOk = true;
  //isBlocking: if it is true, in case of failure the test stops running, otherwise it will go on running with the other checks (the final result does not change)
  boolean isBlocking = TestSuiteHandler.getInstance().getTestCaseUtils().getSystemParamOnBlocking();
  if (responses == null) {
    logUtils.error("response NULL");
    throw new HeatException(logUtils.getExceptionDetails() + "response NULL");
  }
  if (testCaseParams.containsKey(EXPECTS_JSON_ELEMENT)) {
    Map<String, String> expectedParams = (Map<String, String>) testCaseParams.get(EXPECTS_JSON_ELEMENT);
    String expectedRespCode = expectedParams.get(RESPONSE_CODE_JSON_ELEMENT);
    if (expectedRespCode != null) {
      String currentStatusCode = String.valueOf(((Response) responses).getStatusCode());
      logUtils.debug("check response code: current '{}' / expected '{}'", currentStatusCode, expectedRespCode);
      isCheckOk &= assertionHandler.assertion(isBlocking, "assertEquals", logUtils.getTestCaseDetails() + "{checkResponseCode} ", currentStatusCode, expectedRespCode);
    }
  } else {
    throw new HeatException(logUtils.getExceptionDetails() + "not any 'expects' found");
  }
  return isCheckOk;
}

代码示例来源:origin: com.hotels/heat-core-utils

/**
 * Check of the responses code of the retrieved responses.
 * @param testCaseParams it is a map retrieved from the json input file with
 * all input test data
 * @return true if the check is ok, false otherwise
 */
public boolean checkResponseCode(Map testCaseParams) {
  boolean isCheckOk = true;
  //isBlocking: if it is true, in case of failure the test stops running, otherwise it will go on running with the other checks (the final result does not change)
  boolean isBlocking = TestSuiteHandler.getInstance().getTestCaseUtils().getSystemParamOnBlocking();
  if (responses == null) {
    logUtils.error("response NULL");
    throw new HeatException(logUtils.getExceptionDetails() + "response NULL");
  }
  if (testCaseParams.containsKey(EXPECTS_JSON_ELEMENT)) {
    Map<String, String> expectedParams = (Map<String, String>) testCaseParams.get(EXPECTS_JSON_ELEMENT);
    String expectedRespCode = expectedParams.get(RESPONSE_CODE_JSON_ELEMENT);
    if (expectedRespCode != null) {
      String currentStatusCode = String.valueOf(((Response) responses).getStatusCode());
      logUtils.debug("check response code: current '{}' / expected '{}'", currentStatusCode, expectedRespCode);
      isCheckOk &= assertionHandler.assertion(isBlocking, "assertEquals", logUtils.getTestCaseDetails() + "{checkResponseCode} ", currentStatusCode, expectedRespCode);
    }
  } else {
    throw new HeatException(logUtils.getExceptionDetails() + "not any 'expects' found");
  }
  return isCheckOk;
}

相关文章