X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fhandlers%2Frmrmsghandlers%2Fendc_configuration_update_handler_test.go;h=1c2afe9bd731c79d00320a09a4799c66d8b87279;hb=efcb4528362460aa2249d319c9752b63bb720fe2;hp=90059248b80ab6813f87e78353b686498e649855;hpb=ffd085dd7f0654b84b163a7bfedd3fa89e7b8a71;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler_test.go b/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler_test.go index 9005924..1c2afe9 100644 --- a/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler_test.go @@ -13,56 +13,63 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -// + +// This source code is part of the near-RT RIC (RAN Intelligent Controller) +// platform project (RICP). + package rmrmsghandlers import ( - "e2mgr/logger" + "e2mgr/mocks" "e2mgr/models" "e2mgr/rmrCgo" - "e2mgr/tests" - "github.com/stretchr/testify/assert" + "fmt" "testing" "time" ) -func TestHandleSuccessEndcConfigUpdate(t *testing.T) { - /* log, err := logger.InitLogger(logger.InfoLevel) - if err!=nil{ - t.Errorf("#endc_configuration_update_handler_test.TestHandleSuccessEndcConfigUpdate - failed to initialize logger, error: %s", err) - } - h := EndcConfigurationUpdateHandler{} +const PackedEndcConfigurationUpdateAck = "2025000a00000100f70003000000" +const PackedEndcConfigurationUpdateFailure = "402500080000010005400142" - payload := tests.GetPackedPayload(t) - mBuf := rmrCgo.NewMBuf(10370, len(payload),"RanName", &payload, &tests.DummyXAction) - notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now()} - messageChannel := make(chan *models.NotificationResponse) +func initEndcConfigurationUpdateHandlerTest(t *testing.T) (EndcConfigurationUpdateHandler, *mocks.RmrMessengerMock) { + log := initLog(t) + rmrMessengerMock := &mocks.RmrMessengerMock{} + rmrSender := initRmrSender(rmrMessengerMock, log) + h := NewEndcConfigurationUpdateHandler(log, rmrSender) + return h, rmrMessengerMock +} - go h.Handle(log, ¬ificationRequest, messageChannel) +func TestHandleEndcConfigUpdateSuccess(t *testing.T) { + h, rmrMessengerMock := initEndcConfigurationUpdateHandlerTest(t) - response := <-messageChannel + ranName := "test" + xAction := []byte("123456aa") - assert.NotEmpty(t, response) - assert.EqualValues(t, 10371, response.MgsType) - assert.True(t, len(response.Payload) > 0)*/ -} + var payload []byte + _, _ = fmt.Sscanf(PackedEndcConfigurationUpdateAck, "%x", &payload) -func TestHandleFailureEndcConfigUpdate(t *testing.T) { - log, err := logger.InitLogger(logger.InfoLevel) - if err != nil { - t.Errorf("#endc_configuration_update_handler_test.TestHandleFailureEndcConfigUpdate - failed to initialize logger, error: %s", err) - } - h := EndcConfigurationUpdateHandler{} + mBuf := rmrCgo.NewMBuf(rmrCgo.RIC_ENDC_CONF_UPDATE_ACK, len(payload), ranName, &payload, &xAction) + notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now(), + TransactionId: *mBuf.XAction} + var err error + rmrMessengerMock.On("SendMsg", mBuf, true).Return(&rmrCgo.MBuf{}, err) + h.Handle(¬ificationRequest) + rmrMessengerMock.AssertCalled(t, "SendMsg", mBuf, true) +} - mBuf := rmrCgo.NewMBuf(tests.MessageType, 4, "RanName", &tests.DummyPayload, &tests.DummyXAction) - notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now()} - messageChannel := make(chan *models.NotificationResponse) +func TestHandleEndcConfigUpdateFailure(t *testing.T) { + h, rmrMessengerMock := initEndcConfigurationUpdateHandlerTest(t) - go h.Handle(log, ¬ificationRequest, messageChannel) + ranName := "test" + xAction := []byte("123456aa") - response := <-messageChannel + var payload []byte + _, _ = fmt.Sscanf(PackedEndcConfigurationUpdateFailure, "%x", &payload) - assert.NotEmpty(t, response) - assert.EqualValues(t, 10372, response.MgsType) - assert.True(t, len(response.Payload) > 0) + mBuf := rmrCgo.NewMBuf(rmrCgo.RIC_ENDC_CONF_UPDATE_FAILURE, len(payload), ranName, &payload, &xAction) + notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: 0, Payload: []byte{0}, StartTime: time.Now(), + TransactionId: *mBuf.XAction} + rmrMessengerMock.On("SendMsg", mBuf, true).Return(&rmrCgo.MBuf{}, fmt.Errorf("send failure")) + h.Handle(¬ificationRequest) + rmrMessengerMock.AssertCalled(t, "SendMsg", mBuf, true) }