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