MEID tableupdated incrementally rather than full update
[ric-plt/rtmgr.git] / pkg / sdl / sdl_test.go
1 /*
2 ==================================================================================
3    Copyright (c) 2019 AT&T Intellectual Property.
4    Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17
18    This source code is part of the near-RT RIC (RAN Intelligent Controller)
19    platform project (RICP).
20
21 ==================================================================================
22 */
23 /*
24         Mnemonic:       sbi_test.go
25         Abstract:
26         Date:           25 April 2019
27 */
28 package sdl
29
30 import (
31         "routing-manager/pkg/stub"
32         "github.com/go-openapi/swag"
33         "routing-manager/pkg/models"
34         "routing-manager/pkg/rtmgr"
35         "testing"
36 )
37
38 /*
39 RmrPub.GeneratePolicies() method is tested for happy path case
40 */
41 func TestFileWriteAll(t *testing.T) {
42         var err error
43         var file = File{}
44
45         err = file.WriteAll("ut.rt", &stub.ValidRicComponents)
46         t.Log(err)
47         /* This test is for empty file */
48         err = file.WriteAll("", &stub.ValidRicComponents)
49         t.Log(err)
50 }
51
52 /*
53 RmrPush.GeneratePolicies() method is tested for happy path case
54 */
55 func TestFileReadAll(t *testing.T) {
56         var err error
57         var file = File{}
58
59         data, err := file.ReadAll("ut.rt")
60         t.Log(data)
61         t.Log(err)
62         /* Test to read a Directory */
63         data, err = file.ReadAll("/tmp")
64         t.Log(data)
65         t.Log(err)
66 }
67
68 /*
69 WriteXApps
70 */
71 func TestFileWriteXApps(t *testing.T) {
72         var err error
73         var file = File{}
74
75         err = file.WriteXApps("ut.rt", stub.ValidXApps)
76         t.Log(err)
77         /*Write data to a file that doesn't exist */
78         err = file.WriteXApps("ut.rtx", stub.ValidXApps)
79         t.Log(err)
80
81 }
82
83 /*
84 GetSdl instance with correct and incorrect arguments
85 */
86 func TestFileGetSdl(t *testing.T) {
87         var err error
88         _, err = GetSdl("")
89         t.Log(err)
90         _, err = GetSdl("file")
91         t.Log(err)
92 }
93
94 /*
95 WriteNewE2TInstance
96 */
97 func TestWriteNewE2TInstance(t *testing.T) {
98         var err error
99         var file = File{}
100         file.WriteNewE2TInstance("", &stub.ValidE2TInstance,"")
101         t.Log(err)
102         file.WriteNewE2TInstance("ut.rt", &stub.ValidE2TInstance,"meid_arr")
103         t.Log(err)
104 }
105
106 /*
107 WriteAssRANToE2TInstance
108 */
109 func TestWriteAssRANToE2TInstance(t *testing.T) {
110         var err error
111         var file = File{}
112         // File is not provided as argument
113         file.WriteAssRANToE2TInstance("",stub.Rane2tmap)
114         t.Log(err)
115         file.WriteNewE2TInstance("ut.rt", &stub.ValidE2TInstance,"")
116         file.WriteAssRANToE2TInstance("ut.rt",stub.Rane2tmap)
117         t.Log(err)
118 }
119
120 /*
121 WriteDisAssRANFromE2TInstance 
122 */
123 func TestWriteDisAssRANFromE2TInstance(t *testing.T) {
124         var err error
125         var file = File{}
126         // File is not provided as argument
127         file.WriteDisAssRANFromE2TInstance("",stub.Rane2tmap)
128         t.Log(err)
129         //RAN list is empty
130         file.WriteNewE2TInstance("ut.rt", &stub.ValidE2TInstance,"")
131         file.WriteAssRANToE2TInstance("ut.rt",stub.Rane2tmap)
132         file.WriteDisAssRANFromE2TInstance("ut.rt",stub.Rane2tmaponlyE2t)
133         //RAN list is present
134         file.WriteNewE2TInstance("ut.rt", &stub.ValidE2TInstance,"")
135         file.WriteAssRANToE2TInstance("ut.rt",stub.Rane2tmap)
136         file.WriteDisAssRANFromE2TInstance("ut.rt",stub.Rane2tmap)
137         t.Log(err)
138 }
139
140 /*
141 WriteDeleteE2TInstance E2TInst *models.E2tDeleteData) error
142 */
143 func TestWriteDeleteE2TInstance(t *testing.T) {
144         var err error
145         var file = File{}
146         e2deldata := &models.E2tDeleteData{}
147         // File is not provided as argument
148         file.WriteDeleteE2TInstance("",e2deldata)
149         //Delete E2t Instance,associate new rans and dissociate some rans
150         file.WriteNewE2TInstance("ut.rt", &rtmgr.E2TInstance{
151                 Name:    "E2Tinstance1",
152                 Fqdn:    "10.10.10.10:100",
153                 Ranlist: []string{"1", "2"},
154                         },"meid_del|test",
155                 )
156         file.WriteNewE2TInstance("ut.rt", &rtmgr.E2TInstance{
157                 Name:    "E2Tinstance2",
158                 Fqdn:    "11.11.11.11:100",
159                 Ranlist: []string{"3", "4"},
160                         },"",
161                 )
162         file.WriteDeleteE2TInstance("ut.rt",&models.E2tDeleteData{
163                 E2TAddress: swag.String("10.10.10.10:100"),
164                 //RanNamelistTobeDissociated: []string{"1","2"},
165                 RanAssocList: models.RanE2tMap{
166                                 {E2TAddress: swag.String("11.11.11.11:100"),RanNamelist: []string{"5","6"}},
167                                 {E2TAddress: swag.String("doesntexist"),RanNamelist: []string{}}, },
168                         })
169         file.WriteNewE2TInstance("ut.rt", &rtmgr.E2TInstance{
170                 Name:    "E2Tinstance1",
171                 Fqdn:    "10.10.10.10:100",
172                 Ranlist: []string{"1", "2"},
173                         },"meid_del|test",
174                 )
175         file.WriteDeleteE2TInstance("ut.rt",&models.E2tDeleteData{
176                 E2TAddress: swag.String("10.10.10.10:100"),
177                 RanNamelistTobeDissociated: []string{"1","2"},
178                 RanAssocList: models.RanE2tMap{
179                                 {E2TAddress: swag.String("11.11.11.11:100"),RanNamelist: []string{"5","6"}},
180                                 {E2TAddress: swag.String("doesntexist"),RanNamelist: []string{}}, },
181                         })
182         t.Log(err)
183
184 }