ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2019 AT&T Intellectual Property |
| 3 | // Copyright 2019 Nokia |
Rahul Banerji | 5f208b1 | 2020-10-01 17:00:32 +0530 | [diff] [blame] | 4 | // Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved. |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 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. |
nm755n | 15d3982 | 2019-11-28 16:56:00 +0000 | [diff] [blame] | 17 | |
| 18 | // This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 19 | // platform project (RICP). |
| 20 | |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 21 | package controllers |
| 22 | |
| 23 | import ( |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 24 | "bytes" |
Amichai | 804065d | 2019-12-24 14:52:24 +0200 | [diff] [blame] | 25 | "e2mgr/clients" |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 26 | "e2mgr/configuration" |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 27 | "e2mgr/e2managererrors" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 28 | "e2mgr/logger" |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 29 | "e2mgr/managers" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 30 | "e2mgr/mocks" |
| 31 | "e2mgr/models" |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 32 | "e2mgr/providers/httpmsghandlerprovider" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 33 | "e2mgr/rmrCgo" |
| 34 | "e2mgr/services" |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 35 | "e2mgr/services/rmrsender" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 36 | "e2mgr/tests" |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 37 | "encoding/json" |
| 38 | "fmt" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 39 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" |
| 40 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 41 | "github.com/golang/protobuf/jsonpb" |
Amichai | 4db397d | 2019-08-28 19:23:15 +0300 | [diff] [blame] | 42 | "github.com/gorilla/mux" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 43 | "github.com/pkg/errors" |
| 44 | "github.com/stretchr/testify/assert" |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 45 | "github.com/stretchr/testify/mock" |
| 46 | "io" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 47 | "io/ioutil" |
| 48 | "net/http" |
| 49 | "net/http/httptest" |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 50 | "strings" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 51 | "testing" |
ns019t | b3805a9 | 2020-04-13 16:57:59 +0300 | [diff] [blame] | 52 | "unsafe" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 53 | ) |
| 54 | |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 55 | const ( |
| 56 | RanName = "test" |
| 57 | AssociatedE2TInstanceAddress = "10.0.2.15:38000" |
idanshal | e0106ff | 2020-07-07 16:04:00 +0000 | [diff] [blame] | 58 | CorruptedJson = "{\"errorCode\":401,\"errorMessage\":\"corrupted json\"}" |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 59 | ValidationFailureJson = "{\"errorCode\":402,\"errorMessage\":\"Validation error\"}" |
| 60 | ResourceNotFoundJson = "{\"errorCode\":404,\"errorMessage\":\"Resource not found\"}" |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 61 | NodebExistsJson = "{\"errorCode\":406,\"errorMessage\":\"Nodeb already exists\"}" |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 62 | RnibErrorJson = "{\"errorCode\":500,\"errorMessage\":\"RNIB error\"}" |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 63 | InternalErrorJson = "{\"errorCode\":501,\"errorMessage\":\"Internal Server Error. Please try again later\"}" |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 64 | AddEnbUrl = "/nodeb/enb" |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 65 | ) |
| 66 | |
| 67 | var ( |
idanshal | 13fff61 | 2020-07-07 11:53:39 +0000 | [diff] [blame] | 68 | ServedNrCellInformationRequiredFields = []string{"cellId", "choiceNrMode", "nrMode", "servedPlmns"} |
| 69 | NrNeighbourInformationRequiredFields = []string{"nrCgi", "choiceNrMode", "nrMode"} |
| 70 | AddEnbRequestRequiredFields = []string{"ranName", "enb", "globalNbId"} |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 71 | UpdateEnbRequestRequiredFields = []string{"enb"} |
idanshal | e0106ff | 2020-07-07 16:04:00 +0000 | [diff] [blame] | 72 | GlobalIdRequiredFields = []string{"plmnId", "nbId"} |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 73 | EnbRequiredFields = []string{"enbType", "servedCells"} |
idanshal | 13fff61 | 2020-07-07 11:53:39 +0000 | [diff] [blame] | 74 | ServedCellRequiredFields = []string{"broadcastPlmns", "cellId", "choiceEutraMode", "eutraMode", "tac"} |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 75 | ) |
| 76 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 77 | type controllerGetNodebTestContext struct { |
| 78 | ranName string |
| 79 | nodebInfo *entities.NodebInfo |
| 80 | rnibError error |
| 81 | expectedStatusCode int |
| 82 | expectedJsonResponse string |
| 83 | } |
| 84 | |
| 85 | type controllerGetNodebIdListTestContext struct { |
| 86 | nodebIdList []*entities.NbIdentity |
| 87 | rnibError error |
| 88 | expectedStatusCode int |
| 89 | expectedJsonResponse string |
| 90 | } |
| 91 | |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 92 | type getNodebInfoResult struct { |
| 93 | nodebInfo *entities.NodebInfo |
| 94 | rnibError error |
| 95 | } |
| 96 | |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 97 | type updateGnbCellsParams struct { |
| 98 | err error |
| 99 | } |
| 100 | |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 101 | type updateEnbCellsParams struct { |
| 102 | err error |
| 103 | } |
| 104 | |
Amichai | 7ec48b2 | 2020-07-23 11:28:40 +0000 | [diff] [blame] | 105 | type addEnbParams struct { |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 106 | err error |
| 107 | } |
| 108 | |
| 109 | type addNbIdentityParams struct { |
| 110 | err error |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 113 | type removeServedCellsParams struct { |
| 114 | servedCellInfo []*entities.ServedCellInfo |
| 115 | err error |
| 116 | } |
| 117 | |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 118 | type removeServedNrCellsParams struct { |
| 119 | servedNrCells []*entities.ServedNRCell |
idanshal | 087f53f | 2020-04-27 14:12:54 +0300 | [diff] [blame] | 120 | err error |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 121 | } |
| 122 | |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 123 | type controllerUpdateEnbTestContext struct { |
| 124 | getNodebInfoResult *getNodebInfoResult |
| 125 | removeServedCellsParams *removeServedCellsParams |
| 126 | updateEnbCellsParams *updateEnbCellsParams |
| 127 | requestBody map[string]interface{} |
| 128 | expectedStatusCode int |
| 129 | expectedJsonResponse string |
| 130 | } |
| 131 | |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 132 | type controllerUpdateGnbTestContext struct { |
idanshal | 087f53f | 2020-04-27 14:12:54 +0300 | [diff] [blame] | 133 | getNodebInfoResult *getNodebInfoResult |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 134 | removeServedNrCellsParams *removeServedNrCellsParams |
idanshal | 087f53f | 2020-04-27 14:12:54 +0300 | [diff] [blame] | 135 | updateGnbCellsParams *updateGnbCellsParams |
| 136 | requestBody map[string]interface{} |
| 137 | expectedStatusCode int |
| 138 | expectedJsonResponse string |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 139 | } |
| 140 | |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 141 | type controllerAddEnbTestContext struct { |
| 142 | getNodebInfoResult *getNodebInfoResult |
Amichai | 7ec48b2 | 2020-07-23 11:28:40 +0000 | [diff] [blame] | 143 | addEnbParams *addEnbParams |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 144 | addNbIdentityParams *addNbIdentityParams |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 145 | requestBody map[string]interface{} |
| 146 | expectedStatusCode int |
| 147 | expectedJsonResponse string |
| 148 | } |
| 149 | |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 150 | type controllerDeleteEnbTestContext struct { |
| 151 | getNodebInfoResult *getNodebInfoResult |
| 152 | expectedStatusCode int |
| 153 | expectedJsonResponse string |
| 154 | } |
| 155 | |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 156 | func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell { |
| 157 | |
| 158 | servedNrCells := []*entities.ServedNRCell{} |
| 159 | |
| 160 | for _, v := range cellIds { |
| 161 | servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{ |
| 162 | CellId: v, |
| 163 | ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{ |
Rahul Banerji | fe8d481 | 2020-08-24 14:26:41 +0530 | [diff] [blame] | 164 | Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{}, |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 165 | }, |
| 166 | NrMode: entities.Nr_FDD, |
| 167 | NrPci: 5, |
| 168 | ServedPlmns: []string{"whatever"}, |
| 169 | }}) |
| 170 | } |
| 171 | |
| 172 | return servedNrCells |
| 173 | } |
| 174 | |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 175 | func generateServedCells(cellIds ...string) []*entities.ServedCellInfo { |
| 176 | |
| 177 | var servedCells []*entities.ServedCellInfo |
| 178 | |
| 179 | for i, v := range cellIds { |
| 180 | servedCells = append(servedCells, &entities.ServedCellInfo{ |
| 181 | CellId: v, |
| 182 | ChoiceEutraMode: &entities.ChoiceEUTRAMode{ |
| 183 | Fdd: &entities.FddInfo{}, |
| 184 | }, |
| 185 | Pci: uint32(i + 1), |
| 186 | BroadcastPlmns: []string{"whatever"}, |
| 187 | }) |
| 188 | } |
| 189 | |
| 190 | return servedCells |
| 191 | } |
| 192 | |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 193 | func buildNrNeighbourInformation(propToOmit string) map[string]interface{} { |
| 194 | ret := map[string]interface{}{ |
| 195 | "nrCgi": "whatever", |
| 196 | "choiceNrMode": map[string]interface{}{ |
| 197 | "tdd": map[string]interface{}{}, |
| 198 | }, |
| 199 | "nrMode": 1, |
| 200 | "nrPci": 1, |
| 201 | } |
| 202 | |
| 203 | if len(propToOmit) != 0 { |
| 204 | delete(ret, propToOmit) |
| 205 | } |
| 206 | |
| 207 | return ret |
| 208 | } |
| 209 | |
| 210 | func buildServedNrCellInformation(propToOmit string) map[string]interface{} { |
| 211 | ret := map[string]interface{}{ |
| 212 | "cellId": "whatever", |
| 213 | "choiceNrMode": map[string]interface{}{ |
| 214 | "fdd": map[string]interface{}{}, |
| 215 | }, |
| 216 | "nrMode": 1, |
| 217 | "nrPci": 1, |
| 218 | "servedPlmns": []interface{}{ |
| 219 | "whatever", |
| 220 | }, |
| 221 | } |
| 222 | |
| 223 | if len(propToOmit) != 0 { |
| 224 | delete(ret, propToOmit) |
| 225 | } |
| 226 | |
| 227 | return ret |
| 228 | } |
| 229 | |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 230 | func buildServedCell(propToOmit string) map[string]interface{} { |
| 231 | ret := map[string]interface{}{ |
| 232 | "cellId": "whatever", |
| 233 | "choiceEutraMode": map[string]interface{}{ |
| 234 | "fdd": map[string]interface{}{}, |
| 235 | }, |
| 236 | "eutraMode": 1, |
| 237 | "pci": 1, |
| 238 | "tac": "whatever3", |
| 239 | "broadcastPlmns": []interface{}{ |
| 240 | "whatever", |
| 241 | }, |
| 242 | } |
| 243 | |
| 244 | if len(propToOmit) != 0 { |
| 245 | delete(ret, propToOmit) |
| 246 | } |
| 247 | |
| 248 | return ret |
| 249 | } |
| 250 | |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 251 | func getUpdateEnbRequest(propToOmit string) map[string]interface{} { |
| 252 | ret := map[string]interface{}{ |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 253 | "enb": buildEnb(propToOmit), |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | if len(propToOmit) != 0 { |
| 257 | delete(ret, propToOmit) |
| 258 | } |
| 259 | |
| 260 | return ret |
| 261 | } |
| 262 | |
idanshal | 13fff61 | 2020-07-07 11:53:39 +0000 | [diff] [blame] | 263 | func getAddEnbRequest(propToOmit string) map[string]interface{} { |
| 264 | ret := map[string]interface{}{ |
idanshal | e0106ff | 2020-07-07 16:04:00 +0000 | [diff] [blame] | 265 | "ranName": RanName, |
| 266 | "globalNbId": buildGlobalNbId(""), |
| 267 | "enb": buildEnb(""), |
idanshal | 13fff61 | 2020-07-07 11:53:39 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | if len(propToOmit) != 0 { |
| 271 | delete(ret, propToOmit) |
| 272 | } |
| 273 | |
| 274 | return ret |
| 275 | } |
| 276 | |
| 277 | func buildEnb(propToOmit string) map[string]interface{} { |
| 278 | ret := map[string]interface{}{ |
| 279 | "enbType": 1, |
| 280 | "servedCells": []interface{}{ |
| 281 | buildServedCell(""), |
| 282 | }} |
| 283 | |
| 284 | if len(propToOmit) != 0 { |
| 285 | delete(ret, propToOmit) |
| 286 | } |
| 287 | |
| 288 | return ret |
| 289 | } |
| 290 | |
idanshal | e0106ff | 2020-07-07 16:04:00 +0000 | [diff] [blame] | 291 | func buildGlobalNbId(propToOmit string) map[string]interface{} { |
| 292 | ret := map[string]interface{}{ |
| 293 | "plmnId": "whatever", |
| 294 | "nbId": "whatever2", |
| 295 | } |
| 296 | |
| 297 | if len(propToOmit) != 0 { |
| 298 | delete(ret, propToOmit) |
| 299 | } |
| 300 | |
| 301 | return ret |
| 302 | } |
| 303 | |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 304 | func setupControllerTest(t *testing.T) (*NodebController, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.RmrMessengerMock, *mocks.E2TInstancesManagerMock, managers.RanListManager) { |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 305 | log := initLog(t) |
| 306 | config := configuration.ParseConfiguration() |
| 307 | |
| 308 | rmrMessengerMock := &mocks.RmrMessengerMock{} |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 309 | readerMock := &mocks.RnibReaderMock{} |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 310 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 311 | writerMock := &mocks.RnibWriterMock{} |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 312 | |
| 313 | rnibDataService := services.NewRnibDataService(log, config, readerMock, writerMock) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 314 | rmrSender := getRmrSender(rmrMessengerMock, log) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 315 | e2tInstancesManager := &mocks.E2TInstancesManagerMock{} |
Amichai | 804065d | 2019-12-24 14:52:24 +0200 | [diff] [blame] | 316 | httpClientMock := &mocks.HttpClientMock{} |
| 317 | rmClient := clients.NewRoutingManagerClient(log, config, httpClientMock) |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 318 | ranListManager := managers.NewRanListManager(log, rnibDataService) |
idanshal | 7670920 | 2020-06-17 14:53:06 +0300 | [diff] [blame] | 319 | ranAlarmService := &mocks.RanAlarmServiceMock{} |
| 320 | ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(log, rnibDataService, ranListManager, ranAlarmService) |
Irina | b2f2743 | 2020-07-07 11:17:10 +0000 | [diff] [blame] | 321 | nodebValidator := managers.NewNodebValidator() |
Irina | 5830d4d | 2020-07-08 18:11:04 +0000 | [diff] [blame] | 322 | updateEnbManager := managers.NewUpdateEnbManager(log, rnibDataService, nodebValidator) |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 323 | updateGnbManager := managers.NewUpdateGnbManager(log, rnibDataService, nodebValidator) |
| 324 | handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, rmrSender, config, rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager, nodebValidator, updateEnbManager, updateGnbManager, ranListManager) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 325 | controller := NewNodebController(log, handlerProvider) |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 326 | return controller, readerMock, writerMock, rmrMessengerMock, e2tInstancesManager, ranListManager |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 327 | } |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 328 | |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 329 | func setupDeleteEnbControllerTest(t *testing.T, preAddNbIdentity bool) (*NodebController, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *entities.NbIdentity) { |
| 330 | log := initLog(t) |
| 331 | config := configuration.ParseConfiguration() |
| 332 | |
| 333 | rmrMessengerMock := &mocks.RmrMessengerMock{} |
| 334 | readerMock := &mocks.RnibReaderMock{} |
| 335 | |
| 336 | writerMock := &mocks.RnibWriterMock{} |
| 337 | |
| 338 | rnibDataService := services.NewRnibDataService(log, config, readerMock, writerMock) |
| 339 | rmrSender := getRmrSender(rmrMessengerMock, log) |
| 340 | e2tInstancesManager := &mocks.E2TInstancesManagerMock{} |
| 341 | httpClientMock := &mocks.HttpClientMock{} |
| 342 | rmClient := clients.NewRoutingManagerClient(log, config, httpClientMock) |
| 343 | ranListManager := managers.NewRanListManager(log, rnibDataService) |
| 344 | var nbIdentity *entities.NbIdentity |
| 345 | if preAddNbIdentity { |
| 346 | nbIdentity = &entities.NbIdentity{InventoryName: RanName, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}} |
| 347 | writerMock.On("AddNbIdentity", entities.Node_ENB, nbIdentity).Return(nil) |
| 348 | ranListManager.AddNbIdentity(entities.Node_ENB, nbIdentity) |
| 349 | } |
| 350 | ranAlarmService := &mocks.RanAlarmServiceMock{} |
| 351 | ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(log, rnibDataService, ranListManager, ranAlarmService) |
| 352 | nodebValidator := managers.NewNodebValidator() |
| 353 | updateEnbManager := managers.NewUpdateEnbManager(log, rnibDataService, nodebValidator) |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 354 | updateGnbManager := managers.NewUpdateGnbManager(log, rnibDataService, nodebValidator) |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 355 | |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 356 | handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, rmrSender, config, rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager, nodebValidator, updateEnbManager, updateGnbManager, ranListManager) |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 357 | controller := NewNodebController(log, handlerProvider) |
| 358 | return controller, readerMock, writerMock, nbIdentity |
| 359 | } |
| 360 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 361 | func TestShutdownHandlerRnibError(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 362 | controller, _, _, _, e2tInstancesManagerMock, _ := setupControllerTest(t) |
is005q | 90d22a6 | 2020-01-01 11:55:49 +0200 | [diff] [blame] | 363 | e2tInstancesManagerMock.On("GetE2TAddresses").Return([]string{}, e2managererrors.NewRnibDbError()) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 364 | |
| 365 | writer := httptest.NewRecorder() |
| 366 | |
| 367 | controller.Shutdown(writer, tests.GetHttpRequest()) |
| 368 | |
| 369 | var errorResponse = parseJsonRequest(t, writer.Body) |
| 370 | |
| 371 | assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode) |
| 372 | assert.Equal(t, errorResponse.Code, e2managererrors.NewRnibDbError().Code) |
| 373 | } |
| 374 | |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 375 | func TestSetGeneralConfigurationHandlerRnibError(t *testing.T) { |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 376 | controller, readerMock, _, _, _, _ := setupControllerTest(t) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 377 | |
| 378 | configuration := &entities.GeneralConfiguration{} |
| 379 | readerMock.On("GetGeneralConfiguration").Return(configuration, e2managererrors.NewRnibDbError()) |
| 380 | |
| 381 | writer := httptest.NewRecorder() |
| 382 | |
| 383 | httpRequest, _ := http.NewRequest("PUT", "https://localhost:3800/v1/nodeb/parameters", strings.NewReader("{\"enableRic\":false}")) |
| 384 | |
| 385 | controller.SetGeneralConfiguration(writer, httpRequest) |
| 386 | |
| 387 | var errorResponse = parseJsonRequest(t, writer.Body) |
| 388 | |
| 389 | assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode) |
| 390 | assert.Equal(t, e2managererrors.NewRnibDbError().Code, errorResponse.Code) |
| 391 | } |
| 392 | |
| 393 | func TestSetGeneralConfigurationInvalidJson(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 394 | controller, _, _, _, _, _ := setupControllerTest(t) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 395 | |
| 396 | writer := httptest.NewRecorder() |
| 397 | |
Irina | d6d623c | 2020-06-17 15:01:21 +0300 | [diff] [blame] | 398 | httpRequest, _ := http.NewRequest("PUT", "https://localhost:3800/v1/nodeb/parameters", strings.NewReader("{\"enableRic\":false, \"someValue\":false}")) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 399 | |
| 400 | controller.SetGeneralConfiguration(writer, httpRequest) |
| 401 | |
| 402 | var errorResponse = parseJsonRequest(t, writer.Body) |
| 403 | |
| 404 | assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode) |
| 405 | assert.Equal(t, e2managererrors.NewInvalidJsonError().Code, errorResponse.Code) |
| 406 | } |
| 407 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 408 | func controllerGetNodebTestExecuter(t *testing.T, context *controllerGetNodebTestContext) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 409 | controller, readerMock, _, _, _, _ := setupControllerTest(t) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 410 | writer := httptest.NewRecorder() |
| 411 | readerMock.On("GetNodeb", context.ranName).Return(context.nodebInfo, context.rnibError) |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 412 | req, _ := http.NewRequest(http.MethodGet, "/nodeb", nil) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 413 | req = mux.SetURLVars(req, map[string]string{"ranName": context.ranName}) |
| 414 | controller.GetNodeb(writer, req) |
| 415 | assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode) |
| 416 | bodyBytes, _ := ioutil.ReadAll(writer.Body) |
| 417 | assert.Equal(t, context.expectedJsonResponse, string(bodyBytes)) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 418 | } |
| 419 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 420 | func controllerGetNodebIdListTestExecuter(t *testing.T, context *controllerGetNodebIdListTestContext) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 421 | controller, readerMock, _, _, _, ranListManager := setupControllerTest(t) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 422 | writer := httptest.NewRecorder() |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 423 | readerMock.On("GetListNodebIds").Return(context.nodebIdList, context.rnibError) |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 424 | |
| 425 | err := ranListManager.InitNbIdentityMap() |
| 426 | if err != nil { |
| 427 | t.Errorf("Error cannot init identity") |
| 428 | } |
| 429 | |
| 430 | req, _ := http.NewRequest(http.MethodGet, "/nodeb/states", nil) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 431 | controller.GetNodebIdList(writer, req) |
| 432 | assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode) |
| 433 | bodyBytes, _ := ioutil.ReadAll(writer.Body) |
Amichai | 7ec48b2 | 2020-07-23 11:28:40 +0000 | [diff] [blame] | 434 | assert.Contains(t, context.expectedJsonResponse, string(bodyBytes)) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 435 | } |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 436 | |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 437 | func activateControllerUpdateEnbMocks(context *controllerUpdateEnbTestContext, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock, updateEnbRequest *models.UpdateEnbRequest) { |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 438 | if context.getNodebInfoResult != nil { |
| 439 | readerMock.On("GetNodeb", RanName).Return(context.getNodebInfoResult.nodebInfo, context.getNodebInfoResult.rnibError) |
| 440 | } |
| 441 | |
| 442 | if context.removeServedCellsParams != nil { |
| 443 | writerMock.On("RemoveServedCells", RanName, context.removeServedCellsParams.servedCellInfo).Return(context.removeServedCellsParams.err) |
| 444 | } |
| 445 | |
| 446 | if context.updateEnbCellsParams != nil { |
| 447 | updatedNodebInfo := *context.getNodebInfoResult.nodebInfo |
idanshal | 885ce20 | 2020-08-05 06:49:57 +0000 | [diff] [blame] | 448 | |
| 449 | if context.getNodebInfoResult.nodebInfo.SetupFromNetwork { |
| 450 | updateEnbRequest.Enb.EnbType = context.getNodebInfoResult.nodebInfo.GetEnb().EnbType |
| 451 | } |
| 452 | |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 453 | updatedNodebInfo.Configuration = &entities.NodebInfo_Enb{Enb: updateEnbRequest.Enb} |
| 454 | |
| 455 | writerMock.On("UpdateEnb", &updatedNodebInfo, updateEnbRequest.Enb.ServedCells).Return(context.updateEnbCellsParams.err) |
| 456 | } |
| 457 | } |
| 458 | |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 459 | func activateControllerUpdateGnbMocks(context *controllerUpdateGnbTestContext, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock) { |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 460 | if context.getNodebInfoResult != nil { |
| 461 | readerMock.On("GetNodeb", RanName).Return(context.getNodebInfoResult.nodebInfo, context.getNodebInfoResult.rnibError) |
| 462 | } |
| 463 | |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 464 | if context.removeServedNrCellsParams != nil { |
| 465 | writerMock.On("RemoveServedNrCells", RanName, context.removeServedNrCellsParams.servedNrCells).Return(context.removeServedNrCellsParams.err) |
| 466 | } |
| 467 | |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 468 | if context.updateGnbCellsParams != nil { |
| 469 | updatedNodebInfo := *context.getNodebInfoResult.nodebInfo |
| 470 | gnb := entities.Gnb{} |
| 471 | _ = jsonpb.Unmarshal(getJsonRequestAsBuffer(context.requestBody), &gnb) |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 472 | updatedGnb := *updatedNodebInfo.GetGnb() |
| 473 | updatedGnb.ServedNrCells = gnb.ServedNrCells |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 474 | writerMock.On("UpdateGnbCells", &updatedNodebInfo, gnb.ServedNrCells).Return(context.updateGnbCellsParams.err) |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | func assertControllerUpdateGnb(t *testing.T, context *controllerUpdateGnbTestContext, writer *httptest.ResponseRecorder, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock) { |
| 479 | assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode) |
| 480 | bodyBytes, _ := ioutil.ReadAll(writer.Body) |
| 481 | assert.Equal(t, context.expectedJsonResponse, string(bodyBytes)) |
| 482 | readerMock.AssertExpectations(t) |
| 483 | writerMock.AssertExpectations(t) |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 484 | } |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 485 | |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 486 | func assertControllerUpdateEnb(t *testing.T, context *controllerUpdateEnbTestContext, writer *httptest.ResponseRecorder, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock) { |
| 487 | assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode) |
| 488 | bodyBytes, _ := ioutil.ReadAll(writer.Body) |
| 489 | assert.Equal(t, context.expectedJsonResponse, string(bodyBytes)) |
| 490 | readerMock.AssertExpectations(t) |
| 491 | writerMock.AssertExpectations(t) |
| 492 | } |
| 493 | |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 494 | func assertControllerAddEnb(t *testing.T, context *controllerAddEnbTestContext, writer *httptest.ResponseRecorder, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock) { |
| 495 | assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode) |
| 496 | bodyBytes, _ := ioutil.ReadAll(writer.Body) |
| 497 | assert.Equal(t, context.expectedJsonResponse, string(bodyBytes)) |
| 498 | readerMock.AssertExpectations(t) |
| 499 | writerMock.AssertExpectations(t) |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 500 | } |
| 501 | |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 502 | func assertControllerDeleteEnb(t *testing.T, context *controllerDeleteEnbTestContext, writer *httptest.ResponseRecorder, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock) { |
| 503 | assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode) |
| 504 | bodyBytes, _ := ioutil.ReadAll(writer.Body) |
| 505 | assert.Equal(t, context.expectedJsonResponse, string(bodyBytes)) |
| 506 | readerMock.AssertExpectations(t) |
| 507 | writerMock.AssertExpectations(t) |
| 508 | } |
| 509 | |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 510 | func buildUpdateEnbRequest(context *controllerUpdateEnbTestContext) *http.Request { |
| 511 | updateEnbUrl := fmt.Sprintf("/nodeb/enb/%s", RanName) |
| 512 | requestBody := getJsonRequestAsBuffer(context.requestBody) |
| 513 | req, _ := http.NewRequest(http.MethodPut, updateEnbUrl, requestBody) |
| 514 | req.Header.Set("Content-Type", "application/json") |
| 515 | req = mux.SetURLVars(req, map[string]string{"ranName": RanName}) |
| 516 | return req |
| 517 | } |
| 518 | |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 519 | func buildUpdateGnbRequest(context *controllerUpdateGnbTestContext) *http.Request { |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 520 | updateGnbUrl := fmt.Sprintf("/nodeb/gnb/%s", RanName) |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 521 | requestBody := getJsonRequestAsBuffer(context.requestBody) |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 522 | req, _ := http.NewRequest(http.MethodPut, updateGnbUrl, requestBody) |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 523 | req.Header.Set("Content-Type", "application/json") |
| 524 | req = mux.SetURLVars(req, map[string]string{"ranName": RanName}) |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 525 | return req |
| 526 | } |
| 527 | |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 528 | func buildAddEnbRequest(context *controllerAddEnbTestContext) *http.Request { |
| 529 | requestBody := getJsonRequestAsBuffer(context.requestBody) |
| 530 | req, _ := http.NewRequest(http.MethodPost, AddEnbUrl, requestBody) |
| 531 | req.Header.Set("Content-Type", "application/json") |
| 532 | return req |
| 533 | } |
| 534 | |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 535 | func controllerUpdateEnbTestExecuter(t *testing.T, context *controllerUpdateEnbTestContext) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 536 | controller, readerMock, writerMock, _, _, _ := setupControllerTest(t) |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 537 | writer := httptest.NewRecorder() |
| 538 | |
| 539 | r := buildUpdateEnbRequest(context) |
| 540 | body, _ := ioutil.ReadAll(io.LimitReader(r.Body, LimitRequest)) |
| 541 | |
| 542 | updateEnbRequest := models.UpdateEnbRequest{} |
| 543 | _ = json.Unmarshal(body, &updateEnbRequest) |
| 544 | |
| 545 | activateControllerUpdateEnbMocks(context, readerMock, writerMock, &updateEnbRequest) |
| 546 | r = buildUpdateEnbRequest(context) |
| 547 | defer r.Body.Close() |
| 548 | |
| 549 | controller.UpdateEnb(writer, r) |
| 550 | |
| 551 | assertControllerUpdateEnb(t, context, writer, readerMock, writerMock) |
| 552 | } |
| 553 | |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 554 | func controllerUpdateGnbTestExecuter(t *testing.T, context *controllerUpdateGnbTestContext) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 555 | controller, readerMock, writerMock, _, _, _ := setupControllerTest(t) |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 556 | writer := httptest.NewRecorder() |
| 557 | |
| 558 | activateControllerUpdateGnbMocks(context, readerMock, writerMock) |
| 559 | req := buildUpdateGnbRequest(context) |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 560 | controller.UpdateGnb(writer, req) |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 561 | assertControllerUpdateGnb(t, context, writer, readerMock, writerMock) |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 562 | } |
| 563 | |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 564 | func activateControllerAddEnbMocks(context *controllerAddEnbTestContext, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock, addEnbRequest *models.AddEnbRequest) { |
| 565 | if context.getNodebInfoResult != nil { |
| 566 | readerMock.On("GetNodeb", RanName).Return(context.getNodebInfoResult.nodebInfo, context.getNodebInfoResult.rnibError) |
| 567 | } |
| 568 | |
Amichai | 7ec48b2 | 2020-07-23 11:28:40 +0000 | [diff] [blame] | 569 | if context.addEnbParams != nil { |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 570 | nodebInfo := entities.NodebInfo{ |
| 571 | RanName: addEnbRequest.RanName, |
| 572 | Ip: addEnbRequest.Ip, |
| 573 | Port: addEnbRequest.Port, |
idanshal | e0106ff | 2020-07-07 16:04:00 +0000 | [diff] [blame] | 574 | NodeType: entities.Node_ENB, |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 575 | GlobalNbId: addEnbRequest.GlobalNbId, |
| 576 | Configuration: &entities.NodebInfo_Enb{Enb: addEnbRequest.Enb}, |
| 577 | ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, |
| 578 | } |
| 579 | |
Amichai | 7ec48b2 | 2020-07-23 11:28:40 +0000 | [diff] [blame] | 580 | writerMock.On("AddEnb", &nodebInfo).Return(context.addEnbParams.err) |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | if context.addNbIdentityParams != nil { |
| 584 | nbIdentity := entities.NbIdentity{InventoryName: addEnbRequest.RanName, GlobalNbId: addEnbRequest.GlobalNbId, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED} |
| 585 | writerMock.On("AddNbIdentity", entities.Node_ENB, &nbIdentity).Return(context.addNbIdentityParams.err) |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
| 589 | func controllerAddEnbTestExecuter(t *testing.T, context *controllerAddEnbTestContext) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 590 | controller, readerMock, writerMock, _, _, _ := setupControllerTest(t) |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 591 | writer := httptest.NewRecorder() |
| 592 | r := buildAddEnbRequest(context) |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 593 | body, _ := ioutil.ReadAll(io.LimitReader(r.Body, LimitRequest)) |
| 594 | |
| 595 | addEnbRequest := models.AddEnbRequest{} |
| 596 | |
| 597 | _ = json.Unmarshal(body, &addEnbRequest) |
| 598 | activateControllerAddEnbMocks(context, readerMock, writerMock, &addEnbRequest) |
idanshal | 13fff61 | 2020-07-07 11:53:39 +0000 | [diff] [blame] | 599 | r = buildAddEnbRequest(context) |
| 600 | defer r.Body.Close() |
| 601 | controller.AddEnb(writer, r) |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 602 | assertControllerAddEnb(t, context, writer, readerMock, writerMock) |
| 603 | } |
| 604 | |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 605 | func controllerDeleteEnbTestExecuter(t *testing.T, context *controllerDeleteEnbTestContext, preAddNbIdentity bool) { |
| 606 | controller, readerMock, writerMock, nbIdentity := setupDeleteEnbControllerTest(t, preAddNbIdentity) |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 607 | readerMock.On("GetNodeb", RanName).Return(context.getNodebInfoResult.nodebInfo, context.getNodebInfoResult.rnibError) |
idanshal | 885ce20 | 2020-08-05 06:49:57 +0000 | [diff] [blame] | 608 | if context.getNodebInfoResult.rnibError == nil && context.getNodebInfoResult.nodebInfo.GetNodeType() == entities.Node_ENB && |
| 609 | !context.getNodebInfoResult.nodebInfo.SetupFromNetwork { |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 610 | writerMock.On("RemoveEnb", context.getNodebInfoResult.nodebInfo).Return(nil) |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 611 | if preAddNbIdentity { |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 612 | writerMock.On("RemoveNbIdentity", entities.Node_ENB, nbIdentity).Return(nil) |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 613 | } |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 614 | } |
| 615 | writer := httptest.NewRecorder() |
| 616 | r, _ := http.NewRequest(http.MethodDelete, AddEnbUrl+"/"+RanName, nil) |
| 617 | r.Header.Set("Content-Type", "application/json") |
| 618 | r = mux.SetURLVars(r, map[string]string{"ranName": RanName}) |
| 619 | controller.DeleteEnb(writer, r) |
| 620 | assertControllerDeleteEnb(t, context, writer, readerMock, writerMock) |
| 621 | } |
| 622 | |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 623 | /* |
| 624 | UpdateGnb UTs |
| 625 | */ |
| 626 | |
| 627 | // BEGIN - UpdateGnb Validation Failure UTs |
| 628 | |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 629 | func TestControllerUpdateGnbEmptyServedNrCells(t *testing.T) { |
| 630 | context := controllerUpdateGnbTestContext{ |
| 631 | getNodebInfoResult: nil, |
| 632 | requestBody: map[string]interface{}{ |
Rahul Banerji | fe8d481 | 2020-08-24 14:26:41 +0530 | [diff] [blame] | 633 | "servedNrCells": []interface{}{}, |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 634 | }, |
| 635 | expectedStatusCode: http.StatusBadRequest, |
| 636 | expectedJsonResponse: ValidationFailureJson, |
| 637 | } |
| 638 | |
| 639 | controllerUpdateGnbTestExecuter(t, &context) |
| 640 | } |
| 641 | |
| 642 | func TestControllerUpdateGnbMissingServedNrCellInformation(t *testing.T) { |
| 643 | context := controllerUpdateGnbTestContext{ |
| 644 | getNodebInfoResult: nil, |
| 645 | requestBody: map[string]interface{}{ |
| 646 | "servedNrCells": []interface{}{ |
| 647 | map[string]interface{}{ |
| 648 | "servedNrCellInformation": nil, |
| 649 | }, |
| 650 | }, |
| 651 | }, |
| 652 | expectedStatusCode: http.StatusBadRequest, |
| 653 | expectedJsonResponse: ValidationFailureJson, |
| 654 | } |
| 655 | |
| 656 | controllerUpdateGnbTestExecuter(t, &context) |
| 657 | } |
| 658 | |
| 659 | func TestControllerUpdateGnbMissingServedNrCellRequiredProp(t *testing.T) { |
| 660 | |
| 661 | for _, v := range ServedNrCellInformationRequiredFields { |
| 662 | context := controllerUpdateGnbTestContext{ |
| 663 | getNodebInfoResult: nil, |
| 664 | requestBody: map[string]interface{}{ |
| 665 | "servedNrCells": []interface{}{ |
| 666 | map[string]interface{}{ |
| 667 | "servedNrCellInformation": buildServedNrCellInformation(v), |
| 668 | }, |
| 669 | }, |
| 670 | }, |
| 671 | expectedStatusCode: http.StatusBadRequest, |
| 672 | expectedJsonResponse: ValidationFailureJson, |
| 673 | } |
| 674 | |
| 675 | controllerUpdateGnbTestExecuter(t, &context) |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | func TestControllerUpdateGnbMissingServedNrCellFddOrTdd(t *testing.T) { |
| 680 | |
| 681 | servedNrCellInformation := buildServedNrCellInformation("") |
| 682 | servedNrCellInformation["choiceNrMode"] = map[string]interface{}{} |
| 683 | |
| 684 | context := controllerUpdateGnbTestContext{ |
| 685 | getNodebInfoResult: nil, |
| 686 | requestBody: map[string]interface{}{ |
| 687 | "servedNrCells": []interface{}{ |
| 688 | map[string]interface{}{ |
| 689 | "servedNrCellInformation": servedNrCellInformation, |
| 690 | }, |
| 691 | }, |
| 692 | }, |
| 693 | expectedStatusCode: http.StatusBadRequest, |
| 694 | expectedJsonResponse: ValidationFailureJson, |
| 695 | } |
| 696 | |
| 697 | controllerUpdateGnbTestExecuter(t, &context) |
| 698 | } |
| 699 | |
| 700 | func TestControllerUpdateGnbMissingNeighbourInfoFddOrTdd(t *testing.T) { |
| 701 | |
| 702 | nrNeighbourInfo := buildNrNeighbourInformation("") |
| 703 | nrNeighbourInfo["choiceNrMode"] = map[string]interface{}{} |
| 704 | |
| 705 | context := controllerUpdateGnbTestContext{ |
| 706 | getNodebInfoResult: nil, |
| 707 | requestBody: map[string]interface{}{ |
| 708 | "servedNrCells": []interface{}{ |
| 709 | map[string]interface{}{ |
| 710 | "servedNrCellInformation": buildServedNrCellInformation(""), |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 711 | "nrNeighbourInfos": []interface{}{ |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 712 | nrNeighbourInfo, |
| 713 | }, |
| 714 | }, |
| 715 | }, |
| 716 | }, |
| 717 | expectedStatusCode: http.StatusBadRequest, |
| 718 | expectedJsonResponse: ValidationFailureJson, |
| 719 | } |
| 720 | |
| 721 | controllerUpdateGnbTestExecuter(t, &context) |
| 722 | } |
| 723 | |
| 724 | func TestControllerUpdateGnbMissingNrNeighbourInformationRequiredProp(t *testing.T) { |
| 725 | |
| 726 | for _, v := range NrNeighbourInformationRequiredFields { |
| 727 | context := controllerUpdateGnbTestContext{ |
| 728 | getNodebInfoResult: nil, |
| 729 | requestBody: map[string]interface{}{ |
| 730 | "servedNrCells": []interface{}{ |
| 731 | map[string]interface{}{ |
| 732 | "servedNrCellInformation": buildServedNrCellInformation(""), |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 733 | "nrNeighbourInfos": []interface{}{ |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 734 | buildNrNeighbourInformation(v), |
| 735 | }, |
| 736 | }, |
| 737 | }, |
| 738 | }, |
| 739 | expectedStatusCode: http.StatusBadRequest, |
| 740 | expectedJsonResponse: ValidationFailureJson, |
| 741 | } |
| 742 | |
| 743 | controllerUpdateGnbTestExecuter(t, &context) |
| 744 | } |
| 745 | } |
| 746 | |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 747 | // END - UpdateGnb Validation Failure UTs |
| 748 | |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 749 | func TestControllerUpdateGnbValidServedNrCellInformationGetNodebNotFound(t *testing.T) { |
| 750 | context := controllerUpdateGnbTestContext{ |
| 751 | getNodebInfoResult: &getNodebInfoResult{ |
| 752 | nodebInfo: nil, |
| 753 | rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"), |
| 754 | }, |
| 755 | requestBody: map[string]interface{}{ |
| 756 | "servedNrCells": []interface{}{ |
| 757 | map[string]interface{}{ |
| 758 | "servedNrCellInformation": buildServedNrCellInformation(""), |
| 759 | }, |
| 760 | }, |
| 761 | }, |
| 762 | expectedStatusCode: http.StatusNotFound, |
| 763 | expectedJsonResponse: ResourceNotFoundJson, |
| 764 | } |
| 765 | |
| 766 | controllerUpdateGnbTestExecuter(t, &context) |
| 767 | } |
| 768 | |
| 769 | func TestControllerUpdateGnbValidServedNrCellInformationGetNodebInternalError(t *testing.T) { |
| 770 | context := controllerUpdateGnbTestContext{ |
| 771 | getNodebInfoResult: &getNodebInfoResult{ |
| 772 | nodebInfo: nil, |
| 773 | rnibError: common.NewInternalError(errors.New("#reader.GetNodeb - Internal Error")), |
| 774 | }, |
| 775 | requestBody: map[string]interface{}{ |
| 776 | "servedNrCells": []interface{}{ |
| 777 | map[string]interface{}{ |
| 778 | "servedNrCellInformation": buildServedNrCellInformation(""), |
| 779 | }, |
| 780 | }, |
| 781 | }, |
| 782 | expectedStatusCode: http.StatusInternalServerError, |
| 783 | expectedJsonResponse: RnibErrorJson, |
| 784 | } |
| 785 | |
| 786 | controllerUpdateGnbTestExecuter(t, &context) |
| 787 | } |
| 788 | |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 789 | func TestControllerUpdateGnbGetNodebSuccessInvalidGnbConfiguration(t *testing.T) { |
| 790 | context := controllerUpdateGnbTestContext{ |
| 791 | getNodebInfoResult: &getNodebInfoResult{ |
| 792 | nodebInfo: &entities.NodebInfo{ |
| 793 | RanName: RanName, |
| 794 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 795 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 796 | NodeType: entities.Node_ENB, |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 797 | }, |
| 798 | rnibError: nil, |
| 799 | }, |
| 800 | requestBody: map[string]interface{}{ |
| 801 | "servedNrCells": []interface{}{ |
| 802 | map[string]interface{}{ |
| 803 | "servedNrCellInformation": buildServedNrCellInformation(""), |
| 804 | "nrNeighbourInfos": []interface{}{ |
| 805 | buildNrNeighbourInformation(""), |
| 806 | }, |
| 807 | }, |
| 808 | }, |
| 809 | }, |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 810 | expectedStatusCode: http.StatusBadRequest, |
| 811 | expectedJsonResponse: ValidationFailureJson, |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | controllerUpdateGnbTestExecuter(t, &context) |
| 815 | } |
| 816 | |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 817 | func TestControllerUpdateGnbGetNodebSuccessRemoveServedNrCellsFailure(t *testing.T) { |
idanshal | 087f53f | 2020-04-27 14:12:54 +0300 | [diff] [blame] | 818 | oldServedNrCells := generateServedNrCells("whatever1", "whatever2") |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 819 | context := controllerUpdateGnbTestContext{ |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 820 | removeServedNrCellsParams: &removeServedNrCellsParams{ |
idanshal | 087f53f | 2020-04-27 14:12:54 +0300 | [diff] [blame] | 821 | err: common.NewInternalError(errors.New("#writer.UpdateGnbCells - Internal Error")), |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 822 | servedNrCells: oldServedNrCells, |
| 823 | }, |
| 824 | getNodebInfoResult: &getNodebInfoResult{ |
| 825 | nodebInfo: &entities.NodebInfo{ |
| 826 | RanName: RanName, |
| 827 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 828 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
| 829 | Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{ServedNrCells: oldServedNrCells}}, |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 830 | NodeType: entities.Node_GNB, |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 831 | }, |
| 832 | rnibError: nil, |
| 833 | }, |
| 834 | requestBody: map[string]interface{}{ |
| 835 | "servedNrCells": []interface{}{ |
| 836 | map[string]interface{}{ |
| 837 | "servedNrCellInformation": buildServedNrCellInformation(""), |
| 838 | "nrNeighbourInfos": []interface{}{ |
| 839 | buildNrNeighbourInformation(""), |
| 840 | }, |
| 841 | }, |
| 842 | }, |
| 843 | }, |
| 844 | expectedStatusCode: http.StatusInternalServerError, |
| 845 | expectedJsonResponse: RnibErrorJson, |
| 846 | } |
| 847 | |
| 848 | controllerUpdateGnbTestExecuter(t, &context) |
| 849 | } |
| 850 | |
| 851 | func TestControllerUpdateGnbGetNodebSuccessUpdateGnbCellsFailure(t *testing.T) { |
idanshal | 087f53f | 2020-04-27 14:12:54 +0300 | [diff] [blame] | 852 | oldServedNrCells := generateServedNrCells("whatever1", "whatever2") |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 853 | context := controllerUpdateGnbTestContext{ |
| 854 | removeServedNrCellsParams: &removeServedNrCellsParams{ |
idanshal | 087f53f | 2020-04-27 14:12:54 +0300 | [diff] [blame] | 855 | err: nil, |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 856 | servedNrCells: oldServedNrCells, |
| 857 | }, |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 858 | updateGnbCellsParams: &updateGnbCellsParams{ |
| 859 | err: common.NewInternalError(errors.New("#writer.UpdateGnbCells - Internal Error")), |
| 860 | }, |
| 861 | getNodebInfoResult: &getNodebInfoResult{ |
| 862 | nodebInfo: &entities.NodebInfo{ |
| 863 | RanName: RanName, |
| 864 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 865 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 866 | Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{ServedNrCells: oldServedNrCells}}, |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 867 | NodeType: entities.Node_GNB, |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 868 | }, |
| 869 | rnibError: nil, |
| 870 | }, |
| 871 | requestBody: map[string]interface{}{ |
| 872 | "servedNrCells": []interface{}{ |
| 873 | map[string]interface{}{ |
| 874 | "servedNrCellInformation": buildServedNrCellInformation(""), |
| 875 | "nrNeighbourInfos": []interface{}{ |
| 876 | buildNrNeighbourInformation(""), |
| 877 | }, |
| 878 | }, |
| 879 | }, |
| 880 | }, |
| 881 | expectedStatusCode: http.StatusInternalServerError, |
| 882 | expectedJsonResponse: RnibErrorJson, |
| 883 | } |
| 884 | |
| 885 | controllerUpdateGnbTestExecuter(t, &context) |
| 886 | } |
| 887 | |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 888 | func TestControllerUpdateGnbExistingEmptyCellsSuccess(t *testing.T) { |
| 889 | oldServedNrCells := []*entities.ServedNRCell{} |
| 890 | |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 891 | context := controllerUpdateGnbTestContext{ |
| 892 | updateGnbCellsParams: &updateGnbCellsParams{ |
| 893 | err: nil, |
| 894 | }, |
| 895 | getNodebInfoResult: &getNodebInfoResult{ |
| 896 | nodebInfo: &entities.NodebInfo{ |
| 897 | RanName: RanName, |
| 898 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 899 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 900 | Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{ServedNrCells: oldServedNrCells}}, |
| 901 | NodeType: entities.Node_GNB, |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 902 | }, |
| 903 | rnibError: nil, |
| 904 | }, |
| 905 | requestBody: map[string]interface{}{ |
| 906 | "servedNrCells": []interface{}{ |
| 907 | map[string]interface{}{ |
| 908 | "servedNrCellInformation": buildServedNrCellInformation(""), |
| 909 | "nrNeighbourInfos": []interface{}{ |
| 910 | buildNrNeighbourInformation(""), |
| 911 | }, |
| 912 | }, |
| 913 | }, |
| 914 | }, |
| 915 | expectedStatusCode: http.StatusOK, |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 916 | expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"nodeType\":\"GNB\",\"gnb\":{\"servedNrCells\":[{\"servedNrCellInformation\":{\"nrPci\":1,\"cellId\":\"whatever\",\"servedPlmns\":[\"whatever\"],\"nrMode\":\"FDD\",\"choiceNrMode\":{\"fdd\":{}}},\"nrNeighbourInfos\":[{\"nrPci\":1,\"nrCgi\":\"whatever\",\"nrMode\":\"FDD\",\"choiceNrMode\":{\"tdd\":{}}}]}]},\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\"}", |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | controllerUpdateGnbTestExecuter(t, &context) |
| 920 | } |
| 921 | |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 922 | func TestControllerUpdateGnbSuccess(t *testing.T) { |
| 923 | oldServedNrCells := generateServedNrCells("whatever1", "whatever2") |
| 924 | |
| 925 | context := controllerUpdateGnbTestContext{ |
| 926 | removeServedNrCellsParams: &removeServedNrCellsParams{ |
| 927 | err: nil, |
| 928 | servedNrCells: oldServedNrCells, |
| 929 | }, |
| 930 | updateGnbCellsParams: &updateGnbCellsParams{ |
| 931 | err: nil, |
| 932 | }, |
| 933 | getNodebInfoResult: &getNodebInfoResult{ |
| 934 | nodebInfo: &entities.NodebInfo{ |
| 935 | RanName: RanName, |
| 936 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 937 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
| 938 | Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{ServedNrCells: oldServedNrCells}}, |
| 939 | NodeType: entities.Node_GNB, |
| 940 | }, |
| 941 | rnibError: nil, |
| 942 | }, |
| 943 | requestBody: map[string]interface{}{ |
| 944 | "servedNrCells": []interface{}{ |
| 945 | map[string]interface{}{ |
| 946 | "servedNrCellInformation": buildServedNrCellInformation(""), |
| 947 | "nrNeighbourInfos": []interface{}{ |
| 948 | buildNrNeighbourInformation(""), |
| 949 | }, |
| 950 | }, |
| 951 | }, |
| 952 | }, |
| 953 | expectedStatusCode: http.StatusOK, |
| 954 | expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"nodeType\":\"GNB\",\"gnb\":{\"servedNrCells\":[{\"servedNrCellInformation\":{\"nrPci\":1,\"cellId\":\"whatever\",\"servedPlmns\":[\"whatever\"],\"nrMode\":\"FDD\",\"choiceNrMode\":{\"fdd\":{}}},\"nrNeighbourInfos\":[{\"nrPci\":1,\"nrCgi\":\"whatever\",\"nrMode\":\"FDD\",\"choiceNrMode\":{\"tdd\":{}}}]}]},\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\"}", |
| 955 | } |
| 956 | |
| 957 | controllerUpdateGnbTestExecuter(t, &context) |
| 958 | } |
| 959 | |
| 960 | /* |
| 961 | UpdateEnb UTs |
| 962 | */ |
| 963 | |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 964 | func TestControllerUpdateEnbInvalidRequest(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 965 | controller, _, _, _, _, _ := setupControllerTest(t) |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 966 | |
| 967 | writer := httptest.NewRecorder() |
| 968 | invalidJson := strings.NewReader("{enb:\"whatever\"") |
| 969 | |
| 970 | updateEnbUrl := fmt.Sprintf("/nodeb/enb/%s", RanName) |
| 971 | req, _ := http.NewRequest(http.MethodPut, updateEnbUrl, invalidJson) |
| 972 | req.Header.Set("Content-Type", "application/json") |
| 973 | req = mux.SetURLVars(req, map[string]string{"ranName": RanName}) |
| 974 | |
| 975 | controller.UpdateEnb(writer, req) |
| 976 | |
| 977 | assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode) |
| 978 | bodyBytes, _ := ioutil.ReadAll(writer.Body) |
| 979 | assert.Equal(t, CorruptedJson, string(bodyBytes)) |
| 980 | } |
| 981 | |
| 982 | func TestControllerUpdateEnbEmptyEnbType(t *testing.T) { |
| 983 | context := controllerUpdateEnbTestContext{ |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 984 | getNodebInfoResult: nil, |
| 985 | requestBody: getUpdateEnbRequest(EnbRequiredFields[0]), |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 986 | expectedStatusCode: http.StatusBadRequest, |
| 987 | expectedJsonResponse: ValidationFailureJson, |
| 988 | } |
| 989 | |
| 990 | controllerUpdateEnbTestExecuter(t, &context) |
| 991 | } |
| 992 | |
| 993 | func TestControllerUpdateEnbEmptyServedCells(t *testing.T) { |
| 994 | context := controllerUpdateEnbTestContext{ |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 995 | getNodebInfoResult: nil, |
| 996 | requestBody: getUpdateEnbRequest(EnbRequiredFields[1]), |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 997 | expectedStatusCode: http.StatusBadRequest, |
| 998 | expectedJsonResponse: ValidationFailureJson, |
| 999 | } |
| 1000 | |
| 1001 | controllerUpdateEnbTestExecuter(t, &context) |
| 1002 | } |
| 1003 | |
| 1004 | func TestControllerUpdateEnbMissingEnb(t *testing.T) { |
| 1005 | context := controllerUpdateEnbTestContext{ |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1006 | getNodebInfoResult: nil, |
| 1007 | requestBody: getUpdateEnbRequest(UpdateEnbRequestRequiredFields[0]), |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1008 | expectedStatusCode: http.StatusBadRequest, |
| 1009 | expectedJsonResponse: ValidationFailureJson, |
| 1010 | } |
| 1011 | |
| 1012 | controllerUpdateEnbTestExecuter(t, &context) |
| 1013 | } |
| 1014 | |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 1015 | func TestControllerUpdateEnbMissingRequiredServedCellProps(t *testing.T) { |
| 1016 | |
| 1017 | r := getUpdateEnbRequest("") |
| 1018 | |
| 1019 | for _, v := range ServedCellRequiredFields { |
| 1020 | enb := r["enb"] |
| 1021 | |
| 1022 | enbMap, _ := enb.(map[string]interface{}) |
| 1023 | |
| 1024 | enbMap["servedCells"] = []interface{}{ |
| 1025 | buildServedCell(v), |
| 1026 | } |
| 1027 | |
| 1028 | context := controllerUpdateEnbTestContext{ |
| 1029 | requestBody: r, |
| 1030 | expectedStatusCode: http.StatusBadRequest, |
| 1031 | expectedJsonResponse: ValidationFailureJson, |
| 1032 | } |
| 1033 | |
| 1034 | controllerUpdateEnbTestExecuter(t, &context) |
| 1035 | } |
| 1036 | } |
| 1037 | |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1038 | func TestControllerUpdateEnbValidServedCellsGetNodebNotFound(t *testing.T) { |
| 1039 | context := controllerUpdateEnbTestContext{ |
| 1040 | getNodebInfoResult: &getNodebInfoResult{ |
| 1041 | nodebInfo: nil, |
| 1042 | rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"), |
| 1043 | }, |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1044 | requestBody: getUpdateEnbRequest(""), |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1045 | expectedStatusCode: http.StatusNotFound, |
| 1046 | expectedJsonResponse: ResourceNotFoundJson, |
| 1047 | } |
| 1048 | |
| 1049 | controllerUpdateEnbTestExecuter(t, &context) |
| 1050 | } |
| 1051 | |
| 1052 | func TestControllerUpdateEnbValidServedCellsGetNodebInternalError(t *testing.T) { |
| 1053 | context := controllerUpdateEnbTestContext{ |
| 1054 | getNodebInfoResult: &getNodebInfoResult{ |
| 1055 | nodebInfo: nil, |
| 1056 | rnibError: common.NewInternalError(errors.New("#reader.GetNodeb - Internal Error")), |
| 1057 | }, |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1058 | requestBody: getUpdateEnbRequest(""), |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1059 | expectedStatusCode: http.StatusInternalServerError, |
| 1060 | expectedJsonResponse: RnibErrorJson, |
| 1061 | } |
| 1062 | |
| 1063 | controllerUpdateEnbTestExecuter(t, &context) |
| 1064 | } |
| 1065 | |
| 1066 | func TestControllerUpdateEnbGetNodebSuccessGnbTypeFailure(t *testing.T) { |
| 1067 | oldServedCells := generateServedCells("whatever1", "whatever2") |
| 1068 | context := controllerUpdateEnbTestContext{ |
| 1069 | getNodebInfoResult: &getNodebInfoResult{ |
| 1070 | nodebInfo: &entities.NodebInfo{ |
| 1071 | RanName: RanName, |
| 1072 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 1073 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
| 1074 | NodeType: entities.Node_GNB, |
| 1075 | Configuration: &entities.NodebInfo_Enb{Enb: &entities.Enb{ServedCells: oldServedCells}}, |
| 1076 | }, |
| 1077 | rnibError: nil, |
| 1078 | }, |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1079 | requestBody: getUpdateEnbRequest(""), |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1080 | expectedStatusCode: http.StatusBadRequest, |
| 1081 | expectedJsonResponse: ValidationFailureJson, |
| 1082 | } |
| 1083 | |
| 1084 | controllerUpdateEnbTestExecuter(t, &context) |
| 1085 | } |
| 1086 | |
| 1087 | func TestControllerUpdateEnbGetNodebSuccessRemoveServedCellsFailure(t *testing.T) { |
| 1088 | oldServedCells := generateServedCells("whatever1", "whatever2") |
| 1089 | context := controllerUpdateEnbTestContext{ |
| 1090 | removeServedCellsParams: &removeServedCellsParams{ |
| 1091 | err: common.NewInternalError(errors.New("#writer.RemoveServedCells - Internal Error")), |
| 1092 | servedCellInfo: oldServedCells, |
| 1093 | }, |
| 1094 | getNodebInfoResult: &getNodebInfoResult{ |
| 1095 | nodebInfo: &entities.NodebInfo{ |
| 1096 | RanName: RanName, |
| 1097 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 1098 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
| 1099 | NodeType: entities.Node_ENB, |
| 1100 | Configuration: &entities.NodebInfo_Enb{Enb: &entities.Enb{ServedCells: oldServedCells}}, |
| 1101 | }, |
| 1102 | rnibError: nil, |
| 1103 | }, |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1104 | requestBody: getUpdateEnbRequest(""), |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1105 | expectedStatusCode: http.StatusInternalServerError, |
| 1106 | expectedJsonResponse: RnibErrorJson, |
| 1107 | } |
| 1108 | |
| 1109 | controllerUpdateEnbTestExecuter(t, &context) |
| 1110 | } |
| 1111 | |
| 1112 | func TestControllerUpdateEnbGetNodebSuccessUpdateEnbFailure(t *testing.T) { |
| 1113 | oldServedCells := generateServedCells("whatever1", "whatever2") |
| 1114 | context := controllerUpdateEnbTestContext{ |
| 1115 | removeServedCellsParams: &removeServedCellsParams{ |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1116 | err: nil, |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1117 | servedCellInfo: oldServedCells, |
| 1118 | }, |
| 1119 | updateEnbCellsParams: &updateEnbCellsParams{ |
| 1120 | err: common.NewInternalError(errors.New("#writer.UpdateEnb - Internal Error")), |
| 1121 | }, |
| 1122 | getNodebInfoResult: &getNodebInfoResult{ |
| 1123 | nodebInfo: &entities.NodebInfo{ |
| 1124 | RanName: RanName, |
| 1125 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 1126 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
| 1127 | NodeType: entities.Node_ENB, |
| 1128 | Configuration: &entities.NodebInfo_Enb{Enb: &entities.Enb{ServedCells: oldServedCells, EnbType: entities.EnbType_MACRO_ENB}}, |
| 1129 | }, |
| 1130 | rnibError: nil, |
| 1131 | }, |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1132 | requestBody: getUpdateEnbRequest(""), |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1133 | expectedStatusCode: http.StatusInternalServerError, |
| 1134 | expectedJsonResponse: RnibErrorJson, |
| 1135 | } |
| 1136 | |
| 1137 | controllerUpdateEnbTestExecuter(t, &context) |
| 1138 | } |
| 1139 | |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 1140 | func TestControllerUpdateEnbExistingEmptyCellsSuccess(t *testing.T) { |
| 1141 | oldServedCells := []*entities.ServedCellInfo{} |
| 1142 | context := controllerUpdateEnbTestContext{ |
| 1143 | updateEnbCellsParams: &updateEnbCellsParams{ |
| 1144 | err: nil, |
| 1145 | }, |
| 1146 | getNodebInfoResult: &getNodebInfoResult{ |
| 1147 | nodebInfo: &entities.NodebInfo{ |
| 1148 | RanName: RanName, |
| 1149 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 1150 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
| 1151 | NodeType: entities.Node_ENB, |
| 1152 | Configuration: &entities.NodebInfo_Enb{Enb: &entities.Enb{ServedCells: oldServedCells, EnbType: entities.EnbType_MACRO_ENB}}, |
| 1153 | }, |
| 1154 | rnibError: nil, |
| 1155 | }, |
| 1156 | requestBody: getUpdateEnbRequest(""), |
| 1157 | expectedStatusCode: http.StatusOK, |
| 1158 | expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"nodeType\":\"ENB\",\"enb\":{\"enbType\":\"MACRO_ENB\",\"servedCells\":[{\"pci\":1,\"cellId\":\"whatever\",\"tac\":\"whatever3\",\"broadcastPlmns\":[\"whatever\"],\"choiceEutraMode\":{\"fdd\":{}},\"eutraMode\":\"FDD\"}]},\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\"}", |
| 1159 | } |
| 1160 | |
| 1161 | controllerUpdateEnbTestExecuter(t, &context) |
| 1162 | } |
| 1163 | |
idanshal | 885ce20 | 2020-08-05 06:49:57 +0000 | [diff] [blame] | 1164 | func TestControllerUpdateEnbNgEnbFailure(t *testing.T) { |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 1165 | |
idanshal | 885ce20 | 2020-08-05 06:49:57 +0000 | [diff] [blame] | 1166 | requestBody := map[string]interface{}{ |
| 1167 | "enb": map[string]interface{}{ |
ss412g | 7bd44bd | 2020-08-06 21:20:09 +0000 | [diff] [blame] | 1168 | "enbType": 3, |
idanshal | 885ce20 | 2020-08-05 06:49:57 +0000 | [diff] [blame] | 1169 | "servedCells": []interface{}{ |
| 1170 | buildServedCell(""), |
| 1171 | }}, |
| 1172 | } |
| 1173 | |
ss412g | 7bd44bd | 2020-08-06 21:20:09 +0000 | [diff] [blame] | 1174 | oldServedCells := generateServedCells("whatever1", "whatever2") |
| 1175 | |
idanshal | 885ce20 | 2020-08-05 06:49:57 +0000 | [diff] [blame] | 1176 | context := controllerUpdateEnbTestContext{ |
Rahul Banerji | fe8d481 | 2020-08-24 14:26:41 +0530 | [diff] [blame] | 1177 | getNodebInfoResult: &getNodebInfoResult{ |
| 1178 | nodebInfo: &entities.NodebInfo{ |
| 1179 | RanName: RanName, |
| 1180 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 1181 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
| 1182 | NodeType: entities.Node_ENB, |
| 1183 | Configuration: &entities.NodebInfo_Enb{Enb: &entities.Enb{ServedCells: oldServedCells, EnbType: entities.EnbType_MACRO_NG_ENB}}, |
| 1184 | }, |
| 1185 | rnibError: nil, |
| 1186 | }, |
idanshal | 885ce20 | 2020-08-05 06:49:57 +0000 | [diff] [blame] | 1187 | requestBody: requestBody, |
| 1188 | expectedStatusCode: http.StatusBadRequest, |
| 1189 | expectedJsonResponse: ValidationFailureJson, |
| 1190 | } |
| 1191 | |
| 1192 | controllerUpdateEnbTestExecuter(t, &context) |
| 1193 | } |
| 1194 | |
| 1195 | func TestControllerUpdateEnbSuccessSetupFromNwFalse(t *testing.T) { |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1196 | oldServedCells := generateServedCells("whatever1", "whatever2") |
| 1197 | context := controllerUpdateEnbTestContext{ |
| 1198 | removeServedCellsParams: &removeServedCellsParams{ |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1199 | err: nil, |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1200 | servedCellInfo: oldServedCells, |
| 1201 | }, |
| 1202 | updateEnbCellsParams: &updateEnbCellsParams{ |
| 1203 | err: nil, |
| 1204 | }, |
| 1205 | getNodebInfoResult: &getNodebInfoResult{ |
| 1206 | nodebInfo: &entities.NodebInfo{ |
| 1207 | RanName: RanName, |
| 1208 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 1209 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
| 1210 | NodeType: entities.Node_ENB, |
idanshal | 885ce20 | 2020-08-05 06:49:57 +0000 | [diff] [blame] | 1211 | Configuration: &entities.NodebInfo_Enb{Enb: &entities.Enb{ServedCells: oldServedCells, EnbType: entities.EnbType_LONG_MACRO_ENB}}, |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1212 | }, |
| 1213 | rnibError: nil, |
| 1214 | }, |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1215 | requestBody: getUpdateEnbRequest(""), |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1216 | expectedStatusCode: http.StatusOK, |
| 1217 | expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"nodeType\":\"ENB\",\"enb\":{\"enbType\":\"MACRO_ENB\",\"servedCells\":[{\"pci\":1,\"cellId\":\"whatever\",\"tac\":\"whatever3\",\"broadcastPlmns\":[\"whatever\"],\"choiceEutraMode\":{\"fdd\":{}},\"eutraMode\":\"FDD\"}]},\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\"}", |
| 1218 | } |
| 1219 | |
| 1220 | controllerUpdateEnbTestExecuter(t, &context) |
| 1221 | } |
| 1222 | |
idanshal | 885ce20 | 2020-08-05 06:49:57 +0000 | [diff] [blame] | 1223 | func TestControllerUpdateEnbSuccessSetupFromNwTrue(t *testing.T) { |
| 1224 | oldServedCells := generateServedCells("whatever1", "whatever2") |
| 1225 | context := controllerUpdateEnbTestContext{ |
| 1226 | removeServedCellsParams: &removeServedCellsParams{ |
| 1227 | err: nil, |
| 1228 | servedCellInfo: oldServedCells, |
| 1229 | }, |
| 1230 | updateEnbCellsParams: &updateEnbCellsParams{ |
| 1231 | err: nil, |
| 1232 | }, |
| 1233 | getNodebInfoResult: &getNodebInfoResult{ |
| 1234 | nodebInfo: &entities.NodebInfo{ |
| 1235 | RanName: RanName, |
| 1236 | ConnectionStatus: entities.ConnectionStatus_CONNECTED, |
| 1237 | AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, |
| 1238 | NodeType: entities.Node_ENB, |
| 1239 | Configuration: &entities.NodebInfo_Enb{Enb: &entities.Enb{ServedCells: oldServedCells, EnbType: entities.EnbType_LONG_MACRO_ENB}}, |
| 1240 | SetupFromNetwork: true, |
| 1241 | }, |
| 1242 | rnibError: nil, |
| 1243 | }, |
| 1244 | requestBody: getUpdateEnbRequest(""), |
| 1245 | expectedStatusCode: http.StatusOK, |
| 1246 | expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"nodeType\":\"ENB\",\"enb\":{\"enbType\":\"LONG_MACRO_ENB\",\"servedCells\":[{\"pci\":1,\"cellId\":\"whatever\",\"tac\":\"whatever3\",\"broadcastPlmns\":[\"whatever\"],\"choiceEutraMode\":{\"fdd\":{}},\"eutraMode\":\"FDD\"}]},\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\",\"setupFromNetwork\":true}", |
| 1247 | } |
| 1248 | |
| 1249 | controllerUpdateEnbTestExecuter(t, &context) |
| 1250 | } |
| 1251 | |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 1252 | /* |
| 1253 | AddEnb UTs |
| 1254 | */ |
| 1255 | |
idanshal | 13fff61 | 2020-07-07 11:53:39 +0000 | [diff] [blame] | 1256 | func TestControllerAddEnbGetNodebInternalError(t *testing.T) { |
| 1257 | context := controllerAddEnbTestContext{ |
| 1258 | getNodebInfoResult: &getNodebInfoResult{ |
| 1259 | nodebInfo: nil, |
| 1260 | rnibError: common.NewInternalError(errors.New("#reader.GetNodeb - Internal Error")), |
| 1261 | }, |
| 1262 | requestBody: getAddEnbRequest(""), |
| 1263 | expectedStatusCode: http.StatusInternalServerError, |
| 1264 | expectedJsonResponse: RnibErrorJson, |
| 1265 | } |
| 1266 | |
| 1267 | controllerAddEnbTestExecuter(t, &context) |
| 1268 | } |
| 1269 | |
| 1270 | func TestControllerAddEnbNodebExistsFailure(t *testing.T) { |
| 1271 | context := controllerAddEnbTestContext{ |
| 1272 | getNodebInfoResult: &getNodebInfoResult{ |
| 1273 | nodebInfo: &entities.NodebInfo{}, |
| 1274 | rnibError: nil, |
| 1275 | }, |
| 1276 | requestBody: getAddEnbRequest(""), |
| 1277 | expectedStatusCode: http.StatusBadRequest, |
| 1278 | expectedJsonResponse: NodebExistsJson, |
| 1279 | } |
| 1280 | |
| 1281 | controllerAddEnbTestExecuter(t, &context) |
| 1282 | } |
| 1283 | |
| 1284 | func TestControllerAddEnbSaveNodebFailure(t *testing.T) { |
| 1285 | context := controllerAddEnbTestContext{ |
Amichai | 7ec48b2 | 2020-07-23 11:28:40 +0000 | [diff] [blame] | 1286 | addEnbParams: &addEnbParams{ |
| 1287 | err: common.NewInternalError(errors.New("#reader.AddEnb - Internal Error")), |
idanshal | 13fff61 | 2020-07-07 11:53:39 +0000 | [diff] [blame] | 1288 | }, |
| 1289 | getNodebInfoResult: &getNodebInfoResult{ |
| 1290 | nodebInfo: nil, |
| 1291 | rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"), |
| 1292 | }, |
| 1293 | requestBody: getAddEnbRequest(""), |
| 1294 | expectedStatusCode: http.StatusInternalServerError, |
| 1295 | expectedJsonResponse: RnibErrorJson, |
| 1296 | } |
| 1297 | |
| 1298 | controllerAddEnbTestExecuter(t, &context) |
| 1299 | } |
| 1300 | |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1301 | func TestControllerAddEnbAddNbIdentityFailure(t *testing.T) { |
| 1302 | context := controllerAddEnbTestContext{ |
Amichai | 7ec48b2 | 2020-07-23 11:28:40 +0000 | [diff] [blame] | 1303 | addEnbParams: &addEnbParams{ |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1304 | err: nil, |
| 1305 | }, |
| 1306 | addNbIdentityParams: &addNbIdentityParams{ |
| 1307 | err: common.NewInternalError(errors.New("#writer.addNbIdentity - Internal Error")), |
| 1308 | }, |
| 1309 | getNodebInfoResult: &getNodebInfoResult{ |
| 1310 | nodebInfo: nil, |
| 1311 | rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"), |
| 1312 | }, |
| 1313 | requestBody: getAddEnbRequest(""), |
| 1314 | expectedStatusCode: http.StatusInternalServerError, |
| 1315 | expectedJsonResponse: RnibErrorJson, |
| 1316 | } |
| 1317 | |
| 1318 | controllerAddEnbTestExecuter(t, &context) |
| 1319 | } |
| 1320 | |
idanshal | 13fff61 | 2020-07-07 11:53:39 +0000 | [diff] [blame] | 1321 | func TestControllerAddEnbMissingRequiredRequestProps(t *testing.T) { |
| 1322 | |
| 1323 | for _, v := range AddEnbRequestRequiredFields { |
| 1324 | context := controllerAddEnbTestContext{ |
| 1325 | requestBody: getAddEnbRequest(v), |
| 1326 | expectedStatusCode: http.StatusBadRequest, |
| 1327 | expectedJsonResponse: ValidationFailureJson, |
| 1328 | } |
| 1329 | |
| 1330 | controllerAddEnbTestExecuter(t, &context) |
| 1331 | } |
| 1332 | } |
| 1333 | |
idanshal | e0106ff | 2020-07-07 16:04:00 +0000 | [diff] [blame] | 1334 | func TestControllerAddEnbInvalidRequest(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1335 | controller, _, _, _, _, _ := setupControllerTest(t) |
idanshal | e0106ff | 2020-07-07 16:04:00 +0000 | [diff] [blame] | 1336 | writer := httptest.NewRecorder() |
| 1337 | |
| 1338 | // Invalid json: attribute name without quotes (should be "cause":). |
| 1339 | invalidJson := strings.NewReader("{ranName:\"whatever\"") |
| 1340 | req, _ := http.NewRequest(http.MethodPost, AddEnbUrl, invalidJson) |
| 1341 | |
| 1342 | controller.AddEnb(writer, req) |
| 1343 | assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode) |
| 1344 | bodyBytes, _ := ioutil.ReadAll(writer.Body) |
| 1345 | assert.Equal(t, CorruptedJson, string(bodyBytes)) |
| 1346 | |
| 1347 | } |
| 1348 | |
| 1349 | func TestControllerAddEnbMissingRequiredGlobalNbIdProps(t *testing.T) { |
| 1350 | |
| 1351 | r := getAddEnbRequest("") |
| 1352 | |
| 1353 | for _, v := range GlobalIdRequiredFields { |
| 1354 | r["globalNbId"] = buildGlobalNbId(v) |
| 1355 | |
| 1356 | context := controllerAddEnbTestContext{ |
| 1357 | requestBody: r, |
| 1358 | expectedStatusCode: http.StatusBadRequest, |
| 1359 | expectedJsonResponse: ValidationFailureJson, |
| 1360 | } |
| 1361 | |
| 1362 | controllerAddEnbTestExecuter(t, &context) |
| 1363 | } |
| 1364 | } |
| 1365 | |
idanshal | 13fff61 | 2020-07-07 11:53:39 +0000 | [diff] [blame] | 1366 | func TestControllerAddEnbMissingRequiredEnbProps(t *testing.T) { |
| 1367 | |
| 1368 | r := getAddEnbRequest("") |
| 1369 | |
| 1370 | for _, v := range EnbRequiredFields { |
| 1371 | r["enb"] = buildEnb(v) |
| 1372 | |
| 1373 | context := controllerAddEnbTestContext{ |
| 1374 | requestBody: r, |
| 1375 | expectedStatusCode: http.StatusBadRequest, |
| 1376 | expectedJsonResponse: ValidationFailureJson, |
| 1377 | } |
| 1378 | |
| 1379 | controllerAddEnbTestExecuter(t, &context) |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | func TestControllerAddEnbMissingRequiredServedCellProps(t *testing.T) { |
| 1384 | |
| 1385 | r := getAddEnbRequest("") |
| 1386 | |
| 1387 | for _, v := range ServedCellRequiredFields { |
| 1388 | enb := r["enb"] |
| 1389 | |
| 1390 | enbMap, _ := enb.(map[string]interface{}) |
| 1391 | |
| 1392 | enbMap["servedCells"] = []interface{}{ |
| 1393 | buildServedCell(v), |
| 1394 | } |
| 1395 | |
| 1396 | context := controllerAddEnbTestContext{ |
| 1397 | requestBody: r, |
| 1398 | expectedStatusCode: http.StatusBadRequest, |
| 1399 | expectedJsonResponse: ValidationFailureJson, |
| 1400 | } |
| 1401 | |
| 1402 | controllerAddEnbTestExecuter(t, &context) |
| 1403 | } |
| 1404 | } |
| 1405 | |
idanshal | 885ce20 | 2020-08-05 06:49:57 +0000 | [diff] [blame] | 1406 | func TestControllerAddEnbNgEnbFailure(t *testing.T) { |
| 1407 | |
| 1408 | requestBody := map[string]interface{}{ |
| 1409 | "ranName": RanName, |
| 1410 | "globalNbId": buildGlobalNbId(""), |
| 1411 | "enb": map[string]interface{}{ |
| 1412 | "enbType": 5, |
| 1413 | "servedCells": []interface{}{ |
| 1414 | buildServedCell(""), |
| 1415 | }, |
| 1416 | }, |
| 1417 | } |
| 1418 | |
| 1419 | context := controllerAddEnbTestContext{ |
| 1420 | requestBody: requestBody, |
| 1421 | expectedStatusCode: http.StatusBadRequest, |
| 1422 | expectedJsonResponse: ValidationFailureJson, |
| 1423 | } |
| 1424 | |
| 1425 | controllerAddEnbTestExecuter(t, &context) |
| 1426 | } |
| 1427 | |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 1428 | func TestControllerAddEnbSuccess(t *testing.T) { |
| 1429 | context := controllerAddEnbTestContext{ |
Amichai | 7ec48b2 | 2020-07-23 11:28:40 +0000 | [diff] [blame] | 1430 | addEnbParams: &addEnbParams{ |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 1431 | err: nil, |
| 1432 | }, |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1433 | addNbIdentityParams: &addNbIdentityParams{ |
| 1434 | err: nil, |
| 1435 | }, |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 1436 | getNodebInfoResult: &getNodebInfoResult{ |
| 1437 | nodebInfo: nil, |
| 1438 | rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"), |
| 1439 | }, |
idanshal | a269db8 | 2020-07-15 08:59:15 +0000 | [diff] [blame] | 1440 | requestBody: getAddEnbRequest(""), |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 1441 | expectedStatusCode: http.StatusCreated, |
idanshal | e0106ff | 2020-07-07 16:04:00 +0000 | [diff] [blame] | 1442 | expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"DISCONNECTED\",\"globalNbId\":{\"plmnId\":\"whatever\",\"nbId\":\"whatever2\"},\"nodeType\":\"ENB\",\"enb\":{\"enbType\":\"MACRO_ENB\",\"servedCells\":[{\"pci\":1,\"cellId\":\"whatever\",\"tac\":\"whatever3\",\"broadcastPlmns\":[\"whatever\"],\"choiceEutraMode\":{\"fdd\":{}},\"eutraMode\":\"FDD\"}]}}", |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | controllerAddEnbTestExecuter(t, &context) |
| 1446 | } |
| 1447 | |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 1448 | func TestControllerDeleteEnbGetNodebInternalError(t *testing.T) { |
| 1449 | context := controllerDeleteEnbTestContext{ |
| 1450 | getNodebInfoResult: &getNodebInfoResult{ |
| 1451 | nodebInfo: nil, |
| 1452 | rnibError: common.NewInternalError(errors.New("#reader.GetNodeb - Internal Error")), |
| 1453 | }, |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1454 | expectedStatusCode: http.StatusInternalServerError, |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 1455 | expectedJsonResponse: RnibErrorJson, |
| 1456 | } |
| 1457 | |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 1458 | controllerDeleteEnbTestExecuter(t, &context, false) |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 1461 | /* |
| 1462 | DeleteEnb UTs |
| 1463 | */ |
| 1464 | |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 1465 | func TestControllerDeleteEnbNodebNotExistsFailure(t *testing.T) { |
| 1466 | context := controllerDeleteEnbTestContext{ |
| 1467 | getNodebInfoResult: &getNodebInfoResult{ |
| 1468 | nodebInfo: nil, |
| 1469 | rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found"), |
| 1470 | }, |
| 1471 | expectedStatusCode: http.StatusNotFound, |
| 1472 | expectedJsonResponse: ResourceNotFoundJson, |
| 1473 | } |
| 1474 | |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 1475 | controllerDeleteEnbTestExecuter(t, &context, false) |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | func TestControllerDeleteEnbNodebNotEnb(t *testing.T) { |
| 1479 | context := controllerDeleteEnbTestContext{ |
| 1480 | getNodebInfoResult: &getNodebInfoResult{ |
| 1481 | nodebInfo: &entities.NodebInfo{RanName: "ran1", NodeType: entities.Node_GNB, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}, |
| 1482 | rnibError: nil, |
| 1483 | }, |
| 1484 | expectedStatusCode: http.StatusBadRequest, |
| 1485 | expectedJsonResponse: ValidationFailureJson, |
| 1486 | } |
| 1487 | |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 1488 | controllerDeleteEnbTestExecuter(t, &context, false) |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
idanshal | 885ce20 | 2020-08-05 06:49:57 +0000 | [diff] [blame] | 1491 | func TestControllerDeleteEnbSetupFromNetworkTrueFailure(t *testing.T) { |
| 1492 | context := controllerDeleteEnbTestContext{ |
| 1493 | getNodebInfoResult: &getNodebInfoResult{ |
| 1494 | nodebInfo: &entities.NodebInfo{RanName: RanName, NodeType: entities.Node_ENB, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, SetupFromNetwork: true}, |
| 1495 | rnibError: nil, |
| 1496 | }, |
| 1497 | expectedStatusCode: http.StatusBadRequest, |
| 1498 | expectedJsonResponse: ValidationFailureJson, |
| 1499 | } |
| 1500 | controllerDeleteEnbTestExecuter(t, &context, true) |
| 1501 | } |
| 1502 | |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 1503 | func TestControllerDeleteEnbSuccess(t *testing.T) { |
| 1504 | context := controllerDeleteEnbTestContext{ |
| 1505 | getNodebInfoResult: &getNodebInfoResult{ |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 1506 | nodebInfo: &entities.NodebInfo{RanName: RanName, NodeType: entities.Node_ENB, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}, |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 1507 | rnibError: nil, |
| 1508 | }, |
Irina | 9377e3d | 2020-07-13 13:15:03 +0300 | [diff] [blame] | 1509 | expectedStatusCode: http.StatusNoContent, |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 1510 | expectedJsonResponse: "", |
| 1511 | } |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 1512 | controllerDeleteEnbTestExecuter(t, &context, true) |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 1515 | func getJsonRequestAsBuffer(requestJson map[string]interface{}) *bytes.Buffer { |
| 1516 | b := new(bytes.Buffer) |
| 1517 | _ = json.NewEncoder(b).Encode(requestJson) |
idanshal | 087f53f | 2020-04-27 14:12:54 +0300 | [diff] [blame] | 1518 | return b |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 1519 | } |
| 1520 | |
idanshal | 7000880 | 2020-07-23 06:16:41 +0000 | [diff] [blame] | 1521 | /* |
| 1522 | GetNodeb UTs |
| 1523 | */ |
| 1524 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1525 | func TestControllerGetNodebSuccess(t *testing.T) { |
| 1526 | ranName := "test" |
irina | 006fbce | 2019-09-05 16:11:02 +0300 | [diff] [blame] | 1527 | var rnibError error |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1528 | context := controllerGetNodebTestContext{ |
| 1529 | ranName: ranName, |
| 1530 | nodebInfo: &entities.NodebInfo{RanName: ranName, Ip: "10.0.2.15", Port: 1234}, |
| 1531 | rnibError: rnibError, |
| 1532 | expectedStatusCode: http.StatusOK, |
| 1533 | expectedJsonResponse: fmt.Sprintf("{\"ranName\":\"%s\",\"ip\":\"10.0.2.15\",\"port\":1234}", ranName), |
| 1534 | } |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1535 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1536 | controllerGetNodebTestExecuter(t, &context) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1537 | } |
| 1538 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1539 | func TestControllerGetNodebNotFound(t *testing.T) { |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1540 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1541 | ranName := "test" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1542 | var nodebInfo *entities.NodebInfo |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1543 | context := controllerGetNodebTestContext{ |
| 1544 | ranName: ranName, |
| 1545 | nodebInfo: nodebInfo, |
| 1546 | rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"), |
| 1547 | expectedStatusCode: http.StatusNotFound, |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 1548 | expectedJsonResponse: ResourceNotFoundJson, |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1549 | } |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1550 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1551 | controllerGetNodebTestExecuter(t, &context) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1552 | } |
| 1553 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1554 | func TestControllerGetNodebInternal(t *testing.T) { |
| 1555 | ranName := "test" |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1556 | var nodebInfo *entities.NodebInfo |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1557 | context := controllerGetNodebTestContext{ |
| 1558 | ranName: ranName, |
| 1559 | nodebInfo: nodebInfo, |
| 1560 | rnibError: common.NewInternalError(errors.New("#reader.GetNodeb - Internal Error")), |
| 1561 | expectedStatusCode: http.StatusInternalServerError, |
idanshal | f1035e2 | 2020-04-13 11:09:19 +0300 | [diff] [blame] | 1562 | expectedJsonResponse: RnibErrorJson, |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1563 | } |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1564 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1565 | controllerGetNodebTestExecuter(t, &context) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1566 | } |
| 1567 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1568 | func TestControllerGetNodebIdListSuccess(t *testing.T) { |
irina | 006fbce | 2019-09-05 16:11:02 +0300 | [diff] [blame] | 1569 | var rnibError error |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1570 | nodebIdList := []*entities.NbIdentity{ |
is005q | ffd085d | 2019-09-10 15:56:48 +0300 | [diff] [blame] | 1571 | {InventoryName: "test1", GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}, |
| 1572 | {InventoryName: "test2", GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2", NbId: "nbId2"}}, |
Amichai | 1e5e5ae | 2019-09-01 16:46:42 +0300 | [diff] [blame] | 1573 | } |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1574 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1575 | context := controllerGetNodebIdListTestContext{ |
| 1576 | nodebIdList: nodebIdList, |
| 1577 | rnibError: rnibError, |
| 1578 | expectedStatusCode: http.StatusOK, |
Amichai | 7ec48b2 | 2020-07-23 11:28:40 +0000 | [diff] [blame] | 1579 | expectedJsonResponse: "[{\"inventoryName\":\"test1\",\"globalNbId\":{\"plmnId\":\"plmnId1\",\"nbId\":\"nbId1\"}},{\"inventoryName\":\"test2\",\"globalNbId\":{\"plmnId\":\"plmnId2\",\"nbId\":\"nbId2\"}}][{\"inventoryName\":\"test2\",\"globalNbId\":{\"plmnId\":\"plmnId2\",\"nbId\":\"nbId2\"}},{\"inventoryName\":\"test1\",\"globalNbId\":{\"plmnId\":\"plmnId1\",\"nbId\":\"nbId1\"}}]", |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | controllerGetNodebIdListTestExecuter(t, &context) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1583 | } |
| 1584 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1585 | func TestControllerGetNodebIdListEmptySuccess(t *testing.T) { |
| 1586 | var rnibError error |
Irina | 5830d4d | 2020-07-08 18:11:04 +0000 | [diff] [blame] | 1587 | var nodebIdList []*entities.NbIdentity |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1588 | |
| 1589 | context := controllerGetNodebIdListTestContext{ |
| 1590 | nodebIdList: nodebIdList, |
| 1591 | rnibError: rnibError, |
| 1592 | expectedStatusCode: http.StatusOK, |
| 1593 | expectedJsonResponse: "[]", |
| 1594 | } |
| 1595 | |
| 1596 | controllerGetNodebIdListTestExecuter(t, &context) |
| 1597 | } |
| 1598 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1599 | func TestHeaderValidationFailed(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1600 | controller, _, _, _, _, _ := setupControllerTest(t) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1601 | |
| 1602 | writer := httptest.NewRecorder() |
| 1603 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1604 | header := &http.Header{} |
| 1605 | |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 1606 | controller.handleRequest(writer, header, httpmsghandlerprovider.ShutdownRequest, nil, true, 0) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1607 | |
| 1608 | var errorResponse = parseJsonRequest(t, writer.Body) |
| 1609 | err := e2managererrors.NewHeaderValidationError() |
| 1610 | |
| 1611 | assert.Equal(t, http.StatusUnsupportedMediaType, writer.Result().StatusCode) |
| 1612 | assert.Equal(t, errorResponse.Code, err.Code) |
| 1613 | assert.Equal(t, errorResponse.Message, err.Message) |
| 1614 | } |
| 1615 | |
| 1616 | func TestShutdownStatusNoContent(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1617 | controller, readerMock, _, _, e2tInstancesManagerMock, _ := setupControllerTest(t) |
is005q | 90d22a6 | 2020-01-01 11:55:49 +0200 | [diff] [blame] | 1618 | e2tInstancesManagerMock.On("GetE2TAddresses").Return([]string{}, nil) |
| 1619 | readerMock.On("GetListNodebIds").Return([]*entities.NbIdentity{}, nil) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1620 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1621 | writer := httptest.NewRecorder() |
| 1622 | controller.Shutdown(writer, tests.GetHttpRequest()) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1623 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1624 | assert.Equal(t, http.StatusNoContent, writer.Result().StatusCode) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1625 | } |
| 1626 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1627 | func TestHandleInternalError(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1628 | controller, _, _, _, _, _ := setupControllerTest(t) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1629 | |
| 1630 | writer := httptest.NewRecorder() |
| 1631 | err := e2managererrors.NewInternalError() |
| 1632 | |
| 1633 | controller.handleErrorResponse(err, writer) |
| 1634 | var errorResponse = parseJsonRequest(t, writer.Body) |
| 1635 | |
| 1636 | assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode) |
| 1637 | assert.Equal(t, errorResponse.Code, err.Code) |
| 1638 | assert.Equal(t, errorResponse.Message, err.Message) |
| 1639 | } |
| 1640 | |
| 1641 | func TestHandleCommandAlreadyInProgressError(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1642 | controller, _, _, _, _, _ := setupControllerTest(t) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1643 | writer := httptest.NewRecorder() |
| 1644 | err := e2managererrors.NewCommandAlreadyInProgressError() |
| 1645 | |
| 1646 | controller.handleErrorResponse(err, writer) |
| 1647 | var errorResponse = parseJsonRequest(t, writer.Body) |
| 1648 | |
| 1649 | assert.Equal(t, http.StatusMethodNotAllowed, writer.Result().StatusCode) |
| 1650 | assert.Equal(t, errorResponse.Code, err.Code) |
| 1651 | assert.Equal(t, errorResponse.Message, err.Message) |
| 1652 | } |
| 1653 | |
is005q | 32d7f42 | 2020-01-02 16:23:06 +0200 | [diff] [blame] | 1654 | func TestHandleRoutingManagerError(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1655 | controller, _, _, _, _, _ := setupControllerTest(t) |
is005q | 32d7f42 | 2020-01-02 16:23:06 +0200 | [diff] [blame] | 1656 | writer := httptest.NewRecorder() |
| 1657 | err := e2managererrors.NewRoutingManagerError() |
| 1658 | |
| 1659 | controller.handleErrorResponse(err, writer) |
| 1660 | var errorResponse = parseJsonRequest(t, writer.Body) |
| 1661 | |
| 1662 | assert.Equal(t, http.StatusServiceUnavailable, writer.Result().StatusCode) |
| 1663 | assert.Equal(t, errorResponse.Code, err.Code) |
| 1664 | assert.Equal(t, errorResponse.Message, err.Message) |
| 1665 | } |
| 1666 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 1667 | func TestHandleE2TInstanceAbsenceError(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1668 | controller, _, _, _, _, _ := setupControllerTest(t) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 1669 | |
| 1670 | writer := httptest.NewRecorder() |
| 1671 | err := e2managererrors.NewE2TInstanceAbsenceError() |
| 1672 | |
| 1673 | controller.handleErrorResponse(err, writer) |
| 1674 | var errorResponse = parseJsonRequest(t, writer.Body) |
| 1675 | |
| 1676 | assert.Equal(t, http.StatusServiceUnavailable, writer.Result().StatusCode) |
| 1677 | assert.Equal(t, errorResponse.Code, err.Code) |
| 1678 | assert.Equal(t, errorResponse.Message, err.Message) |
| 1679 | } |
| 1680 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1681 | func TestValidateHeaders(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1682 | controller, _, _, _, _, _ := setupControllerTest(t) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1683 | |
| 1684 | header := http.Header{} |
| 1685 | header.Set("Content-Type", "application/json") |
| 1686 | result := controller.validateRequestHeader(&header) |
| 1687 | |
| 1688 | assert.Nil(t, result) |
| 1689 | } |
| 1690 | |
| 1691 | func parseJsonRequest(t *testing.T, r io.Reader) models.ErrorResponse { |
| 1692 | |
| 1693 | var errorResponse models.ErrorResponse |
| 1694 | body, err := ioutil.ReadAll(r) |
| 1695 | if err != nil { |
| 1696 | t.Errorf("Error cannot deserialize json request") |
| 1697 | } |
idanshal | 087f53f | 2020-04-27 14:12:54 +0300 | [diff] [blame] | 1698 | _ = json.Unmarshal(body, &errorResponse) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1699 | |
| 1700 | return errorResponse |
| 1701 | } |
| 1702 | |
| 1703 | func initLog(t *testing.T) *logger.Logger { |
rimverma | 4cd92f9 | 2023-04-25 11:51:14 +0530 | [diff] [blame] | 1704 | InfoLevel := int8(3) |
| 1705 | log, err := logger.InitLogger(InfoLevel) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1706 | if err != nil { |
| 1707 | t.Errorf("#delete_all_request_handler_test.TestHandleSuccessFlow - failed to initialize logger, error: %s", err) |
| 1708 | } |
| 1709 | return log |
| 1710 | } |
| 1711 | |
| 1712 | func TestX2ResetHandleSuccessfulRequestedCause(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1713 | controller, readerMock, _, rmrMessengerMock, _, _ := setupControllerTest(t) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1714 | |
| 1715 | ranName := "test1" |
| 1716 | payload := []byte{0x00, 0x07, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x05, 0x40, 0x01, 0x40} |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 1717 | var xAction []byte |
ns019t | b3805a9 | 2020-04-13 16:57:59 +0300 | [diff] [blame] | 1718 | var msgSrc unsafe.Pointer |
| 1719 | msg := rmrCgo.NewMBuf(rmrCgo.RIC_X2_RESET, len(payload), ranName, &payload, &xAction, msgSrc) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1720 | rmrMessengerMock.On("SendMsg", msg, mock.Anything).Return(msg, nil) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1721 | |
| 1722 | writer := httptest.NewRecorder() |
| 1723 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1724 | var nodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED} |
| 1725 | readerMock.On("GetNodeb", ranName).Return(nodeb, nil) |
ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1726 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1727 | data4Req := map[string]interface{}{"cause": "protocol:transfer-syntax-error"} |
| 1728 | b := new(bytes.Buffer) |
| 1729 | _ = json.NewEncoder(b).Encode(data4Req) |
| 1730 | req, _ := http.NewRequest("PUT", "https://localhost:3800/nodeb-reset", b) |
| 1731 | req = mux.SetURLVars(req, map[string]string{"ranName": ranName}) |
| 1732 | |
| 1733 | controller.X2Reset(writer, req) |
| 1734 | assert.Equal(t, http.StatusNoContent, writer.Result().StatusCode) |
| 1735 | |
| 1736 | } |
| 1737 | |
| 1738 | func TestX2ResetHandleSuccessfulRequestedDefault(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1739 | controller, readerMock, _, rmrMessengerMock, _, _ := setupControllerTest(t) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1740 | |
| 1741 | ranName := "test1" |
| 1742 | // o&m intervention |
| 1743 | payload := []byte{0x00, 0x07, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x05, 0x40, 0x01, 0x64} |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 1744 | var xAction []byte |
ns019t | b3805a9 | 2020-04-13 16:57:59 +0300 | [diff] [blame] | 1745 | var msgSrc unsafe.Pointer |
| 1746 | msg := rmrCgo.NewMBuf(rmrCgo.RIC_X2_RESET, len(payload), ranName, &payload, &xAction, msgSrc) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 1747 | rmrMessengerMock.On("SendMsg", msg, true).Return(msg, nil) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1748 | |
| 1749 | writer := httptest.NewRecorder() |
| 1750 | |
| 1751 | var nodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED} |
| 1752 | readerMock.On("GetNodeb", ranName).Return(nodeb, nil) |
| 1753 | |
| 1754 | // no body |
| 1755 | b := new(bytes.Buffer) |
Idan Shalom | 14eb513 | 2020-07-06 09:41:46 +0000 | [diff] [blame] | 1756 | data4Req := map[string]interface{}{} |
| 1757 | _ = json.NewEncoder(b).Encode(data4Req) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1758 | req, _ := http.NewRequest("PUT", "https://localhost:3800/nodeb-reset", b) |
| 1759 | req = mux.SetURLVars(req, map[string]string{"ranName": ranName}) |
| 1760 | |
| 1761 | controller.X2Reset(writer, req) |
| 1762 | assert.Equal(t, http.StatusNoContent, writer.Result().StatusCode) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1763 | } |
| 1764 | |
Timo Tietavainen | 0234dab | 2020-11-19 09:04:22 +0200 | [diff] [blame] | 1765 | func TestX2ResetHandleFailureBodyReadError(t *testing.T) { |
| 1766 | controller, _, _, _, _, _ := setupControllerTest(t) |
| 1767 | |
| 1768 | ranName := "test1" |
| 1769 | writer := httptest.NewRecorder() |
| 1770 | |
| 1771 | // Fake reader to return reading error. |
| 1772 | req, _ := http.NewRequest("PUT", "https://localhost:3800/nodeb-reset", errReader(0)) |
| 1773 | req = mux.SetURLVars(req, map[string]string{"ranName": ranName}) |
| 1774 | |
| 1775 | controller.X2Reset(writer, req) |
| 1776 | assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode) |
| 1777 | |
| 1778 | } |
| 1779 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1780 | func TestX2ResetHandleFailureInvalidBody(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1781 | controller, _, _, _, _, _ := setupControllerTest(t) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1782 | |
| 1783 | ranName := "test1" |
| 1784 | |
| 1785 | writer := httptest.NewRecorder() |
| 1786 | |
| 1787 | // Invalid json: attribute name without quotes (should be "cause":). |
| 1788 | b := strings.NewReader("{cause:\"protocol:transfer-syntax-error\"") |
| 1789 | req, _ := http.NewRequest("PUT", "https://localhost:3800/nodeb-reset", b) |
| 1790 | req = mux.SetURLVars(req, map[string]string{"ranName": ranName}) |
| 1791 | |
| 1792 | controller.X2Reset(writer, req) |
| 1793 | assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode) |
| 1794 | |
| 1795 | } |
| 1796 | |
Timo Tietavainen | 0234dab | 2020-11-19 09:04:22 +0200 | [diff] [blame] | 1797 | /* |
| 1798 | func TestControllerHealthCheckRequestSuccess(t *testing.T) { |
| 1799 | controller, readerMock, _, rmrMessengerMock, _, _ := setupControllerTest(t) |
| 1800 | |
| 1801 | ranName := "test1" |
| 1802 | // o&m intervention |
| 1803 | payload := []byte{0x00, 0x07, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x05, 0x40, 0x01, 0x64} |
| 1804 | var xAction []byte |
| 1805 | var msgSrc unsafe.Pointer |
| 1806 | msg := rmrCgo.NewMBuf(rmrCgo.RIC_X2_RESET, len(payload), ranName, &payload, &xAction, msgSrc) |
| 1807 | rmrMessengerMock.On("SendMsg", msg, true).Return(msg, nil) |
| 1808 | |
| 1809 | writer := httptest.NewRecorder() |
| 1810 | |
| 1811 | var nodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED} |
| 1812 | readerMock.On("GetNodeb", ranName).Return(nodeb, nil) |
| 1813 | |
| 1814 | data4Req := map[string]interface{}{"ranList": []string{"abcd"}} |
| 1815 | b := new(bytes.Buffer) |
| 1816 | _ = json.NewEncoder(b).Encode(data4Req) |
| 1817 | req, _ := http.NewRequest("PUT", "https://localhost:3800/v1/nodeb/health", b) |
| 1818 | req = mux.SetURLVars(req, map[string]string{"ranName": ranName}) |
| 1819 | |
| 1820 | controller.HealthCheckRequest(writer, req) |
| 1821 | assert.Equal(t, http.StatusNoContent, writer.Result().StatusCode) |
| 1822 | } |
| 1823 | */ |
| 1824 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1825 | func TestHandleErrorResponse(t *testing.T) { |
Irina | a590417 | 2020-07-16 21:21:51 +0300 | [diff] [blame] | 1826 | controller, _, _, _, _, _ := setupControllerTest(t) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1827 | |
| 1828 | writer := httptest.NewRecorder() |
| 1829 | controller.handleErrorResponse(e2managererrors.NewRnibDbError(), writer) |
| 1830 | assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode) |
| 1831 | |
| 1832 | writer = httptest.NewRecorder() |
| 1833 | controller.handleErrorResponse(e2managererrors.NewCommandAlreadyInProgressError(), writer) |
| 1834 | assert.Equal(t, http.StatusMethodNotAllowed, writer.Result().StatusCode) |
| 1835 | |
| 1836 | writer = httptest.NewRecorder() |
| 1837 | controller.handleErrorResponse(e2managererrors.NewHeaderValidationError(), writer) |
| 1838 | assert.Equal(t, http.StatusUnsupportedMediaType, writer.Result().StatusCode) |
| 1839 | |
| 1840 | writer = httptest.NewRecorder() |
| 1841 | controller.handleErrorResponse(e2managererrors.NewWrongStateError("", ""), writer) |
| 1842 | assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode) |
| 1843 | |
| 1844 | writer = httptest.NewRecorder() |
| 1845 | controller.handleErrorResponse(e2managererrors.NewRequestValidationError(), writer) |
| 1846 | assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode) |
| 1847 | |
| 1848 | writer = httptest.NewRecorder() |
| 1849 | controller.handleErrorResponse(e2managererrors.NewRmrError(), writer) |
| 1850 | assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode) |
| 1851 | |
| 1852 | writer = httptest.NewRecorder() |
Rahul Banerji | fe8d481 | 2020-08-24 14:26:41 +0530 | [diff] [blame] | 1853 | controller.handleErrorResponse(e2managererrors.NewNoConnectedRanError(), writer) |
| 1854 | assert.Equal(t, http.StatusNotFound, writer.Result().StatusCode) |
| 1855 | |
| 1856 | writer = httptest.NewRecorder() |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1857 | controller.handleErrorResponse(e2managererrors.NewResourceNotFoundError(), writer) |
| 1858 | assert.Equal(t, http.StatusNotFound, writer.Result().StatusCode) |
| 1859 | |
| 1860 | writer = httptest.NewRecorder() |
| 1861 | controller.handleErrorResponse(fmt.Errorf("ErrorError"), writer) |
| 1862 | assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode) |
| 1863 | } |
| 1864 | |
| 1865 | func getRmrSender(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *rmrsender.RmrSender { |
| 1866 | rmrMessenger := rmrCgo.RmrMessenger(rmrMessengerMock) |
| 1867 | rmrMessengerMock.On("Init", tests.GetPort(), tests.MaxMsgSize, tests.Flags, log).Return(&rmrMessenger) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 1868 | return rmrsender.NewRmrSender(log, rmrMessenger) |
is005q | ffd085d | 2019-09-10 15:56:48 +0300 | [diff] [blame] | 1869 | } |
Timo Tietavainen | 0234dab | 2020-11-19 09:04:22 +0200 | [diff] [blame] | 1870 | |
| 1871 | type errReader int |
| 1872 | |
| 1873 | func (errReader) Read(p []byte) (n int, err error) { |
| 1874 | return 0, errors.New("test error") |
| 1875 | } |