[CR #1478779] CLL: More detailed warning at external template handling

    checking expected warning msg added to test

Change-Id: I41bd0f9afa1d891d2377fe8c546bd2f5a17c3dc2
Signed-off-by: József Gyürüsi <jozsef.gyurusi@ericsson.com>
Signed-off-by: József Gyürüsi <jozsef.gyurusi@ericsson.com>
diff --git a/src/LGenBase/EPTF_CLL_LGenBase_TemplateFunctions.ttcn b/src/LGenBase/EPTF_CLL_LGenBase_TemplateFunctions.ttcn
index 66c9fc0..3fd23ba 100644
--- a/src/LGenBase/EPTF_CLL_LGenBase_TemplateFunctions.ttcn
+++ b/src/LGenBase/EPTF_CLL_LGenBase_TemplateFunctions.ttcn
@@ -434,7 +434,10 @@
     {
       if (v_LGenBase_templateSetDB[p_templateSetIdx][i].templateTypeIdx == p_templateTypeIdx)
       {
-        f_EPTF_LGenBase_loggingWarning(%definitionId&": Assignment in the template set alredy exists");      
+        f_EPTF_LGenBase_loggingWarning(%definitionId&": Assignment in the template set "&int2str(p_templateSetIdx)&" already exists for template type "&
+          int2str(p_templateTypeIdx) & ". Assigned template: " &
+            v_LGenBase_extTemplateDB[v_LGenBase_templateSetDB[p_templateSetIdx][i].externalTemplateIdx].name & ". Cannot assign new template: " &
+            v_LGenBase_extTemplateDB[p_extTemplateIdx].name);
         return -1;
       }
     }
diff --git a/test/LGenBase/EPTF_LGenBase_Test_Definitions.ttcn b/test/LGenBase/EPTF_LGenBase_Test_Definitions.ttcn
index f547f75..b437a6f 100644
--- a/test/LGenBase/EPTF_LGenBase_Test_Definitions.ttcn
+++ b/test/LGenBase/EPTF_LGenBase_Test_Definitions.ttcn
@@ -32,6 +32,7 @@
 {
 
 import from EPTF_CLL_Common_Definitions all;
+import from EPTF_CLL_Logging_Definitions all;
 import from EPTF_CLL_LGenBase_Definitions all;
 import from EPTF_CLL_LGenBase_ConfigDefinitions all;
 import from EPTF_CLL_LGenBase_TemplateDefinitions all;
@@ -218,4 +219,15 @@
 };
 const charstring c_LGenBase_TemplateContentGetter_Dummy_Content := "Template content getter dummy result";
 
+// functions and component that is needed to check expected warning messages
+group CheckExpectedWarning {
+
+  type component EPTF_CLL_LGenBase_Test_ExpectedWarning_CT extends EPTF_Logging_CT {
+    var boolean v_LGenBase_Test_expectedWarningInitialized:=false;
+    var boolean v_LGenBase_Test_expectedWarningArrived := false;
+    var charstring v_LGenBase_Test_expectedWarningMsg:="";
+  }
+
+} // group CheckExpectedWarning
+
 }
diff --git a/test/LGenBase/EPTF_LGenBase_Test_Testcases_Latest.ttcn b/test/LGenBase/EPTF_LGenBase_Test_Testcases_Latest.ttcn
index 89cd055..35c5c3e 100644
--- a/test/LGenBase/EPTF_LGenBase_Test_Testcases_Latest.ttcn
+++ b/test/LGenBase/EPTF_LGenBase_Test_Testcases_Latest.ttcn
@@ -37,6 +37,7 @@
 import from EPTF_CLL_Common_Functions all;
 import from EPTF_CLL_Common_Definitions all;
 import from EPTF_CLL_ILog_Functions all;
+import from EPTF_CLL_Logging_Functions all;
 import from EPTF_CLL_LGenBase_ILog_Functions all;
 import from EPTF_CLL_LGenBase_Functions all;
 import from EPTF_CLL_LGenBase_ConfigFunctions all;
@@ -1073,6 +1074,158 @@
     f_EPTF_Base_cleanup_CT();
   }
 
+// functions and component that is needed to check expected warning messages
+group CheckExpectedWarning {
+
+  private function f_EPTF_LGenBase_Test_ExpectedWarning_init() runs on EPTF_CLL_LGenBase_Test_ExpectedWarning_CT {
+    if (v_LGenBase_Test_expectedWarningInitialized) {
+      return;
+    }
+    v_LGenBase_Test_expectedWarningInitialized:=true;
+    v_LGenBase_Test_expectedWarningArrived := false;
+    v_LGenBase_Test_expectedWarningMsg:="";
+    f_EPTF_Base_registerCleanup(refers(f_EPTF_LGenBase_Test_ExpectedWarning_cleanup));
+    f_EPTF_Logging_registerPreambleFn(refers(f_EPTF_LGenBase_Test_ExpectedWarning_checkExpectedWarning_preamble_FT));
+  }
+
+  private function f_EPTF_LGenBase_Test_ExpectedWarning_cleanup() runs on EPTF_CLL_LGenBase_Test_ExpectedWarning_CT {
+    if (not v_LGenBase_Test_expectedWarningInitialized) {
+      return;
+    }
+    v_LGenBase_Test_expectedWarningInitialized:=false;
+    if (v_LGenBase_Test_expectedWarningMsg != "" and not v_LGenBase_Test_expectedWarningArrived) {
+      setverdict(fail,"Expected warning message ",v_LGenBase_Test_expectedWarningMsg," was not logged!");
+    } else {
+      setverdict(pass,"Expected warning message was logged");
+    }
+  }
+
+  public function f_EPTF_LGenBase_Test_ExpectedWarning_setExpectedWarning(in charstring pl_expectedWarningMsg) runs on EPTF_CLL_LGenBase_Test_ExpectedWarning_CT {
+    if (pl_expectedWarningMsg=="") {
+      return;
+    }
+    f_EPTF_LGenBase_Test_ExpectedWarning_init();
+    v_LGenBase_Test_expectedWarningMsg := pl_expectedWarningMsg;
+  }
+
+  private function f_EPTF_LGenBase_Test_ExpectedWarning_checkExpectedWarning_preamble_FT(in charstring pl_message) runs on EPTF_CLL_LGenBase_Test_ExpectedWarning_CT {
+    if (not match(pl_message,pattern "*Warning*")) {
+      return;
+    }
+    action(match(pl_message,pattern v_LGenBase_Test_expectedWarningMsg))
+    if (match(pl_message,pattern v_LGenBase_Test_expectedWarningMsg)) {
+      v_LGenBase_Test_expectedWarningArrived := true;
+    }
+  }
+
+} // group CheckExpectedWarning
+
+  
+  type component EPTF_LGenBase_Test_CheckExpectedWarning_CT extends EPTF_CLL_LGenBase_Test_ExpectedWarning_CT, EPTF_LGenBase_Test_CT {
+  }
+  
+  ///////////////////////////////////////////////////////////
+  //  Testcase: tc_LGenBase_Test_externalTemplates_assignExisting
+  //
+  //  Purpose:
+  //    Testcase to check the if assign is done for an existing 'external template'
+  //
+  //  Requirement:
+  //    dummy_template.txt external template file is available on filesystem
+  //
+  //  Action:
+  //    - Loads an external template, 
+  //    - creates template set, 
+  //    - declares a template type
+  //    - assigns template type to external template,
+  //    - assigns another template type to the same external template
+  //    - checks the warning
+  //
+  ///////////////////////////////////////////////////////////
+  testcase tc_LGenBase_Test_externalTemplates_assignExisting() runs on EPTF_LGenBase_Test_CheckExpectedWarning_CT
+  {
+    const charstring extTemplName1 := "dummy1";
+    const charstring extTemplName2 := "dummy2";
+    var EPTF_LGenBase_ExtTemplLoadList extTemplLoadList := { {extTemplName1, tsp_dummyTemplatePathArithmetic, true}, 
+                                                             {extTemplName2, tsp_dummyTemplatePathArithmetic, true}
+                                                           }
+
+    // 1. load the external template list
+    log("Init component and load external template list");
+    f_EPTF_LGenBase_init("LGenBase Templates Test", pl_extTemplLoadList := extTemplLoadList, pl_enableDefaultArithmeticOperationsInExtTemplate := true);
+
+    f_EPTF_LGenBase_Test_ExpectedWarning_init();
+    f_EPTF_LGenBase_Test_ExpectedWarning_setExpectedWarning("*Assignment in the template set 0 already exists for template type 0. Assigned template: dummy1. Cannot assign new template: dummy2*");
+
+    // check dummy template exist, other one not exist
+    if (     f_EPTF_LGenBase_getExtTemplIdx(extTemplName1) >= 0
+         and f_EPTF_LGenBase_getExtTemplIdx(extTemplName2) >= 0 )
+    {
+      log("External template loaded OK");
+    }
+    else
+    {
+      setverdict(fail, "Could not load external templates");
+      f_EPTF_Base_stop(none);
+    }
+
+    // 2. create a new template set
+    log("Create template set");
+    var integer setId := f_EPTF_LGenBase_createTemplateSet();
+    if(setId >= 0)
+    {
+      log("Template set created OK");
+    }
+    else
+    {
+      log("Could not create template set");
+      setverdict(fail);
+    }
+
+    // 3. declare a new template type
+    log("Declare new template type");
+    var EPTF_LGenBase_TemplateTypeKey templTypeKey := {"SIP", "INVITE"};
+    var integer templTypeIdx := f_EPTF_LGenBase_declareTemplateType(templTypeKey, {"USERNAME"}, {"USERID"}) 
+    if ( templTypeIdx>=0 )
+    {
+      log("Template type declared OK");
+    }
+    else
+    {
+      log("Could not declare template type");
+      setverdict(fail);
+    }
+
+    // 4. assign declared template type to 'dummy' template
+    log("Assign declared type to external template");
+    // NOTE: f_EPTF_LGenBase_assignExtTemplToTemplType(setId, templTypeIdx, extTemplIdx) is more efficient
+    if(f_EPTF_LGenBase_assignExtTemplToTemplType3(setId, templTypeKey, extTemplName1) >= 0)
+    {
+      log("Assigment OK");
+    }
+    else
+    {
+      log("Could not assign template type with external template");
+      setverdict(fail);
+    }
+
+
+    // 5. assigns another template type to the same external template
+    if(f_EPTF_LGenBase_assignExtTemplToTemplType3(setId, templTypeKey, extTemplName2) >= 0)
+    {
+      log("Assigment OK");
+      setverdict(fail, "Assignment should not be OK");
+    }
+    else
+    {
+      log("Could not assign template type with external template");
+      setverdict(pass);
+    }
+
+    
+    f_EPTF_Base_cleanup_CT();
+  }
+
   type component EPTF_LGenBase_TestPipe_CT extends EPTF_LGenBase_Test_CT{
     port PIPEasp_PT v_pipe_PCO;
   }
@@ -1464,6 +1617,7 @@
   execute(tc_LGenBase_Test_DS_ConditionHasActiveTc_EGNoSCTC());
   execute(tc_LGenBase_DS_Neg_WrongConditionHasActiveTc());
   execute(tc_LGenBase_Test_externalTemplates_arithmetic());
+  execute(tc_LGenBase_Test_externalTemplates_assignExisting());
 
   execute(tc_LGenBase_Test_fsmDump());