Package test.mock.servlet

Examples of test.mock.servlet.MockHttpServletRequest


    Assert.assertThat(request.getAttribute("into").toString(), is("2"));
  }

  @Test
  public void testInterceptorChainReturn1() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/food/view1");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod("GET");
    request.setParameter("strawberry", "strawberry");
    MockHttpServletResponse response = new MockHttpServletResponse();
    dispatcherController.dispatcher(request, response);
    log.info(request.getDispatcherTarget());
    Food food = (Food) request.getAttribute("fruit");
    Assert.assertThat(food.getName(), is("strawberry"));
    Assert.assertThat(food.getPrice(), is(10.00));
    Assert.assertThat(request.getDispatcherTarget(),
        is("/WEB-INF/page/foodView.jsp"));

  }
View Full Code Here


  }

  @Test
  public void testInterceptorChainReturn() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/food/view1");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod("GET");
    request.setParameter("fruit", "apple");
    MockHttpServletResponse response = new MockHttpServletResponse();
    dispatcherController.dispatcher(request, response);
    Food food = (Food) request.getAttribute("fruit");
    Assert.assertThat(food.getName(), is("apple"));
    Assert.assertThat(food.getPrice(), is(5.3));
    Assert.assertThat(request.getDispatcherTarget(),
        is("/WEB-INF/page/food.jsp"));
  }
View Full Code Here

public class TestMvc {
  private static Log log = LogFactory.getInstance().getLog("firefly-system");
  private static DispatcherController dispatcherController = new HttpServletDispatcherController(new AnnotationWebContext("firefly-mvc.xml"));
 
  public static void main(String[] args) {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/book/testMethod/");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod(HttpMethod.GET);
    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);
   
    System.out.println(response.getAsString());
    System.out.println(response.getHeader("Allow"));
View Full Code Here

    System.out.println(response.getHeader("Allow"));
  }
 
  @Test
  public void testAllowMethod() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/book/testMethod/");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod(HttpMethod.PUT);
    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);
    Assert.assertThat(response.getHeader("Allow"), is("POST,GET"));
//    System.out.println(response.getAsString());
//    System.out.println(response.getHeader("Allow"));
View Full Code Here

//    System.out.println(response.getHeader("Allow"));
  }
 
  @Test
  public void testInterceptorChain() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/food/view1");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();
    dispatcherController.dispatch(request, response);
   
    Food food = (Food)request.getAttribute("fruit0");
    Assert.assertThat(food.getName(), is("apple"));
    Assert.assertThat(food.getPrice(), is(8.0));
   
    food = (Food)request.getAttribute("fruit1");
    Assert.assertThat(food.getName(), is("ananas"));
    Assert.assertThat(food.getPrice(), is(4.99));
   
    food = Json.toObject(response.getAsString(), Food.class);
    Assert.assertThat(food.getName(), is("banana"));
View Full Code Here

    Assert.assertThat(food.getPrice(), is(3.99));
  }
 
  @Test
  public void testInterceptor() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/food");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();
    dispatcherController.dispatch(request, response);
   
    Food food = (Food)request.getAttribute("fruit");
    Assert.assertThat(food.getName(), is("orange"));
    Assert.assertThat(food.getPrice(), is(3.5));
   
    food = (Food)request.getAttribute("fruit0");
    Assert.assertThat(food.getName(), is("apple"));
    Assert.assertThat(food.getPrice(), is(8.0));
   
    food = (Food)request.getAttribute("strawberry");
    Assert.assertThat(food.getName(), is("strawberry"));
    Assert.assertThat(food.getPrice(), is(10.0));
  }
View Full Code Here

    Assert.assertThat(food.getPrice(), is(10.0));
  }
 
  @Test
  public void testNotFoundPage() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/book/create00/");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod(HttpMethod.GET);
    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);
   
    Assert.assertThat(response.getStatus(), is(404));
  }
View Full Code Here

    Assert.assertThat(response.getStatus(), is(404));
  }
 
  @Test
  public void testNotAllowMethod() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/book/create/");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod(HttpMethod.GET);
    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);
   
    Assert.assertThat(response.getHeader("Allow"), is("POST"));
    Assert.assertThat(request.getAttribute("book"), nullValue());
  }
View Full Code Here

    Assert.assertThat(request.getAttribute("book"), nullValue());
  }
 
  @Test
  public void testControllerHello() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/hello");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();
    dispatcherController.dispatch(request, response);
    Assert.assertThat(request.getAttribute("hello").toString(),
        is("你好 firefly!"));
  }
View Full Code Here

        is("你好 firefly!"));
  }

  @Test
  public void testBeanParamInject() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/firefly/app/book/value");
    request.setServletPath("/app");
    request.setContextPath("/firefly");
    request.setMethod("GET");
    request.setParameter("text", "ddd");
    request.setParameter("id", "345");
    request.setParameter("price", "23.3");
    MockHttpServletResponse response = new MockHttpServletResponse();
    dispatcherController.dispatch(request, response);
    Book book = (Book) request.getAttribute("book");
    Assert.assertThat(book.getText(), is("ddd"));
    Assert.assertThat(book.getPrice(), is(23.3));
    Assert.assertThat(book.getId(), is(345));
  }
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.