blob: e53ac5c0acf672cb89a2699d14376aa99b89c384 [file] [log] [blame]
kalnagy92162652019-07-02 15:15:49 +02001/*
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.
wahidw761934a2019-11-27 06:07:26 +000017
18 This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 platform project (RICP).
20
kalnagy92162652019-07-02 15:15:49 +020021==================================================================================
22*/
23/*
wahidwbce67472020-06-15 13:52:55 +000024 Mnemonic: rmrpush_test.go
kalnagy92162652019-07-02 15:15:49 +020025 Abstract:
26 Date: 3 May 2019
27*/
28package sbi
29
30import (
wahidw480359e2020-04-06 06:56:02 +000031 //"errors"
wahidwacd34be2020-10-28 17:47:30 +000032 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
33 "os"
kalnagy92162652019-07-02 15:15:49 +020034 "routing-manager/pkg/rtmgr"
35 "routing-manager/pkg/stub"
36 "testing"
wahidwacd34be2020-10-28 17:47:30 +000037 "time"
kalnagy92162652019-07-02 15:15:49 +020038)
39
wahidw480359e2020-04-06 06:56:02 +000040type Consumer struct{}
41
42func (m Consumer) Consume(params *xapp.RMRParams) (err error) {
wahidwacd34be2020-10-28 17:47:30 +000043 xapp.Sdl.Store("myKey", params.Payload)
44 return nil
kalnagy92162652019-07-02 15:15:49 +020045}
46
wahidw480359e2020-04-06 06:56:02 +000047// Test cases
48func TestMain(m *testing.M) {
wahidwacd34be2020-10-28 17:47:30 +000049 go xapp.RunWithParams(Consumer{}, false)
50 time.Sleep(time.Duration(5) * time.Second)
51 code := m.Run()
52 os.Exit(code)
kalnagy92162652019-07-02 15:15:49 +020053}
54
55/*
56Resets the EndpointList according to argumnets
57*/
wahidwbce67472020-06-15 13:52:55 +000058func resetTestPushDataset(instance RmrPush, testdata []rtmgr.Endpoint) {
wahidw4101d102021-05-20 16:33:36 +000059 rtmgr.RMRConnStatus = make(map[string]bool)
kalnagy92162652019-07-02 15:15:49 +020060 rtmgr.Eps = make(map[string]*rtmgr.Endpoint)
61 for _, endpoint := range testdata {
62 ep := endpoint
wahidw480359e2020-04-06 06:56:02 +000063 //ep.Socket, _ = instance.NewSocket()
kalnagy92162652019-07-02 15:15:49 +020064 rtmgr.Eps[ep.Uuid] = &ep
65 }
66}
67
68/*
wahidwbce67472020-06-15 13:52:55 +000069rmrpush.Initialize() method is empty, nothing to be tested
kalnagy92162652019-07-02 15:15:49 +020070*/
wahidwbce67472020-06-15 13:52:55 +000071func TestRmrPushInitialize(t *testing.T) {
72 var rmrpush = RmrPush{}
kalnagy92162652019-07-02 15:15:49 +020073
wahidwbce67472020-06-15 13:52:55 +000074 _ = rmrpush.Initialize("")
kalnagy92162652019-07-02 15:15:49 +020075}
76
77/*
wahidwbce67472020-06-15 13:52:55 +000078rmrpush.Terminate() method is empty, nothing to be tested
kalnagy92162652019-07-02 15:15:49 +020079*/
wahidwbce67472020-06-15 13:52:55 +000080func TestRmrPushTerminate(t *testing.T) {
81 var rmrpush = RmrPush{}
kalnagy92162652019-07-02 15:15:49 +020082
wahidwbce67472020-06-15 13:52:55 +000083 _ = rmrpush.Terminate()
kalnagy92162652019-07-02 15:15:49 +020084}
85
86/*
wahidwbce67472020-06-15 13:52:55 +000087rmrpush.UpdateEndpoints() is testd against stub.ValidXApps dataset
kalnagy92162652019-07-02 15:15:49 +020088*/
wahidwbce67472020-06-15 13:52:55 +000089func TestRmrPushUpdateEndpoints(t *testing.T) {
90 var rmrpush = RmrPush{}
91 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
kalnagy92162652019-07-02 15:15:49 +020092
wahidwbce67472020-06-15 13:52:55 +000093 rmrpush.UpdateEndpoints(&stub.ValidRicComponents)
kalnagy92162652019-07-02 15:15:49 +020094 if rtmgr.Eps == nil {
wahidwbce67472020-06-15 13:52:55 +000095 t.Errorf("rmrpush.UpdateEndpoints() result was incorrect, got: %v, want: %v.", nil, "rtmgr.Endpoints")
kalnagy92162652019-07-02 15:15:49 +020096 }
97}
98
99/*
wahidwbce67472020-06-15 13:52:55 +0000100rmrpush.AddEndpoint() is tested for happy path case
kalnagy92162652019-07-02 15:15:49 +0200101*/
wahidwbce67472020-06-15 13:52:55 +0000102func TestRmrPushAddEndpoint(t *testing.T) {
wahidwacd34be2020-10-28 17:47:30 +0000103 // var err error
wahidwbce67472020-06-15 13:52:55 +0000104 var rmrpush = RmrPush{}
105 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
106 _ = rmrpush.AddEndpoint(rtmgr.Eps["localhost"])
wahidwacd34be2020-10-28 17:47:30 +0000107 /* if err != nil {
wahidwbce67472020-06-15 13:52:55 +0000108 t.Errorf("rmrpush.AddEndpoint() return was incorrect, got: %v, want: %v.", err, "nil")
rangajald14518e2020-04-21 12:33:37 +0000109 }*/
kalnagy92162652019-07-02 15:15:49 +0200110}
111
kalnagy92162652019-07-02 15:15:49 +0200112/*
wahidwbce67472020-06-15 13:52:55 +0000113rmrpush.DistributeAll() is tested for happy path case
kalnagy92162652019-07-02 15:15:49 +0200114*/
wahidwbce67472020-06-15 13:52:55 +0000115func TestRmrPushDistributeAll(t *testing.T) {
kalnagy92162652019-07-02 15:15:49 +0200116 var err error
wahidwbce67472020-06-15 13:52:55 +0000117 var rmrpush = RmrPush{}
118 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
kalnagy92162652019-07-02 15:15:49 +0200119
wahidw49845222020-08-22 20:34:59 +0530120 rmrcallid = 200
wahidwbce67472020-06-15 13:52:55 +0000121 err = rmrpush.DistributeAll(stub.ValidPolicies)
wahidwacd34be2020-10-28 17:47:30 +0000122 t.Log(err)
123 /*if err != nil {
wahidwbce67472020-06-15 13:52:55 +0000124 t.Errorf("rmrpush.DistributeAll(policies) was incorrect, got: %v, want: %v.", err, "nil")
wahidwacd34be2020-10-28 17:47:30 +0000125 }*/
kalnagy92162652019-07-02 15:15:49 +0200126}
127
128/*
wahidwbce67472020-06-15 13:52:55 +0000129rmrpush.DistributeToEp() is tested for Sending case
kalnagy92162652019-07-02 15:15:49 +0200130*/
wahidw480359e2020-04-06 06:56:02 +0000131func TestDistributeToEp(t *testing.T) {
kalnagy92162652019-07-02 15:15:49 +0200132 var err error
wahidwbce67472020-06-15 13:52:55 +0000133 var rmrpush = RmrPush{}
134 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
kalnagy92162652019-07-02 15:15:49 +0200135
wahidw49845222020-08-22 20:34:59 +0530136 rmrdynamiccallid = 255
wahidwacd34be2020-10-28 17:47:30 +0000137 err = rmrpush.DistributeToEp(stub.ValidPolicies, "localhost:4561", 100)
kalnagy92162652019-07-02 15:15:49 +0200138 if err != nil {
wahidwbce67472020-06-15 13:52:55 +0000139 t.Errorf("rmrpush.DistributetoEp(policies) was incorrect, got: %v, want: %v.", err, "nil")
kalnagy92162652019-07-02 15:15:49 +0200140 }
141}
142
wahidw480359e2020-04-06 06:56:02 +0000143func TestDeleteEndpoint(t *testing.T) {
kalnagy92162652019-07-02 15:15:49 +0200144 var err error
wahidwbce67472020-06-15 13:52:55 +0000145 var rmrpush = RmrPush{}
146 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
kalnagy92162652019-07-02 15:15:49 +0200147
wahidwbce67472020-06-15 13:52:55 +0000148 err = rmrpush.DeleteEndpoint(rtmgr.Eps["localhost"])
kalnagy92162652019-07-02 15:15:49 +0200149 if err != nil {
wahidwbce67472020-06-15 13:52:55 +0000150 t.Errorf("rmrpush.DeleteEndpoint() was incorrect, got: %v, want: %v.", err, "nil")
kalnagy92162652019-07-02 15:15:49 +0200151 }
152}
153
wahidw49845222020-08-22 20:34:59 +0530154func 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")
160}
161
wahidw480359e2020-04-06 06:56:02 +0000162func TestCreateEndpoint(t *testing.T) {
wahidwbce67472020-06-15 13:52:55 +0000163 var rmrpush = RmrPush{}
164 resetTestPushDataset(rmrpush, stub.ValidEndpoints1)
wahidw49845222020-08-22 20:34:59 +0530165 rmrpush.CreateEndpoint("Src=127.0.0.1:4561 hello")
kalnagy92162652019-07-02 15:15:49 +0200166}
wahidwacd34be2020-10-28 17:47:30 +0000167
wahidw427929c2019-12-16 07:02:50 +0000168/*
169Initialize and send policies
170*/
wahidwbce67472020-06-15 13:52:55 +0000171func TestRmrPushInitializeandsendPolicies(t *testing.T) {
wahidwacd34be2020-10-28 17:47:30 +0000172 var rmrpush = RmrPush{}
wahidwbce67472020-06-15 13:52:55 +0000173 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
wahidwacd34be2020-10-28 17:47:30 +0000174 policies := []string{"hello", "welcome"}
175 rmrpush.send_data(rtmgr.Eps["localhost"], &policies, 1)
wahidw427929c2019-12-16 07:02:50 +0000176}
wahidw49845222020-08-22 20:34:59 +0530177
wahidwacd34be2020-10-28 17:47:30 +0000178func TestString(t *testing.T) {
wahidw49845222020-08-22 20:34:59 +0530179 var params xapp.RMRParams
180 params.Payload = []byte("abcdefgh")
181 params.Meid = &xapp.RMRMeid{}
182 msg := RMRParams{&params}
183 msg.String()
184
185}
186
187func TestSenddata(t *testing.T) {
188 var rmrpush = RmrPush{}
wahidwacd34be2020-10-28 17:47:30 +0000189 ep := rtmgr.Endpoint{Whid: -1, Ip: "1.1.1.1"}
wahidw49845222020-08-22 20:34:59 +0530190 policies := []string{"mse|12345|-1|local.com"}
wahidwacd34be2020-10-28 17:47:30 +0000191 rmrpush.send_data(&ep, &policies, 300)
wahidw49845222020-08-22 20:34:59 +0530192}
193
194func TestSendDynamicdata(t *testing.T) {
195 var rmrpush = RmrPush{}
196 ep := "1.1.1.1"
197 policies := []string{"mse|12345|-1|local.com"}
wahidwacd34be2020-10-28 17:47:30 +0000198 rmrpush.sendDynamicRoutes(ep, 1, &policies, 300)
wahidw49845222020-08-22 20:34:59 +0530199}