Search in sources :

Example 11 with PagedResult

use of org.apache.archiva.components.rest.model.PagedResult in project archiva by apache.

the class NativeRepositoryGroupServiceTest method testRemoveRepositoryFromGroup404.

@Test
void testRemoveRepositoryFromGroup404() {
    String token = getAdminToken();
    try {
        Map<String, Object> jsonAsMap = new HashMap<>();
        jsonAsMap.put("id", "group_001");
        jsonAsMap.put("name", "group_001");
        jsonAsMap.put("repositories", Arrays.asList("internal"));
        Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).post("").prettyPeek().then().statusCode(201).extract().response();
        assertNotNull(response);
        RepositoryGroup result = response.getBody().jsonPath().getObject("", RepositoryGroup.class);
        assertNotNull(result);
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
        assertNotNull(response);
        PagedResult resultList = response.getBody().jsonPath().getObject("", PagedResult.class);
        assertEquals(1, resultList.getPagination().getTotalCount());
        assertNotNull(result.getRepositories());
        assertEquals(1, result.getRepositories().size());
        assertTrue(result.getRepositories().contains("internal"));
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).delete("group_001/repositories/internalxx").prettyPeek().then().statusCode(404).extract().response();
        assertNotNull(response);
        ArchivaRestError error = response.getBody().jsonPath().getObject("", ArchivaRestError.class);
        assertNotNull(error);
    } finally {
        given().spec(getRequestSpec(token)).contentType(JSON).when().delete("group_001");
    }
}
Also used : Response(io.restassured.response.Response) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) HashMap(java.util.HashMap) ArchivaRestError(org.apache.archiva.rest.api.v2.svc.ArchivaRestError) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Test(org.junit.jupiter.api.Test)

Example 12 with PagedResult

use of org.apache.archiva.components.rest.model.PagedResult in project archiva by apache.

the class NativeRepositoryGroupServiceTest method testRemoveRepositoryGroup.

@Test
void testRemoveRepositoryGroup() {
    String token = getAdminToken();
    List<String> groups = new ArrayList<>();
    try {
        for (int i = 0; i < 10; i++) {
            String groupName = String.format("group_%03d", i);
            groups.add(groupName);
            Map<String, Object> jsonAsMap = new HashMap<>();
            jsonAsMap.put("id", groupName);
            jsonAsMap.put("name", groupName);
            Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).post("").then().statusCode(201).extract().response();
            assertNotNull(response);
            RepositoryGroup result = response.getBody().jsonPath().getObject("", RepositoryGroup.class);
            assertNotNull(result);
        }
        Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().delete("group_001").then().statusCode(200).extract().response();
        assertNotNull(response);
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
        assertNotNull(response);
        PagedResult resultList = response.getBody().jsonPath().getObject("", PagedResult.class);
        assertEquals(9, resultList.getPagination().getTotalCount());
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().delete("group_005").then().statusCode(200).extract().response();
        assertNotNull(response);
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
        assertNotNull(response);
        resultList = response.getBody().jsonPath().getObject("", PagedResult.class);
        assertEquals(8, resultList.getPagination().getTotalCount());
    } finally {
        for (String groupName : groups) {
            if (!("group_001".equals(groupName) || "group_005".equals(groupName))) {
                given().spec(getRequestSpec(token)).contentType(JSON).when().delete(groupName);
            }
        }
    }
}
Also used : Response(io.restassured.response.Response) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Test(org.junit.jupiter.api.Test)

Example 13 with PagedResult

use of org.apache.archiva.components.rest.model.PagedResult in project archiva by apache.

the class NativeRepositoryGroupServiceTest method testAddMultipleGroups.

@Test
void testAddMultipleGroups() {
    String token = getAdminToken();
    List<String> groups = new ArrayList<>();
    try {
        for (int i = 0; i < 10; i++) {
            String groupName = String.format("group_%03d", i);
            groups.add(groupName);
            Map<String, Object> jsonAsMap = new HashMap<>();
            jsonAsMap.put("id", groupName);
            jsonAsMap.put("name", groupName);
            Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).post("").then().statusCode(201).extract().response();
            assertNotNull(response);
            RepositoryGroup result = response.getBody().jsonPath().getObject("", RepositoryGroup.class);
            assertNotNull(result);
        }
        Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
        assertNotNull(response);
        PagedResult resultList = response.getBody().jsonPath().getObject("", PagedResult.class);
        assertEquals(10, resultList.getPagination().getTotalCount());
    } finally {
        for (String groupName : groups) {
            given().spec(getRequestSpec(token)).contentType(JSON).when().delete(groupName);
        }
    }
}
Also used : Response(io.restassured.response.Response) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Test(org.junit.jupiter.api.Test)

Example 14 with PagedResult

use of org.apache.archiva.components.rest.model.PagedResult in project archiva by apache.

the class NativeRepositoryGroupServiceTest method testRemoveRepositoryFromGroup.

@Test
void testRemoveRepositoryFromGroup() {
    String token = getAdminToken();
    try {
        Map<String, Object> jsonAsMap = new HashMap<>();
        jsonAsMap.put("id", "group_001");
        jsonAsMap.put("name", "group_001");
        jsonAsMap.put("repositories", Arrays.asList("internal"));
        Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).post("").prettyPeek().then().statusCode(201).extract().response();
        assertNotNull(response);
        RepositoryGroup result = response.getBody().jsonPath().getObject("", RepositoryGroup.class);
        assertNotNull(result);
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
        assertNotNull(response);
        PagedResult resultList = response.getBody().jsonPath().getObject("", PagedResult.class);
        assertEquals(1, resultList.getPagination().getTotalCount());
        assertNotNull(result.getRepositories());
        assertEquals(1, result.getRepositories().size());
        assertTrue(result.getRepositories().contains("internal"));
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).delete("group_001/repositories/internal").prettyPeek().then().statusCode(200).extract().response();
        assertNotNull(response);
        result = response.getBody().jsonPath().getObject("", RepositoryGroup.class);
        assertNotNull(result);
        assertEquals(0, result.getRepositories().size());
    } finally {
        given().spec(getRequestSpec(token)).contentType(JSON).when().delete("group_001").then().statusCode(200);
    }
}
Also used : Response(io.restassured.response.Response) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) HashMap(java.util.HashMap) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Test(org.junit.jupiter.api.Test)

Aggregations

PagedResult (org.apache.archiva.components.rest.model.PagedResult)14 Response (io.restassured.response.Response)11 Test (org.junit.jupiter.api.Test)11 RepositoryGroup (org.apache.archiva.rest.api.v2.model.RepositoryGroup)8 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Repository (org.apache.archiva.rest.api.v2.model.Repository)3 ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)3 RestAssured.given (io.restassured.RestAssured.given)2 JSON (io.restassured.http.ContentType.JSON)2 PropertyEntry (org.apache.archiva.components.rest.model.PropertyEntry)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ResourceBundle (java.util.ResourceBundle)1 Predicate (java.util.function.Predicate)1