Handling e2 reset request & change status to reset
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / e2_reset_request_handler_test.go
1 //\r
2 // Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.\r
3 //\r
4 // Licensed under the Apache License, Version 2.0 (the "License");\r
5 // you may not use this file except in compliance with the License.\r
6 // You may obtain a copy of the License at\r
7 //\r
8 //      http://www.apache.org/licenses/LICENSE-2.0\r
9 //\r
10 // Unless required by applicable law or agreed to in writing, software\r
11 // distributed under the License is distributed on an "AS IS" BASIS,\r
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 // See the License for the specific language governing permissions and\r
14 // limitations under the License.\r
15 \r
16 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)\r
17 //  platform project (RICP).\r
18 \r
19 package rmrmsghandlers\r
20 \r
21 import (\r
22         "e2mgr/configuration"\r
23         "e2mgr/mocks"\r
24         "e2mgr/models"\r
25         "e2mgr/services"\r
26         "e2mgr/tests"\r
27         "e2mgr/utils"\r
28         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"\r
29         "github.com/stretchr/testify/mock"\r
30         "testing"\r
31 )\r
32 \r
33 const (\r
34         E2ResetXmlPath = "../../tests/resources/reset/reset-request.xml"\r
35 )\r
36 \r
37 func initE2ResetMocks(t *testing.T) (*E2ResetRequestNotificationHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock) {\r
38         logger := tests.InitLog(t)\r
39         config := &configuration.Configuration{\r
40                 RnibRetryIntervalMs:       10,\r
41                 MaxRnibConnectionAttempts: 3,\r
42                 RnibWriter: configuration.RnibWriterConfig{\r
43                         StateChangeMessageChannel: StateChangeMessageChannel,\r
44                 }}\r
45         readerMock := &mocks.RnibReaderMock{}\r
46         writerMock := &mocks.RnibWriterMock{}\r
47         rnibDataService := services.NewRnibDataService(logger, config, readerMock, writerMock)\r
48         handler := NewE2ResetRequestNotificationHandler(logger, rnibDataService)\r
49         return handler, readerMock, writerMock\r
50 }\r
51 \r
52 func TestE2ResetRequestHandler(t *testing.T) {\r
53         e2ResetXml := utils.ReadXmlFile(t, E2ResetXmlPath)\r
54         handler, readerMock, writerMock := initE2ResetMocks(t)\r
55         var nodebInfo = &entities.NodebInfo{\r
56                 RanName:                      gnbNodebRanName,\r
57                 AssociatedE2TInstanceAddress: e2tInstanceFullAddress,\r
58                 ConnectionStatus:             entities.ConnectionStatus_DISCONNECTED,\r
59                 NodeType:                     entities.Node_GNB,\r
60                 Configuration: &entities.NodebInfo_Gnb{\r
61                         Gnb: &entities.Gnb{},\r
62                 },\r
63         }\r
64         readerMock.On("GetNodeb", gnbNodebRanName).Return(nodebInfo, nil)\r
65         writerMock.On("UpdateNodebInfoAndPublish", mock.Anything).Return(nil)\r
66         notificationRequest := &models.NotificationRequest{RanName: gnbNodebRanName, Payload: append([]byte(""), e2ResetXml...)}\r
67         handler.Handle(notificationRequest)\r
68         readerMock.AssertExpectations(t)\r
69         writerMock.AssertExpectations(t)\r
70 }\r