Search in sources :

Example 81 with MockHttpInputMessage

use of cn.taketoday.http.MockHttpInputMessage in project today-infrastructure by TAKETODAY.

the class StringHttpMessageConverterTests method readJsonApi.

// gh-25328
@Test
public void readJsonApi() throws IOException {
    String body = "{\"result\":\"\u0414\u0410\"}";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
    inputMessage.getHeaders().setContentType(new MediaType("application", "vnd.api.v1+json"));
    String result = this.converter.read(String.class, inputMessage);
    assertThat(result).as("Invalid result").isEqualTo(body);
}
Also used : MockHttpInputMessage(cn.taketoday.http.MockHttpInputMessage) MediaType(cn.taketoday.http.MediaType) Test(org.junit.jupiter.api.Test)

Example 82 with MockHttpInputMessage

use of cn.taketoday.http.MockHttpInputMessage in project today-infrastructure by TAKETODAY.

the class BufferedImageHttpMessageConverterTests method read.

@Test
public void read() throws IOException {
    Resource logo = new ClassPathResource("logo.jpg", BufferedImageHttpMessageConverterTests.class);
    byte[] body = FileCopyUtils.copyToByteArray(logo.getInputStream());
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
    inputMessage.getHeaders().setContentType(new MediaType("image", "png"));
    BufferedImage result = converter.read(BufferedImage.class, inputMessage);
    assertThat(result.getHeight()).as("Invalid height").isEqualTo(292);
    assertThat(result.getWidth()).as("Invalid width").isEqualTo(819);
}
Also used : MockHttpInputMessage(cn.taketoday.http.MockHttpInputMessage) Resource(cn.taketoday.core.io.Resource) ClassPathResource(cn.taketoday.core.io.ClassPathResource) MediaType(cn.taketoday.http.MediaType) ClassPathResource(cn.taketoday.core.io.ClassPathResource) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.jupiter.api.Test)

Aggregations

MockHttpInputMessage (cn.taketoday.http.MockHttpInputMessage)82 Test (org.junit.jupiter.api.Test)82 MediaType (cn.taketoday.http.MediaType)56 MockHttpOutputMessage (cn.taketoday.http.MockHttpOutputMessage)26 ArrayList (java.util.ArrayList)24 List (java.util.List)18 TypeReference (cn.taketoday.core.TypeReference)12 HashMap (java.util.HashMap)10 HttpMessageNotReadableException (cn.taketoday.http.converter.HttpMessageNotReadableException)9 Message (com.google.protobuf.Message)8 InputStream (java.io.InputStream)8 ClassPathResource (cn.taketoday.core.io.ClassPathResource)7 InputStreamResource (cn.taketoday.core.io.InputStreamResource)6 Resource (cn.taketoday.core.io.Resource)6 Type (java.lang.reflect.Type)6 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)6 Charset (java.nio.charset.Charset)5 ByteArrayResource (cn.taketoday.core.io.ByteArrayResource)4 Field (java.lang.reflect.Field)4 Nullable (cn.taketoday.lang.Nullable)2