use of com.redhat.cloud.notifications.Json in project notifications-backend by RedHatInsights.
the class NotificationResourceTest method testEventTypeFetchingByApplication.
@Test
void testEventTypeFetchingByApplication() {
helpers.createTestAppAndEventTypes();
List<Application> apps = applicationRepository.getApplications(TEST_BUNDLE_NAME);
UUID myOtherTesterApplicationId = apps.stream().filter(a -> a.getName().equals(TEST_APP_NAME_2)).findFirst().get().getId();
Header identityHeader = initRbacMock(TENANT, ORG_ID, USERNAME, RbacAccess.FULL_ACCESS);
Response response = given().when().header(identityHeader).queryParam("applicationIds", myOtherTesterApplicationId).get("/notifications/eventTypes").then().statusCode(200).contentType(JSON).extract().response();
JsonObject page = new JsonObject(response.getBody().asString());
JsonArray eventTypes = page.getJsonArray("data");
for (int i = 0; i < eventTypes.size(); i++) {
JsonObject ev = eventTypes.getJsonObject(i);
ev.mapTo(EventType.class);
assertEquals(myOtherTesterApplicationId.toString(), ev.getJsonObject("application").getString("id"));
}
assertEquals(100, page.getJsonObject("meta").getInteger("count"));
assertEquals(20, eventTypes.size());
}
use of com.redhat.cloud.notifications.Json 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"));
}
use of com.redhat.cloud.notifications.Json in project notifications-backend by RedHatInsights.
the class NotificationResourceTest method testEventTypeFetchingByBundle.
@Test
void testEventTypeFetchingByBundle() {
helpers.createTestAppAndEventTypes();
List<Application> apps = applicationRepository.getApplications(TEST_BUNDLE_NAME);
UUID myBundleId = apps.stream().filter(a -> a.getName().equals(TEST_APP_NAME_2)).findFirst().get().getBundleId();
Header identityHeader = initRbacMock(TENANT, ORG_ID, USERNAME, RbacAccess.FULL_ACCESS);
Response response = given().when().header(identityHeader).queryParam("bundleId", myBundleId).get("/notifications/eventTypes").then().statusCode(200).contentType(JSON).extract().response();
JsonObject page = new JsonObject(response.getBody().asString());
JsonArray eventTypes = page.getJsonArray("data");
for (int i = 0; i < eventTypes.size(); i++) {
JsonObject ev = eventTypes.getJsonObject(i);
ev.mapTo(EventType.class);
assertEquals(myBundleId.toString(), ev.getJsonObject("application").getString("bundle_id"));
}
assertEquals(200, page.getJsonObject("meta").getInteger("count"));
assertEquals(20, eventTypes.size());
}
use of com.redhat.cloud.notifications.Json in project notifications-backend by RedHatInsights.
the class NotificationResourceTest method testGetBundlesFacets.
@Test
void testGetBundlesFacets() {
// no children by default
Header identityHeader = initRbacMock("test", "test2", "user", READ_ACCESS);
List<Facet> bundles = given().header(identityHeader).when().contentType(JSON).get("/notifications/facets/bundles").then().statusCode(200).contentType(JSON).extract().response().jsonPath().getList(".", Facet.class);
assertTrue(bundles.size() > 0);
Optional<Facet> rhel = bundles.stream().filter(facet -> facet.getName().equals("rhel")).findFirst();
assertTrue(rhel.isPresent());
assertEquals("Red Hat Enterprise Linux", rhel.get().getDisplayName());
assertNull(rhel.get().getChildren());
// with children
bundles = given().header(identityHeader).when().contentType(JSON).queryParam("includeApplications", "true").get("/notifications/facets/bundles").then().statusCode(200).contentType(JSON).extract().response().jsonPath().getList(".", Facet.class);
assertTrue(bundles.size() > 0);
rhel = bundles.stream().filter(facet -> facet.getName().equals("rhel")).findFirst();
assertTrue(rhel.isPresent());
assertEquals("Red Hat Enterprise Linux", rhel.get().getDisplayName());
assertNotNull(rhel.get().getChildren());
Optional<Facet> policies = rhel.get().getChildren().stream().filter(facet -> facet.getName().equals("policies")).findFirst();
assertTrue(policies.isPresent());
assertEquals("Policies", policies.get().getDisplayName());
}
use of com.redhat.cloud.notifications.Json in project notifications-backend by RedHatInsights.
the class NotificationResourceTest method testGetApplicationFacets.
@Test
void testGetApplicationFacets() {
Header identityHeader = initRbacMock("test", "test2", "user", READ_ACCESS);
List<Facet> applications = given().header(identityHeader).when().get("/notifications/facets/applications?bundleName=rhel").then().statusCode(200).contentType(JSON).extract().response().jsonPath().getList(".", Facet.class);
assertTrue(applications.size() > 0);
Optional<Facet> policies = applications.stream().filter(facet -> facet.getName().equals("policies")).findFirst();
assertTrue(policies.isPresent());
assertEquals("Policies", policies.get().getDisplayName());
// Without bundle returns all applications across bundles
applications = given().header(identityHeader).when().get("/notifications/facets/applications").then().statusCode(200).contentType(JSON).extract().response().jsonPath().getList(".", Facet.class);
assertTrue(applications.size() > 0);
policies = applications.stream().filter(facet -> facet.getName().equals("policies")).findFirst();
assertTrue(policies.isPresent());
assertEquals("Policies", policies.get().getDisplayName());
}
Aggregations