use of cn.taketoday.mock.web.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class ClassPathBeanDefinitionScannerScopeIntegrationTests method setup.
@BeforeEach
void setup() {
MockHttpServletRequest oldRequestWithSession = new MockHttpServletRequest();
oldRequestWithSession.setSession(new MockHttpSession());
this.oldRequestAttributesWithSession = new ServletRequestContext(null, oldRequestWithSession, new MockHttpServletResponse());
MockHttpServletRequest newRequestWithSession = new MockHttpServletRequest();
newRequestWithSession.setSession(new MockHttpSession());
this.newRequestAttributesWithSession = new ServletRequestContext(null, newRequestWithSession, new MockHttpServletResponse());
}
use of cn.taketoday.mock.web.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class AopNamespaceHandlerScopeIntegrationTests method testSessionScoping.
@Test
void testSessionScoping() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
RequestContextHolder.set(new ServletRequestContext(null, request, new MockHttpServletResponse()));
assertThat(AopUtils.isAopProxy(sessionScoped)).as("Should be AOP proxy").isTrue();
boolean condition1 = sessionScoped instanceof TestBean;
assertThat(condition1).as("Should not be target class proxy").isFalse();
assertThat(sessionScopedAlias).isSameAs(sessionScoped);
assertThat(AopUtils.isAopProxy(testBean)).as("Should be AOP proxy").isTrue();
boolean condition = testBean instanceof TestBean;
assertThat(condition).as("Regular bean should be JDK proxy").isFalse();
String rob = "Rob Harrop";
String bram = "Bram Smeets";
assertThat(sessionScoped.getName()).isEqualTo(rob);
sessionScoped.setName(bram);
assertThat(((Advised) sessionScoped).getAdvisors().length > 0).as("Should have advisors").isTrue();
}
use of cn.taketoday.mock.web.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class DelegatingFilterProxyRegistrationBeanTests method initShouldNotCauseEarlyInitialization.
@Test
void initShouldNotCauseEarlyInitialization() throws Exception {
this.applicationContext.registerBeanDefinition("mockFilter", new RootBeanDefinition(MockFilter.class));
DelegatingFilterProxyRegistrationBean registrationBean = createFilterRegistrationBean();
Filter filter = registrationBean.getFilter();
filter.init(new MockFilterConfig());
assertThat(mockFilterInitialized.get()).isNull();
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
assertThat(mockFilterInitialized.get()).isTrue();
}
use of cn.taketoday.mock.web.MockHttpServletRequest in project today-framework by TAKETODAY.
the class ServletTestExecutionListenerTests method setUp.
@BeforeEach
void setUp() {
given(wac.getServletContext()).willReturn(mockServletContext);
given(testContext.getApplicationContext()).willReturn(wac);
MockHttpServletRequest request = new MockHttpServletRequest(mockServletContext);
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext servletWebRequest = new ServletRequestContext(null, request, response);
request.setAttribute(SET_UP_OUTSIDE_OF_STEL, "true");
RequestContextHolder.set(servletWebRequest);
assertSetUpOutsideOfStelAttributeExists();
}
use of cn.taketoday.mock.web.MockHttpServletRequest in project today-framework by TAKETODAY.
the class AopNamespaceHandlerScopeIntegrationTests method testRequestScoping.
@Test
void testRequestScoping() throws Exception {
MockHttpServletRequest oldRequest = new MockHttpServletRequest();
MockHttpServletRequest newRequest = new MockHttpServletRequest();
RequestContextHolder.set(new ServletRequestContext(null, oldRequest, null));
assertThat(AopUtils.isAopProxy(requestScoped)).as("Should be AOP proxy").isTrue();
boolean condition = requestScoped instanceof TestBean;
assertThat(condition).as("Should be target class proxy").isTrue();
assertThat(AopUtils.isAopProxy(testBean)).as("Should be AOP proxy").isTrue();
boolean condition1 = testBean instanceof TestBean;
assertThat(condition1).as("Regular bean should be JDK proxy").isFalse();
String rob = "Rob Harrop";
String bram = "Bram Smeets";
assertThat(requestScoped.getName()).isEqualTo(rob);
requestScoped.setName(bram);
RequestContextHolder.set(new ServletRequestContext(null, newRequest, null));
assertThat(requestScoped.getName()).isEqualTo(rob);
RequestContextHolder.set(new ServletRequestContext(null, oldRequest, null));
assertThat(requestScoped.getName()).isEqualTo(bram);
assertThat(((Advised) requestScoped).getAdvisors().length > 0).as("Should have advisors").isTrue();
}
Aggregations