Package org.springframework.http

Examples of org.springframework.http.MockHttpOutputMessage


        outputMessage.getBodyAsString(Charset.forName("UTF-8")));
  }

  @Test
  public void writeXmlRootElementSubclass() throws Exception {
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    converter.write(rootElementCglib, null, outputMessage);
    assertEquals("Invalid content-type", new MediaType("application", "xml"),
        outputMessage.getHeaders().getContentType());
    assertXMLEqual("Invalid result", "<rootElement><type s=\"Hello World\"/></rootElement>",
        outputMessage.getBodyAsString(Charset.forName("UTF-8")));
  }
View Full Code Here


    assertEquals(ProtobufHttpMessageConverter.PROTOBUF, this.converter.getDefaultContentType(this.testMsg));
  }

  @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());
  }
View Full Code Here

  // SPR-11488

  @Test
  public void customizeMarshaller() throws Exception {
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    MyJaxb2RootElementHttpMessageConverter myConverter = new MyJaxb2RootElementHttpMessageConverter();
    myConverter.write(new MyRootElement(new MyCustomElement("a", "b")), null, outputMessage);
    assertXMLEqual("Invalid result", "<myRootElement><element>a|||b</element></myRootElement>",
        outputMessage.getBodyAsString(Charset.forName("UTF-8")));
  }
View Full Code Here

    assertArrayEquals("Invalid result", body, result);
  }

  @Test
  public void write() throws IOException {
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    byte[] body = new byte[]{0x1, 0x2};
    converter.write(body, null, outputMessage);
    assertArrayEquals("Invalid result", body, outputMessage.getBodyAsBytes());
    assertEquals("Invalid content-type", new MediaType("application", "octet-stream"),
        outputMessage.getHeaders().getContentType());
    assertEquals("Invalid content-length", 2, outputMessage.getHeaders().getContentLength());
  }
View Full Code Here

    converter.read(Resource.class, inputMessage);
  }

  @Test
  public void write() throws IOException {
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    Resource body = new ClassPathResource("logo.jpg", getClass());
    converter.write(body, null, outputMessage);
    assertEquals("Invalid content-type", MediaType.IMAGE_JPEG,
        outputMessage.getHeaders().getContentType());
    assertEquals("Invalid content-length", body.getFile().length(), outputMessage.getHeaders().getContentLength());
  }
View Full Code Here

  // SPR-10848

  @Test
  public void writeByteArrayNullMediaType() throws IOException {
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    byte[] byteArray = {1, 2, 3};
    Resource body = new ByteArrayResource(byteArray);
    converter.write(body, null, outputMessage);
    assertTrue(Arrays.equals(byteArray, outputMessage.getBodyAsBytes()));
  }
View Full Code Here

  @Test
  public void write() throws IOException {
    Resource logo = new ClassPathResource("logo.jpg", BufferedImageHttpMessageConverterTests.class);
    BufferedImage body = ImageIO.read(logo.getFile());
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    MediaType contentType = new MediaType("image", "png");
    converter.write(body, contentType, outputMessage);
    assertEquals("Invalid content type", contentType, outputMessage.getHeaders().getContentType());
    assertTrue("Invalid size", outputMessage.getBodyAsBytes().length > 0);
    BufferedImage result = ImageIO.read(new ByteArrayInputStream(outputMessage.getBodyAsBytes()));
    assertEquals("Invalid height", 500, result.getHeight());
    assertEquals("Invalid width", 750, result.getWidth());
  }
View Full Code Here

  public void writeDefaultContentType() throws IOException {
    Resource logo = new ClassPathResource("logo.jpg", BufferedImageHttpMessageConverterTests.class);
    MediaType contentType = new MediaType("image", "png");
    converter.setDefaultContentType(contentType);
    BufferedImage body = ImageIO.read(logo.getFile());
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    converter.write(body, new MediaType("*", "*"), outputMessage);
    assertEquals("Invalid content type", contentType, outputMessage.getHeaders().getContentType());
    assertTrue("Invalid size", outputMessage.getBodyAsBytes().length > 0);
    BufferedImage result = ImageIO.read(new ByteArrayInputStream(outputMessage.getBodyAsBytes()));
    assertEquals("Invalid height", 500, result.getHeight());
    assertEquals("Invalid width", 750, result.getWidth());
  }
View Full Code Here

TOP

Related Classes of org.springframework.http.MockHttpOutputMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.