ChannelServiceImpl implements ChannelService { @Override @Transactional public synchronized void delete(final String moduleName) { final Channel existingChannel = getChannel(moduleName); if (existingChannel != null) { LOGGER.debug("Deleting channel {}", moduleName); channelsDataService.delete(existingChannel); sendChannelDeleteEvent(moduleName); } else if (existingChannel == null) { LOGGER.debug("Channel doesn't exists {}", moduleName); } } @Autowired  ChannelServiceImpl(TriggerEventService triggerEventService, ChannelsDataService channelsDataService, EventRelay eventRelay); @Override @Transactional void registerChannel(ChannelRequest channelRequest); @Override @Transactional void unregisterChannel(String moduleName); @Override @Transactional void registerChannel(final InputStream stream, String moduleName, String moduleVersion); @Override @Transactional synchronized void addOrUpdate(final Channel channel); @Override @Transactional synchronized void delete(final String moduleName); @Override @Transactional List<Channel> getAllChannels(); @Override @Transactional Channel getChannel(final String moduleName); @Override @Transactional boolean channelExists(String moduleName); @Autowired(required = false) void setBundleContext(BundleContext bundleContext);  }
@Test public void shouldSendEventWhenChannelWasDeleted() { Channel channel = new Channel("displayName", BUNDLE_SYMBOLIC_NAME, VERSION); when(channelsDataService.findByModuleName(channel.getModuleName())).thenReturn(channel); when(bundleContext.getBundles()).thenReturn(new Bundle[]{bundle}); when(bundle.getSymbolicName()).thenReturn(BUNDLE_SYMBOLIC_NAME); ArgumentCaptor<MotechEvent> captor = ArgumentCaptor.forClass(MotechEvent.class); Channel deletedChannel = new Channel("displayName2", BUNDLE_SYMBOLIC_NAME, VERSION); channelService.delete(deletedChannel.getModuleName()); verify(channelsDataService).delete(channel); verify(eventRelay).sendEventMessage(captor.capture()); MotechEvent event = captor.getValue(); assertEquals(CHANNEL_DEREGISTER_SUBJECT, event.getSubject()); assertEquals(BUNDLE_SYMBOLIC_NAME, event.getParameters().get(CHANNEL_MODULE_NAME)); }