Search in sources :

Example 61 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.

the class AcceptHeaderLocaleResolverTests method defaultLocale.

@Test
public void defaultLocale() throws Exception {
    this.resolver.setDefaultLocale(JAPANESE);
    MockHttpServletRequest request = new MockHttpServletRequest();
    assertEquals(JAPANESE, this.resolver.resolveLocale(request));
    request.addHeader("Accept-Language", US.toString());
    request.setPreferredLocales(Collections.singletonList(US));
    assertEquals(US, this.resolver.resolveLocale(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Example 62 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.

the class CookieLocaleResolverTests method testResolveLocaleContext.

@Test
public void testResolveLocaleContext() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    Cookie cookie = new Cookie("LanguageKoekje", "nl");
    request.setCookies(cookie);
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setCookieName("LanguageKoekje");
    LocaleContext loc = resolver.resolveLocaleContext(request);
    assertEquals("nl", loc.getLocale().getLanguage());
    assertTrue(loc instanceof TimeZoneAwareLocaleContext);
    assertNull(((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
Also used : Cookie(javax.servlet.http.Cookie) SimpleTimeZoneAwareLocaleContext(org.springframework.context.i18n.SimpleTimeZoneAwareLocaleContext) SimpleLocaleContext(org.springframework.context.i18n.SimpleLocaleContext) TimeZoneAwareLocaleContext(org.springframework.context.i18n.TimeZoneAwareLocaleContext) LocaleContext(org.springframework.context.i18n.LocaleContext) SimpleTimeZoneAwareLocaleContext(org.springframework.context.i18n.SimpleTimeZoneAwareLocaleContext) TimeZoneAwareLocaleContext(org.springframework.context.i18n.TimeZoneAwareLocaleContext) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Example 63 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.

the class JdkProxyControllerTests method typeLevel.

@Test
public void typeLevel() throws Exception {
    initServlet(TypeLevelImpl.class);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("doIt", response.getContentAsString());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 64 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.

the class CompositeRequestConditionTests method compare.

@Test
public void compare() {
    HttpServletRequest request = new MockHttpServletRequest();
    CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
    CompositeRequestCondition cond3 = new CompositeRequestCondition(this.param3);
    assertEquals(1, cond1.compareTo(cond3, request));
    assertEquals(-1, cond3.compareTo(cond1, request));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Example 65 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.

the class CompositeRequestConditionTests method compareEmpty.

@Test
public void compareEmpty() {
    HttpServletRequest request = new MockHttpServletRequest();
    CompositeRequestCondition empty = new CompositeRequestCondition();
    CompositeRequestCondition notEmpty = new CompositeRequestCondition(this.param1);
    assertEquals(0, empty.compareTo(empty, request));
    assertEquals(-1, notEmpty.compareTo(empty, request));
    assertEquals(1, empty.compareTo(notEmpty, request));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)646 Test (org.junit.Test)540 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)330 Before (org.junit.Before)78 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)77 MockServletContext (org.springframework.mock.web.test.MockServletContext)56 TestBean (org.springframework.tests.sample.beans.TestBean)43 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)41 HttpServletResponse (javax.servlet.http.HttpServletResponse)40 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)37 HttpServletRequest (javax.servlet.http.HttpServletRequest)35 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)30 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)29 ITestBean (org.springframework.tests.sample.beans.ITestBean)28 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)28 ServletException (javax.servlet.ServletException)27 HashMap (java.util.HashMap)26 FilterChain (javax.servlet.FilterChain)26 ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)23 Cookie (javax.servlet.http.Cookie)22