Allow merge of MockMultipart- w/ Mock- request builder
Issue: SPR-10280
This commit is contained in:
parent
b47d97c23a
commit
eda53ec1d8
|
@ -84,15 +84,16 @@ public class MockMultipartHttpServletRequestBuilder extends MockHttpServletReque
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if (!(parent instanceof MockMultipartHttpServletRequestBuilder)) {
|
if (parent instanceof MockHttpServletRequestBuilder) {
|
||||||
|
super.merge(parent);
|
||||||
|
if (parent instanceof MockMultipartHttpServletRequestBuilder) {
|
||||||
|
MockMultipartHttpServletRequestBuilder parentBuilder = (MockMultipartHttpServletRequestBuilder) parent;
|
||||||
|
this.files.addAll(parentBuilder.files);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
throw new IllegalArgumentException("Cannot merge with [" + parent.getClass().getName() + "]");
|
throw new IllegalArgumentException("Cannot merge with [" + parent.getClass().getName() + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
super.merge(parent);
|
|
||||||
|
|
||||||
MockMultipartHttpServletRequestBuilder parentBuilder = (MockMultipartHttpServletRequestBuilder) parent;
|
|
||||||
this.files.addAll(parentBuilder.files);
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2004-2013 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.test.web.servlet.request;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
import org.springframework.mock.web.MockServletContext;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test fixture for {@link MockMultipartHttpServletRequestBuilder}.
|
||||||
|
*
|
||||||
|
* @author Rossen Stoyanchev
|
||||||
|
*/
|
||||||
|
public class MockMultipartHttpServletRequestBuilderTests {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
MockHttpServletRequestBuilder parent = new MockHttpServletRequestBuilder(HttpMethod.GET, "/");
|
||||||
|
parent.characterEncoding("UTF-8");
|
||||||
|
Object result = new MockMultipartHttpServletRequestBuilder("/fileUpload").merge(parent);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(MockMultipartHttpServletRequestBuilder.class, result.getClass());
|
||||||
|
|
||||||
|
MockMultipartHttpServletRequestBuilder builder = (MockMultipartHttpServletRequestBuilder) result;
|
||||||
|
MockHttpServletRequest request = builder.buildRequest(new MockServletContext());
|
||||||
|
|
||||||
|
assertEquals("UTF-8", request.getCharacterEncoding());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue