### Question:
NotificationAspect { @AfterReturning( pointcut = "execution(* com.epam.pipeline.manager.pipeline.PipelineRunManager.runPipeline(..)) || " + "execution(* com.epam.pipeline.manager.pipeline.PipelineRunManager.runCmd(..)) ||" + "execution(* com.epam.pipeline.manager.pipeline.PipelineRunCRUDService.updateRunStatus(" + "com.epam.pipeline.entity.pipeline.PipelineRun)) || " + "execution(* com.epam.pipeline.manager.pipeline.PipelineRunManager.updatePipelineStatusIfNotFinal(..)) ||" + "execution(* com.epam.pipeline.manager.pipeline.PipelineRunManager" + ".updatePipelineStatusIfNotFinalExternal(..)))", returning = "run" ) @Async("notificationsExecutor") public void notifyRunStatusChanged(JoinPoint joinPoint, PipelineRun run) { final RunStatus newStatus = RunStatus.builder() .runId(run.getId()).status(run.getStatus()) .timestamp(DateUtils.nowUTC()) .reason(run.getStateReasonMessage()) .build(); runStatusManager.saveStatus(newStatus); if (run.isTerminating()) { LOGGER.debug("Won't send a notification [{} {}: {}] (filtered by status type)", run.getPipelineName(), run.getVersion(), run.getStatus()); return; } if (run.getPipelineName() == null) { if (run.getPipelineId() != null) { Pipeline pipeline = pipelineManager.load(run.getPipelineId()); run.setPipelineName(pipeline.getName()); } else { run.setPipelineName("pipeline"); } } LOGGER.debug("Notify all about pipelineRun status changed {} {} {}: {}", run.getPodId(), run.getPipelineName(), run.getVersion(), run.getStatus()); notificationManager.notifyRunStatusChanged(run); }  @AfterReturning( pointcut = "execution(* com.epam.pipeline.manager.pipeline.PipelineRunManager.runPipeline(..)) || " + "execution(* com.epam.pipeline.manager.pipeline.PipelineRunManager.runCmd(..)) ||" + "execution(* com.epam.pipeline.manager.pipeline.PipelineRunCRUDService.updateRunStatus(" + "com.epam.pipeline.entity.pipeline.PipelineRun)) || " + "execution(* com.epam.pipeline.manager.pipeline.PipelineRunManager.updatePipelineStatusIfNotFinal(..)) ||" + "execution(* com.epam.pipeline.manager.pipeline.PipelineRunManager" + ".updatePipelineStatusIfNotFinalExternal(..)))", returning = "run" ) @Async("notificationsExecutor") void notifyRunStatusChanged(JoinPoint joinPoint, PipelineRun run); static final String RESUME_RUN_FAILED; }### Answer:
@Test @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class) public void testNotifyRunStatusChanged() { PipelineRun run = new PipelineRun(); run.setStatus(TaskStatus.SUCCESS); run.setOwner(testOwner.getUserName()); run.setStartDate(new Date()); pipelineRunManager.updatePipelineStatus(run); List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications(); Assert.assertFalse(messages.isEmpty()); NotificationMessage message = messages.get(0); Assert.assertEquals(testOwner.getId(), message.getToUserId()); Assert.assertEquals(TaskStatus.SUCCESS.name(), message.getTemplateParameters().get("status")); Mockito.verify(pipelineRunDao).updateRunStatus(Mockito.any()); Mockito.verify(runStatusManager).saveStatus(Mockito.any()); }