2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 package rmrmsghandlerprovider
22 "e2mgr/handlers/rmrmsghandlers"
31 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
39 * Verify support for known providers.
42 func initTestCase(t *testing.T) (services.RNibDataService, *managers.RanReconnectionManager) {
44 config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3}
46 readerMock := &mocks.RnibReaderMock{}
47 rnibReaderProvider := func() reader.RNibReader {
50 writerMock := &mocks.RnibWriterMock{}
51 rnibWriterProvider := func() rNibWriter.RNibWriter {
54 rnibDataService := services.NewRnibDataService(logger, config, rnibReaderProvider, rnibWriterProvider)
55 ranSetupManager := managers.NewRanSetupManager(logger, getRmrService(&mocks.RmrMessengerMock{}, logger), rnibDataService)
56 ranReconnectionManager := managers.NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, ranSetupManager)
57 return rnibDataService, ranReconnectionManager
60 func TestGetNotificationHandlerSuccess(t *testing.T) {
62 rnibDataService, ranReconnectionManager := initTestCase(t)
64 var testCases = []struct {
66 handler rmrmsghandlers.NotificationHandler
68 {rmrCgo.RIC_X2_SETUP_RESP, rmrmsghandlers.NewSetupResponseNotificationHandler(rnibDataService, managers.NewX2SetupResponseManager(), "X2 Setup Response")},
69 {rmrCgo.RIC_X2_SETUP_FAILURE, rmrmsghandlers.NewSetupResponseNotificationHandler(rnibDataService, managers.NewX2SetupFailureResponseManager(), "X2 Setup Failure Response")},
70 {rmrCgo.RIC_ENDC_X2_SETUP_RESP, rmrmsghandlers.NewSetupResponseNotificationHandler(rnibDataService, managers.NewEndcSetupResponseManager(), "ENDC Setup Response")},
71 {rmrCgo.RIC_ENDC_X2_SETUP_FAILURE, rmrmsghandlers.NewSetupResponseNotificationHandler(rnibDataService, managers.NewEndcSetupFailureResponseManager(), "ENDC Setup Failure Response"),},
72 {rmrCgo.RIC_SCTP_CONNECTION_FAILURE, rmrmsghandlers.NewRanLostConnectionHandler(ranReconnectionManager)},
73 {rmrCgo.RIC_ENB_LOAD_INFORMATION, rmrmsghandlers.NewEnbLoadInformationNotificationHandler(rnibDataService)},
74 {rmrCgo.RIC_ENB_CONF_UPDATE, rmrmsghandlers.X2EnbConfigurationUpdateHandler{}},
75 {rmrCgo.RIC_ENDC_CONF_UPDATE, rmrmsghandlers.EndcConfigurationUpdateHandler{}},
76 {rmrCgo.RIC_E2_TERM_INIT, rmrmsghandlers.NewE2TermInitNotificationHandler(ranReconnectionManager, rnibDataService)},
79 for _, tc := range testCases {
81 provider := NewNotificationHandlerProvider(rnibDataService, ranReconnectionManager)
82 t.Run(fmt.Sprintf("%d", tc.msgType), func(t *testing.T) {
83 handler, err := provider.GetNotificationHandler(tc.msgType)
85 t.Errorf("want: handler for message type %d, got: error %s", tc.msgType, err)
87 //Note struct is empty, so it will match any other empty struct.
88 // https://golang.org/ref/spec#Comparison_operators: Struct values are comparable if all their fields are comparable. Two struct values are equal if their corresponding non-blank fields are equal.
89 if /*handler != tc.handler &&*/ strings.Compare(fmt.Sprintf("%T", handler), fmt.Sprintf("%T", tc.handler)) != 0 {
90 t.Errorf("want: handler %T for message type %d, got: %T", tc.handler, tc.msgType, handler)
97 * Verify handling of a request for an unsupported message.
100 func TestGetNotificationHandlerFailure(t *testing.T) {
102 var testCases = []struct {
106 {9999 /*unknown*/, "notification handler not found"},
108 for _, tc := range testCases {
110 rnibDataService, ranReconnectionManager := initTestCase(t)
111 provider := NewNotificationHandlerProvider(rnibDataService, ranReconnectionManager)
112 t.Run(fmt.Sprintf("%d", tc.msgType), func(t *testing.T) {
113 _, err := provider.GetNotificationHandler(tc.msgType)
115 t.Errorf("want: no handler for message type %d, got: success", tc.msgType)
117 if !strings.Contains(fmt.Sprintf("%s", err), tc.errorText) {
118 t.Errorf("want: error [%s] for message type %d, got: %s", tc.errorText, tc.msgType, err)
124 // TODO: extract to test_utils
125 func getRmrService(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *services.RmrService {
126 rmrMessenger := rmrCgo.RmrMessenger(rmrMessengerMock)
127 messageChannel := make(chan *models.NotificationResponse)
128 rmrMessengerMock.On("Init", tests.GetPort(), tests.MaxMsgSize, tests.Flags, log).Return(&rmrMessenger)
129 return services.NewRmrService(services.NewRmrConfig(tests.Port, tests.MaxMsgSize, tests.Flags, log), rmrMessenger, messageChannel)
132 // TODO: extract to test_utils
133 func initLog(t *testing.T) *logger.Logger {
134 log, err := logger.InitLogger(logger.InfoLevel)
136 t.Errorf("#delete_all_request_handler_test.TestHandleSuccessFlow - failed to initialize logger, error: %s", err)