Search in sources :

Example 6 with Bundle

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

the class BehaviorGroupRepositoryTest method testCreateAndUpdateAndDeleteBehaviorGroup.

@Test
void testCreateAndUpdateAndDeleteBehaviorGroup() {
    String newDisplayName = "newDisplayName";
    Bundle bundle = resourceHelpers.createBundle();
    // Create behavior group.
    BehaviorGroup behaviorGroup = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "displayName", bundle.getId());
    List<BehaviorGroup> behaviorGroups = behaviorGroupRepository.findByBundleId(DEFAULT_ACCOUNT_ID, bundle.getId());
    assertEquals(1, behaviorGroups.size());
    assertEquals(behaviorGroup, behaviorGroups.get(0));
    assertEquals(behaviorGroup.getDisplayName(), behaviorGroups.get(0).getDisplayName());
    assertEquals(bundle.getId(), behaviorGroups.get(0).getBundle().getId());
    assertNotNull(bundle.getCreated());
    // Update behavior group.
    assertTrue(updateBehaviorGroup(behaviorGroup.getId(), newDisplayName));
    // We need to clear the session L1 cache before checking the update result.
    entityManager.clear();
    behaviorGroups = behaviorGroupRepository.findByBundleId(DEFAULT_ACCOUNT_ID, bundle.getId());
    assertEquals(1, behaviorGroups.size());
    assertEquals(behaviorGroup.getId(), behaviorGroups.get(0).getId());
    assertEquals(newDisplayName, behaviorGroups.get(0).getDisplayName());
    assertEquals(bundle.getId(), behaviorGroups.get(0).getBundle().getId());
    // Delete behavior group.
    assertTrue(resourceHelpers.deleteBehaviorGroup(behaviorGroup.getId()));
    behaviorGroups = behaviorGroupRepository.findByBundleId(DEFAULT_ACCOUNT_ID, bundle.getId());
    assertTrue(behaviorGroups.isEmpty());
}
Also used : Bundle(com.redhat.cloud.notifications.models.Bundle) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) QuarkusTest(io.quarkus.test.junit.QuarkusTest) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest) Test(org.junit.jupiter.api.Test)

Example 7 with Bundle

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

the class BehaviorGroupRepositoryTest method testAddAndDeleteBehaviorGroupAction.

@Test
void testAddAndDeleteBehaviorGroupAction() {
    Bundle bundle = resourceHelpers.createBundle();
    BehaviorGroup behaviorGroup1 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 1", bundle.getId());
    BehaviorGroup behaviorGroup2 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 2", bundle.getId());
    Endpoint endpoint1 = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, WEBHOOK);
    Endpoint endpoint2 = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, WEBHOOK);
    Endpoint endpoint3 = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, WEBHOOK);
    // At the beginning of the test, endpoint1 shouldn't be linked with any behavior group.
    findBehaviorGroupsByEndpointId(endpoint1.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK, endpoint1.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK, endpoint1.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK, endpoint1.getId(), endpoint2.getId());
    // Now, endpoint1 should be linked with behaviorGroup1.
    findBehaviorGroupsByEndpointId(endpoint1.getId(), behaviorGroup1.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup2.getId(), OK, endpoint1.getId());
    // Then, endpoint1 should be linked with both behavior groups.
    findBehaviorGroupsByEndpointId(endpoint1.getId(), behaviorGroup1.getId(), behaviorGroup2.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK, endpoint2.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK, endpoint3.getId(), endpoint2.getId(), endpoint1.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK);
    // The link between endpoint1 and behaviorGroup1 was removed. Let's check it is still linked with behaviorGroup2.
    findBehaviorGroupsByEndpointId(endpoint1.getId(), behaviorGroup2.getId());
}
Also used : Endpoint(com.redhat.cloud.notifications.models.Endpoint) Bundle(com.redhat.cloud.notifications.models.Bundle) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) QuarkusTest(io.quarkus.test.junit.QuarkusTest) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest) Test(org.junit.jupiter.api.Test)

Example 8 with Bundle

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

the class BehaviorGroupRepositoryTest method testAddMultipleEmailSubscriptionBehaviorGroupActions.

@Test
void testAddMultipleEmailSubscriptionBehaviorGroupActions() {
    Bundle bundle = resourceHelpers.createBundle();
    BehaviorGroup behaviorGroup = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "displayName", bundle.getId());
    Endpoint endpoint1 = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, EMAIL_SUBSCRIPTION);
    Endpoint endpoint2 = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, EMAIL_SUBSCRIPTION);
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup.getId(), OK, endpoint1.getId(), endpoint2.getId());
}
Also used : Endpoint(com.redhat.cloud.notifications.models.Endpoint) Bundle(com.redhat.cloud.notifications.models.Bundle) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) QuarkusTest(io.quarkus.test.junit.QuarkusTest) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest) Test(org.junit.jupiter.api.Test)

Example 9 with Bundle

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

the class BehaviorGroupRepositoryTest method testFindBehaviorGroupsByEventTypeId.

@Test
void testFindBehaviorGroupsByEventTypeId() {
    Bundle bundle = resourceHelpers.createBundle();
    Application app = resourceHelpers.createApplication(bundle.getId());
    EventType eventType = createEventType(app);
    BehaviorGroup behaviorGroup = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "displayName", bundle.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup.getId());
    List<BehaviorGroup> behaviorGroups = resourceHelpers.findBehaviorGroupsByEventTypeId(eventType.getId());
    assertEquals(1, behaviorGroups.size());
    assertEquals(behaviorGroup.getId(), behaviorGroups.get(0).getId());
}
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 10 with Bundle

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

the class BehaviorGroupRepositoryTest method testFindEventTypesByBehaviorGroupId.

@Test
void testFindEventTypesByBehaviorGroupId() {
    Bundle bundle = resourceHelpers.createBundle();
    Application app = resourceHelpers.createApplication(bundle.getId());
    EventType eventType = createEventType(app);
    BehaviorGroup behaviorGroup = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "displayName", bundle.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup.getId());
    List<EventType> eventTypes = resourceHelpers.findEventTypesByBehaviorGroupId(behaviorGroup.getId());
    assertEquals(1, eventTypes.size());
    assertEquals(eventType.getId(), eventTypes.get(0).getId());
}
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)

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