Copy latest code
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / endc_configuration_update_handler_test.go
index 9005924..1c2afe9 100644 (file)
 // 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, &notificationRequest, 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(&notificationRequest)
+       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, &notificationRequest, 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(&notificationRequest)
+       rmrMessengerMock.AssertCalled(t, "SendMsg", mBuf, true)
 }