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

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

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

Response.asString介绍

暂无

代码示例

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

@Test
@RunAsClient
@InSequence(13)
public void testPrometheusFormatNoBadChars() throws Exception {
  Header wantPrometheusFormat = new Header("Accept", TEXT_PLAIN);
  String data = given().header(wantPrometheusFormat).get("/metrics/base").asString();
  String[] lines = data.split("\n");
  for (String line : lines) {
    if (line.startsWith("#")) {
      continue;
    }
    String[] tmp = line.split(" ");
    assertEquals(tmp.length, 2);
    assertFalse("Line has illegal chars " + line, tmp[0].matches("[-.]"));
    assertFalse("Found __ in " + line, tmp[0].matches("__"));
  }
}

代码示例来源:origin: yahoo/elide

@Test
public void testSparseTwoDataFieldValuesNoIncludes() throws Exception {
  JsonNode responseBody = objectMapper.readTree(
      RestAssured
          .given()
          .contentType(JSONAPI_CONTENT_TYPE)
          .accept(JSONAPI_CONTENT_TYPE)
          .param("fields[book]", "title,language")
          .get("/book").asString());
  Assert.assertTrue(responseBody.has("data"));
  for (JsonNode bookNode : responseBody.get("data")) {
    Assert.assertTrue(bookNode.has(ATTRIBUTES));
    Assert.assertFalse(bookNode.has(RELATIONSHIPS));
    JsonNode attributes = bookNode.get(ATTRIBUTES);
    Assert.assertEquals(attributes.size(), 2);
    Assert.assertTrue(attributes.has("title"));
    Assert.assertTrue(attributes.has("language"));
  }
  Assert.assertFalse(responseBody.has(INCLUDED));
}

代码示例来源:origin: ldp4j/ldp4j

private final Query queryResource(URL contextURL, String path) throws IOException {
  Response response=
    given().
      accept(TEXT_TURTLE).
      baseUri(contextURL.toString()).
    expect().
      statusCode(OK).
      contentType(TEXT_TURTLE).
    when().
      get(path);
  return QueryResponseHelper.getQuery(contextURL, path, response.asString());
}

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

@Test
public void testTriggerOnProperty() throws Exception {
  String callback = "validate";
  String propName = "tagId";
  Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
      .expect() //
      .statusCode(200).log().ifError() //
      .with() //
      .content(buildTestDataStoreFormData()) //
      .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
      .post(getVersionPrefix() + "/properties/trigger/{callback}/{propName}", callback, propName);
  assertNotNull(response);
  String content = response.asString();
  assertNotNull(content);
}

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

@Test
public void testInitializePropertiesUiSpecs() throws Exception {
  Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
      .expect() //
      .statusCode(200).log().ifError() //
      .with() //
      .content(buildTestDataSetFormData()) //
      .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
      .post(getVersionPrefix() + "/properties/uispec");
  assertNotNull(response);
  String content = response.asString();
  assertEquals(getMockDatasetMainFormUISpecs(), content);
}

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

@Test
@RunAsClient
@InSequence(14)
  Header wantPrometheusFormat = new Header("Accept", TEXT_PLAIN);
  String data = given().header(wantPrometheusFormat).get("/metrics/base").asString();

代码示例来源:origin: yahoo/elide

@Test
public void testSparseSingleDataFieldValue() throws Exception {
  JsonNode responseBody = objectMapper.readTree(
      RestAssured
          .given()
          .contentType(JSONAPI_CONTENT_TYPE)
          .accept(JSONAPI_CONTENT_TYPE)
          .param("include", "authors")
          .param("fields[book]", "title")
          .get("/book").asString());
  Assert.assertTrue(responseBody.has("data"));
  for (JsonNode bookNode : responseBody.get("data")) {
    Assert.assertTrue(bookNode.has(ATTRIBUTES));
    Assert.assertFalse(bookNode.has(RELATIONSHIPS));
    JsonNode attributes = bookNode.get(ATTRIBUTES);
    Assert.assertEquals(attributes.size(), 1);
    Assert.assertTrue(attributes.has("title"));
  }
  Assert.assertTrue(responseBody.has(INCLUDED));
  for (JsonNode include : responseBody.get(INCLUDED)) {
    Assert.assertFalse(include.has(ATTRIBUTES));
    Assert.assertFalse(include.has(RELATIONSHIPS));
  }
}

代码示例来源:origin: apache/marmotta

private void testGetBase(RDFFormat format) throws Exception {
  String data = given().header("Accept",format.getDefaultMIMEType()).expect().statusCode(200).when().get(createResourceURI("sepp_huber").stringValue()).asString();
  Repository mem = new SailRepository(new MemoryStore());
  mem.initialize();
  RepositoryConnection con = mem.getConnection();
  RepositoryConnection icon = sesameService.getConnection();
  try {
    con.begin();
    con.add(new StringReader(data), RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath, format);
    Assert.assertTrue(con.hasStatement(createResourceURI("sepp_huber"),null,null,true));
    RepositoryResult<Statement> statements = icon.getStatements(createResourceURI("sepp_huber"), null,null,true);
    while(statements.hasNext()) {
      Statement stmt = statements.next();
      Assert.assertTrue("statement "+stmt+" not found in results",con.hasStatement(stmt,true));
    }
    con.commit();
    icon.commit();
  } finally {
    con.close();
    icon.close();
  }
  String invalid = given().header("Accept",format.getDefaultMIMEType()).expect().statusCode(404).when().get(createResourceURI("xyz").stringValue()).asString();
}

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

@Test
public void testInitializePropertiesJsonio() throws Exception {
  Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
      .expect() //
      .statusCode(200).log().ifError() //
      .with() //
      .content(buildTestDataSetSerProps()) //
      .contentType(ServiceConstants.JSONIO_CONTENT_TYPE) //
      .post(getVersionPrefix() + "/properties/uispec");
  assertNotNull(response);
  String content = response.asString();
  assertEquals(getMockDatasetMainFormUISpecs(), content);
}

代码示例来源:origin: yahoo/elide

@Test
public void testSparseNoFilters() throws Exception {
  JsonNode responseBody = objectMapper.readTree(
      RestAssured
          .given()
          .contentType(JSONAPI_CONTENT_TYPE)
          .accept(JSONAPI_CONTENT_TYPE)
          .param("include", "authors")
          .get("/book").asString());
  Assert.assertTrue(responseBody.has("data"));
  for (JsonNode bookNode : responseBody.get("data")) {
    Assert.assertTrue(bookNode.has(ATTRIBUTES));
    JsonNode attributes = bookNode.get(ATTRIBUTES);
    Assert.assertTrue(attributes.has("title"));
    Assert.assertTrue(attributes.has("language"));
    Assert.assertTrue(attributes.has("genre"));
    Assert.assertTrue(bookNode.has(RELATIONSHIPS));
    JsonNode relationships = bookNode.get(RELATIONSHIPS);
    Assert.assertTrue(relationships.has("authors"));
  }
  Assert.assertTrue(responseBody.has(INCLUDED));
  for (JsonNode include : responseBody.get(INCLUDED)) {
    Assert.assertTrue(include.has(ATTRIBUTES));
    JsonNode attributes = include.get(ATTRIBUTES);
    Assert.assertTrue(attributes.has("name"));
    Assert.assertTrue(include.has(RELATIONSHIPS));
    JsonNode relationships = include.get(RELATIONSHIPS);
    Assert.assertTrue(relationships.has("books"));
  }
}

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

@Test
public void testSerializeProperties() throws Exception {
  Response response = given().accept(ServiceConstants.JSONIO_CONTENT_TYPE) //
      .expect() //
      .statusCode(200).log().ifError() //
      .with().port(localServerPort) //
      .content(buildTestDataSetFormData()) //
      .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
      .post(getVersionPrefix() + "/properties/serialize");
  assertNotNull(response);
  String content = response.asString();
  assertNotNull(content);
  //take the jsonIO
  JsonNode jsonNode = mapper.readTree(content);
  String jsonioProperties = jsonNode.get("properties").asText();
  Deserialized<MockDatasetProperties> fromSerializedPersistent = Properties.Helper.fromSerializedPersistent(
      jsonioProperties, MockDatasetProperties.class);
  assertNotNull(fromSerializedPersistent);
  assertNotNull(fromSerializedPersistent.object);
  MockDatasetProperties deserializedProps = fromSerializedPersistent.object;
  assertEquals("tata", deserializedProps.tag.getValue());
}

代码示例来源:origin: yahoo/elide

JsonNode responseBody = objectMapper.readTree(
    RestAssured
        .given()
        .contentType(JSONAPI_CONTENT_TYPE)
        .accept(JSONAPI_CONTENT_TYPE)
        .param("fields[book]", "title,genre,authors")
        .param("fields[author]", "name")
        .get("/book").asString());

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

@Test
public void testSerializeDeserializeProperties() throws Exception {
  Response response = given().accept(ServiceConstants.JSONIO_CONTENT_TYPE) //
      .expect() //
      .statusCode(200).log().ifError() //
      .with().port(localServerPort) //
      .content(buildTestDataSetFormData()) //
      .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
      .post(getVersionPrefix() + "/properties/serialize");
  assertNotNull(response);
  String content = response.asString();
  assertNotNull(content);
  response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
      .expect() //
      .statusCode(200).log().ifError() //
      .with() //
      .content(content) //
      .contentType(ServiceConstants.JSONIO_CONTENT_TYPE) //
      .post(getVersionPrefix() + "/properties/uispec");
  assertNotNull(response);
  assertEquals(getMockDatasetMainFormUISpecs(), response.asString());
}

代码示例来源:origin: eventuate-tram/eventuate-tram-examples-java-spring-todo-list

private List<TodoView> search(String value) {
 try {
  return Arrays.asList(objectMapper.readValue(given()
      .queryParam("searchValue", value)
      .when()
      .get(baseUrl() + "/todoviews")
      .then()
      .statusCode(200)
      .extract()
      .response()
      .asString(), TodoView[].class));
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: eventuate-tram/eventuate-tram-examples-java-spring-todo-list

private List<TodoView> search(String value) {
 try {
  return Arrays.asList(objectMapper.readValue(given()
      .queryParam("searchValue", value)
      .when()
      .get(todoViewServiceBaseUrl() + "/todoviews")
      .then()
      .statusCode(200)
      .extract()
      .response()
      .asString(), TodoView[].class));
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: yahoo/elide

@Test(priority = 1)
public void testPatchAttrSingle() throws Exception {
  String request = jsonParser.getJson("/ResourceIT/testPatchAttrSingle.json");
  given()
    .contentType(JSONAPI_CONTENT_TYPE)
    .accept(JSONAPI_CONTENT_TYPE)
    .body(request)
    .patch("/parent/2")
    .then()
    .statusCode(HttpStatus.SC_NO_CONTENT)
    .header(HttpHeaders.CONTENT_LENGTH, (String) null);
  String actual = given()
    .contentType(JSONAPI_CONTENT_TYPE)
    .accept(JSONAPI_CONTENT_TYPE)
    .get("/parent/2")
    .then()
    .statusCode(HttpStatus.SC_OK)
    .contentType(JSONAPI_CONTENT_TYPE)
    .extract().response().asString();
  JsonApiDocument doc = jsonApiMapper.readJsonApiDocument(actual);
  Data<Resource> data = doc.getData();
  Resource resource = data.getSingleValue();
  assertEquals(resource.getAttributes().get("firstName"), "syzygy");
  assertEquals(resource.getRelationships().size(), 2);
  assertEquals(resource.getRelationships().get("children").getData().get().size(), 2);
}

代码示例来源:origin: yahoo/elide

String request = jsonParser.getJson("/ResourceIT/testPatchRelSetDirect.json");
given()
  .contentType(JSONAPI_CONTENT_TYPE)
  .accept(JSONAPI_CONTENT_TYPE)
  .header(HttpHeaders.CONTENT_LENGTH, (String) null);
String actual = given()
  .contentType(JSONAPI_CONTENT_TYPE)
  .accept(JSONAPI_CONTENT_TYPE)
  .then()
  .statusCode(HttpStatus.SC_OK)
  .extract().response().asString();

代码示例来源:origin: yahoo/elide

String request = jsonParser.getJson("/ResourceIT/testPatchSetRel.json");
given()
  .contentType(JSONAPI_CONTENT_TYPE)
  .accept(JSONAPI_CONTENT_TYPE)
  .header(HttpHeaders.CONTENT_LENGTH, (String) null);
String actual = given()
  .contentType(JSONAPI_CONTENT_TYPE)
  .accept(JSONAPI_CONTENT_TYPE)
  .then()
  .statusCode(HttpStatus.SC_OK)
  .extract().response().asString();

代码示例来源:origin: yahoo/elide

given()
    .contentType(JSONAPI_CONTENT_TYPE)
    .accept(JSONAPI_CONTENT_TYPE)
    .then()
    .statusCode(HttpStatus.SC_OK)
    .extract().response().asString();
    .then()
    .statusCode(HttpStatus.SC_OK)
    .extract().response().asString();
    .then()
    .statusCode(HttpStatus.SC_OK)
    .extract().response().asString();
    .then()
    .statusCode(HttpStatus.SC_NOT_FOUND)
    .extract().response().asString();
    .then()
    .statusCode(HttpStatus.SC_OK)
    .extract().response().asString();
    .then()
    .statusCode(HttpStatus.SC_OK)
    .extract().response().asString();

相关文章