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);
}
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);
}
}
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);
}
}
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());
}
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;
}
Aggregations