Search in sources :

Example 6 with Advised

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

the class TraceBeforeAdvice method testBeforeAdviceWithoutJoinPoint.

private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
    ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated before advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    assertTrue(AopUtils.isAopProxy(adrian));
    Advised a = (Advised) adrian;
    assertTrue(a.getAdvisors().length >= 3);
    assertEquals("adrian", adrian.getName());
    for (int i = 0; i < howmany; i++) {
        adrian.getName();
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised) StopWatch(org.springframework.util.StopWatch)

Example 7 with Advised

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

the class CountingAspectJAdvice method testIsProxy.

@Test
public void testIsProxy() throws Exception {
    ITestBean bean = getTestBean();
    assertTrue("Bean is not a proxy", AopUtils.isAopProxy(bean));
    // check the advice details
    Advised advised = (Advised) bean;
    Advisor[] advisors = advised.getAdvisors();
    assertTrue("Advisors should not be empty", advisors.length > 0);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) Advised(org.springframework.aop.framework.Advised) Advisor(org.springframework.aop.Advisor) Test(org.junit.Test)

Example 8 with Advised

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

the class JoinPointMonitorAtAspectJAspect method checkAtAspectJAspect.

private void checkAtAspectJAspect(String appContextFile) {
    ApplicationContext context = new ClassPathXmlApplicationContext(appContextFile, getClass());
    ICounter counter = (ICounter) context.getBean("counter");
    assertTrue("Proxy didn't get created", counter instanceof Advised);
    counter.increment();
    JoinPointMonitorAtAspectJAspect callCountingAspect = (JoinPointMonitorAtAspectJAspect) context.getBean("monitoringAspect");
    assertEquals("Advise didn't get executed", 1, callCountingAspect.beforeExecutions);
    assertEquals("Advise didn't get executed", 1, callCountingAspect.aroundExecutions);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised)

Example 9 with Advised

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

the class InterfaceExtendingAspect method testProxyCreation.

@Test
public void testProxyCreation() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
    ITestBean testBean = (ITestBean) ctx.getBean("testBean");
    AnInterface interfaceExtendingAspect = (AnInterface) ctx.getBean("interfaceExtendingAspect");
    assertTrue(testBean instanceof Advised);
    assertFalse(interfaceExtendingAspect instanceof Advised);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised) Test(org.junit.Test)

Example 10 with Advised

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

the class TestNamespaceHandler method testProxyingDecorator.

@Test
public void testProxyingDecorator() throws Exception {
    ITestBean bean = (ITestBean) this.beanFactory.getBean("debuggingTestBean");
    assertTestBean(bean);
    assertTrue(AopUtils.isAopProxy(bean));
    Advisor[] advisors = ((Advised) bean).getAdvisors();
    assertEquals("Incorrect number of advisors", 1, advisors.length);
    assertEquals("Incorrect advice class", DebugInterceptor.class, advisors[0].getAdvice().getClass());
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) Advised(org.springframework.aop.framework.Advised) Advisor(org.springframework.aop.Advisor) Test(org.junit.Test)

Aggregations

Advised (org.springframework.aop.framework.Advised)35 Test (org.junit.Test)22 ITestBean (org.springframework.tests.sample.beans.ITestBean)15 Advisor (org.springframework.aop.Advisor)10 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)10 TestBean (org.springframework.tests.sample.beans.TestBean)4 JoinPoint (org.aspectj.lang.JoinPoint)3 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)3 SyntheticInstantiationAdvisor (org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor)3 ProxyFactory (org.springframework.aop.framework.ProxyFactory)3 ApplicationContext (org.springframework.context.ApplicationContext)3 Person (org.springframework.tests.sample.beans.Person)3 StopWatch (org.springframework.util.StopWatch)3 PrototypeTargetSource (org.springframework.aop.target.PrototypeTargetSource)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 AnotherTestEvent (org.springframework.context.event.test.AnotherTestEvent)2 TestEvent (org.springframework.context.event.test.TestEvent)2 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)2 SerializableNopInterceptor (org.springframework.tests.aop.interceptor.SerializableNopInterceptor)2 SerializablePerson (org.springframework.tests.sample.beans.SerializablePerson)2