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");
}
}
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);
}
}
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());
}
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));
}
}
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())));
}
Aggregations