[RIC-251, RIC-247] New Rest API - Get NodeB Health Check | Fixed HealthCheckRequest...
[ric-plt/e2mgr.git] / E2Manager / handlers / httpmsghandlers / get_nodeb_id_request_handler_test.go
1 //
2 // Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
3 //
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
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 //  platform project (RICP).
19
20 package httpmsghandlers
21
22 import (
23         "e2mgr/mocks"
24         "e2mgr/models"
25         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
26         "github.com/stretchr/testify/assert"
27         "e2mgr/e2managererrors"
28         "testing"
29 )
30
31 func setupGetNodebIdRequestHandlerTest(t *testing.T) (*GetNodebIdRequestHandler, *mocks.RanListManagerMock) {
32         log := initLog(t)
33         ranListManagerMock := &mocks.RanListManagerMock{}
34
35         handler := NewGetNodebIdRequestHandler(log, ranListManagerMock)
36         return handler, ranListManagerMock
37 }
38
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,
46         }
47         ranListManagerMock.On("GetNbIdentity",nbIdentity.InventoryName).Return(nbIdentity, nil)
48         response, err := handler.Handle(models.GetNodebIdRequest{RanName: nbIdentity.InventoryName})
49
50         assert.Nil(t, err)
51         assert.NotNil(t, response)
52         assert.IsType(t, &models.NodebIdResponse{}, response)
53 }
54
55 func TestHandleGetNodebIdNotFoundFailure(t *testing.T) {
56         handler, ranListManagerMock := setupGetNodebIdRequestHandlerTest(t)
57         nbIdentity := &entities.NbIdentity{
58                 InventoryName:    "test",
59         }
60
61         ranListManagerMock.On("GetNbIdentity",nbIdentity.InventoryName).Return(nbIdentity, e2managererrors.NewResourceNotFoundError())
62         _, err := handler.Handle(models.GetNodebIdRequest{RanName: nbIdentity.InventoryName})
63
64         assert.NotNil(t, err)
65         assert.IsType(t, &e2managererrors.ResourceNotFoundError{}, err)
66 }