Skip to content

Commit 6a2ccfa

Browse files
committed
Rename exception classes related to import feature.
1 parent fb16295 commit 6a2ccfa

6 files changed

Lines changed: 19 additions & 11 deletions

File tree

src/main/kotlin/fi/hsl/jore4/hastus/service/importing/UnmatchedRoutesWithinImportException.kt renamed to src/main/kotlin/fi/hsl/jore4/hastus/service/importing/CannotFindJourneyPatternRefByRouteLabelAndDirectionException.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import fi.hsl.jore4.hastus.data.format.RouteLabelAndDirection
44
import org.springframework.http.HttpStatus
55
import org.springframework.web.server.ResponseStatusException
66

7-
class UnmatchedRoutesWithinImportException(routeIdentifiers: List<RouteLabelAndDirection>) : ResponseStatusException(
7+
class CannotFindJourneyPatternRefByRouteLabelAndDirectionException(
8+
routeIdentifiers: List<RouteLabelAndDirection>
9+
) : ResponseStatusException(
810
HttpStatus.BAD_REQUEST,
911
"Could not find journey pattern reference for Hastus trips with the following route labels and directions: ${
1012
routeIdentifiers.joinToString(separator = ",")

src/main/kotlin/fi/hsl/jore4/hastus/service/importing/NoJourneyPatternRefMatchesHastusTripStopsException.kt renamed to src/main/kotlin/fi/hsl/jore4/hastus/service/importing/CannotFindJourneyPatternRefByStopLabelsAndTimingPointLabelsException.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import fi.hsl.jore4.hastus.service.exporting.ConversionsToHastus
55
import org.springframework.http.HttpStatus
66
import org.springframework.web.server.ResponseStatusException
77

8-
class NoJourneyPatternRefMatchesHastusTripStopsException(message: String) : ResponseStatusException(
8+
class CannotFindJourneyPatternRefByStopLabelsAndTimingPointLabelsException(
9+
message: String
10+
) : ResponseStatusException(
911
HttpStatus.BAD_REQUEST,
1012
message
1113
) {
14+
1215
constructor(
1316
routeIdentifier: RouteLabelAndDirection,
1417
stopLabels: List<String>,

src/main/kotlin/fi/hsl/jore4/hastus/service/importing/ConversionsFromHastus.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ object ConversionsFromHastus {
178178
// Should never happen during application runtime because journeyPatternRefIndex is
179179
// expected to be complete at this point. Possible failures should have occurred
180180
// earlier in the processing chain. Hence, logging as an error.
181-
val exception = UnmatchedRoutesWithinImportException(listOf(routeLabelAndDirection))
181+
val exception =
182+
CannotFindJourneyPatternRefByRouteLabelAndDirectionException(listOf(routeLabelAndDirection))
182183
LOGGER.error(exception.message)
183184
throw exception
184185
}
@@ -200,7 +201,7 @@ object ConversionsFromHastus {
200201
unknownStopLabels.joinToString(prefix = "'", separator = ",", postfix = "'")
201202
}"
202203
LOGGER.error(errorMessage)
203-
throw NoJourneyPatternRefMatchesHastusTripStopsException(errorMessage)
204+
throw CannotFindJourneyPatternRefByStopLabelsAndTimingPointLabelsException(errorMessage)
204205
}
205206
}
206207

src/main/kotlin/fi/hsl/jore4/hastus/service/importing/ImportService.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class ImportService(private val graphQLServiceFactory: GraphQLServiceFactory) {
129129
joreStopLabels == hastusStopLabels && joreTimingPlaceLabels == hastusTimingPlaceLabels
130130
}
131131
?: run {
132-
val exception = NoJourneyPatternRefMatchesHastusTripStopsException(
132+
val exception = CannotFindJourneyPatternRefByStopLabelsAndTimingPointLabelsException(
133133
hastusRouteLabelAndDirection,
134134
hastusStopLabels,
135135
hastusTimingPlaceLabels
@@ -153,7 +153,9 @@ class ImportService(private val graphQLServiceFactory: GraphQLServiceFactory) {
153153
.sorted()
154154

155155
if (missingRouteLabelsAndDirections.isNotEmpty()) {
156-
val exception = UnmatchedRoutesWithinImportException(missingRouteLabelsAndDirections)
156+
val exception = CannotFindJourneyPatternRefByRouteLabelAndDirectionException(
157+
missingRouteLabelsAndDirections
158+
)
157159
LOGGER.warn(exception.message)
158160
throw exception
159161
}

src/test/kotlin/fi/hsl/jore4/hastus/api/ImportControllerTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import fi.hsl.jore4.hastus.Constants.MIME_TYPE_CSV
55
import fi.hsl.jore4.hastus.data.format.JoreRouteDirection
66
import fi.hsl.jore4.hastus.data.format.RouteLabelAndDirection
77
import fi.hsl.jore4.hastus.graphql.converter.GraphQLAuthenticationFailedException
8+
import fi.hsl.jore4.hastus.service.importing.CannotFindJourneyPatternRefByRouteLabelAndDirectionException
9+
import fi.hsl.jore4.hastus.service.importing.CannotFindJourneyPatternRefByStopLabelsAndTimingPointLabelsException
810
import fi.hsl.jore4.hastus.service.importing.ImportService
911
import fi.hsl.jore4.hastus.service.importing.InvalidHastusDataException
10-
import fi.hsl.jore4.hastus.service.importing.NoJourneyPatternRefMatchesHastusTripStopsException
11-
import fi.hsl.jore4.hastus.service.importing.UnmatchedRoutesWithinImportException
1212
import io.mockk.every
1313
import io.mockk.junit5.MockKExtension
1414
import io.mockk.verify
@@ -106,7 +106,7 @@ class ImportControllerTest @Autowired constructor(
106106
fun `returns 400 when there are unmatched routes in Hastus data`() {
107107
every {
108108
importService.importTimetablesFromCsv(any(), any())
109-
} throws UnmatchedRoutesWithinImportException(
109+
} throws CannotFindJourneyPatternRefByRouteLabelAndDirectionException(
110110
listOf(
111111
RouteLabelAndDirection("123", JoreRouteDirection.OUTBOUND),
112112
RouteLabelAndDirection("456", JoreRouteDirection.INBOUND)
@@ -131,7 +131,7 @@ class ImportControllerTest @Autowired constructor(
131131
fun `returns 400 when no journey pattern reference matches any trip record in Hastus data`() {
132132
every {
133133
importService.importTimetablesFromCsv(any(), any())
134-
} throws NoJourneyPatternRefMatchesHastusTripStopsException(
134+
} throws CannotFindJourneyPatternRefByStopLabelsAndTimingPointLabelsException(
135135
RouteLabelAndDirection("123", JoreRouteDirection.OUTBOUND),
136136
listOf("H1000", "H1001", "H1002"),
137137
listOf("1PLACE", null, "2PLACE")

src/test/kotlin/fi/hsl/jore4/hastus/service/importing/ConversionsFromHastusTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class ConversionsFromHastusTest {
260260
generateTripStopRecord("trip1", "stop3", "0530", "T", "")
261261
)
262262

263-
val exception = assertFailsWith<NoJourneyPatternRefMatchesHastusTripStopsException> {
263+
val exception = assertFailsWith<CannotFindJourneyPatternRefByStopLabelsAndTimingPointLabelsException> {
264264
ConversionsFromHastus.convertHastusDataToJore(
265265
hastusData,
266266
vehicleTypeIndex,

0 commit comments

Comments
 (0)