Search in sources :

Example 6 with BehaviorGroup

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

the class LifecycleITest method addBehaviorGroupAction.

@Transactional
void addBehaviorGroupAction(UUID behaviorGroupId, UUID endpointId) {
    BehaviorGroup behaviorGroup = entityManager.find(BehaviorGroup.class, behaviorGroupId);
    Endpoint endpoint = entityManager.find(Endpoint.class, endpointId);
    BehaviorGroupAction action = new BehaviorGroupAction();
    action.setId(new BehaviorGroupActionId());
    action.setBehaviorGroup(behaviorGroup);
    action.setEndpoint(endpoint);
    entityManager.persist(action);
}
Also used : BehaviorGroupActionId(com.redhat.cloud.notifications.models.BehaviorGroupActionId) Endpoint(com.redhat.cloud.notifications.models.Endpoint) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) BehaviorGroupAction(com.redhat.cloud.notifications.models.BehaviorGroupAction) Transactional(javax.transaction.Transactional)

Example 7 with BehaviorGroup

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

the class LifecycleITest method createBehaviorGroup.

@Transactional
BehaviorGroup createBehaviorGroup(String accountId, Bundle bundle) {
    BehaviorGroup behaviorGroup = new BehaviorGroup();
    behaviorGroup.setAccountId(accountId);
    behaviorGroup.setDisplayName("Behavior group");
    behaviorGroup.setBundle(bundle);
    behaviorGroup.setBundleId(bundle.getId());
    entityManager.persist(behaviorGroup);
    return behaviorGroup;
}
Also used : BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) Transactional(javax.transaction.Transactional)

Example 8 with BehaviorGroup

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

the class BehaviorGroupRepositoryTest method updateBehaviorGroup.

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

Example 9 with BehaviorGroup

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

the class BehaviorGroupRepositoryTest method testCreateAndUpdateAndDeleteBehaviorGroup.

@Test
void testCreateAndUpdateAndDeleteBehaviorGroup() {
    String newDisplayName = "newDisplayName";
    Bundle bundle = resourceHelpers.createBundle();
    // Create behavior group.
    BehaviorGroup behaviorGroup = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "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(updateBehaviorGroup(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.deleteBehaviorGroup(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 10 with BehaviorGroup

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

the class BehaviorGroupRepositoryTest method testAddAndDeleteBehaviorGroupAction.

@Test
void testAddAndDeleteBehaviorGroupAction() {
    Bundle bundle = resourceHelpers.createBundle();
    BehaviorGroup behaviorGroup1 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 1", bundle.getId());
    BehaviorGroup behaviorGroup2 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 2", bundle.getId());
    Endpoint endpoint1 = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, WEBHOOK);
    Endpoint endpoint2 = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, WEBHOOK);
    Endpoint endpoint3 = resourceHelpers.createEndpoint(DEFAULT_ACCOUNT_ID, WEBHOOK);
    // At the beginning of the test, endpoint1 shouldn't be linked with any behavior group.
    findBehaviorGroupsByEndpointId(endpoint1.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK, endpoint1.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK, endpoint1.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK, endpoint1.getId(), endpoint2.getId());
    // Now, endpoint1 should be linked with behaviorGroup1.
    findBehaviorGroupsByEndpointId(endpoint1.getId(), behaviorGroup1.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup2.getId(), OK, endpoint1.getId());
    // Then, endpoint1 should be linked with both behavior groups.
    findBehaviorGroupsByEndpointId(endpoint1.getId(), behaviorGroup1.getId(), behaviorGroup2.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK, endpoint2.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK, endpoint3.getId(), endpoint2.getId(), endpoint1.getId());
    updateAndCheckBehaviorGroupActions(DEFAULT_ACCOUNT_ID, bundle.getId(), behaviorGroup1.getId(), OK);
    // The link between endpoint1 and behaviorGroup1 was removed. Let's check it is still linked with behaviorGroup2.
    findBehaviorGroupsByEndpointId(endpoint1.getId(), behaviorGroup2.getId());
}
Also used : Endpoint(com.redhat.cloud.notifications.models.Endpoint) 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)

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