Search in sources :

Example 51 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class ModelMapTests method testAopJdkProxyWithDetectedInterfaces.

@Test
public void testAopJdkProxyWithDetectedInterfaces() throws Exception {
    ModelMap map = new ModelMap();
    Map<?, ?> target = new HashMap<>();
    ProxyFactory factory = new ProxyFactory(target);
    Object proxy = factory.getProxy();
    map.addAttribute(proxy);
    assertSame(proxy, map.get("map"));
}
Also used : HashMap(java.util.HashMap) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Example 52 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class GroovyAspectTests method testAdvice.

private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message, boolean proxyTargetClass) throws Exception {
    logAdvice.reset();
    ProxyFactory factory = new ProxyFactory(target);
    factory.setProxyTargetClass(proxyTargetClass);
    factory.addAdvisor(advisor);
    TestService bean = (TestService) factory.getProxy();
    assertEquals(0, logAdvice.getCountThrows());
    try {
        bean.sayHello();
        fail("Expected exception");
    } catch (TestException ex) {
        assertEquals(message, ex.getMessage());
    }
    assertEquals(1, logAdvice.getCountThrows());
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory)

Example 53 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class FormattingConversionServiceTests method proxiedConverterFactory.

@Test
public void proxiedConverterFactory() {
    ConverterFactory<?, ?> converterFactory = new IntegerConverterFactory();
    formattingService.addConverterFactory((ConverterFactory<?, ?>) new ProxyFactory(converterFactory).getProxy());
    assertEquals(Integer.valueOf(1), formattingService.convert("1", Integer.class));
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Example 54 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class AopTestUtilsTests method cglibProxy.

private Foo cglibProxy(Foo foo) {
    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(foo);
    pf.setProxyTargetClass(true);
    Foo proxy = (Foo) pf.getProxy();
    assertTrue("Proxy is a CGLIB proxy", AopUtils.isCglibProxy(proxy));
    assertThat(proxy, instanceOf(FooImpl.class));
    return proxy;
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory)

Example 55 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class ReflectionTestUtilsTests method setFieldAndGetFieldViaCglibProxy.

@Test
public void setFieldAndGetFieldViaCglibProxy() throws Exception {
    ProxyFactory pf = new ProxyFactory(this.person);
    pf.setProxyTargetClass(true);
    Person proxy = (Person) pf.getProxy();
    assertTrue("Proxy is a CGLIB proxy", AopUtils.isCglibProxy(proxy));
    assertSetFieldAndGetFieldBehaviorForProxy(proxy, this.person);
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) Person(org.springframework.test.util.subpackage.Person) Test(org.junit.Test)

Aggregations

ProxyFactory (org.springframework.aop.framework.ProxyFactory)81 Test (org.junit.Test)49 ITestBean (org.springframework.tests.sample.beans.ITestBean)20 TestBean (org.springframework.tests.sample.beans.TestBean)20 TimeStamped (org.springframework.tests.TimeStamped)8 INestedTestBean (org.springframework.tests.sample.beans.INestedTestBean)8 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)8 Method (java.lang.reflect.Method)6 HashMap (java.util.HashMap)5 MethodBeforeAdvice (org.springframework.aop.MethodBeforeAdvice)4 Context (javax.naming.Context)3 TargetSource (org.springframework.aop.TargetSource)3 Advised (org.springframework.aop.framework.Advised)3 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)3 Factory (org.springframework.cglib.proxy.Factory)3 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)3 IOException (java.io.IOException)2 EJBLocalObject (javax.ejb.EJBLocalObject)2 Message (javax.jms.Message)2 TextMessage (javax.jms.TextMessage)2