Coverage Improvements 64/5864/1
authordhiraj <dhiraj.verma@nokia.com>
Wed, 7 Apr 2021 12:08:06 +0000 (15:08 +0300)
committerdhiraj <dhiraj.verma@nokia.com>
Wed, 7 Apr 2021 12:11:41 +0000 (15:11 +0300)
Signed-off-by: dhiraj <dhiraj.verma@nokia.com>
Change-Id: I1a5208806cf470802bf13b624fbd6af62322e36b

cmd/vespamgr/config_test.go
cmd/vespamgr/vespamgr_test.go
test/inValidMeasurements_xApp_config_test_output.json [new file with mode: 0755]
test/noConfig_xApp_config_test_output.json [new file with mode: 0755]
test/noMeasurements_xApp_config_test_output.json [new file with mode: 0755]

index eacbcbd..d65baa2 100755 (executable)
@@ -178,6 +178,19 @@ func TestParseXAppDescriptor(t *testing.T) {
        assert.Equal(t, "App2ExampleCounterOneObjectInstance", appMetrics["App2ExampleCounterOne"].ObjectInstance)
        assert.Equal(t, "App2ExampleCounterTwoObject", appMetrics["App2ExampleCounterTwo"].ObjectName)
        assert.Equal(t, "App2ExampleCounterTwoObjectInstance", appMetrics["App2ExampleCounterTwo"].ObjectInstance)
+
+       bytes, err = ioutil.ReadFile("../../test/noConfig_xApp_config_test_output.json")
+        assert.Nil(t, err)
+       appMetrics = vespaMgr.ParseMetricsFromDescriptor(bytes, appMetrics)
+
+       bytes, err = ioutil.ReadFile("../../test/noMeasurements_xApp_config_test_output.json")
+        assert.Nil(t, err)
+        appMetrics = vespaMgr.ParseMetricsFromDescriptor(bytes, appMetrics)
+
+       bytes, err = ioutil.ReadFile("../../test/inValidMeasurements_xApp_config_test_output.json")
+        assert.Nil(t, err)
+        appMetrics = vespaMgr.ParseMetricsFromDescriptor(bytes, appMetrics)
+
 }
 
 func TestParseXAppDescriptorWithNoConfig(t *testing.T) {
index 2b84ef5..9a9ca85 100755 (executable)
@@ -163,3 +163,18 @@ func executeRequest(req *http.Request, handleR http.HandlerFunc) *httptest.Respo
 func TestVespaMgrTestSuite(t *testing.T) {
        suite.Run(t, new(VespaMgrTestSuite))
 }
+
+func (suite *VespaMgrTestSuite) TestCreateConf() {
+       suite.vespaMgr.CreateConf("/unknown/text.txt", []byte{})
+}
+
+func (suite *VespaMgrTestSuite) TestHandleMeasurements() {
+        data, err := ioutil.ReadFile("../../test/xApp_config_test_output.json")
+        suite.Nil(err)
+
+        pbodyEn, _ := json.Marshal(data)
+        req, _ := http.NewRequest("POST", "/ric/v1/measurements", bytes.NewBuffer(pbodyEn))
+        handleFunc := http.HandlerFunc(suite.vespaMgr.HandleMeasurements)
+       response := executeRequest(req, handleFunc)
+        suite.Equal(http.StatusOK, response.Code)
+}
diff --git a/test/inValidMeasurements_xApp_config_test_output.json b/test/inValidMeasurements_xApp_config_test_output.json
new file mode 100755 (executable)
index 0000000..8949859
--- /dev/null
@@ -0,0 +1,78 @@
+[
+    {
+        "metadata": { },
+        "descriptor": { },
+        "config": {
+            "local": {
+                "host": ":8080"
+            },
+            "logger": {
+                "level": 5
+            },
+            "measurements": [
+                {
+                    "moId_1": "SEP-12/XAPP-1",
+                    "measType_1": "X2",
+                    "measId_1": "9001",
+                    "measInterval_1": "60",
+                    "metrics_1": [
+                        {
+                            "name": "App1ExampleCounterOne",
+                            "objectName": "App1ExampleCounterOneObject",
+                            "objectInstance": "App1ExampleCounterOneObjectInstance",
+                            "counterId": "0011",
+                            "type": "counter",
+                            "description": "Example counter 1"
+                        },
+                        {
+                            "name": "App1ExampleCounterTwo",
+                            "objectName": "App1ExampleCounterTwoObject",
+                            "objectInstance": "App1ExampleCounterTwoObjectInstance",
+                            "counterId": "0012",
+                            "type": "counter",
+                            "description": "Example counter 2"
+                        }
+                    ]
+                }
+            ]
+        }
+    },
+    {
+        "metadata": {},
+        "descriptor": {},
+        "config": {
+            "local": {
+                "host": ":8080"
+            },
+            "logger": {
+                "level": 3
+            },
+            "measurements": [
+                {
+                    "moId": "SEP-12/XAPP-2",
+                    "measType": "X2",
+                    "measId": "9002",
+                    "measInterval": "60",
+                    "metrics": [
+                        {
+                            "name": "App2ExampleCounterOne",
+                            "objectName": "App2ExampleCounterOneObject",
+                            "objectInstance": "App2ExampleCounterOneObjectInstance",
+                            "counterId": "0021",
+                            "type": "counter",
+                            "description": "Example counter 1"
+                        },
+                        {
+                            "name": "App2ExampleCounterTwo",
+                            "objectName": "App2ExampleCounterTwoObject",
+                            "objectInstance": "App2ExampleCounterTwoObjectInstance",
+                            "counterId": "0022",
+                            "type": "counter",
+                            "description": "Example counter 2"
+                        }
+                    ]
+                }
+            ]
+        }
+    }
+]
diff --git a/test/noConfig_xApp_config_test_output.json b/test/noConfig_xApp_config_test_output.json
new file mode 100755 (executable)
index 0000000..8c94811
--- /dev/null
@@ -0,0 +1,78 @@
+[
+    {
+        "metadata": { },
+        "descriptor": { },
+        "config_1": {
+            "local": {
+                "host": ":8080"
+            },
+            "logger": {
+                "level": 5
+            },
+            "measurements": [
+                {
+                    "moId": "SEP-12/XAPP-1",
+                    "measType": "X2",
+                    "measId": "9001",
+                    "measInterval": "60",
+                    "metrics": [
+                        {
+                            "name": "App1ExampleCounterOne",
+                            "objectName": "App1ExampleCounterOneObject",
+                            "objectInstance": "App1ExampleCounterOneObjectInstance",
+                            "counterId": "0011",
+                            "type": "counter",
+                            "description": "Example counter 1"
+                        },
+                        {
+                            "name": "App1ExampleCounterTwo",
+                            "objectName": "App1ExampleCounterTwoObject",
+                            "objectInstance": "App1ExampleCounterTwoObjectInstance",
+                            "counterId": "0012",
+                            "type": "counter",
+                            "description": "Example counter 2"
+                        }
+                    ]
+                }
+            ]
+        }
+    },
+    {
+        "metadata": {},
+        "descriptor": {},
+        "config": {
+            "local": {
+                "host": ":8080"
+            },
+            "logger": {
+                "level": 3
+            },
+            "measurements": [
+                {
+                    "moId": "SEP-12/XAPP-2",
+                    "measType": "X2",
+                    "measId": "9002",
+                    "measInterval": "60",
+                    "metrics": [
+                        {
+                            "name": "App2ExampleCounterOne",
+                            "objectName": "App2ExampleCounterOneObject",
+                            "objectInstance": "App2ExampleCounterOneObjectInstance",
+                            "counterId": "0021",
+                            "type": "counter",
+                            "description": "Example counter 1"
+                        },
+                        {
+                            "name": "App2ExampleCounterTwo",
+                            "objectName": "App2ExampleCounterTwoObject",
+                            "objectInstance": "App2ExampleCounterTwoObjectInstance",
+                            "counterId": "0022",
+                            "type": "counter",
+                            "description": "Example counter 2"
+                        }
+                    ]
+                }
+            ]
+        }
+    }
+]
diff --git a/test/noMeasurements_xApp_config_test_output.json b/test/noMeasurements_xApp_config_test_output.json
new file mode 100755 (executable)
index 0000000..fa142c3
--- /dev/null
@@ -0,0 +1,78 @@
+[
+    {
+        "metadata": { },
+        "descriptor": { },
+        "config": {
+            "local": {
+                "host": ":8080"
+            },
+            "logger": {
+                "level": 5
+            },
+            "measurements_1": [
+                {
+                    "moId": "SEP-12/XAPP-1",
+                    "measType": "X2",
+                    "measId": "9001",
+                    "measInterval": "60",
+                    "metrics": [
+                        {
+                            "name": "App1ExampleCounterOne",
+                            "objectName": "App1ExampleCounterOneObject",
+                            "objectInstance": "App1ExampleCounterOneObjectInstance",
+                            "counterId": "0011",
+                            "type": "counter",
+                            "description": "Example counter 1"
+                        },
+                        {
+                            "name": "App1ExampleCounterTwo",
+                            "objectName": "App1ExampleCounterTwoObject",
+                            "objectInstance": "App1ExampleCounterTwoObjectInstance",
+                            "counterId": "0012",
+                            "type": "counter",
+                            "description": "Example counter 2"
+                        }
+                    ]
+                }
+            ]
+        }
+    },
+    {
+        "metadata": {},
+        "descriptor": {},
+        "config": {
+            "local": {
+                "host": ":8080"
+            },
+            "logger": {
+                "level": 3
+            },
+            "measurements": [
+                {
+                    "moId": "SEP-12/XAPP-2",
+                    "measType": "X2",
+                    "measId": "9002",
+                    "measInterval": "60",
+                    "metrics": [
+                        {
+                            "name": "App2ExampleCounterOne",
+                            "objectName": "App2ExampleCounterOneObject",
+                            "objectInstance": "App2ExampleCounterOneObjectInstance",
+                            "counterId": "0021",
+                            "type": "counter",
+                            "description": "Example counter 1"
+                        },
+                        {
+                            "name": "App2ExampleCounterTwo",
+                            "objectName": "App2ExampleCounterTwoObject",
+                            "objectInstance": "App2ExampleCounterTwoObjectInstance",
+                            "counterId": "0022",
+                            "type": "counter",
+                            "description": "Example counter 2"
+                        }
+                    ]
+                }
+            ]
+        }
+    }
+]