Search in sources :

Example 26 with Action

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

the class BaseTransformer method toJsonObject.

private JsonObject toJsonObject(Action action) {
    JsonObject message = new JsonObject();
    message.put("bundle", action.getBundle());
    message.put("application", action.getApplication());
    message.put("event_type", action.getEventType());
    message.put("account_id", action.getAccountId());
    message.put("timestamp", action.getTimestamp().toString());
    message.put("events", new JsonArray(action.getEvents().stream().map(event -> Map.of("metadata", JsonObject.mapFrom(event.getMetadata()), "payload", JsonObject.mapFrom(event.getPayload()))).collect(Collectors.toList())));
    message.put("context", JsonObject.mapFrom(action.getContext()));
    return message;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonArray(io.vertx.core.json.JsonArray) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Action(com.redhat.cloud.notifications.ingress.Action) Collectors(java.util.stream.Collectors) JsonObject(io.vertx.core.json.JsonObject)

Example 27 with Action

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

the class EventConsumerTest method testValidPayloadWithMessageId.

@Test
void testValidPayloadWithMessageId() {
    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);
    micrometerAssertionHelper.awaitAndAssertTimerIncrement(CONSUMED_TIMER_NAME, 1);
    assertEquals(1L, registry.timer(CONSUMED_TIMER_NAME, "bundle", action.getBundle(), "application", action.getApplication()).count());
    micrometerAssertionHelper.assertCounterIncrement(MESSAGE_ID_VALID_COUNTER_NAME, 1);
    assertNoCounterIncrement(REJECTED_COUNTER_NAME, PROCESSING_ERROR_COUNTER_NAME, PROCESSING_EXCEPTION_COUNTER_NAME, DUPLICATE_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 28 with Action

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

the class EventConsumerTest method buildValidAction.

private static Action buildValidAction() {
    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(DEFAULT_ACCOUNT_ID);
    action.setRecipients(List.of());
    action.setEvents(List.of(new com.redhat.cloud.notifications.ingress.Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("k", "v").withAdditionalProperty("k2", "v2").withAdditionalProperty("k3", "v").build()).build()));
    action.setContext(new Context.ContextBuilder().build());
    return action;
}
Also used : TestHelpers.serializeAction(com.redhat.cloud.notifications.TestHelpers.serializeAction) Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.models.Event)

Example 29 with Action

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

the class EventConsumerTest method testNullMessageId.

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

Example 30 with Action

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

the class EventConsumerTest method testValidPayloadWithoutMessageId.

@Test
void testValidPayloadWithoutMessageId() {
    EventType eventType = mockGetEventTypeAndCreateEvent();
    Action action = buildValidAction();
    String payload = serializeAction(action);
    inMemoryConnector.source(INGRESS_CHANNEL).send(payload);
    micrometerAssertionHelper.awaitAndAssertTimerIncrement(CONSUMED_TIMER_NAME, 1);
    assertEquals(1L, registry.timer(CONSUMED_TIMER_NAME, "bundle", action.getBundle(), "application", action.getApplication()).count());
    micrometerAssertionHelper.assertCounterIncrement(MESSAGE_ID_MISSING_COUNTER_NAME, 1);
    assertNoCounterIncrement(REJECTED_COUNTER_NAME, PROCESSING_ERROR_COUNTER_NAME, PROCESSING_EXCEPTION_COUNTER_NAME, DUPLICATE_COUNTER_NAME, MESSAGE_ID_VALID_COUNTER_NAME, MESSAGE_ID_INVALID_COUNTER_NAME);
    verifyExactlyOneProcessing(eventType, payload, action);
    verify(kafkaMessageDeduplicator, times(1)).registerMessageId(null);
}
Also used : TestHelpers.serializeAction(com.redhat.cloud.notifications.TestHelpers.serializeAction) Action(com.redhat.cloud.notifications.ingress.Action) EventType(com.redhat.cloud.notifications.models.EventType) 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