use of org.aspectj.lang.ProceedingJoinPoint in project data-prep by Talend.
the class AnnotationUtils method getAnnotatedParameterIndexes.
public static List<Integer> getAnnotatedParameterIndexes(ProceedingJoinPoint pjp, Class<? extends Annotation> annotationClass) {
MethodSignature ms = (MethodSignature) pjp.getSignature();
Method m = ms.getMethod();
Annotation[][] pa = m.getParameterAnnotations();
List<Integer> idParameterIndexes = new ArrayList<>();
int i = 0;
for (Annotation[] annotations : pa) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().equals(annotationClass)) {
idParameterIndexes.add(i);
}
}
i++;
}
return idParameterIndexes;
}
use of org.aspectj.lang.ProceedingJoinPoint in project herd by FINRAOS.
the class StopWatchAdviceTest method testLogMethodTimeWithInfoLoggingEnabled.
@Test
public void testLogMethodTimeWithInfoLoggingEnabled() throws Throwable {
// Mock a join point of the method call.
ProceedingJoinPoint joinPoint = getMockedProceedingJoinPoint(new StopWatchAdviceTest(), StopWatchAdviceTest.class.getDeclaredMethod("mockMethod"));
// Get the logger and the current logger level.
LogLevel origLogLevel = getLogLevel("org.finra.herd.core.StopWatchAdvice");
// Set logging level to INFO.
setLogLevel("org.finra.herd.core.StopWatchAdvice", LogLevel.INFO);
// Run the test and reset the logging level back to the original value.
try {
// Call the method under test.
stopWatchAdvice.logMethodTime(joinPoint);
} finally {
setLogLevel("org.finra.herd.core.StopWatchAdvice", origLogLevel);
}
}
use of org.aspectj.lang.ProceedingJoinPoint in project herd by FINRAOS.
the class StopWatchAdviceTest method getMockedProceedingJoinPoint.
/**
* Creates and returns a mocked join point of the method call.
*
* @param targetObject the target object
* @param method the method
*
* @return the mocked ProceedingJoinPoint
*/
private ProceedingJoinPoint getMockedProceedingJoinPoint(Object targetObject, Method method) throws Exception {
ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
MethodSignature methodSignature = mock(MethodSignature.class);
when(joinPoint.getTarget()).thenReturn(targetObject);
when(joinPoint.getSignature()).thenReturn(methodSignature);
when(methodSignature.getMethod()).thenReturn(method);
when(methodSignature.getName()).thenReturn(method.getName());
return joinPoint;
}
use of org.aspectj.lang.ProceedingJoinPoint in project herd by FINRAOS.
the class StopWatchAdviceTest method testLogMethodTimeTargetMethodTargetMethodSuppressLogging.
@Test
public void testLogMethodTimeTargetMethodTargetMethodSuppressLogging() throws Throwable {
// Mock a join point of the method call.
ProceedingJoinPoint joinPoint = getMockedProceedingJoinPoint(new StopWatchAdviceTest(), StopWatchAdviceTest.class.getDeclaredMethod("mockMethodThatSuppressLogging"));
// Call the method under test.
stopWatchAdvice.logMethodTime(joinPoint);
}
use of org.aspectj.lang.ProceedingJoinPoint in project herd by FINRAOS.
the class PublishNotificationMessagesAdviceTest method getMockedProceedingJoinPoint.
/**
* Creates and returns a mocked join point of the method call.
*
* @param methodName the name of the method
*
* @return the mocked ProceedingJoinPoint
*/
private ProceedingJoinPoint getMockedProceedingJoinPoint(String methodName) throws Exception {
ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
MethodSignature methodSignature = mock(MethodSignature.class);
Method method = PublishNotificationMessagesAdviceTest.class.getDeclaredMethod("mockMethod");
when(joinPoint.getTarget()).thenReturn(new PublishNotificationMessagesAdviceTest());
when(joinPoint.getSignature()).thenReturn(methodSignature);
when(methodSignature.getMethod()).thenReturn(method);
when(methodSignature.getName()).thenReturn(methodName);
return joinPoint;
}
Aggregations