Search in sources :

Example 11 with SimpleMapScope

use of org.springframework.context.testfixture.SimpleMapScope 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
    assertThat(AopUtils.isAopProxy(bean)).isFalse();
    context.close();
}
Also used : SimpleMapScope(org.springframework.context.testfixture.SimpleMapScope) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ScopedProxyTestBean(example.scannable.ScopedProxyTestBean) Test(org.junit.jupiter.api.Test)

Example 12 with SimpleMapScope

use of org.springframework.context.testfixture.SimpleMapScope 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
    assertThat(AopUtils.isCglibProxy(bean)).isTrue();
    // test serializability
    assertThat(bean.foo(1)).isEqualTo("bar");
    ScopedProxyTestBean deserialized = SerializationTestUtils.serializeAndDeserialize(bean);
    assertThat(deserialized).isNotNull();
    assertThat(deserialized.foo(1)).isEqualTo("bar");
    context.close();
}
Also used : SimpleMapScope(org.springframework.context.testfixture.SimpleMapScope) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ScopedProxyTestBean(example.scannable.ScopedProxyTestBean) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)12 SimpleMapScope (org.springframework.context.testfixture.SimpleMapScope)12 FooService (example.scannable.FooService)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 ScopedProxyTestBean (example.scannable.ScopedProxyTestBean)3 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)3 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)2 TestBean (org.springframework.beans.testfixture.beans.TestBean)2 ArrayList (java.util.ArrayList)1 ScopedObject (org.springframework.aop.scope.ScopedObject)1 FactoryMethodComponent (org.springframework.context.annotation4.FactoryMethodComponent)1