Search in sources :

Example 16 with BehaviorGroup

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);
}
Also used : BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup)

Example 17 with 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"));
}
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 18 with BehaviorGroup

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());
}
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 19 with BehaviorGroup

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));
}
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 20 with BehaviorGroup

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

Aggregations

BehaviorGroup (com.redhat.cloud.notifications.models.BehaviorGroup)28 Bundle (com.redhat.cloud.notifications.models.Bundle)12 QuarkusTest (io.quarkus.test.junit.QuarkusTest)12 Test (org.junit.jupiter.api.Test)12 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)11 EventType (com.redhat.cloud.notifications.models.EventType)8 Endpoint (com.redhat.cloud.notifications.models.Endpoint)6 Application (com.redhat.cloud.notifications.models.Application)5 NotFoundException (javax.ws.rs.NotFoundException)4 Transactional (javax.transaction.Transactional)3 ValidatableResponse (io.restassured.response.ValidatableResponse)2 BehaviorGroupAction (com.redhat.cloud.notifications.models.BehaviorGroupAction)1 BehaviorGroupActionId (com.redhat.cloud.notifications.models.BehaviorGroupActionId)1 EventTypeBehavior (com.redhat.cloud.notifications.models.EventTypeBehavior)1 EventTypeBehaviorId (com.redhat.cloud.notifications.models.EventTypeBehaviorId)1 Header (io.restassured.http.Header)1 JsonObject (io.vertx.core.json.JsonObject)1 BadRequestException (javax.ws.rs.BadRequestException)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1