String seyrenUrl = clientDriver.getBaseUrl() + "/seyren";
when(mockSeyrenConfig.getGraphiteUrl()).thenReturn(clientDriver.getBaseUrl() + "/graphite");
when(mockSeyrenConfig.getBaseUrl()).thenReturn(seyrenUrl);
Check check = new Check()
.withEnabled(true)
.withName("check-name")
.withTarget("statsd.metric.name")
.withState(AlertType.ERROR)
.withWarn(BigDecimal.ONE)
.withError(BigDecimal.TEN);
Subscription subscription = new Subscription()
.withType(SubscriptionType.HTTP)
.withTarget(clientDriver.getBaseUrl() + "/myendpoint/thatdoesstuff");
Alert alert = new Alert()
.withTarget("the.target.name")
.withValue(BigDecimal.valueOf(12))
.withWarn(BigDecimal.valueOf(5))
.withError(BigDecimal.valueOf(10))
.withFromType(AlertType.WARN)
.withToType(AlertType.ERROR);
List<Alert> alerts = Arrays.asList(alert);
BodyCapture<JsonNode> bodyCapture = new JsonBodyCapture();
clientDriver.addExpectation(
onRequestTo("/myendpoint/thatdoesstuff")
.withMethod(Method.POST)
.capturingBodyIn(bodyCapture),
giveResponse("success", "text/plain"));
service.sendNotification(check, subscription, alerts);
JsonNode node = bodyCapture.getContent();
assertThat(node, hasJsonPath("$.seyrenUrl", is(seyrenUrl)));
assertThat(node, hasJsonPath("$.check.name", is("check-name")));
assertThat(node, hasJsonPath("$.check.state", is("ERROR")));
assertThat(node, hasJsonPath("$.alerts", hasSize(1)));
assertThat(node, hasJsonPath("$.alerts[0].target", is("the.target.name")));
assertThat(node, hasJsonPath("$.alerts[0].value", is(12)));
assertThat(node, hasJsonPath("$.alerts[0].warn", is(5)));
assertThat(node, hasJsonPath("$.alerts[0].error", is(10)));
assertThat(node, hasJsonPath("$.alerts[0].fromType", is("WARN")));
assertThat(node, hasJsonPath("$.alerts[0].toType", is("ERROR")));
assertThat(node, hasJsonPath("$.preview", Matchers.startsWith("<br />")));
assertThat(node, hasJsonPath("$.preview", containsString(check.getTarget())));
verify(mockSeyrenConfig).getGraphiteUrl();
verify(mockSeyrenConfig).getBaseUrl();
}