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


##########
packages/dmn-marshaller/tests/dmnValidation.test.ts:
##########
@@ -0,0 +1,142 @@
+/*
+ * 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 { executeJBangScript } from "./jbang/jbangManager";
+
+/**
+ * This test suite validates the xml produced 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/ListReplaceEvaluate.dmn",
+  "../valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+  "../valid_models/DMNv1_5/NegationOfDurationEvaluate.dmn",
+  "../valid_models/DMNv1_5/TypeConstraintsChecks.dmn",
+  "../valid_models/DMNv1_x/multiple/Financial.dmn",
+  //FULL_1_x_MULTIPLE_DIRECTORY + "Imported_Traffic_Violation.dmn",
+  "../valid_models/DMNv1_x/multiple/stdlib.dmn",
+  "../valid_models/DMNv1_x/allTypes.dmn",
+  //FULL_1_x_DIRECTORY + "dtevent.dmn",
+  //FULL_1_x_DIRECTORY + "habitability.dmn",
+  "../valid_models/DMNv1_x/loan.dmn",
+  //FULL_1_x_DIRECTORY + "LoanEligibility.dmn",
+  "../valid_models/DMNv1_x/OneOfEachType.dmn",
+  //FULL_1_x_DIRECTORY + "Prequalification.dmn",
+  "../valid_models/DMNv1_x/testWithExtensionElements.dmn",
+  //FULL_1_x_DIRECTORY + "Traffic Violation Simple.dmn",
+];
+
+const dmnTestingImportedModels = [
+  {
+    imported: "../valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+    importer: "../valid_models/DMNv1_5/Importing_EmptyNamed_Model.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: FULL_1_x_MULTIPLE_DIRECTORY + 
"Imported_Traffic_Violation.dmn",
+  //   importer: FULL_1_x_MULTIPLE_DIRECTORY + "Traffic Violation With 
Import.dmn",
+  // },
+];
+
+const marshalledXMLDirectory = path.join(__dirname, 
"../dist-tests/marshalled-dmn-file");
+const jbangDmnValidationScriptPath = path.join(__dirname, 
"./jbang/dmnValidation.java");
+
+describe("validation", () => {
+  beforeAll(() => {
+    if (fs.existsSync(marshalledXMLDirectory)) {
+      fs.rmSync(marshalledXMLDirectory, { recursive: true });
+    }
+    fs.mkdirSync(marshalledXMLDirectory, { 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(normalizedFsPathRelativeToTheFile.substring(normalizedFsPathRelativeToTheFile.lastIndexOf(path.sep)
 + 1), () => {
+    const marshalledXMLFilePath = 
parseXMLAndWriteInFile(normalizedFsPathRelativeToTheFile);
+
+    try {
+      executeJBangScript(jbangDmnValidationScriptPath, marshalledXMLFilePath);
+    } catch (error) {
+      const fileName = normalizedFsPathRelativeToTheFile.substring(
+        normalizedFsPathRelativeToTheFile.lastIndexOf(path.sep) + 1
+      );
+      fail("Validation of " + fileName + " failed! Please scroll up to DMN 
VALIDATION ERROR message to see the reason");
+    }
+  });
+}
+
+function testImportedFile(normalizedFsPathRelativeToTheFiles: { imported: 
string; importer: string }) {
+  test(
+    normalizedFsPathRelativeToTheFiles.importer.substring(
+      normalizedFsPathRelativeToTheFiles.importer.lastIndexOf(path.sep) + 1
+    ),
+    () => {
+      const importedMarshalledXMLFilePath = 
parseXMLAndWriteInFile(normalizedFsPathRelativeToTheFiles.imported);
+      const importerMarshalledXMLFilePath = 
parseXMLAndWriteInFile(normalizedFsPathRelativeToTheFiles.importer);
+
+      try {
+        executeJBangScript(jbangDmnValidationScriptPath, 
importedMarshalledXMLFilePath, importerMarshalledXMLFilePath);
+      } catch (error) {
+        const fileName = normalizedFsPathRelativeToTheFiles.importer.substring(
+          normalizedFsPathRelativeToTheFiles.importer.lastIndexOf(path.sep) + 1
+        );
+        fail("Validation of " + error + " failed! Please scroll up to DMN 
VALIDATION ERROR message to see the reason");

Review Comment:
   ```suggestion
           fail("Validation of " + fileName + " failed! Please scroll up to DMN 
VALIDATION ERROR message to see the reason");
   ```



##########
packages/dmn-marshaller/tests/jbang/dmnValidation.java:
##########


Review Comment:
   what is the difference between this file, `dmnValidation.java` and 
`dmnSemanticComparision.java` please?



##########
packages/dmn-marshaller/tests/jbang/jbangManager.ts:
##########
@@ -0,0 +1,33 @@
+/*
+ * 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 path from "path";
+const jbang = require("@jbangdev/jbang");
+const buildEnv = require("../../env");
+
+export function executeJBangScript(scriptPath: string, ...args: string[]) {
+  /* Windows requires double quotes to wrap the argument, while in POSIX it 
must be wrapped by single quotes */
+  const isWindowsPath = path.sep !== "/";
+  const quoteChar = isWindowsPath ? '"' : "'";
+  jbang.exec("--java 17", "properties@jbangdev", "java.version");
+  jbang.exec(
+    "-Dkogito-runtime.version=" + buildEnv.env.kogitoRuntime.version,

Review Comment:
   am I correct `kogito-runtime.version` as property, its name, is defined in 
`drools` repository? maybe some link/comment for it would help in case it is 
changed in future?



##########
packages/dmn-testing-models/install.js:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+const buildEnv = require("./env");
+const { setup } = require("@kie-tools/maven-config-setup-helper");
+
+setup(`
+    -Drevision=${buildEnv.env.dmnTestingModel.version}
+    -Dversion.org.kie.kogito=${buildEnv.env.kogitoRuntime.version}

Review Comment:
   is it correct here we do not use `kogito-runtime.version`?



-- 
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