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

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

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

Response.then介绍

暂无

代码示例

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void readSecondecretPathOverHttpApi() throws InterruptedException {
  given().
    header("X-Vault-Token", VAULT_TOKEN).
  when().
    get("http://"+getHostAndPort()+"/v1/secret/testing2").
  then().
    assertThat().body("data.secret_one", containsString("password1")).
    assertThat().body("data.secret_two", containsString("password2")).
    assertThat().body("data.secret_three", containsString("password3")).
    assertThat().body("data.secret_four", containsString("password4"));
}

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void readFirstSecretPathOverHttpApi() throws InterruptedException {
  given().
    header("X-Vault-Token", VAULT_TOKEN).
  when().
    get("http://"+getHostAndPort()+"/v1/secret/testing1").
  then().
    assertThat().body("data.top_secret", equalTo("password123"));
}

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

public void body() throws Exception {
  // tag::body[]
  Map<String, String> metadata = new HashMap<>();
  metadata.put("version", "1.0");
  RestAssured.given(this.spec).accept("application/json")
    .filter(document("image-upload", requestPartBody("metadata"))) // <1>
    .when().multiPart("image", new File("image.png"), "image/png")
        .multiPart("metadata", metadata).post("images")
    .then().assertThat().statusCode(is(200));
  // end::body[]
}

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

public void invokeService() throws Exception {
    // tag::invoke-service[]
    RestAssured.given(this.spec) // <1>
        .accept("application/json") // <2>
        .filter(document("index")) // <3>
        .when().get("/") // <4>
        .then().assertThat().statusCode(is(200)); // <5>
    // end::invoke-service[]
  }
}

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

public void bodySubsection() throws Exception {
  // tag::body-subsection[]
  RestAssured.given(this.spec).accept("application/json")
    .filter(document("location", responseBody(beneathPath("weather.temperature")))) // <1>
    .when().get("/locations/1")
    .then().assertThat().statusCode(is(200));
  // end::body-subsection[]
}

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

public void use() throws Exception {
  // tag::use[]
  RestAssured.given(this.spec)
    .filter(document("index",
      links(linkWithRel("self").description("Canonical self link"))))
    .when().get("/")
    .then().assertThat().statusCode(is(200));
  // end::use[]
}

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

public void upload() throws Exception {
  // tag::request-parts[]
  RestAssured.given(this.spec)
    .filter(document("users", requestParts( // <1>
        partWithName("file").description("The file to upload")))) // <2>
    .multiPart("file", "example") // <3>
    .when().post("/upload") // <4>
    .then().statusCode(is(200));
  // end::request-parts[]
}

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

public void general() throws Exception {
  // tag::preprocessing[]
  RestAssured.given(this.spec)
    .filter(document("index", preprocessRequest(removeHeaders("Foo")), // <1>
        preprocessResponse(prettyPrint()))) // <2>
  .when().get("/")
  .then().assertThat().statusCode(is(200));
  // end::preprocessing[]
}

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

public void postFormDataSnippet() throws Exception {
  // tag::request-parameters-form-data[]
  RestAssured.given(this.spec)
    .filter(document("create-user", requestParameters(
        parameterWithName("username").description("The user's username"))))
    .formParam("username", "Tester") // <1>
    .when().post("/users") // <2>
    .then().assertThat().statusCode(is(200));
  // end::request-parameters-form-data[]
}

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

@Test
public void defaultSnippetGeneration() {
  given().port(tomcat.getPort())
      .filter(documentationConfiguration(this.restDocumentation))
      .filter(document("default")).get("/").then().statusCode(200);
  assertExpectedSnippetFilesExist(new File("build/generated-snippets/default"),
      "http-request.adoc", "http-response.adoc", "curl-request.adoc");
}

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

@Test
public void parameterizedOutputDirectory() throws Exception {
  given().port(tomcat.getPort())
      .filter(documentationConfiguration(this.restDocumentation))
      .filter(document("{method-name}")).get("/").then().statusCode(200);
  assertExpectedSnippetFilesExist(
      new File("build/generated-snippets/parameterized-output-directory"),
      "http-request.adoc", "http-response.adoc", "curl-request.adoc");
}

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

public void getQueryStringSnippet() throws Exception {
  // tag::request-parameters-query-string[]
  RestAssured.given(this.spec)
    .filter(document("users", requestParameters( // <1>
        parameterWithName("page").description("The page to retrieve"), // <2>
        parameterWithName("per_page").description("Entries per page")))) // <3>
    .when().get("/users?page=2&per_page=100") // <4>
    .then().assertThat().statusCode(is(200));
  // end::request-parameters-query-string[]
}

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

public void explicitType() throws Exception {
  RestAssured.given(this.spec).accept("application/json")
    // tag::explicit-type[]
    .filter(document("user", responseFields(
        fieldWithPath("contact.email")
            .type(JsonFieldType.STRING) // <1>
            .description("The user's email address"))))
    // end::explicit-type[]
    .when().get("/user/5")
    .then().assertThat().statusCode(is(200));
}

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

public void documentation() throws Exception {
  // tag::use[]
  RestAssured.given(this.spec)
    .accept("application/json")
    .filter(document("example", this.pagingLinks.and( // <1>
        linkWithRel("alpha").description("Link to the alpha resource"),
        linkWithRel("bravo").description("Link to the bravo resource"))))
    .get("/").then().assertThat().statusCode(is(200));
  // end::use[]
}

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

public void pathParametersSnippet() throws Exception {
    // tag::path-parameters[]
    RestAssured.given(this.spec)
      .filter(document("locations", pathParameters( // <1>
          parameterWithName("latitude").description("The location's latitude"), // <2>
          parameterWithName("longitude").description("The location's longitude")))) // <3>
      .when().get("/locations/{latitude}/{longitude}", 51.5072, 0.1275) // <4>
      .then().assertThat().statusCode(is(200));
    // end::path-parameters[]
  }
}

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

public void fieldsSubsection() throws Exception {
  // tag::fields-subsection[]
  RestAssured.given(this.spec).accept("application/json")
    .filter(document("location", responseFields(beneathPath("weather.temperature"), // <1>
      fieldWithPath("high").description("The forecast high in degrees celcius"), // <2>
      fieldWithPath("low").description("The forecast low in degrees celcius"))))
    .when().get("/locations/1")
    .then().assertThat().statusCode(is(200));
  // end::fields-subsection[]
}

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

@Test
public void linksSnippet() throws Exception {
  given().port(tomcat.getPort())
      .filter(documentationConfiguration(this.restDocumentation))
      .filter(document("links",
          links(linkWithRel("rel").description("The description"))))
      .accept("application/json").get("/").then().statusCode(200);
  assertExpectedSnippetFilesExist(new File("build/generated-snippets/links"),
      "http-request.adoc", "http-response.adoc", "curl-request.adoc",
      "links.adoc");
}

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

@Test
public void requestPartsSnippet() throws Exception {
  given().port(tomcat.getPort())
      .filter(documentationConfiguration(this.restDocumentation))
      .filter(document("request-parts",
          requestParts(partWithName("a").description("The description"))))
      .multiPart("a", "foo").post("/upload").then().statusCode(200);
  assertExpectedSnippetFilesExist(
      new File("build/generated-snippets/request-parts"), "http-request.adoc",
      "http-response.adoc", "curl-request.adoc", "request-parts.adoc");
}

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

@Test
public void pathParametersSnippet() throws Exception {
  given().port(tomcat.getPort())
      .filter(documentationConfiguration(this.restDocumentation))
      .filter(document("path-parameters",
          pathParameters(
              parameterWithName("foo").description("The description"))))
      .accept("application/json").get("/{foo}", "").then().statusCode(200);
  assertExpectedSnippetFilesExist(
      new File("build/generated-snippets/path-parameters"), "http-request.adoc",
      "http-response.adoc", "curl-request.adoc", "path-parameters.adoc");
}

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

@Test
public void requestFieldsSnippet() throws Exception {
  given().port(tomcat.getPort())
      .filter(documentationConfiguration(this.restDocumentation))
      .filter(document("request-fields",
          requestFields(fieldWithPath("a").description("The description"))))
      .accept("application/json").body("{\"a\":\"alpha\"}").post("/").then()
      .statusCode(200);
  assertExpectedSnippetFilesExist(
      new File("build/generated-snippets/request-fields"), "http-request.adoc",
      "http-response.adoc", "curl-request.adoc", "request-fields.adoc");
}

相关文章