|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
|
* Copyright 2002-2019 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. |
|
|
|
@ -62,7 +62,7 @@ public abstract class MockRestRequestMatchers { |
|
|
|
|
* @param method the HTTP method |
|
|
|
|
* @return the request matcher |
|
|
|
|
*/ |
|
|
|
|
public static RequestMatcher method(final HttpMethod method) { |
|
|
|
|
public static RequestMatcher method(HttpMethod method) { |
|
|
|
|
Assert.notNull(method, "'method' must not be null"); |
|
|
|
|
return request -> assertEquals("Unexpected HttpMethod", method, request.getMethod()); |
|
|
|
|
} |
|
|
|
@ -72,7 +72,7 @@ public abstract class MockRestRequestMatchers { |
|
|
|
|
* @param matcher the String matcher for the expected URI |
|
|
|
|
* @return the request matcher |
|
|
|
|
*/ |
|
|
|
|
public static RequestMatcher requestTo(final Matcher<String> matcher) { |
|
|
|
|
public static RequestMatcher requestTo(Matcher<String> matcher) { |
|
|
|
|
Assert.notNull(matcher, "'matcher' must not be null"); |
|
|
|
|
return request -> assertThat("Request URI", request.getURI().toString(), matcher); |
|
|
|
|
} |
|
|
|
@ -82,7 +82,7 @@ public abstract class MockRestRequestMatchers { |
|
|
|
|
* @param expectedUri the expected URI |
|
|
|
|
* @return the request matcher |
|
|
|
|
*/ |
|
|
|
|
public static RequestMatcher requestTo(final String expectedUri) { |
|
|
|
|
public static RequestMatcher requestTo(String expectedUri) { |
|
|
|
|
Assert.notNull(expectedUri, "'uri' must not be null"); |
|
|
|
|
return request -> assertEquals("Request URI", expectedUri, request.getURI().toString()); |
|
|
|
|
} |
|
|
|
@ -95,7 +95,7 @@ public abstract class MockRestRequestMatchers { |
|
|
|
|
* @param uriVars zero or more URI variables to populate the expected URI |
|
|
|
|
* @return the request matcher |
|
|
|
|
*/ |
|
|
|
|
public static RequestMatcher requestToUriTemplate(final String expectedUri, final Object... uriVars) { |
|
|
|
|
public static RequestMatcher requestToUriTemplate(String expectedUri, Object... uriVars) { |
|
|
|
|
Assert.notNull(expectedUri, "'uri' must not be null"); |
|
|
|
|
URI uri = UriComponentsBuilder.fromUriString(expectedUri).buildAndExpand(uriVars).encode().toUri(); |
|
|
|
|
return requestTo(uri); |
|
|
|
@ -106,7 +106,7 @@ public abstract class MockRestRequestMatchers { |
|
|
|
|
* @param uri the expected URI |
|
|
|
|
* @return the request matcher |
|
|
|
|
*/ |
|
|
|
|
public static RequestMatcher requestTo(final URI uri) { |
|
|
|
|
public static RequestMatcher requestTo(URI uri) { |
|
|
|
|
Assert.notNull(uri, "'uri' must not be null"); |
|
|
|
|
return request -> assertEquals("Unexpected request", uri, request.getURI()); |
|
|
|
|
} |
|
|
|
@ -115,7 +115,7 @@ public abstract class MockRestRequestMatchers { |
|
|
|
|
* Assert request query parameter values with the given Hamcrest matcher(s). |
|
|
|
|
*/ |
|
|
|
|
@SafeVarargs |
|
|
|
|
public static RequestMatcher queryParam(final String name, final Matcher<? super String>... matchers) { |
|
|
|
|
public static RequestMatcher queryParam(String name, Matcher<? super String>... matchers) { |
|
|
|
|
return request -> { |
|
|
|
|
MultiValueMap<String, String> params = getQueryParams(request); |
|
|
|
|
assertValueCount("query param", name, params, matchers.length); |
|
|
|
@ -128,7 +128,7 @@ public abstract class MockRestRequestMatchers { |
|
|
|
|
/** |
|
|
|
|
* Assert request query parameter values. |
|
|
|
|
*/ |
|
|
|
|
public static RequestMatcher queryParam(final String name, final String... expectedValues) { |
|
|
|
|
public static RequestMatcher queryParam(String name, String... expectedValues) { |
|
|
|
|
return request -> { |
|
|
|
|
MultiValueMap<String, String> params = getQueryParams(request); |
|
|
|
|
assertValueCount("query param", name, params, expectedValues.length); |
|
|
|
@ -143,7 +143,7 @@ public abstract class MockRestRequestMatchers { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void assertValueCount( |
|
|
|
|
String valueType, final String name, MultiValueMap<String, String> map, int count) { |
|
|
|
|
String valueType, String name, MultiValueMap<String, String> map, int count) { |
|
|
|
|
|
|
|
|
|
List<String> values = map.get(name); |
|
|
|
|
String message = "Expected " + valueType + " <" + name + ">"; |
|
|
|
@ -159,7 +159,7 @@ public abstract class MockRestRequestMatchers { |
|
|
|
|
* Assert request header values with the given Hamcrest matcher(s). |
|
|
|
|
*/ |
|
|
|
|
@SafeVarargs |
|
|
|
|
public static RequestMatcher header(final String name, final Matcher<? super String>... matchers) { |
|
|
|
|
public static RequestMatcher header(String name, Matcher<? super String>... matchers) { |
|
|
|
|
return request -> { |
|
|
|
|
assertValueCount("header", name, request.getHeaders(), matchers.length); |
|
|
|
|
List<String> headerValues = request.getHeaders().get(name); |
|
|
|
@ -173,7 +173,7 @@ public abstract class MockRestRequestMatchers { |
|
|
|
|
/** |
|
|
|
|
* Assert request header values. |
|
|
|
|
*/ |
|
|
|
|
public static RequestMatcher header(final String name, final String... expectedValues) { |
|
|
|
|
public static RequestMatcher header(String name, String... expectedValues) { |
|
|
|
|
return request -> { |
|
|
|
|
assertValueCount("header", name, request.getHeaders(), expectedValues.length); |
|
|
|
|
List<String> headerValues = request.getHeaders().get(name); |
|
|
|
|