Search in sources :

Example 1 with JSON

use of io.restassured.http.ContentType.JSON in project archiva by apache.

the class NativeRepositoryServiceTest method testGetRepositories.

@Test
void testGetRepositories() {
    String token = getAdminToken();
    Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
    assertNotNull(response);
    PagedResult<Repository> repositoryPagedResult = response.getBody().jsonPath().getObject("", PagedResult.class);
    assertEquals(3, repositoryPagedResult.getPagination().getTotalCount());
    List<Repository> data = response.getBody().jsonPath().getList("data", Repository.class);
    assertTrue(data.stream().anyMatch(p -> "central".equals(p.getId())));
    assertTrue(data.stream().anyMatch(p -> "internal".equals(p.getId())));
    assertTrue(data.stream().anyMatch(p -> "snapshots".equals(p.getId())));
    Repository snapshotRepo = data.stream().filter(p -> "snapshots".equals(p.getId())).findFirst().get();
    assertEquals("Archiva Managed Snapshot Repository", snapshotRepo.getName());
    assertEquals("MAVEN", snapshotRepo.getType());
    assertEquals("managed", snapshotRepo.getCharacteristic());
    assertEquals("default", snapshotRepo.getLayout());
    assertTrue(snapshotRepo.isScanned());
    assertTrue(snapshotRepo.isIndex());
    Repository centralRepo = data.stream().filter(p -> "central".equals(p.getId())).findFirst().get();
    assertEquals("Central Repository", centralRepo.getName());
    assertEquals("MAVEN", centralRepo.getType());
    assertEquals("remote", centralRepo.getCharacteristic());
    assertEquals("default", centralRepo.getLayout());
}
Also used : Response(io.restassured.response.Response) Repository(org.apache.archiva.rest.api.v2.model.Repository) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) JSON(io.restassured.http.ContentType.JSON) DisplayName(org.junit.jupiter.api.DisplayName) MethodOrderer(org.junit.jupiter.api.MethodOrderer) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) TestInstance(org.junit.jupiter.api.TestInstance) Response(io.restassured.response.Response) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions(org.junit.jupiter.api.Assertions) RestAssured.given(io.restassured.RestAssured.given) Tag(org.junit.jupiter.api.Tag) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Repository(org.apache.archiva.rest.api.v2.model.Repository) Test(org.junit.jupiter.api.Test)

Example 2 with JSON

use of io.restassured.http.ContentType.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());
}
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) Response(io.restassured.response.Response) JsonArray(io.vertx.core.json.JsonArray) Header(io.restassured.http.Header) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) 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 3 with JSON

use of io.restassured.http.ContentType.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"));
}
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) JsonArray(io.vertx.core.json.JsonArray) Header(io.restassured.http.Header) EventType(com.redhat.cloud.notifications.models.EventType) UUID(java.util.UUID) QuarkusTest(io.quarkus.test.junit.QuarkusTest) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest) Test(org.junit.jupiter.api.Test)

Example 4 with JSON

use of io.restassured.http.ContentType.JSON in project archiva by apache.

the class NativeRepositoryServiceTest method testGetFilteredRepositories.

@Test
void testGetFilteredRepositories() {
    String token = getAdminToken();
    Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().queryParam("q", "central").get("").then().statusCode(200).extract().response();
    assertNotNull(response);
    PagedResult<Repository> repositoryPagedResult = response.getBody().jsonPath().getObject("", PagedResult.class);
    assertEquals(1, repositoryPagedResult.getPagination().getTotalCount());
    List<Repository> data = response.getBody().jsonPath().getList("data", Repository.class);
    assertTrue(data.stream().anyMatch(p -> "central".equals(p.getId())));
}
Also used : Response(io.restassured.response.Response) Repository(org.apache.archiva.rest.api.v2.model.Repository) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) JSON(io.restassured.http.ContentType.JSON) DisplayName(org.junit.jupiter.api.DisplayName) MethodOrderer(org.junit.jupiter.api.MethodOrderer) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) TestInstance(org.junit.jupiter.api.TestInstance) Response(io.restassured.response.Response) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions(org.junit.jupiter.api.Assertions) RestAssured.given(io.restassured.RestAssured.given) Tag(org.junit.jupiter.api.Tag) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Repository(org.apache.archiva.rest.api.v2.model.Repository) Test(org.junit.jupiter.api.Test)

Example 5 with JSON

use of io.restassured.http.ContentType.JSON in project archiva by apache.

the class NativeSecurityConfigurationServiceTest method testGetRbacManagers.

@Test
void testGetRbacManagers() {
    String token = getAdminToken();
    Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("rbac_managers").then().statusCode(200).extract().response();
    assertNotNull(response);
    List<BeanInformation> rbacList = response.getBody().jsonPath().getList("", BeanInformation.class);
    assertEquals(2, rbacList.size());
    assertTrue(rbacList.stream().anyMatch(bi -> "Database RBAC Manager".equals(bi.getDisplayName())));
    assertTrue(rbacList.stream().anyMatch(bi -> "LDAP RBAC Manager".equals(bi.getDisplayName())));
}
Also used : Response(io.restassured.response.Response) BeanInformation(org.apache.archiva.rest.api.v2.model.BeanInformation) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Arrays(java.util.Arrays) JSON(io.restassured.http.ContentType.JSON) HashMap(java.util.HashMap) CacheConfiguration(org.apache.archiva.rest.api.v2.model.CacheConfiguration) DisplayName(org.junit.jupiter.api.DisplayName) MethodOrderer(org.junit.jupiter.api.MethodOrderer) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) BeanInformation(org.apache.archiva.rest.api.v2.model.BeanInformation) List(java.util.List) TestInstance(org.junit.jupiter.api.TestInstance) Response(io.restassured.response.Response) PropertyEntry(org.apache.archiva.components.rest.model.PropertyEntry) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Assertions(org.junit.jupiter.api.Assertions) RestAssured.given(io.restassured.RestAssured.given) Tag(org.junit.jupiter.api.Tag) PagedResult(org.apache.archiva.components.rest.model.PagedResult) LdapConfiguration(org.apache.archiva.rest.api.v2.model.LdapConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

RestAssured.given (io.restassured.RestAssured.given)10 JSON (io.restassured.http.ContentType.JSON)10 List (java.util.List)10 Response (io.restassured.response.Response)9 Test (org.junit.jupiter.api.Test)9 Application (com.redhat.cloud.notifications.models.Application)6 BehaviorGroup (com.redhat.cloud.notifications.models.BehaviorGroup)6 EventType (com.redhat.cloud.notifications.models.EventType)6 Header (io.restassured.http.Header)6 JsonArray (io.vertx.core.json.JsonArray)6 JsonObject (io.vertx.core.json.JsonObject)6 Optional (java.util.Optional)6 UUID (java.util.UUID)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)6 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)6 Json (com.redhat.cloud.notifications.Json)5 MockServerConfig (com.redhat.cloud.notifications.MockServerConfig)5 RbacAccess (com.redhat.cloud.notifications.MockServerConfig.RbacAccess)5 FULL_ACCESS (com.redhat.cloud.notifications.MockServerConfig.RbacAccess.FULL_ACCESS)5