use of com.redhat.cloud.notifications.models.Bundle in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepositoryTest method testUpdateBehaviorGroupActionsWithWrongAccountId.
@Test
void testUpdateBehaviorGroupActionsWithWrongAccountId() {
Bundle bundle = resourceHelpers.createBundle();
BehaviorGroup behaviorGroup = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "displayName", bundle.getId());
Endpoint endpoint = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, WEBHOOK);
updateAndCheckBehaviorGroupActions("unknownAccountId", bundle.getId(), behaviorGroup.getId(), NOT_FOUND, endpoint.getId());
}
use of com.redhat.cloud.notifications.models.Bundle 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.Bundle 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.Bundle 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.Bundle in project notifications-backend by RedHatInsights.
the class LifecycleITest method createBundle.
private String createBundle(Header header) {
Bundle bundle = new Bundle(BUNDLE_NAME, "A bundle");
String responseBody = given().basePath(API_INTERNAL).header(header).contentType(JSON).body(Json.encode(bundle)).when().post("/bundles").then().statusCode(200).contentType(JSON).extract().body().asString();
JsonObject jsonBundle = new JsonObject(responseBody);
jsonBundle.mapTo(Bundle.class);
assertNotNull(jsonBundle.getString("id"));
assertEquals(bundle.getName(), jsonBundle.getString("name"));
assertEquals(bundle.getDisplayName(), jsonBundle.getString("display_name"));
assertNotNull(jsonBundle.getString("created"));
return jsonBundle.getString("id");
}
Aggregations