Search in sources :

Example 1 with ArchivaRestError

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();
}
Also used : Response(javax.ws.rs.core.Response) ArchivaRestError(org.apache.archiva.rest.api.v2.svc.ArchivaRestError)

Example 2 with ArchivaRestError

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

Aggregations

ArchivaRestError (org.apache.archiva.rest.api.v2.svc.ArchivaRestError)2 Response (io.restassured.response.Response)1 HashMap (java.util.HashMap)1 Response (javax.ws.rs.core.Response)1 PagedResult (org.apache.archiva.components.rest.model.PagedResult)1 RepositoryGroup (org.apache.archiva.rest.api.v2.model.RepositoryGroup)1 Test (org.junit.jupiter.api.Test)1