Search in sources :

Example 1 with EventLogEntry

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

the class EventResourceTest method assertSameEvent.

private static void assertSameEvent(EventLogEntry eventLogEntry, Event event, NotificationHistory... historyEntries) {
    assertEquals(event.getId(), eventLogEntry.getId());
    // Jackson's serialization gets rid of nanoseconds so an equals between the LocalDateTime objects won't work.
    assertEquals(event.getCreated().toEpochSecond(UTC), eventLogEntry.getCreated().toEpochSecond(UTC));
    assertEquals(event.getBundleDisplayName(), eventLogEntry.getBundle());
    assertEquals(event.getApplicationDisplayName(), eventLogEntry.getApplication());
    assertEquals(event.getEventTypeDisplayName(), eventLogEntry.getEventType());
    if (historyEntries == null) {
        assertTrue(eventLogEntry.getActions().isEmpty());
    } else {
        assertEquals(historyEntries.length, eventLogEntry.getActions().size());
        for (EventLogEntryAction eventLogEntryAction : eventLogEntry.getActions()) {
            Optional<NotificationHistory> historyEntry = Arrays.stream(historyEntries).filter(entry -> entry.getId().equals(eventLogEntryAction.getId())).findAny();
            assertTrue(historyEntry.isPresent());
            assertEquals(historyEntry.get().getEndpointType(), eventLogEntryAction.getEndpointType());
            assertEquals(historyEntry.get().getEndpointSubType(), eventLogEntryAction.getEndpointSubType());
            assertEquals(historyEntry.get().isInvocationResult(), eventLogEntryAction.getInvocationResult());
        }
    }
}
Also used : Arrays(java.util.Arrays) ResourceHelpers(com.redhat.cloud.notifications.db.ResourceHelpers) Endpoint(com.redhat.cloud.notifications.models.Endpoint) TestLifecycleManager(com.redhat.cloud.notifications.TestLifecycleManager) FULL_ACCESS(com.redhat.cloud.notifications.MockServerConfig.RbacAccess.FULL_ACCESS) Header(io.restassured.http.Header) NotificationHistory(com.redhat.cloud.notifications.models.NotificationHistory) DEFAULT_ORG_ID(com.redhat.cloud.notifications.TestConstants.DEFAULT_ORG_ID) NO_ACCESS(com.redhat.cloud.notifications.MockServerConfig.RbacAccess.NO_ACCESS) RequestSpecification(io.restassured.specification.RequestSpecification) Map(java.util.Map) TypeRef(io.restassured.common.mapper.TypeRef) Event(com.redhat.cloud.notifications.models.Event) QuarkusTestResource(io.quarkus.test.common.QuarkusTestResource) Application(com.redhat.cloud.notifications.models.Application) PATH(com.redhat.cloud.notifications.routers.EventResource.PATH) JSON(io.restassured.http.ContentType.JSON) Transactional(javax.transaction.Transactional) Set(java.util.Set) EMAIL_SUBSCRIPTION(com.redhat.cloud.notifications.models.EndpointType.EMAIL_SUBSCRIPTION) UUID(java.util.UUID) DEFAULT_ACCOUNT_ID(com.redhat.cloud.notifications.TestConstants.DEFAULT_ACCOUNT_ID) Test(org.junit.jupiter.api.Test) NOTIFICATIONS_READ_ACCESS_ONLY(com.redhat.cloud.notifications.MockServerConfig.RbacAccess.NOTIFICATIONS_READ_ACCESS_ONLY) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UTC(java.time.ZoneOffset.UTC) Optional(java.util.Optional) TestHelpers(com.redhat.cloud.notifications.TestHelpers) RestAssured.given(io.restassured.RestAssured.given) TRUE(java.lang.Boolean.TRUE) LocalDateTime(java.time.LocalDateTime) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) EndpointRepository(com.redhat.cloud.notifications.db.repositories.EndpointRepository) MockServerConfig(com.redhat.cloud.notifications.MockServerConfig) EventLogEntry(com.redhat.cloud.notifications.routers.models.EventLogEntry) QuarkusTest(io.quarkus.test.junit.QuarkusTest) WEBHOOK(com.redhat.cloud.notifications.models.EndpointType.WEBHOOK) Inject(javax.inject.Inject) NOTIFICATIONS_ACCESS_ONLY(com.redhat.cloud.notifications.MockServerConfig.RbacAccess.NOTIFICATIONS_ACCESS_ONLY) EventType(com.redhat.cloud.notifications.models.EventType) RbacAccess(com.redhat.cloud.notifications.MockServerConfig.RbacAccess) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest) FALSE(java.lang.Boolean.FALSE) Bundle(com.redhat.cloud.notifications.models.Bundle) EntityManager(javax.persistence.EntityManager) CAMEL(com.redhat.cloud.notifications.models.EndpointType.CAMEL) UUID.randomUUID(java.util.UUID.randomUUID) Page(com.redhat.cloud.notifications.routers.models.Page) EventLogEntryAction(com.redhat.cloud.notifications.routers.models.EventLogEntryAction) EventLogEntryAction(com.redhat.cloud.notifications.routers.models.EventLogEntryAction) NotificationHistory(com.redhat.cloud.notifications.models.NotificationHistory)

Example 2 with EventLogEntry

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

the class EventResource method getEvents.

@GET
@Produces(APPLICATION_JSON)
@RolesAllowed(RBAC_READ_NOTIFICATIONS_EVENTS)
@Operation(summary = "Retrieve the event log entries.")
public Page<EventLogEntry> getEvents(@Context SecurityContext securityContext, @RestQuery Set<UUID> bundleIds, @RestQuery Set<UUID> appIds, @RestQuery String eventTypeDisplayName, @RestQuery LocalDate startDate, @RestQuery LocalDate endDate, @RestQuery Set<String> endpointTypes, @RestQuery Set<Boolean> invocationResults, @RestQuery @DefaultValue("10") int limit, @RestQuery @DefaultValue("0") int offset, @RestQuery String sortBy, @RestQuery boolean includeDetails, @RestQuery boolean includePayload, @RestQuery boolean includeActions) {
    if (limit < 1 || limit > 200) {
        throw new BadRequestException("Invalid 'limit' query parameter, its value must be between 1 and 200");
    }
    if (sortBy != null && !SORT_BY_PATTERN.matcher(sortBy).matches()) {
        throw new BadRequestException("Invalid 'sortBy' query parameter");
    }
    Set<EndpointType> basicTypes = Collections.emptySet();
    Set<CompositeEndpointType> compositeTypes = Collections.emptySet();
    if (endpointTypes != null && endpointTypes.size() > 0) {
        basicTypes = new HashSet<>();
        compositeTypes = new HashSet<>();
        for (String stringEndpointType : endpointTypes) {
            try {
                CompositeEndpointType compositeType = CompositeEndpointType.fromString(stringEndpointType);
                if (compositeType.getSubType() == null) {
                    basicTypes.add(compositeType.getType());
                } else {
                    compositeTypes.add(compositeType);
                }
            } catch (IllegalArgumentException e) {
                throw new BadRequestException("Unknown endpoint type: [" + stringEndpointType + "]", e);
            }
        }
    }
    String accountId = getAccountId(securityContext);
    List<Event> events = eventRepository.getEvents(accountId, bundleIds, appIds, eventTypeDisplayName, startDate, endDate, basicTypes, compositeTypes, invocationResults, includeActions, limit, offset, sortBy);
    List<EventLogEntry> eventLogEntries = events.stream().map(event -> {
        List<EventLogEntryAction> actions;
        if (!includeActions) {
            actions = Collections.emptyList();
        } else {
            actions = event.getHistoryEntries().stream().map(historyEntry -> {
                EventLogEntryAction action = new EventLogEntryAction();
                action.setId(historyEntry.getId());
                action.setEndpointId(historyEntry.getEndpointId());
                action.setEndpointType(historyEntry.getEndpointType());
                action.setEndpointSubType(historyEntry.getEndpointSubType());
                action.setInvocationResult(historyEntry.isInvocationResult());
                if (includeDetails) {
                    action.setDetails(historyEntry.getDetails());
                }
                return action;
            }).collect(Collectors.toList());
        }
        EventLogEntry entry = new EventLogEntry();
        entry.setId(event.getId());
        entry.setCreated(event.getCreated());
        entry.setBundle(event.getBundleDisplayName());
        entry.setApplication(event.getApplicationDisplayName());
        entry.setEventType(event.getEventTypeDisplayName());
        entry.setActions(actions);
        if (includePayload) {
            entry.setPayload(event.getPayload());
        }
        return entry;
    }).collect(Collectors.toList());
    Long count = eventRepository.count(accountId, bundleIds, appIds, eventTypeDisplayName, startDate, endDate, basicTypes, compositeTypes, invocationResults);
    Meta meta = new Meta();
    meta.setCount(count);
    Map<String, String> links = PageLinksBuilder.build(PATH, count, limit, offset);
    Page<EventLogEntry> page = new Page<>();
    page.setData(eventLogEntries);
    page.setMeta(meta);
    page.setLinks(links);
    return page;
}
Also used : CompositeEndpointType(com.redhat.cloud.notifications.models.CompositeEndpointType) API_NOTIFICATIONS_V_1_0(com.redhat.cloud.notifications.Constants.API_NOTIFICATIONS_V_1_0) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) EventLogEntry(com.redhat.cloud.notifications.routers.models.EventLogEntry) CASE_INSENSITIVE(java.util.regex.Pattern.CASE_INSENSITIVE) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) SecurityContextUtil.getAccountId(com.redhat.cloud.notifications.routers.SecurityContextUtil.getAccountId) Event(com.redhat.cloud.notifications.models.Event) BadRequestException(javax.ws.rs.BadRequestException) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) RestQuery(org.jboss.resteasy.reactive.RestQuery) PATH(com.redhat.cloud.notifications.routers.EventResource.PATH) Meta(com.redhat.cloud.notifications.routers.models.Meta) Context(javax.ws.rs.core.Context) PageLinksBuilder(com.redhat.cloud.notifications.routers.models.PageLinksBuilder) RBAC_READ_NOTIFICATIONS_EVENTS(com.redhat.cloud.notifications.auth.ConsoleIdentityProvider.RBAC_READ_NOTIFICATIONS_EVENTS) Set(java.util.Set) Operation(org.eclipse.microprofile.openapi.annotations.Operation) UUID(java.util.UUID) EventRepository(com.redhat.cloud.notifications.db.repositories.EventRepository) Collectors(java.util.stream.Collectors) List(java.util.List) EndpointType(com.redhat.cloud.notifications.models.EndpointType) Page(com.redhat.cloud.notifications.routers.models.Page) LocalDate(java.time.LocalDate) EventLogEntryAction(com.redhat.cloud.notifications.routers.models.EventLogEntryAction) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) Meta(com.redhat.cloud.notifications.routers.models.Meta) EventLogEntry(com.redhat.cloud.notifications.routers.models.EventLogEntry) Page(com.redhat.cloud.notifications.routers.models.Page) CompositeEndpointType(com.redhat.cloud.notifications.models.CompositeEndpointType) EventLogEntryAction(com.redhat.cloud.notifications.routers.models.EventLogEntryAction) CompositeEndpointType(com.redhat.cloud.notifications.models.CompositeEndpointType) EndpointType(com.redhat.cloud.notifications.models.EndpointType) BadRequestException(javax.ws.rs.BadRequestException) Event(com.redhat.cloud.notifications.models.Event) List(java.util.List) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 3 with EventLogEntry

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

the class EventResourceTest method testAllQueryParams.

@Test
void testAllQueryParams() {
    /*
         * This method is very long, but splitting it into several smaller ones would mean we have to recreate lots of
         * database records for each test. To avoid doing that, the data is only persisted once and many tests are run
         * from the same data.
         */
    Header defaultIdentityHeader = mockRbac(DEFAULT_ACCOUNT_ID, DEFAULT_ORG_ID, "user", FULL_ACCESS);
    Header otherIdentityHeader = mockRbac(OTHER_ACCOUNT_ID, DEFAULT_ORG_ID, "other-username", FULL_ACCESS);
    Bundle bundle1 = resourceHelpers.createBundle("bundle-1", "Bundle 1");
    Bundle bundle2 = resourceHelpers.createBundle("bundle-2", "Bundle 2");
    Application app1 = resourceHelpers.createApplication(bundle1.getId(), "app-1", "Application 1");
    Application app2 = resourceHelpers.createApplication(bundle2.getId(), "app-2", "Application 2");
    EventType eventType1 = resourceHelpers.createEventType(app1.getId(), "event-type-1", "Event type 1", "Event type 1");
    EventType eventType2 = resourceHelpers.createEventType(app2.getId(), "event-type-2", "Event type 2", "Event type 2");
    Event event1 = createEvent(DEFAULT_ACCOUNT_ID, bundle1, app1, eventType1, NOW.minusDays(5L));
    Event event2 = createEvent(DEFAULT_ACCOUNT_ID, bundle2, app2, eventType2, NOW);
    Event event3 = createEvent(DEFAULT_ACCOUNT_ID, bundle2, app2, eventType2, NOW.minusDays(2L));
    Event event4 = createEvent(OTHER_ACCOUNT_ID, bundle2, app2, eventType2, NOW.minusDays(10L));
    Endpoint endpoint1 = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, WEBHOOK);
    Endpoint endpoint2 = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, EMAIL_SUBSCRIPTION);
    Endpoint endpoint3 = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, CAMEL, "SlAcK");
    NotificationHistory history1 = resourceHelpers.createNotificationHistory(event1, endpoint1, TRUE);
    NotificationHistory history2 = resourceHelpers.createNotificationHistory(event1, endpoint2, FALSE);
    NotificationHistory history3 = resourceHelpers.createNotificationHistory(event2, endpoint1, TRUE);
    NotificationHistory history4 = resourceHelpers.createNotificationHistory(event3, endpoint2, TRUE);
    NotificationHistory history5 = resourceHelpers.createNotificationHistory(event3, endpoint3, TRUE);
    endpointRepository.deleteEndpoint(DEFAULT_ACCOUNT_ID, endpoint1.getId());
    endpointRepository.deleteEndpoint(DEFAULT_ACCOUNT_ID, endpoint2.getId());
    endpointRepository.deleteEndpoint(DEFAULT_ACCOUNT_ID, endpoint3.getId());
    /*
         * Test #1
         * Account: DEFAULT_ACCOUNT_ID
         * Request: No filter
         * Expected response: All event log entries from DEFAULT_ACCOUNT_ID should be returned
         */
    Page<EventLogEntry> page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, null, null, null, null, null, false, true);
    assertEquals(3, page.getMeta().getCount());
    assertEquals(3, page.getData().size());
    assertSameEvent(page.getData().get(0), event2, history3);
    assertSameEvent(page.getData().get(1), event3, history4, history5);
    assertSameEvent(page.getData().get(2), event1, history1, history2);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #2
         * Account: OTHER_ACCOUNT_ID
         * Request: No filter
         * Expected response: All event log entries from OTHER_ACCOUNT_ID should be returned
         */
    page = getEventLogPage(otherIdentityHeader, null, null, null, null, null, null, null, null, null, null, false, true);
    assertEquals(1, page.getMeta().getCount());
    assertEquals(1, page.getData().size());
    assertSameEvent(page.getData().get(0), event4);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #3
         * Account: DEFAULT_ACCOUNT_ID
         * Request: Unknown bundle
         */
    page = getEventLogPage(defaultIdentityHeader, Set.of(randomUUID()), null, null, null, null, null, null, null, null, null, false, true);
    assertEquals(0, page.getMeta().getCount());
    assertTrue(page.getData().isEmpty());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #4
         * Account: DEFAULT_ACCOUNT_ID
         * Request: One existing bundle
         */
    page = getEventLogPage(defaultIdentityHeader, Set.of(bundle1.getId()), null, null, null, null, null, null, null, null, null, false, true);
    assertEquals(1, page.getMeta().getCount());
    assertEquals(1, page.getData().size());
    assertSameEvent(page.getData().get(0), event1, history1, history2);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #5
         * Account: DEFAULT_ACCOUNT_ID
         * Request: Multiple existing bundles, sort by ascending bundle names
         */
    page = getEventLogPage(defaultIdentityHeader, Set.of(bundle1.getId(), bundle2.getId()), null, null, null, null, null, null, null, null, "bundle:asc", false, true);
    assertEquals(3, page.getMeta().getCount());
    assertEquals(3, page.getData().size());
    assertSameEvent(page.getData().get(0), event1, history1, history2);
    assertSameEvent(page.getData().get(1), event2, history3);
    assertSameEvent(page.getData().get(2), event3, history4, history5);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #6
         * Account: DEFAULT_ACCOUNT_ID
         * Request: Unknown application
         */
    page = getEventLogPage(defaultIdentityHeader, null, Set.of(randomUUID()), null, null, null, null, null, null, null, null, false, true);
    assertEquals(0, page.getMeta().getCount());
    assertTrue(page.getData().isEmpty());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #7
         * Account: DEFAULT_ACCOUNT_ID
         * Request: One existing application
         */
    page = getEventLogPage(defaultIdentityHeader, null, Set.of(app2.getId()), null, null, null, null, null, null, null, null, false, true);
    assertEquals(2, page.getMeta().getCount());
    assertEquals(2, page.getData().size());
    assertSameEvent(page.getData().get(0), event2, history3);
    assertSameEvent(page.getData().get(1), event3, history4, history5);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #8
         * Account: DEFAULT_ACCOUNT_ID
         * Request: Multiple existing applications, sort by ascending application names
         */
    page = getEventLogPage(defaultIdentityHeader, null, Set.of(app1.getId(), app2.getId()), null, null, null, null, null, null, null, "application:asc", false, true);
    assertEquals(3, page.getMeta().getCount());
    assertEquals(3, page.getData().size());
    assertSameEvent(page.getData().get(0), event1, history1, history2);
    assertSameEvent(page.getData().get(1), event2, history3);
    assertSameEvent(page.getData().get(2), event3, history4, history5);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #9
         * Account: DEFAULT_ACCOUNT_ID
         * Request: Unknown event type
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, "unknown", null, null, null, null, null, null, null, false, true);
    assertEquals(0, page.getMeta().getCount());
    assertTrue(page.getData().isEmpty());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #10
         * Account: DEFAULT_ACCOUNT_ID
         * Request: Existing event type
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, eventType1.getDisplayName().substring(2).toUpperCase(), null, null, null, null, null, null, null, false, true);
    assertEquals(1, page.getMeta().getCount());
    assertEquals(1, page.getData().size());
    assertSameEvent(page.getData().get(0), event1, history1, history2);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #11
         * Account: DEFAULT_ACCOUNT_ID
         * Request: Start date three days in the past
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, NOW.minusDays(3L), null, null, null, null, null, null, false, true);
    assertEquals(2, page.getMeta().getCount());
    assertEquals(2, page.getData().size());
    assertSameEvent(page.getData().get(0), event2, history3);
    assertSameEvent(page.getData().get(1), event3, history4, history5);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #12
         * Account: DEFAULT_ACCOUNT_ID
         * Request: End date three days in the past
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, NOW.minusDays(3L), null, null, null, null, null, false, true);
    assertEquals(1, page.getMeta().getCount());
    assertEquals(1, page.getData().size());
    assertSameEvent(page.getData().get(0), event1, history1, history2);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #13
         * Account: DEFAULT_ACCOUNT_ID
         * Request: Both start and end date are set
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, NOW.minusDays(3L), NOW.minusDays(1L), null, null, null, null, null, false, true);
    assertEquals(1, page.getMeta().getCount());
    assertEquals(1, page.getData().size());
    assertSameEvent(page.getData().get(0), event3, history4, history5);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #14
         * Account: DEFAULT_ACCOUNT_ID
         * Request: Let's try all request params at once!
         */
    page = getEventLogPage(defaultIdentityHeader, Set.of(bundle2.getId()), Set.of(app2.getId()), eventType2.getDisplayName(), NOW.minusDays(3L), NOW.minusDays(1L), Set.of(EMAIL_SUBSCRIPTION.name()), Set.of(TRUE), 10, 0, "created:desc", true, true);
    assertEquals(1, page.getMeta().getCount());
    assertEquals(1, page.getData().size());
    assertSameEvent(page.getData().get(0), event3, history4, history5);
    assertEquals(PAYLOAD, page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #15
         * Account: DEFAULT_ACCOUNT_ID
         * Request: No filter, limit without offset
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, null, null, 2, null, null, false, true);
    assertEquals(3, page.getMeta().getCount());
    assertEquals(2, page.getData().size());
    assertSameEvent(page.getData().get(0), event2, history3);
    assertSameEvent(page.getData().get(1), event3, history4, history5);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last", "next");
    /*
         * Test #16
         * Account: DEFAULT_ACCOUNT_ID
         * Request: No filter, limit with offset
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, null, null, 1, 2, null, false, true);
    assertEquals(3, page.getMeta().getCount());
    assertEquals(1, page.getData().size());
    assertSameEvent(page.getData().get(0), event1, history1, history2);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last", "prev");
    /*
         * Test #17
         * Account: DEFAULT_ACCOUNT_ID
         * Request: No filter, sort by ascending event names
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, null, null, null, null, "event:asc", false, true);
    assertEquals(3, page.getMeta().getCount());
    assertEquals(3, page.getData().size());
    assertSameEvent(page.getData().get(0), event1, history1, history2);
    assertSameEvent(page.getData().get(1), event2, history3);
    assertSameEvent(page.getData().get(2), event3, history4, history5);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #18
         * Account: DEFAULT_ACCOUNT_ID
         * Request: WEBHOOK endpoints
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, Set.of(WEBHOOK.name()), null, null, null, null, false, true);
    assertEquals(2, page.getMeta().getCount());
    assertEquals(2, page.getData().size());
    assertSameEvent(page.getData().get(0), event2, history3);
    assertSameEvent(page.getData().get(1), event1, history1, history2);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #19
         * Account: DEFAULT_ACCOUNT_ID
         * Request: Invocation succeeded
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, null, Set.of(TRUE), null, null, null, false, true);
    assertEquals(3, page.getMeta().getCount());
    assertEquals(3, page.getData().size());
    assertSameEvent(page.getData().get(0), event2, history3);
    assertSameEvent(page.getData().get(1), event3, history4, history5);
    assertSameEvent(page.getData().get(2), event1, history1, history2);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #20
         * Account: DEFAULT_ACCOUNT_ID
         * Request: EMAIL_SUBSCRIPTION endpoints and invocation failed
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, Set.of(EMAIL_SUBSCRIPTION.name()), Set.of(FALSE), null, null, null, false, true);
    assertEquals(1, page.getMeta().getCount());
    assertEquals(1, page.getData().size());
    assertSameEvent(page.getData().get(0), event1, history1, history2);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #21
         * Account: DEFAULT_ACCOUNT_ID
         * Request: No filter
         * Expected response: All event log entries from DEFAULT_ACCOUNT_ID should be returned without actions
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, null, null, null, null, null, false, false);
    assertEquals(3, page.getMeta().getCount());
    assertEquals(3, page.getData().size());
    assertSameEvent(page.getData().get(0), event2);
    assertSameEvent(page.getData().get(1), event3);
    assertSameEvent(page.getData().get(2), event1);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #22
         * Account: DEFAULT_ACCOUNT_ID
         * Request: CAMEL endpoints
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, Set.of(CAMEL.name()), null, null, null, null, false, true);
    assertEquals(1, page.getMeta().getCount());
    assertEquals(1, page.getData().size());
    assertSameEvent(page.getData().get(0), event3, history4, history5);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #23
         * Account: DEFAULT_ACCOUNT_ID
         * Request: CAMEL:SPLUNK endpoints
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, Set.of("camel:splunk"), null, null, null, null, false, true);
    assertEquals(0, page.getMeta().getCount());
    assertEquals(0, page.getData().size());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #24
         * Account: DEFAULT_ACCOUNT_ID
         * Request: CAMEL:SLACK endpoints
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, Set.of("camel:slack"), null, null, null, null, false, true);
    assertEquals(1, page.getMeta().getCount());
    assertEquals(1, page.getData().size());
    assertSameEvent(page.getData().get(0), event3, history4, history5);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #25
         * Account: DEFAULT_ACCOUNT_ID
         * Request: CAMEL:SLACK and EMAIL endpoints
         */
    page = getEventLogPage(defaultIdentityHeader, null, null, null, null, null, Set.of("camel:SLACK", EMAIL_SUBSCRIPTION.name()), null, null, null, null, false, true);
    assertEquals(2, page.getMeta().getCount());
    assertEquals(2, page.getData().size());
    assertSameEvent(page.getData().get(0), event3, history4, history5);
    assertSameEvent(page.getData().get(1), event1, history1, history2);
    assertNull(page.getData().get(0).getPayload());
    assertLinks(page.getLinks(), "first", "last");
    /*
         * Test #26
         * Account: DEFAULT_ACCOUNT_ID
         * Request: Mixing bundle and an app from a different bundle
         */
    page = getEventLogPage(defaultIdentityHeader, Set.of(bundle1.getId()), Set.of(app2.getId()), null, null, null, null, null, 10, 0, null, true, true);
    assertEquals(3, page.getMeta().getCount());
    assertEquals(3, page.getData().size());
    assertSameEvent(page.getData().get(0), event2, history3);
    assertSameEvent(page.getData().get(1), event3, history4, history5);
    assertSameEvent(page.getData().get(2), event1, history1, history2);
    assertLinks(page.getLinks(), "first", "last");
}
Also used : Header(io.restassured.http.Header) Endpoint(com.redhat.cloud.notifications.models.Endpoint) EventType(com.redhat.cloud.notifications.models.EventType) NotificationHistory(com.redhat.cloud.notifications.models.NotificationHistory) Bundle(com.redhat.cloud.notifications.models.Bundle) EventLogEntry(com.redhat.cloud.notifications.routers.models.EventLogEntry) Event(com.redhat.cloud.notifications.models.Event) Application(com.redhat.cloud.notifications.models.Application) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest)

Aggregations

Event (com.redhat.cloud.notifications.models.Event)3 EventLogEntry (com.redhat.cloud.notifications.routers.models.EventLogEntry)3 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)2 Application (com.redhat.cloud.notifications.models.Application)2 Bundle (com.redhat.cloud.notifications.models.Bundle)2 Endpoint (com.redhat.cloud.notifications.models.Endpoint)2 EventType (com.redhat.cloud.notifications.models.EventType)2 NotificationHistory (com.redhat.cloud.notifications.models.NotificationHistory)2 PATH (com.redhat.cloud.notifications.routers.EventResource.PATH)2 EventLogEntryAction (com.redhat.cloud.notifications.routers.models.EventLogEntryAction)2 Page (com.redhat.cloud.notifications.routers.models.Page)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 Header (io.restassured.http.Header)2 Map (java.util.Map)2 API_NOTIFICATIONS_V_1_0 (com.redhat.cloud.notifications.Constants.API_NOTIFICATIONS_V_1_0)1 MockServerConfig (com.redhat.cloud.notifications.MockServerConfig)1 RbacAccess (com.redhat.cloud.notifications.MockServerConfig.RbacAccess)1 FULL_ACCESS (com.redhat.cloud.notifications.MockServerConfig.RbacAccess.FULL_ACCESS)1 NOTIFICATIONS_ACCESS_ONLY (com.redhat.cloud.notifications.MockServerConfig.RbacAccess.NOTIFICATIONS_ACCESS_ONLY)1 NOTIFICATIONS_READ_ACCESS_ONLY (com.redhat.cloud.notifications.MockServerConfig.RbacAccess.NOTIFICATIONS_READ_ACCESS_ONLY)1