Search in sources :

Example 36 with MolgenisValidationException

use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslatorTest method translateValueTooLongViolation.

@Test
public void translateValueTooLongViolation() {
    ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
    when(serverErrorMessage.getMessage()).thenReturn("ERROR: value too long for type character varying(255)");
    // noinspection ThrowableResultOfMethodCallIgnored
    MolgenisValidationException e = postgreSqlExceptionTranslator.translateValueTooLongViolation();
    assertEquals(e.getMessage(), "One of the values being added is too long.");
}
Also used : ServerErrorMessage(org.postgresql.util.ServerErrorMessage) MolgenisValidationException(org.molgenis.data.validation.MolgenisValidationException) Test(org.testng.annotations.Test)

Example 37 with MolgenisValidationException

use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslatorTest method translateUniqueKeyViolationDoubleQuotes.

@Test
public void translateUniqueKeyViolationDoubleQuotes() {
    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 38 with MolgenisValidationException

use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslatorTest method translateDependentObjectsStillExistMultipleDependentTables.

@Test
public void translateDependentObjectsStillExistMultipleDependentTables() {
    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 \"myOtherDependentTable\"");
    // noinspection ThrowableResultOfMethodCallIgnored
    MolgenisValidationException e = postgreSqlExceptionTranslator.translateDependentObjectsStillExist(new PSQLException(serverErrorMessage));
    assertEquals(e.getMessage(), "Cannot delete entity 'myRefEntity' because entity 'myEntity' depends on it..Cannot delete entity 'myOtherRefEntity' because entity 'myEntity' depends on it.");
}
Also used : ServerErrorMessage(org.postgresql.util.ServerErrorMessage) PSQLException(org.postgresql.util.PSQLException) MolgenisValidationException(org.molgenis.data.validation.MolgenisValidationException) Test(org.testng.annotations.Test)

Example 39 with MolgenisValidationException

use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslatorTest method translateReadonlyViolationNoDoubleQuotes.

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

Example 40 with MolgenisValidationException

use of org.molgenis.data.validation.MolgenisValidationException in project molgenis by molgenis.

the class PostgreSqlExceptionTranslatorTest method translateDependentObjectsStillExistOneDependentTableSingleDependency.

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

Aggregations

MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)43 ServerErrorMessage (org.postgresql.util.ServerErrorMessage)31 Test (org.testng.annotations.Test)25 PSQLException (org.postgresql.util.PSQLException)24 ConstraintViolation (org.molgenis.data.validation.ConstraintViolation)19 Matcher (java.util.regex.Matcher)6 Attribute (org.molgenis.data.meta.model.Attribute)4 String.format (java.lang.String.format)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 MolgenisDataException (org.molgenis.data.MolgenisDataException)2 RepositoryCollection (org.molgenis.data.RepositoryCollection)2 AttributeType (org.molgenis.data.meta.AttributeType)2 EntityType (org.molgenis.data.meta.model.EntityType)2 EntityTypeDescription (org.molgenis.data.postgresql.identifier.EntityTypeDescription)2 Component (org.springframework.stereotype.Component)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Multimap (com.google.common.collect.Multimap)1 File (java.io.File)1