use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateForeignKeyViolation.
@Test
public void translateForeignKeyViolation() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("23503");
when(serverErrorMessage.getTable()).thenReturn("myTable");
when(serverErrorMessage.getDetail()).thenReturn("... (myColumn) ... (myValue) ...");
// noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateForeignKeyViolation(new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Unknown xref value 'myValue' for attribute 'myAttr' of entity 'myEntity'.");
}
use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateReadonlyViolation.
@Test
public void translateReadonlyViolation() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getMessage()).thenReturn("Updating read-only column \"myColumn\" of table \"myTable\" with id [abc] is not allowed");
// noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateReadonlyViolation(new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Updating read-only attribute 'myAttr' of entity 'myEntity' with id 'abc' is not allowed.");
}
use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateNotNullViolation.
@Test
public void translateNotNullViolation() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("23502");
when(serverErrorMessage.getTable()).thenReturn("myTable");
when(serverErrorMessage.getMessage()).thenReturn("null value in column \"myColumn\" violates not-null constraint");
// noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateNotNullViolation(new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "The attribute 'myAttr' of entity 'myEntity' can not be null.");
}
use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateInvalidIntegerExceptionDate.
@Test
public void translateInvalidIntegerExceptionDate() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getMessage()).thenReturn("invalid input syntax for type date: \"str1\"");
// noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = PostgreSqlExceptionTranslator.translateInvalidIntegerException(new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Value [str1] of this entity attribute is not of type [DATE].");
}
use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateDependentObjectsStillExistOneDependentTableMultipleDependencies.
@Test
public void translateDependentObjectsStillExistOneDependentTableMultipleDependencies() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("2BP01");
when(serverErrorMessage.getDetail()).thenReturn("constraint my_foreign_key_constraint on table \"myTable\" depends on table \"myDependentTable\"\nconstraint myOther_foreign_key_constraint on table \"myTable\" depends on table \"myDependentTable\"");
// noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateDependentObjectsStillExist(new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Cannot delete entity 'myRefEntity' because entity 'myEntity' depends on it.");
}
Aggregations