Search in sources :

Example 1 with ScopedProxyTestBean

use of example.scannable.ScopedProxyTestBean in project spring-framework by spring-projects.

the class ComponentScanParserScopedProxyTests method testDefaultScopedProxy.

@Test
public void testDefaultScopedProxy() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyDefaultTests.xml");
    context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
    // should not be a proxy
    assertFalse(AopUtils.isAopProxy(bean));
    context.close();
}
Also used : SimpleMapScope(org.springframework.tests.context.SimpleMapScope) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ScopedProxyTestBean(example.scannable.ScopedProxyTestBean) Test(org.junit.Test)

Example 2 with ScopedProxyTestBean

use of example.scannable.ScopedProxyTestBean in project spring-framework by spring-projects.

the class ComponentScanParserScopedProxyTests method testNoScopedProxy.

@Test
public void testNoScopedProxy() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyNoTests.xml");
    context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
    // should not be a proxy
    assertFalse(AopUtils.isAopProxy(bean));
    context.close();
}
Also used : SimpleMapScope(org.springframework.tests.context.SimpleMapScope) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ScopedProxyTestBean(example.scannable.ScopedProxyTestBean) Test(org.junit.Test)

Example 3 with ScopedProxyTestBean

use of example.scannable.ScopedProxyTestBean in project spring-framework by spring-projects.

the class ComponentScanParserScopedProxyTests method testTargetClassScopedProxy.

@Test
public void testTargetClassScopedProxy() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyTargetClassTests.xml");
    context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
    // should be a class-based proxy
    assertTrue(AopUtils.isCglibProxy(bean));
    // test serializability
    assertEquals("bar", bean.foo(1));
    ScopedProxyTestBean deserialized = (ScopedProxyTestBean) SerializationTestUtils.serializeAndDeserialize(bean);
    assertNotNull(deserialized);
    assertEquals("bar", deserialized.foo(1));
    context.close();
}
Also used : SimpleMapScope(org.springframework.tests.context.SimpleMapScope) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ScopedProxyTestBean(example.scannable.ScopedProxyTestBean) Test(org.junit.Test)

Aggregations

ScopedProxyTestBean (example.scannable.ScopedProxyTestBean)3 Test (org.junit.Test)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 SimpleMapScope (org.springframework.tests.context.SimpleMapScope)3