2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
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
10 http://www.apache.org/licenses/LICENSE-2.0
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.
18 This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 platform project (RICP).
21 ==================================================================================
24 Mnemonic: rmrpush_test.go
32 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
34 "routing-manager/pkg/rtmgr"
35 "routing-manager/pkg/stub"
40 type Consumer struct{}
42 func (m Consumer) Consume(params *xapp.RMRParams) (err error) {
43 xapp.SdlStorage.Store(rtmgr.RTMGR_SDL_NS, "myKey", params.Payload)
48 func TestMain(m *testing.M) {
49 go xapp.RunWithParams(Consumer{}, false)
50 time.Sleep(time.Duration(5) * time.Second)
56 Resets the EndpointList according to argumnets
58 func resetTestPushDataset(instance RmrPush, testdata []rtmgr.Endpoint) {
59 rtmgr.RMRConnStatus = make(map[string]bool)
60 rtmgr.Eps = make(map[string]*rtmgr.Endpoint)
61 for _, endpoint := range testdata {
63 //ep.Socket, _ = instance.NewSocket()
64 rtmgr.Eps[ep.Uuid] = &ep
69 rmrpush.Initialize() method is empty, nothing to be tested
71 func TestRmrPushInitialize(t *testing.T) {
72 var rmrpush = RmrPush{}
74 _ = rmrpush.Initialize("")
78 rmrpush.Terminate() method is empty, nothing to be tested
80 func TestRmrPushTerminate(t *testing.T) {
81 var rmrpush = RmrPush{}
83 _ = rmrpush.Terminate()
87 rmrpush.UpdateEndpoints() is testd against stub.ValidXApps dataset
89 func TestRmrPushUpdateEndpoints(t *testing.T) {
90 var rmrpush = RmrPush{}
91 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
93 rmrpush.UpdateEndpoints(&stub.ValidRicComponents)
95 t.Errorf("rmrpush.UpdateEndpoints() result was incorrect, got: %v, want: %v.", nil, "rtmgr.Endpoints")
100 rmrpush.AddEndpoint() is tested for happy path case
102 func TestRmrPushAddEndpoint(t *testing.T) {
104 var rmrpush = RmrPush{}
105 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
106 _ = rmrpush.AddEndpoint(rtmgr.Eps["localhost"])
108 t.Errorf("rmrpush.AddEndpoint() return was incorrect, got: %v, want: %v.", err, "nil")
113 rmrpush.DistributeAll() is tested for happy path case
115 func TestRmrPushDistributeAll(t *testing.T) {
117 var rmrpush = RmrPush{}
118 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
121 err = rmrpush.DistributeAll(stub.ValidPolicies)
124 t.Errorf("rmrpush.DistributeAll(policies) was incorrect, got: %v, want: %v.", err, "nil")
129 rmrpush.DistributeToEp() is tested for Sending case
131 func TestDistributeToEp(t *testing.T) {
133 var rmrpush = RmrPush{}
134 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
136 rmrdynamiccallid = 255
137 err = rmrpush.DistributeToEp(stub.ValidPolicies, "localhost:4561", 100)
139 t.Errorf("rmrpush.DistributetoEp(policies) was incorrect, got: %v, want: %v.", err, "nil")
143 func TestDeleteEndpoint(t *testing.T) {
145 var rmrpush = RmrPush{}
146 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
148 err = rmrpush.DeleteEndpoint(rtmgr.Eps["localhost"])
150 t.Errorf("rmrpush.DeleteEndpoint() was incorrect, got: %v, want: %v.", err, "nil")
154 func TestCheckEndpoint(t *testing.T) {
155 var rmrpush = RmrPush{}
156 resetTestPushDataset(rmrpush, stub.ValidEndpoints1)
157 rmrpush.CheckEndpoint("192.168.0.1:0")
158 rmrpush.CheckEndpoint("10.2.2.1:0")
159 rmrpush.CheckEndpoint("localhost:0")
162 func TestCreateEndpoint(t *testing.T) {
163 var rmrpush = RmrPush{}
164 resetTestPushDataset(rmrpush, stub.ValidEndpoints1)
165 rmrpush.CreateEndpoint("Src=127.0.0.1:4561 hello")
169 Initialize and send policies
171 func TestRmrPushInitializeandsendPolicies(t *testing.T) {
172 var rmrpush = RmrPush{}
173 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
174 policies := []string{"hello", "welcome"}
175 rmrpush.send_data(rtmgr.Eps["localhost"], &policies, 1)
178 func TestString(t *testing.T) {
179 var params xapp.RMRParams
180 params.Payload = []byte("abcdefgh")
181 params.Meid = &xapp.RMRMeid{}
182 msg := RMRParams{¶ms}
187 func TestSenddata(t *testing.T) {
188 var rmrpush = RmrPush{}
189 ep := rtmgr.Endpoint{Whid: -1, Ip: "1.1.1.1"}
190 policies := []string{"mse|12345|-1|local.com"}
191 rmrpush.send_data(&ep, &policies, 300)
194 func TestSendDynamicdata(t *testing.T) {
195 var rmrpush = RmrPush{}
197 policies := []string{"mse|12345|-1|local.com"}
198 rmrpush.sendDynamicRoutes(ep, 1, &policies, 300)