You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sl...@apache.org on 2019/11/07 14:02:55 UTC

[incubator-daffodil] branch master updated: Adds 2 arg constructor for TDML Runner

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

slawrence pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git


The following commit(s) were added to refs/heads/master by this push:
     new fd6007a  Adds 2 arg constructor for TDML Runner
fd6007a is described below

commit fd6007ab5c2e326daca225136344ee09a37f0516
Author: olabusayoT <50...@users.noreply.github.com>
AuthorDate: Tue Nov 5 15:54:48 2019 -0500

    Adds 2 arg constructor for TDML Runner
    
    -- useful for Java calls
    -- fixes typo in UDF tests
    -- Adds unit tests for RunnerFactory constructors
    
    DAFFODIL-2229
---
 .../org/apache/daffodil/udf/TestCLIUdfs.scala      |  2 +-
 .../org/apache/daffodil/tdml/RunnerFactory.scala   | 15 +++++-
 .../apache/daffodil/tdml/TestRunnerFactory.java    | 56 ++++++++++++++++++++++
 .../org/apache/daffodil/tdml/genericTdml.tdml      | 46 ++++++++++++++++++
 .../apache/daffodil/udf/TestUdfsInSchemas.scala    |  2 +-
 eclipse-projects/tdml-processor/.classpath         |  1 +
 6 files changed, 119 insertions(+), 3 deletions(-)

diff --git a/daffodil-cli/src/it/scala/org/apache/daffodil/udf/TestCLIUdfs.scala b/daffodil-cli/src/it/scala/org/apache/daffodil/udf/TestCLIUdfs.scala
index 00ae136..44b5160 100644
--- a/daffodil-cli/src/it/scala/org/apache/daffodil/udf/TestCLIUdfs.scala
+++ b/daffodil-cli/src/it/scala/org/apache/daffodil/udf/TestCLIUdfs.scala
@@ -421,7 +421,7 @@ class TestCLIUdfs {
    * Tests the case when a function class:
    *   throws processing error on evaluate
    */
-  @Test def test_UDFClass_ProcessingErrroOnEvaluate() {
+  @Test def test_UDFClass_ProcessingErrorOnEvaluate() {
     val schemaFile = Util.daffodilPath("daffodil-udf/src/test/resources/org/apache/daffodil/udf/genericUdfSchema.xsd")
     val (testSchemaFile) = if (Util.isWindows) (Util.cmdConvert(schemaFile)) else (schemaFile)
 
diff --git a/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/RunnerFactory.scala b/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/RunnerFactory.scala
index 08c19e4..e34169e 100644
--- a/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/RunnerFactory.scala
+++ b/daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/RunnerFactory.scala
@@ -76,7 +76,7 @@ object Runner {
    * Negative tests must fail, but error messages aren't compared.
    */
   def defaultShouldDoErrorComparisonOnCrossTests = false
-  
+
   /**
    * By default we don't cross test warning messages because they are too varied.
    */
@@ -98,6 +98,15 @@ class Runner private (elem: scala.xml.Elem, dir: String, file: String,
   defaultValidationDefault: String = Runner.defaultValidationDefaultDefault,
   defaultImplementationsDefault: Seq[String] = Runner.defaultImplementationsDefaultDefault) {
 
+  /*
+   * these constructors are for use by Java programs
+   */
+  def this(dir: String, file:String) =
+    this(null, dir, file)
+
+  def this(elem: scala.xml.Elem) =
+    this(elem, null, null)
+
   if (elem ne null)
     Assert.usage((dir eq null) && (file eq null))
   else
@@ -135,6 +144,10 @@ class Runner private (elem: scala.xml.Elem, dir: String, file: String,
       getTS.setDebugging(false)
     }
 
+  def runOneTest(testName: String) {
+    runOneTest(testName, None, false)
+  }
+
   /**
    *  Call this from an @AfterClass method
    *  to drop any state (like the test suite object) so we don't leak
diff --git a/daffodil-tdml-processor/src/test/java/org/apache/daffodil/tdml/TestRunnerFactory.java b/daffodil-tdml-processor/src/test/java/org/apache/daffodil/tdml/TestRunnerFactory.java
new file mode 100644
index 0000000..9606285
--- /dev/null
+++ b/daffodil-tdml-processor/src/test/java/org/apache/daffodil/tdml/TestRunnerFactory.java
@@ -0,0 +1,56 @@
+/*
+ * 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.tdml;
+
+import java.util.Arrays;
+
+import org.apache.daffodil.util.Misc;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+
+import scala.collection.JavaConverters;
+import scala.xml.Elem;
+import scala.xml.XML;
+
+public class TestRunnerFactory {
+  String testDir = "/org/apache/daffodil/tdml/";
+  String testTdmlFile = "genericTdml.tdml";
+
+  @Test
+  public void testPrimaryConstructor() {
+    Runner runner = new Runner(null, testDir, testTdmlFile, true, true, false, NoRoundTrip$.MODULE$,
+        "off", JavaConverters.asScalaBufferConverter(Arrays.asList("daffodil", "ibm")).asScala());
+    runner.runOneTest("testPass");
+  }
+
+  @Test
+  public void testOneArgConstructor() {
+    String tdmlUri = Misc.getRequiredResource("org/apache/daffodil/tdml/genericTdml.tdml")
+        .toString();
+    InputSource tdmlResource = new InputSource(tdmlUri);
+    Elem testXml = (Elem) XML.load(tdmlResource);
+    Runner runner = new Runner(testXml);
+    runner.runOneTest("testPass");
+  }
+
+  @Test
+  public void testTwoArgConstructor() {
+    Runner runner = new Runner(testDir, testTdmlFile);
+    runner.runOneTest("testPass");
+  }
+}
diff --git a/daffodil-tdml-processor/src/test/resources/org/apache/daffodil/tdml/genericTdml.tdml b/daffodil-tdml-processor/src/test/resources/org/apache/daffodil/tdml/genericTdml.tdml
new file mode 100644
index 0000000..7a6e227
--- /dev/null
+++ b/daffodil-tdml-processor/src/test/resources/org/apache/daffodil/tdml/genericTdml.tdml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<tdml:testSuite suiteName="Info" description="CLI"
+  xmlns:ex="http://example.com" xmlns="http://example.com"
+  xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+  <tdml:defineSchema name="s1">
+    <xs:include
+      schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+    <dfdl:format ref="ex:GeneralFormat" />
+
+    <xs:element name="e1" dfdl:lengthKind="explicit" dfdl:length="2"
+      type="xs:int" />
+
+  </tdml:defineSchema>
+
+  <tdml:parserTestCase name="testPass" root="e1" model="s1"
+    description="This test should pass.">
+    <tdml:document>42</tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <e1>42</e1>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+</tdml:testSuite>
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/udf/TestUdfsInSchemas.scala b/daffodil-test/src/test/scala/org/apache/daffodil/udf/TestUdfsInSchemas.scala
index 5cba7b4..e5cc33f 100644
--- a/daffodil-test/src/test/scala/org/apache/daffodil/udf/TestUdfsInSchemas.scala
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/udf/TestUdfsInSchemas.scala
@@ -58,4 +58,4 @@ class TestUdfsInSchemas {
   @Test def test_javaBigDecimalParamRetType() { runner.runOneTest("test_javaBigDecimalParamRetType") }
   @Test def test_stringParamRetType() { runner.runOneTest("test_stringParamRetType") }
 
-}
\ No newline at end of file
+}
diff --git a/eclipse-projects/tdml-processor/.classpath b/eclipse-projects/tdml-processor/.classpath
index 9507c04..ee68883 100644
--- a/eclipse-projects/tdml-processor/.classpath
+++ b/eclipse-projects/tdml-processor/.classpath
@@ -5,6 +5,7 @@
   <classpathentry kind="src" path="src/main/scala"/>
   <classpathentry kind="src" path="src/test/scala"/>
   <classpathentry kind="src" path="src/test/resources"/>
+  <classpathentry kind="src" path="src/test/java"/>
   <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
   <classpathentry combineaccessrules="false" kind="src" path="/daffodil-core"/>