use of org.postgresql.util.PSQLException 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.postgresql.util.PSQLException 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'.");
}
use of org.postgresql.util.PSQLException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateUniqueKeyViolationBadMessage.
@Test(expectedExceptions = RuntimeException.class)
public void translateUniqueKeyViolationBadMessage() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("23505");
when(serverErrorMessage.getTable()).thenReturn("mytable");
when(serverErrorMessage.getDetail()).thenReturn("xxxyyyyzzz");
// noinspection ThrowableResultOfMethodCallIgnored
postgreSqlExceptionTranslator.translateUniqueKeyViolation(new PSQLException(serverErrorMessage));
}
use of org.postgresql.util.PSQLException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateNotNullViolationBadMessage.
@Test(expectedExceptions = RuntimeException.class)
public void translateNotNullViolationBadMessage() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("23502");
when(serverErrorMessage.getTable()).thenReturn("mytable");
when(serverErrorMessage.getMessage()).thenReturn("xxxyyyzzzz");
// noinspection ThrowableResultOfMethodCallIgnored
postgreSqlExceptionTranslator.translateNotNullViolation(new PSQLException(serverErrorMessage));
}
use of org.postgresql.util.PSQLException in project molgenis by molgenis.
the class PostgreSqlExceptionTranslatorTest method translateInvalidIntegerExceptionInteger.
@Test
public void translateInvalidIntegerExceptionInteger() {
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getMessage()).thenReturn("invalid input syntax for integer: \"str1\"");
// noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = PostgreSqlExceptionTranslator.translateInvalidIntegerException(new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Value [str1] of this entity attribute is not of type [INT or LONG].");
}
Aggregations