yesamer commented on code in PR #2207:
URL: 
https://github.com/apache/incubator-kie-tools/pull/2207#discussion_r1570129537


##########
packages/dmn-marshaller/tests/dmnValidation.test.ts:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.
+ */
+
+import * as fs from "fs";
+import * as path from "path";
+import { getMarshaller } from "@kie-tools/dmn-marshaller";
+import { fail } from "assert";
+import {
+  DmnBackendCompatibilityScript,
+  executeJBangScript,
+} from "@kie-tools/dmn-marshaller-backend-compatibility-tester";
+
+/**
+ * This test suite validates the xml produced (parsed and built) by the 
marshaller relying on KIE DMN Validator
+ * 
(https://github.com/apache/incubator-kie-drools/tree/main/kie-dmn/kie-dmn-validation).
+ * A JBang script is used to actually call the KIE DMN Validator Java code.
+ */
+
+const dmnTestingModelsPath = require.resolve("@kie-tools/dmn-testing-models");
+
+const dmnTestingModels = [
+  "../valid_models/DMNv1_5/AllowedValuesChecksInsideCollection.dmn",
+  "../valid_models/DMNv1_5/DateToDateTimeFunction.dmn",
+  "../valid_models/DMNv1_5/ForLoopDatesEvaluate.dmn",
+  "../valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+  "../valid_models/DMNv1_5/ListReplaceEvaluate.dmn",
+  "../valid_models/DMNv1_5/NegationOfDurationEvaluate.dmn",
+  "../valid_models/DMNv1_5/TypeConstraintsChecks.dmn",
+  "../valid_models/DMNv1_x/multiple/Financial.dmn",
+  "../valid_models/DMNv1_x/multiple/Imported_Traffic_Violation.dmn",
+  "../valid_models/DMNv1_x/multiple/stdlib.dmn",
+  "../valid_models/DMNv1_x/allTypes.dmn",
+  "../valid_models/DMNv1_x/dtevent.dmn",
+  "../valid_models/DMNv1_x/habitability.dmn",
+  "../valid_models/DMNv1_x/loan.dmn",
+  "../valid_models/DMNv1_x/LoanEligibility.dmn",
+  "../valid_models/DMNv1_x/OneOfEachType.dmn",
+  "../valid_models/DMNv1_x/Prequalification.dmn",
+  "../valid_models/DMNv1_x/testWithExtensionElements.dmn",
+  "../valid_models/DMNv1_x/Traffic Violation Simple.dmn",
+  "../valid_models/DMNv1_x/Traffic Violation.dmn",
+];
+
+const dmnTestingImportedModels = [
+  {
+    imported: "../valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+    importer: 
"../valid_models/DMNv1_5/Importing_EmptyNamed_Model_With_Href_Namespace.dmn",
+  },
+  {
+    imported: "../valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+    importer: 
"../valid_models/DMNv1_5/Importing_EmptyNamed_Model_Without_Href_Namespace.dmn",
+  },
+  {
+    imported: "../valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+    importer: "../valid_models/DMNv1_5/Importing_Named_Model.dmn",
+  },
+  {
+    imported: "../valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+    importer: 
"../valid_models/DMNv1_5/Importing_OverridingEmptyNamed_Model.dmn",
+  },
+  {
+    imported: 
"../valid_models/DMNv1_x/multiple/Imported_Traffic_Violation.dmn",
+    importer: "../valid_models/DMNv1_x/multiple/Traffic Violation With 
Import.dmn",
+  },
+];
+export const dmnValidationGeneratedFilesDirectory = path.join(__dirname, 
"../dist-tests/dmnValidation-generated-files");
+
+describe("DMN Validation", () => {
+  beforeAll(() => {
+    if (fs.existsSync(dmnValidationGeneratedFilesDirectory)) {
+      fs.rmSync(dmnValidationGeneratedFilesDirectory, { recursive: true });
+    }
+    fs.mkdirSync(dmnValidationGeneratedFilesDirectory, { recursive: true });
+  });
+
+  for (const file of dmnTestingModels) {
+    testFile(path.join(dmnTestingModelsPath, file));
+  }
+  for (const file of dmnTestingImportedModels) {
+    file.imported = path.join(dmnTestingModelsPath, file.imported);
+    file.importer = path.join(dmnTestingModelsPath, file.importer);
+    testImportedFile(file);
+  }
+});
+
+function testFile(normalizedFsPathRelativeToTheFile: string) {
+  test(
+    "DMN Validation: " +
+      
normalizedFsPathRelativeToTheFile.substring(normalizedFsPathRelativeToTheFile.lastIndexOf(path.sep)
 + 1),
+    () => {
+      const generatedXMLFilePath = 
parseXMLAndWriteInFile(normalizedFsPathRelativeToTheFile);
+
+      try {
+        executeJBangScript(
+          DmnBackendCompatibilityScript.DMN_VALIDATION,
+          "--command=no_imports",
+          "--dmnFilePath=" + generatedXMLFilePath
+        );
+      } catch (error) {
+        fail(error.cause);
+      }
+    }
+  );
+}
+
+function testImportedFile(normalizedFsPathRelativeToTheFiles: { imported: 
string; importer: string }) {
+  test(
+    "DMN Validation: " +
+      normalizedFsPathRelativeToTheFiles.importer.substring(
+        normalizedFsPathRelativeToTheFiles.importer.lastIndexOf(path.sep) + 1
+      ),
+    () => {
+      const importedGeneratedXMLFilePath = 
parseXMLAndWriteInFile(normalizedFsPathRelativeToTheFiles.imported);
+      const importerGeneratedXMLFilePath = 
parseXMLAndWriteInFile(normalizedFsPathRelativeToTheFiles.importer);
+
+      try {
+        executeJBangScript(
+          DmnBackendCompatibilityScript.DMN_VALIDATION,
+          "--command=with_imports",
+          "--dmnFilePath=" + importedGeneratedXMLFilePath,
+          "--importedDmnFilesPaths=" + importerGeneratedXMLFilePath
+        );
+      } catch (error) {
+        fail(error.cause);
+      }
+    }
+  );
+}
+
+function parseXMLAndWriteInFile(normalizedFsPathRelativeToTheFile: string): 
string {

Review Comment:
   Done!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to