use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class GsonHttpMessageConverterTests method prefixJsonCustom.
@Test
public void prefixJsonCustom() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
this.converter.setJsonPrefix(")))");
this.converter.writeInternal("foo", null, outputMessage);
assertEquals(")))\"foo\"", outputMessage.getBodyAsString(StandardCharsets.UTF_8));
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class GsonHttpMessageConverterTests method writeUTF16.
@Test
public void writeUTF16() throws IOException {
MediaType contentType = new MediaType("application", "json", StandardCharsets.UTF_16BE);
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
String body = "Héllo Wörld";
this.converter.write(body, contentType, outputMessage);
assertEquals("Invalid result", "\"" + body + "\"", outputMessage.getBodyAsString(StandardCharsets.UTF_16BE));
assertEquals("Invalid content-type", contentType, outputMessage.getHeaders().getContentType());
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class ProtobufHttpMessageConverterTests method getContentLength.
@Test
public void getContentLength() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
MediaType contentType = ProtobufHttpMessageConverter.PROTOBUF;
this.converter.write(this.testMsg, contentType, outputMessage);
assertEquals(-1, outputMessage.getHeaders().getContentLength());
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class ProtobufHttpMessageConverterTests method write.
@Test
public void write() throws IOException {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
MediaType contentType = ProtobufHttpMessageConverter.PROTOBUF;
this.converter.write(this.testMsg, contentType, outputMessage);
assertEquals(contentType, outputMessage.getHeaders().getContentType());
assertTrue(outputMessage.getBodyAsBytes().length > 0);
Message result = Msg.parseFrom(outputMessage.getBodyAsBytes());
assertEquals(this.testMsg, result);
String messageHeader = outputMessage.getHeaders().getFirst(ProtobufHttpMessageConverter.X_PROTOBUF_MESSAGE_HEADER);
assertEquals("Msg", messageHeader);
String schemaHeader = outputMessage.getHeaders().getFirst(ProtobufHttpMessageConverter.X_PROTOBUF_SCHEMA_HEADER);
assertEquals("sample.proto", schemaHeader);
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class BufferedImageHttpMessageConverterTests method writeDefaultContentType.
@Test
public void writeDefaultContentType() throws IOException {
Resource logo = new ClassPathResource("logo.jpg", BufferedImageHttpMessageConverterTests.class);
MediaType contentType = new MediaType("image", "png");
converter.setDefaultContentType(contentType);
BufferedImage body = ImageIO.read(logo.getFile());
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
converter.write(body, new MediaType("*", "*"), outputMessage);
assertEquals("Invalid content type", contentType, outputMessage.getWrittenHeaders().getContentType());
assertTrue("Invalid size", outputMessage.getBodyAsBytes().length > 0);
BufferedImage result = ImageIO.read(new ByteArrayInputStream(outputMessage.getBodyAsBytes()));
assertEquals("Invalid height", 500, result.getHeight());
assertEquals("Invalid width", 750, result.getWidth());
}
Aggregations