Search in sources :

Example 56 with ProceedingJoinPoint

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;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Annotation(java.lang.annotation.Annotation)

Example 57 with ProceedingJoinPoint

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);
    }
}
Also used : MockProceedingJoinPoint(org.finra.herd.core.MockProceedingJoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) LogLevel(org.finra.herd.core.helper.LogLevel) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 58 with ProceedingJoinPoint

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;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) MockProceedingJoinPoint(org.finra.herd.core.MockProceedingJoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Example 59 with ProceedingJoinPoint

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);
}
Also used : MockProceedingJoinPoint(org.finra.herd.core.MockProceedingJoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 60 with ProceedingJoinPoint

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;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Mockito.doCallRealMethod(org.mockito.Mockito.doCallRealMethod) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Aggregations

ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)77 Around (org.aspectj.lang.annotation.Around)32 MethodSignature (org.aspectj.lang.reflect.MethodSignature)16 Method (java.lang.reflect.Method)14 Test (org.junit.Test)14 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)10 SimpleDateFormat (java.text.SimpleDateFormat)8 ArrayList (java.util.ArrayList)8 JoinPoint (org.aspectj.lang.JoinPoint)8 FaseDTO (com.tomasio.projects.trainning.dto.FaseDTO)7 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)7 PessoaDTO (com.tomasio.projects.trainning.dto.PessoaDTO)7 MockProceedingJoinPoint (org.finra.herd.core.MockProceedingJoinPoint)7 Annotation (java.lang.annotation.Annotation)5 CancelamentoMatriculaDTO (com.tomasio.projects.trainning.dto.CancelamentoMatriculaDTO)4 MatriculaDTO (com.tomasio.projects.trainning.dto.MatriculaDTO)4 Date (java.util.Date)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Action (org.apache.nifi.action.Action)4 MessageHeader (org.finra.herd.model.dto.MessageHeader)4