use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.
the class PgUtilIT method respond422IllegalArgumentException.
@Test(expected = IllegalArgumentException.class)
public void respond422IllegalArgumentException() throws Throwable {
class C {
@SuppressWarnings("unused")
private void privateMethod(Errors entity) {
}
}
Method method = C.class.getDeclaredMethod("privateMethod", Errors.class);
PgUtil.respond422(method, "foo", "bar", "baz");
}
use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.
the class PgUtilIT method putForeignKeyViolation422.
@Test
public void putForeignKeyViolation422(TestContext testContext) {
String user1 = randomUuid();
String user2 = randomUuid();
String refId = randomUuid();
post(testContext, "Folio", user1, 201);
insertReferencing(testContext, refId, user1);
PgUtil.put("referencing", new Referencing().withId(refId).withUserId(user2), refId, okapiHeaders, vertx.getOrCreateContext(), ResponseWith422.class, asyncAssertSuccess(testContext, 422, response -> {
Errors errors = (Errors) response.result().getEntity();
assertThat(errors.getErrors(), hasSize(1));
Error error = errors.getErrors().get(0);
assertThat(error.getMessage(), containsString("Cannot set referencing.userid = " + user2 + " because it does not exist in users.id."));
assertThat(error.getParameters(), hasSize(1));
assertThat(error.getParameters().get(0).getKey(), is("referencing.userid"));
assertThat(error.getParameters().get(0).getValue(), is(user2));
}));
}
use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.
the class PgUtilIT method responseForeignKeyViolationNoMatch422.
@Test
public void responseForeignKeyViolationNoMatch422(TestContext testContext) throws Exception {
Exception genericDatabaseException = new PgException("", null, "", "bazMessage");
PgExceptionFacade exception = new PgExceptionFacade(genericDatabaseException);
Method respond400 = ResponseImpl.class.getMethod("respond400WithTextPlain", Object.class);
Method respond500 = ResponseImpl.class.getMethod("respond500WithTextPlain", Object.class);
Method respond422 = PgUtil.respond422method(ResponseWith422.class);
Future<Response> future = PgUtil.responseForeignKeyViolation("mytable", "myid", exception, respond422, respond400, respond500);
assertTrue(future.succeeded());
assertThat(future.result().getStatus(), is(422));
Errors errors = (Errors) future.result().getEntity();
assertThat(errors.getErrors().get(0).getMessage(), containsString("bazMessage"));
}
use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.
the class PgUtilIT method deleteByIdForeignKeyViolation422.
@Test
public void deleteByIdForeignKeyViolation422(TestContext testContext) {
String userId = randomUuid();
String refId = randomUuid();
post(testContext, "Folio", userId, 201);
insertReferencing(testContext, refId, userId);
PgUtil.deleteById("users", userId, okapiHeaders, vertx.getOrCreateContext(), ResponseWith422.class, asyncAssertSuccess(testContext, 422, response -> {
Errors errors = (Errors) response.result().getEntity();
assertThat(errors.getErrors(), hasSize(1));
Error error = errors.getErrors().get(0);
assertThat(error.getMessage(), containsString("Cannot delete users.id = " + userId + " because id is still referenced from table referencing"));
assertThat(error.getParameters(), hasSize(1));
assertThat(error.getParameters().get(0).getKey(), is("users.id"));
assertThat(error.getParameters().get(0).getValue(), is(userId));
}));
}
use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.
the class ValidationHelper method createValidationErrorMessage.
public static Errors createValidationErrorMessage(String field, String value, String message) {
Errors e = new Errors();
Error error = new Error();
Parameter p = new Parameter();
p.setKey(field);
p.setValue(value);
error.getParameters().add(p);
error.setMessage(message);
error.setCode("-1");
error.setType(DomainModelConsts.VALIDATION_FIELD_ERROR);
List<Error> l = new ArrayList<>();
l.add(error);
e.setErrors(l);
return e;
}
Aggregations