-
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
26 changed files
with
291 additions
and
202 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
2 changes: 1 addition & 1 deletion
2
...ion/validator/jaxb/support/JAXBUtils.java → ...lidation/test/jaxb/support/JAXBUtils.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
46 changes: 46 additions & 0 deletions
46
...test/java/org/entur/netex/validation/test/xpath/support/TestValidationContextBuilder.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,46 @@ | ||
package org.entur.netex.validation.test.xpath.support; | ||
|
||
import static org.entur.netex.validation.test.xpath.support.XPathTestSupport.NETEX_XML_PARSER; | ||
|
||
import net.sf.saxon.s9api.XdmNode; | ||
import org.entur.netex.validation.validator.xpath.XPathRuleValidationContext; | ||
|
||
public class TestValidationContextBuilder { | ||
|
||
private final XdmNode document; | ||
private String codespace = XPathTestSupport.TEST_CODESPACE; | ||
private String filename = XPathTestSupport.TEST_FILENAME; | ||
|
||
public TestValidationContextBuilder(XdmNode xdmNode) { | ||
this.document = xdmNode; | ||
} | ||
|
||
public static TestValidationContextBuilder ofDocument(XdmNode document) { | ||
return new TestValidationContextBuilder(document); | ||
} | ||
|
||
public static TestValidationContextBuilder ofNetexFragment( | ||
String netexFragment | ||
) { | ||
return ofDocument(XPathTestSupport.parseDocument(netexFragment)); | ||
} | ||
|
||
public TestValidationContextBuilder withCodespace(String codespace) { | ||
this.codespace = codespace; | ||
return this; | ||
} | ||
|
||
public TestValidationContextBuilder withFilename(String filename) { | ||
this.filename = filename; | ||
return this; | ||
} | ||
|
||
public XPathRuleValidationContext build() { | ||
return new XPathRuleValidationContext( | ||
document, | ||
NETEX_XML_PARSER, | ||
codespace, | ||
filename | ||
); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/org/entur/netex/validation/test/xpath/support/XPathTestSupport.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,51 @@ | ||
package org.entur.netex.validation.test.xpath.support; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import net.sf.saxon.s9api.XdmNode; | ||
import org.entur.netex.validation.exception.NetexValidationException; | ||
import org.entur.netex.validation.xml.NetexXMLParser; | ||
|
||
/** | ||
* Utility methods for testing XPath validators. | ||
*/ | ||
public class XPathTestSupport { | ||
|
||
public static final String TEST_CODESPACE = "ENT"; | ||
public static final String TEST_FILENAME = "netex.xml"; | ||
|
||
static final NetexXMLParser NETEX_XML_PARSER = new NetexXMLParser(); | ||
|
||
/** | ||
* Parse a NeTEx fragment and return an XML document. | ||
* The XML fragment must be namespaced with the NeTEx schema namespace http://www.netex.org.uk/netex | ||
*/ | ||
public static XdmNode parseDocument(String netexFragment) { | ||
return parseDocument(new ByteArrayInputStream(netexFragment.getBytes())); | ||
} | ||
|
||
/** | ||
* Parse a NeTEx fragment and return an XML document. | ||
* The XML fragment must be namespaced with the NeTEx schema namespace http://www.netex.org.uk/netex | ||
*/ | ||
public static XdmNode parseDocument(InputStream inputStream) { | ||
XdmNode parsedDocument; | ||
try { | ||
parsedDocument = | ||
NETEX_XML_PARSER.parseByteArrayToXdmNode(inputStream.readAllBytes()); | ||
} catch (IOException e) { | ||
throw new NetexValidationException(e); | ||
} | ||
XdmNode rootElement = parsedDocument.children().iterator().next(); | ||
String namespaceURI = rootElement.getNodeName().getNamespaceURI(); | ||
if (!NetexXMLParser.NETEX_NAMESPACE.equals(namespaceURI)) { | ||
throw new IllegalStateException( | ||
"The XML fragment is not namespaced under the NeTEx namespace. Provided namespace: '" + | ||
namespaceURI + | ||
"'" | ||
); | ||
} | ||
return rootElement; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/test/java/org/entur/netex/validation/validator/jaxb/JAXBValidationContextTest.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
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
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
Oops, something went wrong.