Search in sources :

Example 21 with BehaviorGroup

use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.

the class CrudTestHelpers method createDefaultBehaviorGroup.

public static Optional<String> createDefaultBehaviorGroup(Header identity, String displayName, String bundleId, int expected) {
    BehaviorGroup behaviorGroup = buildDefaultBehaviorGroup(displayName, bundleId);
    ValidatableResponse response = given().header(identity).basePath(API_INTERNAL).contentType(JSON).body(Json.encode(behaviorGroup)).post("/behaviorGroups/default").then().statusCode(expected);
    if (familyOf(expected) == SUCCESSFUL) {
        return Optional.of(response.extract().body().jsonPath().getString("id"));
    }
    return Optional.empty();
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup)

Example 22 with BehaviorGroup

use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.

the class BehaviorGroupRepositoryTest method testAddAndDeleteEventTypeBehavior.

@Test
void testAddAndDeleteEventTypeBehavior() {
    Bundle bundle = resourceHelpers.createBundle();
    Application app = resourceHelpers.createApplication(bundle.getId());
    EventType eventType = createEventType(app);
    BehaviorGroup behaviorGroup1 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 1", bundle.getId());
    BehaviorGroup behaviorGroup2 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 2", bundle.getId());
    BehaviorGroup behaviorGroup3 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 3", bundle.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId(), behaviorGroup2.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup2.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId(), behaviorGroup2.getId(), behaviorGroup3.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true);
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) Bundle(com.redhat.cloud.notifications.models.Bundle) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) 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 23 with BehaviorGroup

use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.

the class BehaviorGroupRepository method findDefaults.

public List<BehaviorGroup> findDefaults() {
    final String query = "SELECT DISTINCT b FROM BehaviorGroup b LEFT JOIN FETCH b.actions a " + "WHERE b.accountId IS NULL " + "ORDER BY b.created DESC, a.position ASC";
    List<BehaviorGroup> behaviorGroups = entityManager.createQuery(query, BehaviorGroup.class).getResultList();
    for (BehaviorGroup behaviorGroup : behaviorGroups) {
        behaviorGroup.filterOutBundle();
    }
    return behaviorGroups;
}
Also used : BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup)

Example 24 with BehaviorGroup

use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.

the class BehaviorGroupRepository method findByBundleId.

public List<BehaviorGroup> findByBundleId(String accountId, UUID bundleId) {
    Bundle bundle = entityManager.find(Bundle.class, bundleId);
    if (bundle == null) {
        throw new NotFoundException("Bundle not found");
    }
    List<BehaviorGroup> behaviorGroups = entityManager.createNamedQuery("findByBundleId", BehaviorGroup.class).setParameter("accountId", accountId).setParameter("bundleId", bundleId).getResultList();
    for (BehaviorGroup behaviorGroup : behaviorGroups) {
        behaviorGroup.filterOutBundle();
    }
    return behaviorGroups;
}
Also used : Bundle(com.redhat.cloud.notifications.models.Bundle) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) NotFoundException(javax.ws.rs.NotFoundException)

Example 25 with BehaviorGroup

use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.

the class BehaviorGroupRepository method findBehaviorGroupsByEventTypeId.

public List<BehaviorGroup> findBehaviorGroupsByEventTypeId(String accountId, UUID eventTypeId, Query limiter) {
    EventType eventType = entityManager.find(EventType.class, eventTypeId);
    if (eventType == null) {
        throw new NotFoundException("Event type not found");
    }
    String query = "SELECT bg FROM BehaviorGroup bg JOIN bg.behaviors b WHERE (bg.accountId = :accountId OR bg.accountId IS NULL) AND b.eventType.id = :eventTypeId";
    if (limiter != null) {
        query = limiter.getModifiedQuery(query);
    }
    TypedQuery<BehaviorGroup> typedQuery = entityManager.createQuery(query, BehaviorGroup.class).setParameter("accountId", accountId).setParameter("eventTypeId", eventTypeId);
    if (limiter != null && limiter.getLimit() != null && limiter.getLimit().getLimit() > 0) {
        typedQuery = typedQuery.setMaxResults(limiter.getLimit().getLimit()).setFirstResult(limiter.getLimit().getOffset());
    }
    List<BehaviorGroup> behaviorGroups = typedQuery.getResultList();
    for (BehaviorGroup behaviorGroup : behaviorGroups) {
        behaviorGroup.filterOutBundle().filterOutActions();
    }
    return behaviorGroups;
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) NotFoundException(javax.ws.rs.NotFoundException)

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