@Test public void shouldValidateDynamicTrigger() throws Exception { TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(prepareTrigger()); when(channelsDataService.countFindByModuleName(MODULE_NAME)).thenReturn((long) 1992); when(triggerEventsDataService.countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject())).thenReturn((long) 0); when(dynamicChannelLoader.channelExists(MODULE_NAME)).thenReturn(true); when(dynamicChannelLoader.validateTrigger(MODULE_NAME, triggerInformation.getSubject())).thenReturn(true); Set<TaskError> errors = triggerEventService.validateTrigger(triggerInformation); verify(channelsDataService, times(1)).countFindByModuleName(MODULE_NAME); verify(triggerEventsDataService, times(1)).countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject()); verify(dynamicChannelLoader, times(1)).channelExists(MODULE_NAME); verify(dynamicChannelLoader, times(1)).validateTrigger(MODULE_NAME, triggerInformation.getSubject()); assertEquals(0, errors.size()); }
@Override @Transactional public Set<TaskError> validateTrigger(TaskTriggerInformation trigger) { Set<TaskError> errors = new HashSet<>(); String subject = trigger.getSubject(); String moduleName = trigger.getModuleName(); boolean channelExists = false; boolean validTrigger = false; if (channelsDataService.countFindByModuleName(moduleName) != 0) { channelExists = true; validTrigger = triggerEventsDataService.countByChannelModuleNameAndSubject(moduleName, subject) > 0; } if (!validTrigger && dynamicChannelLoader.channelExists(moduleName)) { channelExists = true; validTrigger = dynamicChannelLoader.validateTrigger(moduleName, subject); } if (channelExists) { if (!validTrigger) { errors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName())); } } else { errors.add(new TaskError("task.validation.error.triggerChannelNotRegistered")); } return errors; }
TriggerEventServiceImpl implements TriggerEventService { @Override @Transactional public Set<TaskError> validateTrigger(TaskTriggerInformation trigger) { Set<TaskError> errors = new HashSet<>(); String subject = trigger.getSubject(); String moduleName = trigger.getModuleName(); boolean channelExists = false; boolean validTrigger = false; if (channelsDataService.countFindByModuleName(moduleName) != 0) { channelExists = true; validTrigger = triggerEventsDataService.countByChannelModuleNameAndSubject(moduleName, subject) > 0; } if (!validTrigger && dynamicChannelLoader.channelExists(moduleName)) { channelExists = true; validTrigger = dynamicChannelLoader.validateTrigger(moduleName, subject); } if (channelExists) { if (!validTrigger) { errors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName())); } } else { errors.add(new TaskError("task.validation.error.triggerChannelNotRegistered")); } return errors; } }
TriggerEventServiceImpl implements TriggerEventService { @Override @Transactional public Set<TaskError> validateTrigger(TaskTriggerInformation trigger) { Set<TaskError> errors = new HashSet<>(); String subject = trigger.getSubject(); String moduleName = trigger.getModuleName(); boolean channelExists = false; boolean validTrigger = false; if (channelsDataService.countFindByModuleName(moduleName) != 0) { channelExists = true; validTrigger = triggerEventsDataService.countByChannelModuleNameAndSubject(moduleName, subject) > 0; } if (!validTrigger && dynamicChannelLoader.channelExists(moduleName)) { channelExists = true; validTrigger = dynamicChannelLoader.validateTrigger(moduleName, subject); } if (channelExists) { if (!validTrigger) { errors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName())); } } else { errors.add(new TaskError("task.validation.error.triggerChannelNotRegistered")); } return errors; }  }
TriggerEventServiceImpl implements TriggerEventService { @Override @Transactional public Set<TaskError> validateTrigger(TaskTriggerInformation trigger) { Set<TaskError> errors = new HashSet<>(); String subject = trigger.getSubject(); String moduleName = trigger.getModuleName(); boolean channelExists = false; boolean validTrigger = false; if (channelsDataService.countFindByModuleName(moduleName) != 0) { channelExists = true; validTrigger = triggerEventsDataService.countByChannelModuleNameAndSubject(moduleName, subject) > 0; } if (!validTrigger && dynamicChannelLoader.channelExists(moduleName)) { channelExists = true; validTrigger = dynamicChannelLoader.validateTrigger(moduleName, subject); } if (channelExists) { if (!validTrigger) { errors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName())); } } else { errors.add(new TaskError("task.validation.error.triggerChannelNotRegistered")); } return errors; }  @Override @Transactional List<TriggerEvent> getDynamicTriggers(String moduleName, int page, int pareSize); @Override @Transactional List<TriggerEvent> getStaticTriggers(String moduleName, int page, int pageSize); @Override @Transactional TriggerEvent getTrigger(TaskTriggerInformation triggerInformation); @Override @Transactional boolean triggerExists(TaskTriggerInformation information); @Override boolean providesDynamicTriggers(String moduleName); @Override @Transactional long countStaticTriggers(String moduleName); @Override long countDynamicTriggers(String moduleName); @Override @Transactional Set<TaskError> validateTrigger(TaskTriggerInformation trigger); @Autowired void setTriggerEventsDataService(TriggerEventsDataService triggerEventsDataService); @Autowired void setChannelsDataService(ChannelsDataService channelsDataService); @Autowired void setDynamicChannelLoader(DynamicChannelLoader dynamicChannelLoader); }
TriggerEventServiceImpl implements TriggerEventService { @Override @Transactional public Set<TaskError> validateTrigger(TaskTriggerInformation trigger) { Set<TaskError> errors = new HashSet<>(); String subject = trigger.getSubject(); String moduleName = trigger.getModuleName(); boolean channelExists = false; boolean validTrigger = false; if (channelsDataService.countFindByModuleName(moduleName) != 0) { channelExists = true; validTrigger = triggerEventsDataService.countByChannelModuleNameAndSubject(moduleName, subject) > 0; } if (!validTrigger && dynamicChannelLoader.channelExists(moduleName)) { channelExists = true; validTrigger = dynamicChannelLoader.validateTrigger(moduleName, subject); } if (channelExists) { if (!validTrigger) { errors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName())); } } else { errors.add(new TaskError("task.validation.error.triggerChannelNotRegistered")); } return errors; }  @Override @Transactional List<TriggerEvent> getDynamicTriggers(String moduleName, int page, int pareSize); @Override @Transactional List<TriggerEvent> getStaticTriggers(String moduleName, int page, int pageSize); @Override @Transactional TriggerEvent getTrigger(TaskTriggerInformation triggerInformation); @Override @Transactional boolean triggerExists(TaskTriggerInformation information); @Override boolean providesDynamicTriggers(String moduleName); @Override @Transactional long countStaticTriggers(String moduleName); @Override long countDynamicTriggers(String moduleName); @Override @Transactional Set<TaskError> validateTrigger(TaskTriggerInformation trigger); @Autowired void setTriggerEventsDataService(TriggerEventsDataService triggerEventsDataService); @Autowired void setChannelsDataService(ChannelsDataService channelsDataService); @Autowired void setDynamicChannelLoader(DynamicChannelLoader dynamicChannelLoader);  }