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);
}
Aggregations