Search in sources :

Example 11 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project herd by FINRAOS.

the class StopWatchAdviceTest method testLogMethodTime.

@Test
public void testLogMethodTime() throws Throwable {
    // Mock a join point of the method call.
    ProceedingJoinPoint joinPoint = getMockedProceedingJoinPoint(new StopWatchAdviceTest(), StopWatchAdviceTest.class.getDeclaredMethod("mockMethod"));
    // 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 12 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project herd by FINRAOS.

the class StopWatchAdviceTest method testLogMethodTimeWithInfoLoggingDisabled.

@Test
public void testLogMethodTimeWithInfoLoggingDisabled() 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 OFF.
    setLogLevel("org.finra.herd.core.StopWatchAdvice", LogLevel.OFF);
    // 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 13 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project herd by FINRAOS.

the class PublishNotificationMessagesAdviceTest method testPublishNotificationMessagesDebugEnabled.

@Test
public void testPublishNotificationMessagesDebugEnabled() throws Throwable {
    // Save the current log level.
    LogLevel originalLogLevel = getLogLevel(PublishNotificationMessagesAdvice.class);
    try {
        // Set the log level to debug.
        setLogLevel(PublishNotificationMessagesAdvice.class, LogLevel.DEBUG);
        // Create a notification message.
        NotificationMessage notificationMessage = new NotificationMessage(MessageTypeEntity.MessageEventTypes.SQS.name(), AWS_SQS_QUEUE_NAME, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE)));
        // Mock a join point of the method call.
        ProceedingJoinPoint joinPoint = getMockedProceedingJoinPoint("testPublishNotificationMessages");
        // Mock the external calls.
        doCallRealMethod().when(notificationMessageInMemoryQueue).clear();
        doCallRealMethod().when(notificationMessageInMemoryQueue).add(notificationMessage);
        when(notificationMessageInMemoryQueue.size()).thenCallRealMethod();
        when(notificationMessageInMemoryQueue.isEmpty()).thenCallRealMethod();
        doCallRealMethod().when(notificationMessageInMemoryQueue).remove();
        // Clear the queue.
        notificationMessageInMemoryQueue.clear();
        // Add the notification message to the queue.
        notificationMessageInMemoryQueue.add(notificationMessage);
        // Validate that the queue is not empty now.
        assertFalse(notificationMessageInMemoryQueue.isEmpty());
        // Call the method under test.
        publishNotificationMessagesAdvice.publishNotificationMessages(joinPoint);
        // Verify the external calls.
        verify(notificationMessageInMemoryQueue, times(2)).clear();
        verify(notificationMessageInMemoryQueue).add(notificationMessage);
        verify(notificationMessageInMemoryQueue).size();
        verify(notificationMessageInMemoryQueue, times(3)).isEmpty();
        verify(notificationMessageInMemoryQueue).remove();
        verify(notificationMessagePublishingService).publishNotificationMessage(notificationMessage);
        verifyNoMoreInteractionsHelper();
        // Validate the results.
        assertTrue(notificationMessageInMemoryQueue.isEmpty());
    } finally {
        // Restore log level to the original value.
        setLogLevel(PublishNotificationMessagesAdvice.class, originalLogLevel);
    }
}
Also used : NotificationMessage(org.finra.herd.model.dto.NotificationMessage) MessageHeader(org.finra.herd.model.dto.MessageHeader) LogLevel(org.finra.herd.core.helper.LogLevel) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 14 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project herd by FINRAOS.

the class PublishNotificationMessagesAdviceTest method testPublishNotificationMessages.

@Test
public void testPublishNotificationMessages() throws Throwable {
    // Create a notification message.
    NotificationMessage notificationMessage = new NotificationMessage(MessageTypeEntity.MessageEventTypes.SQS.name(), AWS_SQS_QUEUE_NAME, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE)));
    // Mock a join point of the method call.
    ProceedingJoinPoint joinPoint = getMockedProceedingJoinPoint("testPublishNotificationMessages");
    // Mock the external calls.
    doCallRealMethod().when(notificationMessageInMemoryQueue).clear();
    doCallRealMethod().when(notificationMessageInMemoryQueue).add(notificationMessage);
    when(notificationMessageInMemoryQueue.isEmpty()).thenCallRealMethod();
    doCallRealMethod().when(notificationMessageInMemoryQueue).remove();
    // Clear the queue.
    notificationMessageInMemoryQueue.clear();
    // Add the notification message to the queue.
    notificationMessageInMemoryQueue.add(notificationMessage);
    // Validate that the queue is not empty now.
    assertFalse(notificationMessageInMemoryQueue.isEmpty());
    // Call the method under test.
    publishNotificationMessagesAdvice.publishNotificationMessages(joinPoint);
    // Verify the external calls.
    verify(notificationMessageInMemoryQueue, times(2)).clear();
    verify(notificationMessageInMemoryQueue).add(notificationMessage);
    verify(notificationMessageInMemoryQueue, times(3)).isEmpty();
    verify(notificationMessageInMemoryQueue).remove();
    verify(notificationMessagePublishingService).publishNotificationMessage(notificationMessage);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertTrue(notificationMessageInMemoryQueue.isEmpty());
}
Also used : NotificationMessage(org.finra.herd.model.dto.NotificationMessage) MessageHeader(org.finra.herd.model.dto.MessageHeader) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 15 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project BroadleafCommerce by BroadleafCommerce.

the class ServiceResponseCache method processRequest.

public Object processRequest(ProceedingJoinPoint call) throws Throwable {
    CacheRequest cacheRequest = (CacheRequest) call.getArgs()[0];
    Cache cache = ((ServiceResponseCacheable) call.getTarget()).getCache();
    List<Serializable> cacheItemResponses = new ArrayList<Serializable>();
    Iterator<CacheItemRequest> itr = cacheRequest.getCacheItemRequests().iterator();
    while (itr.hasNext()) {
        CacheItemRequest itemRequest = itr.next();
        if (cache.isKeyInCache(itemRequest.key())) {
            cacheItemResponses.add(cache.get(itemRequest.key()).getValue());
            itr.remove();
        }
    }
    CacheResponse returnValue = (CacheResponse) call.proceed();
    Object[] responses = new Object[cacheItemResponses.size() + returnValue.getCacheItemResponses().length];
    responses = cacheItemResponses.toArray(responses);
    for (int j = 0; j < returnValue.getCacheItemResponses().length; j++) {
        Element element = new Element(cacheRequest.getCacheItemRequests().get(j).key(), returnValue.getCacheItemResponses()[j]);
        cache.put(element);
    }
    System.arraycopy(returnValue.getCacheItemResponses(), 0, responses, cacheItemResponses.size(), returnValue.getCacheItemResponses().length);
    returnValue.setCacheItemResponses(responses);
    return returnValue;
}
Also used : Serializable(java.io.Serializable) Element(net.sf.ehcache.Element) ArrayList(java.util.ArrayList) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Cache(net.sf.ehcache.Cache)

Aggregations

ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)78 Around (org.aspectj.lang.annotation.Around)33 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