Search in sources :

Example 11 with Bundle

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());
}
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 12 with Bundle

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"));
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) Bundle(com.redhat.cloud.notifications.models.Bundle) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) BadRequestException(javax.ws.rs.BadRequestException) 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 13 with Bundle

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());
}
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 14 with Bundle

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));
}
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 15 with Bundle

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");
}
Also used : Bundle(com.redhat.cloud.notifications.models.Bundle) JsonObject(io.vertx.core.json.JsonObject)

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