@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 xxx depends on table yyy"); //noinspection ThrowableResultOfMethodCallIgnored MolgenisValidationException e = PostgreSqlExceptionTranslator.translateDependentObjectsStillExist( new PSQLException(serverErrorMessage)); assertEquals(e.getMessage(), "Cannot delete entity 'xxx' because entity 'yyy' depends on it."); }
@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 'myTable' because entities 'myDependentTable, myOtherDependentTable' depend on it."); }