summaryrefslogtreecommitdiffstats
path: root/test/apps/nxi_termination
diff options
context:
space:
mode:
authorhariharan97 <rh20085046@wipro.com>2020-08-26 09:42:29 +0530
committerhariharan97 <rh20085046@wipro.com>2020-09-02 17:38:41 +0530
commit7b7cfac3d2ae636f63c0e94df1a7129f2d10cb54 (patch)
treeaefbb5da4319a5fe3bc7b4a2c8d6b2156201038b /test/apps/nxi_termination
parent053c09a2ed1a8fc8aeef3f8185902634feec8000 (diff)
Add Nxi-Termination feature
Issue-ID: OPTFRA-825 Signed-off-by: hariharan97 <rh20085046@wipro.com> Change-Id: I0d768e36708e9f26e5bcdf661b2bcb5772ed48c2
Diffstat (limited to 'test/apps/nxi_termination')
-rw-r--r--test/apps/nxi_termination/_init_.py0
-rw-r--r--test/apps/nxi_termination/aai_exception_response.json4
-rw-r--r--test/apps/nxi_termination/aai_response.json64
-rw-r--r--test/apps/nxi_termination/exception_response1.json7
-rw-r--r--test/apps/nxi_termination/failure_relationship_list.json27
-rw-r--r--test/apps/nxi_termination/failure_relationship_list2.json52
-rw-r--r--test/apps/nxi_termination/failure_service_profiles.json24
-rw-r--r--test/apps/nxi_termination/failure_service_profiles2.json42
-rw-r--r--test/apps/nxi_termination/invalid_request.json17
-rw-r--r--test/apps/nxi_termination/nsi_success_output.json7
-rw-r--r--test/apps/nxi_termination/nssi_failure_output.json8
-rw-r--r--test/apps/nxi_termination/nssi_termination.json17
-rw-r--r--test/apps/nxi_termination/nxi_failure_output1.json10
-rw-r--r--test/apps/nxi_termination/nxi_failure_output2.json7
-rw-r--r--test/apps/nxi_termination/nxi_termination.json17
-rw-r--r--test/apps/nxi_termination/service_profiles.json23
-rw-r--r--test/apps/nxi_termination/success_relationship_list.json27
-rw-r--r--test/apps/nxi_termination/test_fetch_aai_data.py70
-rw-r--r--test/apps/nxi_termination/test_remote_opt_processor_termination.py141
19 files changed, 564 insertions, 0 deletions
diff --git a/test/apps/nxi_termination/_init_.py b/test/apps/nxi_termination/_init_.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/apps/nxi_termination/_init_.py
diff --git a/test/apps/nxi_termination/aai_exception_response.json b/test/apps/nxi_termination/aai_exception_response.json
new file mode 100644
index 0000000..56f61df
--- /dev/null
+++ b/test/apps/nxi_termination/aai_exception_response.json
@@ -0,0 +1,4 @@
+{
+ "status-code": 404,
+ "status-response": "NOT FOUND"
+} \ No newline at end of file
diff --git a/test/apps/nxi_termination/aai_response.json b/test/apps/nxi_termination/aai_response.json
new file mode 100644
index 0000000..b7ef43b
--- /dev/null
+++ b/test/apps/nxi_termination/aai_response.json
@@ -0,0 +1,64 @@
+{"service-instance": [{
+ "service-instance-id": "1a636c4d-5e76-427e-bfd6-241a947224b0",
+ "service-instance-name": "nssi_test_0211",
+ "service-type": "embb",
+ "service-role": "nssi",
+ "environment-context": "cn",
+ "model-invariant-id": "21d57d4b-52ad-4d3c-a798-248b5bb9124a",
+ "model-version-id": "bfba363e-e39c-4bd9-a9d5-1371c28f4d22",
+ "resource-version": "1581418601616",
+ "orchestration-status": "active",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "service-instance",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf",
+ "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/4115d3c8-dd59-45d6-b09d-e756dee9b518",
+ "relationship-data": [
+ {
+ "relationship-key": "customer.global-customer-id",
+ "relationship-value": "5GCustomer"
+ },
+ {
+ "relationship-key": "service-subscription.service-type",
+ "relationship-value": "5G"
+ },
+ {
+ "relationship-key": "service-instance.service-instance-id",
+ "relationship-value": "4115d3c8-dd59-45d6-b09d-e756dee9b518"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "service-instance.service-instance-name",
+ "property-value": "nsi_test_0211"
+ }
+ ]
+ }
+ ]
+ },
+ "slice-profiles": {
+ "slice-profile": [
+ {
+ "profile-id": "cdad9f49-4201-4e3a-aac1-b0f27902c299",
+ "latency": 20,
+ "max-number-of-UEs": 0,
+ "coverage-area-TA-list": "[{\"province\":\"??\",\"city\":\"???\",\"county\":\"???\",\"street\":\"?????\"}]",
+ "ue-mobility-level": "stationary",
+ "resource-sharing-level": "0",
+ "exp-data-rate-UL": 100,
+ "exp-data-rate-DL": 100,
+ "activity-factor": 0,
+ "e2e-latency": 0,
+ "jitter": 0,
+ "survival-time": 0,
+ "exp-data-rate": 0,
+ "payload-size": 0,
+ "traffic-density": 0,
+ "conn-density": 0,
+ "reliability": 99.999,
+ "resource-version": "1581418602494"
+ }
+ ]
+ }
+}]}
diff --git a/test/apps/nxi_termination/exception_response1.json b/test/apps/nxi_termination/exception_response1.json
new file mode 100644
index 0000000..cde603f
--- /dev/null
+++ b/test/apps/nxi_termination/exception_response1.json
@@ -0,0 +1,7 @@
+{
+ "requestId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "requestStatus": "failure",
+ "reason": "Error response recieved from AAI for the request"
+
+} \ No newline at end of file
diff --git a/test/apps/nxi_termination/failure_relationship_list.json b/test/apps/nxi_termination/failure_relationship_list.json
new file mode 100644
index 0000000..537f283
--- /dev/null
+++ b/test/apps/nxi_termination/failure_relationship_list.json
@@ -0,0 +1,27 @@
+[
+ {
+ "related-to": "service-instance",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf",
+ "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/4115d3c8-dd59-45d6-b09d-e756dee9b518",
+ "relationship-data": [
+ {
+ "relationship-key": "customer.global-customer-id",
+ "relationship-value": "5GCustomer"
+ },
+ {
+ "relationship-key": "service-subscription.service-type",
+ "relationship-value": "5G"
+ },
+ {
+ "relationship-key": "service-instance.service-instance-id",
+ "relationship-value": "4115d3c8-dd59-45d6-b09d-e756dee9b567"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "service-instance.service-instance-name",
+ "property-value": "nsi_test_0211"
+ }
+ ]
+ }
+ ] \ No newline at end of file
diff --git a/test/apps/nxi_termination/failure_relationship_list2.json b/test/apps/nxi_termination/failure_relationship_list2.json
new file mode 100644
index 0000000..624448a
--- /dev/null
+++ b/test/apps/nxi_termination/failure_relationship_list2.json
@@ -0,0 +1,52 @@
+[
+ {
+ "related-to": "service-instance",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf",
+ "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/4115d3c8-dd59-45d6-b09d-e756dee9b518",
+ "relationship-data": [
+ {
+ "relationship-key": "customer.global-customer-id",
+ "relationship-value": "5GCustomer"
+ },
+ {
+ "relationship-key": "service-subscription.service-type",
+ "relationship-value": "5G"
+ },
+ {
+ "relationship-key": "service-instance.service-instance-id",
+ "relationship-value": "4115d3c8-dd59-45d6-b09d-e756dee9b567"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "service-instance.service-instance-name",
+ "property-value": "nsi_test_0211"
+ }
+ ]
+ },
+ {
+ "related-to": "service-instance",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf",
+ "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/4115d3c8-dd59-45d6-b09d-e756dee9b518",
+ "relationship-data": [
+ {
+ "relationship-key": "customer.global-customer-id",
+ "relationship-value": "5GCustomer"
+ },
+ {
+ "relationship-key": "service-subscription.service-type",
+ "relationship-value": "5G"
+ },
+ {
+ "relationship-key": "service-instance.service-instance-id",
+ "relationship-value": "4115d3c8-dd59-45d6-b09d-e756dee9b567"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "service-instance.service-instance-name",
+ "property-value": "nsi_test_0211"
+ }
+ ]
+ }
+ ] \ No newline at end of file
diff --git a/test/apps/nxi_termination/failure_service_profiles.json b/test/apps/nxi_termination/failure_service_profiles.json
new file mode 100644
index 0000000..d10a818
--- /dev/null
+++ b/test/apps/nxi_termination/failure_service_profiles.json
@@ -0,0 +1,24 @@
+[
+ {
+ "profile-id": "cdad9f49-4201-4e3a-aac1-b0f27902c29",
+ "latency": 20,
+ "max-number-of-UEs": 0,
+ "coverage-area-TA-list": "[{\"province\":\"??\",\"city\":\"???\",\"county\":\"???\",\"street\":\"?????\"}]",
+ "ue-mobility-level": "stationary",
+ "resource-sharing-level": "0",
+ "exp-data-rate-UL": 100,
+ "exp-data-rate-DL": 100,
+ "activity-factor": 0,
+ "e2e-latency": 0,
+ "jitter": 0,
+ "survival-time": 0,
+ "exp-data-rate": 0,
+ "payload-size": 0,
+ "traffic-density": 0,
+ "conn-density": 0,
+ "reliability": 99.999,
+ "resource-version": "1581418602494"
+ }
+]
+
+
diff --git a/test/apps/nxi_termination/failure_service_profiles2.json b/test/apps/nxi_termination/failure_service_profiles2.json
new file mode 100644
index 0000000..1740758
--- /dev/null
+++ b/test/apps/nxi_termination/failure_service_profiles2.json
@@ -0,0 +1,42 @@
+[
+ {
+ "profile-id": "cdad9f49-4201-4e3a-aac1-b0f27902c299",
+ "latency": 20,
+ "max-number-of-UEs": 0,
+ "coverage-area-TA-list": "[{\"province\":\"??\",\"city\":\"???\",\"county\":\"???\",\"street\":\"?????\"}]",
+ "ue-mobility-level": "stationary",
+ "resource-sharing-level": "0",
+ "exp-data-rate-UL": 100,
+ "exp-data-rate-DL": 100,
+ "activity-factor": 0,
+ "e2e-latency": 0,
+ "jitter": 0,
+ "survival-time": 0,
+ "exp-data-rate": 0,
+ "payload-size": 0,
+ "traffic-density": 0,
+ "conn-density": 0,
+ "reliability": 99.999,
+ "resource-version": "1581418602494"
+ },
+ {
+ "profile-id": "abcd9f49-4201-4e3a-aac1-b0f27902c299",
+ "latency": 20,
+ "max-number-of-UEs": 0,
+ "coverage-area-TA-list": "[{\"province\":\"??\",\"city\":\"???\",\"county\":\"???\",\"street\":\"?????\"}]",
+ "ue-mobility-level": "stationary",
+ "resource-sharing-level": "0",
+ "exp-data-rate-UL": 100,
+ "exp-data-rate-DL": 100,
+ "activity-factor": 0,
+ "e2e-latency": 0,
+ "jitter": 0,
+ "survival-time": 0,
+ "exp-data-rate": 0,
+ "payload-size": 0,
+ "traffic-density": 0,
+ "conn-density": 0,
+ "reliability": 99.999,
+ "resource-version": "1581418602494"
+ }
+]
diff --git a/test/apps/nxi_termination/invalid_request.json b/test/apps/nxi_termination/invalid_request.json
new file mode 100644
index 0000000..793776d
--- /dev/null
+++ b/test/apps/nxi_termination/invalid_request.json
@@ -0,0 +1,17 @@
+{
+ "requestInfo": {
+ "transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "requestId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "callbackUrl": "http://0.0.0.0:9000/osdfCallback/",
+ "sourceId": "SO",
+ "timeout": 5,
+ "addtnlArgs": {
+ "serviceProfileId":"cdad9f49-4201-4e3a-aac1-b0f27902c299"
+ }
+ },
+ "type":"NST",
+ "NxIId":"d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "UUID":"d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "invariantUUID":"d290f1ee-6c54-4b01-90e6-d701748f0851"
+
+} \ No newline at end of file
diff --git a/test/apps/nxi_termination/nsi_success_output.json b/test/apps/nxi_termination/nsi_success_output.json
new file mode 100644
index 0000000..e25a272
--- /dev/null
+++ b/test/apps/nxi_termination/nsi_success_output.json
@@ -0,0 +1,7 @@
+{
+ "requestId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "requestStatus": "success",
+ "terminateResponse": true,
+ "reason": ""
+} \ No newline at end of file
diff --git a/test/apps/nxi_termination/nssi_failure_output.json b/test/apps/nxi_termination/nssi_failure_output.json
new file mode 100644
index 0000000..5ada892
--- /dev/null
+++ b/test/apps/nxi_termination/nssi_failure_output.json
@@ -0,0 +1,8 @@
+{
+ "requestId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "requestStatus": "success",
+ "terminateResponse": false,
+ "reason": "4115d3c8-dd59-45d6-b09d-e756dee9b518 is not available in AAI"
+
+} \ No newline at end of file
diff --git a/test/apps/nxi_termination/nssi_termination.json b/test/apps/nxi_termination/nssi_termination.json
new file mode 100644
index 0000000..b4e3711
--- /dev/null
+++ b/test/apps/nxi_termination/nssi_termination.json
@@ -0,0 +1,17 @@
+{
+ "requestInfo": {
+ "transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "requestId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "callbackUrl": "http://0.0.0.0:9000/osdfCallback/",
+ "sourceId": "SO",
+ "timeout": 5,
+ "addtnlArgs": {
+ "serviceInstanceId":"4115d3c8-dd59-45d6-b09d-e756dee9b518"
+ }
+ },
+ "type":"NSSI",
+ "NxIId":"d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "UUID":"d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "invariantUUID":"d290f1ee-6c54-4b01-90e6-d701748f0851"
+
+} \ No newline at end of file
diff --git a/test/apps/nxi_termination/nxi_failure_output1.json b/test/apps/nxi_termination/nxi_failure_output1.json
new file mode 100644
index 0000000..b363e86
--- /dev/null
+++ b/test/apps/nxi_termination/nxi_failure_output1.json
@@ -0,0 +1,10 @@
+{
+ "requestId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "requestStatus": "success",
+ "terminateResponse": false,
+ "reason": "cdad9f49-4201-4e3a-aac1-b0f27902c299 is not available in AAI"
+
+}
+
+
diff --git a/test/apps/nxi_termination/nxi_failure_output2.json b/test/apps/nxi_termination/nxi_failure_output2.json
new file mode 100644
index 0000000..5d430bc
--- /dev/null
+++ b/test/apps/nxi_termination/nxi_failure_output2.json
@@ -0,0 +1,7 @@
+{
+ "requestId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "requestStatus": "success",
+ "terminateResponse": false,
+ "reason": "Associated to more than one"
+} \ No newline at end of file
diff --git a/test/apps/nxi_termination/nxi_termination.json b/test/apps/nxi_termination/nxi_termination.json
new file mode 100644
index 0000000..ac53c4d
--- /dev/null
+++ b/test/apps/nxi_termination/nxi_termination.json
@@ -0,0 +1,17 @@
+{
+ "requestInfo": {
+ "transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "requestId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "callbackUrl": "http://0.0.0.0:9000/osdfCallback/",
+ "sourceId": "SO",
+ "timeout": 5,
+ "addtnlArgs": {
+ "serviceProfileId":"cdad9f49-4201-4e3a-aac1-b0f27902c299"
+ }
+ },
+ "type":"NSI",
+ "NxIId":"d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "UUID":"d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "invariantUUID":"d290f1ee-6c54-4b01-90e6-d701748f0851"
+
+} \ No newline at end of file
diff --git a/test/apps/nxi_termination/service_profiles.json b/test/apps/nxi_termination/service_profiles.json
new file mode 100644
index 0000000..899acb4
--- /dev/null
+++ b/test/apps/nxi_termination/service_profiles.json
@@ -0,0 +1,23 @@
+[
+ {
+ "profile-id": "cdad9f49-4201-4e3a-aac1-b0f27902c299",
+ "latency": 20,
+ "max-number-of-UEs": 0,
+ "coverage-area-TA-list": "[{\"province\":\"??\",\"city\":\"???\",\"county\":\"???\",\"street\":\"?????\"}]",
+ "ue-mobility-level": "stationary",
+ "resource-sharing-level": "0",
+ "exp-data-rate-UL": 100,
+ "exp-data-rate-DL": 100,
+ "activity-factor": 0,
+ "e2e-latency": 0,
+ "jitter": 0,
+ "survival-time": 0,
+ "exp-data-rate": 0,
+ "payload-size": 0,
+ "traffic-density": 0,
+ "conn-density": 0,
+ "reliability": 99.999,
+ "resource-version": "1581418602494"
+ }
+]
+
diff --git a/test/apps/nxi_termination/success_relationship_list.json b/test/apps/nxi_termination/success_relationship_list.json
new file mode 100644
index 0000000..4f2a8bb
--- /dev/null
+++ b/test/apps/nxi_termination/success_relationship_list.json
@@ -0,0 +1,27 @@
+[
+ {
+ "related-to": "service-instance",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf",
+ "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/4115d3c8-dd59-45d6-b09d-e756dee9b518",
+ "relationship-data": [
+ {
+ "relationship-key": "customer.global-customer-id",
+ "relationship-value": "5GCustomer"
+ },
+ {
+ "relationship-key": "service-subscription.service-type",
+ "relationship-value": "5G"
+ },
+ {
+ "relationship-key": "service-instance.service-instance-id",
+ "relationship-value": "4115d3c8-dd59-45d6-b09d-e756dee9b518"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "service-instance.service-instance-name",
+ "property-value": "nsi_test_0211"
+ }
+ ]
+ }
+ ] \ No newline at end of file
diff --git a/test/apps/nxi_termination/test_fetch_aai_data.py b/test/apps/nxi_termination/test_fetch_aai_data.py
new file mode 100644
index 0000000..241b24b
--- /dev/null
+++ b/test/apps/nxi_termination/test_fetch_aai_data.py
@@ -0,0 +1,70 @@
+# -------------------------------------------------------------------------
+# Copyright (C) 2020 Wipro Limited.
+#
+# Licensed 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 unittest
+import mock
+from unittest.mock import patch
+from osdf.config.base import osdf_config
+import osdf.config.loader as config_loader
+from osdf.utils.programming_utils import DotDict
+from osdf.utils.interfaces import json_from_file
+from osdf.adapters.aai.fetch_aai_data import get_aai_data,AAIException
+
+class TestRemoteOptProcessor(unittest.TestCase):
+ def setUp(self):
+ self.config_spec = {
+ "deployment": "config/osdf_config.yaml",
+ "core": "config/common_config.yaml"
+ }
+ self.osdf_config = DotDict(config_loader.all_configs(**self.config_spec))
+
+ def tearDown(self):
+
+ patch.stopall()
+
+
+ def test_get_aai_data(self):
+ main_dir = ""
+ response_file = main_dir + 'test/apps/nxi_termination/aai_response.json'
+ exception_response_file = main_dir + 'test/apps/nxi_termination/aai_exception_response.json'
+ request_file = main_dir + 'test/apps/nxi_termination/nxi_termination.json'
+ response_json = json_from_file(response_file)
+ request_json = json_from_file(request_file)
+ exception_json = json_from_file(exception_response_file)
+ response = mock.MagicMock()
+ response.status_code = 200
+ response.ok = True
+ response.json.return_value = response_json
+ self.patcher_req = patch('requests.get',
+ return_value = response)
+ self.Mock_req = self.patcher_req.start()
+ self.assertEquals(response_json, get_aai_data(request_json,osdf_config))
+ self.patcher_req.stop()
+
+ responsenew=mock.MagicMock()
+ responsenew.status_code=404
+ responsenew.json.return_value = exception_json
+ self.patcher_req = patch('requests.get',
+ return_value=responsenew)
+ self.Mock_req = self.patcher_req.start()
+ self.assertRaises( AAIException,get_aai_data,request_json,osdf_config)
+ self.patcher_req.stop()
+
+
+if __name__ == "__main__":
+ unittest.main() \ No newline at end of file
diff --git a/test/apps/nxi_termination/test_remote_opt_processor_termination.py b/test/apps/nxi_termination/test_remote_opt_processor_termination.py
new file mode 100644
index 0000000..4fa8170
--- /dev/null
+++ b/test/apps/nxi_termination/test_remote_opt_processor_termination.py
@@ -0,0 +1,141 @@
+# -------------------------------------------------------------------------
+# Copyright (C) 2020 Wipro Limited.
+#
+# Licensed 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 unittest
+from unittest.mock import patch
+import osdf.config.loader as config_loader
+import pytest
+from apps.nxi_termination.optimizers.remote_opt_processor import process_nxi_termination_opt
+from osdf.adapters.aai.fetch_aai_data import AAIException
+
+from osdf.config.base import osdf_config
+from osdf.utils.programming_utils import DotDict
+from osdf.utils.interfaces import json_from_file
+
+class TestRemoteOptProcessor(unittest.TestCase):
+ def setUp(self):
+ self.config_spec = {
+ "deployment": "config/osdf_config.yaml",
+ "core": "config/common_config.yaml"
+ }
+ self.osdf_config = DotDict(config_loader.all_configs(**self.config_spec))
+
+ def tearDown(self):
+
+ patch.stopall()
+
+ def test_process_nxi_termination_opt(self):
+ main_dir = ""
+ request_file = main_dir + 'test/apps/nxi_termination/nxi_termination.json'
+ nssi_request_file=main_dir + 'test/apps/nxi_termination/nssi_termination.json'
+ service_file = main_dir + 'test/apps/nxi_termination/service_profiles.json'
+ failure_service_file = main_dir + 'test/apps/nxi_termination/failure_service_profiles.json'
+ failure_service_file2 = main_dir + 'test/apps/nxi_termination/failure_service_profiles2.json'
+ nsi_success=main_dir + 'test/apps/nxi_termination/nsi_success_output.json'
+ nxi_failure1 = main_dir + 'test/apps/nxi_termination/nxi_failure_output1.json'
+ nxi_failure2 = main_dir + 'test/apps/nxi_termination/nxi_failure_output2.json'
+ nssi_failure = main_dir + 'test/apps/nxi_termination/nssi_failure_output.json'
+ success_rel_file = main_dir + 'test/apps/nxi_termination/success_relationship_list.json'
+ failure_rel_file1 = main_dir + 'test/apps/nxi_termination/failure_relationship_list.json'
+ failure_rel_file2 = main_dir + 'test/apps/nxi_termination/failure_relationship_list2.json'
+ exception_response_file1 = main_dir + 'test/apps/nxi_termination/exception_response1.json'
+ request_json=json_from_file(request_file)
+ nssi_request_json = json_from_file(nssi_request_file)
+ service_profile_json = json_from_file(service_file)
+ failure_service_profile_json = json_from_file(failure_service_file)
+ failure_service_profile_json2 = json_from_file(failure_service_file2)
+ success_rel_json=json_from_file(success_rel_file)
+ failure_rel_json = json_from_file(failure_rel_file1)
+ failure_rel_json2 = json_from_file(failure_rel_file2)
+ success_output_json=json_from_file(nsi_success)
+ nxi_failure_output_json1 = json_from_file(nxi_failure1)
+ nxi_failure_output_json2 = json_from_file(nxi_failure2)
+ nssi_failure_output_json = json_from_file(nssi_failure)
+ exception_response_json1 = json_from_file(exception_response_file1)
+
+ #nsi success scenario
+ self.patcher_req=patch('apps.nxi_termination.optimizers.remote_opt_processor.get_service_profiles',return_value=service_profile_json)
+ self.Mock_req = self.patcher_req.start()
+ self.assertEquals(success_output_json, process_nxi_termination_opt(request_json,osdf_config))
+ self.patcher_req.stop()
+
+ #nsi failure scenario
+ self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_service_profiles', return_value=failure_service_profile_json)
+ self.Mock_req = self.patcher_req.start()
+ self.assertEquals(nxi_failure_output_json1, process_nxi_termination_opt(request_json, osdf_config))
+ self.patcher_req.stop()
+
+ #nsi success scenario
+ self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_service_profiles',
+ return_value=[])
+ self.Mock_req = self.patcher_req.start()
+ self.assertEquals(success_output_json, process_nxi_termination_opt(request_json, osdf_config))
+ self.patcher_req.stop()
+
+ # nsi failure scenario
+ self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_service_profiles',
+ return_value=failure_service_profile_json2)
+ self.Mock_req = self.patcher_req.start()
+ self.assertEquals(nxi_failure_output_json2, process_nxi_termination_opt(request_json, osdf_config))
+ self.patcher_req.stop()
+ # #
+ # nssi success scenario
+ self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_relationshiplist', return_value=success_rel_json)
+ self.Mock_req = self.patcher_req.start()
+ self.assertEquals(success_output_json, process_nxi_termination_opt(nssi_request_json, osdf_config))
+ self.patcher_req.stop()
+
+ # nssi success scenario
+ self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_relationshiplist',
+ return_value=[])
+ self.Mock_req = self.patcher_req.start()
+ self.assertEquals(success_output_json, process_nxi_termination_opt(nssi_request_json, osdf_config))
+ self.patcher_req.stop()
+
+ # nssi failure scenario
+ self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_relationshiplist',
+ return_value=failure_rel_json)
+ self.Mock_req = self.patcher_req.start()
+ self.assertEquals(nssi_failure_output_json, process_nxi_termination_opt(nssi_request_json, osdf_config))
+ self.patcher_req.stop()
+
+ # nssi failure scenario
+ self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_relationshiplist',
+ return_value=failure_rel_json2)
+ self.Mock_req = self.patcher_req.start()
+ self.assertEquals(nxi_failure_output_json2, process_nxi_termination_opt(nssi_request_json, osdf_config))
+ self.patcher_req.stop()
+
+ self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_relationshiplist',
+ side_effect=AAIException("Error response recieved from AAI for the request"))
+ self.Mock_req = self.patcher_req.start()
+ self.assertEquals(exception_response_json1, process_nxi_termination_opt(nssi_request_json, osdf_config))
+ self.patcher_req.stop()
+
+
+ self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_relationshiplist',
+ side_effect=AAIException("Request exception was encountered"))
+ self.Mock_req = self.patcher_req.start()
+ self.assertEquals("failure", process_nxi_termination_opt(nssi_request_json, osdf_config).get('requestStatus'))
+ self.patcher_req.stop()
+
+
+
+
+if __name__ == "__main__":
+ unittest.main() \ No newline at end of file