Search in sources :

Example 31 with Action

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

the class EventConsumerTest method testDuplicatePayload.

@Test
void testDuplicatePayload() {
    EventType eventType = mockGetEventTypeAndCreateEvent();
    Action action = buildValidAction();
    String payload = serializeAction(action);
    UUID messageId = UUID.randomUUID();
    Message<String> message = buildMessageWithId(messageId.toString().getBytes(UTF_8), payload);
    inMemoryConnector.source(INGRESS_CHANNEL).send(message);
    inMemoryConnector.source(INGRESS_CHANNEL).send(message);
    micrometerAssertionHelper.awaitAndAssertTimerIncrement(CONSUMED_TIMER_NAME, 2);
    assertEquals(2L, registry.timer(CONSUMED_TIMER_NAME, "bundle", action.getBundle(), "application", action.getApplication()).count());
    micrometerAssertionHelper.assertCounterIncrement(MESSAGE_ID_VALID_COUNTER_NAME, 2);
    micrometerAssertionHelper.assertCounterIncrement(DUPLICATE_COUNTER_NAME, 1);
    assertNoCounterIncrement(REJECTED_COUNTER_NAME, PROCESSING_ERROR_COUNTER_NAME, PROCESSING_EXCEPTION_COUNTER_NAME, MESSAGE_ID_INVALID_COUNTER_NAME, MESSAGE_ID_MISSING_COUNTER_NAME);
    verifyExactlyOneProcessing(eventType, payload, action);
    verify(kafkaMessageDeduplicator, times(1)).registerMessageId(messageId);
}
Also used : TestHelpers.serializeAction(com.redhat.cloud.notifications.TestHelpers.serializeAction) Action(com.redhat.cloud.notifications.ingress.Action) EventType(com.redhat.cloud.notifications.models.EventType) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 32 with Action

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

the class CamelTypeProcessorTest method buildEvent.

private static Event buildEvent() {
    Action action = new Action();
    action.setVersion("v1.0.0");
    action.setBundle("bundle");
    action.setApplication("app");
    action.setEventType("event-type");
    action.setTimestamp(LocalDateTime.now());
    action.setAccountId("account-id");
    action.setRecipients(List.of());
    action.setContext(new Context.ContextBuilder().build());
    action.setEvents(List.of(new com.redhat.cloud.notifications.ingress.Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("k1", "v1").withAdditionalProperty("k2", "v2").withAdditionalProperty("k3", "v3").build()).build()));
    Event event = new Event();
    event.setAction(action);
    return event;
}
Also used : Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.models.Event)

Example 33 with Action

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

the class RhosakEmailAggregatorTest method createUpgradeEmailAggregation.

private static EmailAggregation createUpgradeEmailAggregation(String kafkaName, String kafkaVersion) {
    EmailAggregation aggregation = new EmailAggregation();
    aggregation.setBundleName(APPLICATION_SERVICES);
    aggregation.setApplicationName(RHOSAK);
    aggregation.setAccountId(ACCOUNT_ID);
    Action emailActionMessage = new Action();
    emailActionMessage.setBundle(APPLICATION_SERVICES);
    emailActionMessage.setApplication(RHOSAK);
    emailActionMessage.setTimestamp(NOW);
    emailActionMessage.setEventType(SCHEDULED_UPGRADE);
    emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("kafka_version", kafkaVersion).withAdditionalProperty("upgrade_time", LocalDateTime.now().toString()).build());
    emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("id", kafkaName).withAdditionalProperty("name", kafkaName).build()).build()));
    emailActionMessage.setAccountId(ACCOUNT_ID);
    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 34 with Action

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

the class WebhookTest method buildWebhookAction.

private static Action buildWebhookAction() {
    Action webhookActionMessage = new Action();
    webhookActionMessage.setBundle("mybundle");
    webhookActionMessage.setApplication("WebhookTest");
    webhookActionMessage.setTimestamp(LocalDateTime.of(2020, 10, 3, 15, 22, 13, 25));
    webhookActionMessage.setEventType("testWebhook");
    webhookActionMessage.setAccountId("tenant");
    Payload payload1 = new Payload.PayloadBuilder().withAdditionalProperty("any", "thing").withAdditionalProperty("we", 1).withAdditionalProperty("want", "here").build();
    Context context = new Context.ContextBuilder().withAdditionalProperty("free", "more").withAdditionalProperty("format", 1).withAdditionalProperty("here", "stuff").build();
    webhookActionMessage.setEvents(List.of(new com.redhat.cloud.notifications.ingress.Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(payload1).build(), new com.redhat.cloud.notifications.ingress.Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().build()).build()));
    webhookActionMessage.setContext(context);
    return webhookActionMessage;
}
Also used : Context(com.redhat.cloud.notifications.ingress.Context) Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.models.Event) Payload(com.redhat.cloud.notifications.ingress.Payload)

Example 35 with Action

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

the class WebhookTest method testWebhook.

@Test
void testWebhook() {
    String url = getMockServerUrl() + "/foobar";
    final List<String> bodyRequests = new ArrayList<>();
    ExpectationResponseCallback verifyEmptyRequest = req -> {
        bodyRequests.add(req.getBodyAsString());
        return response().withStatusCode(200);
    };
    HttpRequest postReq = getMockHttpRequest(verifyEmptyRequest);
    Action webhookActionMessage = buildWebhookAction();
    Event event = new Event();
    event.setAction(webhookActionMessage);
    Endpoint ep = buildWebhookEndpoint(url);
    try {
        List<NotificationHistory> process = webhookTypeProcessor.process(event, List.of(ep));
        NotificationHistory history = process.get(0);
        assertTrue(history.isInvocationResult());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e);
    } finally {
        // Remove expectations
        MockServerLifecycleManager.getClient().clear(postReq);
    }
    assertEquals(1, bodyRequests.size());
    JsonObject webhookInput = new JsonObject(bodyRequests.get(0));
    assertEquals("mybundle", webhookInput.getString("bundle"));
    assertEquals("WebhookTest", webhookInput.getString("application"));
    assertEquals("testWebhook", webhookInput.getString("event_type"));
    assertEquals("tenant", webhookInput.getString("account_id"));
    JsonObject webhookInputContext = webhookInput.getJsonObject("context");
    assertEquals("more", webhookInputContext.getString("free"));
    assertEquals(1, webhookInputContext.getInteger("format"));
    assertEquals("stuff", webhookInputContext.getString("here"));
    JsonArray webhookInputEvents = webhookInput.getJsonArray("events");
    assertEquals(2, webhookInputEvents.size());
    JsonObject webhookInputPayload1 = webhookInputEvents.getJsonObject(0).getJsonObject("payload");
    assertEquals("thing", webhookInputPayload1.getString("any"));
    assertEquals(1, webhookInputPayload1.getInteger("we"));
    assertEquals("here", webhookInputPayload1.getString("want"));
}
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) ExpectationResponseCallback(org.mockserver.mock.action.ExpectationResponseCallback) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) JsonArray(io.vertx.core.json.JsonArray) Endpoint(com.redhat.cloud.notifications.models.Endpoint) NotificationHistory(com.redhat.cloud.notifications.models.NotificationHistory) Event(com.redhat.cloud.notifications.models.Event) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

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