@Override public MockRestServiceServer build() { if (this.ignoreExpectOrder) { return build(new UnorderedRequestExpectationManager()); } else { return build(new SimpleRequestExpectationManager()); } }
@Override public RequestExpectation matchRequest(ClientHttpRequest request) throws IOException { RequestExpectation expectation = this.remainingExpectations.findExpectation(request); if (expectation == null) { throw createUnexpectedRequestError(request); } this.remainingExpectations.update(expectation); return expectation; }
@Override protected void afterExpectationsDeclared() { this.remainingExpectations.addAllExpectations(getExpectations()); }
@Test public void repeatedRequests() throws Exception { this.manager.expectRequest(twice(), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess()); this.manager.expectRequest(twice(), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess()); this.manager.validateRequest(createRequest(GET, "/bar")); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.validateRequest(createRequest(GET, "/bar")); this.manager.verify(); }
@Test public void repeatedRequestsTooMany() throws Exception { this.manager.expectRequest(max(2), requestTo("/foo")).andExpect(method(GET)).andRespond(withSuccess()); this.manager.expectRequest(max(2), requestTo("/bar")).andExpect(method(GET)).andRespond(withSuccess()); this.thrown.expectMessage("No further requests expected: HTTP GET /foo\n" + "4 request(s) executed:\n" + "GET /bar\n" + "GET /foo\n" + "GET /bar\n" + "GET /foo\n"); 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, "/foo")); }
@Test public void zeroExpectedRequests() throws Exception { this.manager.verify(); }
@Test public void unexpectedRequest() throws Exception { try { this.manager.validateRequest(createRequest(GET, "/foo")); } catch (AssertionError error) { assertEquals("No further requests expected: HTTP GET /foo\n" + "0 request(s) executed.\n", error.getMessage()); } }
@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 /bar\n" + "GET /foo\n" + "GET /foo\n"); this.manager.validateRequest(createRequest(GET, "/bar")); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.verify(); }
@Test public void multipleRequests() 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, "/bar")); this.manager.validateRequest(createRequest(GET, "/foo")); this.manager.verify(); }
@Override public RequestExpectation matchRequest(ClientHttpRequest request) throws IOException { RequestExpectation expectation = this.remainingExpectations.findExpectation(request); if (expectation == null) { throw createUnexpectedRequestError(request); } this.remainingExpectations.update(expectation); return expectation; }
@Override public MockRestServiceServer build() { if (this.ignoreExpectOrder) { return build(new UnorderedRequestExpectationManager()); } else { return build(new SimpleRequestExpectationManager()); } }
@Override protected void afterExpectationsDeclared() { this.remainingExpectations.addAllExpectations(getExpectations()); }
@Override public ClientHttpResponse validateRequestInternal(ClientHttpRequest request) throws IOException { RequestExpectation expectation = this.remainingExpectations.findExpectation(request); if (expectation != null) { ClientHttpResponse response = expectation.createResponse(request); this.remainingExpectations.update(expectation); return response; } throw createUnexpectedRequestError(request); }
@Override public MockRestServiceServer build() { if (this.ignoreExpectOrder) { return build(new UnorderedRequestExpectationManager()); } else { return build(new SimpleRequestExpectationManager()); } }
@Override protected void afterExpectationsDeclared() { this.remainingExpectations.updateAll(getExpectations()); }