|
17 | 17 | package org.springframework.web.servlet.view.xml;
|
18 | 18 |
|
19 | 19 | import java.util.HashMap;
|
| 20 | +import java.util.LinkedHashMap; |
20 | 21 | import java.util.Map;
|
21 | 22 | import javax.xml.transform.stream.StreamResult;
|
22 | 23 |
|
|
26 | 27 | import org.springframework.mock.web.test.MockHttpServletRequest;
|
27 | 28 | import org.springframework.mock.web.test.MockHttpServletResponse;
|
28 | 29 | import org.springframework.oxm.Marshaller;
|
| 30 | +import org.springframework.validation.BeanPropertyBindingResult; |
| 31 | +import org.springframework.validation.BindingResult; |
29 | 32 |
|
30 | 33 | import static org.junit.Assert.*;
|
31 | 34 | import static org.mockito.BDDMockito.*;
|
|
35 | 38 | */
|
36 | 39 | public class MarshallingViewTests {
|
37 | 40 |
|
| 41 | + private Marshaller marshallerMock; |
| 42 | + |
38 | 43 | private MarshallingView view;
|
39 | 44 |
|
40 |
| - private Marshaller marshallerMock; |
41 | 45 |
|
42 | 46 | @Before
|
43 | 47 | public void createView() throws Exception {
|
44 | 48 | marshallerMock = mock(Marshaller.class);
|
45 | 49 | view = new MarshallingView(marshallerMock);
|
46 | 50 | }
|
47 | 51 |
|
| 52 | + |
48 | 53 | @Test
|
49 | 54 | public void getContentType() {
|
50 | 55 | assertEquals("Invalid content type", "application/xml", view.getContentType());
|
@@ -159,6 +164,26 @@ public void renderNoModelKey() throws Exception {
|
159 | 164 | verify(marshallerMock).marshal(eq(toBeMarshalled), isA(StreamResult.class));
|
160 | 165 | }
|
161 | 166 |
|
| 167 | + @Test |
| 168 | + public void renderNoModelKeyAndBindingResultFirst() throws Exception { |
| 169 | + Object toBeMarshalled = new Object(); |
| 170 | + String modelKey = "key"; |
| 171 | + Map<String, Object> model = new LinkedHashMap<String, Object>(); |
| 172 | + model.put(BindingResult.MODEL_KEY_PREFIX + modelKey, new BeanPropertyBindingResult(toBeMarshalled, modelKey)); |
| 173 | + model.put(modelKey, toBeMarshalled); |
| 174 | + |
| 175 | + MockHttpServletRequest request = new MockHttpServletRequest(); |
| 176 | + MockHttpServletResponse response = new MockHttpServletResponse(); |
| 177 | + |
| 178 | + given(marshallerMock.supports(BeanPropertyBindingResult.class)).willReturn(true); |
| 179 | + given(marshallerMock.supports(Object.class)).willReturn(true); |
| 180 | + |
| 181 | + view.render(model, request, response); |
| 182 | + assertEquals("Invalid content type", "application/xml", response.getContentType()); |
| 183 | + assertEquals("Invalid content length", 0, response.getContentLength()); |
| 184 | + verify(marshallerMock).marshal(eq(toBeMarshalled), isA(StreamResult.class)); |
| 185 | + } |
| 186 | + |
162 | 187 | @Test
|
163 | 188 | public void testRenderUnsupportedModel() throws Exception {
|
164 | 189 | Object toBeMarshalled = new Object();
|
|
0 commit comments