use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class RhosakEmailAggregatorTest method allAggregationTests.
@Test
void allAggregationTests() {
String kafkaName = "my-kafka";
// disruption aggregation
EmailAggregation aggregation = createDisruptionEmailAggregation(kafkaName, "performance");
aggregator.processEmailAggregation(aggregation);
// check upgrades aggregation
aggregation = createUpgradeEmailAggregation(kafkaName, "2.8.0");
aggregator.processEmailAggregation(aggregation);
assertEquals(1, disruptions.size(), "aggregator should have content in disruption body");
assertEquals(1, upgrades.size(), "aggregator should have content in upgrades body");
// test template render
TemplateInstance dailyBodyTemplateInstance = Templates.dailyRhosakEmailsBody();
TemplateInstance dailyTittleTemplateInstance = Templates.dailyRhosakEmailsTitle();
Action emailActionMessage = new Action();
aggregator.setStartTime(LocalDateTime.now());
Context.ContextBuilder contextBuilder = new Context.ContextBuilder();
aggregator.getContext().forEach(contextBuilder::withAdditionalProperty);
emailActionMessage.setContext(contextBuilder.build());
String title = dailyTittleTemplateInstance.data("action", emailActionMessage).render();
assertTrue(title.contains("Red Hat OpenShift Streams for Apache Kafka Daily Report"), "Title must contain RHOSAK related digest info");
String body = dailyBodyTemplateInstance.data("action", emailActionMessage).data("user", Map.of("firstName", "machi1990", "lastName", "Last Name")).render();
assertTrue(body.contains("The following table summarizes the OpenShift Streams instances affected by unexpected disruptions of the OpenShift Streams service."), "Body must contain service disruption summary");
assertTrue(body.contains("The following table summarizes Kafka upgrade activity for your OpenShift Streams instances."), "Body must contain upgrades summary");
assertTrue(body.contains("Hello machi1990."), "Body must contain greeting message");
assertTrue(body.contains("This is the daily report for your OpenShift Streams instances"), "Body must contain greeting message");
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class WebhookTest method testRetry.
private void testRetry(boolean shouldSucceedEventually) {
String url = getMockServerUrl() + "/foobar";
AtomicInteger callsCounter = new AtomicInteger();
ExpectationResponseCallback expectationResponseCallback = request -> {
if (callsCounter.incrementAndGet() == MAX_RETRY_ATTEMPTS && shouldSucceedEventually) {
return response().withStatusCode(200);
} else {
return response().withStatusCode(500);
}
};
HttpRequest mockServerRequest = getMockHttpRequest(expectationResponseCallback);
try {
Action action = buildWebhookAction();
Event event = new Event();
event.setAction(action);
Endpoint ep = buildWebhookEndpoint(url);
List<NotificationHistory> process = webhookTypeProcessor.process(event, List.of(ep));
NotificationHistory history = process.get(0);
assertEquals(shouldSucceedEventually, history.isInvocationResult());
assertEquals(MAX_RETRY_ATTEMPTS, callsCounter.get());
} finally {
// Remove expectations
MockServerLifecycleManager.getClient().clear(mockServerRequest);
}
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class TestAdvisorTemplate method testInstantEmailBodyForDeactivatedRecommendation.
@Test
public void testInstantEmailBodyForDeactivatedRecommendation() {
Action action = TestHelpers.createAdvisorAction("123456", "deactivated-recommendation");
final String result = Advisor.Templates.deactivatedRecommendationInstantEmailBody().data("action", action).data("user", Map.of("firstName", "Testing")).render();
action.getEvents().forEach(event -> {
assertTrue(result.contains(event.getPayload().getAdditionalProperties().get("rule_description").toString()), "Body should contain rule description" + event.getPayload().getAdditionalProperties().get("rule_description"));
assertTrue(result.contains(event.getPayload().getAdditionalProperties().get("affected_systems").toString()), "Body should contain affected systems" + event.getPayload().getAdditionalProperties().get("affected_systems"));
assertTrue(result.contains(event.getPayload().getAdditionalProperties().get("deactivation_reason").toString()), "Body should contain deactivation reason" + event.getPayload().getAdditionalProperties().get("deactivation_reason"));
});
assertTrue(result.contains("<span class=\"rh-metric__count\">2</span>"), "Body should contain the number of deactivated recommendations");
assertTrue(result.contains("alt=\"Low severity\""), "Body should contain low severity rule image");
assertTrue(result.contains("alt=\"Moderate severity\""), "Body should contain moderate severity rule image");
assertTrue(result.contains("Hi Testing,"), "Body should contain user's first name");
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class TestAdvisorTemplate method testInstantEmailTitleForDeactivatedRecommendation.
@Test
public void testInstantEmailTitleForDeactivatedRecommendation() {
Action action = TestHelpers.createAdvisorAction("123456", "deactivated-recommendation");
String result = Advisor.Templates.deactivatedRecommendationInstantEmailTitle().data("action", action).render();
assertEquals("Red Hat Enterprise Linux - Advisor Instant Notification - 03 Oct 2020 15:22 UTC - 2 deactivated recommendations\n", result, "Title contains the number of reports created");
// Action with only 1 event
action.setEvents(List.of(action.getEvents().get(0)));
result = Advisor.Templates.deactivatedRecommendationInstantEmailTitle().data("action", action).render();
assertEquals("Red Hat Enterprise Linux - Advisor Instant Notification - 03 Oct 2020 15:22 UTC - 1 deactivated recommendation\n", result, "Title contains the number of reports created");
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class TestAdvisorTemplate method testInstantEmailTitleForResolvedRecommendations.
@Test
void testInstantEmailTitleForResolvedRecommendations() {
Action action = TestHelpers.createAdvisorAction("123456", "resolved-recommendation");
String result = Advisor.Templates.resolvedRecommendationInstantEmailTitle().data("action", action).render();
assertEquals("Red Hat Enterprise Linux - Advisor Instant Notification - 03 Oct 2020 15:22 UTC - 4 resolved recommendations\n", result, "Title contains the number of reports created");
// Action with only 1 event
action.setEvents(List.of(action.getEvents().get(0)));
result = Advisor.Templates.resolvedRecommendationInstantEmailTitle().data("action", action).render();
assertEquals("Red Hat Enterprise Linux - Advisor Instant Notification - 03 Oct 2020 15:22 UTC - 1 resolved recommendation\n", result, "Title contains the number of reports created");
}
Aggregations