2 // Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
20 package httpmsghandlers
25 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
26 "github.com/stretchr/testify/assert"
27 "e2mgr/e2managererrors"
31 func setupGetNodebIdRequestHandlerTest(t *testing.T) (*GetNodebIdRequestHandler, *mocks.RanListManagerMock) {
33 ranListManagerMock := &mocks.RanListManagerMock{}
35 handler := NewGetNodebIdRequestHandler(log, ranListManagerMock)
36 return handler, ranListManagerMock
39 func TestHandleGetNodebIdSuccess(t *testing.T) {
40 handler, ranListManagerMock := setupGetNodebIdRequestHandlerTest(t)
41 nbIdentity := &entities.NbIdentity{
42 InventoryName: "test",
43 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
44 HealthCheckTimestampSent: 12345678,
45 HealthCheckTimestampReceived: 12346548,
47 ranListManagerMock.On("GetNbIdentity",nbIdentity.InventoryName).Return(nbIdentity, nil)
48 response, err := handler.Handle(models.GetNodebIdRequest{RanName: nbIdentity.InventoryName})
51 assert.NotNil(t, response)
52 assert.IsType(t, &models.NodebIdResponse{}, response)
55 func TestHandleGetNodebIdNotFoundFailure(t *testing.T) {
56 handler, ranListManagerMock := setupGetNodebIdRequestHandlerTest(t)
57 nbIdentity := &entities.NbIdentity{
58 InventoryName: "test",
61 ranListManagerMock.On("GetNbIdentity",nbIdentity.InventoryName).Return(nbIdentity, e2managererrors.NewResourceNotFoundError())
62 _, err := handler.Handle(models.GetNodebIdRequest{RanName: nbIdentity.InventoryName})
65 assert.IsType(t, &e2managererrors.ResourceNotFoundError{}, err)