-
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.
- Loading branch information
Showing
8 changed files
with
324 additions
and
4 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
49 changes: 49 additions & 0 deletions
49
...test/java/org/entur/netex/validation/configuration/DefaultValidationConfigLoaderTest.java
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,49 @@ | ||
package org.entur.netex.validation.configuration; | ||
|
||
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; | ||
|
||
class DefaultValidationConfigLoaderTest { | ||
|
||
private static final String RULE_CODE = "RULE_1"; | ||
private static final String CONFIGURATION_FILE_NAME = | ||
"configuration.test.yaml"; | ||
private static final String CONFIGURATION_FILE_NAME_OVERLOAD = | ||
"configuration.test.overloaded.yaml"; | ||
|
||
@Test | ||
void loadConfiguration() { | ||
DefaultValidationConfigLoader loader = new DefaultValidationConfigLoader( | ||
CONFIGURATION_FILE_NAME | ||
); | ||
ValidationRuleConfig validationRuleConfig = loader.getValidationRuleConfig( | ||
RULE_CODE | ||
); | ||
assertNotNull(validationRuleConfig); | ||
assertEquals(Severity.ERROR, validationRuleConfig.getSeverity()); | ||
} | ||
|
||
@Test | ||
void loadConfigurationNonExistingFile() { | ||
assertThrows( | ||
NetexValidationException.class, | ||
() -> new DefaultValidationConfigLoader("missing.yaml") | ||
); | ||
} | ||
|
||
@Test | ||
void loadOverloadedConfiguration() { | ||
DefaultValidationConfigLoader loader = new DefaultValidationConfigLoader( | ||
List.of(CONFIGURATION_FILE_NAME, CONFIGURATION_FILE_NAME_OVERLOAD) | ||
); | ||
ValidationRuleConfig validationRuleConfig = loader.getValidationRuleConfig( | ||
RULE_CODE | ||
); | ||
assertNotNull(validationRuleConfig); | ||
assertEquals(Severity.WARNING, validationRuleConfig.getSeverity()); | ||
} | ||
} |
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
80 changes: 80 additions & 0 deletions
80
src/test/java/org/entur/netex/validation/validator/schema/NetexSchemaValidatorTest.java
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,80 @@ | ||
package org.entur.netex.validation.validator.schema; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import org.entur.netex.validation.validator.ValidationIssue; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class NetexSchemaValidatorTest { | ||
|
||
private static final int MAX_VALIDATION_REPORT_ENTRIES = 2; | ||
private static final String TEST_CODESPACE = "ENT"; | ||
private static final String TEST_FILENAME = "netex.xml"; | ||
|
||
private static final String NETEX_FRAGMENT_VALID = | ||
""" | ||
<PublicationDelivery xmlns="http://www.netex.org.uk/netex" xmlns:ns2="http://www.opengis.net/gml/3.2" xmlns:ns3="http://www.siri.org.uk/siri" version="1.15:NO-NeTEx-networktimetable:1.5"> | ||
<PublicationTimestamp>2021-10-07T13:40:22.872</PublicationTimestamp> | ||
<ParticipantRef>RB</ParticipantRef> | ||
</PublicationDelivery> | ||
"""; | ||
|
||
private static final String NETEX_FRAGMENT_INVALID = | ||
""" | ||
<PublicationDelivery xmlns="http://www.netex.org.uk/netex" xmlns:ns2="http://www.opengis.net/gml/3.2" xmlns:ns3="http://www.siri.org.uk/siri" version="1.15:NO-NeTEx-networktimetable:1.5"> | ||
<PublicationTimestamp>2021-10-07T13:40:22.872</PublicationTimestamp> | ||
</PublicationDelivery> | ||
"""; | ||
|
||
private static final String NETEX_FRAGMENT_INVALID_TOO_MANY_ERRORS = | ||
""" | ||
<PublicationDelivery xmlns="http://www.netex.org.uk/netex" xmlns:ns2="http://www.opengis.net/gml/3.2" xmlns:ns3="http://www.siri.org.uk/siri" version="1.15:NO-NeTEx-networktimetable:1.5"> | ||
<dataObjects> | ||
<CompositeFrame created="2024-11-28T02:58:39.64" version="1" > | ||
<validityConditions/> | ||
</CompositeFrame> | ||
</dataObjects> | ||
</PublicationDelivery> | ||
"""; | ||
|
||
@Test | ||
void validateValidDocument() { | ||
List<ValidationIssue> validationIssues = validate(NETEX_FRAGMENT_VALID); | ||
assertTrue(validationIssues.isEmpty()); | ||
} | ||
|
||
@Test | ||
void validateInvalidDocument() { | ||
List<ValidationIssue> validationIssues = validate(NETEX_FRAGMENT_INVALID); | ||
assertEquals(1, validationIssues.size()); | ||
} | ||
|
||
@Test | ||
void validateInvalidDocumentTooManyErrors() { | ||
List<ValidationIssue> validationIssues = validate( | ||
NETEX_FRAGMENT_INVALID_TOO_MANY_ERRORS | ||
); | ||
assertEquals(MAX_VALIDATION_REPORT_ENTRIES, validationIssues.size()); | ||
} | ||
|
||
@Test | ||
void validateMalformedDocument() { | ||
List<ValidationIssue> validationIssues = validate("x"); | ||
assertEquals(1, validationIssues.size()); | ||
} | ||
|
||
private static List<ValidationIssue> validate(String netexFragment) { | ||
NetexSchemaValidator validator = new NetexSchemaValidator( | ||
MAX_VALIDATION_REPORT_ENTRIES | ||
); | ||
NetexSchemaValidationContext validationContext = | ||
new NetexSchemaValidationContext( | ||
TEST_FILENAME, | ||
TEST_CODESPACE, | ||
netexFragment.getBytes(StandardCharsets.UTF_8) | ||
); | ||
return validator.validate(validationContext); | ||
} | ||
} |
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,9 @@ | ||
validationRuleConfigs: | ||
- code: RULE_1 | ||
name: Rule 1 | ||
severity: WARNING | ||
|
||
|
||
|
||
|
||
|
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,9 @@ | ||
validationRuleConfigs: | ||
- code: RULE_1 | ||
name: Rule 1 | ||
severity: ERROR | ||
|
||
|
||
|
||
|
||
|