-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fine grained exceptions for known commit error situations
To allow better error messages in UI. Note: most of these shouldn't actually be possible in replace or combine APIs, because the staging frames would run into these constraints already when being created in Hastus import. In addition there are lots of plain DB constraints, from simple value checks to foreign key constraints etc, but I don't see it as beneficial to add custom exceptions for all of these. Can always add these if users actually encounter them.
- Loading branch information
Showing
6 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/test/kotlin/fi/hsl/jore4/timetables/api/util/TransactionSystemExtensionsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package fi.hsl.jore4.timetables.api.util | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.springframework.transaction.TransactionSystemException | ||
import kotlin.test.assertEquals | ||
|
||
class TransactionSystemExtensionsTest { | ||
|
||
private fun createTransactionSystemExceptionWithCause(message: String): TransactionSystemException { | ||
return TransactionSystemException("test exception", Exception(message)) | ||
} | ||
|
||
@Test | ||
fun `resolves PassingTimeStopPointMatchingOrderError`() { | ||
val exception = TransactionSystemExtensions.from( | ||
createTransactionSystemExceptionWithCause( | ||
""" | ||
ERROR: passing times and their matching stop points must be in same order | ||
Where: PL/pgSQL function passing_times.validate_passing_time_sequences() | ||
""".trimIndent() | ||
) | ||
) | ||
assertEquals(exception.type, HasuraErrorType.PassingTimeStopPointMatchingOrderError) | ||
} | ||
|
||
@Test | ||
fun `resolves PassingTimeFirstArrivalTimeError`() { | ||
val exception = TransactionSystemExtensions.from( | ||
createTransactionSystemExceptionWithCause( | ||
""" | ||
ERROR: first passing time must not have arrival_time set | ||
Where: PL/pgSQL function passing_times.validate_passing_time_sequences() | ||
""".trimIndent() | ||
) | ||
) | ||
assertEquals(exception.type, HasuraErrorType.PassingTimeFirstArrivalTimeError) | ||
} | ||
|
||
@Test | ||
fun `resolves PassingTimeLastDepartureTimeError`() { | ||
val exception = TransactionSystemExtensions.from( | ||
createTransactionSystemExceptionWithCause( | ||
""" | ||
ERROR: last passing time must not have departure_time set | ||
Where: PL/pgSQL function passing_times.validate_passing_time_sequences() | ||
""".trimIndent() | ||
) | ||
) | ||
assertEquals(exception.type, HasuraErrorType.PassingTimeLastDepartureTimeError) | ||
} | ||
|
||
@Test | ||
fun `resolves PassingTimeNullError`() { | ||
val exception = TransactionSystemExtensions.from( | ||
createTransactionSystemExceptionWithCause( | ||
""" | ||
ERROR: all passing time that are not first or last in the sequence must have both departure and arrival time defined | ||
Where: PL/pgSQL function passing_times.validate_passing_time_sequences() | ||
""".trimIndent() | ||
) | ||
) | ||
assertEquals(exception.type, HasuraErrorType.PassingTimeNullError) | ||
} | ||
|
||
@Test | ||
fun `resolves PassingTimesMixedJourneyPatternRefsError`() { | ||
val exception = TransactionSystemExtensions.from( | ||
createTransactionSystemExceptionWithCause( | ||
""" | ||
ERROR: inconsistent journey_pattern_ref within vehicle journey, all timetabled_passing_times must reference same journey_pattern_ref as the vehicle_journey | ||
Where: PL/pgSQL function passing_times.validate_passing_time_sequences() | ||
""".trimIndent() | ||
) | ||
) | ||
assertEquals(exception.type, HasuraErrorType.PassingTimesMixedJourneyPatternRefsError) | ||
} | ||
|
||
@Test | ||
fun `resolves ConflictingSchedulesError`() { | ||
val exception = TransactionSystemExtensions.from( | ||
createTransactionSystemExceptionWithCause( | ||
""" | ||
ERROR: conflicting schedules detected: vehicle schedule frame | ||
Where: PL/pgSQL function vehicle_schedule.validate_queued_schedules_uniqueness() | ||
""".trimIndent() | ||
) | ||
) | ||
assertEquals(exception.type, HasuraErrorType.ConflictingSchedulesError) | ||
} | ||
|
||
@Test | ||
fun `resolves SequentialIntegrityError`() { | ||
val exception = TransactionSystemExtensions.from( | ||
createTransactionSystemExceptionWithCause( | ||
""" | ||
ERROR: Sequential integrity issues detected: | ||
Where: PL/pgSQL function vehicle_service.validate_service_sequential_integrity() | ||
""".trimIndent() | ||
) | ||
) | ||
assertEquals(exception.type, HasuraErrorType.SequentialIntegrityError) | ||
} | ||
|
||
@Test | ||
fun `resolves an unknown error as TransactionSystemError`() { | ||
val exception = TransactionSystemExtensions.from( | ||
createTransactionSystemExceptionWithCause( | ||
""" | ||
ERROR: something else: | ||
Where: PL/pgSQL function somewhere_else() | ||
""".trimIndent() | ||
) | ||
) | ||
assertEquals(exception.type, HasuraErrorType.TransactionSystemError) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters