@Test public void zeroExpectedRequests() throws Exception { this.manager.verify(); }
@Test // SPR-16132 public void sequentialRequestsWithFirstFailing() throws Exception { this.manager.expectRequest(once(), requestTo("/foo")). andExpect(method(GET)).andRespond(request -> { throw new SocketException("pseudo network error"); }); this.manager.expectRequest(once(), requestTo("/handle-error")). andExpect(method(POST)).andRespond(withSuccess()); try { this.manager.validateRequest(createRequest(GET, "/foo")); fail("Expected SocketException"); } catch (SocketException ex) { // expected } this.manager.validateRequest(createRequest(POST, "/handle-error")); this.manager.verify(); }
@Test public void sequentialRequestsTooFew() throws Exception { this.manager.expectRequest(min(1), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess()); this.manager.expectRequest(min(1), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess()); this.thrown.expectMessage("Further request(s) expected leaving 1 unsatisfied expectation(s).\n" + "1 request(s) executed:\nGET /foo\n"); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.verify(); }
@Test public void sequentialRequests() throws Exception { this.manager.expectRequest(once(), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess()); this.manager.expectRequest(once(), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess()); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.validateRequest(createRequest(GET, "/bar")); this.manager.verify(); }
@Test public void repeatedRequestsTooFew() throws Exception { this.manager.expectRequest(min(2), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess()); this.manager.expectRequest(min(2), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess()); this.thrown.expectMessage("3 request(s) executed:\n" + "GET /foo\n" + "GET /bar\n" + "GET /foo\n"); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.validateRequest(createRequest(GET, "/bar")); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.verify(); }
@Test public void repeatedRequests() throws Exception { this.manager.expectRequest(times(3), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess()); this.manager.expectRequest(times(3), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess()); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.validateRequest(createRequest(GET, "/bar")); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.validateRequest(createRequest(GET, "/bar")); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.validateRequest(createRequest(GET, "/bar")); this.manager.verify(); }