This is an automated email from the ASF dual-hosted git repository.

olabusayo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new c1c8e9890 Add TDML Exception when there's no Expected Data
c1c8e9890 is described below

commit c1c8e9890f772e487939a46b18c2b0e931446c43
Author: olabusayoT <[email protected]>
AuthorDate: Tue Nov 12 15:40:23 2024 -0500

    Add TDML Exception when there's no Expected Data
    
    - 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
---
 .../org/apache/daffodil/tdml/TDMLRunner.scala      |  6 ++-
 .../daffodil/processor/tdml/TestTDMLRunner2.scala  | 43 +++++++++++++++++++++-
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git 
a/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala 
b/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
index ad25deacf..e984765d9 100644
--- a/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
+++ b/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
@@ -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
+        )
     }
 
   }
diff --git 
a/daffodil-tdml-processor/src/test/scala/org/apache/daffodil/processor/tdml/TestTDMLRunner2.scala
 
b/daffodil-tdml-processor/src/test/scala/org/apache/daffodil/processor/tdml/TestTDMLRunner2.scala
index 691e29924..2a9c336ea 100644
--- 
a/daffodil-tdml-processor/src/test/scala/org/apache/daffodil/processor/tdml/TestTDMLRunner2.scala
+++ 
b/daffodil-tdml-processor/src/test/scala/org/apache/daffodil/processor/tdml/TestTDMLRunner2.scala
@@ -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
@@ -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">
@@ -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")

Reply via email to