|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -25,26 +25,22 @@ import org.junit.rules.ExpectedException; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.client.ClientHttpRequest; |
|
|
|
import org.springframework.http.client.ClientHttpRequest; |
|
|
|
|
|
|
|
import org.springframework.mock.http.client.MockClientHttpRequest; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.springframework.http.HttpMethod.GET; |
|
|
|
import static org.springframework.http.HttpMethod.*; |
|
|
|
import static org.springframework.http.HttpMethod.POST; |
|
|
|
import static org.springframework.test.web.client.ExpectedCount.*; |
|
|
|
import static org.springframework.test.web.client.ExpectedCount.max; |
|
|
|
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*; |
|
|
|
import static org.springframework.test.web.client.ExpectedCount.min; |
|
|
|
import static org.springframework.test.web.client.response.MockRestResponseCreators.*; |
|
|
|
import static org.springframework.test.web.client.ExpectedCount.once; |
|
|
|
|
|
|
|
import static org.springframework.test.web.client.ExpectedCount.times; |
|
|
|
|
|
|
|
import static org.springframework.test.web.client.ExpectedCount.twice; |
|
|
|
|
|
|
|
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; |
|
|
|
|
|
|
|
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; |
|
|
|
|
|
|
|
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unit tests for {@link SimpleRequestExpectationManager}. |
|
|
|
* Unit tests for {@link SimpleRequestExpectationManager}. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class SimpleRequestExpectationManagerTests { |
|
|
|
public class SimpleRequestExpectationManagerTests { |
|
|
|
|
|
|
|
|
|
|
|
private SimpleRequestExpectationManager manager = new SimpleRequestExpectationManager(); |
|
|
|
private final SimpleRequestExpectationManager manager = new SimpleRequestExpectationManager(); |
|
|
|
|
|
|
|
|
|
|
|
@Rule |
|
|
|
@Rule |
|
|
|
public ExpectedException thrown = ExpectedException.none(); |
|
|
|
public ExpectedException thrown = ExpectedException.none(); |
|
|
|
@ -162,11 +158,21 @@ public class SimpleRequestExpectationManagerTests { |
|
|
|
this.manager.validateRequest(createRequest(POST, "/foo")); |
|
|
|
this.manager.validateRequest(createRequest(POST, "/foo")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-15672
|
|
|
|
|
|
|
|
public void sequentialRequestsWithDifferentCount() throws Exception { |
|
|
|
|
|
|
|
this.manager.expectRequest(times(2), 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, "/foo")); |
|
|
|
|
|
|
|
this.manager.validateRequest(createRequest(GET, "/bar")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
private ClientHttpRequest createRequest(HttpMethod method, String url) { |
|
|
|
private ClientHttpRequest createRequest(HttpMethod method, String url) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return new org.springframework.mock.http.client.MockAsyncClientHttpRequest(method, new URI(url)); |
|
|
|
return new MockClientHttpRequest(method, new URI(url)); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (URISyntaxException ex) { |
|
|
|
catch (URISyntaxException ex) { |
|
|
|
throw new IllegalStateException(ex); |
|
|
|
throw new IllegalStateException(ex); |
|
|
|
|