use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.
the class BaseViewTests method renderWithStaticAttributesNoCollision.
/**
* Test attribute passing, NOT CSV parsing.
*/
@Test
public void renderWithStaticAttributesNoCollision() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
Properties p = new Properties();
p.setProperty("foo", "bar");
p.setProperty("something", "else");
tv.setAttributes(p);
Map<String, Object> model = new HashMap<>();
model.put("one", new HashMap<>());
model.put("two", new Object());
tv.render(model, request, response);
checkContainsAll(model, tv.model);
checkContainsAll(p, tv.model);
assertThat(tv.initialized).isTrue();
}
use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.
the class BaseViewTests method pathVarsOverrideStaticAttributes.
@Test
public void pathVarsOverrideStaticAttributes() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
Properties p = new Properties();
p.setProperty("one", "bar");
p.setProperty("something", "else");
tv.setAttributes(p);
Map<String, Object> pathVars = new HashMap<>();
pathVars.put("one", new HashMap<>());
pathVars.put("two", new Object());
request.setAttribute(View.PATH_VARIABLES, pathVars);
tv.render(new HashMap<>(), request, response);
checkContainsAll(pathVars, tv.model);
assertThat(tv.model.size()).isEqualTo(3);
assertThat(tv.model.get("something")).isEqualTo("else");
assertThat(tv.initialized).isTrue();
}
use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.
the class BaseViewTests method renderWithoutStaticAttributes.
@Test
public void renderWithoutStaticAttributes() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
// Check superclass handles duplicate init
tv.setApplicationContext(wac);
tv.setApplicationContext(wac);
Map<String, Object> model = new HashMap<>();
model.put("foo", "bar");
model.put("something", new Object());
tv.render(model, request, response);
checkContainsAll(model, tv.model);
assertThat(tv.initialized).isTrue();
}
use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.
the class CharacterEncodingFilterTests method forceEncodingAlwaysSetsEncoding.
@Test
public void forceEncodingAlwaysSetsEncoding() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
request.setCharacterEncoding(ENCODING);
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
given(request.getDispatcherType()).willReturn(DispatcherType.REQUEST);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain filterChain = mock(FilterChain.class);
CharacterEncodingFilter filter = new CharacterEncodingFilter(ENCODING, true);
filter.init(new MockFilterConfig(FILTER_NAME));
filter.doFilter(request, response, filterChain);
verify(request).setAttribute(filteredName(FILTER_NAME), Boolean.TRUE);
verify(request).removeAttribute(filteredName(FILTER_NAME));
verify(response).setCharacterEncoding(ENCODING);
verify(filterChain).doFilter(request, response);
}
use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.
the class CharacterEncodingFilterTests method setForceEncodingOnRequestOnly.
// SPR-14240
@Test
public void setForceEncodingOnRequestOnly() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
request.setCharacterEncoding(ENCODING);
given(request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)).willReturn(null);
given(request.getAttribute(filteredName(FILTER_NAME))).willReturn(null);
given(request.getDispatcherType()).willReturn(DispatcherType.REQUEST);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain filterChain = mock(FilterChain.class);
CharacterEncodingFilter filter = new CharacterEncodingFilter(ENCODING, true, false);
filter.init(new MockFilterConfig(FILTER_NAME));
filter.doFilter(request, response, filterChain);
verify(request).setAttribute(filteredName(FILTER_NAME), Boolean.TRUE);
verify(request).removeAttribute(filteredName(FILTER_NAME));
verify(request, times(2)).setCharacterEncoding(ENCODING);
verify(response, never()).setCharacterEncoding(ENCODING);
verify(filterChain).doFilter(request, response);
}
Aggregations