Example usage for org.springframework.mock.http MockHttpOutputMessage getBodyAsString

List of usage examples for org.springframework.mock.http MockHttpOutputMessage getBodyAsString

Introduction

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

Prototype

public String getBodyAsString(Charset charset) 

Source Link

Document

Return the body content as a string.

Usage

From source file:org.hobsoft.symmetry.spring.SymmetryHttpMessageConverterTest.java

@Test
public void writeWithoutCharsetEncodesReflectionUsingIso88591() throws IOException, ReflectorException {
    Reflector<DummyComponent> reflector = mockReflector(DummyComponent.class, "x/y");
    doAnswer(write(1, "\u20AC")).when(reflector).reflect(any(DummyComponent.class), any(Writer.class));
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();

    newConverter(reflector).write(new DummyComponent(), parseMediaType("x/y"), outputMessage);

    assertThat(outputMessage.getBodyAsString(ISO_8859_1), is("?"));
}

From source file:org.hobsoft.symmetry.spring.SymmetryHttpMessageConverterTest.java

@Test
public void writeWithCharsetEncodesReflectionUsingCharset() throws IOException, ReflectorException {
    Reflector<DummyComponent> reflector = mockReflector(DummyComponent.class, "x/y; charset=UTF-8");
    doAnswer(write(1, "\u20AC")).when(reflector).reflect(any(DummyComponent.class), any(Writer.class));
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();

    newConverter(reflector).write(new DummyComponent(), parseMediaType("x/y; charset=UTF-8"), outputMessage);

    assertThat(outputMessage.getBodyAsString(UTF_8), is("\u20AC"));
}