Search in sources :

Example 16 with Action

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

Example 17 with Action

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

Example 18 with Action

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

Example 19 with Action

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;
}
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 20 with Action

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;
}
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)

Aggregations

Action (com.redhat.cloud.notifications.ingress.Action)49 Test (org.junit.jupiter.api.Test)22 QuarkusTest (io.quarkus.test.junit.QuarkusTest)20 Payload (com.redhat.cloud.notifications.ingress.Payload)19 JsonObject (io.vertx.core.json.JsonObject)17 Event (com.redhat.cloud.notifications.ingress.Event)15 Context (com.redhat.cloud.notifications.ingress.Context)14 EmailAggregation (com.redhat.cloud.notifications.models.EmailAggregation)12 Event (com.redhat.cloud.notifications.models.Event)12 TestHelpers.serializeAction (com.redhat.cloud.notifications.TestHelpers.serializeAction)9 Endpoint (com.redhat.cloud.notifications.models.Endpoint)8 EventType (com.redhat.cloud.notifications.models.EventType)7 NotificationHistory (com.redhat.cloud.notifications.models.NotificationHistory)7 LocalDateTime (java.time.LocalDateTime)7 JsonArray (io.vertx.core.json.JsonArray)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 TemplateInstance (io.quarkus.qute.TemplateInstance)5 MockServerLifecycleManager (com.redhat.cloud.notifications.MockServerLifecycleManager)4