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 rmrmsghandlers
28 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
29 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
30 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
35 func initX2ResetResponseHandlerTest(t *testing.T) (*logger.Logger, X2ResetResponseHandler, *mocks.RnibReaderMock) {
36 log, err := logger.InitLogger(logger.DebugLevel)
37 config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3}
39 t.Errorf("#sctp_errors_notification_handler_test.TestHandleInSession - failed to initialize logger, error: %s", err)
41 readerMock :=&mocks.RnibReaderMock{}
42 rnibReaderProvider := func() reader.RNibReader {
45 rnibDataService := services.NewRnibDataService(log, config, rnibReaderProvider, nil)
47 h := NewX2ResetResponseHandler(rnibDataService)
48 return log, h, readerMock
51 func TestX2ResetResponseSuccess(t *testing.T) {
52 log, h, readerMock := initX2ResetResponseHandlerTest(t)
54 payload, err := tests.BuildPackedX2ResetResponse()
56 t.Errorf("#x2_reset_response_handler_test.TestX2resetResponse - failed to build and pack X2ResetResponse. Error %x", err)
59 xaction := []byte("RanName")
60 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
61 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
62 StartTime: time.Now(), TransactionId: string(xaction)}
63 var messageChannel chan<- *models.NotificationResponse
65 nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_CONNECTED_SETUP_FAILED,}
67 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
69 h.Handle(log, ¬ificationRequest, messageChannel)
71 //TODO:Nothing to verify
74 func TestX2ResetResponseReaderFailure(t *testing.T) {
75 log, h, readerMock := initX2ResetResponseHandlerTest(t)
78 xaction := []byte("RanName")
79 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
80 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
81 StartTime: time.Now(), TransactionId: string(xaction)}
82 var messageChannel chan<- *models.NotificationResponse
84 var nb *entities.NodebInfo
85 rnibErr := common.NewResourceNotFoundError("nodeb not found")
86 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
88 h.Handle(log, ¬ificationRequest, messageChannel)
90 //TODO:Nothing to verify
93 func TestX2ResetResponseUnpackFailure(t *testing.T) {
94 log, h, readerMock := initX2ResetResponseHandlerTest(t)
96 payload := []byte("not valid payload")
97 xaction := []byte("RanName")
98 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
99 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
100 StartTime: time.Now(), TransactionId: string(xaction)}
101 var messageChannel chan<- *models.NotificationResponse
103 nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_CONNECTED_SETUP_FAILED,}
105 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
107 h.Handle(log, ¬ificationRequest, messageChannel)
109 //TODO:Nothing to verify