本文整理了Java中org.springframework.test.web.client.MockRestServiceServer.verify()
方法的一些代码示例,展示了MockRestServiceServer.verify()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockRestServiceServer.verify()
方法的具体详情如下:
包路径:org.springframework.test.web.client.MockRestServiceServer
类名称:MockRestServiceServer
方法名:verify
[英]Verify that all expected requests set up via #expect(RequestMatcher) were indeed performed.
[中]验证是否确实执行了通过#expect(RequestMatcher)设置的所有预期请求。
代码示例来源:origin: spring-projects/spring-framework
private void executeAndVerify() throws URISyntaxException {
this.restTemplate.getForObject(new URI("/person/1"), Person.class);
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
private void executeAndVerify() throws URISyntaxException {
this.restTemplate.put(new URI("/composers"), this.people);
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
private void executeAndVerify() throws URISyntaxException {
this.restTemplate.put(new URI("/composers"), this.people);
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
private void executeAndVerify(Object body) throws URISyntaxException {
this.restTemplate.put(new URI("/foo"), body);
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
private void executeAndVerify() throws URISyntaxException {
this.restTemplate.put(new URI("/composers"), people);
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void performGetWithResponseBodyFromFile() {
Resource responseBody = new ClassPathResource("ludwig.json", this.getClass());
this.mockServer.expect(requestTo("/composers/42")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
@SuppressWarnings("unused")
Person ludwig = this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
// hotel.getId() == 42
// hotel.getName().equals("Holiday Inn")
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void performGetManyTimes() {
String responseBody = "{\"name\" : \"Ludwig van Beethoven\", \"someDouble\" : \"1.6035\"}";
this.mockServer.expect(manyTimes(), requestTo("/composers/42")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
@SuppressWarnings("unused")
Person ludwig = this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
// We are only validating the request. The response is mocked out.
// hotel.getId() == 42
// hotel.getName().equals("Holiday Inn")
this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void resetAndReuseServer() {
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate).build();
server.expect(requestTo("/foo")).andRespond(withSuccess());
this.restTemplate.getForObject("/foo", Void.class);
server.verify();
server.reset();
server.expect(requestTo("/bar")).andRespond(withSuccess());
this.restTemplate.getForObject("/bar", Void.class);
server.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void performGetWithResponseBodyFromFile() throws Exception {
Resource responseBody = new ClassPathResource("ludwig.json", this.getClass());
this.mockServer.expect(requestTo("/composers/42")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
@SuppressWarnings("unused")
ListenableFuture<ResponseEntity<Person>> ludwig =
this.restTemplate.getForEntity("/composers/{id}", Person.class, 42);
// hotel.getId() == 42
// hotel.getName().equals("Holiday Inn")
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void performGet() {
String responseBody = "{\"name\" : \"Ludwig van Beethoven\", \"someDouble\" : \"1.6035\"}";
this.mockServer.expect(requestTo("/composers/42")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
@SuppressWarnings("unused")
Person ludwig = this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
// We are only validating the request. The response is mocked out.
// hotel.getId() == 42
// hotel.getName().equals("Holiday Inn")
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-14694
public void repeatedAccessToResponseViaResource() {
Resource resource = new ClassPathResource("ludwig.json", this.getClass());
RestTemplate restTemplate = new RestTemplate();
restTemplate.setInterceptors(Collections.singletonList(new ContentInterceptor(resource)));
MockRestServiceServer mockServer = MockRestServiceServer.bindTo(restTemplate)
.ignoreExpectOrder(true)
.bufferContent() // enable repeated reads of response body
.build();
mockServer.expect(requestTo("/composers/42")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess(resource, MediaType.APPLICATION_JSON));
restTemplate.getForObject("/composers/{id}", Person.class, 42);
mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void resetAndReuseServerWithUnorderedExpectationManager() {
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate)
.ignoreExpectOrder(true).build();
server.expect(requestTo("/foo")).andRespond(withSuccess());
this.restTemplate.getForObject("/foo", Void.class);
server.verify();
server.reset();
server.expect(requestTo("/foo")).andRespond(withSuccess());
server.expect(requestTo("/bar")).andRespond(withSuccess());
this.restTemplate.getForObject("/bar", Void.class);
this.restTemplate.getForObject("/foo", Void.class);
server.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void buildMultipleTimes() {
MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(this.restTemplate);
MockRestServiceServer server = builder.build();
server.expect(requestTo("/foo")).andRespond(withSuccess());
this.restTemplate.getForObject("/foo", Void.class);
server.verify();
server = builder.ignoreExpectOrder(true).build();
server.expect(requestTo("/foo")).andRespond(withSuccess());
server.expect(requestTo("/bar")).andRespond(withSuccess());
this.restTemplate.getForObject("/bar", Void.class);
this.restTemplate.getForObject("/foo", Void.class);
server.verify();
server = builder.build();
server.expect(requestTo("/bar")).andRespond(withSuccess());
this.restTemplate.getForObject("/bar", Void.class);
server.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void ignoreExpectOrder() {
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate)
.ignoreExpectOrder(true).build();
server.expect(requestTo("/foo")).andRespond(withSuccess());
server.expect(requestTo("/bar")).andRespond(withSuccess());
this.restTemplate.getForObject("/bar", Void.class);
this.restTemplate.getForObject("/foo", Void.class);
server.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void performGet() throws Exception {
String responseBody = "{\"name\" : \"Ludwig van Beethoven\", \"someDouble\" : \"1.6035\"}";
this.mockServer.expect(requestTo("/composers/42")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
@SuppressWarnings("unused")
ListenableFuture<ResponseEntity<Person>> ludwig =
this.restTemplate.getForEntity("/composers/{id}", Person.class, 42);
// We are only validating the request. The response is mocked out.
// person.getName().equals("Ludwig van Beethoven")
// person.getDouble().equals(1.6035)
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-16132
public void followUpRequestAfterFailure() {
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate).build();
server.expect(requestTo("/some-service/some-endpoint"))
.andRespond(request -> { throw new SocketException("pseudo network error"); });
server.expect(requestTo("/reporting-service/report-error"))
.andExpect(method(POST)).andRespond(withSuccess());
try {
this.restTemplate.getForEntity("/some-service/some-endpoint", String.class);
}
catch (Exception ex) {
this.restTemplate.postForEntity("/reporting-service/report-error", ex.toString(), String.class);
}
server.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void expectNever() {
String responseBody = "{\"name\" : \"Ludwig van Beethoven\", \"someDouble\" : \"1.6035\"}";
this.mockServer.expect(once(), requestTo("/composers/42")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
this.mockServer.expect(never(), requestTo("/composers/43")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void verify() {
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("1", MediaType.TEXT_PLAIN));
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("2", MediaType.TEXT_PLAIN));
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("4", MediaType.TEXT_PLAIN));
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("8", MediaType.TEXT_PLAIN));
@SuppressWarnings("unused")
String result1 = this.restTemplate.getForObject("/number", String.class);
// result1 == "1"
@SuppressWarnings("unused")
String result2 = this.restTemplate.getForObject("/number", String.class);
// result == "2"
try {
this.mockServer.verify();
}
catch (AssertionError error) {
assertTrue(error.getMessage(), error.getMessage().contains("2 unsatisfied expectation(s)"));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void performGetManyTimes() throws Exception {
String responseBody = "{\"name\" : \"Ludwig van Beethoven\", \"someDouble\" : \"1.6035\"}";
this.mockServer.expect(manyTimes(), requestTo("/composers/42")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
@SuppressWarnings("unused")
ListenableFuture<ResponseEntity<Person>> ludwig =
this.restTemplate.getForEntity("/composers/{id}", Person.class, 42);
// We are only validating the request. The response is mocked out.
// person.getName().equals("Ludwig van Beethoven")
// person.getDouble().equals(1.6035)
this.restTemplate.getForEntity("/composers/{id}", Person.class, 42);
this.restTemplate.getForEntity("/composers/{id}", Person.class, 42);
this.restTemplate.getForEntity("/composers/{id}", Person.class, 42);
this.restTemplate.getForEntity("/composers/{id}", Person.class, 42);
this.mockServer.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void verify() {
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("1", MediaType.TEXT_PLAIN));
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("2", MediaType.TEXT_PLAIN));
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("4", MediaType.TEXT_PLAIN));
this.mockServer.expect(requestTo("/number")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("8", MediaType.TEXT_PLAIN));
@SuppressWarnings("unused")
ListenableFuture<ResponseEntity<String>> result = this.restTemplate.getForEntity("/number", String.class);
// result == "1"
result = this.restTemplate.getForEntity("/number", String.class);
// result == "2"
try {
this.mockServer.verify();
}
catch (AssertionError error) {
assertTrue(error.getMessage(), error.getMessage().contains("2 unsatisfied expectation(s)"));
}
}
内容来源于网络,如有侵权,请联系作者删除!