Search in sources :

Example 16 with Bundle

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

the class CrudTestHelpers method updateBundle.

public static void updateBundle(Header identity, String bundleId, String name, String displayName, int expectedStatusCode) {
    Bundle bundle = buildBundle(name, displayName);
    updateBundle(identity, bundleId, bundle, expectedStatusCode);
}
Also used : Bundle(com.redhat.cloud.notifications.models.Bundle)

Example 17 with Bundle

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

the class DbCleaner method clean.

/**
 * Deletes all records from all database tables (except for flyway_schema_history) and restores the default records.
 * This method should be called from a method annotated with <b>both</b> {@link BeforeEach} and {@link AfterEach} in
 * all test classes that involve SQL queries to guarantee the tests isolation in terms of stored data.
 */
@Transactional
public void clean() {
    for (Class<?> entity : ENTITIES) {
        entityManager.createQuery("DELETE FROM " + entity.getSimpleName()).executeUpdate();
    }
    Bundle bundle = new Bundle(DEFAULT_BUNDLE_NAME, DEFAULT_BUNDLE_DISPLAY_NAME);
    bundleRepository.createBundle(bundle);
    Application app = new Application();
    app.setBundleId(bundle.getId());
    app.setName(DEFAULT_APP_NAME);
    app.setDisplayName(DEFAULT_APP_DISPLAY_NAME);
    applicationRepository.createApp(app);
    EventType eventType = new EventType();
    eventType.setApplicationId(app.getId());
    eventType.setName(DEFAULT_EVENT_TYPE_NAME);
    eventType.setDisplayName(DEFAULT_EVENT_TYPE_DISPLAY_NAME);
    eventType.setDescription(DEFAULT_EVENT_TYPE_DESCRIPTION);
    applicationRepository.createEventType(eventType);
    entityManager.createQuery("UPDATE CurrentStatus SET status = :status").setParameter("status", Status.UP).executeUpdate();
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) Bundle(com.redhat.cloud.notifications.models.Bundle) Application(com.redhat.cloud.notifications.models.Application) Transactional(javax.transaction.Transactional)

Example 18 with Bundle

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

the class BehaviorGroupRepositoryTest method testAddAndDeleteEventTypeBehavior.

@Test
void testAddAndDeleteEventTypeBehavior() {
    Bundle bundle = resourceHelpers.createBundle();
    Application app = resourceHelpers.createApplication(bundle.getId());
    EventType eventType = createEventType(app);
    BehaviorGroup behaviorGroup1 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 1", bundle.getId());
    BehaviorGroup behaviorGroup2 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 2", bundle.getId());
    BehaviorGroup behaviorGroup3 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 3", bundle.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId(), behaviorGroup2.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup2.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId(), behaviorGroup2.getId(), behaviorGroup3.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true);
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) Bundle(com.redhat.cloud.notifications.models.Bundle) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) Application(com.redhat.cloud.notifications.models.Application) QuarkusTest(io.quarkus.test.junit.QuarkusTest) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest) Test(org.junit.jupiter.api.Test)

Example 19 with Bundle

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

the class BehaviorGroupRepositoryTest method createBehaviorGroupWithIllegalDisplayName.

private void createBehaviorGroupWithIllegalDisplayName(String displayName) {
    Bundle bundle = resourceHelpers.createBundle();
    ConstraintViolationException e = assertThrows(ConstraintViolationException.class, () -> {
        resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, displayName, bundle.getId());
    });
    assertTrue(Pattern.compile("property path: [a-zA-Z0-9.]+displayName").matcher(e.getMessage()).find());
}
Also used : Bundle(com.redhat.cloud.notifications.models.Bundle) ConstraintViolationException(javax.validation.ConstraintViolationException)

Example 20 with Bundle

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

the class UserConfigResource method getSettingsValueForUser.

/**
 * Pulls the user settings values of an user across all the know applications of a bundle
 */
private SettingsValues getSettingsValueForUser(String account, String username, String bundleName) {
    if (bundleName == null || bundleName.equals("")) {
        throw new BadRequestException("bundleName must have a value");
    }
    SettingsValues settingsValues = new SettingsValues();
    Bundle bundle = bundleRepository.getBundle(bundleName);
    if (bundle == null) {
        throw new BadRequestException("Unknown bundleName: " + bundleName);
    } else {
        BundleSettingsValue bundleSettingsValue = new BundleSettingsValue();
        bundleSettingsValue.displayName = bundle.getDisplayName();
        settingsValues.bundles.put(bundle.getName(), bundleSettingsValue);
        for (Application application : applicationRepository.getApplications(bundle.getName())) {
            ApplicationSettingsValue applicationSettingsValue = new ApplicationSettingsValue();
            applicationSettingsValue.displayName = application.getDisplayName();
            settingsValues.bundles.get(bundle.getName()).applications.put(application.getName(), applicationSettingsValue);
            for (EmailSubscriptionType emailSubscriptionType : EmailSubscriptionType.values()) {
                // TODO NOTIF-450 How do we deal with a failure here? What kind of response should be sent to the UI when the engine is down?
                boolean supported = templateEngineClient.isSubscriptionTypeSupported(bundle.getName(), application.getName(), emailSubscriptionType);
                if (supported) {
                    settingsValues.bundles.get(bundle.getName()).applications.get(application.getName()).notifications.put(emailSubscriptionType, false);
                }
            }
        }
        List<EmailSubscription> emailSubscriptions = emailSubscriptionRepository.getEmailSubscriptionsForUser(account, username);
        for (EmailSubscription emailSubscription : emailSubscriptions) {
            if (settingsValues.bundles.containsKey(emailSubscription.getApplication().getBundle().getName())) {
                BundleSettingsValue bundleSettings = settingsValues.bundles.get(emailSubscription.getApplication().getBundle().getName());
                if (bundleSettings.applications.containsKey(emailSubscription.getApplication().getName())) {
                    ApplicationSettingsValue applicationSettingsValue = bundleSettings.applications.get(emailSubscription.getApplication().getName());
                    if (applicationSettingsValue.notifications.containsKey(emailSubscription.getType())) {
                        bundleSettings.applications.get(emailSubscription.getApplication().getName()).notifications.put(emailSubscription.getType(), true);
                    }
                }
            }
        }
        return settingsValues;
    }
}
Also used : ApplicationSettingsValue(com.redhat.cloud.notifications.routers.models.SettingsValues.ApplicationSettingsValue) SettingsValues(com.redhat.cloud.notifications.routers.models.SettingsValues) BundleSettingsValue(com.redhat.cloud.notifications.routers.models.SettingsValues.BundleSettingsValue) EmailSubscriptionType(com.redhat.cloud.notifications.models.EmailSubscriptionType) Bundle(com.redhat.cloud.notifications.models.Bundle) BadRequestException(javax.ws.rs.BadRequestException) Application(com.redhat.cloud.notifications.models.Application) EmailSubscription(com.redhat.cloud.notifications.models.EmailSubscription)

Aggregations

Bundle (com.redhat.cloud.notifications.models.Bundle)28 Application (com.redhat.cloud.notifications.models.Application)13 QuarkusTest (io.quarkus.test.junit.QuarkusTest)13 Test (org.junit.jupiter.api.Test)13 BehaviorGroup (com.redhat.cloud.notifications.models.BehaviorGroup)12 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)11 EventType (com.redhat.cloud.notifications.models.EventType)11 Endpoint (com.redhat.cloud.notifications.models.Endpoint)6 Transactional (javax.transaction.Transactional)5 NotFoundException (javax.ws.rs.NotFoundException)4 BadRequestException (javax.ws.rs.BadRequestException)3 Event (com.redhat.cloud.notifications.models.Event)2 EmailSubscription (com.redhat.cloud.notifications.models.EmailSubscription)1 EmailSubscriptionType (com.redhat.cloud.notifications.models.EmailSubscriptionType)1 NotificationHistory (com.redhat.cloud.notifications.models.NotificationHistory)1 EventLogEntry (com.redhat.cloud.notifications.routers.models.EventLogEntry)1 SettingsValues (com.redhat.cloud.notifications.routers.models.SettingsValues)1 ApplicationSettingsValue (com.redhat.cloud.notifications.routers.models.SettingsValues.ApplicationSettingsValue)1 BundleSettingsValue (com.redhat.cloud.notifications.routers.models.SettingsValues.BundleSettingsValue)1 Header (io.restassured.http.Header)1