com.jayway.restassured.response.Response.jsonPath()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(125)

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

Response.jsonPath介绍

暂无

代码示例

代码示例来源:origin: com.qaprosoft/carina-utils

public static JsonPath jsonResponse(Response response) {
    return response.jsonPath();
  }
}

代码示例来源:origin: qaprosoft/carina

public static JsonPath jsonResponse(Response response) {
    return response.jsonPath();
  }
}

代码示例来源:origin: org.eclipse.microprofile.metrics/microprofile-metrics-rest-tck

@Test
@RunAsClient
@InSequence(19)
public void testApplicationMetadataItems() {
  Header wantJson = new Header("Accept", APPLICATION_JSON);
  JsonPath jsonPath = given().header(wantJson).options("/metrics/application").jsonPath();
  Map<String, Object> elements = jsonPath.getMap(".");
  List<String> missing = new ArrayList<>();
  Map<String, MiniMeta> names = getExpectedMetadataFromXmlFile(MetricRegistry.Type.APPLICATION);
  for (String item : names.keySet()) {
    if (!elements.containsKey(item)) {
      missing.add(item);
    }
  }
  assertTrue("Following application items are missing: " + Arrays.toString(missing.toArray()), missing.isEmpty());
}

代码示例来源:origin: org.eclipse.microprofile.metrics/microprofile-metrics-rest-tck

@Test
@RunAsClient
@InSequence(8)
public void testBaseSingularMetricsPresent() {
  Header wantJson = new Header("Accept", APPLICATION_JSON);
  JsonPath jsonPath = given().header(wantJson).get("/metrics/base").jsonPath();
  Map<String, Object> elements = jsonPath.getMap(".");
  List<String> missing = new ArrayList<>();
  Map<String, MiniMeta> baseNames = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE);
  for (String item : baseNames.keySet()) {
    if (item.startsWith("gc.")) {
      continue;
    }
    if (!elements.containsKey(item) && !baseNames.get(item).optional) {
      missing.add(item);
    }
  }
  
  assertTrue("Following base items are missing: " + Arrays.toString(missing.toArray()), missing.isEmpty());
}

代码示例来源:origin: org.eclipse.microprofile.metrics/microprofile-metrics-rest-tck

@Test
@RunAsClient
@InSequence(11)
public void testBaseMetadataSingluarItems() {
  Header wantJson = new Header("Accept", APPLICATION_JSON);
  JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath();
  Map<String, Object> elements = jsonPath.getMap(".");
  List<String> missing = new ArrayList<>();
  Map<String, MiniMeta> baseNames = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE);
  for (String item : baseNames.keySet()) {
    if (item.startsWith("gc.") || baseNames.get(item).optional) {
      continue;
    }
    if (!elements.containsKey(item)) {
      missing.add(item);
    }
  }
  assertTrue("Following base items are missing: " + Arrays.toString(missing.toArray()), missing.isEmpty());
}

代码示例来源:origin: org.eclipse.microprofile.metrics/microprofile-metrics-rest-tck

@Test
@RunAsClient
@InSequence(15)
public void testBaseMetadataGarbageCollection() throws Exception {
  Header wantJson = new Header("Accept", APPLICATION_JSON);
  JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath();
  int count = 0;
  Map<String, Object> elements = jsonPath.getMap(".");
  for (String name : elements.keySet()) {
    if (name.startsWith("gc.")) {
      assertTrue(name.endsWith(".count") || name.endsWith(".time"));
      count++;
    }
  }
  assertThat(count, greaterThan(0));
}

代码示例来源:origin: Hualiner/Api-Auto-Test

/**
 * 获取本次请求的响应信息
 *
 * @param response
 */
private String getResponseInfo(Response response) {
  // TODO - 此处容易抛异常
  if (response.contentType().contains("json")) {
    return "[" + response.statusCode() + "]" + response.jsonPath().get();
  } else {
    return "[" + response.statusCode() + "]" + response.htmlPath().get();
  }
}

代码示例来源:origin: org.eclipse.microprofile.metrics/microprofile-metrics-rest-tck

@Test
@RunAsClient
@InSequence(31)
public void testOptionalBaseMetrics() {
  Header wantJson = new Header("Accept", APPLICATION_JSON);
  JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath();
  Map<String, Object> elements = jsonPath.getMap(".");
  Map<String, MiniMeta> names = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE);
  for (String item : names.keySet()) {
    if (elements.containsKey(item) && names.get(item).optional) {
      String prefix = names.get(item).name;
      String type = "\""+prefix+"\""+".type";
      String unit= "\""+prefix+"\""+".unit";
      given().header(wantJson).options("/metrics/base/"+prefix).then().statusCode(200)
      .body(type, equalTo(names.get(item).type))
      .body(unit, equalTo(names.get(item).unit));
    }
  }
}

代码示例来源:origin: org.eclipse.microprofile.metrics/microprofile-metrics-rest-tck

@Test
@RunAsClient
@InSequence(21)
public void testApplicationTagJson() {
  JsonPath jsonPath = given().header("Accept", APPLICATION_JSON)
    .when()
    .options("/metrics/application/purple").jsonPath();
  String tags = jsonPath.getString("purple.tags");
  assertNotNull(tags);
  assertTrue(tags.contains("app=myShop"));
  assertTrue(tags.contains("tier=integration"));
}

代码示例来源:origin: Hualiner/Api-Auto-Test

/**
   * 请求
   *
   * @param testStep
   */
  public Response request(TestStep testStep) {
    RestAssured.baseURI = baseURL;

    if (!testStep.getParams().isEmpty()) {
      response = request(testStep.getType(), testStep.getPath(), testStep.getParams());
    } else {
      response = request(testStep.getType(), testStep.getPath());
    }

    logger.info(getResponseInfo(response));

    // TODO - 此处容易抛异常
    if (response.contentType().contains("json")) {
      listenerUtils.testCaseResult.setDescription(response.jsonPath().get().toString());
    } else {
      listenerUtils.testCaseResult.setDescription(response.htmlPath().get().toString());
    }

    return response;
  }
}

代码示例来源:origin: org.eclipse.microprofile.metrics/microprofile-metrics-rest-tck

@Test
@RunAsClient
@InSequence(12)
public void testBaseMetadataTypeAndUnit() {
  Header wantJson = new Header("Accept", APPLICATION_JSON);
  JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath();
  Map<String, Map<String, Object>> elements = jsonPath.getMap(".");
  Map<String, MiniMeta> expectedMetadata = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE);
     checkMetadataPresent(elements, expectedMetadata);
}

代码示例来源:origin: org.eclipse.microprofile.metrics/microprofile-metrics-rest-tck

@Test
@RunAsClient
@InSequence(20)
public void testApplicationMetadataTypeAndUnit() {
  Header wantJson = new Header("Accept", APPLICATION_JSON);
  JsonPath jsonPath = given().header(wantJson).options("/metrics/application").jsonPath();
  Map<String, Map<String, Object>> elements = jsonPath.getMap(".");
  Map<String, MiniMeta> expectedMetadata = getExpectedMetadataFromXmlFile(MetricRegistry.Type.APPLICATION);
  checkMetadataPresent(elements, expectedMetadata);
}

代码示例来源:origin: Talend/components

@Test
  public void testGetVersion() throws Exception {
    Response r = given().accept(APPLICATION_JSON_UTF8_VALUE) //
        .expect() //
        .statusCode(200).log().ifError() //
        .with().port(localServerPort) //
        .get(getVersionPrefix() + "/version");

    r.then() //
        .statusCode(HttpStatus.OK.value()).log().ifError() //
        .contentType(APPLICATION_JSON_UTF8_VALUE);

    // We don't care what values are returned as long as they are filled.
    JsonPath jsonPathEvaluator = r.jsonPath();
    assertThat(jsonPathEvaluator.get("version"), allOf(notNullValue(), not(equalTo(VersionDto.N_A))));
    assertThat(jsonPathEvaluator.get("commit"), allOf(notNullValue(), not(equalTo(VersionDto.N_A))));
    assertThat(jsonPathEvaluator.get("time"), allOf(notNullValue(), not(equalTo(VersionDto.N_A))));
  }
}

相关文章