From 8348ce0052c85d1f6a52ceed5d4eaf1b63e0e6c8 Mon Sep 17 00:00:00 2001 From: Vincent Paturet Date: Thu, 2 Jan 2025 15:14:38 +0100 Subject: [PATCH] Update rules documentation --- README.md | 283 ++++++------ .../DefaultValidationConfigLoader.java | 6 +- .../DefaultValidationEntryFactory.java | 26 ++ .../validator/NetexValidatorsRunner.java | 28 +- .../ValidationReportEntryFactory.java | 22 +- .../id/NetexIdUniquenessValidator.java | 2 +- .../id/VersionOnLocalNetexIdValidator.java | 2 +- .../ValidateAllowedTransportModeOnLine.java | 2 +- src/main/resources/configuration.default.yaml | 433 ------------------ .../DefaultValidationConfigLoaderTest.java | 7 +- .../DefaultValidationEntryFactoryTest.java | 62 ++- .../validator/NetexValidatorsRunnerTest.java | 8 + .../validator/demo/AllValidatorsDemo.java | 49 ++ 13 files changed, 337 insertions(+), 593 deletions(-) delete mode 100644 src/main/resources/configuration.default.yaml create mode 100644 src/test/java/org/entur/netex/validation/validator/demo/AllValidatorsDemo.java diff --git a/README.md b/README.md index 7283cb6d..99ee11f9 100644 --- a/README.md +++ b/README.md @@ -104,140 +104,149 @@ ValidationReport validationReport = netexValidatorsRunner.validate(codespace, re # Default rule set The NeTEx validator library comes with the following rule set by default: -| Sr. | Rule Code | Rule Description | -|-----|------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------:| -| 1 | AUTHORITY_1 | Missing CompanyNumber element on Authority | -| 2 | AUTHORITY_2 | Missing Name element on Authority | -| 3 | AUTHORITY_3 | Missing LegalName element on Authority | -| 4 | AUTHORITY_4 | Missing ContactDetails on Authority | -| 5 | AUTHORITY_5 | The Url must be defined for ContactDetails on Authority and it must start with 'http://' or 'https://' | -| 6 | BLOCK_1 | At least one Block or TrainBlock required in VehicleScheduleFrame | -| 7 | BLOCK_2 | At least one Journey must be defined for Block | -| 8 | BLOCK_3 | At least one DayType must be defined for Block | -| 9 | BOOKING_1 | Illegal value for BookingAccess | -| 10 | BOOKING_2 | Illegal value for BookingMethod | -| 11 | BOOKING_3 | Illegal value for BookWhen | -| 12 | BOOKING_4 | Mandatory booking property BookingContact not specified on FlexibleServiceProperties, FlexibleLine or on all StopPointInJourneyPatterns | -| 13 | BOOKING_4 | Mandatory booking property BookingMethods not specified on FlexibleServiceProperties, FlexibleLine or on all StopPointInJourneyPatterns | -| 14 | BOOKING_5 | Either BookWhen or MinimumBookingPeriod should be specified on FlexibleServiceProperties, FlexibleLine or on all StopPointInJourneyPatterns | -| 15 | BUY_WHEN_1 | Illegal value for BuyWhen | -| 16 | COMPOSITE_FRAME_1 | A CompositeFrame must define a ValidityCondition valid for all data within the CompositeFrame | -| 17 | COMPOSITE_FRAME_2 | ValidityConditions defined inside a frame inside a CompositeFrame | -| 18 | COMPOSITE_FRAME_3 | ValidBetween missing either or both of FromDate/ToDate | -| 19 | COMPOSITE_FRAME_4 | FromDate cannot be after ToDate on ValidBetween | -| 20 | COMPOSITE_FRAME_4 | AvailabilityCondition must have either FromDate or ToDate or both present | -| 21 | COMPOSITE_FRAME_5 | FromDate cannot be after ToDate on AvailabilityCondition | -| 22 | COMPOSITE_SITE_FRAME_IN_COMMON_FILE | Unexpected element SiteFrame. It will be ignored | -| 23 | COMPOSITE_TIMETABLE_FRAME_IN_COMMON_FILE | Timetable frame not allowed in common files | -| 24 | DATED_SERVICE_JOURNEY_1 | Missing OperatingDayRef on DatedServiceJourney | -| 25 | DATED_SERVICE_JOURNEY_2 | Missing ServiceJourneyRef on DatedServiceJourney | -| 26 | DATED_SERVICE_JOURNEY_3 | Multiple ServiceJourneyRef on DatedServiceJourney | -| 27 | DATED_SERVICE_JOURNEY_4 | DatedServiceJourney is repeated with a different version | -| 28 | DATED_SERVICE_JOURNEY_5 | Multiple references from a DatedServiceJourney to the same DatedServiceJourney | -| 29 | DEAD_RUN_1 | The Dead run does not reference passing times | -| 30 | DEAD_RUN_2 | The Dead run does not reference a journey pattern | -| 31 | DEAD_RUN_3 | The Dead run does not reference day types | -| 32 | DESTINATION_DISPLAY_1 | Missing FrontText on DestinationDisplay | -| 33 | DESTINATION_DISPLAY_2 | Missing DestinationDisplayRef on Via | -| 34 | FLEXIBLE_LINE_1 | Missing FlexibleLineType on FlexibleLine | -| 35 | FLEXIBLE_LINE_10 | Only one of BookWhen or MinimumBookingPeriod should be specified on FlexibleLine | -| 36 | FLEXIBLE_LINE_11 | BookWhen must be used together with LatestBookingTime on FlexibleLine | -| 37 | FLEXIBLE_LINE_8 | Illegal FlexibleLineType on FlexibleLine | -| 38 | FLEXIBLE_LINE_9 | Illegal FlexibleServiceType on ServiceJourney | -| 39 | FLEXIBLE_SERVICE_1 | Missing id on FlexibleServiceProperties | -| 40 | FLEXIBLE_SERVICE_2 | Missing version on FlexibleServiceProperties | -| 41 | FLEXIBLE_SERVICE_3 | Only one of BookWhen or MinimumBookingPeriod should be specified on FlexibleServiceProperties | -| 42 | FLEXIBLE_SERVICE_4 | BookWhen must be used together with LatestBookingTime on FlexibleServiceProperties | -| 43 | INTERCHANGE_1 | The 'Planned' and 'Advertised' properties of an Interchange should not be specified | -| 44 | INTERCHANGE_2 | Guaranteed Interchange should not have a maximum wait time value of zero | -| 45 | INTERCHANGE_3 | The maximum waiting time after planned departure for the interchange consumer journey (MaximumWaitTime) should not be longer than one hour | -| 46 | JOURNEY_PATTERN_1 | ServiceJourneyPattern not allowed | -| 47 | JOURNEY_PATTERN_2 | No JourneyPattern defined in the Service Frame | -| 48 | JOURNEY_PATTERN_3 | Missing RouteRef on JourneyPattern | -| 49 | JOURNEY_PATTERN_4 | Missing DestinationDisplayRef on first StopPointInJourneyPattern | -| 50 | JOURNEY_PATTERN_5 | DestinationDisplayRef not allowed on last StopPointInJourneyPattern | -| 51 | JOURNEY_PATTERN_6 | StopPointInJourneyPattern neither allows boarding nor alighting | -| 52 | JOURNEY_PATTERN_7 | StopPointInJourneyPattern declares reference to the same DestinationDisplay as previous StopPointInJourneyPattern | -| 53 | JOURNEY_PATTERN_8 | Only one of BookWhen or MinimumBookingPeriod should be specified on StopPointInJourneyPattern | -| 54 | JOURNEY_PATTERN_9 | BookWhen must be used together with LatestBookingTime on StopPointInJourneyPattern | -| 55 | LINE_1 | There must be either Lines or Flexible Lines | -| 56 | LINE_2 | Missing Name on Line | -| 57 | LINE_3 | Missing PublicCode on Line | -| 58 | LINE_4 | Missing TransportMode on Line | -| 59 | LINE_5 | Missing TransportSubmode on Line | -| 60 | LINE_6 | Routes should not be defined within a Line or FlexibleLine | -| 61 | LINE_7 | A Line must refer to a GroupOfLines or a Network through element RepresentedByGroupRef | -| 62 | LINE_8 | Line colour should be encoded with 6 hexadecimal digits | -| 63 | LINE_9 | Line colour should be encoded with valid hexadecimal digits | -| 64 | NETWORK_1 | Missing AuthorityRef on Network | -| 65 | NETWORK_2 | Missing Name element on Network | -| 66 | NETWORK_3 | Missing Name element on GroupOfLines | -| 67 | NOTICE_1 | Missing element Text for Notice | -| 68 | NOTICE_2 | Missing or empty element Text for Notice Alternative Text | -| 69 | NOTICE_3 | Missing element Lang for Notice Alternative Text | -| 70 | NOTICE_4 | The Notice has two Alternative Texts with the same language | -| 71 | NOTICE_5 | The notice is assigned multiple times to the same object | -| 72 | NOTICE_6 | The notice assignment does not reference an object | -| 73 | NOTICE_7 | The notice assignment does not reference a notice | -| 74 | OPERATOR_1 | Missing CompanyNumber element on Operator | -| 75 | OPERATOR_2 | Missing Name on Operator | -| 76 | OPERATOR_3 | Missing LegalName element on Operator | -| 77 | OPERATOR_4 | Missing ContactDetails element on Operator | -| 78 | OPERATOR_5 | At least one of Url, Phone or Email must be defined for ContactDetails on Operator | -| 79 | OPERATOR_6 | Missing CustomerServiceContactDetails element on Operator | -| 80 | OPERATOR_7 | Missing Url element for CustomerServiceContactDetails on Operator | -| 81 | PASSENGER_STOP_ASSIGNMENT_1 | Missing ScheduledStopPointRef on PassengerStopAssignment | -| 82 | PASSENGER_STOP_ASSIGNMENT_2 | Missing QuayRef on PassengerStopAssignment | -| 83 | PASSENGER_STOP_ASSIGNMENT_3 | The same quay is assigned more than once in PassengerStopAssignments | -| 84 | RESOURCE_FRAME_IN_LINE_FILE | Exactly one ResourceFrame should be present | -| 85 | ROUTE_1 | There should be at least one Route | -| 86 | ROUTE_2 | Missing Name on Route | -| 87 | ROUTE_3 | Missing lineRef on Route | -| 88 | ROUTE_4 | Missing pointsInSequence on Route | -| 89 | ROUTE_5 | DirectionRef not allowed on Route (use DirectionType) | -| 90 | ROUTE_6 | Several points on route have the same order | -| 91 | SERVICE_CALENDAR_1 | The DayType is not assigned to any calendar dates or periods | -| 92 | SERVICE_CALENDAR_2 | ServiceCalendar does not contain neither DayTypes nor DayTypeAssignments | -| 93 | SERVICE_CALENDAR_3 | Missing ToDate on ServiceCalendar | -| 94 | SERVICE_CALENDAR_4 | Missing FromDate on ServiceCalendar | -| 95 | SERVICE_CALENDAR_5 | FromDate cannot be after ToDate on ServiceCalendar | -| 96 | SERVICE_FRAME_1 | Unexpected element groupsOfLines outside of Network | -| 97 | SERVICE_FRAME_2 | Unexpected element timingPoints. Content ignored | -| 98 | SERVICE_FRAME_3 | Missing Projection on RoutePoint | -| 99 | SERVICE_FRAME_IN_COMMON_FILE_1 | Line not allowed in common files | -| 100 | SERVICE_FRAME_IN_COMMON_FILE_2 | Route not allowed in common files | -| 101 | SERVICE_FRAME_IN_COMMON_FILE_3 | JourneyPattern not allowed in common files | -| 102 | SERVICE_JOURNEY_1 | There should be at least one ServiceJourney | -| 103 | SERVICE_JOURNEY_10 | The ServiceJourney does not refer to a JourneyPattern | -| 104 | SERVICE_JOURNEY_11 | If overriding Line TransportMode or TransportSubmode on a ServiceJourney, both elements must be present | -| 105 | SERVICE_JOURNEY_12 | Missing OperatorRef on ServiceJourney (not defined on Line) | -| 106 | SERVICE_JOURNEY_13 | The ServiceJourney does not refer to DayTypes nor DatedServiceJourneys | -| 107 | SERVICE_JOURNEY_14 | The ServiceJourney references both DayTypes and DatedServiceJourneys | -| 108 | SERVICE_JOURNEY_15 | ServiceJourney does not specify passing time for all StopPointInJourneyPattern | -| 109 | SERVICE_JOURNEY_16 | ServiceJourney is repeated with a different version | -| 110 | SERVICE_JOURNEY_2 | Element Call not allowed | -| 111 | SERVICE_JOURNEY_3 | The ServiceJourney does not specify any TimetabledPassingTimes | -| 112 | SERVICE_JOURNEY_4 | TimetabledPassingTime contains neither DepartureTime/EarliestDepartureTime nor ArrivalTime/LatestArrivalTime | -| 113 | SERVICE_JOURNEY_5 | All TimetabledPassingTime except last call must have DepartureTime | -| 114 | SERVICE_JOURNEY_6 | Last TimetabledPassingTime must have ArrivalTime | -| 115 | SERVICE_JOURNEY_7 | ArrivalTime is identical to DepartureTime | -| 116 | SERVICE_JOURNEY_8 | Missing id on TimetabledPassingTime | -| 117 | SERVICE_JOURNEY_9 | Missing version on TimetabledPassingTime | -| 118 | SERVICE_LINK_1 | Missing FromPointRef on ServiceLink | -| 119 | SERVICE_LINK_2 | Missing ToPointRef on ServiceLink | -| 120 | SERVICE_LINK_3 | Missing projections element on ServiceLink | -| 121 | SITE_FRAME_IN_COMMON_FILE | Unexpected element SiteFrame. It will be ignored | -| 122 | SITE_FRAME_IN_LINE_FILE | Unexpected element SiteFrame. It will be ignored | -| 123 | TIMETABLE_FRAME_IN_COMMON_FILE | Timetable frame not allowed in common files | -| 124 | TRANSPORT_MODE | Illegal TransportMode | -| 125 | TRANSPORT_SUB_MODE | Illegal TransportSubMode | -| 126 | VALIDITY_CONDITIONS_IN_COMMON_FILE_1 | Neither ServiceFrame nor ServiceCalendarFrame defines ValidityConditions | -| 127 | VALIDITY_CONDITIONS_IN_COMMON_FILE_2 | Multiple ResourceFrames without validity conditions | -| 128 | VALIDITY_CONDITIONS_IN_COMMON_FILE_3 | Multiple ServiceFrames without validity conditions | -| 129 | VALIDITY_CONDITIONS_IN_COMMON_FILE_4 | Multiple ServiceCalendarFrames without validity conditions | -| 130 | VALIDITY_CONDITIONS_IN_LINE_FILE_1 | Neither ServiceFrame, ServiceCalendarFrame nor TimetableFrame defines ValidityConditions | -| 131 | VALIDITY_CONDITIONS_IN_LINE_FILE_2 | Multiple frames of same type without validity conditions | -| 132 | VALIDITY_CONDITIONS_IN_LINE_FILE_3 | Multiple frames of same type without validity conditions | -| 133 | VALIDITY_CONDITIONS_IN_LINE_FILE_4 | Multiple frames of same type without validity conditions | -| 134 | VALIDITY_CONDITIONS_IN_LINE_FILE_5 | Multiple frames of same type without validity conditions | -| 135 | VERSION_NON_NUMERIC | Non-numeric NeTEx version | \ No newline at end of file +| Rule Code | Rule Description | +|------------------------------------------|:----------------------------------------------------------------------------------------:| +| AUTHORITY_1 | Authority missing CompanyNumber | +| AUTHORITY_2 | Authority missing Name | +| AUTHORITY_3 | Authority missing LegalName | +| AUTHORITY_4 | Authority missing ContactDetails | +| AUTHORITY_5 | Authority missing Url for ContactDetails | +| BLOCK_1 | Block missing VehicleScheduleFrame | +| BLOCK_2 | Block missing Journey | +| BLOCK_3 | Block missing DayType | +| BOOKING_1 | Booking illegal BookingAccess | +| BOOKING_2 | Booking illegal BookingMethod | +| BOOKING_3 | Booking illegal BookWhen | +| BOOKING_4 | Booking property | +| BOOKING_5 | Missing BookWhen or MinimumBookingPeriod | +| BUY_WHEN_1 | BuyWhen illegal value | +| COMPOSITE_FRAME_1 | CompositeFrame - missing ValidityCondition | +| COMPOSITE_FRAME_2 | CompositeFrame - invalid nested ValidityCondition | +| COMPOSITE_FRAME_3 | CompositeFrame - missing ValidBetween | +| COMPOSITE_FRAME_4 | CompositeFrame - invalid ValidBetween | +| COMPOSITE_FRAME_5 | CompositeFrame - invalid AvailabilityCondition | +| COMPOSITE_FRAME_6 | CompositeFrame - missing AvailabilityCondition | +| COMPOSITE_FRAME_SITE_FRAME | CompositeFrame - unexpected SiteFrame | +| COMPOSITE_TIMETABLE_FRAME_IN_COMMON_FILE | CompositeFrame - Illegal TimetableFrame in common file | +| DATED_SERVICE_JOURNEY_1 | DatedServiceJourney missing OperatingDayRef | +| DATED_SERVICE_JOURNEY_2 | DatedServiceJourney missing ServiceJourneyRef | +| DATED_SERVICE_JOURNEY_3 | DatedServiceJourney multiple ServiceJourneyRef | +| DATED_SERVICE_JOURNEY_4 | DatedServiceJourney multiple versions | +| DATED_SERVICE_JOURNEY_5 | DatedServiceJourney multiple references to the same DatedServiceJourney | +| DEAD_RUN_1 | DeadRun missing PassingTime references | +| DEAD_RUN_2 | DeadRun missing JourneyPattern references | +| DEAD_RUN_3 | DeadRun missing DayType references | +| DESTINATION_DISPLAY_1 | DestinationDisplay missing FrontText | +| DESTINATION_DISPLAY_2 | DestinationDisplay missing DestinationDisplayRef on Via | +| FLEXIBLE_LINE_1 | FlexibleLine missing FlexibleLineType | +| FLEXIBLE_LINE_10 | FlexibleLine illegal use of both BookWhen and MinimumBookingPeriod | +| FLEXIBLE_LINE_11 | FlexibleLine BookWhen without LatestBookingTime or LatestBookingTime without BookWhen | +| FLEXIBLE_LINE_8 | FlexibleLine illegal FlexibleLineType | +| FLEXIBLE_LINE_9 | FlexibleLine illegal FlexibleServiceType | +| FLEXIBLE_SERVICE_1 | FlexibleService missing Id on FlexibleServiceProperties | +| FLEXIBLE_SERVICE_2 | FlexibleService missing version on FlexibleServiceProperties | +| FLEXIBLE_SERVICE_3 | FlexibleService illegal use of both BookWhen and MinimumBookingPeriod | +| FLEXIBLE_SERVICE_4 | FlexibleService BookWhen without LatestBookingTime or LatestBookingTime without BookWhen | +| INTERCHANGE_1 | Interchange invalid properties | +| INTERCHANGE_2 | Interchange unexpected MaximumWaitTime | +| INTERCHANGE_3 | Interchange excessive MaximumWaitTime | +| JOURNEY_PATTERN_1 | JourneyPattern illegal element ServiceJourneyPattern | +| JOURNEY_PATTERN_2 | JourneyPattern missing JourneyPattern | +| JOURNEY_PATTERN_3 | JourneyPattern missing RouteRef | +| JOURNEY_PATTERN_4 | JourneyPattern missing DestinationDisplayRef on first stop point | +| JOURNEY_PATTERN_5 | JourneyPattern illegal DestinationDisplayRef on last stop point | +| JOURNEY_PATTERN_6 | JourneyPattern stop point without boarding or alighting | +| JOURNEY_PATTERN_7 | JourneyPattern illegal repetition of DestinationDisplay | +| JOURNEY_PATTERN_8 | JourneyPattern illegal use of both BookWhen and MinimumBookingPeriod | +| JOURNEY_PATTERN_9 | JourneyPattern BookWhen without LatestBookingTime or LatestBookingTime without BookWhen | +| LINE_1 | Line missing Line or FlexibleLine | +| LINE_2 | Line missing Name | +| LINE_3 | Line missing PublicCode | +| LINE_4 | Line missing TransportMode | +| LINE_5 | Line missing TransportSubmode | +| LINE_6 | Line with incorrect use of Route | +| LINE_7 | Line missing Network or GroupOfLines | +| LINE_8 | Invalid color coding length on Presentation | +| LINE_9 | Invalid color coding value on Presentation | +| NETEX_ID_1 | NeTEx ID duplicated across files | +| NETEX_ID_10 | Duplicate NeTEx ID across common files | +| NETEX_ID_5 | NeTEx ID unresolved reference | +| NETEX_ID_6 | NeTEx ID reference to invalid element | +| NETEX_ID_7 | NeTEx ID invalid value | +| NETEX_ID_8 | NeTEx ID missing version on elements | +| NETEX_ID_9 | NeTEx ID missing version on reference | +| NETWORK_1 | Network missing AuthorityRef | +| NETWORK_2 | Network missing Name on Network | +| NETWORK_3 | Network missing Name on GroupOfLines | +| NOTICE_1 | Notice missing Text | +| NOTICE_2 | Notice missing Text with alternative text | +| NOTICE_3 | Notice missing language with alternative text | +| NOTICE_4 | Notice duplicated alternative texts | +| NOTICE_5 | Notice duplicated assignment | +| NOTICE_6 | Notice assignment missing reference to noticed object | +| NOTICE_7 | Notice assignment missing reference to notice | +| OPERATOR_1 | Operator missing CompanyNumber | +| OPERATOR_2 | Operator missing Name | +| OPERATOR_3 | Operator missing LegalName | +| OPERATOR_4 | Operator missing ContactDetails | +| OPERATOR_5 | Operator missing Url for ContactDetails | +| OPERATOR_6 | Operator missing CustomerServiceContactDetails | +| OPERATOR_7 | Operator missing Url for CustomerServiceContactDetails | +| PASSENGER_STOP_ASSIGNMENT_1 | PassengerStopAssignment missing ScheduledStopPointRef | +| PASSENGER_STOP_ASSIGNMENT_2 | PassengerStopAssignment missing QuayRef | +| PASSENGER_STOP_ASSIGNMENT_3 | PassengerStopAssignment duplicated Quay assignment | +| RESOURCE_FRAME_IN_LINE_FILE | ResourceFrame must be exactly one | +| ROUTE_1 | Route missing | +| ROUTE_2 | Route missing Name | +| ROUTE_3 | Route missing LineRef | +| ROUTE_4 | Route missing pointsInSequence | +| ROUTE_5 | Route illegal DirectionRef | +| ROUTE_6 | Route duplicated order | +| SERVICE_CALENDAR_1 | ServiceCalendar unused DayType | +| SERVICE_CALENDAR_2 | ServiceCalendar empty ServiceCalendar | +| SERVICE_CALENDAR_3 | ServiceCalendar missing ToDate | +| SERVICE_CALENDAR_4 | ServiceCalendar missing FromDate | +| SERVICE_CALENDAR_5 | ServiceCalendar invalid time interval | +| SERVICE_FRAME_1 | ServiceFrame unexpected element GroupOfLines | +| SERVICE_FRAME_2 | ServiceFrame unexpected element timingPoints | +| SERVICE_FRAME_3 | ServiceFrame missing Projection on RoutePoint | +| SERVICE_FRAME_IN_COMMON_FILE_1 | ServiceFrame unexpected element Line | +| SERVICE_FRAME_IN_COMMON_FILE_2 | ServiceFrame unexpected element Route | +| SERVICE_FRAME_IN_COMMON_FILE_3 | ServiceFrame unexpected element JourneyPattern | +| SERVICE_JOURNEY_1 | ServiceJourney must exist | +| SERVICE_JOURNEY_10 | ServiceJourney missing reference to JourneyPattern | +| SERVICE_JOURNEY_11 | ServiceJourney invalid overriding of transport modes | +| SERVICE_JOURNEY_12 | ServiceJourney missing OperatorRef | +| SERVICE_JOURNEY_13 | ServiceJourney missing reference to calendar data | +| SERVICE_JOURNEY_14 | ServiceJourney duplicated reference to calendar data | +| SERVICE_JOURNEY_15 | ServiceJourney missing some passing times | +| SERVICE_JOURNEY_16 | ServiceJourney multiple versions | +| SERVICE_JOURNEY_17 | Non-unique NeTEx id for TimetabledPassingTime | +| SERVICE_JOURNEY_2 | ServiceJourney illegal element Call | +| SERVICE_JOURNEY_3 | ServiceJourney missing element PassingTimes | +| SERVICE_JOURNEY_4 | ServiceJourney missing arrival and departure | +| SERVICE_JOURNEY_5 | ServiceJourney missing departure times | +| SERVICE_JOURNEY_6 | ServiceJourney missing arrival time for last stop | +| SERVICE_JOURNEY_7 | ServiceJourney identical arrival and departure | +| SERVICE_JOURNEY_8 | ServiceJourney missing id on TimetabledPassingTime | +| SERVICE_JOURNEY_9 | ServiceJourney missing version on TimetabledPassingTime | +| SERVICE_LINK_1 | ServiceLink missing FromPointRef | +| SERVICE_LINK_2 | ServiceLink missing ToPointRef | +| SERVICE_LINK_3 | ServiceLink missing element Projections | +| SITE_FRAME_IN_COMMON_FILE | SiteFrame unexpected SiteFrame in Common file | +| SITE_FRAME_IN_LINE_FILE | SiteFrame unexpected SiteFrame in Line file | +| TIMETABLE_FRAME_IN_COMMON_FILE | TimetableFrame illegal in Common file | +| TRANSPORT_MODE_ON_LINE | Line Illegal TransportMode | +| TRANSPORT_MODE_ON_SERVICE_JOURNEY | Service Journey Illegal TransportMode | +| TRANSPORT_SUB_MODE_ON_LINE | Line Illegal TransportSubMode | +| TRANSPORT_SUB_MODE_ON_SERVICE_JOURNEY | Service Journey Illegal TransportSubMode | +| VALIDITY_CONDITIONS_IN_COMMON_FILE_1 | ValidityConditions missing in ServiceFrame or ServiceCalendarFrame | +| VALIDITY_CONDITIONS_IN_COMMON_FILE_2 | ValidityConditions missing in ResourceFrames | +| VALIDITY_CONDITIONS_IN_COMMON_FILE_3 | ValidityConditions missing in ServiceFrames | +| VALIDITY_CONDITIONS_IN_COMMON_FILE_4 | ValidityConditions missing in ServiceCalendarFrames | +| VALIDITY_CONDITIONS_IN_LINE_FILE_1 | ValidityConditions missing in all frames | +| VALIDITY_CONDITIONS_IN_LINE_FILE_2 | ValidityConditions missing in ServiceFrames | +| VALIDITY_CONDITIONS_IN_LINE_FILE_3 | ValidityConditions missing in ServiceCalendarFrames | +| VALIDITY_CONDITIONS_IN_LINE_FILE_4 | ValidityConditions missing in TimeTableFrames | +| VALIDITY_CONDITIONS_IN_LINE_FILE_5 | ValidityConditions missing in VehicleScheduleFrame | +| VERSION_NON_NUMERIC | Non-numeric NeTEx version | diff --git a/src/main/java/org/entur/netex/validation/configuration/DefaultValidationConfigLoader.java b/src/main/java/org/entur/netex/validation/configuration/DefaultValidationConfigLoader.java index 5044a2f5..fda330eb 100644 --- a/src/main/java/org/entur/netex/validation/configuration/DefaultValidationConfigLoader.java +++ b/src/main/java/org/entur/netex/validation/configuration/DefaultValidationConfigLoader.java @@ -2,11 +2,11 @@ import java.io.InputStream; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; -import org.entur.netex.validation.exception.NetexValidationException; import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; @@ -48,9 +48,7 @@ private Map loadConfigurationFile( .getResourceAsStream(configurationFile); if (inputStream == null) { - throw new NetexValidationException( - "Validation rules configuration file not found: " + configurationFile - ); + return new HashMap<>(); } Yaml yaml = new Yaml( diff --git a/src/main/java/org/entur/netex/validation/validator/DefaultValidationEntryFactory.java b/src/main/java/org/entur/netex/validation/validator/DefaultValidationEntryFactory.java index 799470eb..0a21c767 100644 --- a/src/main/java/org/entur/netex/validation/validator/DefaultValidationEntryFactory.java +++ b/src/main/java/org/entur/netex/validation/validator/DefaultValidationEntryFactory.java @@ -52,4 +52,30 @@ public ValidationReportEntry createValidationReportEntry( validationIssue.dataLocation() ); } + + @Override + public ValidationReportEntry templateValidationReportEntry( + ValidationRule validationRule + ) { + ValidationRuleConfig validationRuleConfig = validationConfigLoader + .getValidationRuleConfigs() + .get(validationRule.code()); + if (validationRuleConfig == null) { + return ValidationReportEntryFactory.super.templateValidationReportEntry( + validationRule + ); + } + + String message = validationRuleConfig.getMessage() != null + ? validationRuleConfig.getMessage() + : validationRule.message(); + String name = validationRuleConfig.getName() != null + ? validationRuleConfig.getName() + : validationRule.name(); + Severity severity = validationRuleConfig.getSeverity() != null + ? validationRuleConfig.getSeverity() + : validationRule.severity(); + + return new ValidationReportEntry(message, name, severity); + } } diff --git a/src/main/java/org/entur/netex/validation/validator/NetexValidatorsRunner.java b/src/main/java/org/entur/netex/validation/validator/NetexValidatorsRunner.java index 7d99589f..875c13d0 100644 --- a/src/main/java/org/entur/netex/validation/validator/NetexValidatorsRunner.java +++ b/src/main/java/org/entur/netex/validation/validator/NetexValidatorsRunner.java @@ -482,12 +482,34 @@ > List runValidator( } } - public Set getRuleDescriptions() { + public Map getRuleDescriptionByCode() { return Stream .concat(xPathValidators.stream(), jaxbValidators.stream()) .map(NetexValidator::getRules) .flatMap(Collection::stream) - .map(ValidationRule::name) - .collect(Collectors.toSet()); + .collect( + Collectors.toMap( + ValidationRule::code, + validationRule -> + validationReportEntryFactory + .templateValidationReportEntry(validationRule) + .getName(), + (a, b) -> { + throw new IllegalStateException( + "Duplicate validation rule: " + a + ", " + b + ); + }, + TreeMap::new + ) + ); + } + + /** + * + * @deprecated use {@link #getRuleDescriptionByCode()} + */ + @Deprecated + public Set getRuleDescriptions() { + return new LinkedHashSet<>(getRuleDescriptionByCode().values()); } } diff --git a/src/main/java/org/entur/netex/validation/validator/ValidationReportEntryFactory.java b/src/main/java/org/entur/netex/validation/validator/ValidationReportEntryFactory.java index 7431025b..272cc860 100644 --- a/src/main/java/org/entur/netex/validation/validator/ValidationReportEntryFactory.java +++ b/src/main/java/org/entur/netex/validation/validator/ValidationReportEntryFactory.java @@ -1,10 +1,30 @@ package org.entur.netex.validation.validator; /** - * Create validation entries based on the rule execution result (code and message) and the configuration file (name and severity) + * Factory for validation report entries. + * Concrete implementation may override the default configuration provided by the validation rule. */ public interface ValidationReportEntryFactory { + /** + * Create a validation report entry for a validation issue. + * Concrete implementations may override the default configuration provided by the validation rule. + */ ValidationReportEntry createValidationReportEntry( ValidationIssue validationIssue ); + + /** + * Create a template validation report entry for a validation rule, for documentation purpose. + * The data location is empty and the message placeholders are not resolved. + * Concrete implementations may override the default configuration provided by the validation rule. + */ + default ValidationReportEntry templateValidationReportEntry( + ValidationRule validationRule + ) { + return new ValidationReportEntry( + validationRule.message(), + validationRule.name(), + validationRule.severity() + ); + } } diff --git a/src/main/java/org/entur/netex/validation/validator/id/NetexIdUniquenessValidator.java b/src/main/java/org/entur/netex/validation/validator/id/NetexIdUniquenessValidator.java index 641508a7..030b2b47 100644 --- a/src/main/java/org/entur/netex/validation/validator/id/NetexIdUniquenessValidator.java +++ b/src/main/java/org/entur/netex/validation/validator/id/NetexIdUniquenessValidator.java @@ -34,7 +34,7 @@ public class NetexIdUniquenessValidator implements XPathValidator { static final ValidationRule RULE_DUPLICATE_ID_ACROSS_COMMON_FILES = new ValidationRule( "NETEX_ID_10", - " Duplicate NeTEx ID across common files", + "Duplicate NeTEx ID across common files", "Duplicate element identifiers across common files", Severity.WARNING ); diff --git a/src/main/java/org/entur/netex/validation/validator/id/VersionOnLocalNetexIdValidator.java b/src/main/java/org/entur/netex/validation/validator/id/VersionOnLocalNetexIdValidator.java index 7f93400e..f312e201 100644 --- a/src/main/java/org/entur/netex/validation/validator/id/VersionOnLocalNetexIdValidator.java +++ b/src/main/java/org/entur/netex/validation/validator/id/VersionOnLocalNetexIdValidator.java @@ -18,7 +18,7 @@ */ public class VersionOnLocalNetexIdValidator implements XPathValidator { - static final ValidationRule RULE = new ValidationRule( + public static final ValidationRule RULE = new ValidationRule( "NETEX_ID_8", "NeTEx ID missing version on elements", "Missing version attribute on elements with id attribute", diff --git a/src/main/java/org/entur/netex/validation/validator/xpath/rules/ValidateAllowedTransportModeOnLine.java b/src/main/java/org/entur/netex/validation/validator/xpath/rules/ValidateAllowedTransportModeOnLine.java index 565cfe0c..df8f0dd2 100644 --- a/src/main/java/org/entur/netex/validation/validator/xpath/rules/ValidateAllowedTransportModeOnLine.java +++ b/src/main/java/org/entur/netex/validation/validator/xpath/rules/ValidateAllowedTransportModeOnLine.java @@ -8,8 +8,8 @@ public class ValidateAllowedTransportModeOnLine public ValidateAllowedTransportModeOnLine() { super( "lines/*[self::Line or self::FlexibleLine]", - "Line Illegal TransportMode", "TRANSPORT_MODE_ON_LINE", + "Line Illegal TransportMode", "Illegal TransportMode on Line: %s", Severity.ERROR ); diff --git a/src/main/resources/configuration.default.yaml b/src/main/resources/configuration.default.yaml deleted file mode 100644 index 63c9bf44..00000000 --- a/src/main/resources/configuration.default.yaml +++ /dev/null @@ -1,433 +0,0 @@ -validationRuleConfigs: - # NeTEX id and reference rules - - code: NETEX_ID_1 - name: NeTEx ID duplicated across files - severity: ERROR - - code: NETEX_ID_5 - name: NeTEx ID unresolved reference - severity: ERROR - - code: NETEX_ID_6 - name: NeTEx ID reference to invalid element - severity: ERROR - - code: NETEX_ID_7 - name: NeTEx ID invalid value - severity: ERROR - - code: NETEX_ID_8 - name: NeTEx ID missing version on elements - severity: ERROR - - code: NETEX_ID_9 - name: NeTEx ID missing version on reference - severity: ERROR - - code: NETEX_ID_10 - name: Duplicate NeTEx ID across common files - severity: WARNING - - - # XPath rules - - code: VERSION_NON_NUMERIC - name: Non-numeric NeTEx version - severity: WARNING - - code: AUTHORITY_1 - name: Authority missing CompanyNumber - severity: INFO - - code: AUTHORITY_2 - name: Authority missing Name - severity: ERROR - - code: AUTHORITY_3 - name: Authority missing LegalName - severity: INFO - - code: AUTHORITY_4 - name: Authority missing ContactDetails - severity: ERROR - - code: AUTHORITY_5 - name: Authority missing Url for ContactDetails - severity: ERROR - - code: BLOCK_1 - name: Block missing VehicleScheduleFrame - severity: ERROR - - code: BLOCK_2 - name: Block missing Journey - severity: ERROR - - code: BLOCK_3 - name: Block missing DayType - severity: WARNING - - code: BOOKING_1 - name: Booking illegal BookingAccess - severity: ERROR - - code: BOOKING_2 - name: Booking illegal BookingMethod - severity: ERROR - - code: BOOKING_3 - name: Booking illegal BookWhen - severity: ERROR - - code: BOOKING_4 - name: Booking property - severity: ERROR - - code: BOOKING_5 - name: Missing BookWhen or MinimumBookingPeriod - severity: WARNING - - code: BUY_WHEN_1 - name: BuyWhen illegal value - severity: ERROR - - code: COMPOSITE_FRAME_1 - name: CompositeFrame missing ValidityCondition - severity: ERROR - - code: COMPOSITE_FRAME_2 - name: CompositeFrame invalid nested ValidityCondition - severity: WARNING - - code: COMPOSITE_FRAME_3 - name: CompositeFrame missing ValidBetween - severity: ERROR - - code: COMPOSITE_FRAME_4 - name: CompositeFrame invalid ValidBetween - severity: ERROR - - code: COMPOSITE_FRAME_5 - name: CompositeFrame invalid AvailabilityCondition - severity: ERROR - - code: COMPOSITE_SITE_FRAME_IN_COMMON_FILE - name: CompositeFrame unexpected SiteFrame - severity: WARNING - - code: COMPOSITE_TIMETABLE_FRAME_IN_COMMON_FILE - name: CompositeFrame illegal Timetable - severity: ERROR - - code: DATED_SERVICE_JOURNEY_1 - name: DatedServiceJourney missing OperatingDayRef - severity: ERROR - - code: DATED_SERVICE_JOURNEY_2 - name: DatedServiceJourney missing ServiceJourneyRef - severity: ERROR - - code: DATED_SERVICE_JOURNEY_3 - name: DatedServiceJourney multiple ServiceJourneyRef - severity: ERROR - - code: DATED_SERVICE_JOURNEY_4 - name: DatedServiceJourney multiple versions - severity: WARNING - - code: DATED_SERVICE_JOURNEY_5 - name: DatedServiceJourney multiple references to the same DatedServiceJourney - severity: ERROR - - code: DEAD_RUN_1 - name: DeadRun missing PassingTime references - severity: INFO - - code: DEAD_RUN_2 - name: DeadRun missing JourneyPattern references - severity: ERROR - - code: DEAD_RUN_3 - name: DeadRun missing DayType references - severity: ERROR - - code: DESTINATION_DISPLAY_1 - name: DestinationDisplay missing FrontText - severity: ERROR - - code: DESTINATION_DISPLAY_2 - name: DestinationDisplay missing DestinationDisplayRef on Via - severity: ERROR - - code: FLEXIBLE_LINE_1 - name: FlexibleLine missing FlexibleLineType - severity: ERROR - - code: FLEXIBLE_LINE_8 - name: FlexibleLine illegal FlexibleLineType - severity: ERROR - - code: FLEXIBLE_LINE_9 - name: FlexibleLine illegal FlexibleServiceType - severity: ERROR - - code: FLEXIBLE_LINE_10 - name: FlexibleLine illegal use of both BookWhen and MinimumBookingPeriod - severity: WARNING - - code: FLEXIBLE_LINE_11 - name: FlexibleLine BookWhen without LatestBookingTime or LatestBookingTime without BookWhen - severity: WARNING - - code: FLEXIBLE_SERVICE_1 - name: FlexibleService missing Id on FlexibleServiceProperties - severity: ERROR - - code: FLEXIBLE_SERVICE_2 - name: FlexibleService missing version on FlexibleServiceProperties - severity: ERROR - - code: FLEXIBLE_SERVICE_3 - name: FlexibleService illegal use of both BookWhen and MinimumBookingPeriod - severity: WARNING - - code: FLEXIBLE_SERVICE_4 - name: FlexibleService BookWhen without LatestBookingTime or LatestBookingTime without BookWhen - severity: WARNING - - code: INTERCHANGE_1 - name: Interchange invalid properties - severity: WARNING - - code: INTERCHANGE_2 - name: Interchange unexpected MaximumWaitTime - severity: WARNING - - code: INTERCHANGE_3 - name: Interchange excessive MaximumWaitTime - severity: WARNING - - code: JOURNEY_PATTERN_1 - name: JourneyPattern illegal element ServiceJourneyPattern - severity: ERROR - - code: JOURNEY_PATTERN_2 - name: JourneyPattern missing JourneyPattern - severity: ERROR - - code: JOURNEY_PATTERN_3 - name: JourneyPattern missing RouteRef - severity: ERROR - - code: JOURNEY_PATTERN_4 - name: JourneyPattern missing DestinationDisplayRef on first stop point - severity: ERROR - - code: JOURNEY_PATTERN_5 - name: JourneyPattern illegal DestinationDisplayRef on last stop point - severity: WARNING - - code: JOURNEY_PATTERN_6 - name: JourneyPattern stop point without boarding or alighting - severity: WARNING - - code: JOURNEY_PATTERN_7 - name: JourneyPattern illegal repetition of DestinationDisplay - severity: ERROR - - code: JOURNEY_PATTERN_8 - name: JourneyPattern illegal use of both BookWhen and MinimumBookingPeriod - severity: WARNING - - code: JOURNEY_PATTERN_9 - name: JourneyPattern BookWhen without LatestBookingTime or LatestBookingTime without BookWhen - severity: WARNING - - code: LINE_1 - name: Line missing Line or FlexibleLine - severity: ERROR - - code: LINE_2 - name: Line missing Name - severity: ERROR - - code: LINE_3 - name: Line missing PublicCode - severity: WARNING - - code: LINE_4 - name: Line missing TransportMode - severity: ERROR - - code: LINE_5 - name: Line missing TransportSubmode - severity: WARNING - - code: LINE_6 - name: Line with incorrect use of Route - severity: ERROR - - code: LINE_7 - name: Line missing Network or GroupOfLines - severity: ERROR - - code: LINE_8 - name: Invalid color coding length on Presentation - severity: WARNING - - code: LINE_9 - name: Invalid color coding value on Presentation - severity: WARNING - - code: NETWORK_1 - name: Network missing AuthorityRef - severity: ERROR - - code: NETWORK_2 - name: Network missing Name on Network - severity: ERROR - - code: NETWORK_3 - name: Network missing Name on GroupOfLines - severity: ERROR - - code: NOTICE_1 - name: Notice missing Text - severity: ERROR - - code: NOTICE_2 - name: Notice missing Text with alternative text - severity: ERROR - - code: NOTICE_3 - name: Notice missing language with alternative text - severity: ERROR - - code: NOTICE_4 - name: Notice duplicated alternative texts - severity: ERROR - - code: NOTICE_5 - name: Notice duplicated assignment - severity: WARNING - - code: NOTICE_6 - name: Notice assignment missing reference to noticed object - severity: ERROR - - code: NOTICE_7 - name: Notice assignment missing reference to notice - severity: ERROR - - code: OPERATOR_1 - name: Operator missing CompanyNumber - severity: INFO - - code: OPERATOR_2 - name: Operator missing Name - severity: ERROR - - code: OPERATOR_3 - name: Operator missing LegalName - severity: INFO - - code: OPERATOR_4 - name: Operator missing ContactDetails - severity: WARNING - - code: OPERATOR_5 - name: Operator missing Url for ContactDetails - severity: WARNING - - code: OPERATOR_6 - name: Operator missing CustomerServiceContactDetails - severity: WARNING - - code: OPERATOR_7 - name: Operator missing Url for CustomerServiceContactDetails - severity: WARNING - - code: PASSENGER_STOP_ASSIGNMENT_1 - name: PassengerStopAssignment missing ScheduledStopPointRef - severity: ERROR - - code: PASSENGER_STOP_ASSIGNMENT_2 - name: PassengerStopAssignment missing QuayRef - severity: ERROR - - code: PASSENGER_STOP_ASSIGNMENT_3 - name: PassengerStopAssignment duplicated Quay assignment - severity: WARNING - - code: RESOURCE_FRAME_IN_LINE_FILE - name: ResourceFrame must be exactly one - severity: ERROR - - code: ROUTE_1 - name: Route missing - severity: ERROR - - code: ROUTE_2 - name: Route missing Name - severity: ERROR - - code: ROUTE_3 - name: Route missing LineRef - severity: ERROR - - code: ROUTE_4 - name: Route missing pointsInSequence - severity: ERROR - - code: ROUTE_5 - name: Route illegal DirectionRef - severity: WARNING - - code: ROUTE_6 - name: Route duplicated order - severity: WARNING - - code: SERVICE_CALENDAR_1 - name: ServiceCalendar unused DayType - severity: WARNING - - code: SERVICE_CALENDAR_2 - name: ServiceCalendar empty ServiceCalendar - severity: WARNING - - code: SERVICE_CALENDAR_3 - name: ServiceCalendar missing ToDate - severity: WARNING - - code: SERVICE_CALENDAR_4 - name: ServiceCalendar missing FromDate - severity: WARNING - - code: SERVICE_CALENDAR_5 - name: ServiceCalendar invalid time interval - severity: ERROR - - code: SERVICE_FRAME_1 - name: ServiceFrame unexpected element GroupOfLines - severity: ERROR - - code: SERVICE_FRAME_2 - name: ServiceFrame unexpected element timingPoints - severity: WARNING - - code: SERVICE_FRAME_3 - name: ServiceFrame missing Projection on RoutePoint - severity: ERROR - - code: SERVICE_FRAME_IN_COMMON_FILE_1 - name: ServiceFrame unexpected element Line - severity: ERROR - - code: SERVICE_FRAME_IN_COMMON_FILE_2 - name: ServiceFrame unexpected element Route - severity: ERROR - - code: SERVICE_FRAME_IN_COMMON_FILE_3 - name: ServiceFrame unexpected element JourneyPattern - severity: ERROR - - code: SERVICE_JOURNEY_1 - name: ServiceJourney must exist - severity: ERROR - - code: SERVICE_JOURNEY_10 - name: ServiceJourney missing reference to JourneyPattern - severity: ERROR - - code: SERVICE_JOURNEY_11 - name: ServiceJourney invalid overriding of transport modes - severity: WARNING - - code: SERVICE_JOURNEY_12 - name: ServiceJourney missing OperatorRef - severity: ERROR - - code: SERVICE_JOURNEY_13 - name: ServiceJourney missing reference to calendar data - severity: ERROR - - code: SERVICE_JOURNEY_14 - name: ServiceJourney duplicated reference to calendar data - severity: ERROR - - code: SERVICE_JOURNEY_15 - name: ServiceJourney missing some passing times - severity: ERROR - - code: SERVICE_JOURNEY_16 - name: ServiceJourney multiple versions - severity: WARNING - - code: SERVICE_JOURNEY_2 - name: ServiceJourney illegal element Call - severity: ERROR - - code: SERVICE_JOURNEY_3 - name: ServiceJourney missing element PassingTimes - severity: ERROR - - code: SERVICE_JOURNEY_4 - name: ServiceJourney missing arrival and departure - severity: ERROR - - code: SERVICE_JOURNEY_5 - name: ServiceJourney missing departure times - severity: ERROR - - code: SERVICE_JOURNEY_6 - name: ServiceJourney missing arrival time for last stop - severity: ERROR - - code: SERVICE_JOURNEY_7 - name: ServiceJourney identical arrival and departure - severity: WARNING - - code: SERVICE_JOURNEY_8 - name: ServiceJourney missing id on TimetabledPassingTime - severity: WARNING - - code: SERVICE_JOURNEY_9 - name: ServiceJourney missing version on TimetabledPassingTime - severity: WARNING - - code: SERVICE_JOURNEY_17 - name: ServiceJourney duplicated TimetabledPassingTime id - severity: ERROR - - code: SERVICE_LINK_1 - name: ServiceLink missing FromPointRef - severity: ERROR - - code: SERVICE_LINK_2 - name: ServiceLink missing ToPointRef - severity: ERROR - - code: SERVICE_LINK_3 - name: ServiceLink missing element Projections - severity: ERROR - - code: SITE_FRAME_IN_COMMON_FILE - name: SiteFrame unexpected SiteFrame in Common file - severity: WARNING - - code: SITE_FRAME_IN_LINE_FILE - name: SiteFrame unexpected SiteFrame in Line file - severity: WARNING - - code: TIMETABLE_FRAME_IN_COMMON_FILE - name: TimetableFrame illegal in Common file - severity: ERROR - - code: TRANSPORT_MODE - name: TransportMode illegal value - severity: ERROR - - code: TRANSPORT_SUB_MODE - name: TransportSubmode illegal value - severity: ERROR - - code: VALIDITY_CONDITIONS_IN_COMMON_FILE_1 - name: ValidityConditions missing in ServiceFrame or ServiceCalendarFrame - severity: ERROR - - code: VALIDITY_CONDITIONS_IN_COMMON_FILE_2 - name: ValidityConditions missing in ResourceFrames - severity: ERROR - - code: VALIDITY_CONDITIONS_IN_COMMON_FILE_3 - name: ValidityConditions missing in ServiceFrames - severity: ERROR - - code: VALIDITY_CONDITIONS_IN_COMMON_FILE_4 - name: ValidityConditions missing in ServiceCalendarFrames - severity: ERROR - - code: VALIDITY_CONDITIONS_IN_LINE_FILE_1 - name: ValidityConditions missing in all frames - severity: ERROR - - code: VALIDITY_CONDITIONS_IN_LINE_FILE_2 - name: ValidityConditions missing in ServiceFrames - severity: ERROR - - code: VALIDITY_CONDITIONS_IN_LINE_FILE_3 - name: ValidityConditions missing in ServiceCalendarFrames - severity: ERROR - - code: VALIDITY_CONDITIONS_IN_LINE_FILE_4 - name: ValidityConditions missing in TimeTableFrames - severity: ERROR - - code: VALIDITY_CONDITIONS_IN_LINE_FILE_5 - name: ValidityConditions missing in VehicleScheduleFrame - severity: ERROR - - - - - diff --git a/src/test/java/org/entur/netex/validation/configuration/DefaultValidationConfigLoaderTest.java b/src/test/java/org/entur/netex/validation/configuration/DefaultValidationConfigLoaderTest.java index 5a814ead..d482ba89 100644 --- a/src/test/java/org/entur/netex/validation/configuration/DefaultValidationConfigLoaderTest.java +++ b/src/test/java/org/entur/netex/validation/configuration/DefaultValidationConfigLoaderTest.java @@ -3,7 +3,6 @@ import static org.junit.jupiter.api.Assertions.*; import java.util.List; -import org.entur.netex.validation.exception.NetexValidationException; import org.entur.netex.validation.validator.Severity; import org.junit.jupiter.api.Test; @@ -29,10 +28,10 @@ void loadConfiguration() { @Test void loadConfigurationNonExistingFile() { - assertThrows( - NetexValidationException.class, - () -> new DefaultValidationConfigLoader("missing.yaml") + DefaultValidationConfigLoader loader = new DefaultValidationConfigLoader( + "non existing file" ); + assertTrue(loader.getValidationRuleConfigs().isEmpty()); } @Test diff --git a/src/test/java/org/entur/netex/validation/validator/DefaultValidationEntryFactoryTest.java b/src/test/java/org/entur/netex/validation/validator/DefaultValidationEntryFactoryTest.java index 6c5d5881..632497be 100644 --- a/src/test/java/org/entur/netex/validation/validator/DefaultValidationEntryFactoryTest.java +++ b/src/test/java/org/entur/netex/validation/validator/DefaultValidationEntryFactoryTest.java @@ -1,7 +1,6 @@ package org.entur.netex.validation.validator; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; import java.util.Set; import java.util.function.Function; @@ -28,15 +27,17 @@ class DefaultValidationEntryFactoryTest { private static final Severity OVERRIDEN_RULE_SEVERITY = Severity.WARNING; private ValidationIssue validationIssue; + private ValidationRule validationRule; @BeforeEach void setUp() { - ValidationRule validationRule = new ValidationRule( - RULE_CODE, - ORIGINAL_RULE_NAME, - ORIGINAL_RULE_MESSAGE, - ORIGINAL_RULE_SEVERITY - ); + validationRule = + new ValidationRule( + RULE_CODE, + ORIGINAL_RULE_NAME, + ORIGINAL_RULE_MESSAGE, + ORIGINAL_RULE_SEVERITY + ); DataLocation dataLocation = new DataLocation(LINE_ID, "netex.xml", 1, 2); validationIssue = new ValidationIssue(validationRule, dataLocation, LINE_ID); @@ -92,6 +93,51 @@ void testValidConfiguration() { assertEquals(OVERRIDEN_RULE_SEVERITY, validationReportEntry.getSeverity()); } + @Test + void testTemplateReportEntry() { + ValidationConfigLoader validationConfigLoader = getValidationConfigLoader( + Set.of() + ); + ValidationReportEntryFactory factory = new DefaultValidationEntryFactory( + validationConfigLoader + ); + ValidationReportEntry validationReportEntry = + factory.templateValidationReportEntry(validationRule); + assertNotNull(validationReportEntry); + assertEquals(ORIGINAL_RULE_NAME, validationReportEntry.getName()); + assertEquals(ORIGINAL_RULE_MESSAGE, validationReportEntry.getMessage()); + assertEquals(ORIGINAL_RULE_SEVERITY, validationReportEntry.getSeverity()); + assertNull(validationReportEntry.getFileName()); + assertNull(validationReportEntry.getLineNumber()); + assertNull(validationReportEntry.getColumnNumber()); + } + + @Test + void testTemplateReportEntryWithConfigurationOverride() { + ValidationRuleConfig config = new ValidationRuleConfig(); + config.setCode(RULE_CODE); + config.setName(OVERRIDDEN_RULE_NAME); + config.setMessage(OVERRIDDEN_RULE_MESSAGE); + config.setSeverity(OVERRIDEN_RULE_SEVERITY); + + ValidationConfigLoader validationConfigLoader = getValidationConfigLoader( + Set.of(config) + ); + + ValidationReportEntryFactory factory = new DefaultValidationEntryFactory( + validationConfigLoader + ); + ValidationReportEntry validationReportEntry = + factory.templateValidationReportEntry(validationRule); + assertNotNull(validationReportEntry); + assertEquals(OVERRIDDEN_RULE_NAME, validationReportEntry.getName()); + assertEquals(OVERRIDDEN_RULE_MESSAGE, validationReportEntry.getMessage()); + assertEquals(OVERRIDEN_RULE_SEVERITY, validationReportEntry.getSeverity()); + assertNull(validationReportEntry.getFileName()); + assertNull(validationReportEntry.getLineNumber()); + assertNull(validationReportEntry.getColumnNumber()); + } + private static ValidationConfigLoader getValidationConfigLoader( Set configs ) { diff --git a/src/test/java/org/entur/netex/validation/validator/NetexValidatorsRunnerTest.java b/src/test/java/org/entur/netex/validation/validator/NetexValidatorsRunnerTest.java index 5790833d..49fe4416 100644 --- a/src/test/java/org/entur/netex/validation/validator/NetexValidatorsRunnerTest.java +++ b/src/test/java/org/entur/netex/validation/validator/NetexValidatorsRunnerTest.java @@ -164,6 +164,14 @@ void testDescriptions() { .map(ValidationRule::name) .collect(Collectors.toUnmodifiableSet()); assertEquals(xpathRuleDescriptions, ruleDescriptions); + + assertEquals(1, runner.getRuleDescriptionByCode().size()); + assertEquals( + VersionOnLocalNetexIdValidator.RULE.name(), + runner + .getRuleDescriptionByCode() + .get(VersionOnLocalNetexIdValidator.RULE.code()) + ); } private static ValidationReport validationReport( diff --git a/src/test/java/org/entur/netex/validation/validator/demo/AllValidatorsDemo.java b/src/test/java/org/entur/netex/validation/validator/demo/AllValidatorsDemo.java new file mode 100644 index 00000000..ccd9a0cb --- /dev/null +++ b/src/test/java/org/entur/netex/validation/validator/demo/AllValidatorsDemo.java @@ -0,0 +1,49 @@ +package org.entur.netex.validation.validator.demo; + +import java.util.List; +import org.entur.netex.validation.validator.NetexValidatorsRunner; +import org.entur.netex.validation.validator.XPathValidator; +import org.entur.netex.validation.validator.id.DefaultNetexIdRepository; +import org.entur.netex.validation.validator.id.NetexIdUniquenessValidator; +import org.entur.netex.validation.validator.id.NetexReferenceValidator; +import org.entur.netex.validation.validator.id.ReferenceToValidEntityTypeValidator; +import org.entur.netex.validation.validator.id.VersionOnLocalNetexIdValidator; +import org.entur.netex.validation.validator.id.VersionOnRefToLocalNetexIdValidator; +import org.entur.netex.validation.validator.schema.NetexSchemaValidator; +import org.entur.netex.validation.validator.xpath.XPathRuleValidator; +import org.entur.netex.validation.validator.xpath.tree.PublicationDeliveryValidationTreeFactory; +import org.entur.netex.validation.xml.NetexXMLParser; + +/** + * Demonstrate the configuration of all the validators provided by the library. + */ +public class AllValidatorsDemo { + + public static void main(String[] args) { + // create a NeTEx XML Parser that ignores SiteFrame elements + NetexXMLParser netexXMLParser = new NetexXMLParser(); + // create a NeTEx schema validator, limit the number of findings to 100 + NetexSchemaValidator netexSchemaValidator = new NetexSchemaValidator(100); + + // Configure all XPath validators + List xPathValidators = List.of( + new XPathRuleValidator(new PublicationDeliveryValidationTreeFactory()), + new NetexIdUniquenessValidator(new DefaultNetexIdRepository()), + new NetexReferenceValidator(new DefaultNetexIdRepository(), List.of()), + new ReferenceToValidEntityTypeValidator(), + new VersionOnLocalNetexIdValidator(), + new VersionOnRefToLocalNetexIdValidator() + ); + + NetexValidatorsRunner netexValidatorsRunner = NetexValidatorsRunner + .of() + .withNetexXMLParser(netexXMLParser) + .withNetexSchemaValidator(netexSchemaValidator) + .withXPathValidators(xPathValidators) + .build(); + + netexValidatorsRunner + .getRuleDescriptionByCode() + .forEach((key, value) -> System.out.println(key + " | " + value)); + } +}