Package org.springframework.http

Examples of org.springframework.http.MockHttpInputMessage


  @Test
  @SuppressWarnings("unchecked")
  public void readXmlRootElementList() throws Exception {
    String content = "<list><rootElement><type s=\"1\"/></rootElement><rootElement><type s=\"2\"/></rootElement></list>";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));

    List<RootElement> result = (List<RootElement>) converter.read(rootElementListType, null, inputMessage);

    assertEquals("Invalid result", 2, result.size());
    assertEquals("Invalid result", "1", result.get(0).type.s);
View Full Code Here


  @Test
  @SuppressWarnings("unchecked")
  public void readXmlRootElementSet() throws Exception {
    String content = "<set><rootElement><type s=\"1\"/></rootElement><rootElement><type s=\"2\"/></rootElement></set>";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));

    Set<RootElement> result = (Set<RootElement>) converter.read(rootElementSetType, null, inputMessage);

    assertEquals("Invalid result", 2, result.size());
    assertTrue("Invalid result", result.contains(new RootElement("1")));
View Full Code Here

  @Test
  @SuppressWarnings("unchecked")
  public void readXmlTypeList() throws Exception {
    String content = "<list><foo s=\"1\"/><bar s=\"2\"/></list>";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));

    List<TestType> result = (List<TestType>) converter.read(typeListType, null, inputMessage);

    assertEquals("Invalid result", 2, result.size());
    assertEquals("Invalid result", "1", result.get(0).s);
View Full Code Here

  @Test
  @SuppressWarnings("unchecked")
  public void readXmlTypeSet() throws Exception {
    String content = "<set><foo s=\"1\"/><bar s=\"2\"/></set>";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));

    Set<TestType> result = (Set<TestType>) converter.read(typeSetType, null, inputMessage);

    assertEquals("Invalid result", 2, result.size());
    assertTrue("Invalid result", result.contains(new TestType("1")));
View Full Code Here

    Resource external = new ClassPathResource("external.txt", getClass());
    String content =  "<!DOCTYPE root [" +
        "  <!ELEMENT external ANY >\n" +
        "  <!ENTITY ext SYSTEM \"" + external.getURI() + "\" >]>" +
        "  <list><rootElement><type s=\"1\"/><external>&ext;</external></rootElement></list>";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));

    Collection<RootElement> result = converter.read(rootElementListType, null, inputMessage);
    assertEquals(1, result.size());
    assertEquals("", result.iterator().next().external);
  }
View Full Code Here

    Resource external = new ClassPathResource("external.txt", getClass());
    String content =  "<!DOCTYPE root [" +
        "  <!ELEMENT external ANY >\n" +
        "  <!ENTITY ext SYSTEM \"" + external.getURI() + "\" >]>" +
        "  <list><rootElement><type s=\"1\"/><external>&ext;</external></rootElement></list>";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));

    Jaxb2CollectionHttpMessageConverter<?> c = new Jaxb2CollectionHttpMessageConverter<Collection<Object>>() {
      @Override
      protected XMLInputFactory createXmlInputFactory() {
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
View Full Code Here

  @Test
  public void readTyped() throws IOException {
    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"));
    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
  @SuppressWarnings("unchecked")
  public void readUntyped() throws IOException {
    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"));
    HashMap<String, Object> result = (HashMap<String, Object>) converter.read(HashMap.class, inputMessage);
    assertEquals("Foo", result.get("string"));
    assertEquals(42, result.get("number"));
    assertEquals(42D, (Double) result.get("fraction"), 0D);
    List<String> array = new ArrayList<String>();
View Full Code Here

  }

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

  }

  @Test
  public void readValidJsonWithUnknownProperty() throws IOException {
    String body = "{\"string\":\"string\",\"unknownProperty\":\"value\"}";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
    inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
    converter.read(MyBean.class, inputMessage);
    // Assert no HttpMessageNotReadableException is thrown
  }
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.