@Test public void basicFlowdockTest() { BigDecimal value = new BigDecimal("1.0"); Check check = new Check() .withId("123") .withEnabled(true) .withName("test-check") .withState(AlertType.ERROR); Subscription subscription = new Subscription() .withEnabled(true) .withType(SubscriptionType.FLOWDOCK) .withTarget("target"); Alert alert = new Alert() .withValue(value) .withTimestamp(new DateTime()) .withFromType(AlertType.OK) .withToType(AlertType.ERROR); List<Alert> alerts = Arrays.asList(alert); BodyCapture<JsonNode> bodyCapture = new JsonBodyCapture(); clientDriver.addExpectation( onRequestTo("/v1/messages/chat/target") .withMethod(ClientDriverRequest.Method.POST) .capturingBodyIn(bodyCapture) .withHeader("Content-Type", "application/json") .withHeader("accept", "application/json"), giveEmptyResponse()); notificationService.sendNotification(check, subscription, alerts); JsonNode node = bodyCapture.getContent(); assertThat(node, hasJsonPath("$.content", containsString("test-check"))); assertThat(node, hasJsonPath("$.content", containsString("ERROR"))); assertThat(node, hasJsonPath("$.content", containsString(value.toString()))); assertThat(node, hasJsonPath("$.content", containsString("/#/checks/123"))); assertThat(node, hasJsonPath("$.external_user_name", is("Seyren"))); assertThat(node, hasJsonPath("$.tags", hasSize(1))); assertThat(node, hasJsonPath("$.tags[0]", is("ERROR"))); verify(mockSeyrenConfig).getFlowdockExternalUsername(); verify(mockSeyrenConfig).getFlowdockEmojis(); verify(mockSeyrenConfig).getFlowdockTags(); verify(mockSeyrenConfig).getBaseUrl(); }
@Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String token = subscription.getTarget(); String externalUsername = seyrenConfig.getFlowdockExternalUsername(); List<String> tags = Lists.newArrayList( Splitter.on(',').omitEmptyStrings().trimResults().split(seyrenConfig.getFlowdockTags()) ); List<String> emojis = Lists.newArrayList( Splitter.on(',').omitEmptyStrings().trimResults().split(seyrenConfig.getFlowdockEmojis()) ); String url = String.format("%s/v1/messages/chat/%s", baseUrl, token); HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost post = new HttpPost(url); post.addHeader("Content-Type", "application/json"); post.addHeader("accept", "application/json"); ObjectMapper mapper = new ObjectMapper(); Map<String, Object> dataToSend = new HashMap<String, Object>(); dataToSend.put("content", formatContent(emojis, check, subscription, alerts)); dataToSend.put("external_user_name", externalUsername); dataToSend.put("tags", formatTags(tags, check, subscription, alerts)); try { String data = StringEscapeUtils.unescapeJava(mapper.writeValueAsString(dataToSend)); post.setEntity(new StringEntity(data, APPLICATION_JSON)); client.execute(post); } catch (Exception e) { LOGGER.warn("Error posting to Flowdock", e); } finally { post.releaseConnection(); HttpClientUtils.closeQuietly(client); } }
FlowdockNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String token = subscription.getTarget(); String externalUsername = seyrenConfig.getFlowdockExternalUsername(); List<String> tags = Lists.newArrayList( Splitter.on(',').omitEmptyStrings().trimResults().split(seyrenConfig.getFlowdockTags()) ); List<String> emojis = Lists.newArrayList( Splitter.on(',').omitEmptyStrings().trimResults().split(seyrenConfig.getFlowdockEmojis()) ); String url = String.format("%s/v1/messages/chat/%s", baseUrl, token); HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost post = new HttpPost(url); post.addHeader("Content-Type", "application/json"); post.addHeader("accept", "application/json"); ObjectMapper mapper = new ObjectMapper(); Map<String, Object> dataToSend = new HashMap<String, Object>(); dataToSend.put("content", formatContent(emojis, check, subscription, alerts)); dataToSend.put("external_user_name", externalUsername); dataToSend.put("tags", formatTags(tags, check, subscription, alerts)); try { String data = StringEscapeUtils.unescapeJava(mapper.writeValueAsString(dataToSend)); post.setEntity(new StringEntity(data, APPLICATION_JSON)); client.execute(post); } catch (Exception e) { LOGGER.warn("Error posting to Flowdock", e); } finally { post.releaseConnection(); HttpClientUtils.closeQuietly(client); } } }
FlowdockNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String token = subscription.getTarget(); String externalUsername = seyrenConfig.getFlowdockExternalUsername(); List<String> tags = Lists.newArrayList( Splitter.on(',').omitEmptyStrings().trimResults().split(seyrenConfig.getFlowdockTags()) ); List<String> emojis = Lists.newArrayList( Splitter.on(',').omitEmptyStrings().trimResults().split(seyrenConfig.getFlowdockEmojis()) ); String url = String.format("%s/v1/messages/chat/%s", baseUrl, token); HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost post = new HttpPost(url); post.addHeader("Content-Type", "application/json"); post.addHeader("accept", "application/json"); ObjectMapper mapper = new ObjectMapper(); Map<String, Object> dataToSend = new HashMap<String, Object>(); dataToSend.put("content", formatContent(emojis, check, subscription, alerts)); dataToSend.put("external_user_name", externalUsername); dataToSend.put("tags", formatTags(tags, check, subscription, alerts)); try { String data = StringEscapeUtils.unescapeJava(mapper.writeValueAsString(dataToSend)); post.setEntity(new StringEntity(data, APPLICATION_JSON)); client.execute(post); } catch (Exception e) { LOGGER.warn("Error posting to Flowdock", e); } finally { post.releaseConnection(); HttpClientUtils.closeQuietly(client); } } @Inject  FlowdockNotificationService(SeyrenConfig seyrenConfig); protected  FlowdockNotificationService(SeyrenConfig seyrenConfig, String baseUrl); }
FlowdockNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String token = subscription.getTarget(); String externalUsername = seyrenConfig.getFlowdockExternalUsername(); List<String> tags = Lists.newArrayList( Splitter.on(',').omitEmptyStrings().trimResults().split(seyrenConfig.getFlowdockTags()) ); List<String> emojis = Lists.newArrayList( Splitter.on(',').omitEmptyStrings().trimResults().split(seyrenConfig.getFlowdockEmojis()) ); String url = String.format("%s/v1/messages/chat/%s", baseUrl, token); HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost post = new HttpPost(url); post.addHeader("Content-Type", "application/json"); post.addHeader("accept", "application/json"); ObjectMapper mapper = new ObjectMapper(); Map<String, Object> dataToSend = new HashMap<String, Object>(); dataToSend.put("content", formatContent(emojis, check, subscription, alerts)); dataToSend.put("external_user_name", externalUsername); dataToSend.put("tags", formatTags(tags, check, subscription, alerts)); try { String data = StringEscapeUtils.unescapeJava(mapper.writeValueAsString(dataToSend)); post.setEntity(new StringEntity(data, APPLICATION_JSON)); client.execute(post); } catch (Exception e) { LOGGER.warn("Error posting to Flowdock", e); } finally { post.releaseConnection(); HttpClientUtils.closeQuietly(client); } } @Inject  FlowdockNotificationService(SeyrenConfig seyrenConfig); protected  FlowdockNotificationService(SeyrenConfig seyrenConfig, String baseUrl); @Override void sendNotification(Check check, Subscription subscription, List<Alert> alerts); @Override boolean canHandle(SubscriptionType subscriptionType); }
FlowdockNotificationService implements NotificationService { @Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String token = subscription.getTarget(); String externalUsername = seyrenConfig.getFlowdockExternalUsername(); List<String> tags = Lists.newArrayList( Splitter.on(',').omitEmptyStrings().trimResults().split(seyrenConfig.getFlowdockTags()) ); List<String> emojis = Lists.newArrayList( Splitter.on(',').omitEmptyStrings().trimResults().split(seyrenConfig.getFlowdockEmojis()) ); String url = String.format("%s/v1/messages/chat/%s", baseUrl, token); HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost post = new HttpPost(url); post.addHeader("Content-Type", "application/json"); post.addHeader("accept", "application/json"); ObjectMapper mapper = new ObjectMapper(); Map<String, Object> dataToSend = new HashMap<String, Object>(); dataToSend.put("content", formatContent(emojis, check, subscription, alerts)); dataToSend.put("external_user_name", externalUsername); dataToSend.put("tags", formatTags(tags, check, subscription, alerts)); try { String data = StringEscapeUtils.unescapeJava(mapper.writeValueAsString(dataToSend)); post.setEntity(new StringEntity(data, APPLICATION_JSON)); client.execute(post); } catch (Exception e) { LOGGER.warn("Error posting to Flowdock", e); } finally { post.releaseConnection(); HttpClientUtils.closeQuietly(client); } } @Inject  FlowdockNotificationService(SeyrenConfig seyrenConfig); protected  FlowdockNotificationService(SeyrenConfig seyrenConfig, String baseUrl); @Override void sendNotification(Check check, Subscription subscription, List<Alert> alerts); @Override boolean canHandle(SubscriptionType subscriptionType);  }