use of cn.taketoday.aop.framework.Advised in project today-infrastructure by TAKETODAY.
the class JoinPointMonitorAtAspectJAspect method checkXmlAspect.
private void checkXmlAspect(String appContextFile) {
ApplicationContext context = new ClassPathXmlApplicationContext(appContextFile, getClass());
ICounter counter = (ICounter) context.getBean("counter");
boolean condition = counter instanceof Advised;
assertThat(condition).as("Proxy didn't get created").isTrue();
counter.increment();
JoinPointMonitorAspect callCountingAspect = (JoinPointMonitorAspect) context.getBean("monitoringAspect");
assertThat(callCountingAspect.beforeExecutions).as("Advise didn't get executed").isEqualTo(1);
assertThat(callCountingAspect.aroundExecutions).as("Advise didn't get executed").isEqualTo(1);
}
use of cn.taketoday.aop.framework.Advised in project today-infrastructure by TAKETODAY.
the class CreatesTestBean method withFrozenProxy.
@Test
void withFrozenProxy() {
ITestBean testBean = (ITestBean) beanFactory.getBean("frozenBean");
assertThat(((Advised) testBean).isFrozen()).isTrue();
}
use of cn.taketoday.aop.framework.Advised in project today-infrastructure by TAKETODAY.
the class ConcurrencyThrottleInterceptorTests method testSerializable.
@Test
public void testSerializable() throws Exception {
DerivedTestBean tb = new DerivedTestBean();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean.class);
ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
proxyFactory.addAdvice(cti);
proxyFactory.setTarget(tb);
ITestBean proxy = (ITestBean) proxyFactory.getProxy();
proxy.getAge();
ITestBean serializedProxy = SerializationTestUtils.serializeAndDeserialize(proxy);
Advised advised = (Advised) serializedProxy;
ConcurrencyThrottleInterceptor serializedCti = (ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
assertThat(serializedCti.getConcurrencyLimit()).isEqualTo(cti.getConcurrencyLimit());
serializedProxy.getAge();
}
use of cn.taketoday.aop.framework.Advised in project today-infrastructure by TAKETODAY.
the class SimpleBeforeAdviceInterceptor method getAdviceImpl.
private SimpleBeforeAdviceImpl getAdviceImpl(ITestBean tb) {
Advised advised = (Advised) tb;
Advisor advisor = advised.getAdvisors()[0];
return (SimpleBeforeAdviceImpl) advisor.getAdvice();
}
use of cn.taketoday.aop.framework.Advised in project today-infrastructure by TAKETODAY.
the class MethodInvokerUtils method getMethodInvokerByAnnotation.
/**
* Create {@link MethodInvoker} for the method with the provided annotation on the
* provided object. Annotations that cannot be applied to methods (i.e. that aren't
* annotated with an element type of METHOD) will cause an exception to be thrown.
*
* @param annotationType to be searched for
* @param target to be invoked
* @return MethodInvoker for the provided annotation, null if none is found.
*/
public static MethodInvoker getMethodInvokerByAnnotation(Class<? extends Annotation> annotationType, Object target) {
Assert.notNull(target, "Target must not be null");
Assert.notNull(annotationType, "AnnotationType must not be null");
if (!ObjectUtils.containsElement(annotationType.getAnnotation(Target.class).value(), ElementType.METHOD)) {
throw new IllegalArgumentException("Annotation [" + annotationType + "] is not a Method-level annotation.");
}
Class<?> targetClass = target instanceof Advised ? ((Advised) target).getTargetSource().getTargetClass() : target.getClass();
if (targetClass == null) {
// Proxy with no target cannot have annotations
return null;
}
final AtomicReference<Method> annotatedMethod = new AtomicReference<>();
ReflectionUtils.doWithMethods(targetClass, method -> {
Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType);
if (annotation != null) {
if (annotatedMethod.get() != null) {
throw new IllegalArgumentException("found more than one method on target class [" + targetClass.getSimpleName() + "] with the annotation type [" + annotationType.getSimpleName() + "].");
}
annotatedMethod.set(method);
}
});
Method method = annotatedMethod.get();
if (method == null) {
return null;
} else {
return new SimpleMethodInvoker(target, annotatedMethod.get());
}
}
Aggregations