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 "routing-manager/pkg/rtmgr"
33 "routing-manager/pkg/stub"
36 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
40 type Consumer struct{}
42 func (m Consumer) Consume(params *xapp.RMRParams) (err error) {
43 xapp.Sdl.Store("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.Eps = make(map[string]*rtmgr.Endpoint)
60 for _, endpoint := range testdata {
62 //ep.Socket, _ = instance.NewSocket()
63 rtmgr.Eps[ep.Uuid] = &ep
68 rmrpush.Initialize() method is empty, nothing to be tested
70 func TestRmrPushInitialize(t *testing.T) {
71 var rmrpush = RmrPush{}
73 _ = rmrpush.Initialize("")
77 rmrpush.Terminate() method is empty, nothing to be tested
79 func TestRmrPushTerminate(t *testing.T) {
80 var rmrpush = RmrPush{}
82 _ = rmrpush.Terminate()
86 rmrpush.UpdateEndpoints() is testd against stub.ValidXApps dataset
88 func TestRmrPushUpdateEndpoints(t *testing.T) {
89 var rmrpush = RmrPush{}
90 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
92 rmrpush.UpdateEndpoints(&stub.ValidRicComponents)
94 t.Errorf("rmrpush.UpdateEndpoints() result was incorrect, got: %v, want: %v.", nil, "rtmgr.Endpoints")
99 rmrpush.AddEndpoint() is tested for happy path case
101 func TestRmrPushAddEndpoint(t *testing.T) {
103 var rmrpush = RmrPush{}
104 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
105 _ = rmrpush.AddEndpoint(rtmgr.Eps["localhost"])
107 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)
120 err = rmrpush.DistributeAll(stub.ValidPolicies)
122 t.Errorf("rmrpush.DistributeAll(policies) was incorrect, got: %v, want: %v.", err, "nil")
127 rmrpush.DistributeToEp() is tested for Sending case
129 func TestDistributeToEp(t *testing.T) {
131 var rmrpush = RmrPush{}
132 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
134 err = rmrpush.DistributeToEp(stub.ValidPolicies,rtmgr.Eps["localhost"])
136 t.Errorf("rmrpush.DistributetoEp(policies) was incorrect, got: %v, want: %v.", err, "nil")
140 func TestDeleteEndpoint(t *testing.T) {
142 var rmrpush = RmrPush{}
143 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
145 err = rmrpush.DeleteEndpoint(rtmgr.Eps["localhost"])
147 t.Errorf("rmrpush.DeleteEndpoint() was incorrect, got: %v, want: %v.", err, "nil")
151 func TestCreateEndpoint(t *testing.T) {
152 var rmrpush = RmrPush{}
153 resetTestPushDataset(rmrpush, stub.ValidEndpoints1)
154 rmrpush.CreateEndpoint("192.168.0.1:0","Src=192.168.0.1:4561")
155 rmrpush.CreateEndpoint("localhost:4560","Src=localhost:4561")
158 Initialize and send policies
160 func TestRmrPushInitializeandsendPolicies(t *testing.T) {
161 var rmrpush = RmrPush{}
162 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
163 policies := []string{"hello","welcome"}
164 rmrpush.send_data(rtmgr.Eps["localhost"],&policies,1)