b19e46e73e572d043b5dd919a7e2ec5b841cb01c
[ric-plt/e2mgr.git] / E2Manager / managers / ric_service_update_manager_test.go
1 //
2 // Copyright 2023 Nokia
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 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
17 //  platform project (RICP).
18
19 package managers
20
21
22 import (
23         "e2mgr/configuration"
24         "e2mgr/logger"
25         "e2mgr/mocks"
26         
27         "e2mgr/services"
28         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
29         "testing"
30         "github.com/stretchr/testify/assert"
31         "e2mgr/tests"
32         "github.com/stretchr/testify/mock"
33 )
34
35 const (
36         serviceUpdateRANName1 = "gnb:TestRan1"
37     E2tAddress = "10.10.2.15:9800"
38 )
39
40
41 func initRicServiceUpdateManagerTest(t *testing.T) (*logger.Logger,*mocks.RnibReaderMock, *mocks.RnibWriterMock,services.RNibDataService, *configuration.Configuration, *RicServiceUpdateManager) {
42         logger := tests.InitLog(t)
43
44         config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3}
45         readerMock := &mocks.RnibReaderMock{}
46         writerMock := &mocks.RnibWriterMock{}
47         rnibDataService := services.NewRnibDataService(logger, config, readerMock, writerMock)
48         RicServiceUpdateManager := NewRicServiceUpdateManager(logger, rnibDataService)
49         return logger, readerMock, writerMock, rnibDataService, config, RicServiceUpdateManager
50 }
51 func TestUpdateRevertRanFunctions(t *testing.T) {
52
53         _,readerMock, writerMock, _, _, RicServiceUpdateManager := initRicServiceUpdateManagerTest(t)
54         InvName := "test"
55         nodebInfo := &entities.NodebInfo{
56                 RanName: InvName,
57                 NodeType:                     entities.Node_GNB,
58                 Configuration:                &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{}},
59         }
60         gnb := nodebInfo.GetGnb()
61         gnb.RanFunctions = []*entities.RanFunction{{RanFunctionId: 2, RanFunctionRevision: 2}}
62         readerMock.On("GetNodeb", InvName).Return(nodebInfo, nil)
63         writerMock.On("UpdateNodebInfoAndPublish", mock.Anything).Return(nil)
64         err := RicServiceUpdateManager.StoreExistingRanFunctions(ranName)
65         assert.Nil(t, err)
66         err = RicServiceUpdateManager.RevertRanFunctions(ranName)
67         assert.Nil(t, err)
68         writerMock.AssertExpectations(t)
69         readerMock.AssertExpectations(t)
70         readerMock.AssertCalled(t, "GetNodeb", InvName)
71 }