@Test public void buildMessageChaosMessage () { ChaosNotification messageNotif = ChaosMessage.builder().withTitle(TITLE).withMessage(MESSAGE) .withNotificationLevel(NotificationLevel.GOOD) .build(); Message notification = xmppNotification.buildMessage(messageNotif); assertEquals(messageNotif.getTitle(), notification.getSubject()); assertEquals(messageNotif.getMessage(), notification.getBody()); assertTrue(XHTMLManager.isXHTMLMessage(notification)); List<CharSequence> bodies = XHTMLManager.getBodies(notification); assertEquals(5, bodies.size()); String bodyTitle = String.valueOf(bodies.get(0)); assertThat(bodyTitle, allOf(Matchers.containsString(messageNotif.getTitle()), Matchers.containsString(XMPPNotification.SIZE_NORMAL), Matchers.containsString(XMPPNotification.WEIGHT_NORMAL), Matchers.containsString(XMPPNotification.COLOR_BLUE))); String bodyMessageHeader = String.valueOf(bodies.get(1)); assertThat(bodyMessageHeader, allOf(Matchers.containsString(XMPPNotification.MESSAGE_HEADER), Matchers.containsString(XMPPNotification.SIZE_NORMAL), Matchers.containsString(XMPPNotification.WEIGHT_BOLD), Matchers.containsString(XMPPNotification.COLOR_NORMAL))); String bodyMessage = String.valueOf(bodies.get(2)); assertThat(bodyMessage, allOf(Matchers.containsString(messageNotif.getMessage()), Matchers.containsString(XMPPNotification.SIZE_SMALLER), Matchers.containsString(XMPPNotification.WEIGHT_NORMAL), Matchers.containsString(XMPPNotification.COLOR_GREEN))); String instanceHeader = String.valueOf(bodies.get(3)); assertThat(instanceHeader, allOf(Matchers.containsString(XMPPNotification.INSTANCE_HEADER), Matchers.containsString(XMPPNotification.SIZE_NORMAL), Matchers.containsString(XMPPNotification.WEIGHT_BOLD), Matchers.containsString(XMPPNotification.COLOR_NORMAL))); String instance = String.valueOf(bodies.get(4)); assertThat(instance, allOf(Matchers.containsString(HttpUtils.getMachineHostname()), Matchers.containsString(XMPPNotification.SIZE_SMALLER), Matchers.containsString(XMPPNotification.WEIGHT_NORMAL), Matchers.containsString(XMPPNotification.COLOR_NORMAL))); }
Message buildMessage (ChaosNotification notification) { Message msg = new Message(); msg.setSubject(notification.getTitle()); msg.setBody(notification.getMessage()); XHTMLManager.addBody(msg, composeParagraph(notification.getTitle(), ParagraphStyle.NOTIFICATION_TITLE)); XHTMLManager.addBody(msg, composeParagraph(MESSAGE_HEADER, ParagraphStyle.NOTIFICATION_MESSAGE_HEADER)); XHTMLManager.addBody(msg, composeParagraph(notification.getMessage(), mapLevelToStyle(notification.getNotificationLevel()))); XHTMLManager.addBody(msg, composeParagraph(INSTANCE_HEADER, ParagraphStyle.NOTIFICATION_FIELD_HEADER)); XHTMLManager.addBody(msg, composeParagraph(HttpUtils.getMachineHostname(), ParagraphStyle.NOTIFICATION_FIELD)); collectExperimentEventFields(notification.asMap(), msg); return msg; }
XMPPNotification implements NotificationMethods { Message buildMessage (ChaosNotification notification) { Message msg = new Message(); msg.setSubject(notification.getTitle()); msg.setBody(notification.getMessage()); XHTMLManager.addBody(msg, composeParagraph(notification.getTitle(), ParagraphStyle.NOTIFICATION_TITLE)); XHTMLManager.addBody(msg, composeParagraph(MESSAGE_HEADER, ParagraphStyle.NOTIFICATION_MESSAGE_HEADER)); XHTMLManager.addBody(msg, composeParagraph(notification.getMessage(), mapLevelToStyle(notification.getNotificationLevel()))); XHTMLManager.addBody(msg, composeParagraph(INSTANCE_HEADER, ParagraphStyle.NOTIFICATION_FIELD_HEADER)); XHTMLManager.addBody(msg, composeParagraph(HttpUtils.getMachineHostname(), ParagraphStyle.NOTIFICATION_FIELD)); collectExperimentEventFields(notification.asMap(), msg); return msg; } }
XMPPNotification implements NotificationMethods { Message buildMessage (ChaosNotification notification) { Message msg = new Message(); msg.setSubject(notification.getTitle()); msg.setBody(notification.getMessage()); XHTMLManager.addBody(msg, composeParagraph(notification.getTitle(), ParagraphStyle.NOTIFICATION_TITLE)); XHTMLManager.addBody(msg, composeParagraph(MESSAGE_HEADER, ParagraphStyle.NOTIFICATION_MESSAGE_HEADER)); XHTMLManager.addBody(msg, composeParagraph(notification.getMessage(), mapLevelToStyle(notification.getNotificationLevel()))); XHTMLManager.addBody(msg, composeParagraph(INSTANCE_HEADER, ParagraphStyle.NOTIFICATION_FIELD_HEADER)); XHTMLManager.addBody(msg, composeParagraph(HttpUtils.getMachineHostname(), ParagraphStyle.NOTIFICATION_FIELD)); collectExperimentEventFields(notification.asMap(), msg); return msg; } @Autowired  XMPPNotification(); }
XMPPNotification implements NotificationMethods { Message buildMessage (ChaosNotification notification) { Message msg = new Message(); msg.setSubject(notification.getTitle()); msg.setBody(notification.getMessage()); XHTMLManager.addBody(msg, composeParagraph(notification.getTitle(), ParagraphStyle.NOTIFICATION_TITLE)); XHTMLManager.addBody(msg, composeParagraph(MESSAGE_HEADER, ParagraphStyle.NOTIFICATION_MESSAGE_HEADER)); XHTMLManager.addBody(msg, composeParagraph(notification.getMessage(), mapLevelToStyle(notification.getNotificationLevel()))); XHTMLManager.addBody(msg, composeParagraph(INSTANCE_HEADER, ParagraphStyle.NOTIFICATION_FIELD_HEADER)); XHTMLManager.addBody(msg, composeParagraph(HttpUtils.getMachineHostname(), ParagraphStyle.NOTIFICATION_FIELD)); collectExperimentEventFields(notification.asMap(), msg); return msg; } @Autowired  XMPPNotification(); @Override void logNotification(ChaosNotification notification); }
XMPPNotification implements NotificationMethods { Message buildMessage (ChaosNotification notification) { Message msg = new Message(); msg.setSubject(notification.getTitle()); msg.setBody(notification.getMessage()); XHTMLManager.addBody(msg, composeParagraph(notification.getTitle(), ParagraphStyle.NOTIFICATION_TITLE)); XHTMLManager.addBody(msg, composeParagraph(MESSAGE_HEADER, ParagraphStyle.NOTIFICATION_MESSAGE_HEADER)); XHTMLManager.addBody(msg, composeParagraph(notification.getMessage(), mapLevelToStyle(notification.getNotificationLevel()))); XHTMLManager.addBody(msg, composeParagraph(INSTANCE_HEADER, ParagraphStyle.NOTIFICATION_FIELD_HEADER)); XHTMLManager.addBody(msg, composeParagraph(HttpUtils.getMachineHostname(), ParagraphStyle.NOTIFICATION_FIELD)); collectExperimentEventFields(notification.asMap(), msg); return msg; } @Autowired  XMPPNotification(); @Override void logNotification(ChaosNotification notification);  }