Search in sources :

Example 51 with MockHttpInputMessage

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);
}
Also used : MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) Message(com.google.protobuf.Message) MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) Test(org.junit.Test)

Example 52 with MockHttpInputMessage

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);
}
Also used : MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) Message(com.google.protobuf.Message) MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) Test(org.junit.Test)

Example 53 with MockHttpInputMessage

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")));
}
Also used : MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) Set(java.util.Set) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Test(org.junit.Test)

Example 54 with MockHttpInputMessage

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);
}
Also used : MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 55 with MockHttpInputMessage

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);
}
Also used : MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)56 MockHttpInputMessage (org.springframework.http.MockHttpInputMessage)56 MediaType (org.springframework.http.MediaType)31 ClassPathResource (org.springframework.core.io.ClassPathResource)8 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)7 Resource (org.springframework.core.io.Resource)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 InputStream (java.io.InputStream)4 StreamSource (javax.xml.transform.stream.StreamSource)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 SAXSource (javax.xml.transform.sax.SAXSource)3 StAXSource (javax.xml.transform.stax.StAXSource)3 Unmarshaller (org.springframework.oxm.Unmarshaller)3 InputSource (org.xml.sax.InputSource)3 Message (com.google.protobuf.Message)2 InputStreamReader (java.io.InputStreamReader)2 Type (java.lang.reflect.Type)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2