use of jakarta.servlet.ServletRequestEvent in project spring-framework by spring-projects.
the class RequestContextListenerTests method requestContextListenerWithSameThreadAndAttributesGone.
@Test
public void requestContextListenerWithSameThreadAndAttributesGone() {
RequestContextListener listener = new RequestContextListener();
MockServletContext context = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest(context);
request.setAttribute("test", "value");
assertThat(RequestContextHolder.getRequestAttributes()).isNull();
listener.requestInitialized(new ServletRequestEvent(context, request));
assertThat(RequestContextHolder.getRequestAttributes()).isNotNull();
assertThat(RequestContextHolder.getRequestAttributes().getAttribute("test", RequestAttributes.SCOPE_REQUEST)).isEqualTo("value");
MockRunnable runnable = new MockRunnable();
RequestContextHolder.getRequestAttributes().registerDestructionCallback("test", runnable, RequestAttributes.SCOPE_REQUEST);
request.clearAttributes();
listener.requestDestroyed(new ServletRequestEvent(context, request));
assertThat(RequestContextHolder.getRequestAttributes()).isNull();
assertThat(runnable.wasExecuted()).isTrue();
}
Aggregations