@Test public void send_UserIsConfiguredForMailChannelAndDummyChannel_SucessForDummy_FaildForMail() throws Exception { doNothing().when(dummyChannelMock).send(any(Subscriber.class), anyListOf(NotificationEventTO.class)); doThrow(new MailSendException("")).when(mailChannelMock).send(any(Subscriber.class), anyListOf(NotificationEventTO.class)); NotifyStatistics statistics = channelChainTestObject.send(subscriber, eventTOs); assertEquals("Wrong number of the size", 2, statistics.getChannel2StatusMap().size()); assertFalse(statistics.getChannel2StatusMap().get(Subscriber.Channel.EMAIL)); assertTrue(statistics.getChannel2StatusMap().get(null)); }
public NotifyStatistics send(Subscriber subscriber, List<NotificationEventTO> events) { NotifyStatistics statistics = new NotifyStatistics(); if (events == null || events.isEmpty()) { return statistics; } for (Channel channel : channels) { boolean delivered = false; if (!subscriber.getChannels().contains(channel.getChannelName())) continue; try { channel.send(subscriber, events); delivered = true; } catch (Exception e) { log.error("Could not send via the channel [" + channel.getChannelName() + "] for the subscriber [" + subscriber.getId() + "] because of: " + e); } finally { statistics.addChannelResponse(channel.getChannelName(), delivered); } } return statistics; }
ChannelChain { public NotifyStatistics send(Subscriber subscriber, List<NotificationEventTO> events) { NotifyStatistics statistics = new NotifyStatistics(); if (events == null || events.isEmpty()) { return statistics; } for (Channel channel : channels) { boolean delivered = false; if (!subscriber.getChannels().contains(channel.getChannelName())) continue; try { channel.send(subscriber, events); delivered = true; } catch (Exception e) { log.error("Could not send via the channel [" + channel.getChannelName() + "] for the subscriber [" + subscriber.getId() + "] because of: " + e); } finally { statistics.addChannelResponse(channel.getChannelName(), delivered); } } return statistics; } }
ChannelChain { public NotifyStatistics send(Subscriber subscriber, List<NotificationEventTO> events) { NotifyStatistics statistics = new NotifyStatistics(); if (events == null || events.isEmpty()) { return statistics; } for (Channel channel : channels) { boolean delivered = false; if (!subscriber.getChannels().contains(channel.getChannelName())) continue; try { channel.send(subscriber, events); delivered = true; } catch (Exception e) { log.error("Could not send via the channel [" + channel.getChannelName() + "] for the subscriber [" + subscriber.getId() + "] because of: " + e); } finally { statistics.addChannelResponse(channel.getChannelName(), delivered); } } return statistics; }  }
ChannelChain { public NotifyStatistics send(Subscriber subscriber, List<NotificationEventTO> events) { NotifyStatistics statistics = new NotifyStatistics(); if (events == null || events.isEmpty()) { return statistics; } for (Channel channel : channels) { boolean delivered = false; if (!subscriber.getChannels().contains(channel.getChannelName())) continue; try { channel.send(subscriber, events); delivered = true; } catch (Exception e) { log.error("Could not send via the channel [" + channel.getChannelName() + "] for the subscriber [" + subscriber.getId() + "] because of: " + e); } finally { statistics.addChannelResponse(channel.getChannelName(), delivered); } } return statistics; }  @PostConstruct void init(); List<Channel> getChannels(); Channel getMailChannel(); void setMailChannel(MailChannel mailChannel); Channel getDummyChannel(); void setDummyChannel(DummyChannel dummyChannel); NotifyStatistics send(Subscriber subscriber, List<NotificationEventTO> events); }
ChannelChain { public NotifyStatistics send(Subscriber subscriber, List<NotificationEventTO> events) { NotifyStatistics statistics = new NotifyStatistics(); if (events == null || events.isEmpty()) { return statistics; } for (Channel channel : channels) { boolean delivered = false; if (!subscriber.getChannels().contains(channel.getChannelName())) continue; try { channel.send(subscriber, events); delivered = true; } catch (Exception e) { log.error("Could not send via the channel [" + channel.getChannelName() + "] for the subscriber [" + subscriber.getId() + "] because of: " + e); } finally { statistics.addChannelResponse(channel.getChannelName(), delivered); } } return statistics; }  @PostConstruct void init(); List<Channel> getChannels(); Channel getMailChannel(); void setMailChannel(MailChannel mailChannel); Channel getDummyChannel(); void setDummyChannel(DummyChannel dummyChannel); NotifyStatistics send(Subscriber subscriber, List<NotificationEventTO> events);  }