Search in sources :

Example 26 with ITestBean

use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.

the class TraceBeforeAdvice method testRepeatedAroundAdviceInvocations.

private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
    ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated around advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    assertTrue(AopUtils.isAopProxy(adrian));
    assertEquals(68, adrian.getAge());
    for (int i = 0; i < howmany; i++) {
        adrian.getAge();
    }
    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) StopWatch(org.springframework.util.StopWatch)

Example 27 with ITestBean

use of org.springframework.tests.sample.beans.ITestBean 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 28 with ITestBean

use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.

the class AopNamespaceHandlerProxyTargetClassTests method testIsClassProxy.

@Test
public void testIsClassProxy() {
    ITestBean bean = getTestBean();
    assertTrue("Should be a CGLIB proxy", AopUtils.isCglibProxy(bean));
    assertTrue("Should expose proxy", ((Advised) bean).isExposeProxy());
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) Test(org.junit.Test)

Example 29 with ITestBean

use of org.springframework.tests.sample.beans.ITestBean 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 30 with ITestBean

use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.

the class AbstractAopProxyTests method testRejectsBogusDynamicIntroductionAdviceWithNoAdapter.

@Test
public void testRejectsBogusDynamicIntroductionAdviceWithNoAdapter() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);
    ProxyFactory pc = new ProxyFactory(target);
    pc.addAdvisor(new DefaultIntroductionAdvisor(new DummyIntroductionAdviceImpl(), Comparable.class));
    try {
        // TODO May fail on either call: may want to tighten up definition
        ITestBean proxied = (ITestBean) createProxy(pc);
        proxied.getName();
        fail("Bogus introduction");
    } catch (Exception ex) {
    // TODO used to catch UnknownAdviceTypeException, but
    // with CGLIB some errors are in proxy creation and are wrapped
    // in aspect exception. Error message is still fine.
    //assertTrue(ex.getMessage().indexOf("ntroduction") > -1);
    }
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) DefaultIntroductionAdvisor(org.springframework.aop.support.DefaultIntroductionAdvisor) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) MarshalException(java.rmi.MarshalException) IOException(java.io.IOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) LockedException(test.mixin.LockedException) Test(org.junit.Test)

Aggregations

ITestBean (org.springframework.tests.sample.beans.ITestBean)221 Test (org.junit.Test)205 TestBean (org.springframework.tests.sample.beans.TestBean)127 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)37 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 SerializableNopInterceptor (org.springframework.tests.aop.interceptor.SerializableNopInterceptor)24 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)21 IOException (java.io.IOException)15 Advisor (org.springframework.aop.Advisor)15 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)15 Method (java.lang.reflect.Method)14 ProxyFactory (org.springframework.aop.framework.ProxyFactory)14 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)14 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)13 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)13 MethodInvocation (org.aopalliance.intercept.MethodInvocation)12 Advised (org.springframework.aop.framework.Advised)12 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)11 LockedException (test.mixin.LockedException)11 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)10