Package org.springframework.http

Examples of org.springframework.http.MockHttpInputMessage


        }
      }
    };
    String body =
        "[{\"bytes\":\"AQI=\",\"array\":[\"Foo\",\"Bar\"],\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}]";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
    inputMessage.getHeaders().setContentType(new MediaType("application", "json"));

    List<MyBean> results = (List<MyBean>) converter.read(List.class, inputMessage);
    assertEquals(1, results.size());
    MyBean result = results.get(0);
    assertEquals("Foo", result.getString());
View Full Code Here


  public void readParameterizedType() throws IOException {
    ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<List<MyBean>>() {};

    String body =
        "[{\"bytes\":\"AQI=\",\"array\":[\"Foo\",\"Bar\"],\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}]";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
    inputMessage.getHeaders().setContentType(new MediaType("application", "json"));

    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    List<MyBean> results = (List<MyBean>) converter.read(beansList.getType(), null, inputMessage);
    assertEquals(1, results.size());
    MyBean result = results.get(0);
View Full Code Here

  }

  @Test
  public void read() throws Exception {
    String body = "<root>Hello World</root>";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));

    Unmarshaller unmarshaller = mock(Unmarshaller.class);
    given(unmarshaller.unmarshal(isA(StreamSource.class))).willReturn(body);

    MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();
View Full Code Here

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

  @Test(expected = TypeMismatchException.class)
  public void readWithTypeMismatchException() throws Exception {
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]);

    Marshaller marshaller = mock(Marshaller.class);
    Unmarshaller unmarshaller = mock(Unmarshaller.class);
    given(unmarshaller.unmarshal(isA(StreamSource.class))).willReturn(Integer.valueOf(3));
View Full Code Here

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

  @Test
  public void readWithMarshallingFailureException() throws Exception {
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]);
    UnmarshallingFailureException ex = new UnmarshallingFailureException("forced");

    Unmarshaller unmarshaller = mock(Unmarshaller.class);
    given(unmarshaller.unmarshal(isA(StreamSource.class))).willThrow(ex);
View Full Code Here

  }

  @Test
  public void read() throws IOException {
    InputStream is = getClass().getResourceAsStream("atom.xml");
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(is);
    inputMessage.getHeaders().setContentType(new MediaType("application", "atom+xml", utf8));
    Feed result = converter.read(Feed.class, inputMessage);
    assertEquals("title", result.getTitle());
    assertEquals("subtitle", result.getSubtitle().getValue());
    List<?> entries = result.getEntries();
    assertEquals(2, entries.size());
View Full Code Here

  @Test
  public void read() throws IOException {
    String body =
        "<MyBean><string>Foo</string><number>42</number><fraction>42.0</fraction><array><array>Foo</array><array>Bar</array></array><bool>true</bool><bytes>AQI=</bytes></MyBean>";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
    inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
    MyBean result = (MyBean) converter.read(MyBean.class, inputMessage);
    assertEquals("Foo", result.getString());
    assertEquals(42, result.getNumber());
    assertEquals(42F, result.getFraction(), 0F);
    assertArrayEquals(new String[]{"Foo", "Bar"}, result.getArray());
View Full Code Here

  }

  @Test(expected = HttpMessageNotReadableException.class)
  public void readInvalidXml() throws IOException {
    String body = "FooBar";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
    inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
    converter.read(MyBean.class, inputMessage);
  }
View Full Code Here

  }

  @Test
  public void readValidXmlWithUnknownProperty() throws IOException {
    String body = "<MyBean><string>string</string><unknownProperty>value</unknownProperty></MyBean>";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
    inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
    converter.read(MyBean.class, inputMessage);
    // Assert no HttpMessageNotReadableException is thrown
  }
View Full Code Here

  }

  @Test
  public void read() throws IOException {
    InputStream is = getClass().getResourceAsStream("rss.xml");
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(is);
    inputMessage.getHeaders().setContentType(new MediaType("application", "rss+xml", utf8));
    Channel result = converter.read(Channel.class, inputMessage);
    assertEquals("title", result.getTitle());
    assertEquals("http://example.com", result.getLink());
    assertEquals("description", result.getDescription());
View Full Code Here

TOP

Related Classes of org.springframework.http.MockHttpInputMessage

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.