Search in sources :

Example 36 with Action

use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.

the class TestAdvisorTemplate method testInstantEmailTitleForNewRecommendations.

@Test
public void testInstantEmailTitleForNewRecommendations() {
    Action action = TestHelpers.createAdvisorAction("123456", "new-recommendation");
    String result = Advisor.Templates.newRecommendationInstantEmailTitle().data("action", action).render();
    assertEquals("Red Hat Enterprise Linux - Advisor Instant Notification - 03 Oct 2020 15:22 UTC - 4 new 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.newRecommendationInstantEmailTitle().data("action", action).render();
    assertEquals("Red Hat Enterprise Linux - Advisor Instant Notification - 03 Oct 2020 15:22 UTC - 1 new recommendation\n", result, "Title contains the number of reports created");
}
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 37 with Action

use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.

the class TestDriftTemplate method testInstantEmailTitle.

public void testInstantEmailTitle() {
    Action action = DriftTestHelpers.createDriftAction("tenant", "rhel", "drift", "host-01", "Machine 1");
    String result = Drift.Templates.newBaselineDriftInstantEmailTitle().data("action", action).render();
    assertTrue(result.contains("2 drifts from baseline detected on Machine 1"));
}
Also used : Action(com.redhat.cloud.notifications.ingress.Action)

Example 38 with Action

use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.

the class TestOpenshiftAdvisorTemplate method testInstantEmailTitle.

@Test
public void testInstantEmailTitle() {
    Action action = TestHelpers.createAdvisorOpenshiftAction("123456", "new-recommendation");
    String result = AdvisorOpenshift.Templates.newRecommendationInstantEmailTitle().data("action", action).render();
    assertTrue(result.contains("OpenShift - Advisor Instant Notification - "));
    assertTrue(result.contains("2021"));
}
Also used : Action(com.redhat.cloud.notifications.ingress.Action) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 39 with Action

use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.

the class TestOpenshiftAdvisorTemplate method testInstantEmailBody.

@Test
public void testInstantEmailBody() {
    Action action = TestHelpers.createAdvisorOpenshiftAction("123456", "new-recommendation");
    final String result = AdvisorOpenshift.Templates.newRecommendationInstantEmailBody().data("action", action).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("total_risk").toString()), "Body should contain total_risk" + event.getPayload().getAdditionalProperties().get("total_risk"));
        assertTrue(result.contains(event.getPayload().getAdditionalProperties().get("rule_url").toString()), "Body should contain rule_url" + event.getPayload().getAdditionalProperties().get("rule_url"));
    });
    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("some-cluster-name"), "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 = AdvisorOpenshift.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) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 40 with Action

use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.

the class TestPoliciesTemplate method testInstantEmailTitle.

@Test
public void testInstantEmailTitle() {
    Action action = TestHelpers.createPoliciesAction("", "", "", "FooMachine");
    String result = Policies.Templates.instantEmailTitle().data("action", action).render();
    assertTrue(result.contains("2"), "Title contains the number of policies triggered");
    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)

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