Search in sources :

Example 21 with PSQLException

use of org.postgresql.util.PSQLException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslatorTest method translateNotNullViolationNoDoubleQuotes.

@Test
public void translateNotNullViolationNoDoubleQuotes() {
    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.");
}
Also used : ServerErrorMessage(org.postgresql.util.ServerErrorMessage) PSQLException(org.postgresql.util.PSQLException) MolgenisValidationException(org.molgenis.data.validation.MolgenisValidationException) Test(org.testng.annotations.Test)

Example 22 with PSQLException

use of org.postgresql.util.PSQLException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslatorTest method translateForeignKeyViolationBadMessage.

@Test(expectedExceptions = RuntimeException.class)
public void translateForeignKeyViolationBadMessage() {
    ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
    when(serverErrorMessage.getSQLState()).thenReturn("23503");
    when(serverErrorMessage.getTable()).thenReturn("mytable");
    when(serverErrorMessage.getDetail()).thenReturn("xxxyyyyzzzz");
    // noinspection ThrowableResultOfMethodCallIgnored
    postgreSqlExceptionTranslator.translateForeignKeyViolation(new PSQLException(serverErrorMessage));
}
Also used : ServerErrorMessage(org.postgresql.util.ServerErrorMessage) PSQLException(org.postgresql.util.PSQLException) Test(org.testng.annotations.Test)

Example 23 with PSQLException

use of org.postgresql.util.PSQLException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslatorTest method translateForeignKeyViolationNotPresent.

@Test
public void translateForeignKeyViolationNotPresent() {
    ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
    when(serverErrorMessage.getSQLState()).thenReturn("23503");
    when(serverErrorMessage.getTable()).thenReturn("myTable");
    when(serverErrorMessage.getDetail()).thenReturn("Key (myColumn)=(myValue) is not present in table \"myTable\"");
    // noinspection ThrowableResultOfMethodCallIgnored
    MolgenisValidationException e = postgreSqlExceptionTranslator.translateForeignKeyViolation(new PSQLException(serverErrorMessage));
    assertEquals(e.getMessage(), "Unknown xref value 'myValue' for attribute 'myAttr' of entity 'myEntity'.");
}
Also used : ServerErrorMessage(org.postgresql.util.ServerErrorMessage) PSQLException(org.postgresql.util.PSQLException) MolgenisValidationException(org.molgenis.data.validation.MolgenisValidationException) Test(org.testng.annotations.Test)

Example 24 with PSQLException

use of org.postgresql.util.PSQLException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslatorTest method translateUniqueKeyViolation.

@Test
public void translateUniqueKeyViolation() {
    ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
    when(serverErrorMessage.getSQLState()).thenReturn("23505");
    when(serverErrorMessage.getTable()).thenReturn("myTable");
    when(serverErrorMessage.getDetail()).thenReturn("Key (myColumn)=(myValue) already exists.");
    // noinspection ThrowableResultOfMethodCallIgnored
    MolgenisValidationException e = postgreSqlExceptionTranslator.translateUniqueKeyViolation(new PSQLException(serverErrorMessage));
    assertEquals(e.getMessage(), "Duplicate value 'myValue' for unique attribute 'myAttr' from entity 'myEntity'.");
}
Also used : ServerErrorMessage(org.postgresql.util.ServerErrorMessage) PSQLException(org.postgresql.util.PSQLException) MolgenisValidationException(org.molgenis.data.validation.MolgenisValidationException) Test(org.testng.annotations.Test)

Example 25 with PSQLException

use of org.postgresql.util.PSQLException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslatorTest method translateCheckConstraintViolation.

@Test
public void translateCheckConstraintViolation() {
    ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
    when(serverErrorMessage.getTable()).thenReturn("myTable");
    when(serverErrorMessage.getConstraint()).thenReturn("myTable_myColumn_chk");
    // noinspection ThrowableResultOfMethodCallIgnored
    MolgenisValidationException e = postgreSqlExceptionTranslator.translateCheckConstraintViolation(new PSQLException(serverErrorMessage));
    assertEquals(e.getMessage(), "Unknown enum value for attribute 'myAttr' of entity 'myEntity'.");
}
Also used : ServerErrorMessage(org.postgresql.util.ServerErrorMessage) PSQLException(org.postgresql.util.PSQLException) MolgenisValidationException(org.molgenis.data.validation.MolgenisValidationException) Test(org.testng.annotations.Test)

Aggregations

PSQLException (org.postgresql.util.PSQLException)36 ServerErrorMessage (org.postgresql.util.ServerErrorMessage)28 Test (org.testng.annotations.Test)26 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)24 SQLException (java.sql.SQLException)3 MolgenisDataException (org.molgenis.data.MolgenisDataException)3 BatchUpdateException (java.sql.BatchUpdateException)2 PGExceptionSorter (com.alibaba.druid.pool.vendor.PGExceptionSorter)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 ConnectException (java.net.ConnectException)1 ByteBuffer (java.nio.ByteBuffer)1 PreparedStatement (java.sql.PreparedStatement)1 SQLWarning (java.sql.SQLWarning)1 ArrayList (java.util.ArrayList)1 Collections.singleton (java.util.Collections.singleton)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1