blob: 3acc56bb4ed0548e7dfe6012852eaead12e436ab [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"
kalnagy92162652019-07-02 15:15:49 +020032 "routing-manager/pkg/rtmgr"
33 "routing-manager/pkg/stub"
wahidw480359e2020-04-06 06:56:02 +000034 "time"
35 "os"
36 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
kalnagy92162652019-07-02 15:15:49 +020037 "testing"
38)
39
wahidw480359e2020-04-06 06:56:02 +000040type Consumer struct{}
41
42func (m Consumer) Consume(params *xapp.RMRParams) (err error) {
43 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) {
49 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) {
kalnagy92162652019-07-02 15:15:49 +020059 rtmgr.Eps = make(map[string]*rtmgr.Endpoint)
60 for _, endpoint := range testdata {
61 ep := endpoint
wahidw480359e2020-04-06 06:56:02 +000062 //ep.Socket, _ = instance.NewSocket()
kalnagy92162652019-07-02 15:15:49 +020063 rtmgr.Eps[ep.Uuid] = &ep
64 }
65}
66
67/*
wahidwbce67472020-06-15 13:52:55 +000068rmrpush.Initialize() method is empty, nothing to be tested
kalnagy92162652019-07-02 15:15:49 +020069*/
wahidwbce67472020-06-15 13:52:55 +000070func TestRmrPushInitialize(t *testing.T) {
71 var rmrpush = RmrPush{}
kalnagy92162652019-07-02 15:15:49 +020072
wahidwbce67472020-06-15 13:52:55 +000073 _ = rmrpush.Initialize("")
kalnagy92162652019-07-02 15:15:49 +020074}
75
76/*
wahidwbce67472020-06-15 13:52:55 +000077rmrpush.Terminate() method is empty, nothing to be tested
kalnagy92162652019-07-02 15:15:49 +020078*/
wahidwbce67472020-06-15 13:52:55 +000079func TestRmrPushTerminate(t *testing.T) {
80 var rmrpush = RmrPush{}
kalnagy92162652019-07-02 15:15:49 +020081
wahidwbce67472020-06-15 13:52:55 +000082 _ = rmrpush.Terminate()
kalnagy92162652019-07-02 15:15:49 +020083}
84
85/*
wahidwbce67472020-06-15 13:52:55 +000086rmrpush.UpdateEndpoints() is testd against stub.ValidXApps dataset
kalnagy92162652019-07-02 15:15:49 +020087*/
wahidwbce67472020-06-15 13:52:55 +000088func TestRmrPushUpdateEndpoints(t *testing.T) {
89 var rmrpush = RmrPush{}
90 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
kalnagy92162652019-07-02 15:15:49 +020091
wahidwbce67472020-06-15 13:52:55 +000092 rmrpush.UpdateEndpoints(&stub.ValidRicComponents)
kalnagy92162652019-07-02 15:15:49 +020093 if rtmgr.Eps == nil {
wahidwbce67472020-06-15 13:52:55 +000094 t.Errorf("rmrpush.UpdateEndpoints() result was incorrect, got: %v, want: %v.", nil, "rtmgr.Endpoints")
kalnagy92162652019-07-02 15:15:49 +020095 }
96}
97
98/*
wahidwbce67472020-06-15 13:52:55 +000099rmrpush.AddEndpoint() is tested for happy path case
kalnagy92162652019-07-02 15:15:49 +0200100*/
wahidwbce67472020-06-15 13:52:55 +0000101func TestRmrPushAddEndpoint(t *testing.T) {
rangajald14518e2020-04-21 12:33:37 +0000102// var err error
wahidwbce67472020-06-15 13:52:55 +0000103 var rmrpush = RmrPush{}
104 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
105 _ = rmrpush.AddEndpoint(rtmgr.Eps["localhost"])
rangajald14518e2020-04-21 12:33:37 +0000106/* if err != nil {
wahidwbce67472020-06-15 13:52:55 +0000107 t.Errorf("rmrpush.AddEndpoint() return was incorrect, got: %v, want: %v.", err, "nil")
rangajald14518e2020-04-21 12:33:37 +0000108 }*/
kalnagy92162652019-07-02 15:15:49 +0200109}
110
kalnagy92162652019-07-02 15:15:49 +0200111
112/*
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
wahidwbce67472020-06-15 13:52:55 +0000120 err = rmrpush.DistributeAll(stub.ValidPolicies)
kalnagy92162652019-07-02 15:15:49 +0200121 if err != nil {
wahidwbce67472020-06-15 13:52:55 +0000122 t.Errorf("rmrpush.DistributeAll(policies) was incorrect, got: %v, want: %v.", err, "nil")
kalnagy92162652019-07-02 15:15:49 +0200123 }
124}
125
126/*
wahidwbce67472020-06-15 13:52:55 +0000127rmrpush.DistributeToEp() is tested for Sending case
kalnagy92162652019-07-02 15:15:49 +0200128*/
wahidw480359e2020-04-06 06:56:02 +0000129func TestDistributeToEp(t *testing.T) {
kalnagy92162652019-07-02 15:15:49 +0200130 var err error
wahidwbce67472020-06-15 13:52:55 +0000131 var rmrpush = RmrPush{}
132 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
kalnagy92162652019-07-02 15:15:49 +0200133
wahidwbce67472020-06-15 13:52:55 +0000134 err = rmrpush.DistributeToEp(stub.ValidPolicies,rtmgr.Eps["localhost"])
kalnagy92162652019-07-02 15:15:49 +0200135 if err != nil {
wahidwbce67472020-06-15 13:52:55 +0000136 t.Errorf("rmrpush.DistributetoEp(policies) was incorrect, got: %v, want: %v.", err, "nil")
kalnagy92162652019-07-02 15:15:49 +0200137 }
138}
139
wahidw480359e2020-04-06 06:56:02 +0000140func TestDeleteEndpoint(t *testing.T) {
kalnagy92162652019-07-02 15:15:49 +0200141 var err error
wahidwbce67472020-06-15 13:52:55 +0000142 var rmrpush = RmrPush{}
143 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
kalnagy92162652019-07-02 15:15:49 +0200144
wahidwbce67472020-06-15 13:52:55 +0000145 err = rmrpush.DeleteEndpoint(rtmgr.Eps["localhost"])
kalnagy92162652019-07-02 15:15:49 +0200146 if err != nil {
wahidwbce67472020-06-15 13:52:55 +0000147 t.Errorf("rmrpush.DeleteEndpoint() was incorrect, got: %v, want: %v.", err, "nil")
kalnagy92162652019-07-02 15:15:49 +0200148 }
149}
150
wahidw480359e2020-04-06 06:56:02 +0000151func TestCreateEndpoint(t *testing.T) {
wahidwbce67472020-06-15 13:52:55 +0000152 var rmrpush = RmrPush{}
153 resetTestPushDataset(rmrpush, stub.ValidEndpoints1)
wahidw7aaff4b2020-08-12 13:06:43 +0530154 rmrpush.CreateEndpoint("192.168.0.1:0","Src=192.168.0.1:4561")
wahidw2e7c3b22020-08-13 15:59:55 +0530155 rmrpush.CreateEndpoint("localhost:4560","Src=192.168.11.1:4444")
kalnagy92162652019-07-02 15:15:49 +0200156}
wahidw427929c2019-12-16 07:02:50 +0000157/*
158Initialize and send policies
159*/
wahidwbce67472020-06-15 13:52:55 +0000160func TestRmrPushInitializeandsendPolicies(t *testing.T) {
161 var rmrpush = RmrPush{}
162 resetTestPushDataset(rmrpush, stub.ValidEndpoints)
wahidw427929c2019-12-16 07:02:50 +0000163 policies := []string{"hello","welcome"}
wahidwbce67472020-06-15 13:52:55 +0000164 rmrpush.send_data(rtmgr.Eps["localhost"],&policies,1)
wahidw427929c2019-12-16 07:02:50 +0000165}