Commit 19c65a65 by Amelin Konstantin

delete hardcore paths on resources.

parent 1354bc97
...@@ -30,8 +30,8 @@ object Main { ...@@ -30,8 +30,8 @@ object Main {
else if (!Files.exists(Paths.get(args(1)))) println("Error: OUTPUT directory doesn`t exist") else if (!Files.exists(Paths.get(args(1)))) println("Error: OUTPUT directory doesn`t exist")
else { else {
val p = new PrettyPrinter(140, 2) val p = new PrettyPrinter(140, 2)
val nsdXmlValid = XMLValid("src/main/resources/nsd/nsd-ext-merged-schema.xsd") val nsdXmlValid = XMLValid(getClass.getResource("/nsd/nsd-ext-merged-schema.xsd"))
val rtsXmlValid = XMLValid("src/main/resources/rts/fpml-recordkeeping-merged-schema.xsd") val rtsXmlValid = XMLValid(getClass.getResource("/rts/fpml-recordkeeping-merged-schema.xsd"))
var logString = "" var logString = ""
for (v <- Files.walk(Paths.get(args(0))).toArray; f = v.asInstanceOf[Path]; if !Files.isDirectory(f)) { for (v <- Files.walk(Paths.get(args(0))).toArray; f = v.asInstanceOf[Path]; if !Files.isDirectory(f)) {
......
package xmlvalid package xmlvalid
import java.io.File import java.net.URL
import javax.xml.XMLConstants import javax.xml.XMLConstants
import javax.xml.parsers.SAXParser import javax.xml.parsers.SAXParser
import javax.xml.parsers.SAXParserFactory import javax.xml.parsers.SAXParserFactory
...@@ -17,12 +18,12 @@ import scala.xml.parsing.{ConsoleErrorHandler, NoBindingFactoryAdapter} ...@@ -17,12 +18,12 @@ import scala.xml.parsing.{ConsoleErrorHandler, NoBindingFactoryAdapter}
* }}} * }}}
* *
* @constructor Creates instance from path to xsd schema * @constructor Creates instance from path to xsd schema
* @param xsdPath path to xsd file (URI) * @param xsdPath path to xsd file (URL)
*/ */
class XMLValid(xsdPath: String) extends XMLLoader[Node] { class XMLValid(xsdPath: URL) extends XMLLoader[Node] {
private[this] val schema = SchemaFactory private[this] val schema = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
.newSchema(new File(xsdPath)) .newSchema(xsdPath)
override def adapter: NoBindingFactoryAdapter with ConsoleErrorHandler = override def adapter: NoBindingFactoryAdapter with ConsoleErrorHandler =
new NoBindingFactoryAdapter with ConsoleErrorHandler { new NoBindingFactoryAdapter with ConsoleErrorHandler {
...@@ -47,8 +48,8 @@ object XMLValid { ...@@ -47,8 +48,8 @@ object XMLValid {
/** Creates a ValidXML instance with given xsd schema /** Creates a ValidXML instance with given xsd schema
* *
* @param xsdPath path to xsd file (URI) * @param xsdPath path to xsd file (URL)
* @return XMLValid instance * @return XMLValid instance
*/ */
def apply(xsdPath: String) = new XMLValid(xsdPath) def apply(xsdPath: URL) = new XMLValid(xsdPath)
} }
\ No newline at end of file
...@@ -8,8 +8,8 @@ import scala.xml.{Elem, Node, XML} ...@@ -8,8 +8,8 @@ import scala.xml.{Elem, Node, XML}
class TemplateSpec extends WordSpec { class TemplateSpec extends WordSpec {
"XMLValid for RTS example" should { "XMLValid for RTS example" should {
"successfully loadFile(xmlPath) with well formed and valid xml" in { "successfully loadFile(xmlPath) with well formed and valid xml" in {
val validXml = XMLValid("src/test/resources/templates/rts/fpml-recordkeeping-merged-schema.xsd") val validXml = XMLValid(getClass.getResource("/templates/rts/fpml-recordkeeping-merged-schema.xsd"))
val xml = validXml.loadFile("src/test/resources/templates/rts/Example repo RTS.xml") val xml = validXml.load(getClass.getResource("/templates/rts/Example repo RTS.xml"))
assert(xml.isInstanceOf[Node]) assert(xml.isInstanceOf[Node])
} }
} }
...@@ -17,16 +17,16 @@ class TemplateSpec extends WordSpec { ...@@ -17,16 +17,16 @@ class TemplateSpec extends WordSpec {
it should { it should {
"throw exception in loadFile(xmlPath) with well formed but invalid xml" in { "throw exception in loadFile(xmlPath) with well formed but invalid xml" in {
assertThrows[Exception] { assertThrows[Exception] {
val validXml = XMLValid("src/test/resources/templates/rts/fpml-recordkeeping-merged-schema.xsd") val validXml = XMLValid(getClass.getResource("/templates/rts/fpml-recordkeeping-merged-schema.xsd"))
val xml = validXml.loadFile("src/test/resources/templates/rts/Example repo RTS invalid.xml") val xml = validXml.load(getClass.getResource("/templates/rts/Example repo RTS invalid.xml"))
} }
} }
} }
"XMLValid for NSD example" should { "XMLValid for NSD example" should {
"successfully loadFile(xmlPath) with well formed and valid xml" in { "successfully loadFile(xmlPath) with well formed and valid xml" in {
val validXml = XMLValid("src/test/resources/templates/nsd/nsd-ext-merged-schema.xsd") val validXml = XMLValid(getClass.getResource("/templates/nsd/nsd-ext-merged-schema.xsd"))
val xml = validXml.loadFile("src/test/resources/templates/nsd/Example repo NSD.xml") val xml = validXml.load(getClass.getResource("/templates/nsd/Example repo NSD.xml"))
assert(xml.isInstanceOf[Node]) assert(xml.isInstanceOf[Node])
} }
} }
...@@ -34,8 +34,8 @@ class TemplateSpec extends WordSpec { ...@@ -34,8 +34,8 @@ class TemplateSpec extends WordSpec {
it should { it should {
"throw exception in loadFile(xmlPath) with well formed but invalid xml" in { "throw exception in loadFile(xmlPath) with well formed but invalid xml" in {
assertThrows[Exception] { assertThrows[Exception] {
val validXml = XMLValid("src/test/resources/templates/nsd/nsd-ext-merged-schema.xsd") val validXml = XMLValid(getClass.getResource("/templates/nsd/nsd-ext-merged-schema.xsd"))
val xml = validXml.loadFile("src/test/resources/templates/nsd/Example repo NSD invalid.xml") val xml = validXml.load(getClass.getResource("/templates/nsd/Example repo NSD invalid.xml"))
} }
} }
} }
...@@ -85,9 +85,9 @@ class TemplateSpec extends WordSpec { ...@@ -85,9 +85,9 @@ class TemplateSpec extends WordSpec {
"Template" should { "Template" should {
"render valid xml against schema" in { "render valid xml against schema" in {
val sourceXml: Node = XML.loadFile("src/test/resources/templates/general/test_valid.xml") val sourceXml: Node = XML.load(getClass.getResource("/templates/general/test_valid.xml"))
val outputXml = new MockTemplate(sourceXml).render val outputXml = new MockTemplate(sourceXml).render
val checkedXml = XMLValid("src/test/resources/templates/general/test_valid.xsd").loadString(outputXml.mkString) val checkedXml = XMLValid(getClass.getResource("/templates/general/test_valid.xsd")).loadString(outputXml.mkString)
assert(checkedXml.isInstanceOf[Node]) assert(checkedXml.isInstanceOf[Node])
} }
...@@ -105,7 +105,7 @@ class TemplateSpec extends WordSpec { ...@@ -105,7 +105,7 @@ class TemplateSpec extends WordSpec {
} }
} }
val sourceXml: Node = XML.loadFile("src/test/resources/templates/general/test_valid.xml") val sourceXml: Node = XML.load(getClass.getResource("/templates/general/test_valid.xml"))
val template = Template(sourceXml) val template = Template(sourceXml)
assert(template.isInstanceOf[Template]) assert(template.isInstanceOf[Template])
...@@ -124,7 +124,7 @@ class TemplateSpec extends WordSpec { ...@@ -124,7 +124,7 @@ class TemplateSpec extends WordSpec {
} }
} }
val sourceXml: Node = XML.loadFile("src/test/resources/templates/general/test_valid.xml") val sourceXml: Node = XML.load(getClass.getResource("/templates/general/test_valid.xml"))
assertThrows[Exception] { assertThrows[Exception] {
val template = Template(sourceXml) val template = Template(sourceXml)
......
...@@ -8,15 +8,15 @@ class XMLValidSpec extends WordSpec { ...@@ -8,15 +8,15 @@ class XMLValidSpec extends WordSpec {
"XMLValid" can { "XMLValid" can {
"envoke parser:SAXParser if schema is valid" in { "envoke parser:SAXParser if schema is valid" in {
val validXml = XMLValid("src/test/resources/xmlvalid/test_valid.xsd") val validXml = XMLValid(getClass.getResource("/xmlvalid/test_valid.xsd"))
assert(validXml.parser.isInstanceOf[SAXParser]) assert(validXml.parser.isInstanceOf[SAXParser])
} }
} }
it should { it should {
"successfully loadFile(xmlPath) with well formed and valid xml" in { "successfully loadFile(xmlPath) with well formed and valid xml" in {
val validXml = XMLValid("src/test/resources/xmlvalid/test_valid.xsd") val validXml = XMLValid(getClass.getResource("/xmlvalid/test_valid.xsd"))
val xml = validXml.loadFile("src/test/resources/xmlvalid/test_valid.xml") val xml = validXml.load(getClass.getResource("/xmlvalid/test_valid.xml"))
assert(xml.isInstanceOf[Node]) assert(xml.isInstanceOf[Node])
} }
} }
...@@ -24,7 +24,7 @@ class XMLValidSpec extends WordSpec { ...@@ -24,7 +24,7 @@ class XMLValidSpec extends WordSpec {
it should { it should {
"throw exception with nonexisting schema" in { "throw exception with nonexisting schema" in {
assertThrows[Exception] { assertThrows[Exception] {
val validXml = XMLValid("src/test/resources/xmlvalid/test_foo.xsd") val validXml = XMLValid(getClass.getResource("/xmlvalid/test_foo.xsd"))
} }
} }
} }
...@@ -32,7 +32,7 @@ class XMLValidSpec extends WordSpec { ...@@ -32,7 +32,7 @@ class XMLValidSpec extends WordSpec {
it should { it should {
"throw exception with invalid schema" in { "throw exception with invalid schema" in {
assertThrows[Exception] { assertThrows[Exception] {
val validXml = XMLValid("src/test/resources/xmlvalid/test_invalid.xsd") val validXml = XMLValid(getClass.getResource("/xmlvalid/test_invalid.xsd"))
} }
} }
} }
...@@ -40,8 +40,8 @@ class XMLValidSpec extends WordSpec { ...@@ -40,8 +40,8 @@ class XMLValidSpec extends WordSpec {
it should { it should {
"throw exception in loadFile(xmlPath) with nonexisting xml" in { "throw exception in loadFile(xmlPath) with nonexisting xml" in {
assertThrows[Exception] { assertThrows[Exception] {
val validXml = XMLValid("src/test/resources/xmlvalid/test_valid.xsd") val validXml = XMLValid(getClass.getResource("/xmlvalid/test_valid.xsd"))
val xml = validXml.loadFile("src/test/resources/xmlvalid/test_foo.xml") val xml = validXml.load(getClass.getResource("/xmlvalid/test_foo.xml"))
} }
} }
} }
...@@ -49,8 +49,8 @@ class XMLValidSpec extends WordSpec { ...@@ -49,8 +49,8 @@ class XMLValidSpec extends WordSpec {
it should { it should {
"throw exception in loadFile(xmlPath) with well formed but invalid xml" in { "throw exception in loadFile(xmlPath) with well formed but invalid xml" in {
assertThrows[Exception] { assertThrows[Exception] {
val validXml = XMLValid("src/test/resources/xmlvalid/test.xsd") val validXml = XMLValid(getClass.getResource("/xmlvalid/test.xsd"))
val xml = validXml.loadFile("src/test/resources/xmlvalid/test_invalid.xml") val xml = validXml.load(getClass.getResource("/xmlvalid/test_invalid.xml"))
} }
} }
} }
...@@ -58,8 +58,8 @@ class XMLValidSpec extends WordSpec { ...@@ -58,8 +58,8 @@ class XMLValidSpec extends WordSpec {
it should { it should {
"throw exception with error xml" in { "throw exception with error xml" in {
assertThrows[Exception] { assertThrows[Exception] {
val validXml = XMLValid("src/test/resources/xmlvalid/test.xsd") val validXml = XMLValid(getClass.getResource("/xmlvalid/test.xsd"))
val xml = validXml.loadFile("src/test/resources/xmlvalid/test_error.xml") val xml = validXml.load(getClass.getResource("/xmlvalid/test_error.xml"))
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment