Handling e2 reset request & change status to reset
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / e2_reset_request_handler_test.go
diff --git a/E2Manager/handlers/rmrmsghandlers/e2_reset_request_handler_test.go b/E2Manager/handlers/rmrmsghandlers/e2_reset_request_handler_test.go
new file mode 100644 (file)
index 0000000..8b15865
--- /dev/null
@@ -0,0 +1,70 @@
+//\r
+// Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+//  This source code is part of the near-RT RIC (RAN Intelligent Controller)\r
+//  platform project (RICP).\r
+\r
+package rmrmsghandlers\r
+\r
+import (\r
+       "e2mgr/configuration"\r
+       "e2mgr/mocks"\r
+       "e2mgr/models"\r
+       "e2mgr/services"\r
+       "e2mgr/tests"\r
+       "e2mgr/utils"\r
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"\r
+       "github.com/stretchr/testify/mock"\r
+       "testing"\r
+)\r
+\r
+const (\r
+       E2ResetXmlPath = "../../tests/resources/reset/reset-request.xml"\r
+)\r
+\r
+func initE2ResetMocks(t *testing.T) (*E2ResetRequestNotificationHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock) {\r
+       logger := tests.InitLog(t)\r
+       config := &configuration.Configuration{\r
+               RnibRetryIntervalMs:       10,\r
+               MaxRnibConnectionAttempts: 3,\r
+               RnibWriter: configuration.RnibWriterConfig{\r
+                       StateChangeMessageChannel: StateChangeMessageChannel,\r
+               }}\r
+       readerMock := &mocks.RnibReaderMock{}\r
+       writerMock := &mocks.RnibWriterMock{}\r
+       rnibDataService := services.NewRnibDataService(logger, config, readerMock, writerMock)\r
+       handler := NewE2ResetRequestNotificationHandler(logger, rnibDataService)\r
+       return handler, readerMock, writerMock\r
+}\r
+\r
+func TestE2ResetRequestHandler(t *testing.T) {\r
+       e2ResetXml := utils.ReadXmlFile(t, E2ResetXmlPath)\r
+       handler, readerMock, writerMock := initE2ResetMocks(t)\r
+       var nodebInfo = &entities.NodebInfo{\r
+               RanName:                      gnbNodebRanName,\r
+               AssociatedE2TInstanceAddress: e2tInstanceFullAddress,\r
+               ConnectionStatus:             entities.ConnectionStatus_DISCONNECTED,\r
+               NodeType:                     entities.Node_GNB,\r
+               Configuration: &entities.NodebInfo_Gnb{\r
+                       Gnb: &entities.Gnb{},\r
+               },\r
+       }\r
+       readerMock.On("GetNodeb", gnbNodebRanName).Return(nodebInfo, nil)\r
+       writerMock.On("UpdateNodebInfoAndPublish", mock.Anything).Return(nil)\r
+       notificationRequest := &models.NotificationRequest{RanName: gnbNodebRanName, Payload: append([]byte(""), e2ResetXml...)}\r
+       handler.Handle(notificationRequest)\r
+       readerMock.AssertExpectations(t)\r
+       writerMock.AssertExpectations(t)\r
+}\r