Search in sources :

Example 1 with READ_ACCESS

use of com.redhat.cloud.notifications.MockServerConfig.RbacAccess.READ_ACCESS 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());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ResourceHelpers(com.redhat.cloud.notifications.db.ResourceHelpers) TestLifecycleManager(com.redhat.cloud.notifications.TestLifecycleManager) FULL_ACCESS(com.redhat.cloud.notifications.MockServerConfig.RbacAccess.FULL_ACCESS) TEST_BUNDLE_NAME(com.redhat.cloud.notifications.db.ResourceHelpers.TEST_BUNDLE_NAME) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Header(io.restassured.http.Header) MockServerConfig(com.redhat.cloud.notifications.MockServerConfig) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) EventType(com.redhat.cloud.notifications.models.EventType) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) NO_ACCESS(com.redhat.cloud.notifications.MockServerConfig.RbacAccess.NO_ACCESS) RbacAccess(com.redhat.cloud.notifications.MockServerConfig.RbacAccess) JsonObject(io.vertx.core.json.JsonObject) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest) BehaviorGroupRepository(com.redhat.cloud.notifications.db.repositories.BehaviorGroupRepository) QuarkusTestResource(io.quarkus.test.common.QuarkusTestResource) Application(com.redhat.cloud.notifications.models.Application) Json(com.redhat.cloud.notifications.Json) JSON(io.restassured.http.ContentType.JSON) ApplicationRepository(com.redhat.cloud.notifications.db.repositories.ApplicationRepository) Set(java.util.Set) Facet(com.redhat.cloud.notifications.routers.models.Facet) READ_ACCESS(com.redhat.cloud.notifications.MockServerConfig.RbacAccess.READ_ACCESS) UUID(java.util.UUID) TEST_APP_NAME_2(com.redhat.cloud.notifications.db.ResourceHelpers.TEST_APP_NAME_2) Test(org.junit.jupiter.api.Test) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Response(io.restassured.response.Response) TestConstants(com.redhat.cloud.notifications.TestConstants) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) TestHelpers(com.redhat.cloud.notifications.TestHelpers) RestAssured.given(io.restassured.RestAssured.given) RestAssured(io.restassured.RestAssured) Header(io.restassured.http.Header) Facet(com.redhat.cloud.notifications.routers.models.Facet) QuarkusTest(io.quarkus.test.junit.QuarkusTest) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest) Test(org.junit.jupiter.api.Test)

Example 2 with READ_ACCESS

use of com.redhat.cloud.notifications.MockServerConfig.RbacAccess.READ_ACCESS 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());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ResourceHelpers(com.redhat.cloud.notifications.db.ResourceHelpers) TestLifecycleManager(com.redhat.cloud.notifications.TestLifecycleManager) FULL_ACCESS(com.redhat.cloud.notifications.MockServerConfig.RbacAccess.FULL_ACCESS) TEST_BUNDLE_NAME(com.redhat.cloud.notifications.db.ResourceHelpers.TEST_BUNDLE_NAME) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Header(io.restassured.http.Header) MockServerConfig(com.redhat.cloud.notifications.MockServerConfig) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) EventType(com.redhat.cloud.notifications.models.EventType) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) NO_ACCESS(com.redhat.cloud.notifications.MockServerConfig.RbacAccess.NO_ACCESS) RbacAccess(com.redhat.cloud.notifications.MockServerConfig.RbacAccess) JsonObject(io.vertx.core.json.JsonObject) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest) BehaviorGroupRepository(com.redhat.cloud.notifications.db.repositories.BehaviorGroupRepository) QuarkusTestResource(io.quarkus.test.common.QuarkusTestResource) Application(com.redhat.cloud.notifications.models.Application) Json(com.redhat.cloud.notifications.Json) JSON(io.restassured.http.ContentType.JSON) ApplicationRepository(com.redhat.cloud.notifications.db.repositories.ApplicationRepository) Set(java.util.Set) Facet(com.redhat.cloud.notifications.routers.models.Facet) READ_ACCESS(com.redhat.cloud.notifications.MockServerConfig.RbacAccess.READ_ACCESS) UUID(java.util.UUID) TEST_APP_NAME_2(com.redhat.cloud.notifications.db.ResourceHelpers.TEST_APP_NAME_2) Test(org.junit.jupiter.api.Test) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Response(io.restassured.response.Response) TestConstants(com.redhat.cloud.notifications.TestConstants) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) TestHelpers(com.redhat.cloud.notifications.TestHelpers) RestAssured.given(io.restassured.RestAssured.given) RestAssured(io.restassured.RestAssured) Header(io.restassured.http.Header) Facet(com.redhat.cloud.notifications.routers.models.Facet) QuarkusTest(io.quarkus.test.junit.QuarkusTest) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest) Test(org.junit.jupiter.api.Test)

Aggregations

Json (com.redhat.cloud.notifications.Json)2 MockServerConfig (com.redhat.cloud.notifications.MockServerConfig)2 RbacAccess (com.redhat.cloud.notifications.MockServerConfig.RbacAccess)2 FULL_ACCESS (com.redhat.cloud.notifications.MockServerConfig.RbacAccess.FULL_ACCESS)2 NO_ACCESS (com.redhat.cloud.notifications.MockServerConfig.RbacAccess.NO_ACCESS)2 READ_ACCESS (com.redhat.cloud.notifications.MockServerConfig.RbacAccess.READ_ACCESS)2 TestConstants (com.redhat.cloud.notifications.TestConstants)2 TestHelpers (com.redhat.cloud.notifications.TestHelpers)2 TestLifecycleManager (com.redhat.cloud.notifications.TestLifecycleManager)2 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)2 ResourceHelpers (com.redhat.cloud.notifications.db.ResourceHelpers)2 TEST_APP_NAME_2 (com.redhat.cloud.notifications.db.ResourceHelpers.TEST_APP_NAME_2)2 TEST_BUNDLE_NAME (com.redhat.cloud.notifications.db.ResourceHelpers.TEST_BUNDLE_NAME)2 ApplicationRepository (com.redhat.cloud.notifications.db.repositories.ApplicationRepository)2 BehaviorGroupRepository (com.redhat.cloud.notifications.db.repositories.BehaviorGroupRepository)2 Application (com.redhat.cloud.notifications.models.Application)2 BehaviorGroup (com.redhat.cloud.notifications.models.BehaviorGroup)2 EventType (com.redhat.cloud.notifications.models.EventType)2 Facet (com.redhat.cloud.notifications.routers.models.Facet)2 QuarkusTestResource (io.quarkus.test.common.QuarkusTestResource)2