use of org.springframework.http.MockHttpInputMessage in project spring-framework by spring-projects.
the class ProtobufHttpMessageConverterTests method read.
@Test
public void read() throws IOException {
byte[] body = this.testMsg.toByteArray();
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
inputMessage.getHeaders().setContentType(ProtobufHttpMessageConverter.PROTOBUF);
Message result = this.converter.read(Msg.class, inputMessage);
assertEquals(this.testMsg, result);
}
use of org.springframework.http.MockHttpInputMessage in project spring-framework by spring-projects.
the class ProtobufHttpMessageConverterTests method readNoContentType.
@Test
public void readNoContentType() throws IOException {
byte[] body = this.testMsg.toByteArray();
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
Message result = this.converter.read(Msg.class, inputMessage);
assertEquals(this.testMsg, result);
}
use of org.springframework.http.MockHttpInputMessage in project spring-framework by spring-projects.
the class Jaxb2CollectionHttpMessageConverterTests method readXmlRootElementSet.
@Test
@SuppressWarnings("unchecked")
public void readXmlRootElementSet() throws Exception {
String content = "<set><rootElement><type s=\"1\"/></rootElement><rootElement><type s=\"2\"/></rootElement></set>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
Set<RootElement> result = (Set<RootElement>) converter.read(rootElementSetType, null, inputMessage);
assertEquals("Invalid result", 2, result.size());
assertTrue("Invalid result", result.contains(new RootElement("1")));
assertTrue("Invalid result", result.contains(new RootElement("2")));
}
use of org.springframework.http.MockHttpInputMessage in project spring-framework by spring-projects.
the class Jaxb2RootElementHttpMessageConverterTests method readXmlRootElementExternalEntityDisabled.
@Test
public void readXmlRootElementExternalEntityDisabled() throws Exception {
Resource external = new ClassPathResource("external.txt", getClass());
String content = "<!DOCTYPE root SYSTEM \"http://192.168.28.42/1.jsp\" [" + " <!ELEMENT external ANY >\n" + " <!ENTITY ext SYSTEM \"" + external.getURI() + "\" >]>" + " <rootElement><external>&ext;</external></rootElement>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
converter.setSupportDtd(true);
RootElement rootElement = (RootElement) converter.read(RootElement.class, inputMessage);
assertEquals("", rootElement.external);
}
use of org.springframework.http.MockHttpInputMessage in project spring-framework by spring-projects.
the class Jaxb2RootElementHttpMessageConverterTests method readXmlRootElement.
@Test
public void readXmlRootElement() throws Exception {
byte[] body = "<rootElement><type s=\"Hello World\"/></rootElement>".getBytes("UTF-8");
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
RootElement result = (RootElement) converter.read(RootElement.class, inputMessage);
assertEquals("Invalid result", "Hello World", result.type.s);
}
Aggregations