|
|
|
|
@ -17,6 +17,7 @@
@@ -17,6 +17,7 @@
|
|
|
|
|
package org.springframework.web.servlet.view.xml; |
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import javax.xml.transform.stream.StreamResult; |
|
|
|
|
|
|
|
|
|
@ -26,6 +27,8 @@ import org.junit.Test;
@@ -26,6 +27,8 @@ import org.junit.Test;
|
|
|
|
|
import org.springframework.mock.web.test.MockHttpServletRequest; |
|
|
|
|
import org.springframework.mock.web.test.MockHttpServletResponse; |
|
|
|
|
import org.springframework.oxm.Marshaller; |
|
|
|
|
import org.springframework.validation.BeanPropertyBindingResult; |
|
|
|
|
import org.springframework.validation.BindingResult; |
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
import static org.mockito.BDDMockito.*; |
|
|
|
|
@ -35,9 +38,10 @@ import static org.mockito.BDDMockito.*;
@@ -35,9 +38,10 @@ import static org.mockito.BDDMockito.*;
|
|
|
|
|
*/ |
|
|
|
|
public class MarshallingViewTests { |
|
|
|
|
|
|
|
|
|
private Marshaller marshallerMock; |
|
|
|
|
|
|
|
|
|
private MarshallingView view; |
|
|
|
|
|
|
|
|
|
private Marshaller marshallerMock; |
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
public void createView() throws Exception { |
|
|
|
|
@ -45,6 +49,7 @@ public class MarshallingViewTests {
@@ -45,6 +49,7 @@ public class MarshallingViewTests {
|
|
|
|
|
view = new MarshallingView(marshallerMock); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void getContentType() { |
|
|
|
|
assertEquals("Invalid content type", "application/xml", view.getContentType()); |
|
|
|
|
@ -159,6 +164,26 @@ public class MarshallingViewTests {
@@ -159,6 +164,26 @@ public class MarshallingViewTests {
|
|
|
|
|
verify(marshallerMock).marshal(eq(toBeMarshalled), isA(StreamResult.class)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void renderNoModelKeyAndBindingResultFirst() throws Exception { |
|
|
|
|
Object toBeMarshalled = new Object(); |
|
|
|
|
String modelKey = "key"; |
|
|
|
|
Map<String, Object> model = new LinkedHashMap<String, Object>(); |
|
|
|
|
model.put(BindingResult.MODEL_KEY_PREFIX + modelKey, new BeanPropertyBindingResult(toBeMarshalled, modelKey)); |
|
|
|
|
model.put(modelKey, toBeMarshalled); |
|
|
|
|
|
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
|
|
|
|
|
|
given(marshallerMock.supports(BeanPropertyBindingResult.class)).willReturn(true); |
|
|
|
|
given(marshallerMock.supports(Object.class)).willReturn(true); |
|
|
|
|
|
|
|
|
|
view.render(model, request, response); |
|
|
|
|
assertEquals("Invalid content type", "application/xml", response.getContentType()); |
|
|
|
|
assertEquals("Invalid content length", 0, response.getContentLength()); |
|
|
|
|
verify(marshallerMock).marshal(eq(toBeMarshalled), isA(StreamResult.class)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testRenderUnsupportedModel() throws Exception { |
|
|
|
|
Object toBeMarshalled = new Object(); |
|
|
|
|
|