use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepositoryTest method updateDefaultBehaviorGroup.
private Boolean updateDefaultBehaviorGroup(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.updateDefaultBehaviorGroup(behaviorGroup);
}
use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepositoryTest method testAddEventTypeBehaviorWithBundleIntegrityCheckFailure.
@Test
void testAddEventTypeBehaviorWithBundleIntegrityCheckFailure() {
/*
* Bundle 1 objects hierarchy.
*/
Bundle bundle1 = resourceHelpers.createBundle("bundle-1", "Bundle 1");
Application app = resourceHelpers.createApplication(bundle1.getId());
// 'eventType' is a child of 'bundle1'.
EventType eventType = createEventType(app);
// 'behaviorGroup1' is a child of 'bundle1'.
BehaviorGroup behaviorGroup1 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 1", bundle1.getId());
/*
* Bundle 2 objects hierarchy.
*/
Bundle bundle2 = resourceHelpers.createBundle("bundle-2", "Bundle 2");
// 'behaviorGroup2' is a child of 'bundle2'.
BehaviorGroup behaviorGroup2 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 2", bundle2.getId());
// 'behaviorGroup2' should not be added to 'eventType' behaviors because it comes from a different bundle.
BadRequestException e = assertThrows(BadRequestException.class, () -> {
behaviorGroupRepository.updateEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), Set.of(behaviorGroup1.getId(), behaviorGroup2.getId()));
});
assertTrue(e.getMessage().startsWith("Some behavior groups can't be linked"));
}
use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepositoryTest method testCreateAndUpdateAndDeleteDefaultBehaviorGroup.
@Test
void testCreateAndUpdateAndDeleteDefaultBehaviorGroup() {
String newDisplayName = "newDisplayName";
Bundle bundle = resourceHelpers.createBundle();
// Create behavior group.
BehaviorGroup behaviorGroup = resourceHelpers.createDefaultBehaviorGroup("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(updateDefaultBehaviorGroup(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.deleteDefaultBehaviorGroup(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 testfindByBundleIdOrdering.
@Test
void testfindByBundleIdOrdering() {
Bundle bundle = resourceHelpers.createBundle();
BehaviorGroup behaviorGroup1 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "displayName", bundle.getId());
BehaviorGroup behaviorGroup2 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "displayName", bundle.getId());
BehaviorGroup behaviorGroup3 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "displayName", bundle.getId());
List<BehaviorGroup> behaviorGroups = behaviorGroupRepository.findByBundleId(DEFAULT_ACCOUNT_ID, bundle.getId());
assertEquals(3, behaviorGroups.size());
// Behavior groups should be sorted on descending creation date.
assertEquals(behaviorGroup3, behaviorGroups.get(0));
assertEquals(behaviorGroup2, behaviorGroups.get(1));
assertEquals(behaviorGroup1, behaviorGroups.get(2));
}
use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class LifecycleITest method createBehaviorGroupInternal.
private String createBehaviorGroupInternal(String path, Header identityHeader, String bundleId) {
BehaviorGroup behaviorGroup = new BehaviorGroup();
behaviorGroup.setDisplayName("Behavior group");
behaviorGroup.setBundleId(UUID.fromString(bundleId));
var request = given();
if (identityHeader != null) {
request.header(identityHeader);
}
String responseBody = request.contentType(JSON).body(Json.encode(behaviorGroup)).when().post(path).then().statusCode(200).contentType(JSON).extract().body().asString();
JsonObject jsonBehaviorGroup = new JsonObject(responseBody);
jsonBehaviorGroup.mapTo(BehaviorGroup.class);
assertNotNull(jsonBehaviorGroup.getString("id"));
assertNull(jsonBehaviorGroup.getString("accountId"));
assertNull(jsonBehaviorGroup.getString("orgId"));
assertEquals(behaviorGroup.getDisplayName(), jsonBehaviorGroup.getString("display_name"));
assertEquals(behaviorGroup.getBundleId().toString(), jsonBehaviorGroup.getString("bundle_id"));
assertNotNull(jsonBehaviorGroup.getString("created"));
return jsonBehaviorGroup.getString("id");
}
Aggregations