use of org.apache.archiva.rest.api.v2.svc.ArchivaRestError in project archiva by apache.
the class ArchivaRestServiceExceptionMapper method toResponse.
@Override
public Response toResponse(final ArchivaRestServiceException e) {
ArchivaRestError restError = new ArchivaRestError(e);
Response.ResponseBuilder responseBuilder = Response.status(e.getHttpErrorCode()).entity(restError);
if (e.getMessage() != null) {
responseBuilder = responseBuilder.status(new Response.StatusType() {
public int getStatusCode() {
return e.getHttpErrorCode();
}
public Response.Status.Family getFamily() {
return Response.Status.Family.familyOf(e.getHttpErrorCode());
}
public String getReasonPhrase() {
return e.getMessage();
}
});
}
return responseBuilder.build();
}
use of org.apache.archiva.rest.api.v2.svc.ArchivaRestError 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");
}
}
Aggregations