From 8cf768d23127c54ca3b4c79e01dee0599dee0c08 Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Tue, 12 May 2020 16:13:29 +0200
Subject: [PATCH] SqlLib_tests updated

---
 process/SqlLib_tests/process.js | 36 +++++++++++++--------------
 process/UnitTest_lib/process.js | 43 +++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 18 deletions(-)

diff --git a/process/SqlLib_tests/process.js b/process/SqlLib_tests/process.js
index e1b78e43af..924162e2a4 100644
--- a/process/SqlLib_tests/process.js
+++ b/process/SqlLib_tests/process.js
@@ -646,68 +646,68 @@ var mandatoryErrorTests = new TestSuite([
     ["and without parameter should error", function(pTester)
     {
         new SqlBuilder().where().or();
-    }, SqlBuilder.ERROR_NO_PARAMETER_PROVIDED()],
+    }, SqlBuilder._ERROR_NO_PARAMETER_PROVIDED()],
 
     ["and with null as value should error", function(pTester)
     {
         new SqlBuilder().where().or("PERSON.FIRSTNAME", null);
-    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+    }, SqlBuilder._ERROR_VALUE_IS_MANDATORY()],
 
     ["and with undefined as value should error", function(pTester)
     {
         new SqlBuilder().where().or("PERSON.FIRSTNAME", undefined);
-    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+    }, SqlBuilder._ERROR_VALUE_IS_MANDATORY()],
 
     ["and with a jdito-var containing null should error", function(pTester)
     {
         vars.set("$global.TestingVarNull", null);
         
         new SqlBuilder().where().or("PERSON.FIRSTNAME", "$global.TestingVarNull");
-    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY_JDITO_VAR()],
+    }, SqlBuilder._ERROR_VALUE_IS_MANDATORY_JDITO_VAR()],
 
     ["and with an empty sql-builder as subquery should error", function(pTester)
     {        
         new SqlBuilder().where().or("PERSON.FIRSTNAME", new SqlBuilder());
-    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+    }, SqlBuilder._ERROR_VALUE_IS_MANDATORY()],
 
     ["and with an empty prepared statement as subquery should error", function(pTester)
     {        
         new SqlBuilder().where().or("PERSON.FIRSTNAME", ["", []]);
-    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+    }, SqlBuilder._ERROR_VALUE_IS_MANDATORY()],
 
 
 // or
     ["or without parameter should error", function(pTester)
     {
         new SqlBuilder().where().or();
-    }, SqlBuilder.ERROR_NO_PARAMETER_PROVIDED()],
+    }, SqlBuilder._ERROR_NO_PARAMETER_PROVIDED()],
 
     ["or with null as value should error", function(pTester)
     {
         new SqlBuilder().where().or("PERSON.FIRSTNAME", null);
-    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+    }, SqlBuilder._ERROR_VALUE_IS_MANDATORY()],
 
     ["or with undefined as value should error", function(pTester)
     {
         new SqlBuilder().where().or("PERSON.FIRSTNAME", undefined);
-    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+    }, SqlBuilder._ERROR_VALUE_IS_MANDATORY()],
 
     ["or with a jdito-var containing null should error", function(pTester)
     {
         vars.set("$global.TestingVarNull", null);
         
         new SqlBuilder().where().or("PERSON.FIRSTNAME", "$global.TestingVarNull");
-    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY_JDITO_VAR()],
+    }, SqlBuilder._ERROR_VALUE_IS_MANDATORY_JDITO_VAR()],
 
     ["or with an empty sql-builder as subquery should error", function(pTester)
     {        
         new SqlBuilder().where().or("PERSON.FIRSTNAME", new SqlBuilder());
-    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+    }, SqlBuilder._ERROR_VALUE_IS_MANDATORY()],
 
     ["or with an empty prepared statement as subquery should error", function(pTester)
     {        
         new SqlBuilder().where().or("PERSON.FIRSTNAME", ["", []]);
-    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()],
+    }, SqlBuilder._ERROR_VALUE_IS_MANDATORY()],
 ]);
 
 var inStatementTests = new TestSuite([
@@ -766,7 +766,7 @@ var inStatementTests = new TestSuite([
     {
         new SqlBuilder()
                 .where("PERSON.LASTNAME", []);
-    }, SqlBuilder.ERROR_VALUE_IS_MANDATORY()]
+    }, SqlBuilder._ERROR_VALUE_IS_MANDATORY()]
 ]);
 
 var testConstantFunctions = new TestSuite([
@@ -886,7 +886,7 @@ var subqueryAsFieldTests = new TestSuite([
                                 .where("ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID")
                                 .and("PERSON.FIRSTNAME", "val1") // test if the value is added at the correct place
         new SqlBuilder().where(subQuery, "val2", "# = ?");
-    }, SqlBuilder.ERROR_SUBSELECT_AS_FIELD_NO_FIELD_TYPE()],
+    }, SqlBuilder._ERROR_SUBSELECT_AS_FIELD_NO_FIELD_TYPE()],
 
     ["Test if a Subselect as field should error if it is not a full select.", function(pTester)
     {
@@ -895,7 +895,7 @@ var subqueryAsFieldTests = new TestSuite([
                                 .and("PERSON.FIRSTNAME", "val1") // test if the value is added at the correct place
     
         new SqlBuilder().where(subQuery, "val2", "# = ?", SQLTYPES.VARCHAR);
-    }, SqlBuilder.ERROR_SUBSELECT_AS_FIELD_NOT_COMPLETE()]
+    }, SqlBuilder._ERROR_SUBSELECT_AS_FIELD_NOT_COMPLETE()]
 ]);
 
 var conditionFormatTests = new TestSuite([
@@ -918,17 +918,17 @@ var conditionFormatTests = new TestSuite([
     ["pCondition should fail if more than one ? exists", function(pTester)
     {
         new SqlBuilder().where("PERSON.FIRSTNAME", "val1", "? test ?")
-    }, SqlBuilder.ERROR_CONDITION_WRONG_FORMAT()],
+    }, SqlBuilder._ERROR_CONDITION_WRONG_FORMAT()],
 
     ["pCondition should fail if more than one # exists", function(pTester)
     {
         new SqlBuilder().where("PERSON.FIRSTNAME", "val1", "# test #")
-    }, SqlBuilder.ERROR_CONDITION_WRONG_FORMAT()],
+    }, SqlBuilder._ERROR_CONDITION_WRONG_FORMAT()],
 
     ["pCondition should fail if # and ? are in wrong order", function(pTester)
     {
         new SqlBuilder().where("PERSON.FIRSTNAME", "val1", "? = #")
-    }, SqlBuilder.ERROR_CONDITION_WRONG_FORMAT()]
+    }, SqlBuilder._ERROR_CONDITION_WRONG_FORMAT()]
 ]);
 
 var subqueryAliasTests = new TestSuite([
diff --git a/process/UnitTest_lib/process.js b/process/UnitTest_lib/process.js
index 69be82eb2d..0ce141d482 100644
--- a/process/UnitTest_lib/process.js
+++ b/process/UnitTest_lib/process.js
@@ -53,6 +53,48 @@ function Tester(pCollectionName)
     this.currentTestHadAlreadyAssert = false;
 }
 
+/**
+ * generates a summary of the test results
+ * 
+ * @return {Obect}
+ */
+Tester.prototype.getSummary = function ()
+{
+    var summary = {
+        failures : 0,
+        successes : 0,
+        failedTests : [],
+        getMessage : function ()
+        {
+            var message = "-------------------------\n"
+                + (this.failures ? "Test failure" : "Test success")
+                + "\n-------------------------\nTests performed: " + (this.successes + this.failures)
+                + "\nTests successful: " + this.successes
+                + "\nTests failed: " + this.failures;
+            if (this.failedTests.length)
+            {
+                message += "\nFailures:";
+                this.failedTests.forEach(function (testName)
+                {
+                    message += "\n\t" + testName;
+                });
+            }
+            return message;
+        }
+    }
+    this.testResults.forEach(function ([testName,, successful])
+    {
+        if (successful)
+            summary.successes++;
+        else
+        {
+            summary.failures++;
+            summary.failedTests.push(testName);
+        }
+    });
+    return summary;
+}
+
 /**
  * With assert you can test if a variable is the same like an expected value.<br/>
  * The test result is added to the Tester<br/>
@@ -189,4 +231,5 @@ Tester.prototype.printResults = function ()
         logging.log(message);
         lastTestDescription = pResult[0];
     }, this);
+    logging.log(this.getSummary().getMessage());
 }
\ No newline at end of file
-- 
GitLab