use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateUndefinedColumnException.
@Test
public void translateUndefinedColumnException() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("42703");
when(serverErrorMessage.getMessage()).thenReturn("Undefined column: 7 ERROR: column \"test\" does not exist");
// noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = PostgreSqlExceptionTranslator.translateUndefinedColumnException(new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Undefined column: 7 ERROR: column \"test\" does not exist");
}
use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateInvalidIntegerExceptionDouble.
@Test
public void translateInvalidIntegerExceptionDouble() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getMessage()).thenReturn("invalid input syntax for type double precision: \"str1\"");
// noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = PostgreSqlExceptionTranslator.translateInvalidIntegerException(new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Value [str1] of this entity attribute is not of type [DECIMAL].");
}
use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateDependentObjectsStillExistNoDoubleQuotes.
@Test
public void translateDependentObjectsStillExistNoDoubleQuotes() {
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");
// noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateDependentObjectsStillExist(new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Cannot delete entity 'myRefEntity' because entity 'myEntity' depends on it.");
}
use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateUniqueKeyViolationKeyIsDuplicated.
@Test
public void translateUniqueKeyViolationKeyIsDuplicated() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("23505");
when(serverErrorMessage.getTable()).thenReturn("myTable");
when(serverErrorMessage.getDetail()).thenReturn("Key (myColumn)=(myValue) is duplicated.");
// noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateUniqueKeyViolation(new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "The attribute 'myAttr' of entity 'myEntity' contains duplicate value 'myValue'.");
}
use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateForeignKeyViolationStillReferenced.
@Test
public void translateForeignKeyViolationStillReferenced() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("23503");
when(serverErrorMessage.getTable()).thenReturn("myTable");
when(serverErrorMessage.getMessage()).thenReturn("update or delete on table \"myDependentTable\" violates foreign key constraint \"myTable_myAttr_fkey\" on table \"myTable\"");
when(serverErrorMessage.getDetail()).thenReturn("Key (myColumn)=(myValue) is still referenced from table \"myTable\"");
// noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateForeignKeyViolation(new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Value 'myValue' for attribute 'myAttr' is referenced by entity 'myEntity'.");
}
Aggregations