Package test.mock.servlet

Examples of test.mock.servlet.MockHttpServletRequest


    Assert.assertThat(book.getId(), is(345));
  }

  @Test
  public void testPostBeanParamInject() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/book/create/");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod(HttpMethod.POST);
    request.setParameter("title", "good book");
    request.setParameter("text", "一本好书");
    request.setParameter("id", "330");
    request.setParameter("price", "79.9");
    request.setParameter("sell", "true");
    MockHttpServletResponse response = new MockHttpServletResponse();
    dispatcherController.dispatch(request, response);
    Book book = (Book) request.getAttribute("book");
    Assert.assertThat(book.getText(), is("一本好书"));
    Assert.assertThat(book.getPrice(), is(79.9));
    Assert.assertThat(book.getId(), is(330));
    Assert.assertThat(book.getSell(), is(true));
  }
View Full Code Here


    Assert.assertThat(book.getSell(), is(true));
  }

  @Test
  public void testResponseOutput() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/hello/text");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();
    dispatcherController.dispatch(request, response);
    Assert.assertThat(response.getAsString(), is("文本输出"));
   
    request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/hello/text-xo/333-444");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod("GET");
    response = new MockHttpServletResponse();
    dispatcherController.dispatch(request, response);
    Assert.assertThat(response.getAsString(), is("text-xo-333-444"));
   
    request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/hello55555/");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod("GET");
    response = new MockHttpServletResponse();
    dispatcherController.dispatch(request, response);
    Assert.assertThat(response.getAsString(), is("text-55555"));
  }
View Full Code Here

    Assert.assertThat(response.getAsString(), is("text-55555"));
  }

  @Test
  public void testJsonOutput() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/book/json/");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod(HttpMethod.POST);
    request.setParameter("title", "good book");
    request.setParameter("text", "very good");
    request.setParameter("id", "331");
    request.setParameter("price", "10.0");
    request.setParameter("sell", "false");
    MockHttpServletResponse response = new MockHttpServletResponse();
    dispatcherController.dispatch(request, response);
    log.info(response.getAsString());
    Assert.assertThat(response.getAsString().length(), greaterThan(10));
    Book book = Json.toObject(response.getAsString(), Book.class);
View Full Code Here

    Assert.assertThat(book.getTitle(), is("good book"));
  }

  @Test
  public void testRedirect() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/hello/redirect");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();
    dispatcherController.dispatch(request, response);
    Assert.assertThat(response.getHeader("Location"), is("/firefly/app/hello"));
  }
View Full Code Here

TOP

Related Classes of test.mock.servlet.MockHttpServletRequest

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.