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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations