use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class TestAdvisorTemplate method testInstantEmailBodyForNewRecommendation.
@Test
public void testInstantEmailBodyForNewRecommendation() {
Action action = TestHelpers.createAdvisorAction("123456", "new-recommendation");
final String result = Advisor.Templates.newRecommendationInstantEmailBody().data("action", action).render();
action.getEvents().forEach(event -> {
assertTrue(result.contains(event.getPayload().getAdditionalProperties().get("rule_id").toString()), "Body should contain rule id" + event.getPayload().getAdditionalProperties().get("rule_id"));
assertTrue(result.contains(event.getPayload().getAdditionalProperties().get("rule_description").toString()), "Body should contain rule description" + event.getPayload().getAdditionalProperties().get("rule_description"));
});
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("alt=\"Important severity\""), "Body should contain important severity rule image");
assertTrue(result.contains("alt=\"Critical severity\""), "Body should contain critical severity rule image");
// Display name
assertTrue(result.contains("My Host"), "Body should contain the display_name");
action.setEvents(action.getEvents().stream().filter(event -> event.getPayload().getAdditionalProperties().get("total_risk").equals("1")).collect(Collectors.toList()));
String result2 = Advisor.Templates.newRecommendationInstantEmailBody().data("action", action).render();
assertTrue(result2.contains("alt=\"Low severity\""), "Body 2 should contain low severity rule image");
assertFalse(result2.contains("alt=\"Moderate severity\""), "Body 2 should not contain moderate severity rule image");
assertFalse(result2.contains("alt=\"Important severity\""), "Body 2 should not contain important severity rule image");
assertFalse(result2.contains("alt=\"Critical severity\""), "Body 2 should not contain critical severity rule image");
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class TestDriftTemplate method testInstantEmailBody.
@Test
public void testInstantEmailBody() {
Action action = DriftTestHelpers.createDriftAction("tenant", "rhel", "drift", "host-01", "Machine 1");
String result = Drift.Templates.newBaselineDriftInstantEmailBody().data("action", action).render();
assertTrue(result.contains("baseline_01"));
assertTrue(result.contains("Machine 1"));
// writeEmailTemplate(result, "instantEmail.html");
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class TestPoliciesTemplate method testInstantEmailBody.
@Test
public void testInstantEmailBody() {
Action action = TestHelpers.createPoliciesAction("", "", "", "FooMachine");
String result = Policies.Templates.instantEmailBody().data("action", action).render();
assertTrue(result.contains(TestHelpers.policyId1), "Body should contain policy id" + TestHelpers.policyId1);
assertTrue(result.contains(TestHelpers.policyName1), "Body should contain policy name" + TestHelpers.policyName1);
assertTrue(result.contains(TestHelpers.policyId2), "Body should contain policy id" + TestHelpers.policyId2);
assertTrue(result.contains(TestHelpers.policyName2), "Body should contain policy name" + TestHelpers.policyName2);
// Display name
assertTrue(result.contains("FooMachine"), "Body should contain the display_name");
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class PatchTestHelpers method createEmailAggregation.
public static EmailAggregation createEmailAggregation(String tenant, String bundle, String application, String advisoryName, String advisoryType, String inventory_id) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setBundleName(bundle);
aggregation.setApplicationName(application);
aggregation.setAccountId(tenant);
Action emailActionMessage = new Action();
emailActionMessage.setBundle(bundle);
emailActionMessage.setApplication(application);
emailActionMessage.setTimestamp(LocalDateTime.now());
emailActionMessage.setEventType("new-advisories");
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", inventory_id).build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty(ADVISORY_NAME, advisoryName).withAdditionalProperty(ADVISORY_TYPE, advisoryType).build()).build()));
emailActionMessage.setAccountId(tenant);
JsonObject payload = baseTransformer.transform(emailActionMessage);
aggregation.setPayload(payload);
return aggregation;
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class PatchTestHelpers method createEmailAggregationMultipleEvents.
public static EmailAggregation createEmailAggregationMultipleEvents(String tenant, String bundle, String application) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setBundleName(bundle);
aggregation.setApplicationName(application);
aggregation.setAccountId(tenant);
Action emailActionMessage = new Action();
emailActionMessage = new Action();
emailActionMessage.setBundle(bundle);
emailActionMessage.setApplication(application);
emailActionMessage.setTimestamp(LocalDateTime.now());
emailActionMessage.setEventType("new-advisories");
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", "inventory_id").build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty(ADVISORY_NAME, "RH-1").withAdditionalProperty(ADVISORY_TYPE, "ENHANCEMENT").build()).build(), new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty(ADVISORY_NAME, "RH-2").withAdditionalProperty(ADVISORY_TYPE, "BUGFIX").build()).build(), new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty(ADVISORY_NAME, "RH-3").withAdditionalProperty(ADVISORY_TYPE, "UNKNOWN").build()).build()));
emailActionMessage.setAccountId(tenant);
JsonObject payload = baseTransformer.transform(emailActionMessage);
aggregation.setPayload(payload);
return aggregation;
}
Aggregations