Search in sources :

Example 16 with EventType

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

the class ValidationResourceTest method shouldReturnStatusOkWhenTripleExists.

@Test
void shouldReturnStatusOkWhenTripleExists() {
    EventType eventType = new EventType();
    when(applicationRepository.getEventType(eq("my-bundle"), eq("Policies"), eq("Any"))).thenReturn(eventType);
    String identityHeaderValue = TestHelpers.encodeRHIdentityInfo("empty", "empty", "user");
    Header identityHeader = TestHelpers.createRHIdentityHeader(identityHeaderValue);
    MockServerConfig.addMockRbacAccess(identityHeaderValue, FULL_ACCESS);
    given().header(identityHeader).when().param("bundle", "my-bundle").param("application", "Policies").param("eventType", "Any").get(API_INTERNAL + "/validation/baet").then().statusCode(200);
}
Also used : Header(io.restassured.http.Header) EventType(com.redhat.cloud.notifications.models.EventType) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 17 with EventType

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

the class BehaviorGroupRepositoryTest method testFindEventTypesByBehaviorGroupId.

@Test
void testFindEventTypesByBehaviorGroupId() {
    Bundle bundle = resourceHelpers.createBundle();
    Application app = resourceHelpers.createApplication(bundle.getId());
    EventType eventType = createEventType(app);
    BehaviorGroup behaviorGroup = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "displayName", bundle.getId());
    updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup.getId());
    List<EventType> eventTypes = resourceHelpers.findEventTypesByBehaviorGroupId(behaviorGroup.getId());
    assertEquals(1, eventTypes.size());
    assertEquals(eventType.getId(), eventTypes.get(0).getId());
}
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 18 with EventType

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

the class BehaviorGroupRepositoryTest method createEventType.

@Transactional
EventType createEventType(Application app) {
    EventType eventType = new EventType();
    eventType.setApplication(app);
    eventType.setApplicationId(app.getId());
    eventType.setName("name");
    eventType.setDisplayName("displayName");
    entityManager.persist(eventType);
    return eventType;
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) Transactional(javax.transaction.Transactional)

Example 19 with EventType

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

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

the class LifecycleITest method createEventType.

private String createEventType(Header header, String appId) {
    EventType eventType = new EventType();
    eventType.setApplicationId(UUID.fromString(appId));
    eventType.setName(EVENT_TYPE_NAME);
    eventType.setDisplayName("Policies will take care of the rules");
    eventType.setDescription("Policies is super cool, you should use it");
    String responseBody = given().when().basePath(API_INTERNAL).header(header).contentType(JSON).body(Json.encode(eventType)).post("/eventTypes").then().statusCode(200).contentType(JSON).extract().body().asString();
    JsonObject jsonEventType = new JsonObject(responseBody);
    jsonEventType.mapTo(EventType.class);
    assertNotNull(jsonEventType.getString("id"));
    assertEquals(eventType.getName(), jsonEventType.getString("name"));
    assertEquals(eventType.getDisplayName(), jsonEventType.getString("display_name"));
    assertEquals(eventType.getDescription(), jsonEventType.getString("description"));
    return jsonEventType.getString("id");
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) JsonObject(io.vertx.core.json.JsonObject)

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