|
|
@ -142,7 +142,7 @@ public class MockHttpServletRequestBuilder |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Add a request parameter to the {@link MockHttpServletRequest}. |
|
|
|
* Add a request parameter to the {@link MockHttpServletRequest}. |
|
|
|
* If called more than once, the new values are added. |
|
|
|
* <p>If called more than once, new values get added to existing ones. |
|
|
|
* @param name the parameter name |
|
|
|
* @param name the parameter name |
|
|
|
* @param values one or more values |
|
|
|
* @param values one or more values |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -152,10 +152,11 @@ public class MockHttpServletRequestBuilder |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Add request parameters to the {@link MockHttpServletRequest} for example |
|
|
|
* Add a map of request parameters to the {@link MockHttpServletRequest}, |
|
|
|
* such as when testing a form submission. If called more than once, the new |
|
|
|
* for example when testing a form submission. |
|
|
|
* values are added. |
|
|
|
* <p>If called more than once, new values get added to existing ones. |
|
|
|
* @param params the parameters to add |
|
|
|
* @param params the parameters to add |
|
|
|
|
|
|
|
* @since 4.2.4 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MockHttpServletRequestBuilder params(MultiValueMap<String, String> params) { |
|
|
|
public MockHttpServletRequestBuilder params(MultiValueMap<String, String> params) { |
|
|
|
for (String name : params.keySet()) { |
|
|
|
for (String name : params.keySet()) { |
|
|
@ -300,7 +301,7 @@ public class MockHttpServletRequestBuilder |
|
|
|
* @param value the attribute value |
|
|
|
* @param value the attribute value |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MockHttpServletRequestBuilder requestAttr(String name, Object value) { |
|
|
|
public MockHttpServletRequestBuilder requestAttr(String name, Object value) { |
|
|
|
addAttributeToMap(this.attributes, name, value); |
|
|
|
addToMap(this.attributes, name, value); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -310,7 +311,7 @@ public class MockHttpServletRequestBuilder |
|
|
|
* @param value the session attribute value |
|
|
|
* @param value the session attribute value |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MockHttpServletRequestBuilder sessionAttr(String name, Object value) { |
|
|
|
public MockHttpServletRequestBuilder sessionAttr(String name, Object value) { |
|
|
|
addAttributeToMap(this.sessionAttributes, name, value); |
|
|
|
addToMap(this.sessionAttributes, name, value); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -332,7 +333,7 @@ public class MockHttpServletRequestBuilder |
|
|
|
* @param value the flash attribute value |
|
|
|
* @param value the flash attribute value |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MockHttpServletRequestBuilder flashAttr(String name, Object value) { |
|
|
|
public MockHttpServletRequestBuilder flashAttr(String name, Object value) { |
|
|
|
addAttributeToMap(this.flashAttributes, name, value); |
|
|
|
addToMap(this.flashAttributes, name, value); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -712,19 +713,19 @@ public class MockHttpServletRequestBuilder |
|
|
|
return request; |
|
|
|
return request; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void addToMap(Map<String, Object> map, String name, Object value) { |
|
|
|
|
|
|
|
Assert.hasLength(name, "'name' must not be empty"); |
|
|
|
|
|
|
|
Assert.notNull(value, "'value' must not be null"); |
|
|
|
|
|
|
|
map.put(name, value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static <T> void addToMultiValueMap(MultiValueMap<String, T> map, String name, T[] values) { |
|
|
|
private static <T> void addToMultiValueMap(MultiValueMap<String, T> map, String name, T[] values) { |
|
|
|
Assert.hasLength(name, "'name' must not be empty"); |
|
|
|
Assert.hasLength(name, "'name' must not be empty"); |
|
|
|
Assert.notNull(values, "'values' is required"); |
|
|
|
|
|
|
|
Assert.notEmpty(values, "'values' must not be empty"); |
|
|
|
Assert.notEmpty(values, "'values' must not be empty"); |
|
|
|
for (T value : values) { |
|
|
|
for (T value : values) { |
|
|
|
map.add(name, value); |
|
|
|
map.add(name, value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void addAttributeToMap(Map<String, Object> map, String name, Object value) { |
|
|
|
|
|
|
|
Assert.hasLength(name, "'name' must not be empty"); |
|
|
|
|
|
|
|
Assert.notNull(value, "'value' must not be null"); |
|
|
|
|
|
|
|
map.put(name, value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|