Adapted test scripts to changes in PMS 2.0

Issue-ID: NONRTRIC-307

Signed-off-by: BjornMagnussonXA <bjorn.magnusson@est.tech>
Change-Id: I41effdcfbe41c742d618d247b0d60f6e8090048f
diff --git a/test/common/README.md b/test/common/README.md
index 75b16b5..24dfc9d 100644
--- a/test/common/README.md
+++ b/test/common/README.md
@@ -16,7 +16,7 @@
 Common functions for running two or more auto test scripts as a suite.
 
 `api_curl.sh` \
-A common curl based function for the agent and ecs apis.
+A common curl based function for the agent and ecs apis. Also partly used for the Callback receiver api.
 
 `agent_api_functions.sh` \
 Contains functions for adapting towards the Policy Agent API, also via dmaap (using a message-router stub interface)
@@ -54,6 +54,8 @@
 `do_curl_function.sh`
 A script for executing a curl call with a specific url and optional payload. It also compare the response with an expected result in terms of response code and optional returned payload. Intended to be used by test script (for example basic test scripts of other components)
 
+`cr_api_functions.sh` \
+Contains functions for adapting towards the Callback receiver for checking received callback event.
 
 
 # Description of functions in testcase_common.sh #
@@ -344,6 +346,12 @@
 |--|
 | None |
 
+## Function: restart_ecs ##
+Restart the ECS container.
+| arg list |
+|--|
+| None |
+
 ## Function: use_ecs_rest_http ##
 Use http for all API calls to the ECS. This is the default protocol.
 | arg list |
@@ -415,21 +423,6 @@
 | `<logfile-prefix>` | Log file prefix  |
 
 
-## Function: cr_equal ##
-Tests if a variable value in the Callback Receiver (CR) simulator is equal to a target value.
-Without the timeout, the test sets pass or fail immediately depending on if the variable is equal to the target or not.
-With the timeout, the test waits up to the timeout seconds before setting pass or fail depending on if the variable value becomes equal to the target value or not.
-See the 'cr' dir for more details.
-| arg list |
-|--|
-| `<variable-name> <target-value> [ <timeout-in-sec> ]` |
-
-| parameter | description |
-| --------- | ----------- |
-| `<variable-name>` | Variable name in the CR  |
-| `<target-value>` | Target value for the variable  |
-| `<timeout-in-sec>` | Max time to wait for the variable to reach the target value  |
-
 ## Function: mr_equal ##
 Tests if a variable value in the Message Router (MR) simulator is equal to a target value.
 Without the timeout, the test sets pass or fail immediately depending on if the variable is equal to the target or not.
@@ -531,7 +524,7 @@
 | `<timeout-in-sec>` | Max time to wait for the length to reach the target value  |
 
 ## Function: api_get_policies() ##
-Test of GET '/policies' or V2 GET '/v2/policy_instances' and optional check of the array of returned policies.
+Test of GET '/policies' or V2 GET '/v2/policy-instances' and optional check of the array of returned policies.
 To test the response code only, provide the response code parameter as well as the following three parameters.
 To also test the response payload add the 'NOID' for an expected empty array or repeat the last five/seven parameters for each expected policy.
 
@@ -1478,6 +1471,39 @@
 | `<target-value>` | Target value for the variable  |
 | `<timeout-in-sec>` | Max time to wait for the variable to reach the target value  |
 
+# Description of functions in cr_api_function.sh #
+
+
+
+## Function: cr_equal ##
+Tests if a variable value in the Callback Receiver (CR) simulator is equal to a target value.
+Without the timeout, the test sets pass or fail immediately depending on if the variable is equal to the target or not.
+With the timeout, the test waits up to the timeout seconds before setting pass or fail depending on if the variable value becomes equal to the target value or not.
+See the 'cr' dir for more details.
+| arg list |
+|--|
+| `<variable-name> <target-value> [ <timeout-in-sec> ]` |
+
+| parameter | description |
+| --------- | ----------- |
+| `<variable-name>` | Variable name in the CR  |
+| `<target-value>` | Target value for the variable  |
+| `<timeout-in-sec>` | Max time to wait for the variable to reach the target value  |
+
+## Function: cr_api_check_all_sync_events() ##
+Check the contents of all ric events received for a callback id.
+
+| arg list |
+|--|
+| `<response-code> <id> [ EMPTY | ( <ric-id> )+ ]` |
+
+| parameter | description |
+| --------- | ----------- |
+| `<response-code>` | Expected http response code |
+| `<id>` | Id of the callback destination  |
+| `EMPTY` | Indicator for an empty list  |
+| `<ric-id>` | Id of the ric  |
+
 
 ## License
 
diff --git a/test/common/agent_api_functions.sh b/test/common/agent_api_functions.sh
index 507e011..5f5a2c6 100644
--- a/test/common/agent_api_functions.sh
+++ b/test/common/agent_api_functions.sh
@@ -49,7 +49,7 @@
 	return 1
 }
 
-# API Test function: GET /policies and V2 GET /v2/policy_instances
+# API Test function: GET /policies and V2 GET /v2/policy-instances
 # args: <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <template-file>]*]
 # args(V2): <response-code> <ric-id>|NORIC <service-id>|NOSERVICE <policy-type-id>|NOTYPE [ NOID | [<policy-id> <ric-id> <service-id> EMPTY|<policy-type-id> <transient> <notification-url> <template-file>]*]
 # (Function for test scripts)
@@ -110,7 +110,7 @@
 			fi
 		fi
 
-		query="/v2/policy_instances"$queryparams
+		query="/v2/policy-instances"$queryparams
 		res="$(__do_curl_to_api PA GET $query)"
 		status=${res:${#res}-3}
 
@@ -134,7 +134,7 @@
 					if [ "$targetJson" != "[" ]; then
 						targetJson=$targetJson","
 					fi
-					targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policy_type_id\":"
+					targetJson=$targetJson"{\"policy_id\":\"$UUID${arr[$i]}\",\"ric_id\":\"${arr[$i+1]}\",\"service_id\":\"${arr[$i+2]}\",\"policytype_id\":"
 					if [ "${arr[$i+3]}" == "EMPTY" ]; then
 						targetJson=$targetJson"\"\","
 					else
@@ -282,9 +282,9 @@
 				targetJson=$targetJson", \"transient\":$7"
 			fi
 			if [ $6 != "NOTYPE" ]; then
-				targetJson=$targetJson", \"policy_type_id\":\"$6\""
+				targetJson=$targetJson", \"policytype_id\":\"$6\""
 			else
-				targetJson=$targetJson", \"policy_type_id\":\"\""
+				targetJson=$targetJson", \"policytype_id\":\"\""
 			fi
 			if [ $8 != "NOURL" ]; then
 				targetJson=$targetJson", \"status_notification_uri\":\"$8\""
@@ -378,9 +378,9 @@
 				inputJson=$inputJson", \"transient\":$trans"
 			fi
 			if [ $pt != "NOTYPE" ]; then
-				inputJson=$inputJson", \"policy_type_id\":$pt"
+				inputJson=$inputJson", \"policytype_id\":\"$pt\""
 			else
-				inputJson=$inputJson", \"policy_type_id\":\"\""
+				inputJson=$inputJson", \"policytype_id\":\"\""
 			fi
 			if [ $noti != "NOURL" ]; then
 				inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
@@ -478,9 +478,9 @@
 				inputJson=$inputJson", \"transient\":$trans"
 			fi
 			if [ $pt != "NOTYPE" ]; then
-				inputJson=$inputJson", \"policy_type_id\":$pt"
+				inputJson=$inputJson", \"policytype_id\":\"$pt\""
 			else
-				inputJson=$inputJson", \"policy_type_id\":\"\""
+				inputJson=$inputJson", \"policytype_id\":\"\""
 			fi
 			if [ $noti != "NOURL" ]; then
 				inputJson=$inputJson", \"status_notification_uri\":\"$noti\""
@@ -640,7 +640,7 @@
 		else
 			res=${tmp:0:1}
 			if [ $res == "0" ]; then
-				echo " Process $i : OK"
+				echo " Process $i : OK - "${tmp:1}
 			else
 				echo " Process $i : failed - "${tmp:1}
 				msg="failed"
@@ -841,7 +841,7 @@
 		else
 			res=${tmp:0:1}
 			if [ $res == "0" ]; then
-				echo " Process $i : OK"
+				echo " Process $i : OK - "${tmp:1}
 			else
 				echo " Process $i : failed - "${tmp:1}
 				msg="failed"
@@ -1264,7 +1264,7 @@
 
 		targetJson=$targetJson"]"
 		if [ "$PMS_VERSION" == "V2" ]; then
-			targetJson="{\"policy_type_ids\": $targetJson }"
+			targetJson="{\"policytype_ids\": $targetJson }"
 		fi
 		echo "TARGET JSON: $targetJson" >> $HTTPLOG
 		res=$(python3 ../common/compare_json.py "$targetJson" "$body")
diff --git a/test/common/api_curl.sh b/test/common/api_curl.sh
index 2aff131..611fc4d 100644
--- a/test/common/api_curl.sh
+++ b/test/common/api_curl.sh
@@ -40,6 +40,11 @@
             __RESTBASE=$ECS_RESTBASE
             __RESTBASE_SECURE=$ECS_RESTBASE_SECURE
             __RETRY_CODES=$ECS_RETRY_CODES
+		elif [ $1 == "CR" ]; then
+		    __ADAPTER=$CR_ADAPTER
+            __RESTBASE=$CR_RESTBASE
+            __RESTBASE_SECURE=$CR_RESTBASE_SECURE
+            __RETRY_CODES=""
         else
             paramError=1
         fi
@@ -97,7 +102,7 @@
 
     if [ $paramError -eq 1 ]; then
 		((RES_CONF_FAIL++))
-        echo "-Incorrect number of parameters to __do_curl_agent " $@ >> $HTTPLOG
+        echo "-Incorrect number of parameters to __do_curl_to_api " $@ >> $HTTPLOG
         echo "-Expected: (PA|ECS GET|PUT|POST|DELETE|GET_BATCH|PUT_BATCH|POST_BATCH|DELETE_BATCH <url> [<file>]) | (PA|ECS RESPONSE <correlation-id>)" >> $HTTPLOG
         echo "-Returning response 000" >> $HTTPLOG
         echo "-000"
@@ -150,6 +155,8 @@
 				payload="$(cat $4 | tr -d '\n' | tr -d ' ' )"
 				echo "payload: "$payload >> $HTTPLOG
 				file=" --data-binary "$payload
+			elif [ $# -eq 4 ]; then
+				echo " FILE: $(cat $4)" >> $HTTPLOG
 			fi
 			#urlencode the request url since it will be carried by send-request url
 			requestUrl=$(python3 -c "from __future__ import print_function; import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))"  "$3")
diff --git a/test/common/create_policies_process.py b/test/common/create_policies_process.py
index d1bfd6f..89bfde8 100644
--- a/test/common/create_policies_process.py
+++ b/test/common/create_policies_process.py
@@ -24,6 +24,7 @@
 import sys
 import requests
 import traceback
+from time import sleep
 
 # disable warning about unverified https requests
 from requests.packages import urllib3
@@ -79,52 +80,68 @@
         start=start
         stop=count*num_rics+start
 
+        total_retry_count=0
+
         for i in range(start,stop):
             if (i%pids == (pid_id-1)):
                 payload=template.replace("XXX",str(i))
                 ric_id=(i%num_rics)+1
                 ric=ric_base+str(ric_id)
 
-                try:
-                    headers = {'Content-type': 'application/json'}
-                    if ("/v2/" in baseurl):
-                        url=baseurl
+                retry_cnt=5
+                while(retry_cnt>0):
+                    try:
+                        headers = {'Content-type': 'application/json'}
+                        if ("/v2/" in baseurl):
+                            url=baseurl
 
-                        data={}
-                        data["ric_id"]=ric
-                        data["policy_id"]=uuid+str(i)
-                        data["service_id"]=serv
-                        if (trans != "NOTRANSIENT"):
-                            data["transient"]=trans
-                        if (pt != "NOTYPE"):
-                            data["policy_type_id"]=pt
+                            data={}
+                            data["ric_id"]=ric
+                            data["policy_id"]=uuid+str(i)
+                            data["service_id"]=serv
+                            if (trans != "NOTRANSIENT"):
+                                data["transient"]=trans
+                            if (pt != "NOTYPE"):
+                                data["policytype_id"]=pt
+                            else:
+                                data["policytype_id"]=""
+                            if (noti != "NOURL"):
+                                data["status_notification_uri"]=noti
+                            data["policy_data"]=json.loads(payload)
+
+                            url_out=url
+                            data_out=json.dumps(data)
                         else:
-                            data["policy_type_id"]=""
-                        if (noti != "NOURL"):
-                            data["status_notification_uri"]=noti
-                        data["policy_data"]=json.loads(payload)
+                            url=baseurl+"&id="+uuid+str(i)+"&ric="+str(ric)
+                            url_out=url
+                            data_out=json.dumps(json.loads(payload))
 
-                        url_out=url
-                        data_out=json.dumps(data)
                         resp=requests.put(url, data_out, headers=headers, verify=False, timeout=90)
+                    except Exception as e1:
+                        print("1Put failed for id:"+uuid+str(i)+ ", "+str(e1) + " "+traceback.format_exc())
+                        sys.exit()
+
+                    if (resp.status_code == None):
+                        print("1Put failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: None")
+                        sys.exit()
+
+                    if (resp.status_code != responsecode):
+                        if (resp.status_code == 503 ) and (retry_cnt > 1):
+                            sleep(0.1)
+                            retry_cnt -= 1
+                            total_retry_count += 1
+                        else:
+                            print("1Put failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: "+str(resp.status_code))
+                            print(url_out)
+                            print(str(data_out))
+                            sys.exit()
                     else:
-                        url=baseurl+"&id="+uuid+str(i)+"&ric="+str(ric)
-                        url_out=url
-                        data_out=json.dumps(json.loads(payload))
-                        resp=requests.put(url, data_out, headers=headers, verify=False, timeout=90)
-                except Exception as e1:
-                    print("1Put failed for id:"+uuid+str(i)+ ", "+str(e1) + " "+traceback.format_exc())
-                    sys.exit()
-                if (resp.status_code == None):
-                    print("1Put failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: None")
-                    sys.exit()
-                if (resp.status_code != responsecode):
-                    print("1Put failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: "+str(resp.status_code))
-                    print(url_out)
-                    print(str(data_out))
-                    sys.exit()
+                        retry_cnt=-1
 
-    print("0")
+    if (total_retry_count > 0):
+        print("0 retries:"+str(total_retry_count))
+    else:
+        print("0")
     sys.exit()
 
 except Exception as e:
diff --git a/test/common/create_rics_json.py b/test/common/create_rics_json.py
index b2ad528..5f2fe69 100644
--- a/test/common/create_rics_json.py
+++ b/test/common/create_rics_json.py
@@ -40,7 +40,7 @@
     if (api_version == "V2"):
         param_ric='ric_id'
         param_me='managed_element_ids'
-        param_policy_type='policy_type_ids'
+        param_policy_type='policytype_ids'
         param_state='state'
     else:
         param_ric='ricName'
diff --git a/test/common/delete_policies_process.py b/test/common/delete_policies_process.py
index cf293c8..febb3cc 100644
--- a/test/common/delete_policies_process.py
+++ b/test/common/delete_policies_process.py
@@ -49,26 +49,40 @@
     if uuid == "NOUUID":
         uuid=""
 
+    total_retry_count=0
+
     stop=count*num_rics+start
     for i in range(start,stop):
         if (i%pids == (pid_id-1)):
-            if ("/v2/policies/" in baseurl):
-                url=str(baseurl+uuid+str(i))
-            else:
-                url=str(baseurl+"?id="+uuid+str(i))
-            try:
-                resp=requests.delete(url, verify=False, timeout=90)
-            except Exception as e1:
-                print("1Delete failed for id:"+uuid+str(i)+ ", "+str(e1) + " "+traceback.format_exc())
-                sys.exit()
-            if (resp.status_code == None):
-                print("1Delete failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: None")
-                sys.exit()
-            if (resp.status_code != responsecode):
-                print("1Delete failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: "+str(resp.status_code))
-                sys.exit()
+            retry_cnt=5
+            while(retry_cnt>0):
+                if ("/v2/policies/" in baseurl):
+                    url=str(baseurl+uuid+str(i))
+                else:
+                    url=str(baseurl+"?id="+uuid+str(i))
+                try:
+                    resp=requests.delete(url, verify=False, timeout=90)
+                except Exception as e1:
+                    print("1Delete failed for id:"+uuid+str(i)+ ", "+str(e1) + " "+traceback.format_exc())
+                    sys.exit()
+                if (resp.status_code == None):
+                    print("1Delete failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: None")
+                    sys.exit()
+                if (resp.status_code != responsecode):
+                    if (resp.status_code == 503 ) and (retry_cnt > 1):
+                        sleep(0.1)
+                        retry_cnt -= 1
+                        total_retry_count += 1
+                    else:
+                        print("1Delete failed for id:"+uuid+str(i)+ ", expected response code: "+str(responsecode)+", got: "+str(resp.status_code))
+                        sys.exit()
+                else:
+                    retry_cnt=-1
 
-    print("0")
+    if (total_retry_count > 0):
+        print("0 retries:"+str(total_retry_count))
+    else:
+        print("0")
     sys.exit()
 
 except Exception as e:
diff --git a/test/common/ricsimulator_api_functions.sh b/test/common/ricsimulator_api_functions.sh
index 67a398e..56f968e 100644
--- a/test/common/ricsimulator_api_functions.sh
+++ b/test/common/ricsimulator_api_functions.sh
@@ -30,6 +30,7 @@
 	echo " RESP: $res" >> $HTTPLOG
 	retcode=$?
     if [ $retcode -ne 0 ]; then
+		((RES_CONF_FAIL++))
 		echo " RETCODE: "$retcode
         echo -e $RED" FAIL - fatal error when executing curl."$ERED
         return 1
@@ -40,6 +41,7 @@
         return 0
     fi
     echo -e $RED" FAIL - expected http response: "$1" but got http response: "$status $ERED
+	((RES_CONF_FAIL++))
     return 1
 }
 
@@ -119,7 +121,7 @@
 	return $?
 }
 
-# DSimulator API: Delete a policy type in a ric
+# Simulator API: Delete a policy type in a ric
 # <response-code> <ric-id> <policy-type-id>
 # (Function for test scripts)
 sim_delete_policy_type() {
diff --git a/test/common/test_env-onap-guilin.sh b/test/common/test_env-onap-guilin.sh
index f92bf79..51eab69 100644
--- a/test/common/test_env-onap-guilin.sh
+++ b/test/common/test_env-onap-guilin.sh
@@ -17,6 +17,8 @@
 #  ============LICENSE_END=================================================
 #
 
+TEST_ENV_PROFILE="ONAP-GUILIN"
+
 # Set up the image and tags for the test. Do not add the image tag to the image names.
 
 # NOTE: A env var for each container is created by the test script.
diff --git a/test/common/test_env-onap-master.sh b/test/common/test_env-onap-master.sh
index da6906d..f97309c 100644
--- a/test/common/test_env-onap-master.sh
+++ b/test/common/test_env-onap-master.sh
@@ -17,6 +17,8 @@
 #  ============LICENSE_END=================================================
 #
 
+TEST_ENV_PROFILE="ONAP-MASTER"
+
 # Set up the image and tags for the test. Do not add the image tag to the image names.
 
 # NOTE: A env var for each container is created by the test script.
@@ -112,6 +114,8 @@
 export ECS_APP_NAME="ecs"                                       # Name for ECS container
 ECS_LOGPATH="/var/log/enrichment-coordinator-service/application.log" # Path the application log in the ECS container
 export ECS_APP_NAME_ALIAS="enrichment-service-container"        # Alias name, name used by the control panel
+export ECS_HOST_MNT_DIR="./mnt"                                 # Mounted dir, relative to compose file, on the host
+export ECS_CONTAINER_MNT_DIR="/var/enrichment-coordinator-service" # Mounted dir in the container
 
 export MR_EXTERNAL_PORT=3905                                    # MR stub container external port (host -> container)
 export MR_INTERNAL_PORT=3905                                    # MR stub container internal port (container -> container)
@@ -126,6 +130,7 @@
 export CR_EXTERNAL_SECURE_PORT=8091                             # Callback receiver container external secure port (host -> container)
 export CR_INTERNAL_SECURE_PORT=8091                             # Callback receiver container internal secure port (container -> container)
 export CR_APP_NAME="callback-receiver"                          # Name for the Callback receiver
+export CR_APP_CALLBACK="/callbacks"                             # Url for callbacks
 
 export PROD_STUB_EXTERNAL_PORT=8092                             # Producer stub container external port (host -> container)
 export PROD_STUB_INTERNAL_PORT=8092                             # Producer stub container internal port (container -> container)
@@ -187,4 +192,9 @@
 ECS_DMAAPBASE="http://localhost:"$MR_EXTERNAL_PORT              # Base url to the Dmaap adapter, http
 ECS_DMAAPBASE_SECURE="https://localhost:"$MR_EXTERNAL_SECURE_PORT   # Base url to the Dmaap adapter, https
 ECS_ADAPTER=$ECS_RESTBASE                                       # Adapter holds the address the ECS R-APP interface (REST OR DMAAP)
-                                                                # The values of this var is swiched between the four base url when needed
\ No newline at end of file
+                                                                # The values of this var is swiched between the four base url when needed
+
+CR_RESTBASE="http://localhost:"$CR_EXTERNAL_PORT                # Base url to the Callback receiver REST interface
+CR_RESTBASE_SECURE="https://localhost:"$CR_EXTERNAL_SECURE_PORT # Base url to the secure Callback receiver REST interface
+CR_ADAPTER=$CR_RESTBASE                                         # Adapter holds the address the CR admin interface (REST only)
+                                                                # The values of this var is swiched between the two base url when needed
\ No newline at end of file
diff --git a/test/common/test_env-oran-master.sh b/test/common/test_env-oran-master.sh
index 7b8e8f8..0077ef0 100755
--- a/test/common/test_env-oran-master.sh
+++ b/test/common/test_env-oran-master.sh
@@ -17,6 +17,8 @@
 #  ============LICENSE_END=================================================
 #
 
+TEST_ENV_PROFILE="ORAN-MASTER"
+
 # Set up the image and tags for the test. Do not add the image tag to the image names.
 
 # NOTE: A env var for each container is created by the test script.
@@ -115,6 +117,8 @@
 export ECS_APP_NAME="ecs"                                       # Name for ECS container
 ECS_LOGPATH="/var/log/enrichment-coordinator-service/application.log" # Path the application log in the ECS container
 export ECS_APP_NAME_ALIAS="enrichment-service-container"        # Alias name, name used by the control panel
+export ECS_HOST_MNT_DIR="./mnt"                                 # Mounted dir, relative to compose file, on the host
+export ECS_CONTAINER_MNT_DIR="/var/enrichment-coordinator-service" # Mounted dir in the container
 
 export MR_EXTERNAL_PORT=3905                                    # MR stub container external port (host -> container)
 export MR_INTERNAL_PORT=3905                                    # MR stub container internal port (container -> container)
@@ -129,6 +133,7 @@
 export CR_EXTERNAL_SECURE_PORT=8091                             # Callback receiver container external secure port (host -> container)
 export CR_INTERNAL_SECURE_PORT=8091                             # Callback receiver container internal secure port (container -> container)
 export CR_APP_NAME="callback-receiver"                          # Name for the Callback receiver
+export CR_APP_CALLBACK="/callbacks"                             # Url for callbacks
 
 export PROD_STUB_EXTERNAL_PORT=8092                             # Producer stub container external port (host -> container)
 export PROD_STUB_INTERNAL_PORT=8092                             # Producer stub container internal port (container -> container)
@@ -188,4 +193,9 @@
 ECS_DMAAPBASE="http://localhost:"$MR_EXTERNAL_PORT              # Base url to the Dmaap adapter, http
 ECS_DMAAPBASE_SECURE="https://localhost:"$MR_EXTERNAL_SECURE_PORT   # Base url to the Dmaap adapter, https
 ECS_ADAPTER=$ECS_RESTBASE                                       # Adapter holds the address the ECS R-APP interface (REST OR DMAAP)
-                                                                # The values of this var is swiched between the four base url when needed
\ No newline at end of file
+                                                                # The values of this var is swiched between the four base url when needed
+
+CR_RESTBASE="http://localhost:"$CR_EXTERNAL_PORT                # Base url to the Callback receiver REST interface
+CR_RESTBASE_SECURE="https://localhost:"$CR_EXTERNAL_SECURE_PORT # Base url to the secure Callback receiver REST interface
+CR_ADAPTER=$CR_RESTBASE                                         # Adapter holds the address the CR admin interface (REST only)
+                                                                # The values of this var is swiched between the two base url when needed
\ No newline at end of file
diff --git a/test/common/testcase_common.sh b/test/common/testcase_common.sh
index ea940a1..0afc2bc 100755
--- a/test/common/testcase_common.sh
+++ b/test/common/testcase_common.sh
@@ -128,6 +128,17 @@
 # Create a log dir for the test case
 mkdir -p $TESTLOGS/$ATC
 
+# Save create for current logs
+mkdir -p $TESTLOGS/$ATC/previous
+
+rm $TESTLOGS/$ATC/previous/*.log &> /dev/null
+rm $TESTLOGS/$ATC/previous/*.txt &> /dev/null
+rm $TESTLOGS/$ATC/previous/*.json &> /dev/null
+
+mv  $TESTLOGS/$ATC/*.log $TESTLOGS/$ATC/previous &> /dev/null
+mv  $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
+mv  $TESTLOGS/$ATC/*.txt $TESTLOGS/$ATC/previous &> /dev/null
+
 # Clear the log dir for the test case
 rm $TESTLOGS/$ATC/*.log &> /dev/null
 rm $TESTLOGS/$ATC/*.txt &> /dev/null
@@ -257,6 +268,18 @@
 if [ -f "$TEST_ENV_VAR_FILE" ]; then
 	echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD
 	. $TEST_ENV_VAR_FILE
+
+	if [ -z "$TEST_ENV_PROFILE" ] || [ -z "$SUPPORTED_PROFILES" ]; then
+		echo -e $YELLOW"This test case may no work with selected test env file. TEST_ENV_PROFILE is missing in test_env file or SUPPORTED_PROFILES is missing in test case file"$EYELLOW
+	else
+		if [[ "$SUPPORTED_PROFILES" == *"$TEST_ENV_PROFILE"* ]]; then
+			echo -e $GREEN"Test case support the selected test env file"$EGREEN
+		else
+			echo -e $RED"Test case does not support the selected test env file"$ERED
+			echo -e $RED"Exiting...."$ERED
+			exit 1
+		fi
+	fi
 else
 	echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED
 	echo " Select one of following env var file matching the intended target of the test"
@@ -290,6 +313,7 @@
 export CR_HTTPX="http"
 export CR_PORT=$CR_INTERNAL_PORT
 export CR_LOCAL_PORT=$CR_EXTERNAL_PORT #When CR is running outside the docker net
+export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
 
 export PROD_STUB_HTTPX="http"
 export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT
@@ -1154,7 +1178,8 @@
 			((RES_CONF_FAIL++))
 			echo ""
 			echo -e $RED" Container $BOLD${appname}$EBOLD could not be started"$ERED
-			return 1
+			echo -e $RED" Stopping script..."$ERED
+			exit 1
 		fi
 		if [ $localport -eq 0 ]; then
 			while [ $localport -eq 0 ]; do
@@ -1189,7 +1214,7 @@
 	 	else
 		 	TS_TMP=$SECONDS
 			while [ $(($TS_TMP+$i)) -gt $SECONDS ]; do
-				echo -ne " Waiting for container ${appname} service status...retrying in $(($TS_TMP+$i-$SECONDS)) seconds   ${SAMELINE}"
+				echo -ne " Waiting for container ${appname} service status...$(($SECONDS-$TSTART)) seconds, retrying in $(($TS_TMP+$i-$SECONDS)) seconds   ${SAMELINE}"
 				sleep 1
 			done
 	 	fi
@@ -1197,7 +1222,7 @@
 
 	if [ "$pa_st" = "false"  ]; then
 		((RES_CONF_FAIL++))
-		echo -e $RED" Container ${appname} did not respond to service status"$ERED
+		echo -e $RED" Container ${appname} did not respond to service status in $(($SECONDS-$TSTART)) seconds"$ERED
 		return 0
 	fi
 
@@ -1228,6 +1253,8 @@
 		if [ $? -ne 0 ]; then
 			echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
 			cat .dockererr
+			echo -e $RED"Stopping script...."$ERED
+			exit 1
 		fi
 	elif [ "$2" == "STANDALONE" ]; then
 		echo "Skipping docker-compose"
@@ -1236,6 +1263,8 @@
 		if [ $? -ne 0 ]; then
 			echo -e $RED"Problem to launch container(s) with docker-compose"$ERED
 			cat .dockererr
+			echo -e $RED"Stopping script...."$ERED
+			exit 1
 		fi
 	fi
 	app_prefix=""
@@ -1652,6 +1681,7 @@
 	export CR_HTTPX="http"
 	export CR_PORT=$CR_INTERNAL_PORT
 	export CR_LOCAL_PORT=$CR_EXTERNAL_PORT
+	export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
 	echo ""
 }
 
@@ -1660,6 +1690,7 @@
 	export CR_HTTPX="https"
 	export CR_PORT=$CR_INTERNAL_SECURE_PORT
 	export CR_LOCAL_PORT=$CR_EXTERNAL_SECURE_PORT
+	export CR_PATH="$CR_HTTPX://$CR_APP_NAME:$CR_PORT$CR_APP_CALLBACK"
 	echo ""
 }
 
@@ -1771,7 +1802,7 @@
 # args: -
 # (Function for test scripts)
 use_agent_dmaap_https() {
-	echo -e "Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
+	echo -e "Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
 	export ADAPTER=$DMAAPBASE_SECURE
 	echo ""
 	return 0
@@ -1847,6 +1878,23 @@
 	__start_container ecs NODOCKERARGS $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
 }
 
+# Restart ECS
+# args: -
+# (Function for test scripts)
+restart_ecs() {
+	docker restart $ECS_APP_NAME &> ./tmp/.dockererr
+	if [ $? -ne 0 ]; then
+		__print_err "Could restart $ECS_APP_NAME" $@
+		cat ./tmp/.dockererr
+		((RES_CONF_FAIL++))
+		return 1
+	fi
+
+	__check_container_start $ECS_APP_NAME $ECS_EXTERNAL_PORT "/status" "http"
+	echo ""
+	return 0
+}
+
 # All calls to ECS will be directed to the ECS REST interface from now on
 # args: -
 # (Function for test scripts)
@@ -2000,7 +2048,7 @@
     	__print_err "need one arg, <file-prefix>" $@
 		exit 1
 	fi
-	echo -e $BOLD"Storing all container logs using prefix: "$1$EBOLD
+	echo -e $BOLD"Storing all container logs in $TESTLOGS/$ATC using prefix: "$1$EBOLD
 
 	docker stats --no-stream > $TESTLOGS/$ATC/$1_docker_stats.log 2>&1
 
@@ -2226,22 +2274,6 @@
 
 ### Generic test cases for varaible checking
 
-# Tests if a variable value in the CR is equal to a target value and and optional timeout.
-# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
-# equal to the target or not.
-# Arg: <variable-name> <target-value> <timeout-in-sec>  - This test waits up to the timeout seconds
-# before setting pass or fail depending on if the variable value becomes equal to the target
-# value or not.
-# (Function for test scripts)
-cr_equal() {
-	if [ $# -eq 2 ] || [ $# -eq 3 ]; then
-		__var_test "CR" "$LOCALHOST$CR_EXTERNAL_PORT/counter/" $1 "=" $2 $3
-	else
-		((RES_CONF_FAIL++))
-		__print_err "Wrong args to cr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
-	fi
-}
-
 # Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
 # equal to the target or not.