Search in sources :

Example 46 with ProxyFactory

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

the class SimpleRemoteSlsbInvokerInterceptorTests method configuredProxy.

protected Object configuredProxy(SimpleRemoteSlsbInvokerInterceptor si, Class<?> ifc) throws NamingException {
    si.afterPropertiesSet();
    ProxyFactory pf = new ProxyFactory(new Class<?>[] { ifc });
    pf.addAdvice(si);
    return pf.getProxy();
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory)

Example 47 with ProxyFactory

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

the class LocalSlsbInvokerInterceptorTests method testInvokesMethodOnEjbInstance.

@Test
public void testInvokesMethodOnEjbInstance() throws Exception {
    Object retVal = new Object();
    LocalInterfaceWithBusinessMethods ejb = mock(LocalInterfaceWithBusinessMethods.class);
    given(ejb.targetMethod()).willReturn(retVal);
    String jndiName = "foobar";
    Context mockContext = mockContext(jndiName, ejb);
    LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
    ProxyFactory pf = new ProxyFactory(new Class<?>[] { BusinessMethods.class });
    pf.addAdvice(si);
    BusinessMethods target = (BusinessMethods) pf.getProxy();
    assertTrue(target.targetMethod() == retVal);
    verify(mockContext).close();
    verify(ejb).remove();
}
Also used : Context(javax.naming.Context) ProxyFactory(org.springframework.aop.framework.ProxyFactory) EJBLocalObject(javax.ejb.EJBLocalObject) Test(org.junit.Test)

Example 48 with ProxyFactory

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

the class ModelMapTests method testAopCglibProxy.

@Test
public void testAopCglibProxy() throws Exception {
    ModelMap map = new ModelMap();
    ProxyFactory factory = new ProxyFactory();
    SomeInnerClass val = new SomeInnerClass();
    factory.setTarget(val);
    factory.setProxyTargetClass(true);
    map.addAttribute(factory.getProxy());
    assertTrue(map.containsKey("someInnerClass"));
    assertEquals(val, map.get("someInnerClass"));
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Example 49 with ProxyFactory

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

the class ModelMapTests method testAopJdkProxy.

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

Example 50 with ProxyFactory

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

the class ModelMapTests method testAopJdkProxyWithMultipleInterfaces.

@Test
public void testAopJdkProxyWithMultipleInterfaces() throws Exception {
    ModelMap map = new ModelMap();
    Map<?, ?> target = new HashMap<>();
    ProxyFactory factory = new ProxyFactory();
    factory.setTarget(target);
    factory.addInterface(Serializable.class);
    factory.addInterface(Cloneable.class);
    factory.addInterface(Comparable.class);
    factory.addInterface(Map.class);
    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)

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