use of org.springframework.http.MockHttpInputMessage in project spring-framework by spring-projects.
the class MappingJackson2HttpMessageConverterTests method readInvalidJson.
@Test
public void readInvalidJson() throws IOException {
String body = "FooBar";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
assertThatExceptionOfType(HttpMessageNotReadableException.class).isThrownBy(() -> converter.read(MyBean.class, inputMessage));
}
use of org.springframework.http.MockHttpInputMessage in project spring-framework by spring-projects.
the class ProtobufJsonFormatHttpMessageConverterTests 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);
assertThat(result).isEqualTo(this.testMsg);
}
use of org.springframework.http.MockHttpInputMessage in project spring-framework by spring-projects.
the class MappingJackson2XmlHttpMessageConverterTests method readValidXmlWithUnknownProperty.
@Test
public void readValidXmlWithUnknownProperty() throws IOException {
String body = "<MyBean><string>string</string><unknownProperty>value</unknownProperty></MyBean>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML);
converter.read(MyBean.class, inputMessage);
// Assert no HttpMessageNotReadableException is thrown
}
use of org.springframework.http.MockHttpInputMessage in project spring-framework by spring-projects.
the class MappingJackson2XmlHttpMessageConverterTests method readNonUnicode.
@Test
@SuppressWarnings("unchecked")
public void readNonUnicode() throws Exception {
String body = "<MyBean>" + "<string>føø bår</string>" + "</MyBean>";
Charset charset = StandardCharsets.ISO_8859_1;
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(charset));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml", charset));
MyBean result = (MyBean) converter.read(MyBean.class, inputMessage);
assertThat(result.getString()).isEqualTo("føø bår");
}
use of org.springframework.http.MockHttpInputMessage in project spring-framework by spring-projects.
the class MappingJackson2XmlHttpMessageConverterTests method readWithExternalReference.
@Test
public void readWithExternalReference() throws IOException {
String body = "<!DOCTYPE MyBean SYSTEM \"https://192.168.28.42/1.jsp\" [" + " <!ELEMENT root ANY >\n" + " <!ENTITY ext SYSTEM \"" + new ClassPathResource("external.txt", getClass()).getURI() + "\" >]><MyBean><string>&ext;</string></MyBean>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
inputMessage.getHeaders().setContentType(MediaType.APPLICATION_XML);
assertThatExceptionOfType(HttpMessageNotReadableException.class).isThrownBy(() -> this.converter.read(MyBean.class, inputMessage));
}
Aggregations