Search in sources :

Example 71 with ITestBean

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

the class BeanFactoryTransactionTests method testGetsAreNotTransactionalWithProxyFactory3.

@Test
public void testGetsAreNotTransactionalWithProxyFactory3() throws NoSuchMethodException {
    ITestBean testBean = (ITestBean) factory.getBean("proxyFactory3");
    assertTrue("testBean is a full proxy", testBean instanceof DerivedTestBean);
    assertTrue(testBean instanceof TransactionalProxy);
    InvocationCounterPointcut txnCounter = (InvocationCounterPointcut) factory.getBean("txnInvocationCounterPointcut");
    InvocationCounterInterceptor preCounter = (InvocationCounterInterceptor) factory.getBean("preInvocationCounterInterceptor");
    InvocationCounterInterceptor postCounter = (InvocationCounterInterceptor) factory.getBean("postInvocationCounterInterceptor");
    txnCounter.counter = 0;
    preCounter.counter = 0;
    postCounter.counter = 0;
    doTestGetsAreNotTransactional(testBean);
    // Can't assert it's equal to 4 as the pointcut may be optimized and only invoked once
    assertTrue(0 < txnCounter.counter && txnCounter.counter <= 4);
    assertEquals(4, preCounter.counter);
    assertEquals(4, postCounter.counter);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) Test(org.junit.Test)

Example 72 with ITestBean

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

the class BeanFactoryTransactionTests method testGetsAreNotTransactionalWithProxyFactory1.

@Test
public void testGetsAreNotTransactionalWithProxyFactory1() throws NoSuchMethodException {
    ITestBean testBean = (ITestBean) factory.getBean("proxyFactory1");
    assertTrue("testBean is a dynamic proxy", Proxy.isProxyClass(testBean.getClass()));
    assertFalse(testBean instanceof TransactionalProxy);
    doTestGetsAreNotTransactional(testBean);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) Test(org.junit.Test)

Example 73 with ITestBean

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

the class BeanFactoryTransactionTests method testGetsAreNotTransactionalWithProxyFactory2Cglib.

@Test
public void testGetsAreNotTransactionalWithProxyFactory2Cglib() throws NoSuchMethodException {
    ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2Cglib");
    assertTrue("testBean is CGLIB advised", AopUtils.isCglibProxy(testBean));
    assertTrue(testBean instanceof TransactionalProxy);
    doTestGetsAreNotTransactional(testBean);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) Test(org.junit.Test)

Example 74 with ITestBean

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

the class BeanFactoryTransactionTests method testProxyFactory2Lazy.

@Test
public void testProxyFactory2Lazy() throws NoSuchMethodException {
    ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2Lazy");
    assertFalse(factory.containsSingleton("target"));
    assertEquals(666, testBean.getAge());
    assertTrue(factory.containsSingleton("target"));
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) Test(org.junit.Test)

Example 75 with ITestBean

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

the class PerThisAspect method testFailureWithoutExplicitDeclarePrecedence.

@Test
public void testFailureWithoutExplicitDeclarePrecedence() {
    TestBean target = new TestBean();
    MetadataAwareAspectInstanceFactory aspectInstanceFactory = new SingletonMetadataAwareAspectInstanceFactory(new NoDeclarePrecedenceShouldFail(), "someBean");
    ITestBean itb = (ITestBean) createProxy(target, getFixture().getAdvisors(aspectInstanceFactory), ITestBean.class);
    itb.getAge();
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) 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