use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class ExceptionMapperHelper method accepts.
public static boolean accepts(ErrorResponse errorResponse, int acceptedStatusCode, String metaTypeValue) {
if (errorResponse.getHttpStatus() != acceptedStatusCode) {
return false;
}
Iterator<ErrorData> errors = errorResponse.getErrors().iterator();
if (!errors.hasNext()) {
return false;
}
ErrorData error = errors.next();
Map<String, Object> meta = error.getMeta();
return meta != null && metaTypeValue.equals(meta.get(META_TYPE_KEY));
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class ErrorResponse method toResponse.
public Response toResponse() {
Document responseDocument = new Document();
List<ErrorData> errors = new ArrayList<>();
for (ErrorData error : getErrors()) {
errors.add(error);
}
responseDocument.setErrors(errors);
return new Response(responseDocument, getHttpStatus());
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class DocumentMapperTest method testErrors.
@Test
public void testErrors() {
JsonApiResponse response = new JsonApiResponse();
ErrorData error = Mockito.mock(ErrorData.class);
response.setErrors(Arrays.asList(error));
Document document = mapper.toDocument(response, createAdapter(Task.class));
List<ErrorData> errors = document.getErrors();
Assert.assertEquals(1, errors.size());
Assert.assertSame(error, errors.get(0));
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class ErrorDataBuilderTest method shouldSetSourcePointer.
@Test
public void shouldSetSourcePointer() throws Exception {
ErrorData error = ErrorData.builder().setSourcePointer(ErrorDataMother.POINTER).build();
assertThat(error.getSourcePointer()).isEqualTo(ErrorDataMother.POINTER);
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class ErrorDataBuilderTest method shouldSetMeta.
@Test
public void shouldSetMeta() throws Exception {
ErrorData error = ErrorData.builder().setMeta(ErrorDataMother.META).build();
assertThat(error.getMeta()).contains(MapEntry.entry(ErrorDataMother.META_KEY, ErrorDataMother.META_VALUE));
}
Aggregations