SpringCloud JAX-RS支持

2023-12-13 11:40 更新

Spring Cloud Contract驗(yàn)證程序支持JAX-RS 2客戶端API。基類(lèi)需要定義protected WebTarget webTarget和服務(wù)器初始化。測(cè)試JAX-RS API的唯一選項(xiàng)是啟動(dòng)web服務(wù)器。同樣,帶有主體的請(qǐng)求需要設(shè)置內(nèi)容類(lèi)型。否則,將使用默認(rèn)值application/octet-stream。

為了使用JAX-RS模式,請(qǐng)使用以下設(shè)置:

testMode == 'JAXRSCLIENT'

以下示例顯示了生成的測(cè)試API:

					'''
 // when:
  Response response = webTarget
    .path("/users")
    .queryParam("limit", "10")
    .queryParam("offset", "20")
    .queryParam("filter", "email")
    .queryParam("sort", "name")
    .queryParam("search", "55")
    .queryParam("age", "99")
    .queryParam("name", "Denis.Stepanov")
    .queryParam("email", "bob@email.com")
    .request()
    .method("GET");

  String responseAsString = response.readEntity(String.class);

 // then:
  assertThat(response.getStatus()).isEqualTo(200);
 // and:
  DocumentContext parsedJson = JsonPath.parse(responseAsString);
  assertThatJson(parsedJson).field("['property1']").isEqualTo("a");
'''
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)