ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2019 AT&T Intellectual Property |
| 3 | // Copyright 2019 Nokia |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
nm755n | 15d3982 | 2019-11-28 16:56:00 +0000 | [diff] [blame] | 16 | |
| 17 | // This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 18 | // platform project (RICP). |
| 19 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 20 | package rNibWriter |
| 21 | |
| 22 | import ( |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 23 | "e2mgr/configuration" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 24 | "e2mgr/mocks" |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 25 | "encoding/json" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 26 | "errors" |
| 27 | "fmt" |
is005q | 19bf35e | 2019-08-12 18:59:29 +0300 | [diff] [blame] | 28 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" |
| 29 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 30 | "github.com/golang/protobuf/proto" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 31 | "github.com/stretchr/testify/assert" |
| 32 | "testing" |
| 33 | "time" |
| 34 | ) |
| 35 | |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 36 | var namespace = "namespace" |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 37 | |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 38 | const ( |
| 39 | RanName = "test" |
| 40 | ) |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 41 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 42 | func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) { |
| 43 | sdlInstanceMock = new(mocks.MockSdlInstance) |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 44 | w = GetRNibWriter(sdlInstanceMock, configuration.RnibWriterConfig{StateChangeMessageChannel: "RAN_CONNECTION_STATUS_CHANGE", RanManipulationMessageChannel: "RAN_MANIPULATION"}) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 45 | return |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 46 | } |
| 47 | |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 48 | func generateNodebInfo(inventoryName string, nodeType entities.Node_Type, plmnId string, nbId string) *entities.NodebInfo { |
| 49 | nodebInfo := &entities.NodebInfo{ |
| 50 | RanName: inventoryName, |
| 51 | GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}, |
| 52 | NodeType: nodeType, |
| 53 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 54 | } |
| 55 | |
| 56 | if nodeType == entities.Node_ENB { |
| 57 | nodebInfo.Configuration = &entities.NodebInfo_Enb{ |
| 58 | Enb: &entities.Enb{}, |
| 59 | } |
| 60 | } else if nodeType == entities.Node_GNB { |
| 61 | nodebInfo.Configuration = &entities.NodebInfo_Gnb{ |
| 62 | Gnb: &entities.Gnb{}, |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return nodebInfo |
| 67 | } |
| 68 | |
| 69 | func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell { |
| 70 | |
Irina | 5830d4d | 2020-07-08 18:11:04 +0000 | [diff] [blame^] | 71 | var servedNrCells []*entities.ServedNRCell |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 72 | |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 73 | for i, v := range cellIds { |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 74 | servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{ |
| 75 | CellId: v, |
| 76 | ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{ |
| 77 | Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{ |
| 78 | |
| 79 | }, |
| 80 | }, |
| 81 | NrMode: entities.Nr_FDD, |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 82 | NrPci: uint32(i + 1), |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 83 | ServedPlmns: []string{"whatever"}, |
| 84 | }}) |
| 85 | } |
| 86 | |
| 87 | return servedNrCells |
| 88 | } |
| 89 | |
Irina | 5830d4d | 2020-07-08 18:11:04 +0000 | [diff] [blame^] | 90 | func generateServedCells(cellIds ...string) []*entities.ServedCellInfo { |
| 91 | |
| 92 | var servedCells []*entities.ServedCellInfo |
| 93 | |
| 94 | for i, v := range cellIds { |
| 95 | servedCells = append(servedCells, &entities.ServedCellInfo{ |
| 96 | CellId: v, |
| 97 | ChoiceEutraMode: &entities.ChoiceEUTRAMode{ |
| 98 | Fdd: &entities.FddInfo{}, |
| 99 | }, |
| 100 | Pci: uint32(i + 1), |
| 101 | BroadcastPlmns: []string{"whatever"}, |
| 102 | }) |
| 103 | } |
| 104 | |
| 105 | return servedCells |
| 106 | } |
| 107 | |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 108 | func TestRemoveServedNrCellsSuccess(t *testing.T) { |
| 109 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 110 | servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2") |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 111 | sdlInstanceMock.On("Remove", buildServedNRCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(nil) |
Irina | 5830d4d | 2020-07-08 18:11:04 +0000 | [diff] [blame^] | 112 | |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 113 | err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove) |
| 114 | assert.Nil(t, err) |
| 115 | } |
| 116 | |
| 117 | func TestRemoveServedNrCellsFailure(t *testing.T) { |
| 118 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 119 | servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2") |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 120 | sdlInstanceMock.On("Remove", buildServedNRCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(errors.New("expected error")) |
Irina | 5830d4d | 2020-07-08 18:11:04 +0000 | [diff] [blame^] | 121 | |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 122 | err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove) |
| 123 | assert.IsType(t, &common.InternalError{}, err) |
| 124 | } |
| 125 | |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 126 | func TestUpdateGnbCellsInvalidNodebInfoFailure(t *testing.T) { |
| 127 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 128 | servedNrCells := generateServedNrCells("test1", "test2") |
| 129 | nodebInfo := &entities.NodebInfo{} |
| 130 | sdlInstanceMock.AssertNotCalled(t, "Set") |
| 131 | rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells) |
| 132 | assert.IsType(t, &common.ValidationError{}, rNibErr) |
| 133 | } |
| 134 | |
| 135 | func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) { |
| 136 | inventoryName := "name" |
| 137 | plmnId := "02f829" |
| 138 | nbId := "4a952a0a" |
| 139 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 140 | servedNrCells := []*entities.ServedNRCell{{ServedNrCellInformation: &entities.ServedNRCellInformation{}}} |
| 141 | nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId) |
| 142 | nodebInfo.GetGnb().ServedNrCells = servedNrCells |
| 143 | sdlInstanceMock.AssertNotCalled(t, "Set") |
| 144 | rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells) |
| 145 | assert.IsType(t, &common.ValidationError{}, rNibErr) |
| 146 | } |
| 147 | |
| 148 | func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} { |
| 149 | |
| 150 | nodebInfoData, err := proto.Marshal(nodebInfo) |
| 151 | if err != nil { |
| 152 | t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err) |
| 153 | } |
| 154 | |
| 155 | nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName) |
| 156 | nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId) |
| 157 | setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData} |
| 158 | |
| 159 | for _, v := range servedNrCells { |
| 160 | |
| 161 | cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}} |
| 162 | cellData, err := proto.Marshal(&cellEntity) |
| 163 | |
| 164 | if err != nil { |
| 165 | t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err) |
| 166 | } |
| 167 | |
| 168 | nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId()) |
| 169 | cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci()) |
| 170 | setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData) |
| 171 | } |
| 172 | |
| 173 | return setExpected |
| 174 | } |
| 175 | |
| 176 | func TestUpdateGnbCellsSdlFailure(t *testing.T) { |
| 177 | inventoryName := "name" |
| 178 | plmnId := "02f829" |
| 179 | nbId := "4a952a0a" |
| 180 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 181 | servedNrCells := generateServedNrCells("test1", "test2") |
| 182 | nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId) |
| 183 | nodebInfo.GetGnb().ServedNrCells = servedNrCells |
| 184 | setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells) |
| 185 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(errors.New("expected error")) |
| 186 | rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells) |
| 187 | assert.IsType(t, &common.InternalError{}, rNibErr) |
| 188 | } |
| 189 | |
| 190 | func TestUpdateGnbCellsSuccess(t *testing.T) { |
| 191 | inventoryName := "name" |
| 192 | plmnId := "02f829" |
| 193 | nbId := "4a952a0a" |
| 194 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 195 | servedNrCells := generateServedNrCells("test1", "test2") |
| 196 | nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId) |
| 197 | nodebInfo.GetGnb().ServedNrCells = servedNrCells |
| 198 | setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells) |
| 199 | var e error |
| 200 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) |
| 201 | rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells) |
| 202 | assert.Nil(t, rNibErr) |
| 203 | } |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 204 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 205 | func TestUpdateNodebInfoSuccess(t *testing.T) { |
| 206 | inventoryName := "name" |
| 207 | plmnId := "02f829" |
| 208 | nbId := "4a952a0a" |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 209 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 210 | nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 211 | data, err := proto.Marshal(nodebInfo) |
| 212 | if err != nil { |
| 213 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err) |
| 214 | } |
| 215 | var e error |
| 216 | var setExpected []interface{} |
| 217 | |
| 218 | nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName) |
| 219 | nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId) |
| 220 | setExpected = append(setExpected, nodebNameKey, data) |
| 221 | setExpected = append(setExpected, nodebIdKey, data) |
| 222 | |
| 223 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) |
| 224 | |
| 225 | rNibErr := w.UpdateNodebInfo(nodebInfo) |
| 226 | assert.Nil(t, rNibErr) |
| 227 | } |
| 228 | |
| 229 | func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) { |
| 230 | inventoryName := "name" |
| 231 | plmnId := "02f829" |
| 232 | nbId := "4a952a0a" |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 233 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 234 | nodebInfo := &entities.NodebInfo{} |
| 235 | data, err := proto.Marshal(nodebInfo) |
| 236 | if err != nil { |
| 237 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err) |
| 238 | } |
| 239 | var e error |
| 240 | var setExpected []interface{} |
| 241 | |
| 242 | nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName) |
| 243 | nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId) |
| 244 | setExpected = append(setExpected, nodebNameKey, data) |
| 245 | setExpected = append(setExpected, nodebIdKey, data) |
| 246 | |
| 247 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) |
| 248 | |
| 249 | rNibErr := w.UpdateNodebInfo(nodebInfo) |
| 250 | |
| 251 | assert.NotNil(t, rNibErr) |
irina | 006fbce | 2019-09-05 16:11:02 +0300 | [diff] [blame] | 252 | assert.IsType(t, &common.ValidationError{}, rNibErr) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 253 | } |
| 254 | |
is005q | 2647319 | 2019-08-28 17:51:37 +0300 | [diff] [blame] | 255 | func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) { |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 256 | inventoryName := "name" |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 257 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 258 | nodebInfo := &entities.NodebInfo{} |
| 259 | nodebInfo.RanName = inventoryName |
| 260 | data, err := proto.Marshal(nodebInfo) |
| 261 | if err != nil { |
| 262 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err) |
| 263 | } |
| 264 | var e error |
| 265 | var setExpected []interface{} |
| 266 | |
| 267 | nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 268 | setExpected = append(setExpected, nodebNameKey, data) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 269 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) |
| 270 | |
| 271 | rNibErr := w.UpdateNodebInfo(nodebInfo) |
| 272 | |
is005q | 2647319 | 2019-08-28 17:51:37 +0300 | [diff] [blame] | 273 | assert.Nil(t, rNibErr) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 274 | } |
| 275 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 276 | func TestSaveEnb(t *testing.T) { |
| 277 | name := "name" |
| 278 | ranName := "RAN:" + name |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 279 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 280 | nb := entities.NodebInfo{} |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 281 | nb.RanName = name |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 282 | nb.NodeType = entities.Node_ENB |
| 283 | nb.ConnectionStatus = 1 |
| 284 | nb.Ip = "localhost" |
| 285 | nb.Port = 5656 |
| 286 | enb := entities.Enb{} |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 287 | cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3} |
| 288 | cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 289 | enb.ServedCells = []*entities.ServedCellInfo{cell} |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 290 | nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 291 | data, err := proto.Marshal(&nb) |
| 292 | if err != nil { |
| 293 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err) |
| 294 | } |
| 295 | var e error |
| 296 | |
| 297 | cellData, err := proto.Marshal(&cellEntity) |
| 298 | if err != nil { |
| 299 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err) |
| 300 | } |
| 301 | var setExpected []interface{} |
| 302 | setExpected = append(setExpected, ranName, data) |
| 303 | setExpected = append(setExpected, "ENB:02f829:4a952a0a", data) |
| 304 | setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData) |
| 305 | setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData) |
| 306 | |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 307 | sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", name + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(e) |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame] | 308 | |
| 309 | nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name}) |
| 310 | if err != nil { |
| 311 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err) |
| 312 | } |
| 313 | sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e) |
| 314 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 315 | nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}} |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame] | 316 | nbIdData, err = proto.Marshal(nbIdentity) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 317 | if err != nil { |
| 318 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err) |
| 319 | } |
| 320 | sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e) |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame] | 321 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 322 | rNibErr := w.SaveNodeb(nbIdentity, &nb) |
| 323 | assert.Nil(t, rNibErr) |
| 324 | } |
| 325 | |
| 326 | func TestSaveEnbCellIdValidationFailure(t *testing.T) { |
| 327 | name := "name" |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 328 | w, _ := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 329 | nb := entities.NodebInfo{} |
| 330 | nb.NodeType = entities.Node_ENB |
| 331 | nb.ConnectionStatus = 1 |
| 332 | nb.Ip = "localhost" |
| 333 | nb.Port = 5656 |
| 334 | enb := entities.Enb{} |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 335 | cell := &entities.ServedCellInfo{Pci: 3} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 336 | enb.ServedCells = []*entities.ServedCellInfo{cell} |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 337 | nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 338 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 339 | nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 340 | rNibErr := w.SaveNodeb(nbIdentity, &nb) |
| 341 | assert.NotNil(t, rNibErr) |
irina | 006fbce | 2019-09-05 16:11:02 +0300 | [diff] [blame] | 342 | assert.IsType(t, &common.ValidationError{}, rNibErr) |
| 343 | assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error()) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | func TestSaveEnbInventoryNameValidationFailure(t *testing.T) { |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 347 | w, _ := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 348 | nb := entities.NodebInfo{} |
| 349 | nb.NodeType = entities.Node_ENB |
| 350 | nb.ConnectionStatus = 1 |
| 351 | nb.Ip = "localhost" |
| 352 | nb.Port = 5656 |
| 353 | enb := entities.Enb{} |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 354 | cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 355 | enb.ServedCells = []*entities.ServedCellInfo{cell} |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 356 | nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 357 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 358 | nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 359 | rNibErr := w.SaveNodeb(nbIdentity, &nb) |
| 360 | assert.NotNil(t, rNibErr) |
irina | 006fbce | 2019-09-05 16:11:02 +0300 | [diff] [blame] | 361 | assert.IsType(t, &common.ValidationError{}, rNibErr) |
| 362 | assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error()) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 363 | } |
| 364 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 365 | func TestSaveGnbCellIdValidationFailure(t *testing.T) { |
| 366 | name := "name" |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 367 | w, _ := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 368 | nb := entities.NodebInfo{} |
| 369 | nb.NodeType = entities.Node_GNB |
| 370 | nb.ConnectionStatus = 1 |
| 371 | nb.Ip = "localhost" |
| 372 | nb.Port = 5656 |
| 373 | gnb := entities.Gnb{} |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 374 | cellInfo := &entities.ServedNRCellInformation{NrPci: 2} |
| 375 | cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 376 | gnb.ServedNrCells = []*entities.ServedNRCell{cell} |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 377 | nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 378 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 379 | nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 380 | rNibErr := w.SaveNodeb(nbIdentity, &nb) |
| 381 | assert.NotNil(t, rNibErr) |
irina | 006fbce | 2019-09-05 16:11:02 +0300 | [diff] [blame] | 382 | assert.IsType(t, &common.ValidationError{}, rNibErr) |
| 383 | assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error()) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | func TestSaveGnb(t *testing.T) { |
| 387 | name := "name" |
| 388 | ranName := "RAN:" + name |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 389 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 390 | nb := entities.NodebInfo{} |
| 391 | nb.NodeType = entities.Node_GNB |
| 392 | nb.ConnectionStatus = 1 |
| 393 | nb.Ip = "localhost" |
| 394 | nb.Port = 5656 |
| 395 | gnb := entities.Gnb{} |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 396 | cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"} |
| 397 | cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo} |
| 398 | cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 399 | gnb.ServedNrCells = []*entities.ServedNRCell{cell} |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 400 | nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 401 | data, err := proto.Marshal(&nb) |
| 402 | if err != nil { |
| 403 | t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err) |
| 404 | } |
| 405 | var e error |
| 406 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 407 | cellData, err := proto.Marshal(&cellEntity) |
| 408 | if err != nil { |
| 409 | t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err) |
| 410 | } |
| 411 | var setExpected []interface{} |
| 412 | setExpected = append(setExpected, ranName, data) |
| 413 | setExpected = append(setExpected, "GNB:02f829:4a952a0a", data) |
| 414 | setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData) |
| 415 | setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData) |
| 416 | |
| 417 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 418 | nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 419 | nbIdData, err := proto.Marshal(nbIdentity) |
| 420 | if err != nil { |
| 421 | t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err) |
| 422 | } |
| 423 | sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e) |
| 424 | |
ns019t | 57c3fae | 2019-08-12 20:08:49 +0300 | [diff] [blame] | 425 | nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name}) |
| 426 | if err != nil { |
| 427 | t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err) |
| 428 | } |
| 429 | sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e) |
| 430 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 431 | rNibErr := w.SaveNodeb(nbIdentity, &nb) |
| 432 | assert.Nil(t, rNibErr) |
| 433 | } |
| 434 | |
| 435 | func TestSaveRanLoadInformationSuccess(t *testing.T) { |
| 436 | inventoryName := "name" |
| 437 | loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName) |
| 438 | |
| 439 | if validationErr != nil { |
| 440 | t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr) |
| 441 | } |
| 442 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 443 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 444 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 445 | ranLoadInformation := generateRanLoadInformation() |
| 446 | data, err := proto.Marshal(ranLoadInformation) |
| 447 | |
| 448 | if err != nil { |
| 449 | t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err) |
| 450 | } |
| 451 | |
| 452 | var e error |
| 453 | var setExpected []interface{} |
| 454 | setExpected = append(setExpected, loadKey, data) |
| 455 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) |
| 456 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 457 | rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation) |
| 458 | assert.Nil(t, rNibErr) |
| 459 | } |
| 460 | |
| 461 | func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) { |
| 462 | inventoryName := "name2" |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 463 | w, _ := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 464 | |
| 465 | expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil")) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 466 | err := w.SaveRanLoadInformation(inventoryName, nil) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 467 | assert.Equal(t, expectedErr, err) |
| 468 | } |
| 469 | |
| 470 | func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) { |
| 471 | inventoryName := "" |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 472 | w, _ := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 473 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 474 | err := w.SaveRanLoadInformation(inventoryName, nil) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 475 | assert.NotNil(t, err) |
irina | 006fbce | 2019-09-05 16:11:02 +0300 | [diff] [blame] | 476 | assert.IsType(t, &common.ValidationError{}, err) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | func TestSaveRanLoadInformationSdlFailure(t *testing.T) { |
| 480 | inventoryName := "name2" |
| 481 | |
| 482 | loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName) |
| 483 | |
| 484 | if validationErr != nil { |
| 485 | t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr) |
| 486 | } |
| 487 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 488 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 489 | |
| 490 | ranLoadInformation := generateRanLoadInformation() |
| 491 | data, err := proto.Marshal(ranLoadInformation) |
| 492 | |
| 493 | if err != nil { |
| 494 | t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err) |
| 495 | } |
| 496 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 497 | expectedErr := errors.New("expected error") |
| 498 | var setExpected []interface{} |
| 499 | setExpected = append(setExpected, loadKey, data) |
| 500 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr) |
| 501 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 502 | rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation) |
| 503 | assert.NotNil(t, rNibErr) |
irina | 006fbce | 2019-09-05 16:11:02 +0300 | [diff] [blame] | 504 | assert.IsType(t, &common.InternalError{}, rNibErr) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | func generateCellLoadInformation() *entities.CellLoadInformation { |
| 508 | cellLoadInformation := entities.CellLoadInformation{} |
| 509 | |
| 510 | cellLoadInformation.CellId = "123" |
| 511 | |
| 512 | ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE |
| 513 | cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication} |
| 514 | |
| 515 | ulHighInterferenceInformation := entities.UlHighInterferenceInformation{ |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 516 | TargetCellId: "456", |
| 517 | UlHighInterferenceIndication: "xxx", |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 518 | } |
| 519 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 520 | cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 521 | |
| 522 | cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{ |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 523 | RntpPerPrb: "xxx", |
| 524 | RntpThreshold: entities.RntpThreshold_NEG_4, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 525 | NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT, |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 526 | PB: 1, |
| 527 | PdcchInterferenceImpact: 2, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 528 | EnhancedRntp: &entities.EnhancedRntp{ |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 529 | EnhancedRntpBitmap: "xxx", |
| 530 | RntpHighPowerThreshold: entities.RntpThreshold_NEG_2, |
| 531 | EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5}, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 532 | }, |
| 533 | } |
| 534 | |
| 535 | cellLoadInformation.AbsInformation = &entities.AbsInformation{ |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 536 | Mode: entities.AbsInformationMode_ABS_INFO_FDD, |
| 537 | AbsPatternInfo: "xxx", |
| 538 | NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT, |
| 539 | MeasurementSubset: "xxx", |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION |
| 543 | |
| 544 | cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{ |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 545 | AssociatedSubframes: "xxx", |
| 546 | ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | compInformationItem := &entities.CompInformationItem{ |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 550 | CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}}, |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 551 | BenefitMetric: 50, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | cellLoadInformation.CompInformation = &entities.CompInformation{ |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 555 | CompInformationItems: []*entities.CompInformationItem{compInformationItem}, |
| 556 | CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456}, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{ |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 560 | State: entities.NaicsState_NAICS_ACTIVE, |
| 561 | TransmissionModes: "xxx", |
| 562 | PB: 2, |
| 563 | PAList: []entities.PA{entities.PA_DB_NEG_3}, |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | return &cellLoadInformation |
| 567 | } |
| 568 | |
| 569 | func generateRanLoadInformation() *entities.RanLoadInformation { |
| 570 | ranLoadInformation := entities.RanLoadInformation{} |
| 571 | |
is005q | 19bf35e | 2019-08-12 18:59:29 +0300 | [diff] [blame] | 572 | ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano()) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 573 | |
| 574 | cellLoadInformation := generateCellLoadInformation() |
| 575 | ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation} |
| 576 | |
| 577 | return &ranLoadInformation |
| 578 | } |
| 579 | |
| 580 | func TestSaveNilEntityFailure(t *testing.T) { |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 581 | w, _ := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 582 | expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil")) |
| 583 | nbIdentity := &entities.NbIdentity{} |
| 584 | actualErr := w.SaveNodeb(nbIdentity, nil) |
| 585 | assert.Equal(t, expectedErr, actualErr) |
| 586 | } |
| 587 | |
| 588 | func TestSaveUnknownTypeEntityFailure(t *testing.T) { |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 589 | w, _ := initSdlInstanceMock(namespace) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 590 | nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 591 | nb := &entities.NodebInfo{} |
| 592 | nb.Port = 5656 |
| 593 | nb.Ip = "localhost" |
| 594 | actualErr := w.SaveNodeb(nbIdentity, nb) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 595 | assert.IsType(t, &common.ValidationError{}, actualErr) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | func TestSaveEntityFailure(t *testing.T) { |
| 599 | name := "name" |
| 600 | plmnId := "02f829" |
| 601 | nbId := "4a952a0a" |
| 602 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 603 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 604 | gnb := entities.NodebInfo{} |
| 605 | gnb.NodeType = entities.Node_GNB |
| 606 | data, err := proto.Marshal(&gnb) |
| 607 | if err != nil { |
| 608 | t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err) |
| 609 | } |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 610 | nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}} |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 611 | setExpected := []interface{}{"RAN:" + name, data} |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 612 | setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 613 | expectedErr := errors.New("expected error") |
| 614 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr) |
| 615 | rNibErr := w.SaveNodeb(nbIdentity, &gnb) |
| 616 | assert.NotEmpty(t, rNibErr) |
| 617 | } |
| 618 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 619 | func TestGetRNibWriter(t *testing.T) { |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 620 | received, _ := initSdlInstanceMock(namespace) |
| 621 | assert.NotEmpty(t, received) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 622 | } |
| 623 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 624 | func TestSaveE2TInstanceSuccess(t *testing.T) { |
| 625 | address := "10.10.2.15:9800" |
| 626 | loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address) |
| 627 | |
| 628 | if validationErr != nil { |
| 629 | t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr) |
| 630 | } |
| 631 | |
| 632 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 633 | |
| 634 | e2tInstance := generateE2tInstance(address) |
| 635 | data, err := json.Marshal(e2tInstance) |
| 636 | |
| 637 | if err != nil { |
| 638 | t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err) |
| 639 | } |
| 640 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 641 | var e error |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 642 | var setExpected []interface{} |
| 643 | setExpected = append(setExpected, loadKey, data) |
| 644 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) |
| 645 | |
| 646 | rNibErr := w.SaveE2TInstance(e2tInstance) |
| 647 | assert.Nil(t, rNibErr) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 648 | } |
| 649 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 650 | func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) { |
| 651 | w, _ := initSdlInstanceMock(namespace) |
| 652 | var address string |
Irina | 4914446 | 2020-04-07 16:37:20 +0300 | [diff] [blame] | 653 | e2tInstance := entities.NewE2TInstance(address, "test") |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 654 | err := w.SaveE2TInstance(e2tInstance) |
| 655 | assert.NotNil(t, err) |
| 656 | assert.IsType(t, &common.ValidationError{}, err) |
| 657 | } |
| 658 | |
| 659 | func TestSaveE2TInstanceSdlFailure(t *testing.T) { |
| 660 | address := "10.10.2.15:9800" |
| 661 | loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address) |
| 662 | |
| 663 | if validationErr != nil { |
| 664 | t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr) |
| 665 | } |
| 666 | |
| 667 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 668 | |
| 669 | e2tInstance := generateE2tInstance(address) |
| 670 | data, err := json.Marshal(e2tInstance) |
| 671 | |
| 672 | if err != nil { |
| 673 | t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err) |
| 674 | } |
| 675 | |
| 676 | expectedErr := errors.New("expected error") |
| 677 | var setExpected []interface{} |
| 678 | setExpected = append(setExpected, loadKey, data) |
| 679 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr) |
| 680 | |
| 681 | rNibErr := w.SaveE2TInstance(e2tInstance) |
| 682 | assert.NotNil(t, rNibErr) |
| 683 | assert.IsType(t, &common.InternalError{}, rNibErr) |
| 684 | } |
| 685 | |
| 686 | func generateE2tInstance(address string) *entities.E2TInstance { |
Irina | 4914446 | 2020-04-07 16:37:20 +0300 | [diff] [blame] | 687 | e2tInstance := entities.NewE2TInstance(address, "pod test") |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 688 | |
| 689 | e2tInstance.AssociatedRanList = []string{"test1", "test2"} |
| 690 | |
| 691 | return e2tInstance |
| 692 | } |
| 693 | |
| 694 | func TestSaveE2TAddressesSuccess(t *testing.T) { |
| 695 | address := "10.10.2.15:9800" |
| 696 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 697 | |
| 698 | e2tAddresses := []string{address} |
| 699 | data, err := json.Marshal(e2tAddresses) |
| 700 | |
| 701 | if err != nil { |
| 702 | t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err) |
| 703 | } |
| 704 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 705 | var e error |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 706 | var setExpected []interface{} |
| 707 | setExpected = append(setExpected, E2TAddressesKey, data) |
| 708 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) |
| 709 | |
| 710 | rNibErr := w.SaveE2TAddresses(e2tAddresses) |
| 711 | assert.Nil(t, rNibErr) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 712 | } |
| 713 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 714 | func TestSaveE2TAddressesSdlFailure(t *testing.T) { |
| 715 | address := "10.10.2.15:9800" |
| 716 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 717 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 718 | e2tAddresses := []string{address} |
| 719 | data, err := json.Marshal(e2tAddresses) |
| 720 | |
| 721 | if err != nil { |
| 722 | t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err) |
| 723 | } |
| 724 | |
| 725 | expectedErr := errors.New("expected error") |
| 726 | var setExpected []interface{} |
| 727 | setExpected = append(setExpected, E2TAddressesKey, data) |
| 728 | sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr) |
| 729 | |
| 730 | rNibErr := w.SaveE2TAddresses(e2tAddresses) |
| 731 | assert.NotNil(t, rNibErr) |
| 732 | assert.IsType(t, &common.InternalError{}, rNibErr) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 733 | } |
| 734 | |
Amichai | f846c59 | 2020-01-08 16:45:07 +0200 | [diff] [blame] | 735 | func TestRemoveE2TInstanceSuccess(t *testing.T) { |
| 736 | address := "10.10.2.15:9800" |
| 737 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 738 | |
| 739 | e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)} |
| 740 | var e error |
| 741 | sdlInstanceMock.On("Remove", e2tAddresses).Return(e) |
| 742 | |
| 743 | rNibErr := w.RemoveE2TInstance(address) |
| 744 | assert.Nil(t, rNibErr) |
| 745 | sdlInstanceMock.AssertExpectations(t) |
| 746 | } |
| 747 | |
| 748 | func TestRemoveE2TInstanceSdlFailure(t *testing.T) { |
| 749 | address := "10.10.2.15:9800" |
| 750 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 751 | |
| 752 | e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)} |
| 753 | expectedErr := errors.New("expected error") |
| 754 | sdlInstanceMock.On("Remove", e2tAddresses).Return(expectedErr) |
| 755 | |
| 756 | rNibErr := w.RemoveE2TInstance(address) |
| 757 | assert.IsType(t, &common.InternalError{}, rNibErr) |
| 758 | } |
| 759 | |
| 760 | func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) { |
| 761 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 762 | |
| 763 | rNibErr := w.RemoveE2TInstance("") |
| 764 | assert.IsType(t, &common.ValidationError{}, rNibErr) |
| 765 | sdlInstanceMock.AssertExpectations(t) |
| 766 | } |
| 767 | |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 768 | func TestUpdateNodebInfoOnConnectionStatusInversionSuccess(t *testing.T) { |
| 769 | inventoryName := "name" |
| 770 | plmnId := "02f829" |
| 771 | nbId := "4a952a0a" |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 772 | channelName := "RAN_CONNECTION_STATUS_CHANGE" |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 773 | eventName := inventoryName + "_" + "CONNECTED" |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 774 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 775 | nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId) |
| 776 | data, err := proto.Marshal(nodebInfo) |
| 777 | if err != nil { |
| 778 | t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err) |
| 779 | } |
| 780 | var e error |
| 781 | var setExpected []interface{} |
| 782 | |
| 783 | nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName) |
| 784 | nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId) |
| 785 | setExpected = append(setExpected, nodebNameKey, data) |
| 786 | setExpected = append(setExpected, nodebIdKey, data) |
| 787 | |
idanshal | 1766b71 | 2020-06-22 12:41:02 +0300 | [diff] [blame] | 788 | sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 789 | |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 790 | rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 791 | assert.Nil(t, rNibErr) |
| 792 | } |
| 793 | |
| 794 | func TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure(t *testing.T) { |
| 795 | inventoryName := "name" |
| 796 | plmnId := "02f829" |
| 797 | nbId := "4a952a0a" |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 798 | channelName := "RAN_CONNECTION_STATUS_CHANGE" |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 799 | eventName := inventoryName + "_" + "CONNECTED" |
| 800 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 801 | nodebInfo := &entities.NodebInfo{} |
| 802 | data, err := proto.Marshal(nodebInfo) |
| 803 | if err != nil { |
| 804 | t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err) |
| 805 | } |
| 806 | var e error |
| 807 | var setExpected []interface{} |
| 808 | |
| 809 | nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName) |
| 810 | nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId) |
| 811 | setExpected = append(setExpected, nodebNameKey, data) |
| 812 | setExpected = append(setExpected, nodebIdKey, data) |
| 813 | |
idanshal | 1766b71 | 2020-06-22 12:41:02 +0300 | [diff] [blame] | 814 | sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 815 | |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 816 | rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 817 | |
| 818 | assert.NotNil(t, rNibErr) |
| 819 | assert.IsType(t, &common.ValidationError{}, rNibErr) |
| 820 | } |
| 821 | |
| 822 | func TestUpdateNodebInfoOnConnectionStatusInversionMissingGlobalNbId(t *testing.T) { |
| 823 | inventoryName := "name" |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 824 | channelName := "RAN_CONNECTION_STATUS_CHANGE" |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 825 | eventName := inventoryName + "_" + "CONNECTED" |
| 826 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 827 | nodebInfo := &entities.NodebInfo{} |
| 828 | nodebInfo.RanName = inventoryName |
| 829 | data, err := proto.Marshal(nodebInfo) |
| 830 | if err != nil { |
| 831 | t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err) |
| 832 | } |
| 833 | var e error |
| 834 | var setExpected []interface{} |
| 835 | |
| 836 | nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName) |
| 837 | setExpected = append(setExpected, nodebNameKey, data) |
idanshal | 1766b71 | 2020-06-22 12:41:02 +0300 | [diff] [blame] | 838 | sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 839 | |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 840 | rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 841 | |
| 842 | assert.Nil(t, rNibErr) |
| 843 | } |
| 844 | |
| 845 | func TestSaveGeneralConfiguration(t *testing.T) { |
| 846 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 847 | |
| 848 | key := common.BuildGeneralConfigurationKey() |
| 849 | configurationData := "{\"enableRic\":true}" |
| 850 | configuration := &entities.GeneralConfiguration{} |
| 851 | configuration.EnableRic = true |
| 852 | |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 853 | sdlInstanceMock.On("Set", []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(nil) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 854 | rNibErr := w.SaveGeneralConfiguration(configuration) |
| 855 | |
| 856 | assert.Nil(t, rNibErr) |
| 857 | sdlInstanceMock.AssertExpectations(t) |
| 858 | } |
| 859 | |
| 860 | func TestSaveGeneralConfigurationDbError(t *testing.T) { |
| 861 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 862 | |
| 863 | key := common.BuildGeneralConfigurationKey() |
| 864 | configurationData := "{\"enableRic\":true}" |
| 865 | configuration := &entities.GeneralConfiguration{} |
| 866 | configuration.EnableRic = true |
| 867 | |
| 868 | expectedErr := errors.New("expected error") |
| 869 | |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 870 | sdlInstanceMock.On("Set", []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(expectedErr) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 871 | rNibErr := w.SaveGeneralConfiguration(configuration) |
| 872 | |
| 873 | assert.NotNil(t, rNibErr) |
| 874 | } |
Irina | 5830d4d | 2020-07-08 18:11:04 +0000 | [diff] [blame^] | 875 | func TestRemoveServedCellsSuccess(t *testing.T) { |
| 876 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 877 | servedCellsToRemove := generateServedCells("whatever1", "whatever2") |
| 878 | sdlInstanceMock.On("Remove", buildServedCellInfoKeysToRemove(RanName, servedCellsToRemove)).Return(nil) |
| 879 | err := w.RemoveServedCells(RanName, servedCellsToRemove) |
| 880 | assert.Nil(t, err) |
| 881 | } |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 882 | |
Irina | 5830d4d | 2020-07-08 18:11:04 +0000 | [diff] [blame^] | 883 | func TestUpdateEnbInvalidNodebInfoFailure(t *testing.T) { |
| 884 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 885 | servedCells := generateServedCells("test1", "test2") |
| 886 | nodebInfo := &entities.NodebInfo{} |
| 887 | sdlInstanceMock.AssertNotCalled(t, "SetAndPublish") |
| 888 | rNibErr := w.UpdateEnb(nodebInfo, servedCells) |
| 889 | assert.IsType(t, &common.ValidationError{}, rNibErr) |
| 890 | } |
| 891 | |
| 892 | func TestUpdateEnbInvalidCellFailure(t *testing.T) { |
| 893 | inventoryName := "name" |
| 894 | plmnId := "02f829" |
| 895 | nbId := "4a952a0a" |
| 896 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 897 | servedCells := []*entities.ServedCellInfo{{CellId: ""}} |
| 898 | nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId) |
| 899 | nodebInfo.GetEnb().ServedCells = servedCells |
| 900 | sdlInstanceMock.AssertNotCalled(t, "SetAndPublish") |
| 901 | rNibErr := w.UpdateEnb(nodebInfo, servedCells) |
| 902 | assert.IsType(t, &common.ValidationError{}, rNibErr) |
| 903 | } |
| 904 | |
| 905 | /*func TestUpdateEnbSdlFailure(t *testing.T) { |
| 906 | inventoryName := "ranName" |
| 907 | plmnId := "02f829" |
| 908 | nbId := "4a952a0a" |
| 909 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 910 | servedCells := generateServedCells("test1", "test2") |
| 911 | nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId) |
| 912 | nodebInfo.GetEnb().ServedCells = servedCells |
| 913 | setExpected := getUpdateEnbSetExpected(t, nodebInfo, servedCells) |
| 914 | sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(errors.New("expected error")) |
| 915 | rNibErr := w.UpdateEnb(nodebInfo, servedCells) |
| 916 | assert.IsType(t, &common.InternalError{}, rNibErr) |
| 917 | }*/ |
| 918 | |
| 919 | /*func TestUpdateEnbSuccess(t *testing.T) { |
| 920 | inventoryName := "ranName" |
| 921 | plmnId := "02f829" |
| 922 | nbId := "4a952a0a" |
| 923 | w, sdlInstanceMock := initSdlInstanceMock(namespace) |
| 924 | servedCells := generateServedCells("test1", "test2") |
| 925 | nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId) |
| 926 | nodebInfo.GetEnb().ServedCells = servedCells |
| 927 | setExpected := getUpdateEnbSetExpected(t, nodebInfo, servedCells) |
| 928 | |
| 929 | var e error |
| 930 | sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e) |
| 931 | rNibErr := w.UpdateEnb(nodebInfo, servedCells) |
| 932 | assert.Nil(t, rNibErr) |
| 933 | }*/ |
| 934 | |
| 935 | func getUpdateEnbSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) []interface{} { |
| 936 | |
| 937 | nodebInfoData, err := proto.Marshal(nodebInfo) |
| 938 | if err != nil { |
| 939 | t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal NodeB entity. Error: %s", err) |
| 940 | } |
| 941 | |
| 942 | nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName) |
| 943 | nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId) |
| 944 | setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData} |
| 945 | |
| 946 | for _, v := range servedCells { |
| 947 | |
| 948 | cellEntity := entities.ServedCellInfo{CellId: "some cell id", EutraMode: entities.Eutra_FDD, CsgId: "some csg id"} |
| 949 | cellData, err := proto.Marshal(&cellEntity) |
| 950 | |
| 951 | if err != nil { |
| 952 | t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal cell entity. Error: %s", err) |
| 953 | } |
| 954 | |
| 955 | nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetCellId()) |
| 956 | cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetPci()) |
| 957 | setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData) |
| 958 | } |
| 959 | return setExpected |
| 960 | } |