use of org.springframework.tests.sample.beans.DerivedTestBean in project spring-framework by spring-projects.
the class WebApplicationContextScopeTests method testSessionScope.
@Test
public void testSessionScope() {
WebApplicationContext ac = initApplicationContext(WebApplicationContext.SCOPE_SESSION);
MockHttpServletRequest request = new MockHttpServletRequest();
ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(requestAttributes);
try {
assertNull(request.getSession().getAttribute(NAME));
DerivedTestBean bean = ac.getBean(NAME, DerivedTestBean.class);
assertSame(bean, request.getSession().getAttribute(NAME));
assertSame(bean, ac.getBean(NAME));
request.getSession().invalidate();
assertTrue(bean.wasDestroyed());
} finally {
RequestContextHolder.setRequestAttributes(null);
}
}
use of org.springframework.tests.sample.beans.DerivedTestBean in project spring-framework by spring-projects.
the class WebApplicationContextScopeTests method testApplicationScope.
@Test
public void testApplicationScope() {
WebApplicationContext ac = initApplicationContext(WebApplicationContext.SCOPE_APPLICATION);
assertNull(ac.getServletContext().getAttribute(NAME));
DerivedTestBean bean = ac.getBean(NAME, DerivedTestBean.class);
assertSame(bean, ac.getServletContext().getAttribute(NAME));
assertSame(bean, ac.getBean(NAME));
new ContextCleanupListener().contextDestroyed(new ServletContextEvent(ac.getServletContext()));
assertTrue(bean.wasDestroyed());
}
use of org.springframework.tests.sample.beans.DerivedTestBean in project spring-framework by spring-projects.
the class RequestScopedProxyTests method testDestructionAtRequestCompletion.
@Test
public void testDestructionAtRequestCompletion() throws Exception {
String name = "requestScopedDisposableObject";
DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name);
assertTrue(AopUtils.isCglibProxy(bean));
MockHttpServletRequest request = new MockHttpServletRequest();
ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(requestAttributes);
try {
assertNull(request.getAttribute("scopedTarget." + name));
assertEquals("scoped", bean.getName());
assertNotNull(request.getAttribute("scopedTarget." + name));
assertEquals(DerivedTestBean.class, request.getAttribute("scopedTarget." + name).getClass());
assertEquals("scoped", ((TestBean) request.getAttribute("scopedTarget." + name)).getName());
assertSame(bean, this.beanFactory.getBean(name));
requestAttributes.requestCompleted();
assertTrue(((TestBean) request.getAttribute("scopedTarget." + name)).wasDestroyed());
} finally {
RequestContextHolder.setRequestAttributes(null);
}
}
use of org.springframework.tests.sample.beans.DerivedTestBean in project spring-framework by spring-projects.
the class ConcurrencyThrottleInterceptorTests method testSerializable.
@Test
public void testSerializable() throws Exception {
DerivedTestBean tb = new DerivedTestBean();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(new Class[] { ITestBean.class });
ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
proxyFactory.addAdvice(cti);
proxyFactory.setTarget(tb);
ITestBean proxy = (ITestBean) proxyFactory.getProxy();
proxy.getAge();
ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
Advised advised = (Advised) serializedProxy;
ConcurrencyThrottleInterceptor serializedCti = (ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
assertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit());
serializedProxy.getAge();
}
use of org.springframework.tests.sample.beans.DerivedTestBean in project spring-framework by spring-projects.
the class BeanUtilsTests method testCopyPropertiesWithDifferentTypes1.
@Test
public void testCopyPropertiesWithDifferentTypes1() throws Exception {
DerivedTestBean tb = new DerivedTestBean();
tb.setName("rod");
tb.setAge(32);
tb.setTouchy("touchy");
TestBean tb2 = new TestBean();
assertTrue("Name empty", tb2.getName() == null);
assertTrue("Age empty", tb2.getAge() == 0);
assertTrue("Touchy empty", tb2.getTouchy() == null);
BeanUtils.copyProperties(tb, tb2);
assertTrue("Name copied", tb2.getName().equals(tb.getName()));
assertTrue("Age copied", tb2.getAge() == tb.getAge());
assertTrue("Touchy copied", tb2.getTouchy().equals(tb.getTouchy()));
}
Aggregations