|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
|
* Copyright 2002-2015 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. |
|
|
|
@ -28,13 +28,15 @@ import org.springframework.util.AntPathMatcher;
@@ -28,13 +28,15 @@ import org.springframework.util.AntPathMatcher;
|
|
|
|
|
import static org.springframework.test.util.AssertionErrors.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Static, factory methods for {@link ResultMatcher}-based result actions. |
|
|
|
|
* Static factory methods for {@link ResultMatcher}-based result actions. |
|
|
|
|
* |
|
|
|
|
* <p><strong>Eclipse users:</strong> consider adding this class as a Java editor |
|
|
|
|
* favorite. To navigate, open the Preferences and type "favorites". |
|
|
|
|
* <h3>Eclipse Users</h3> |
|
|
|
|
* <p>Consider adding this class as a Java editor favorite. To navigate to |
|
|
|
|
* this setting, open the Preferences and type "favorites". |
|
|
|
|
* |
|
|
|
|
* @author Rossen Stoyanchev |
|
|
|
|
* @author Brian Clozel |
|
|
|
|
* @author Sam Brannen |
|
|
|
|
* @since 3.2 |
|
|
|
|
*/ |
|
|
|
|
public abstract class MockMvcResultMatchers { |
|
|
|
@ -42,9 +44,6 @@ public abstract class MockMvcResultMatchers {
@@ -42,9 +44,6 @@ public abstract class MockMvcResultMatchers {
|
|
|
|
|
private static final AntPathMatcher pathMatcher = new AntPathMatcher(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MockMvcResultMatchers() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Access to request-related assertions. |
|
|
|
|
*/ |
|
|
|
@ -82,12 +81,11 @@ public abstract class MockMvcResultMatchers {
@@ -82,12 +81,11 @@ public abstract class MockMvcResultMatchers {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Asserts the request was forwarded to the given URL. |
|
|
|
|
* This methods accepts only exact matches. |
|
|
|
|
* <p>This methods accepts only exact matches. |
|
|
|
|
* @param expectedUrl the exact URL expected |
|
|
|
|
*/ |
|
|
|
|
public static ResultMatcher forwardedUrl(final String expectedUrl) { |
|
|
|
|
return new ResultMatcher() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void match(MvcResult result) { |
|
|
|
|
assertEquals("Forwarded URL", expectedUrl, result.getResponse().getForwardedUrl()); |
|
|
|
@ -97,14 +95,14 @@ public abstract class MockMvcResultMatchers {
@@ -97,14 +95,14 @@ public abstract class MockMvcResultMatchers {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Asserts the request was forwarded to the given URL. |
|
|
|
|
* This methods accepts {@link org.springframework.util.AntPathMatcher} expressions. |
|
|
|
|
* <p>This methods accepts {@link org.springframework.util.AntPathMatcher} |
|
|
|
|
* expressions. |
|
|
|
|
* @param urlPattern an AntPath expression to match against |
|
|
|
|
* @see org.springframework.util.AntPathMatcher |
|
|
|
|
* @since 4.0 |
|
|
|
|
* @see org.springframework.util.AntPathMatcher |
|
|
|
|
*/ |
|
|
|
|
public static ResultMatcher forwardedUrlPattern(final String urlPattern) { |
|
|
|
|
return new ResultMatcher() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void match(MvcResult result) { |
|
|
|
|
assertTrue("AntPath expression", pathMatcher.isPattern(urlPattern)); |
|
|
|
@ -116,12 +114,11 @@ public abstract class MockMvcResultMatchers {
@@ -116,12 +114,11 @@ public abstract class MockMvcResultMatchers {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Asserts the request was redirected to the given URL. |
|
|
|
|
* This methods accepts only exact matches. |
|
|
|
|
* <p>This methods accepts only exact matches. |
|
|
|
|
* @param expectedUrl the exact URL expected |
|
|
|
|
*/ |
|
|
|
|
public static ResultMatcher redirectedUrl(final String expectedUrl) { |
|
|
|
|
return new ResultMatcher() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void match(MvcResult result) { |
|
|
|
|
assertEquals("Redirected URL", expectedUrl, result.getResponse().getRedirectedUrl()); |
|
|
|
@ -131,14 +128,14 @@ public abstract class MockMvcResultMatchers {
@@ -131,14 +128,14 @@ public abstract class MockMvcResultMatchers {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Asserts the request was redirected to the given URL. |
|
|
|
|
* This methods accepts {@link org.springframework.util.AntPathMatcher} expressions. |
|
|
|
|
* <p>This method accepts {@link org.springframework.util.AntPathMatcher} |
|
|
|
|
* expressions. |
|
|
|
|
* @param expectedUrl an AntPath expression to match against |
|
|
|
|
* @see org.springframework.util.AntPathMatcher |
|
|
|
|
* @since 4.0 |
|
|
|
|
*/ |
|
|
|
|
public static ResultMatcher redirectedUrlPattern(final String expectedUrl) { |
|
|
|
|
return new ResultMatcher() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void match(MvcResult result) { |
|
|
|
|
assertTrue("AntPath expression",pathMatcher.isPattern(expectedUrl)); |
|
|
|
@ -170,13 +167,13 @@ public abstract class MockMvcResultMatchers {
@@ -170,13 +167,13 @@ public abstract class MockMvcResultMatchers {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Access to response body assertions using a <a |
|
|
|
|
* href="http://goessner.net/articles/JsonPath/">JSONPath</a> expression to |
|
|
|
|
* inspect a specific subset of the body. The JSON path expression can be a |
|
|
|
|
* parameterized string using formatting specifiers as defined in |
|
|
|
|
* Access to response body assertions using a |
|
|
|
|
* <a href="https://github.com/jayway/JsonPath">JsonPath</a> expression |
|
|
|
|
* to inspect a specific subset of the body. |
|
|
|
|
* <p>The JSON path expression can be a parameterized string using |
|
|
|
|
* formatting specifiers as defined in |
|
|
|
|
* {@link String#format(String, Object...)}. |
|
|
|
|
* |
|
|
|
|
* @param expression the JSON path optionally parameterized with arguments |
|
|
|
|
* @param expression the JSON path expression, optionally parameterized with arguments |
|
|
|
|
* @param args arguments to parameterize the JSON path expression with |
|
|
|
|
*/ |
|
|
|
|
public static JsonPathResultMatchers jsonPath(String expression, Object ... args) { |
|
|
|
@ -184,11 +181,10 @@ public abstract class MockMvcResultMatchers {
@@ -184,11 +181,10 @@ public abstract class MockMvcResultMatchers {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Access to response body assertions using a <a |
|
|
|
|
* href="http://goessner.net/articles/JsonPath/">JSONPath</a> expression to |
|
|
|
|
* inspect a specific subset of the body and a Hamcrest match for asserting |
|
|
|
|
* the value found at the JSON path. |
|
|
|
|
* |
|
|
|
|
* Access to response body assertions using a |
|
|
|
|
* <a href="https://github.com/jayway/JsonPath">JsonPath</a> expression |
|
|
|
|
* to inspect a specific subset of the body and a Hamcrest matcher for |
|
|
|
|
* asserting the value found at the JSON path. |
|
|
|
|
* @param expression the JSON path expression |
|
|
|
|
* @param matcher a matcher for the value expected at the JSON path |
|
|
|
|
*/ |
|
|
|
@ -197,12 +193,11 @@ public abstract class MockMvcResultMatchers {
@@ -197,12 +193,11 @@ public abstract class MockMvcResultMatchers {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Access to response body assertions using an XPath to inspect a specific |
|
|
|
|
* subset of the body. The XPath expression can be a parameterized string |
|
|
|
|
* using formatting specifiers as defined in |
|
|
|
|
* {@link String#format(String, Object...)}. |
|
|
|
|
* |
|
|
|
|
* @param expression the XPath optionally parameterized with arguments |
|
|
|
|
* Access to response body assertions using an XPath expression to |
|
|
|
|
* inspect a specific subset of the body. |
|
|
|
|
* <p>The XPath expression can be a parameterized string using formatting |
|
|
|
|
* specifiers as defined in {@link String#format(String, Object...)}. |
|
|
|
|
* @param expression the XPath expression, optionally parameterized with arguments |
|
|
|
|
* @param args arguments to parameterize the XPath expression with |
|
|
|
|
*/ |
|
|
|
|
public static XpathResultMatchers xpath(String expression, Object... args) throws XPathExpressionException { |
|
|
|
@ -210,12 +205,11 @@ public abstract class MockMvcResultMatchers {
@@ -210,12 +205,11 @@ public abstract class MockMvcResultMatchers {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Access to response body assertions using an XPath to inspect a specific |
|
|
|
|
* subset of the body. The XPath expression can be a parameterized string |
|
|
|
|
* using formatting specifiers as defined in |
|
|
|
|
* {@link String#format(String, Object...)}. |
|
|
|
|
* |
|
|
|
|
* @param expression the XPath optionally parameterized with arguments |
|
|
|
|
* Access to response body assertions using an XPath expression to |
|
|
|
|
* inspect a specific subset of the body. |
|
|
|
|
* <p>The XPath expression can be a parameterized string using formatting |
|
|
|
|
* specifiers as defined in {@link String#format(String, Object...)}. |
|
|
|
|
* @param expression the XPath expression, optionally parameterized with arguments |
|
|
|
|
* @param namespaces namespaces referenced in the XPath expression |
|
|
|
|
* @param args arguments to parameterize the XPath expression with |
|
|
|
|
*/ |
|
|
|
|