Package org.springframework.mock.web.test

Examples of org.springframework.mock.web.test.MockHttpServletRequest


  @Test
  public void headerValueNoMatch() {
    HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("foo", "bazz");

    assertNull(condition.getMatchingCondition(request));
  }
View Full Code Here


  @Test
  public void headerCaseSensitiveValueMatch() {
    HeadersRequestCondition condition = new HeadersRequestCondition("foo=Bar");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("foo", "bar");

    assertNull(condition.getMatchingCondition(request));
  }
View Full Code Here

  }

  @Test
  public void headerValueMatchNegated() {
    HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("foo", "baz");

    assertNotNull(condition.getMatchingCondition(request));
  }
View Full Code Here

  private MockHttpServletResponse renderViewWithModel(String viewUrl, Map<String, Object> model, Locale locale) throws Exception {

    GroovyMarkupView view = createViewWithUrl(viewUrl);
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setPreferredLocales(Arrays.asList(locale));
    LocaleContextHolder.setLocale(locale);
    view.renderMergedTemplateModel(model, request, response);
    return response;
  }
View Full Code Here

  }

  public void testRequestsWithoutHandlers() throws Exception {
    HandlerMapping hm = (HandlerMapping) wac.getBean("handlerMapping");

    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/nonsense.html");
    req.setContextPath("/myapp");
    Object h = hm.getHandler(req);
    assertTrue("Handler is null", h == null);

    req = new MockHttpServletRequest("GET", "/foo/bar/baz.html");
    h = hm.getHandler(req);
    assertTrue("Handler is null", h == null);
  }
View Full Code Here

  }

  private void doTestRequestsWithSubPaths(HandlerMapping hm) throws Exception {
    Object bean = wac.getBean("godCtrl");

    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/welcome.html");
    HandlerExecutionChain hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/myapp/mypath/welcome.html");
    req.setContextPath("/myapp");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/myapp/mypath/welcome.html");
    req.setContextPath("/myapp");
    req.setServletPath("/mypath/welcome.html");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/myapp/myservlet/mypath/welcome.html");
    req.setContextPath("/myapp");
    req.setServletPath("/myservlet");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/myapp/myapp/mypath/welcome.html");
    req.setContextPath("/myapp");
    req.setServletPath("/myapp");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/mypath/show.html");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/mypath/bookseats.html");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
  }
View Full Code Here

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(new MockServletContext());
    wac.refresh();
    viewResolver = new ContentNegotiatingViewResolver();
    viewResolver.setApplicationContext(wac);
    request = new MockHttpServletRequest("GET", "/test");
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
  }
View Full Code Here

    BeanNameUrlHandlerMapping hm = new BeanNameUrlHandlerMapping();
    hm.setAlwaysUseFullPath(true);
    hm.setApplicationContext(wac);
    Object bean = wac.getBean("godCtrl");

    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/welcome.html");
    HandlerExecutionChain hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/myapp/mypath/welcome.html");
    req.setContextPath("/myapp");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/mypath/welcome.html");
    req.setContextPath("");
    req.setServletPath("/mypath");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/Myapp/mypath/welcome.html");
    req.setContextPath("/myapp");
    req.setServletPath("/mypath");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
  }
View Full Code Here

    this.wac.refresh();
    this.hm = (HandlerMapping) this.wac.getBean("mapping");
  }

  public void testIndexUri() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index");
    HandlerExecutionChain chain = this.hm.getHandler(request);
    assertEquals(this.wac.getBean("index"), chain.getHandler());
  }
View Full Code Here

  public void testAsteriskMatches() throws Exception {
    HandlerMapping hm = (HandlerMapping) wac.getBean("handlerMapping");
    Object bean = wac.getBean("godCtrl");

    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/test.html");
    HandlerExecutionChain hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/mypath/testarossa");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/mypath/tes");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec == null);
  }
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.test.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.