use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class EmailTemplateMigrationServiceTest method testMigration.
@Test
void testMigration() {
/*
* Bundle: rhel
*/
Bundle rhel = findBundle("rhel");
// App: advisor
Application advisor = resourceHelpers.createApp(rhel.getId(), "advisor");
EventType newRecommendation = resourceHelpers.createEventType(advisor.getId(), "new-recommendation");
EventType resolvedRecommendation = resourceHelpers.createEventType(advisor.getId(), "resolved-recommendation");
EventType deactivatedRecommendation = resourceHelpers.createEventType(advisor.getId(), "deactivated-recommendation");
// App: compliance
Application compliance = resourceHelpers.createApp(rhel.getId(), "compliance");
EventType complianceBelowThreshold = resourceHelpers.createEventType(compliance.getId(), "compliance-below-threshold");
EventType reportUploadFailed = resourceHelpers.createEventType(compliance.getId(), "report-upload-failed");
// App: drift
Application drift = resourceHelpers.createApp(rhel.getId(), "drift");
EventType driftBaselineDetected = resourceHelpers.createEventType(drift.getId(), "drift-baseline-detected");
// App: edge-management
Application edgeManagement = resourceHelpers.createApp(rhel.getId(), "edge-management");
EventType imageCreation = resourceHelpers.createEventType(edgeManagement.getId(), "image-creation");
EventType updateDevices = resourceHelpers.createEventType(edgeManagement.getId(), "update-devices");
// App: patch
Application patch = resourceHelpers.createApp(rhel.getId(), "patch");
EventType newAdvisories = resourceHelpers.createEventType(patch.getId(), "new-advisory");
// App: policies
Application policies = findApp("rhel", "policies");
EventType policyTriggered = findEventType("rhel", "policies", "policy-triggered");
// App: vulnerability
Application vulnerability = resourceHelpers.createApp(rhel.getId(), "vulnerability");
EventType newCveCvss = resourceHelpers.createEventType(vulnerability.getId(), "new-cve-cvss");
EventType newCveSeverity = resourceHelpers.createEventType(vulnerability.getId(), "new-cve-severity");
EventType newCveSecurityRule = resourceHelpers.createEventType(vulnerability.getId(), "new-cve-security-rule");
EventType anyCveKnownExploit = resourceHelpers.createEventType(vulnerability.getId(), "any-cve-known-exploit");
/*
* Bundle: openshift
*/
Bundle openshift = resourceHelpers.createBundle("openshift");
// App: advisor
Application advisorOpenshift = resourceHelpers.createApp(openshift.getId(), "advisor");
EventType newRecommendationOpenshift = resourceHelpers.createEventType(advisorOpenshift.getId(), "new-recommendation");
/*
* Bundle: application-services
*/
Bundle applicationServices = resourceHelpers.createBundle("application-services");
// App: rhosak
Application rhosak = resourceHelpers.createApp(applicationServices.getId(), "rhosak");
EventType scheduledUpgrade = resourceHelpers.createEventType(rhosak.getId(), "scheduled-upgrade");
EventType disruption = resourceHelpers.createEventType(rhosak.getId(), "disruption");
EventType instanceCreated = resourceHelpers.createEventType(rhosak.getId(), "instance-created");
EventType instanceDeleted = resourceHelpers.createEventType(rhosak.getId(), "instance-deleted");
EventType actionRequired = resourceHelpers.createEventType(rhosak.getId(), "action-required");
/*
* Bundle: ansible
*/
Bundle ansible = resourceHelpers.createBundle("ansible");
// App: reports
Application reports = resourceHelpers.createApp(ansible.getId(), "reports");
EventType reportAvailable = resourceHelpers.createEventType(reports.getId(), "report-available");
/*
* Bundle: console
*/
Bundle console = findBundle("console");
// App: notifications
Application notifications = findApp("console", "notifications");
EventType failedIntegration = resourceHelpers.createEventType(notifications.getId(), "failed-integration");
// App: sources
Application sources = resourceHelpers.createApp(console.getId(), "sources");
EventType availabilityStatus = resourceHelpers.createEventType(sources.getId(), "availability-status");
// App: rbac
Application rbac = resourceHelpers.createApp(console.getId(), "rbac");
EventType rhNewRoleAvailable = resourceHelpers.createEventType(rbac.getId(), "rh-new-role-available");
EventType rhPlatformDefaultRoleUpdated = resourceHelpers.createEventType(rbac.getId(), "rh-platform-default-role-updated");
EventType rhNonPlatformDefaultRoleUpdated = resourceHelpers.createEventType(rbac.getId(), "rh-non-platform-default-role-updated");
EventType customRoleCreated = resourceHelpers.createEventType(rbac.getId(), "custom-role-created");
EventType customRoleUpdated = resourceHelpers.createEventType(rbac.getId(), "custom-role-updated");
EventType customRoleDeleted = resourceHelpers.createEventType(rbac.getId(), "custom-role-deleted");
EventType rhNewRoleAddedToDefaultAccess = resourceHelpers.createEventType(rbac.getId(), "rh-new-role-added-to-default-access");
EventType rhRoleRemovedFromDefaultAccess = resourceHelpers.createEventType(rbac.getId(), "rh-role-removed-from-default-access");
EventType customDefaultAccessUpdated = resourceHelpers.createEventType(rbac.getId(), "custom-default-access-updated");
EventType groupCreated = resourceHelpers.createEventType(rbac.getId(), "group-created");
EventType groupUpdated = resourceHelpers.createEventType(rbac.getId(), "group-updated");
EventType groupDeleted = resourceHelpers.createEventType(rbac.getId(), "group-deleted");
EventType platformDefaultGroupTurnedIntoCustom = resourceHelpers.createEventType(rbac.getId(), "platform-default-group-turned-into-custom");
clearDbTemplates();
given().basePath(API_INTERNAL).when().put("/template-engine/migrate").then().statusCode(200).contentType(JSON);
statelessSessionFactory.withSession(statelessSession -> {
/*
* Bundle: rhel
*/
// App: advisor
findAndCompileInstantEmailTemplate(newRecommendation.getId());
findAndCompileInstantEmailTemplate(resolvedRecommendation.getId());
findAndCompileInstantEmailTemplate(deactivatedRecommendation.getId());
assertTrue(templateRepository.findAggregationEmailTemplate(rhel.getName(), advisor.getName(), DAILY).isEmpty());
// App: compliance
findAndCompileInstantEmailTemplate(complianceBelowThreshold.getId());
findAndCompileInstantEmailTemplate(reportUploadFailed.getId());
findAndCompileAggregationEmailTemplate(rhel.getName(), compliance.getName(), DAILY);
// App: drift
findAndCompileInstantEmailTemplate(driftBaselineDetected.getId());
findAndCompileAggregationEmailTemplate(rhel.getName(), drift.getName(), DAILY);
// App: edge-management
findAndCompileInstantEmailTemplate(imageCreation.getId());
findAndCompileInstantEmailTemplate(updateDevices.getId());
// App: patch
findAndCompileInstantEmailTemplate(newAdvisories.getId());
findAndCompileAggregationEmailTemplate(rhel.getName(), patch.getName(), DAILY);
// App: policies
findAndCompileInstantEmailTemplate(policyTriggered.getId());
findAndCompileAggregationEmailTemplate(rhel.getName(), policies.getName(), DAILY);
// App: vulnerability
findAndCompileInstantEmailTemplate(newCveCvss.getId());
findAndCompileInstantEmailTemplate(newCveSecurityRule.getId());
findAndCompileInstantEmailTemplate(newCveSeverity.getId());
findAndCompileInstantEmailTemplate(anyCveKnownExploit.getId());
findAndCompileAggregationEmailTemplate(rhel.getName(), vulnerability.getName(), DAILY);
/*
* Bundle: openshift
*/
// App: advisor
findAndCompileInstantEmailTemplate(newRecommendationOpenshift.getId());
assertTrue(templateRepository.findAggregationEmailTemplate(openshift.getName(), advisorOpenshift.getName(), DAILY).isEmpty());
/*
* Bundle: application-services
*/
// App: rhosak
findAndCompileInstantEmailTemplate(scheduledUpgrade.getId());
findAndCompileInstantEmailTemplate(disruption.getId());
findAndCompileInstantEmailTemplate(instanceCreated.getId());
findAndCompileInstantEmailTemplate(instanceDeleted.getId());
findAndCompileInstantEmailTemplate(actionRequired.getId());
findAndCompileAggregationEmailTemplate(applicationServices.getName(), rhosak.getName(), DAILY);
/*
* Bundle: ansible
*/
// App: reports
findAndCompileInstantEmailTemplate(reportAvailable.getId());
assertTrue(templateRepository.findAggregationEmailTemplate(ansible.getName(), reports.getName(), DAILY).isEmpty());
/*
* Bundle: console
*/
// App: notifications
findAndCompileInstantEmailTemplate(failedIntegration.getId());
assertTrue(templateRepository.findAggregationEmailTemplate(console.getName(), notifications.getName(), DAILY).isEmpty());
// App: sources
findAndCompileInstantEmailTemplate(availabilityStatus.getId());
assertTrue(templateRepository.findAggregationEmailTemplate(console.getName(), sources.getName(), DAILY).isEmpty());
// App: rbac
findAndCompileInstantEmailTemplate(rhNewRoleAvailable.getId());
findAndCompileInstantEmailTemplate(rhPlatformDefaultRoleUpdated.getId());
findAndCompileInstantEmailTemplate(rhNonPlatformDefaultRoleUpdated.getId());
findAndCompileInstantEmailTemplate(customRoleCreated.getId());
findAndCompileInstantEmailTemplate(customRoleUpdated.getId());
findAndCompileInstantEmailTemplate(customRoleDeleted.getId());
findAndCompileInstantEmailTemplate(rhNewRoleAddedToDefaultAccess.getId());
findAndCompileInstantEmailTemplate(rhRoleRemovedFromDefaultAccess.getId());
findAndCompileInstantEmailTemplate(customDefaultAccessUpdated.getId());
findAndCompileInstantEmailTemplate(groupCreated.getId());
findAndCompileInstantEmailTemplate(groupUpdated.getId());
findAndCompileInstantEmailTemplate(groupDeleted.getId());
findAndCompileInstantEmailTemplate(platformDefaultGroupTurnedIntoCustom.getId());
assertTrue(templateRepository.findAggregationEmailTemplate(console.getName(), rbac.getName(), DAILY).isEmpty());
});
clearDbTemplates();
}
use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class EventLogCleanerTest method createEventType.
private EventType createEventType() {
Bundle bundle = new Bundle();
bundle.setName("bundle");
bundle.setDisplayName("Bundle");
bundle.prePersist();
entityManager.persist(bundle);
Application app = new Application();
app.setBundle(bundle);
app.setBundleId(bundle.getId());
app.setName("app");
app.setDisplayName("Application");
app.prePersist();
entityManager.persist(app);
EventType eventType = new EventType();
eventType.setApplication(app);
eventType.setApplicationId(app.getId());
eventType.setName("event-type");
eventType.setDisplayName("Event type");
entityManager.persist(eventType);
return eventType;
}
use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class EmailTemplateMigrationService method createDailyEmailTemplate.
/*
* Creates an aggregation email template and the underlying templates only if:
* - the application exists in the DB
* - the aggregation email template does not already exist in the DB
* Existing aggregation email templates are never updated by this migration service.
*/
private void createDailyEmailTemplate(List<String> warnings, String bundleName, String appName, String subjectTemplateName, String subjectTemplateExtension, String subjectTemplateDescription, String bodyTemplateName, String bodyTemplateExtension, String bodyTemplateDescription) {
Optional<Application> app = findApplication(warnings, bundleName, appName);
if (app.isPresent()) {
if (aggregationEmailTemplateExists(app.get())) {
warnings.add(String.format("Aggregation email template found in DB for application: %s/%s", bundleName, appName));
} else {
Template subjectTemplate = getOrCreateTemplate(warnings, subjectTemplateName, subjectTemplateExtension, subjectTemplateDescription);
Template bodyTemplate = getOrCreateTemplate(warnings, bodyTemplateName, bodyTemplateExtension, bodyTemplateDescription);
LOGGER.infof("Creating daily email template for application: %s/%s", bundleName, appName);
AggregationEmailTemplate emailTemplate = new AggregationEmailTemplate();
emailTemplate.setApplication(app.get());
emailTemplate.setSubscriptionType(DAILY);
emailTemplate.setSubjectTemplate(subjectTemplate);
emailTemplate.setSubjectTemplateId(subjectTemplate.getId());
emailTemplate.setBodyTemplate(bodyTemplate);
emailTemplate.setBodyTemplateId(bodyTemplate.getId());
entityManager.persist(emailTemplate);
}
}
}
use of com.redhat.cloud.notifications.models.Application 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");
}
use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class NotificationResourceTest method testEventTypeFetchingByBundle.
@Test
void testEventTypeFetchingByBundle() {
helpers.createTestAppAndEventTypes();
List<Application> apps = applicationRepository.getApplications(TEST_BUNDLE_NAME);
UUID myBundleId = apps.stream().filter(a -> a.getName().equals(TEST_APP_NAME_2)).findFirst().get().getBundleId();
Header identityHeader = initRbacMock(TENANT, ORG_ID, USERNAME, RbacAccess.FULL_ACCESS);
Response response = given().when().header(identityHeader).queryParam("bundleId", myBundleId).get("/notifications/eventTypes").then().statusCode(200).contentType(JSON).extract().response();
JsonObject page = new JsonObject(response.getBody().asString());
JsonArray eventTypes = page.getJsonArray("data");
for (int i = 0; i < eventTypes.size(); i++) {
JsonObject ev = eventTypes.getJsonObject(i);
ev.mapTo(EventType.class);
assertEquals(myBundleId.toString(), ev.getJsonObject("application").getString("bundle_id"));
}
assertEquals(200, page.getJsonObject("meta").getInteger("count"));
assertEquals(20, eventTypes.size());
}
Aggregations