Search in sources :

Example 6 with PagedResult

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

the class NativeRepositoryGroupServiceTest method testAddRepositoryToGroup.

@Test
void testAddRepositoryToGroup() {
    String token = getAdminToken();
    try {
        Map<String, Object> jsonAsMap = new HashMap<>();
        jsonAsMap.put("id", "group_001");
        jsonAsMap.put("name", "group_001");
        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());
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).put("group_001/repositories/internal").prettyPeek().then().statusCode(200).extract().response();
        assertNotNull(response);
        result = response.getBody().jsonPath().getObject("", RepositoryGroup.class);
        assertNotNull(result);
        assertEquals(1, result.getRepositories().size());
        assertTrue(result.getRepositories().contains("internal"));
    } 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) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Test(org.junit.jupiter.api.Test)

Example 7 with PagedResult

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

the class NativeRepositoryGroupServiceTest method testAddRepositoryToGroupIdempotency.

@Test
void testAddRepositoryToGroupIdempotency() {
    String token = getAdminToken();
    try {
        Map<String, Object> jsonAsMap = new HashMap<>();
        jsonAsMap.put("id", "group_001");
        jsonAsMap.put("name", "group_001");
        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());
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).put("group_001/repositories/internal").prettyPeek().then().statusCode(200).extract().response();
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).put("group_001/repositories/internal").prettyPeek().then().statusCode(200).extract().response();
        assertNotNull(response);
        result = response.getBody().jsonPath().getObject("", RepositoryGroup.class);
        assertNotNull(result);
        assertEquals(1, result.getRepositories().size());
        assertTrue(result.getRepositories().contains("internal"));
    } 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)

Example 8 with PagedResult

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

the class NativeSecurityConfigurationServiceTest method testGetConfigurationProperties.

@Test
void testGetConfigurationProperties() {
    String token = getAdminToken();
    Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("config/properties").then().statusCode(200).extract().response();
    assertNotNull(response);
    PagedResult<PropertyEntry> result = response.getBody().jsonPath().getObject("", PagedResult.class);
    List<PropertyEntry> propList = response.getBody().jsonPath().getList("data", PropertyEntry.class);
    assertEquals(10, result.getPagination().getLimit());
    assertEquals(0, result.getPagination().getOffset());
    assertEquals(47, result.getPagination().getTotalCount());
    assertEquals("authentication.jwt.keystoreType", propList.get(0).getKey());
    response = given().spec(getRequestSpec(token)).contentType(JSON).when().queryParam("offset", "3").queryParam("limit", "5").get("config/properties").then().statusCode(200).extract().response();
    assertNotNull(response);
    result = response.getBody().jsonPath().getObject("", PagedResult.class);
    assertEquals(5, result.getPagination().getLimit());
    assertEquals(47, result.getPagination().getTotalCount());
    propList = response.getBody().jsonPath().getList("data", PropertyEntry.class);
    assertEquals("authentication.jwt.refreshLifetimeMs", propList.get(0).getKey());
}
Also used : Response(io.restassured.response.Response) PropertyEntry(org.apache.archiva.components.rest.model.PropertyEntry) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Test(org.junit.jupiter.api.Test)

Example 9 with PagedResult

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

the class DefaultRepositoryGroupService method getRepositoriesGroups.

@Override
public PagedResult<RepositoryGroup> getRepositoriesGroups(String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order) throws ArchivaRestServiceException {
    try {
        Predicate<org.apache.archiva.repository.RepositoryGroup> filter = QUERY_HELPER.getQueryFilter(searchTerm);
        Comparator<org.apache.archiva.repository.RepositoryGroup> ordering = QUERY_HELPER.getComparator(orderBy, QUERY_HELPER.isAscending(order));
        int totalCount = Math.toIntExact(repositoryRegistry.getRepositoryGroups().stream().filter(filter).count());
        List<RepositoryGroup> result = repositoryRegistry.getRepositoryGroups().stream().filter(filter).sorted(ordering).skip(offset).limit(limit).map(RepositoryGroup::of).collect(Collectors.toList());
        return new PagedResult<>(totalCount, offset, limit, result);
    } catch (ArithmeticException e) {
        log.error("Could not convert total count: {}", e.getMessage());
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.INVALID_RESULT_SET_ERROR));
    }
}
Also used : EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) PagedResult(org.apache.archiva.components.rest.model.PagedResult)

Example 10 with PagedResult

use of org.apache.archiva.components.rest.model.PagedResult 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)

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