Search in sources :

Example 21 with EventType

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

the class LifecycleITest method createEvent.

@Transactional
Event createEvent(String accountId, String orgId, String eventTypeId) {
    EventType eventType = entityManager.createQuery("FROM EventType e JOIN FETCH e.application a JOIN FETCH a.bundle WHERE e.id = :id", EventType.class).setParameter("id", UUID.fromString(eventTypeId)).getSingleResult();
    Event event = new Event(accountId, orgId, eventType, UUID.randomUUID());
    entityManager.persist(event);
    return event;
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) Event(com.redhat.cloud.notifications.models.Event) Transactional(javax.transaction.Transactional)

Example 22 with EventType

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

the class DbCleaner method clean.

/**
 * Deletes all records from all database tables (except for flyway_schema_history) and restores the default records.
 * This method should be called from a method annotated with <b>both</b> {@link BeforeEach} and {@link AfterEach} in
 * all test classes that involve SQL queries to guarantee the tests isolation in terms of stored data.
 */
@Transactional
public void clean() {
    for (Class<?> entity : ENTITIES) {
        entityManager.createQuery("DELETE FROM " + entity.getSimpleName()).executeUpdate();
    }
    Bundle bundle = new Bundle(DEFAULT_BUNDLE_NAME, DEFAULT_BUNDLE_DISPLAY_NAME);
    bundleRepository.createBundle(bundle);
    Application app = new Application();
    app.setBundleId(bundle.getId());
    app.setName(DEFAULT_APP_NAME);
    app.setDisplayName(DEFAULT_APP_DISPLAY_NAME);
    applicationRepository.createApp(app);
    EventType eventType = new EventType();
    eventType.setApplicationId(app.getId());
    eventType.setName(DEFAULT_EVENT_TYPE_NAME);
    eventType.setDisplayName(DEFAULT_EVENT_TYPE_DISPLAY_NAME);
    eventType.setDescription(DEFAULT_EVENT_TYPE_DESCRIPTION);
    applicationRepository.createEventType(eventType);
    entityManager.createQuery("UPDATE CurrentStatus SET status = :status").setParameter("status", Status.UP).executeUpdate();
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) Bundle(com.redhat.cloud.notifications.models.Bundle) Application(com.redhat.cloud.notifications.models.Application) Transactional(javax.transaction.Transactional)

Example 23 with EventType

use of com.redhat.cloud.notifications.models.EventType 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 24 with EventType

use of com.redhat.cloud.notifications.models.EventType 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)

Example 25 with EventType

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

the class CrudTestHelpers method updateEventType.

public static void updateEventType(Header identity, String appId, String eventTypeId, String name, String displayName, String description, int expectedStatusCode) {
    EventType eventType = buildEventType(appId, name, displayName, description);
    given().contentType(JSON).header(identity).pathParam("eventTypeId", eventTypeId).body(Json.encode(eventType)).put("/internal/eventTypes/{eventTypeId}").then().statusCode(expectedStatusCode).contentType(familyOf(expectedStatusCode) == SUCCESSFUL ? containsString(TEXT.toString()) : any(String.class));
    if (familyOf(expectedStatusCode) == SUCCESSFUL) {
        String responseBody = given().header(identity).pathParam("appId", eventType.getApplicationId()).when().get("/internal/applications/{appId}/eventTypes").then().statusCode(expectedStatusCode).contentType(JSON).extract().asString();
        JsonArray jsonEventTypes = new JsonArray(responseBody);
        for (int i = 0; i < jsonEventTypes.size(); i++) {
            JsonObject jsonEventType = jsonEventTypes.getJsonObject(i);
            jsonEventType.mapTo(EventType.class);
            if (jsonEventType.getString("id").equals(eventTypeId)) {
                assertEquals(eventType.getName(), jsonEventType.getString("name"));
                assertEquals(eventType.getDisplayName(), jsonEventType.getString("display_name"));
                assertEquals(eventType.getDescription(), jsonEventType.getString("description"));
                break;
            }
            if (i == jsonEventTypes.size() - 1) {
                fail("Event type not found");
            }
        }
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) EventType(com.redhat.cloud.notifications.models.EventType) JsonObject(io.vertx.core.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

EventType (com.redhat.cloud.notifications.models.EventType)36 QuarkusTest (io.quarkus.test.junit.QuarkusTest)16 Test (org.junit.jupiter.api.Test)16 Application (com.redhat.cloud.notifications.models.Application)14 Bundle (com.redhat.cloud.notifications.models.Bundle)11 Transactional (javax.transaction.Transactional)10 BehaviorGroup (com.redhat.cloud.notifications.models.BehaviorGroup)9 Action (com.redhat.cloud.notifications.ingress.Action)7 TestHelpers.serializeAction (com.redhat.cloud.notifications.TestHelpers.serializeAction)6 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)6 UUID (java.util.UUID)5 Event (com.redhat.cloud.notifications.models.Event)4 NotFoundException (javax.ws.rs.NotFoundException)4 AggregationEmailTemplate (com.redhat.cloud.notifications.models.AggregationEmailTemplate)3 InstantEmailTemplate (com.redhat.cloud.notifications.models.InstantEmailTemplate)3 Template (com.redhat.cloud.notifications.models.Template)3 Header (io.restassured.http.Header)3 Endpoint (com.redhat.cloud.notifications.models.Endpoint)2 JsonArray (io.vertx.core.json.JsonArray)2 JsonObject (io.vertx.core.json.JsonObject)2