Example usage for org.springframework.http MockHttpOutputMessage getBodyAsBytes

List of usage examples for org.springframework.http MockHttpOutputMessage getBodyAsBytes

Introduction

In this page you can find the example usage for org.springframework.http MockHttpOutputMessage getBodyAsBytes.

Prototype

public byte[] getBodyAsBytes() 

Source Link

Usage

From source file:org.springframework.http.converter.FormHttpMessageConverterTests.java

@Test
public void writeForm() throws IOException {
    MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
    body.set("name 1", "value 1");
    body.add("name 2", "value 2+1");
    body.add("name 2", "value 2+2");
    body.add("name 3", null);
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    this.converter.write(body, MediaType.APPLICATION_FORM_URLENCODED, outputMessage);

    assertEquals("Invalid result", "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3",
            outputMessage.getBodyAsString(StandardCharsets.UTF_8));
    assertEquals("Invalid content-type", new MediaType("application", "x-www-form-urlencoded"),
            outputMessage.getHeaders().getContentType());
    assertEquals("Invalid content-length", outputMessage.getBodyAsBytes().length,
            outputMessage.getHeaders().getContentLength());
}