org.springframework.aop.framework.Advised

Here are the examples of the java api org.springframework.aop.framework.Advised taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

50 Examples 7

19 Source : ScriptingDefaultsTests.java
with MIT License
from Vip-Augus

@Test
public void defaultRefreshCheckDelay() throws Exception {
    ApplicationContext context = new ClreplacedPathXmlApplicationContext(CONFIG);
    Advised advised = (Advised) context.getBean("testBean");
    AbstractRefreshableTargetSource targetSource = ((AbstractRefreshableTargetSource) advised.getTargetSource());
    Field field = AbstractRefreshableTargetSource.clreplaced.getDeclaredField("refreshCheckDelay");
    field.setAccessible(true);
    long delay = ((Long) field.get(targetSource)).longValue();
    replacedertEquals(5000L, delay);
}

19 Source : AdvisorAutoProxyCreatorTests.java
with MIT License
from Vip-Augus

@Test
public void testQuickTargetSourceCreator() throws Exception {
    ClreplacedPathXmlApplicationContext bf = new ClreplacedPathXmlApplicationContext(QUICK_TARGETSOURCE_CONTEXT, CLreplaced);
    ITestBean test = (ITestBean) bf.getBean("test");
    replacedertFalse(AopUtils.isAopProxy(test));
    replacedertEquals("Rod", test.getName());
    // Check that references survived pooling
    replacedertEquals("Kerry", test.getSpouse().getName());
    // Now test the pooled one
    test = (ITestBean) bf.getBean(":test");
    replacedertTrue(AopUtils.isAopProxy(test));
    Advised advised = (Advised) test;
    replacedertTrue(advised.getTargetSource() instanceof CommonsPool2TargetSource);
    replacedertEquals("Rod", test.getName());
    // Check that references survived pooling
    replacedertEquals("Kerry", test.getSpouse().getName());
    // Now test the ThreadLocal one
    test = (ITestBean) bf.getBean("%test");
    replacedertTrue(AopUtils.isAopProxy(test));
    advised = (Advised) test;
    replacedertTrue(advised.getTargetSource() instanceof ThreadLocalTargetSource);
    replacedertEquals("Rod", test.getName());
    // Check that references survived pooling
    replacedertEquals("Kerry", test.getSpouse().getName());
    // Now test the Prototype TargetSource
    test = (ITestBean) bf.getBean("!test");
    replacedertTrue(AopUtils.isAopProxy(test));
    advised = (Advised) test;
    replacedertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
    replacedertEquals("Rod", test.getName());
    // Check that references survived pooling
    replacedertEquals("Kerry", test.getSpouse().getName());
    ITestBean test2 = (ITestBean) bf.getBean("!test");
    replacedertFalse("Prototypes cannot be the same object", test == test2);
    replacedertEquals("Rod", test2.getName());
    replacedertEquals("Kerry", test2.getSpouse().getName());
    bf.close();
}

19 Source : AdvisorAdapterRegistrationTests.java
with MIT License
from Vip-Augus

private SimpleBeforeAdviceImpl getAdviceImpl(ITestBean tb) {
    Advised advised = (Advised) tb;
    Advisor advisor = advised.getAdvisors()[0];
    return (SimpleBeforeAdviceImpl) advisor.getAdvice();
}

19 Source : BenchmarkTests.java
with MIT License
from Vip-Augus

private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
    ClreplacedPathXmlApplicationContext bf = new ClreplacedPathXmlApplicationContext(file, CLreplaced);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated after returning advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    replacedertTrue(AopUtils.isAopProxy(adrian));
    Advised a = (Advised) adrian;
    replacedertTrue(a.getAdvisors().length >= 3);
    // Hits joinpoint
    adrian.setAge(25);
    for (int i = 0; i < howmany; i++) {
        adrian.setAge(i);
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}

19 Source : BenchmarkTests.java
with MIT License
from Vip-Augus

private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
    ClreplacedPathXmlApplicationContext bf = new ClreplacedPathXmlApplicationContext(file, CLreplaced);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated before advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    replacedertTrue(AopUtils.isAopProxy(adrian));
    Advised a = (Advised) adrian;
    replacedertTrue(a.getAdvisors().length >= 3);
    replacedertEquals("adrian", adrian.getName());
    for (int i = 0; i < howmany; i++) {
        adrian.getName();
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}

19 Source : AbstractAspectJAdvisorFactoryTests.java
with MIT License
from Vip-Augus

@Test
public void testPerThisAspect() throws SecurityException, NoSuchMethodException {
    TestBean target = new TestBean();
    int realAge = 65;
    target.setAge(realAge);
    TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerThisAspect(), "someBean")), TestBean.clreplaced);
    replacedertEquals("Around advice must NOT apply", realAge, itb.getAge());
    Advised advised = (Advised) itb;
    // Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
    replacedertEquals(4, advised.getAdvisors().length);
    ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia = (ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
    replacedertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
    LazySingletonAspectInstanceFactoryDecorator maaif = (LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
    replacedertFalse(maaif.isMaterialized());
    // Check that the perclause pointcut is valid
    replacedertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    replacedertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
    // Hit the method in the per clause to instantiate the aspect
    itb.getSpouse();
    replacedertTrue(maaif.isMaterialized());
    replacedertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getAge"), null));
    replacedertEquals("Around advice must apply", 0, itb.getAge());
    replacedertEquals("Around advice must apply", 1, itb.getAge());
}

19 Source : AbstractAspectJAdvisorFactoryTests.java
with MIT License
from Vip-Augus

@Test
public void testPerTypeWithinAspect() throws SecurityException, NoSuchMethodException {
    TestBean target = new TestBean();
    int realAge = 65;
    target.setAge(realAge);
    PerTypeWithinAspectInstanceFactory aif = new PerTypeWithinAspectInstanceFactory();
    TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.clreplaced);
    replacedertEquals("No method calls", 0, aif.getInstantiationCount());
    replacedertEquals("Around advice must now apply", 0, itb.getAge());
    Advised advised = (Advised) itb;
    // Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
    replacedertEquals(4, advised.getAdvisors().length);
    ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia = (ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
    replacedertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
    LazySingletonAspectInstanceFactoryDecorator maaif = (LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
    replacedertTrue(maaif.isMaterialized());
    // Check that the perclause pointcut is valid
    replacedertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    replacedertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
    // Hit the method in the per clause to instantiate the aspect
    itb.getSpouse();
    replacedertTrue(maaif.isMaterialized());
    replacedertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getAge"), null));
    replacedertEquals("Around advice must still apply", 1, itb.getAge());
    replacedertEquals("Around advice must still apply", 2, itb.getAge());
    TestBean itb2 = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.clreplaced);
    replacedertEquals(1, aif.getInstantiationCount());
    replacedertEquals("Around advice be independent for second instance", 0, itb2.getAge());
    replacedertEquals(2, aif.getInstantiationCount());
}

19 Source : AbstractAspectJAdvisorFactoryTests.java
with MIT License
from Vip-Augus

@Test
public void testPerTargetAspect() throws SecurityException, NoSuchMethodException {
    TestBean target = new TestBean();
    int realAge = 65;
    target.setAge(realAge);
    TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean")), TestBean.clreplaced);
    replacedertEquals("Around advice must NOT apply", realAge, itb.getAge());
    Advised advised = (Advised) itb;
    ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia = (ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
    replacedertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[3];
    LazySingletonAspectInstanceFactoryDecorator maaif = (LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
    replacedertFalse(maaif.isMaterialized());
    // Check that the perclause pointcut is valid
    replacedertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    replacedertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
    // Hit the method in the per clause to instantiate the aspect
    itb.getSpouse();
    replacedertTrue(maaif.isMaterialized());
    replacedertEquals("Around advice must apply", 0, itb.getAge());
    replacedertEquals("Around advice must apply", 1, itb.getAge());
}

19 Source : CommonsPool2TargetSourceTests.java
with Apache License 2.0
from SourceHot

@Test
public void testHitMaxSizeLoadedFromContext() throws Exception {
    Advised person = (Advised) beanFactory.getBean("maxSizePooledPerson");
    CommonsPool2TargetSource targetSource = (CommonsPool2TargetSource) person.getTargetSource();
    int maxSize = targetSource.getMaxSize();
    Object[] pooledInstances = new Object[maxSize];
    for (int x = 0; x < maxSize; x++) {
        Object instance = targetSource.getTarget();
        replacedertThat(instance).isNotNull();
        pooledInstances[x] = instance;
    }
    // should be at maximum now
    replacedertThatExceptionOfType(NoSuchElementException.clreplaced).isThrownBy(targetSource::getTarget);
    // lets now release an object and try to acquire a new one
    targetSource.releaseTarget(pooledInstances[9]);
    pooledInstances[9] = targetSource.getTarget();
    // release all objects
    for (int i = 0; i < pooledInstances.length; i++) {
        System.out.println(i);
        targetSource.releaseTarget(pooledInstances[i]);
    }
}

19 Source : BenchmarkTests.java
with Apache License 2.0
from SourceHot

private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
    ClreplacedPathXmlApplicationContext bf = new ClreplacedPathXmlApplicationContext(file, CLreplaced);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated after returning advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    replacedertThat(AopUtils.isAopProxy(adrian)).isTrue();
    Advised a = (Advised) adrian;
    replacedertThat(a.getAdvisors().length >= 3).isTrue();
    // Hits joinpoint
    adrian.setAge(25);
    for (int i = 0; i < howmany; i++) {
        adrian.setAge(i);
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}

19 Source : AbstractAspectJAdvisorFactoryTests.java
with Apache License 2.0
from SourceHot

@Test
public void testPerThisAspect() throws SecurityException, NoSuchMethodException {
    TestBean target = new TestBean();
    int realAge = 65;
    target.setAge(realAge);
    TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerThisAspect(), "someBean")), TestBean.clreplaced);
    replacedertThat(itb.getAge()).as("Around advice must NOT apply").isEqualTo(realAge);
    Advised advised = (Advised) itb;
    // Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
    replacedertThat(advised.getAdvisors().length).isEqualTo(4);
    ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia = (ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
    replacedertThat(sia.getPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null)).isTrue();
    InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
    LazySingletonAspectInstanceFactoryDecorator maaif = (LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
    replacedertThat(maaif.isMaterialized()).isFalse();
    // Check that the perclause pointcut is valid
    replacedertThat(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null)).isTrue();
    replacedertThat(imapa.getPointcut()).isNotSameAs(imapa.getDeclaredPointcut());
    // Hit the method in the per clause to instantiate the aspect
    itb.getSpouse();
    replacedertThat(maaif.isMaterialized()).isTrue();
    replacedertThat(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getAge"), null)).isTrue();
    replacedertThat(itb.getAge()).as("Around advice must apply").isEqualTo(0);
    replacedertThat(itb.getAge()).as("Around advice must apply").isEqualTo(1);
}

19 Source : AbstractAspectJAdvisorFactoryTests.java
with Apache License 2.0
from SourceHot

@Test
public void testPerTypeWithinAspect() throws SecurityException, NoSuchMethodException {
    TestBean target = new TestBean();
    int realAge = 65;
    target.setAge(realAge);
    PerTypeWithinAspectInstanceFactory aif = new PerTypeWithinAspectInstanceFactory();
    TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.clreplaced);
    replacedertThat(aif.getInstantiationCount()).as("No method calls").isEqualTo(0);
    replacedertThat(itb.getAge()).as("Around advice must now apply").isEqualTo(0);
    Advised advised = (Advised) itb;
    // Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
    replacedertThat(advised.getAdvisors().length).isEqualTo(4);
    ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia = (ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
    replacedertThat(sia.getPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null)).isTrue();
    InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
    LazySingletonAspectInstanceFactoryDecorator maaif = (LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
    replacedertThat(maaif.isMaterialized()).isTrue();
    // Check that the perclause pointcut is valid
    replacedertThat(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null)).isTrue();
    replacedertThat(imapa.getPointcut()).isNotSameAs(imapa.getDeclaredPointcut());
    // Hit the method in the per clause to instantiate the aspect
    itb.getSpouse();
    replacedertThat(maaif.isMaterialized()).isTrue();
    replacedertThat(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getAge"), null)).isTrue();
    replacedertThat(itb.getAge()).as("Around advice must still apply").isEqualTo(1);
    replacedertThat(itb.getAge()).as("Around advice must still apply").isEqualTo(2);
    TestBean itb2 = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.clreplaced);
    replacedertThat(aif.getInstantiationCount()).isEqualTo(1);
    replacedertThat(itb2.getAge()).as("Around advice be independent for second instance").isEqualTo(0);
    replacedertThat(aif.getInstantiationCount()).isEqualTo(2);
}

19 Source : AbstractAspectJAdvisorFactoryTests.java
with Apache License 2.0
from SourceHot

@Test
public void testPerTargetAspect() throws SecurityException, NoSuchMethodException {
    TestBean target = new TestBean();
    int realAge = 65;
    target.setAge(realAge);
    TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean")), TestBean.clreplaced);
    replacedertThat(itb.getAge()).as("Around advice must NOT apply").isEqualTo(realAge);
    Advised advised = (Advised) itb;
    ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia = (ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
    replacedertThat(sia.getPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null)).isTrue();
    InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[3];
    LazySingletonAspectInstanceFactoryDecorator maaif = (LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
    replacedertThat(maaif.isMaterialized()).isFalse();
    // Check that the perclause pointcut is valid
    replacedertThat(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null)).isTrue();
    replacedertThat(imapa.getPointcut()).isNotSameAs(imapa.getDeclaredPointcut());
    // Hit the method in the per clause to instantiate the aspect
    itb.getSpouse();
    replacedertThat(maaif.isMaterialized()).isTrue();
    replacedertThat(itb.getAge()).as("Around advice must apply").isEqualTo(0);
    replacedertThat(itb.getAge()).as("Around advice must apply").isEqualTo(1);
}

19 Source : ServiceTestBase.java
with GNU Lesser General Public License v2.1
from phoenixctms

protected Object getServiceImpl(Object serviceProxy) {
    try {
        Advised proxy = (Advised) serviceProxy;
        return proxy.getTargetSource().getTarget();
    } catch (Exception e) {
        throw new Error("Could not get implementation clreplaced from service proxy!", e);
    }
}

19 Source : AbstractAspectJAdvisorFactoryTests.java
with Apache License 2.0
from langtianya

@Test
public void testPerTypeWithinAspect() throws SecurityException, NoSuchMethodException {
    TestBean target = new TestBean();
    int realAge = 65;
    target.setAge(realAge);
    PerTypeWithinAspectInstanceFactory aif = new PerTypeWithinAspectInstanceFactory();
    TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.clreplaced);
    replacedertEquals("No method calls", 0, aif.getInstantiationCount());
    replacedertEquals("Around advice must now apply", 0, itb.getAge());
    Advised advised = (Advised) itb;
    // Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
    replacedertEquals(4, advised.getAdvisors().length);
    SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
    replacedertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
    LazySingletonAspectInstanceFactoryDecorator maaif = (LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
    replacedertTrue(maaif.isMaterialized());
    // Check that the perclause pointcut is valid
    replacedertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    replacedertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
    // Hit the method in the per clause to instantiate the aspect
    itb.getSpouse();
    replacedertTrue(maaif.isMaterialized());
    replacedertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getAge"), null));
    replacedertEquals("Around advice must still apply", 1, itb.getAge());
    replacedertEquals("Around advice must still apply", 2, itb.getAge());
    TestBean itb2 = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.clreplaced);
    replacedertEquals(1, aif.getInstantiationCount());
    replacedertEquals("Around advice be independent for second instance", 0, itb2.getAge());
    replacedertEquals(2, aif.getInstantiationCount());
}

19 Source : AbstractAspectJAdvisorFactoryTests.java
with Apache License 2.0
from langtianya

@Test
public void testPerThisAspect() throws SecurityException, NoSuchMethodException {
    TestBean target = new TestBean();
    int realAge = 65;
    target.setAge(realAge);
    TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerThisAspect(), "someBean")), TestBean.clreplaced);
    replacedertEquals("Around advice must NOT apply", realAge, itb.getAge());
    Advised advised = (Advised) itb;
    // Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
    replacedertEquals(4, advised.getAdvisors().length);
    SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
    replacedertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
    LazySingletonAspectInstanceFactoryDecorator maaif = (LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
    replacedertFalse(maaif.isMaterialized());
    // Check that the perclause pointcut is valid
    replacedertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    replacedertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
    // Hit the method in the per clause to instantiate the aspect
    itb.getSpouse();
    replacedertTrue(maaif.isMaterialized());
    replacedertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getAge"), null));
    replacedertEquals("Around advice must apply", 0, itb.getAge());
    replacedertEquals("Around advice must apply", 1, itb.getAge());
}

19 Source : AbstractAspectJAdvisorFactoryTests.java
with Apache License 2.0
from langtianya

@Test
public void testPerTargetAspect() throws SecurityException, NoSuchMethodException {
    TestBean target = new TestBean();
    int realAge = 65;
    target.setAge(realAge);
    TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean")), TestBean.clreplaced);
    replacedertEquals("Around advice must NOT apply", realAge, itb.getAge());
    Advised advised = (Advised) itb;
    SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
    replacedertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[3];
    LazySingletonAspectInstanceFactoryDecorator maaif = (LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
    replacedertFalse(maaif.isMaterialized());
    // Check that the perclause pointcut is valid
    replacedertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.clreplaced.getMethod("getSpouse"), null));
    replacedertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
    // Hit the method in the per clause to instantiate the aspect
    itb.getSpouse();
    replacedertTrue(maaif.isMaterialized());
    replacedertEquals("Around advice must apply", 0, itb.getAge());
    replacedertEquals("Around advice must apply", 1, itb.getAge());
}

19 Source : AmazonS3ProxyFactoryTest.java
with Apache License 2.0
from awspring

@Test
void verifyBasicAdvice() throws Exception {
    AmazonS3 amazonS3 = mock(AmazonS3.clreplaced);
    replacedertThat(AopUtils.isAopProxy(amazonS3)).isFalse();
    AmazonS3 proxy = AmazonS3ProxyFactory.createProxy(amazonS3);
    replacedertThat(AopUtils.isAopProxy(proxy)).isTrue();
    Advised advised = (Advised) proxy;
    replacedertThat(advised.getAdvisors().length).isEqualTo(1);
    replacedertThat(advised.getAdvisors()[0].getAdvice()).isInstanceOf(AmazonS3ProxyFactory.SimpleStorageRedirectInterceptor.clreplaced);
    replacedertThat(AopUtils.isAopProxy(advised.getTargetSource().getTarget())).isFalse();
}

19 Source : AmazonS3ProxyFactoryTest.java
with Apache License 2.0
from awspring

@Test
void verifyDoubleWrappingHandled() throws Exception {
    AmazonS3 amazonS3 = mock(AmazonS3.clreplaced);
    AmazonS3 proxy = AmazonS3ProxyFactory.createProxy(AmazonS3ProxyFactory.createProxy(amazonS3));
    replacedertThat(AopUtils.isAopProxy(proxy)).isTrue();
    Advised advised = (Advised) proxy;
    replacedertThat(advised.getAdvisors().length).isEqualTo(1);
    replacedertThat(advised.getAdvisors()[0].getAdvice()).isInstanceOf(AmazonS3ProxyFactory.SimpleStorageRedirectInterceptor.clreplaced);
    replacedertThat(AopUtils.isAopProxy(advised.getTargetSource().getTarget())).isFalse();
}

19 Source : AmazonS3ClientFactory.java
with Apache License 2.0
from awspring

private static AmazonS3Client getAmazonS3ClientFromProxy(AmazonS3 amazonS3) {
    if (AopUtils.isAopProxy(amazonS3)) {
        Advised advised = (Advised) amazonS3;
        Object target = null;
        try {
            target = advised.getTargetSource().getTarget();
        } catch (Exception e) {
            return null;
        }
        return target instanceof AmazonS3Client ? (AmazonS3Client) target : null;
    } else {
        return amazonS3 instanceof AmazonS3Client ? (AmazonS3Client) amazonS3 : null;
    }
}

19 Source : SpringWorkflowDefinitionFactoryFactory.java
with Apache License 2.0
from aws

public void addWorkflowImplementation(Object workflowImplementation) throws InstantiationException, IllegalAccessException {
    Clreplaced<? extends Object> implementationClreplaced;
    if (workflowImplementation instanceof Advised) {
        Advised advised = (Advised) workflowImplementation;
        // Cannot use advised.getTargetClreplaced() as the following configuration:
        // 
        // @Bean(name="workflowImpl", autowire=Autowire.BY_TYPE)
        // @Scope(value="workflow", proxyMode=ScopedProxyMode.INTERFACES)
        // public MyWorkflow myWorkflow() {
        // return new MyWorkflowImpl();
        // }
        // 
        // returns MyWorkflow.clreplaced when
        // we need MyWorkflowImpl.clreplaced
        // So the workaround is to instantiate workflow implementation which requires
        // initialization of the WorkflowScope with a context.
        try {
            WorkflowScope.setDecisionContext(new DummyDecisionContext());
            Object target = advised.getTargetSource().getTarget();
            implementationClreplaced = target.getClreplaced();
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        } finally {
            WorkflowScope.removeDecisionContext();
        }
    } else {
        implementationClreplaced = workflowImplementation.getClreplaced();
    }
    workflowImplementations.put(implementationClreplaced, workflowImplementation);
    impl.addWorkflowImplementationType(implementationClreplaced);
}

18 Source : PersistenceExceptionTranslationPostProcessorTests.java
with MIT License
from Vip-Augus

protected void checkWillTranslateExceptions(Object o) {
    replacedertTrue(o instanceof Advised);
    Advised a = (Advised) o;
    for (Advisor advisor : a.getAdvisors()) {
        if (advisor instanceof PersistenceExceptionTranslationAdvisor) {
            return;
        }
    }
    fail("No translation");
}

18 Source : AdvisorAutoProxyCreatorTests.java
with MIT License
from Vip-Augus

@Test
public void testCustomPrototypeTargetSource() throws Exception {
    CountingTestBean.count = 0;
    BeanFactory bf = new ClreplacedPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLreplaced);
    ITestBean test = (ITestBean) bf.getBean("prototypeTest");
    replacedertTrue(AopUtils.isAopProxy(test));
    Advised advised = (Advised) test;
    replacedertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
    replacedertEquals("Rod", test.getName());
    // Check that references survived prototype creation
    replacedertEquals("Kerry", test.getSpouse().getName());
    replacedertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count);
    CountingTestBean.count = 0;
}

18 Source : AdvisorAutoProxyCreatorTests.java
with MIT License
from Vip-Augus

@Test
public void testLazyInitTargetSource() throws Exception {
    CountingTestBean.count = 0;
    BeanFactory bf = new ClreplacedPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLreplaced);
    ITestBean test = (ITestBean) bf.getBean("lazyInitTest");
    replacedertTrue(AopUtils.isAopProxy(test));
    Advised advised = (Advised) test;
    replacedertTrue(advised.getTargetSource() instanceof LazyInitTargetSource);
    replacedertEquals("No CountingTestBean instantiated yet", 0, CountingTestBean.count);
    replacedertEquals("Rod", test.getName());
    replacedertEquals("Kerry", test.getSpouse().getName());
    replacedertEquals("Only 1 CountingTestBean instantiated", 1, CountingTestBean.count);
    CountingTestBean.count = 0;
}

18 Source : BenchmarkTests.java
with MIT License
from Vip-Augus

private long testMix(String file, int howmany, String technology) {
    ClreplacedPathXmlApplicationContext bf = new ClreplacedPathXmlApplicationContext(file, CLreplaced);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated mixed invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    replacedertTrue(AopUtils.isAopProxy(adrian));
    Advised a = (Advised) adrian;
    replacedertTrue(a.getAdvisors().length >= 3);
    for (int i = 0; i < howmany; i++) {
        // Hit all 3 joinpoints
        adrian.getAge();
        adrian.getName();
        adrian.setAge(i);
        // Invoke three non-advised methods
        adrian.getDoctor();
        adrian.getLawyer();
        adrian.getSpouse();
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}

18 Source : AnnotationTransactionAttributeSourceTests.java
with Apache License 2.0
from SourceHot

@Test
public void serializable() throws Exception {
    TestBean1 tb = new TestBean1();
    CallCountingTransactionManager ptm = new CallCountingTransactionManager();
    AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
    TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(ITestBean1.clreplaced);
    proxyFactory.addAdvice(ti);
    proxyFactory.setTarget(tb);
    ITestBean1 proxy = (ITestBean1) proxyFactory.getProxy();
    proxy.getAge();
    replacedertThat(ptm.commits).isEqualTo(1);
    ITestBean1 serializedProxy = (ITestBean1) SerializationTestUtils.serializeAndDeserialize(proxy);
    serializedProxy.getAge();
    Advised advised = (Advised) serializedProxy;
    TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
    CallCountingTransactionManager serializedPtm = (CallCountingTransactionManager) serializedTi.getTransactionManager();
    replacedertThat(serializedPtm.commits).isEqualTo(2);
}

18 Source : ScriptingDefaultsTests.java
with Apache License 2.0
from SourceHot

@Test
public void defaultRefreshCheckDelay() throws Exception {
    ApplicationContext context = new ClreplacedPathXmlApplicationContext(CONFIG);
    Advised advised = (Advised) context.getBean("testBean");
    AbstractRefreshableTargetSource targetSource = ((AbstractRefreshableTargetSource) advised.getTargetSource());
    Field field = AbstractRefreshableTargetSource.clreplaced.getDeclaredField("refreshCheckDelay");
    field.setAccessible(true);
    long delay = ((Long) field.get(targetSource)).longValue();
    replacedertThat(delay).isEqualTo(5000L);
}

18 Source : AdvisorAutoProxyCreatorTests.java
with Apache License 2.0
from SourceHot

@Test
public void testQuickTargetSourceCreator() throws Exception {
    ClreplacedPathXmlApplicationContext bf = new ClreplacedPathXmlApplicationContext(QUICK_TARGETSOURCE_CONTEXT, CLreplaced);
    ITestBean test = (ITestBean) bf.getBean("test");
    replacedertThat(AopUtils.isAopProxy(test)).isFalse();
    replacedertThat(test.getName()).isEqualTo("Rod");
    // Check that references survived pooling
    replacedertThat(test.getSpouse().getName()).isEqualTo("Kerry");
    // Now test the pooled one
    test = (ITestBean) bf.getBean(":test");
    replacedertThat(AopUtils.isAopProxy(test)).isTrue();
    Advised advised = (Advised) test;
    boolean condition2 = advised.getTargetSource() instanceof CommonsPool2TargetSource;
    replacedertThat(condition2).isTrue();
    replacedertThat(test.getName()).isEqualTo("Rod");
    // Check that references survived pooling
    replacedertThat(test.getSpouse().getName()).isEqualTo("Kerry");
    // Now test the ThreadLocal one
    test = (ITestBean) bf.getBean("%test");
    replacedertThat(AopUtils.isAopProxy(test)).isTrue();
    advised = (Advised) test;
    boolean condition1 = advised.getTargetSource() instanceof ThreadLocalTargetSource;
    replacedertThat(condition1).isTrue();
    replacedertThat(test.getName()).isEqualTo("Rod");
    // Check that references survived pooling
    replacedertThat(test.getSpouse().getName()).isEqualTo("Kerry");
    // Now test the Prototype TargetSource
    test = (ITestBean) bf.getBean("!test");
    replacedertThat(AopUtils.isAopProxy(test)).isTrue();
    advised = (Advised) test;
    boolean condition = advised.getTargetSource() instanceof PrototypeTargetSource;
    replacedertThat(condition).isTrue();
    replacedertThat(test.getName()).isEqualTo("Rod");
    // Check that references survived pooling
    replacedertThat(test.getSpouse().getName()).isEqualTo("Kerry");
    ITestBean test2 = (ITestBean) bf.getBean("!test");
    replacedertThat(test == test2).as("Prototypes cannot be the same object").isFalse();
    replacedertThat(test2.getName()).isEqualTo("Rod");
    replacedertThat(test2.getSpouse().getName()).isEqualTo("Kerry");
    bf.close();
}

18 Source : AdvisorAutoProxyCreatorTests.java
with Apache License 2.0
from SourceHot

@Test
public void testLazyInitTargetSource() throws Exception {
    CountingTestBean.count = 0;
    BeanFactory bf = new ClreplacedPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLreplaced);
    ITestBean test = (ITestBean) bf.getBean("lazyInitTest");
    replacedertThat(AopUtils.isAopProxy(test)).isTrue();
    Advised advised = (Advised) test;
    boolean condition = advised.getTargetSource() instanceof LazyInitTargetSource;
    replacedertThat(condition).isTrue();
    replacedertThat(CountingTestBean.count).as("No CountingTestBean instantiated yet").isEqualTo(0);
    replacedertThat(test.getName()).isEqualTo("Rod");
    replacedertThat(test.getSpouse().getName()).isEqualTo("Kerry");
    replacedertThat(CountingTestBean.count).as("Only 1 CountingTestBean instantiated").isEqualTo(1);
    CountingTestBean.count = 0;
}

18 Source : AdvisorAutoProxyCreatorTests.java
with Apache License 2.0
from SourceHot

@Test
public void testCustomPrototypeTargetSource() throws Exception {
    CountingTestBean.count = 0;
    BeanFactory bf = new ClreplacedPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLreplaced);
    ITestBean test = (ITestBean) bf.getBean("prototypeTest");
    replacedertThat(AopUtils.isAopProxy(test)).isTrue();
    Advised advised = (Advised) test;
    boolean condition = advised.getTargetSource() instanceof PrototypeTargetSource;
    replacedertThat(condition).isTrue();
    replacedertThat(test.getName()).isEqualTo("Rod");
    // Check that references survived prototype creation
    replacedertThat(test.getSpouse().getName()).isEqualTo("Kerry");
    replacedertThat(CountingTestBean.count).as("Only 2 CountingTestBeans instantiated").isEqualTo(2);
    CountingTestBean.count = 0;
}

18 Source : BenchmarkTests.java
with Apache License 2.0
from SourceHot

private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
    ClreplacedPathXmlApplicationContext bf = new ClreplacedPathXmlApplicationContext(file, CLreplaced);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated before advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    replacedertThat(AopUtils.isAopProxy(adrian)).isTrue();
    Advised a = (Advised) adrian;
    replacedertThat(a.getAdvisors().length >= 3).isTrue();
    replacedertThat(adrian.getName()).isEqualTo("adrian");
    for (int i = 0; i < howmany; i++) {
        adrian.getName();
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}

18 Source : ServiceContext.java
with Apache License 2.0
from isstac

/**
 * @param cls
 * @param advisor
 */
public void addAdvisor(Clreplaced cls, Advisor advisor) {
    Advised advisedService = (Advised) services.get(cls);
    if (advisedService.indexOf(advisor) < 0) {
        advisedService.addAdvisor(advisor);
    }
    addedAdvisors.computeIfAbsent(cls, k -> new HashSet<>());
    getAddedAdvisors(cls).add(advisor);
}

18 Source : ServiceContext.java
with Apache License 2.0
from isstac

/**
 * @param cls
 * @param advice
 */
public void removeAdvice(Clreplaced cls, Advice advice) {
    Advised advisedService = (Advised) services.get(cls);
    advisedService.removeAdvice(advice);
    getAddedAdvice(cls).remove(advice);
}

18 Source : ServiceContext.java
with Apache License 2.0
from isstac

/**
 * Allow other services to be added to our service layer
 *
 * @param cls Interface to proxy
 * @param clreplacedInstance the actual instance of the <code>cls</code> interface
 */
public void setService(Clreplaced cls, Object clreplacedInstance) {
    log.debug("Setting service: " + cls);
    if (cls != null && clreplacedInstance != null) {
        try {
            Advised cachedService = (Advised) services.get(cls);
            boolean noExistingService = cachedService == null;
            boolean replacingService = cachedService != null && cachedService != clreplacedInstance;
            boolean serviceAdvised = clreplacedInstance instanceof Advised;
            if (noExistingService || replacingService) {
                Advised advisedService;
                if (!serviceAdvised) {
                    // Adding a bare service, wrap with AOP proxy
                    Clreplaced[] interfaces = { cls };
                    ProxyFactory factory = new ProxyFactory(interfaces);
                    factory.setTarget(clreplacedInstance);
                    advisedService = (Advised) factory.getProxy(OpenmrsClreplacedLoader.getInstance());
                } else {
                    advisedService = (Advised) clreplacedInstance;
                }
                if (replacingService) {
                    moveAddedAOP(cachedService, advisedService);
                }
                services.put(cls, advisedService);
            }
            log.debug("Service: " + cls + " set successfully");
        } catch (Exception e) {
            throw new APIException("service.unable.create.proxy.factory", new Object[] { clreplacedInstance.getClreplaced().getName() }, e);
        }
    }
}

18 Source : ServiceContext.java
with Apache License 2.0
from isstac

/**
 * @param cls
 * @param advisor
 */
public void removeAdvisor(Clreplaced cls, Advisor advisor) {
    Advised advisedService = (Advised) services.get(cls);
    advisedService.removeAdvisor(advisor);
    getAddedAdvisors(cls).remove(advisor);
}

18 Source : AmazonS3ProxyFactoryTest.java
with Apache License 2.0
from awspring

@SuppressWarnings("unchecked")
@Test
void verifyAddingRedirectAdviceToExistingProxy() {
    AmazonS3 amazonS3 = mock(AmazonS3.clreplaced);
    ProxyFactory factory = new ProxyFactory(amazonS3);
    factory.addAdvice(new TestAdvice());
    AmazonS3 proxy1 = (AmazonS3) factory.getProxy();
    replacedertThat(((Advised) proxy1).getAdvisors().length).isEqualTo(1);
    AmazonS3 proxy2 = AmazonS3ProxyFactory.createProxy(proxy1);
    Advised advised = (Advised) proxy2;
    replacedertThat(advised.getAdvisors().length).isEqualTo(2);
    List<Clreplaced<? extends MethodInterceptor>> advisorClreplacedes = new ArrayList<>();
    for (Advisor advisor : advised.getAdvisors()) {
        advisorClreplacedes.add(((MethodInterceptor) advisor.getAdvice()).getClreplaced());
    }
    replacedertThat(advisorClreplacedes).contains(TestAdvice.clreplaced, AmazonS3ProxyFactory.SimpleStorageRedirectInterceptor.clreplaced);
}

17 Source : AnnotationTransactionAttributeSourceTests.java
with MIT License
from Vip-Augus

@Test
public void serializable() throws Exception {
    TestBean1 tb = new TestBean1();
    CallCountingTransactionManager ptm = new CallCountingTransactionManager();
    AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
    TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(ITestBean1.clreplaced);
    proxyFactory.addAdvice(ti);
    proxyFactory.setTarget(tb);
    ITestBean1 proxy = (ITestBean1) proxyFactory.getProxy();
    proxy.getAge();
    replacedertEquals(1, ptm.commits);
    ITestBean1 serializedProxy = (ITestBean1) SerializationTestUtils.serializeAndDeserialize(proxy);
    serializedProxy.getAge();
    Advised advised = (Advised) serializedProxy;
    TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
    CallCountingTransactionManager serializedPtm = (CallCountingTransactionManager) serializedTi.getTransactionManager();
    replacedertEquals(2, serializedPtm.commits);
}

17 Source : AopNamespaceHandlerTests.java
with MIT License
from Vip-Augus

@Test
public void testIsProxy() throws Exception {
    ITestBean bean = getTestBean();
    replacedertTrue("Bean is not a proxy", AopUtils.isAopProxy(bean));
    // check the advice details
    Advised advised = (Advised) bean;
    Advisor[] advisors = advised.getAdvisors();
    replacedertTrue("Advisors should not be empty", advisors.length > 0);
}

17 Source : ConcurrencyThrottleInterceptorTests.java
with MIT License
from Vip-Augus

@Test
public void testSerializable() throws Exception {
    DerivedTestBean tb = new DerivedTestBean();
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(ITestBean.clreplaced);
    ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
    proxyFactory.addAdvice(cti);
    proxyFactory.setTarget(tb);
    ITestBean proxy = (ITestBean) proxyFactory.getProxy();
    proxy.getAge();
    ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
    Advised advised = (Advised) serializedProxy;
    ConcurrencyThrottleInterceptor serializedCti = (ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
    replacedertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit());
    serializedProxy.getAge();
}

17 Source : BenchmarkTests.java
with Apache License 2.0
from SourceHot

private long testMix(String file, int howmany, String technology) {
    ClreplacedPathXmlApplicationContext bf = new ClreplacedPathXmlApplicationContext(file, CLreplaced);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated mixed invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    replacedertThat(AopUtils.isAopProxy(adrian)).isTrue();
    Advised a = (Advised) adrian;
    replacedertThat(a.getAdvisors().length >= 3).isTrue();
    for (int i = 0; i < howmany; i++) {
        // Hit all 3 joinpoints
        adrian.getAge();
        adrian.getName();
        adrian.setAge(i);
        // Invoke three non-advised methods
        adrian.getDoctor();
        adrian.getLawyer();
        adrian.getSpouse();
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}

17 Source : AnnotationTransactionAttributeSourceTests.java
with Apache License 2.0
from langtianya

@Test
public void serializable() throws Exception {
    TestBean1 tb = new TestBean1();
    CallCountingTransactionManager ptm = new CallCountingTransactionManager();
    AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
    TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(new Clreplaced[] { ITestBean.clreplaced });
    proxyFactory.addAdvice(ti);
    proxyFactory.setTarget(tb);
    ITestBean proxy = (ITestBean) proxyFactory.getProxy();
    proxy.getAge();
    replacedertEquals(1, ptm.commits);
    ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
    serializedProxy.getAge();
    Advised advised = (Advised) serializedProxy;
    TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
    CallCountingTransactionManager serializedPtm = (CallCountingTransactionManager) serializedTi.getTransactionManager();
    replacedertEquals(2, serializedPtm.commits);
}

17 Source : ConcurrencyThrottleInterceptorTests.java
with Apache License 2.0
from langtianya

@Test
public void testSerializable() throws Exception {
    DerivedTestBean tb = new DerivedTestBean();
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(new Clreplaced[] { ITestBean.clreplaced });
    ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
    proxyFactory.addAdvice(cti);
    proxyFactory.setTarget(tb);
    ITestBean proxy = (ITestBean) proxyFactory.getProxy();
    proxy.getAge();
    ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
    Advised advised = (Advised) serializedProxy;
    ConcurrencyThrottleInterceptor serializedCti = (ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
    replacedertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit());
    serializedProxy.getAge();
}

17 Source : ServiceContext.java
with Apache License 2.0
from isstac

/**
 * @param cls
 * @param advice
 */
public void addAdvice(Clreplaced cls, Advice advice) {
    Advised advisedService = (Advised) services.get(cls);
    if (advisedService.indexOf(advice) < 0) {
        advisedService.addAdvice(advice);
    }
    addedAdvice.computeIfAbsent(cls, k -> new HashSet<>());
    getAddedAdvice(cls).add(advice);
}

17 Source : ServiceContext.java
with Apache License 2.0
from isstac

/**
 * Removes all the advisors added by ServiceContext.
 *
 * @param cls the clreplaced of the cached service to cleanup
 */
private void removeAddedAdvisors(Clreplaced cls) {
    Advised advisedService = (Advised) services.get(cls);
    Set<Advisor> advisorsToRemove = addedAdvisors.get(cls);
    if (advisedService != null && advisorsToRemove != null) {
        for (Advisor advisor : advisorsToRemove.toArray(new Advisor[] {})) {
            removeAdvisor(cls, advisor);
        }
    }
}

17 Source : ServiceContext.java
with Apache License 2.0
from isstac

/**
 * Removes all the advice added by the ServiceContext.
 *
 * @param cls the clreplaced of the caches service to cleanup
 */
private void removeAddedAdvice(Clreplaced cls) {
    Advised advisedService = (Advised) services.get(cls);
    Set<Advice> adviceToRemove = addedAdvice.get(cls);
    if (advisedService != null && adviceToRemove != null) {
        for (Advice advice : adviceToRemove.toArray(new Advice[] {})) {
            removeAdvice(cls, advice);
        }
    }
}

16 Source : AopNamespaceHandlerTests.java
with Apache License 2.0
from SourceHot

@Test
public void testIsProxy() throws Exception {
    ITestBean bean = getTestBean();
    replacedertThat(AopUtils.isAopProxy(bean)).as("Bean is not a proxy").isTrue();
    // check the advice details
    Advised advised = (Advised) bean;
    Advisor[] advisors = advised.getAdvisors();
    replacedertThat(advisors.length > 0).as("Advisors should not be empty").isTrue();
}

16 Source : ContextResourceLoaderBeanDefinitionParserTest.java
with Apache License 2.0
from awspring

@Test
void parseInternal_configurationWithCustomAmazonS3Client_createResourceLoaderWithCustomS3Client() throws Exception {
    // Arrange
    ClreplacedPathXmlApplicationContext applicationContext = new ClreplacedPathXmlApplicationContext(getClreplaced().getSimpleName() + "-withCustomS3Client.xml", getClreplaced());
    // Act
    replacedertThat(DefaultResourceLoader.clreplaced.isInstance(applicationContext)).isTrue();
    ProtocolResolver protocolResolver = applicationContext.getProtocolResolvers().iterator().next();
    replacedertThat(SimpleStorageProtocolResolver.clreplaced.isInstance(protocolResolver)).isTrue();
    // replacedert that the proxied AmazonS2 instances are the same as the customS3Client
    // in the app context.
    AmazonS3 customS3Client = applicationContext.getBean(AmazonS3.clreplaced);
    SimpleStorageProtocolResolver resourceLoader = (SimpleStorageProtocolResolver) protocolResolver;
    AmazonS3 amazonS3FromResourceLoader = (AmazonS3) ReflectionTestUtils.getField(resourceLoader, "amazonS3");
    replacedertThat(AopUtils.isAopProxy(amazonS3FromResourceLoader)).isTrue();
    Advised advised2 = (Advised) amazonS3FromResourceLoader;
    AmazonS3 amazonS3WrappedInsideSimpleStorageResourceLoader = (AmazonS3) advised2.getTargetSource().getTarget();
    replacedertThat(amazonS3WrappedInsideSimpleStorageResourceLoader).isSameAs(customS3Client);
}

15 Source : ConcurrencyThrottleInterceptorTests.java
with Apache License 2.0
from SourceHot

@Test
public void testSerializable() throws Exception {
    DerivedTestBean tb = new DerivedTestBean();
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(ITestBean.clreplaced);
    ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
    proxyFactory.addAdvice(cti);
    proxyFactory.setTarget(tb);
    ITestBean proxy = (ITestBean) proxyFactory.getProxy();
    proxy.getAge();
    ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
    Advised advised = (Advised) serializedProxy;
    ConcurrencyThrottleInterceptor serializedCti = (ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
    replacedertThat(serializedCti.getConcurrencyLimit()).isEqualTo(cti.getConcurrencyLimit());
    serializedProxy.getAge();
}

14 Source : ServiceContext.java
with Apache License 2.0
from isstac

/**
 * Moves advisors and advice added by ServiceContext from the source service to the target one.
 *
 * @param source the existing service
 * @param target the new service
 */
private void moveAddedAOP(Advised source, Advised target) {
    Clreplaced serviceClreplaced = source.getClreplaced();
    Set<Advisor> existingAdvisors = getAddedAdvisors(serviceClreplaced);
    for (Advisor advisor : existingAdvisors) {
        target.addAdvisor(advisor);
        source.removeAdvisor(advisor);
    }
    Set<Advice> existingAdvice = getAddedAdvice(serviceClreplaced);
    for (Advice advice : existingAdvice) {
        target.addAdvice(advice);
        source.removeAdvice(advice);
    }
}

13 Source : AmazonS3ProxyFactory.java
with Apache License 2.0
from awspring

/**
 * Factory-method to create a proxy using the {@link SimpleStorageRedirectInterceptor}
 * that supports redirects for buckets which are in a different region. This proxy
 * uses the amazonS3 parameter as a "prototype" and re-uses the credentials from the
 * preplaceded in {@link AmazonS3} instance. Proxy implementations uses the
 * {@link AmazonS3ClientFactory} to create region specific clients, which are cached
 * by the implementation on a region basis to avoid unnecessary object creation.
 * @param amazonS3 Fully configured AmazonS3 client, the client can be an immutable
 * instance (created by the {@link com.amazonaws.services.s3.AmazonS3ClientBuilder})
 * as this proxy will not change the underlying implementation.
 * @return AOP-Proxy that intercepts all method calls using the
 * {@link SimpleStorageRedirectInterceptor}
 */
public static AmazonS3 createProxy(AmazonS3 amazonS3) {
    replacedert.notNull(amazonS3, "AmazonS3 client must not be null");
    if (AopUtils.isAopProxy(amazonS3)) {
        Advised advised = (Advised) amazonS3;
        for (Advisor advisor : advised.getAdvisors()) {
            if (ClreplacedUtils.isreplacedignableValue(SimpleStorageRedirectInterceptor.clreplaced, advisor.getAdvice())) {
                return amazonS3;
            }
        }
        try {
            advised.addAdvice(new SimpleStorageRedirectInterceptor((AmazonS3) advised.getTargetSource().getTarget()));
        } catch (Exception e) {
            throw new RuntimeException("Error adding advice for clreplaced amazonS3 instance", e);
        }
        return amazonS3;
    }
    ProxyFactory factory = new ProxyFactory(amazonS3);
    factory.setInterfaces(AmazonS3.clreplaced);
    factory.addAdvice(new SimpleStorageRedirectInterceptor(amazonS3));
    return (AmazonS3) factory.getProxy();
}