Search in sources :

Example 6 with EmailAggregation

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");
}
Also used : Context(com.redhat.cloud.notifications.ingress.Context) Action(com.redhat.cloud.notifications.ingress.Action) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation) TemplateInstance(io.quarkus.qute.TemplateInstance) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 7 with EmailAggregation

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;
}
Also used : Context(com.redhat.cloud.notifications.ingress.Context) Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) JsonObject(io.vertx.core.json.JsonObject) Payload(com.redhat.cloud.notifications.ingress.Payload) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Example 8 with EmailAggregation

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;
}
Also used : Context(com.redhat.cloud.notifications.ingress.Context) Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) JsonObject(io.vertx.core.json.JsonObject) Payload(com.redhat.cloud.notifications.ingress.Payload) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Example 9 with EmailAggregation

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;
}
Also used : Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) JsonObject(io.vertx.core.json.JsonObject) Payload(com.redhat.cloud.notifications.ingress.Payload) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Example 10 with EmailAggregation

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;
}
Also used : Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) JsonObject(io.vertx.core.json.JsonObject) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Aggregations

EmailAggregation (com.redhat.cloud.notifications.models.EmailAggregation)19 JsonObject (io.vertx.core.json.JsonObject)13 Action (com.redhat.cloud.notifications.ingress.Action)11 Event (com.redhat.cloud.notifications.ingress.Event)9 Payload (com.redhat.cloud.notifications.ingress.Payload)8 Context (com.redhat.cloud.notifications.ingress.Context)5 QuarkusTest (io.quarkus.test.junit.QuarkusTest)5 Test (org.junit.jupiter.api.Test)5 EmailAggregationKey (com.redhat.cloud.notifications.models.EmailAggregationKey)4 LocalDateTime (java.time.LocalDateTime)4 EmailAggregationRepository (com.redhat.cloud.notifications.db.repositories.EmailAggregationRepository)2 EmailSubscriptionRepository (com.redhat.cloud.notifications.db.repositories.EmailSubscriptionRepository)2 EmailSubscriptionType (com.redhat.cloud.notifications.models.EmailSubscriptionType)2 Endpoint (com.redhat.cloud.notifications.models.Endpoint)2 RecipientResolver (com.redhat.cloud.notifications.recipients.RecipientResolver)2 User (com.redhat.cloud.notifications.recipients.User)2 ActionRecipientSettings (com.redhat.cloud.notifications.recipients.request.ActionRecipientSettings)2 EndpointRecipientSettings (com.redhat.cloud.notifications.recipients.request.EndpointRecipientSettings)2 TemplateInstance (io.quarkus.qute.TemplateInstance)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1