use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class LifecycleITest method addBehaviorGroupAction.
@Transactional
void addBehaviorGroupAction(UUID behaviorGroupId, UUID endpointId) {
BehaviorGroup behaviorGroup = entityManager.find(BehaviorGroup.class, behaviorGroupId);
Endpoint endpoint = entityManager.find(Endpoint.class, endpointId);
BehaviorGroupAction action = new BehaviorGroupAction();
action.setId(new BehaviorGroupActionId());
action.setBehaviorGroup(behaviorGroup);
action.setEndpoint(endpoint);
entityManager.persist(action);
}
use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class LifecycleITest method createBehaviorGroup.
@Transactional
BehaviorGroup createBehaviorGroup(String accountId, Bundle bundle) {
BehaviorGroup behaviorGroup = new BehaviorGroup();
behaviorGroup.setAccountId(accountId);
behaviorGroup.setDisplayName("Behavior group");
behaviorGroup.setBundle(bundle);
behaviorGroup.setBundleId(bundle.getId());
entityManager.persist(behaviorGroup);
return behaviorGroup;
}
use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepositoryTest method updateBehaviorGroup.
private Boolean updateBehaviorGroup(UUID behaviorGroupId, String displayName) {
BehaviorGroup behaviorGroup = new BehaviorGroup();
behaviorGroup.setId(behaviorGroupId);
behaviorGroup.setDisplayName(displayName);
// This should not have any effect, the bundle is not updatable.
behaviorGroup.setBundleId(UUID.randomUUID());
return resourceHelpers.updateBehaviorGroup(behaviorGroup);
}
use of com.redhat.cloud.notifications.models.BehaviorGroup 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.BehaviorGroup 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());
}
Aggregations