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.
24 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
33 * Verify support for known providers.
36 func TestGetNotificationHandlerSuccess(t *testing.T) {
37 readerMock :=&mocks.RnibReaderMock{}
38 rnibReaderProvider := func() reader.RNibReader {
41 writerMock := &mocks.RnibWriterMock{}
42 rnibWriterProvider := func() rNibWriter.RNibWriter {
45 var testCases = []struct {
47 handler handlers.NotificationHandler
49 {rmrCgo.RIC_X2_SETUP_RESP /*successful x2 setup response*/, handlers.X2SetupResponseNotificationHandler{}},
50 {rmrCgo.RIC_X2_SETUP_FAILURE /*unsuccessful x2 setup response*/, handlers.X2SetupFailureResponseNotificationHandler{}},
51 {rmrCgo.RIC_ENDC_X2_SETUP_RESP /*successful en-dc x2 setup response*/,handlers.EndcX2SetupResponseNotificationHandler{}},
52 {rmrCgo.RIC_ENDC_X2_SETUP_FAILURE /*unsuccessful en-dc x2 setup response*/,handlers.EndcX2SetupFailureResponseNotificationHandler{}},
53 {rmrCgo.RIC_SCTP_CONNECTION_FAILURE /*sctp errors*/, handlers.NewRanLostConnectionHandler(rnibReaderProvider, rnibWriterProvider)},
54 {rmrCgo.RIC_ENB_LOAD_INFORMATION, handlers.RicEnbLoadInformationNotificationHandler{}},
55 {rmrCgo.RIC_ENB_CONF_UPDATE, handlers.X2EnbConfigurationUpdateHandler{}},
56 {rmrCgo.RIC_ENDC_CONF_UPDATE, handlers.EndcConfigurationUpdateHandler{}},
58 for _, tc := range testCases {
60 provider := NewNotificationHandlerProvider(rnibReaderProvider, rnibWriterProvider)
61 t.Run(fmt.Sprintf("%d", tc.msgType), func(t *testing.T) {
62 handler, err := provider.GetNotificationHandler(tc.msgType)
64 t.Errorf("want: handler for message type %d, got: error %s", tc.msgType, err)
66 //Note struct is empty, so it will match any other empty struct.
67 // 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.
68 if /*handler != tc.handler &&*/ strings.Compare(fmt.Sprintf("%T", handler), fmt.Sprintf("%T", tc.handler)) != 0 {
69 t.Errorf("want: handler %T for message type %d, got: %T", tc.handler,tc.msgType, handler)
76 * Verify handling of a request for an unsupported message.
79 func TestGetNotificationHandlerFailure(t *testing.T) {
80 var testCases = []struct {
84 {9999 /*unknown*/, "notification handler not found"},
86 for _, tc := range testCases {
87 readerMock :=&mocks.RnibReaderMock{}
88 rnibReaderProvider := func() reader.RNibReader {
91 writerMock := &mocks.RnibWriterMock{}
92 rnibWriterProvider := func() rNibWriter.RNibWriter {
95 provider := NewNotificationHandlerProvider(rnibReaderProvider, rnibWriterProvider)
96 t.Run(fmt.Sprintf("%d", tc.msgType), func(t *testing.T) {
97 _, err := provider.GetNotificationHandler(tc.msgType)
99 t.Errorf("want: no handler for message type %d, got: success", tc.msgType)
101 if !strings.Contains(fmt.Sprintf("%s", err), tc.errorText) {
102 t.Errorf("want: error [%s] for message type %d, got: %s", tc.errorText, tc.msgType, err)