use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class CrudTestHelpers method buildEventType.
public static EventType buildEventType(String appId, String name, String displayName, String description) {
EventType eventType = new EventType();
if (appId != null) {
eventType.setApplicationId(UUID.fromString(appId));
}
eventType.setName(name);
eventType.setDisplayName(displayName);
eventType.setDescription(description);
return eventType;
}
use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class EphemeralDataInitializer method persist.
@Transactional
void persist(EphemeralData data) {
if (data.bundles != null) {
for (com.redhat.cloud.notifications.ephemeral.Bundle b : data.bundles) {
String selectBundleQuery = "FROM Bundle WHERE name = :bundleName";
Bundle bundle;
try {
bundle = entityManager.createQuery(selectBundleQuery, Bundle.class).setParameter("bundleName", b.name).getSingleResult();
LOGGER.infof("Bundle with name '%s' already exists, it won't be created from the ephemeral data", b.name);
} catch (NoResultException e) {
bundle = new Bundle();
bundle.setName(b.name);
bundle.setDisplayName(b.displayName);
entityManager.persist(bundle);
}
if (b.applications != null) {
for (com.redhat.cloud.notifications.ephemeral.Application a : b.applications) {
String selectAppQuery = "FROM Application WHERE bundle.name = :bundleName AND name = :appName";
Application app;
try {
app = entityManager.createQuery(selectAppQuery, Application.class).setParameter("bundleName", b.name).setParameter("appName", a.name).getSingleResult();
LOGGER.infof("Application with name '%s' already exists, it won't be created from the ephemeral data", a.name);
} catch (NoResultException e) {
app = new Application();
app.setName(a.name);
app.setDisplayName(a.displayName);
app.setBundle(bundle);
app.setBundleId(bundle.getId());
entityManager.persist(app);
}
if (a.eventTypes != null) {
for (com.redhat.cloud.notifications.ephemeral.EventType et : a.eventTypes) {
String selectEventTypeQuery = "FROM EventType WHERE application.bundle.name = :bundleName AND application.name = :appName AND name = :eventTypeName";
EventType eventType;
try {
entityManager.createQuery(selectEventTypeQuery, EventType.class).setParameter("bundleName", b.name).setParameter("appName", a.name).setParameter("eventTypeName", et.name).getSingleResult();
LOGGER.infof("Event type with name '%s' already exists, it won't be created from the ephemeral data", et.name);
} catch (NoResultException e) {
eventType = new EventType();
eventType.setName(et.name);
eventType.setDisplayName(et.displayName);
eventType.setDescription(et.description);
eventType.setApplication(app);
eventType.setApplicationId(app.getId());
entityManager.persist(eventType);
}
}
}
}
}
}
}
}
use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class EventConsumerTest method testInvalidMessageId.
@Test
void testInvalidMessageId() {
EventType eventType = mockGetEventTypeAndCreateEvent();
Action action = buildValidAction();
String payload = serializeAction(action);
Message<String> message = buildMessageWithId("I am not a valid UUID!".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_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.models.EventType in project notifications-backend by RedHatInsights.
the class EventConsumerTest method testProcessingErrorWithoutMessageId.
@Test
void testProcessingErrorWithoutMessageId() {
EventType eventType = mockGetEventTypeAndCreateEvent();
mockProcessingFailure();
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);
micrometerAssertionHelper.assertCounterIncrement(PROCESSING_ERROR_COUNTER_NAME, 1);
assertNoCounterIncrement(REJECTED_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);
}
use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class EventConsumerTest method mockGetEventTypeAndCreateEvent.
private EventType mockGetEventTypeAndCreateEvent() {
Bundle bundle = new Bundle();
bundle.setDisplayName("Bundle");
Application app = new Application();
app.setDisplayName("Application");
app.setBundle(bundle);
EventType eventType = new EventType();
eventType.setDisplayName("Event type");
eventType.setApplication(app);
when(eventTypeRepository.getEventType(eq(BUNDLE), eq(APP), eq(EVENT_TYPE))).thenReturn(eventType);
when(eventRepository.create(any(Event.class))).thenAnswer(invocation -> invocation.getArgument(0));
return eventType;
}
Aggregations