下面列出了怎么用org.springframework.boot.test.json.BasicJsonTester的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testCmmnRestApiIntegrationNotFound() {
String processDefinitionsUrl = "http://localhost:" + serverPort + "/cmmn-api/cmmn-repository/case-definitions/does-not-exist";
ResponseEntity<String> response = restTemplate.getForEntity(processDefinitionsUrl, String.class);
BasicJsonTester jsonTester = new BasicJsonTester(getClass());
assertThat(jsonTester.from(response.getBody())).isEqualToJson("{"
+ "\"message\": \"Not found\","
+ "\"exception\": \"no deployed case definition found with id 'does-not-exist'\""
+ "}");
assertThat(response.getStatusCode())
.as("Status code")
.isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
public void testExternalJobRestApiIntegrationNotFound() {
String url = "http://localhost:" + serverPort + "/external-job-api/jobs/does-not-exist";
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
BasicJsonTester jsonTester = new BasicJsonTester(getClass());
assertThat(jsonTester.from(response.getBody())).isEqualToJson("{"
+ "\"message\": \"Not found\","
+ "\"exception\": \"Could not find external worker job with id 'does-not-exist'.\""
+ "}");
assertThat(response.getStatusCode())
.as("Status code")
.isEqualTo(HttpStatus.NOT_FOUND);
}