Search in sources :

Example 1 with MockHttpInputMessage

use of org.springframework.mock.http.MockHttpInputMessage in project thingsboard by thingsboard.

the class AbstractControllerTest method readResponse.

@SuppressWarnings("unchecked")
protected <T> T readResponse(ResultActions result, Class<T> responseClass) throws Exception {
    byte[] content = result.andReturn().getResponse().getContentAsByteArray();
    MockHttpInputMessage mockHttpInputMessage = new MockHttpInputMessage(content);
    HttpMessageConverter converter = responseClass.equals(String.class) ? stringHttpMessageConverter : mappingJackson2HttpMessageConverter;
    return (T) converter.read(responseClass, mockHttpInputMessage);
}
Also used : MockHttpInputMessage(org.springframework.mock.http.MockHttpInputMessage) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)

Example 2 with MockHttpInputMessage

use of org.springframework.mock.http.MockHttpInputMessage in project irida by phac-nml.

the class SequenceFileMessageConverterTest method testRead.

@Test
public void testRead() throws HttpMessageNotReadableException, IOException {
    String message = "Some fastq file";
    HttpInputMessage inputMessage = new MockHttpInputMessage(message.getBytes());
    Path read = converter.read(Path.class, inputMessage);
    assertTrue(Files.exists(read));
    byte[] fileBytes = Files.readAllBytes(read);
    assertEquals(message, new String(fileBytes));
    Files.delete(read);
}
Also used : HttpInputMessage(org.springframework.http.HttpInputMessage) MockHttpInputMessage(org.springframework.mock.http.MockHttpInputMessage) Path(java.nio.file.Path) MockHttpInputMessage(org.springframework.mock.http.MockHttpInputMessage) Test(org.junit.Test)

Example 3 with MockHttpInputMessage

use of org.springframework.mock.http.MockHttpInputMessage in project thingsboard by thingsboard.

the class AbstractWebTest method readResponse.

@SuppressWarnings("unchecked")
protected <T> T readResponse(ResultActions result, Class<T> responseClass) throws Exception {
    byte[] content = result.andReturn().getResponse().getContentAsByteArray();
    MockHttpInputMessage mockHttpInputMessage = new MockHttpInputMessage(content);
    HttpMessageConverter converter = responseClass.equals(String.class) ? stringHttpMessageConverter : mappingJackson2HttpMessageConverter;
    return (T) converter.read(responseClass, mockHttpInputMessage);
}
Also used : MockHttpInputMessage(org.springframework.mock.http.MockHttpInputMessage) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)

Aggregations

MockHttpInputMessage (org.springframework.mock.http.MockHttpInputMessage)3 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)2 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)2 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)2 Path (java.nio.file.Path)1 Test (org.junit.Test)1 HttpInputMessage (org.springframework.http.HttpInputMessage)1