use of org.springframework.beans.testfixture.beans.DerivedTestBean in project spring-framework by spring-projects.
the class SessionScopeTests method doTestDestructionWithSessionSerialization.
private void doTestDestructionWithSessionSerialization(boolean beanNameReset) throws Exception {
Serializable serializedState = null;
MockHttpSession session = new MockHttpSession();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSession(session);
ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(requestAttributes);
String name = "sessionScopedDisposableObject";
assertThat(session.getAttribute(name)).isNull();
DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name);
assertThat(bean).isEqualTo(session.getAttribute(name));
assertThat(this.beanFactory.getBean(name)).isSameAs(bean);
requestAttributes.requestCompleted();
serializedState = session.serializeState();
assertThat(bean.wasDestroyed()).isFalse();
serializedState = SerializationTestUtils.serializeAndDeserialize(serializedState);
session = new MockHttpSession();
session.deserializeState(serializedState);
request = new MockHttpServletRequest();
request.setSession(session);
requestAttributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(requestAttributes);
name = "sessionScopedDisposableObject";
assertThat(session.getAttribute(name)).isNotNull();
bean = (DerivedTestBean) this.beanFactory.getBean(name);
assertThat(bean).isEqualTo(session.getAttribute(name));
assertThat(this.beanFactory.getBean(name)).isSameAs(bean);
requestAttributes.requestCompleted();
session.invalidate();
assertThat(bean.wasDestroyed()).isTrue();
if (beanNameReset) {
assertThat(bean.getBeanName()).isNull();
} else {
assertThat(bean.getBeanName()).isNotNull();
}
}
use of org.springframework.beans.testfixture.beans.DerivedTestBean in project spring-framework by spring-projects.
the class SessionScopeTests method destructionAtSessionTermination.
@Test
public void destructionAtSessionTermination() throws Exception {
MockHttpSession session = new MockHttpSession();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSession(session);
ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(requestAttributes);
String name = "sessionScopedDisposableObject";
assertThat(session.getAttribute(name)).isNull();
DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name);
assertThat(bean).isEqualTo(session.getAttribute(name));
assertThat(this.beanFactory.getBean(name)).isSameAs(bean);
requestAttributes.requestCompleted();
session.invalidate();
assertThat(bean.wasDestroyed()).isTrue();
}
Aggregations