use of com.redhat.cloud.notifications.MockServerConfig.RbacAccess.FULL_ACCESS in project notifications-backend by RedHatInsights.
the class NotificationResourceTest method testGetEventTypesAffectedByEndpoint.
@Test
void testGetEventTypesAffectedByEndpoint() {
String tenant = "testGetEventTypesAffectedByEndpoint";
String orgId = "testGetEventTypesAffectedByEndpointOrgId";
Header identityHeader = initRbacMock(tenant, orgId, "user", FULL_ACCESS);
UUID bundleId = helpers.createTestAppAndEventTypes();
UUID behaviorGroupId1 = helpers.createBehaviorGroup(tenant, "behavior-group-1", bundleId).getId();
UUID behaviorGroupId2 = helpers.createBehaviorGroup(tenant, "behavior-group-2", bundleId).getId();
UUID appId = applicationRepository.getApplications(TEST_BUNDLE_NAME).stream().filter(a -> a.getName().equals(TEST_APP_NAME_2)).findFirst().get().getId();
UUID endpointId1 = helpers.createWebhookEndpoint(tenant);
UUID endpointId2 = helpers.createWebhookEndpoint(tenant);
List<EventType> eventTypes = applicationRepository.getEventTypes(appId);
// ep1 assigned to ev0; ep2 not assigned.
behaviorGroupRepository.updateEventTypeBehaviors(tenant, eventTypes.get(0).getId(), Set.of(behaviorGroupId1));
behaviorGroupRepository.updateBehaviorGroupActions(tenant, behaviorGroupId1, List.of(endpointId1));
String responseBody = given().header(identityHeader).pathParam("endpointId", endpointId1.toString()).when().get("/notifications/behaviorGroups/affectedByRemovalOfEndpoint/{endpointId}").then().statusCode(200).contentType(JSON).extract().asString();
JsonArray behaviorGroups = new JsonArray(responseBody);
assertEquals(1, behaviorGroups.size());
behaviorGroups.getJsonObject(0).mapTo(BehaviorGroup.class);
assertEquals(behaviorGroupId1.toString(), behaviorGroups.getJsonObject(0).getString("id"));
responseBody = given().header(identityHeader).pathParam("endpointId", endpointId2.toString()).when().get("/notifications/behaviorGroups/affectedByRemovalOfEndpoint/{endpointId}").then().statusCode(200).contentType(JSON).extract().asString();
behaviorGroups = new JsonArray(responseBody);
assertEquals(0, behaviorGroups.size());
// ep1 assigned to event ev0; ep2 assigned to event ev1
behaviorGroupRepository.updateEventTypeBehaviors(tenant, eventTypes.get(0).getId(), Set.of(behaviorGroupId2));
behaviorGroupRepository.updateBehaviorGroupActions(tenant, behaviorGroupId2, List.of(endpointId2));
responseBody = given().header(identityHeader).pathParam("endpointId", endpointId1.toString()).when().get("/notifications/behaviorGroups/affectedByRemovalOfEndpoint/{endpointId}").then().statusCode(200).contentType(JSON).extract().asString();
behaviorGroups = new JsonArray(responseBody);
assertEquals(1, behaviorGroups.size());
behaviorGroups.getJsonObject(0).mapTo(BehaviorGroup.class);
assertEquals(behaviorGroupId1.toString(), behaviorGroups.getJsonObject(0).getString("id"));
responseBody = given().header(identityHeader).pathParam("endpointId", endpointId2.toString()).when().get("/notifications/behaviorGroups/affectedByRemovalOfEndpoint/{endpointId}").then().statusCode(200).contentType(JSON).extract().asString();
behaviorGroups = new JsonArray(responseBody);
assertEquals(1, behaviorGroups.size());
behaviorGroups.getJsonObject(0).mapTo(BehaviorGroup.class);
assertEquals(behaviorGroupId2.toString(), behaviorGroups.getJsonObject(0).getString("id"));
}
Aggregations