use of com.redhat.cloud.notifications.models.EmailAggregation 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.models.EmailAggregation 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.models.EmailAggregation 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;
}
use of com.redhat.cloud.notifications.models.EmailAggregation in project notifications-backend by RedHatInsights.
the class TestHelpers method createEmailAggregation.
public static EmailAggregation createEmailAggregation(String tenant, String bundle, String application, String policyId, 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(eventType);
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", inventory_id).withAdditionalProperty("system_check_in", "2020-08-03T15:22:42.199046").withAdditionalProperty("display_name", "My test machine").withAdditionalProperty("tags", List.of()).build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("policy_id", policyId).withAdditionalProperty("policy_name", "not-tested-name").withAdditionalProperty("policy_description", "not-used-desc").withAdditionalProperty("policy_condition", "not-used-condition").build()).build()));
emailActionMessage.setAccountId(tenant);
JsonObject payload = baseTransformer.transform(emailActionMessage);
aggregation.setPayload(payload);
return aggregation;
}
use of com.redhat.cloud.notifications.models.EmailAggregation in project notifications-backend by RedHatInsights.
the class VulnerabilityTestHelpers method createEmailAggregation.
public static EmailAggregation createEmailAggregation(String tenant, String bundle, String application, String eventType, String cve) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setAccountId(tenant);
aggregation.setBundleName(bundle);
aggregation.setApplicationName(application);
Action emailActionMessage = new Action();
emailActionMessage.setAccountId(tenant);
emailActionMessage.setApplication(application);
emailActionMessage.setBundle(bundle);
emailActionMessage.setTimestamp(LocalDateTime.now());
emailActionMessage.setEventType(eventType);
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("reported_cve", cve).build()).build()));
JsonObject payload = baseTransformer.transform(emailActionMessage);
aggregation.setPayload(payload);
return aggregation;
}
Aggregations