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;
}
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();
}
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);
}
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;
}
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");
}
}
}
}
Aggregations