Search in sources :

Example 26 with EventType

use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.

the class ApplicationRepository method getEventTypes.

public List<EventType> getEventTypes(UUID appId) {
    String query = "FROM EventType WHERE application.id = :appId";
    Application app = entityManager.find(Application.class, appId);
    if (app == null) {
        throw new NotFoundException();
    } else {
        List<EventType> eventTypes = entityManager.createQuery(query, EventType.class).setParameter("appId", appId).getResultList();
        for (EventType eventType : eventTypes) {
            eventType.filterOutApplication();
        }
        return eventTypes;
    }
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) NotFoundException(javax.ws.rs.NotFoundException) Application(com.redhat.cloud.notifications.models.Application)

Example 27 with EventType

use of com.redhat.cloud.notifications.models.EventType 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 EventType

use of com.redhat.cloud.notifications.models.EventType 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 29 with EventType

use of com.redhat.cloud.notifications.models.EventType 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)

Example 30 with EventType

use of com.redhat.cloud.notifications.models.EventType 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)

Aggregations

EventType (com.redhat.cloud.notifications.models.EventType)36 QuarkusTest (io.quarkus.test.junit.QuarkusTest)16 Test (org.junit.jupiter.api.Test)16 Application (com.redhat.cloud.notifications.models.Application)14 Bundle (com.redhat.cloud.notifications.models.Bundle)11 Transactional (javax.transaction.Transactional)10 BehaviorGroup (com.redhat.cloud.notifications.models.BehaviorGroup)9 Action (com.redhat.cloud.notifications.ingress.Action)7 TestHelpers.serializeAction (com.redhat.cloud.notifications.TestHelpers.serializeAction)6 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)6 UUID (java.util.UUID)5 Event (com.redhat.cloud.notifications.models.Event)4 NotFoundException (javax.ws.rs.NotFoundException)4 AggregationEmailTemplate (com.redhat.cloud.notifications.models.AggregationEmailTemplate)3 InstantEmailTemplate (com.redhat.cloud.notifications.models.InstantEmailTemplate)3 Template (com.redhat.cloud.notifications.models.Template)3 Header (io.restassured.http.Header)3 Endpoint (com.redhat.cloud.notifications.models.Endpoint)2 JsonArray (io.vertx.core.json.JsonArray)2 JsonObject (io.vertx.core.json.JsonObject)2