diff --git a/spring-test-mvc/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java b/spring-test-mvc/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java index 4d708ddd18..0abfd6d221 100644 --- a/spring-test-mvc/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java +++ b/spring-test-mvc/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.test.web.client; import java.io.IOException; @@ -39,7 +40,7 @@ import org.springframework.web.client.support.RestGatewaySupport; * actual running server. * *
Below is an example: - *
+ *
* RestTemplate restTemplate = new RestTemplate()
* MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
*
@@ -95,28 +96,24 @@ public class MockRestServiceServer {
private MockRestServiceServer() {
}
+
/**
* Create a {@code MockRestServiceServer} and set up the given
* {@code RestTemplate} with a mock {@link ClientHttpRequestFactory}.
- *
* @param restTemplate the RestTemplate to set up for mock testing
* @return the created mock server
*/
public static MockRestServiceServer createServer(RestTemplate restTemplate) {
Assert.notNull(restTemplate, "'restTemplate' must not be null");
-
MockRestServiceServer mockServer = new MockRestServiceServer();
RequestMatcherClientHttpRequestFactory factory = mockServer.new RequestMatcherClientHttpRequestFactory();
-
restTemplate.setRequestFactory(factory);
-
return mockServer;
}
/**
* Create a {@code MockRestServiceServer} and set up the given
* {@code RestGatewaySupport} with a mock {@link ClientHttpRequestFactory}.
- *
* @param restGateway the REST gateway to set up for mock testing
* @return the created mock server
*/
@@ -125,14 +122,12 @@ public class MockRestServiceServer {
return createServer(restGateway.getRestTemplate());
}
+
/**
* Set up a new HTTP request expectation. The returned {@link ResponseActions}
* is used to set up further expectations and to define the response.
- *
- * This method may be invoked multiple times before starting the test, i.e.
- * before using the {@code RestTemplate}, to set up expectations for multiple
- * requests.
- *
+ *
This method may be invoked multiple times before starting the test, i.e. before
+ * using the {@code RestTemplate}, to set up expectations for multiple requests.
* @param requestMatcher a request expectation, see {@link MockRestRequestMatchers}
* @return used to set up further expectations or to define a response
*/
@@ -146,7 +141,6 @@ public class MockRestServiceServer {
/**
* Verify that all expected requests set up via
* {@link #expect(RequestMatcher)} were indeed performed.
- *
* @throws AssertionError when some expectations were not met
*/
public void verify() {
@@ -158,7 +152,6 @@ public class MockRestServiceServer {
private String getVerifyMessage() {
StringBuilder sb = new StringBuilder("Further request(s) expected\n");
-
if (this.actualRequests.size() > 0) {
sb.append("The following ");
}
@@ -171,7 +164,6 @@ public class MockRestServiceServer {
sb.append(request.toString()).append("\n");
}
}
-
return sb.toString();
}
@@ -192,7 +184,7 @@ public class MockRestServiceServer {
this.requestIterator = MockRestServiceServer.this.expectedRequests.iterator();
}
if (!this.requestIterator.hasNext()) {
- throw new AssertionError("No further requests expected");
+ throw new AssertionError("No further requests expected: HTTP " + httpMethod + " " + uri);
}
RequestMatcherClientHttpRequest request = this.requestIterator.next();
@@ -200,7 +192,6 @@ public class MockRestServiceServer {
request.setMethod(httpMethod);
MockRestServiceServer.this.actualRequests.add(request);
-
return request;
}
}
diff --git a/spring-test-mvc/src/test/java/org/springframework/test/web/client/MockClientHttpRequestFactoryTests.java b/spring-test-mvc/src/test/java/org/springframework/test/web/client/MockClientHttpRequestFactoryTests.java
index ef4b4957a6..dfd3a7147e 100644
--- a/spring-test-mvc/src/test/java/org/springframework/test/web/client/MockClientHttpRequestFactoryTests.java
+++ b/spring-test-mvc/src/test/java/org/springframework/test/web/client/MockClientHttpRequestFactoryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,25 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.test.web.client;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.springframework.test.web.client.match.MockRestRequestMatchers.anything;
+package org.springframework.test.web.client;
import java.net.URI;
import org.junit.Before;
import org.junit.Test;
+
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;
-import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestTemplate;
+import static org.junit.Assert.*;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
+
/**
- * Tests for {@link MockClientHttpRequestFactory}.
+ * Tests for
+ * {@link org.springframework.test.web.client.MockMvcClientHttpRequestFactory}.
*
* @author Rossen Stoyanchev
*/
@@ -66,7 +66,7 @@ public class MockClientHttpRequestFactoryTests {
this.factory.createRequest(new URI("/foo"), HttpMethod.GET);
}
catch (AssertionError error) {
- assertEquals("No further requests expected", error.getMessage());
+ assertEquals("No further requests expected: HTTP GET /foo", error.getMessage());
}
}