Skip to content
Permalink
Browse files
Support embedding Schematron rules in DFDL schemas.
DAFFODIL-2446
  • Loading branch information
jw3 committed Jan 21, 2021
1 parent c2357f5 commit 583a91d427ee6f055e2c1957e493452d837e25c3
Showing 37 changed files with 1,562 additions and 126 deletions.
63 LICENSE
@@ -366,22 +366,47 @@ subcomponents is subject to the terms and conditions of the following licenses.
- daffodil-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-en.xhtml
The content is available under the MIT License:

Copyright (c) 2004-2010 Rick Jellife and Academia Sinica Computing Centre, Taiwan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Copyright (c) 2004-2010 Rick Jellife and Academia Sinica Computing Centre, Taiwan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

This product bundles content from the Schematron converters, including
the following files:
- daffodil-schematron/src/main/resources/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl
The content is available under the MIT License:

Copyright (c) 2002-2010 Rick Jelliffe and Topologi Pty. Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -76,7 +76,7 @@ lazy val udf = Project("daffodil-udf", file("daffodil-udf")).config
.settings(commonSettings)

lazy val schematron = Project("daffodil-schematron", file("daffodil-schematron"))
.dependsOn(lib)
.dependsOn(lib, sapi % Test)
.settings(commonSettings)
.settings(libraryDependencies ++= Dependencies.schematron)
.configs(IntegrationTest)
@@ -849,30 +849,55 @@ subcomponents is subject to the terms and conditions of the following licenses.

This product bundles content from the Schematron "skeleton" - XSLT implementation, including
the following files:
- daffodil-schematron/src/main/resources/iso-schematron-xslt2/iso_abstract_expand.xsl
- daffodil-schematron/src/main/resources/iso-schematron-xslt2/iso_dsdl_include.xsl
- daffodil-schematron/src/main/resources/iso-schematron-xslt2/iso_schematron_message_xslt2.xsl
- daffodil-schematron/src/main/resources/iso-schematron-xslt2/iso_schematron_skeleton_for_saxon.xsl
- daffodil-schematron/src/main/resources/iso-schematron-xslt2/iso_svrl_for_xslt2.xsl
- daffodil-schematron/src/main/resources/iso-schematron-xslt2/sch-messages-en.xhtml
- iso-schematron-xslt2/iso_abstract_expand.xsl in lib/org.apache.daffodil.daffodil-schematron-<VERSION>.jar
- iso-schematron-xslt2/iso_dsdl_include.xsl in lib/org.apache.daffodil.daffodil-schematron-<VERSION>.jar
- iso-schematron-xslt2/iso_schematron_message_xslt2.xsl in lib/org.apache.daffodil.daffodil-schematron-<VERSION>.jar
- iso-schematron-xslt2/iso_schematron_skeleton_for_saxon.xsl in lib/org.apache.daffodil.daffodil-schematron-<VERSION>.jar
- iso-schematron-xslt2/iso_svrl_for_xslt2.xsl in lib/org.apache.daffodil.daffodil-schematron-<VERSION>.jar
- iso-schematron-xslt2/sch-messages-en.xhtml in lib/org.apache.daffodil.daffodil-schematron-<VERSION>.jar
The content is available under the MIT License:

Copyright (c) 2004-2010 Rick Jellife and Academia Sinica Computing Centre, Taiwan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Copyright (c) 2004-2010 Rick Jellife and Academia Sinica Computing Centre, Taiwan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

This product bundles content from the Schematron converters, including
the following files:
- iso-schematron-xslt2/ExtractSchFromXSD-2.xsl in lib/org.apache.daffodil.daffodil-schematron-<VERSION>.jar
The content is available under the MIT License:

Copyright (c) 2002-2010 Rick Jelliffe and Topologi Pty. Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -0,0 +1 @@
2f6481e6-542c-11eb-ae93-0242ac130002
@@ -0,0 +1,107 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.daffodil.schematron

import net.sf.expectit.matcher.Matchers.sequence
import org.junit.Test

import java.util.UUID

class TestEmbedded {
@Test def alwaysFails(): Unit = withShell(FailureErrorCode) {
val data = mktmp(UUID.randomUUID.toString)
val schema = "xsd/always-fails-1.dfdl.xsd"
s"parse --validate schematron={{$schema}} -s {{$schema}} $data" -> lineEndsWith("</always-fails>")
}

@Test def unitPriceWithoutValidation(): Unit = withShell() {
val data = mktmp("widget,monday,1,$5.00,$5.00")
val schema = "xsd/unit_price.dfdl.xsd"
s"parse -r list -s {{$schema}} $data" -> lineEndsWith("</ex:list>")
}

@Test def unitPriceWithValidation(): Unit = withShell(FailureErrorCode, JoinStdError) {
val data = mktmp("widget,monday,1,$5.00,$6.00")
val schema = "xsd/unit_price.dfdl.xsd"
s"parse -r list --validate schematron={{$schema}} -s {{$schema}} $data" -> sequence(
lineEndsWith("</ex:list>"),
anyLines(3)
)
}

@Test def unitPriceWithValidationCheckMessage(): Unit = withShell(FailureErrorCode, JoinStdError) {
val data = mktmp("widget,monday,5,$5.00,$25.00||gadget,tuesday,1,$10.00,$11.00")
val schema = "xsd/unit_price.dfdl.xsd"
s"parse -r list --validate schematron={{$schema}} -s {{$schema}} $data" -> sequence(
lineEndsWith("</ex:list>"),
lineEndsWith("[error] Validation Error: wrong unit price for gadget, tuesday"),
anyLines(2)
)
}

@Test def extends1(): Unit = withShell() {
val data = mktmp("bob;l;smith")
val schema = "xsd/extends-1.dfdl.xsd"
s"parse --validate schematron={{$schema}} -s {{$schema}} $data" -> lineEndsWith("</name>")
}

@Test def extends2(): Unit = withShell() {
val data = mktmp("ob;;smith")
val schema = "xsd/extends-1.dfdl.xsd"
s"parse --validate schematron={{$schema}} -s {{$schema}} $data" -> lineEndsWith("</name>")
}

@Test def extends3(): Unit = withShell(FailureErrorCode, JoinStdError) {
val data = mktmp(";;smith")
val schema = "xsd/extends-1.dfdl.xsd"
s"parse --validate schematron={{$schema}} -s {{$schema}} $data" -> validationError("first is blank")
}

@Test def extends4(): Unit = withShell(FailureErrorCode, JoinStdError) {
val data = mktmp("bob;l;")
val schema = "xsd/extends-1.dfdl.xsd"
s"parse --validate schematron={{$schema}} -s {{$schema}} $data" -> validationError("last is blank")
}

@Test def extends5(): Unit = withShell(FailureErrorCode, JoinStdError) {
val data = mktmp(";l;")
val schema = "xsd/extends-1.dfdl.xsd"
s"parse --validate schematron={{$schema}} -s {{$schema}} $data" -> sequence(
validationError("last is blank"),
validationError("first is blank")
)
}

@Test def testWithNs1(): Unit = withShell() {
val data = mktmp("0;1")
val schema = "xsd/with-ns-1.dfdl.xsd"
s"parse --validate schematron={{$schema}} -s {{$schema}} $data" -> lineEndsWith("</myns:interval>")
}

@Test def testWithNs2(): Unit = withShell(FailureErrorCode, JoinStdError) {
val data = mktmp("2;1")
val schema = "xsd/with-ns-1.dfdl.xsd"
s"parse --validate schematron={{$schema}} -s {{$schema}} $data" -> validationError()
}

@Test def testWithNs3(): Unit = withShell(FailureErrorCode, JoinStdError) {
val data = mktmp("0;0")
val schema = "xsd/with-ns-1.dfdl.xsd"
s"parse --validate schematron={{$schema}} -s {{$schema}} $data" -> validationError()
}
}
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.daffodil.schematron

import org.junit.Test

class TestValidating {
val data = "input/uuid.txt"
val uuid = "xsd/string.dfdl.xsd"
val never = "sch/never-fails.sch"
val always = "sch/always-fails.sch"

val alwaysResult = regexLine("<.+-fails>2f6481e6-542c-11eb-ae93-0242ac130002</.+-fails>")

// always fails sch, but no validate flag so it should pass
@Test def nonShouldPass(): Unit = withShell() {
s"parse -s {{$uuid}} {$data}" -> alwaysResult
}

// always fails sch, with validate flag should fail
@Test def failShouldFail(): Unit = withShell(FailureErrorCode) {
s"parse --validate schematron={{$always}} -s {{$uuid}} {$data}" -> alwaysResult
}

// never fails sch, with validate flag should pass
@Test def passShouldPass(): Unit = withShell() {
s"parse --validate schematron={{$never}} -s {{$uuid}} {$data}" -> alwaysResult
}
}

0 comments on commit 583a91d

Please sign in to comment.