Skip to content

Commit

Permalink
Add TDML Exception when there's no Expected Data
Browse files Browse the repository at this point in the history
- note this only gets thrown where there is a warning as well, as UnparserTestCase requires 2 children. So if you just have an infoset and nothing else, you'll get an XSD error.

DAFFODIL-2289
  • Loading branch information
olabusayoT committed Nov 12, 2024
1 parent fd4be92 commit 97d9cea
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,11 @@ case class UnparserTestCase(ptc: NodeSeq, parentArg: DFDLTestSuite)
}
}
}
case _ => Assert.impossibleCase()
case _ =>
throw TDMLException(
"Either tdml:document or tdml:errors must be present in the test.",
implString
)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.apache.daffodil.lib.Implicits.using
import org.apache.daffodil.lib.xml.XMLUtils
import org.apache.daffodil.tdml.Document
import org.apache.daffodil.tdml.Runner
import org.apache.daffodil.tdml.TDMLException

import org.junit.AfterClass
import org.junit.Assert.assertEquals
Expand Down Expand Up @@ -534,7 +535,7 @@ abc # a comment
runner.reset
}

@Test def testTDMLUnparse(): Unit = {
@Test def testTDMLUnparse1(): Unit = {
val testSuite = <ts:testSuite xmlns:ts={tdml} xmlns:tns={tns} xmlns:dfdl={dfdl} xmlns:xs={
xsd
} xmlns:xsi={xsi} suiteName="theSuiteName">
Expand All @@ -558,6 +559,46 @@ abc # a comment
runner.reset
}

@Test def testTDMLUnparse2(): Unit = {
val testSuite = <ts:testSuite xmlns:ts={tdml} xmlns:tns={tns} xmlns:dfdl={dfdl} xmlns:xs={
xsd
} xmlns:xsi={xsi} suiteName="theSuiteName">
<ts:defineSchema name="unparseTestSchema1">
<xs:include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
<dfdl:format ref="tns:GeneralFormat"/>
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element name="e1" type="xs:string" dfdl:lengthKind="explicit" dfdl:length="{ 9 }"/>
<xs:element name="len" type="xs:string" dfdl:inputValueCalc="{ fn:string-length(../e1)}"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</ts:defineSchema>
<ts:unparserTestCase ID="some identifier" name="testTDMLUnparse" root="data" model="unparseTestSchema1">
<ts:infoset>
<ts:dfdlInfoset>
<data xmlns={example}>
<e1>123456789</e1>
<len/>
</data>
</ts:dfdlInfoset>
</ts:infoset>
<ts:warnings>
<ts:warning/>
</ts:warnings>
</ts:unparserTestCase>
</ts:testSuite>

val runner = Runner(testSuite)
val err = intercept[TDMLException] {
runner.runOneTest("testTDMLUnparse")
}
val actualMessage = err.getMessage()
assertTrue(actualMessage.contains("Either tdml:document or tdml:errors must be present"))
runner.reset
}

@Test def test_quote_test1() = {
val runner = Runner("/test/tdml/", "tdmlQuoting.tdml")
runner.runOneTest("quote_test1")
Expand Down

0 comments on commit 97d9cea

Please sign in to comment.