Search in sources :

Example 11 with Action

use of com.redhat.cloud.notifications.ingress.Action 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 12 with Action

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

the class WebhookTest method testRetry.

private void testRetry(boolean shouldSucceedEventually) {
    String url = getMockServerUrl() + "/foobar";
    AtomicInteger callsCounter = new AtomicInteger();
    ExpectationResponseCallback expectationResponseCallback = request -> {
        if (callsCounter.incrementAndGet() == MAX_RETRY_ATTEMPTS && shouldSucceedEventually) {
            return response().withStatusCode(200);
        } else {
            return response().withStatusCode(500);
        }
    };
    HttpRequest mockServerRequest = getMockHttpRequest(expectationResponseCallback);
    try {
        Action action = buildWebhookAction();
        Event event = new Event();
        event.setAction(action);
        Endpoint ep = buildWebhookEndpoint(url);
        List<NotificationHistory> process = webhookTypeProcessor.process(event, List.of(ep));
        NotificationHistory history = process.get(0);
        assertEquals(shouldSucceedEventually, history.isInvocationResult());
        assertEquals(MAX_RETRY_ATTEMPTS, callsCounter.get());
    } finally {
        // Remove expectations
        MockServerLifecycleManager.getClient().clear(mockServerRequest);
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) HttpType(com.redhat.cloud.notifications.models.HttpType) HttpRequest(org.mockserver.model.HttpRequest) Endpoint(com.redhat.cloud.notifications.models.Endpoint) WebhookTypeProcessor(com.redhat.cloud.notifications.processors.webhooks.WebhookTypeProcessor) TestLifecycleManager(com.redhat.cloud.notifications.TestLifecycleManager) LocalDateTime(java.time.LocalDateTime) NotificationHistory(com.redhat.cloud.notifications.models.NotificationHistory) MockServerLifecycleManager(com.redhat.cloud.notifications.MockServerLifecycleManager) QuarkusTest(io.quarkus.test.junit.QuarkusTest) ArrayList(java.util.ArrayList) MockServerLifecycleManager.getMockServerUrl(com.redhat.cloud.notifications.MockServerLifecycleManager.getMockServerUrl) Inject(javax.inject.Inject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Event(com.redhat.cloud.notifications.models.Event) WebhookProperties(com.redhat.cloud.notifications.models.WebhookProperties) JsonObject(io.vertx.core.json.JsonObject) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Payload(com.redhat.cloud.notifications.ingress.Payload) Context(com.redhat.cloud.notifications.ingress.Context) QuarkusTestResource(io.quarkus.test.common.QuarkusTestResource) ExpectationResponseCallback(org.mockserver.mock.action.ExpectationResponseCallback) Test(org.junit.jupiter.api.Test) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) EndpointType(com.redhat.cloud.notifications.models.EndpointType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Metadata(com.redhat.cloud.notifications.ingress.Metadata) Action(com.redhat.cloud.notifications.ingress.Action) HttpResponse.response(org.mockserver.model.HttpResponse.response) HttpRequest(org.mockserver.model.HttpRequest) Action(com.redhat.cloud.notifications.ingress.Action) Endpoint(com.redhat.cloud.notifications.models.Endpoint) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExpectationResponseCallback(org.mockserver.mock.action.ExpectationResponseCallback) NotificationHistory(com.redhat.cloud.notifications.models.NotificationHistory) Event(com.redhat.cloud.notifications.models.Event)

Example 13 with Action

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

the class TestAdvisorTemplate method testInstantEmailBodyForDeactivatedRecommendation.

@Test
public void testInstantEmailBodyForDeactivatedRecommendation() {
    Action action = TestHelpers.createAdvisorAction("123456", "deactivated-recommendation");
    final String result = Advisor.Templates.deactivatedRecommendationInstantEmailBody().data("action", action).data("user", Map.of("firstName", "Testing")).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("affected_systems").toString()), "Body should contain affected systems" + event.getPayload().getAdditionalProperties().get("affected_systems"));
        assertTrue(result.contains(event.getPayload().getAdditionalProperties().get("deactivation_reason").toString()), "Body should contain deactivation reason" + event.getPayload().getAdditionalProperties().get("deactivation_reason"));
    });
    assertTrue(result.contains("<span class=\"rh-metric__count\">2</span>"), "Body should contain the number of deactivated recommendations");
    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("Hi Testing,"), "Body should contain user's first name");
}
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 14 with Action

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

the class TestAdvisorTemplate method testInstantEmailTitleForDeactivatedRecommendation.

@Test
public void testInstantEmailTitleForDeactivatedRecommendation() {
    Action action = TestHelpers.createAdvisorAction("123456", "deactivated-recommendation");
    String result = Advisor.Templates.deactivatedRecommendationInstantEmailTitle().data("action", action).render();
    assertEquals("Red Hat Enterprise Linux - Advisor Instant Notification - 03 Oct 2020 15:22 UTC - 2 deactivated 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.deactivatedRecommendationInstantEmailTitle().data("action", action).render();
    assertEquals("Red Hat Enterprise Linux - Advisor Instant Notification - 03 Oct 2020 15:22 UTC - 1 deactivated 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 15 with Action

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

the class TestAdvisorTemplate method testInstantEmailTitleForResolvedRecommendations.

@Test
void testInstantEmailTitleForResolvedRecommendations() {
    Action action = TestHelpers.createAdvisorAction("123456", "resolved-recommendation");
    String result = Advisor.Templates.resolvedRecommendationInstantEmailTitle().data("action", action).render();
    assertEquals("Red Hat Enterprise Linux - Advisor Instant Notification - 03 Oct 2020 15:22 UTC - 4 resolved 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.resolvedRecommendationInstantEmailTitle().data("action", action).render();
    assertEquals("Red Hat Enterprise Linux - Advisor Instant Notification - 03 Oct 2020 15:22 UTC - 1 resolved 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)

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