X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fhandlers%2Frmrmsghandlers%2Fe2_setup_request_notification_handler_test.go;h=137464b2c54393ce94442644a797cdb6ae00e9db;hb=refs%2Fchanges%2F76%2F4376%2F1;hp=1d878098d4081a18fd333e91cf3e6b64b1a34711;hpb=ca265f6ea96500b9a01e2b13e76b162a4c557297;p=ric-plt%2Fe2mgr.git
diff --git a/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler_test.go b/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler_test.go
index 1d87809..137464b 100644
--- a/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler_test.go
+++ b/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler_test.go
@@ -22,58 +22,93 @@ package rmrmsghandlers
import (
"bytes"
"e2mgr/configuration"
- "e2mgr/logger"
"e2mgr/managers"
"e2mgr/mocks"
"e2mgr/models"
"e2mgr/rmrCgo"
"e2mgr/services"
"e2mgr/tests"
+ "encoding/xml"
"errors"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
- "io"
"io/ioutil"
- "os"
"path/filepath"
"testing"
)
const (
- prefix = "10.0.2.15:9999|"
- logFilePath = "./loggerTest.txt"
- e2tInstanceFullAddress = "10.0.2.15:9999"
- nodebRanName = "gnb:310-410-b5c67788"
+ e2tInstanceFullAddress = "10.0.2.15:9999"
+ e2SetupMsgPrefix = e2tInstanceFullAddress + "|"
+ nodebRanName = "gnb:310-410-b5c67788"
+ GnbSetupRequestXmlPath = "../../tests/resources/setupRequest_gnb.xml"
+ EnGnbSetupRequestXmlPath = "../../tests/resources/setupRequest_en-gNB.xml"
+ NgEnbSetupRequestXmlPath = "../../tests/resources/setupRequest_ng-eNB.xml"
+ EnbSetupRequestXmlPath = "../../tests/resources/setupRequest_enb.xml"
+ GnbWithoutFunctionsSetupRequestXmlPath = "../../tests/resources/setupRequest_gnb_without_functions.xml"
+ E2SetupFailureResponseWithMiscCause = "1131"
+ E2SetupFailureResponseWithTransportCause = "1131"
+ StateChangeMessageChannel = "RAN_CONNECTION_STATUS_CHANGE"
)
-func TestParseSetupRequest_Success(t *testing.T){
- path, err :=filepath.Abs("../../tests/resources/setupRequest_gnb.xml")
+func readXmlFile(t *testing.T, xmlPath string) []byte {
+ path, err := filepath.Abs(xmlPath)
if err != nil {
t.Fatal(err)
}
- xmlGnb, err := ioutil.ReadFile(path)
+ xmlAsBytes, err := ioutil.ReadFile(path)
if err != nil {
t.Fatal(err)
}
- handler := stubMockSuccessFlowNewNodeb(t)
- prefBytes := []byte(prefix)
- request, _, err := handler.parseSetupRequest(append(prefBytes, xmlGnb...))
- assert.Equal(t, request.GetPlmnId(), "131014")
- assert.Equal(t, request.GetNbId(), "10110101110001100111011110001000")
+
+ return xmlAsBytes
}
-func TestParseSetupRequest_PipFailure(t *testing.T){
- path, err :=filepath.Abs("../../tests/resources/setupRequest_gnb.xml")
- if err != nil {
- t.Fatal(err)
- }
- xmlGnb, err := ioutil.ReadFile(path)
- if err != nil {
- t.Fatal(err)
- }
- handler := stubMockSuccessFlowNewNodeb(t)
+func TestParseGnbSetupRequest_Success(t *testing.T) {
+ xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ handler, _, _, _, _, _ := initMocks(t)
+ prefBytes := []byte(e2SetupMsgPrefix)
+ request, _, err := handler.parseSetupRequest(append(prefBytes, xmlGnb...))
+ assert.Equal(t, "02F829", request.GetPlmnId())
+ assert.Equal(t, "001100000011000000110000", request.GetNbId())
+ assert.Nil(t, err)
+}
+
+func TestParseEnGnbSetupRequest_Success(t *testing.T) {
+ enGnbXml := readXmlFile(t, EnGnbSetupRequestXmlPath)
+ handler, _, _, _, _, _ := initMocks(t)
+ prefBytes := []byte(e2SetupMsgPrefix)
+ request, _, err := handler.parseSetupRequest(append(prefBytes, enGnbXml...))
+ assert.Equal(t, "131014", request.GetPlmnId())
+ assert.Equal(t, "11000101110001101100011111111000", request.GetNbId())
+ assert.Nil(t, err)
+}
+
+func TestParseNgEnbSetupRequest_Success(t *testing.T) {
+ ngEnbXml := readXmlFile(t, NgEnbSetupRequestXmlPath)
+ handler, _, _, _, _, _ := initMocks(t)
+ prefBytes := []byte(e2SetupMsgPrefix)
+ request, _, err := handler.parseSetupRequest(append(prefBytes, ngEnbXml...))
+ assert.Equal(t, "131014", request.GetPlmnId())
+ assert.Equal(t, "101010101010101010", request.GetNbId())
+ assert.Nil(t, err)
+}
+
+func TestParseEnbSetupRequest_Success(t *testing.T) {
+ enbXml := readXmlFile(t, EnbSetupRequestXmlPath)
+ handler, _, _, _, _, _ := initMocks(t)
+ prefBytes := []byte(e2SetupMsgPrefix)
+ request, _, err := handler.parseSetupRequest(append(prefBytes, enbXml...))
+ assert.Equal(t, "6359AB", request.GetPlmnId())
+ assert.Equal(t, "101010101010101010", request.GetNbId())
+ assert.Nil(t, err)
+}
+
+func TestParseSetupRequest_PipFailure(t *testing.T) {
+ xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ handler, _, _, _, _, _ := initMocks(t)
prefBytes := []byte("10.0.2.15:9999")
request, _, err := handler.parseSetupRequest(append(prefBytes, xmlGnb...))
assert.Nil(t, request)
@@ -81,479 +116,403 @@ func TestParseSetupRequest_PipFailure(t *testing.T){
assert.EqualError(t, err, "#E2SetupRequestNotificationHandler.parseSetupRequest - Error parsing E2 Setup Request failed extract Payload: no | separator found")
}
-func TestParseSetupRequest_UnmarshalFailure(t *testing.T){
- handler := stubMockSuccessFlowNewNodeb(t)
- prefBytes := []byte(prefix)
- request, _, err := handler.parseSetupRequest(append(prefBytes, 1,2,3))
+func TestParseSetupRequest_UnmarshalFailure(t *testing.T) {
+ handler, _, _, _, _, _ := initMocks(t)
+ prefBytes := []byte(e2SetupMsgPrefix)
+ request, _, err := handler.parseSetupRequest(append(prefBytes, 1, 2, 3))
assert.Nil(t, request)
assert.NotNil(t, err)
assert.EqualError(t, err, "#E2SetupRequestNotificationHandler.parseSetupRequest - Error unmarshalling E2 Setup Request payload: 31302e302e322e31353a393939397c010203")
}
-func TestE2SetupRequestNotificationHandler_HandleNewGnbSuccess(t *testing.T) {
- path, err :=filepath.Abs("../../tests/resources/setupRequest_gnb.xml")
- if err != nil {
- t.Fatal(err)
- }
- xmlGnb, err := ioutil.ReadFile(path)
- if err != nil {
- t.Fatal(err)
- }
-
- logFile, err := os.Create(logFilePath)
- if err != nil{
- t.Errorf("e2_setup_request_notification_handler_test.TestE2SetupRequestNotificationHandler_HandleNewGnbSuccess - failed to create file, error: %s", err)
- }
- oldStdout := os.Stdout
- defer changeStdout(oldStdout)
- defer removeLogFile(t)
- os.Stdout = logFile
-
- handler := stubMockSuccessFlowNewNodeb(t)
- prefBytes := []byte(prefix)
- notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlGnb...)}
+func TestE2SetupRequestNotificationHandler_GetGeneralConfigurationFailure(t *testing.T) {
+ xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{}, common.NewInternalError(errors.New("some error")))
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append([]byte(e2SetupMsgPrefix), xmlGnb...)}
handler.Handle(notificationRequest)
- assertSuccessFlowNewNodebLogs(t)
-}
-
-func TestE2SetupRequestNotificationHandler_HandleNewEnGnbSuccess(t *testing.T) {
- path, err :=filepath.Abs("../../tests/resources/setupRequest_en-gNB.xml")
- if err != nil {
- t.Fatal(err)
- }
- xmlEnGnb, err := ioutil.ReadFile(path)
- if err != nil {
- t.Fatal(err)
- }
- logFile, err := os.Create(logFilePath)
- if err != nil{
- t.Errorf("e2_setup_request_notification_handler_test.TestE2SetupRequestNotificationHandler_HandleNewEnGnbSuccess - failed to create file, error: %s", err)
- }
- oldStdout := os.Stdout
- defer changeStdout(oldStdout)
- defer removeLogFile(t)
- os.Stdout = logFile
-
- handler := stubMockSuccessFlowNewNodeb(t)
- prefBytes := []byte(prefix)
- notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlEnGnb...)}
- handler.Handle(notificationRequest)
- assertSuccessFlowNewNodebLogs(t)
-}
-
-func TestE2SetupRequestNotificationHandler_HandleNewNgEnbSuccess(t *testing.T) {
- path, err :=filepath.Abs("../../tests/resources/setupRequest_ng-eNB.xml")
- if err != nil {
- t.Fatal(err)
- }
- xmlEnGnb, err := ioutil.ReadFile(path)
- if err != nil {
- t.Fatal(err)
- }
- logFile, err := os.Create(logFilePath)
- if err != nil{
- t.Errorf("e2_setup_request_notification_handler_test.TestE2SetupRequestNotificationHandler_HandleNewNgEnbSuccess - failed to create file, error: %s", err)
- }
- oldStdout := os.Stdout
- defer changeStdout(oldStdout)
- defer removeLogFile(t)
- os.Stdout = logFile
-
- handler := stubMockSuccessFlowNewNodeb(t)
- prefBytes := []byte(prefix)
- notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlEnGnb...)}
- handler.Handle(notificationRequest)
- assertSuccessFlowNewNodebLogs(t)
-}
-
-func TestE2SetupRequestNotificationHandler_HandleExistingGnbSuccess(t *testing.T) {
- path, err :=filepath.Abs("../../tests/resources/setupRequest_gnb.xml")
- if err != nil {
- t.Fatal(err)
- }
- xmlGnb, err := ioutil.ReadFile(path)
- if err != nil {
- t.Fatal(err)
- }
-
- logFile, err := os.Create(logFilePath)
- if err != nil{
- t.Errorf("e2_setup_request_notification_handler_test.TestE2SetupRequestNotificationHandler_HandleNewGnbSuccess - failed to create file, error: %s", err)
- }
- oldStdout := os.Stdout
- defer changeStdout(oldStdout)
- defer removeLogFile(t)
- os.Stdout = logFile
-
- handler := stubMockSuccessFlowExistingNodeb(t)
- prefBytes := []byte(prefix)
- notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlGnb...)}
+ rmrMessengerMock.AssertNotCalled(t, "SendMsg")
+ e2tInstancesManagerMock.AssertNotCalled(t, "GetE2TInstance")
+ routingManagerClientMock.AssertNotCalled(t, "AssociateRanToE2TInstance")
+ readerMock.AssertNotCalled(t, "GetNodeb")
+ writerMock.AssertNotCalled(t, "SaveNodeb")
+}
+
+func getMbuf(msgType int, payloadStr string, request *models.NotificationRequest) *rmrCgo.MBuf {
+ payload := []byte(payloadStr)
+ mbuf := rmrCgo.NewMBuf(msgType, len(payload), nodebRanName, &payload, &request.TransactionId, request.GetMsgSrc())
+ return mbuf
+}
+
+func TestE2SetupRequestNotificationHandler_EnableRicFalse(t *testing.T) {
+ xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: false}, nil)
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append([]byte(e2SetupMsgPrefix), xmlGnb...)}
+ mbuf := getMbuf(rmrCgo.RIC_E2_SETUP_FAILURE, E2SetupFailureResponseWithMiscCause, notificationRequest)
+ rmrMessengerMock.On("WhSendMsg", mbuf, true).Return(&rmrCgo.MBuf{}, nil)
handler.Handle(notificationRequest)
- assertSuccessFlowExistingNodebLogs(t)
+ rmrMessengerMock.AssertCalled(t, "WhSendMsg", mbuf, true)
+ e2tInstancesManagerMock.AssertNotCalled(t, "GetE2TInstance")
+ routingManagerClientMock.AssertNotCalled(t, "AssociateRanToE2TInstance")
+ readerMock.AssertNotCalled(t, "GetNodeb")
+ writerMock.AssertNotCalled(t, "SaveNodeb")
}
-func TestE2SetupRequestNotificationHandler_HandleParseError(t *testing.T) {
- path, err :=filepath.Abs("../../tests/resources/setupRequest_gnb.xml")
- if err != nil {
- t.Fatal(err)
- }
- xmlGnb, err := ioutil.ReadFile(path)
- if err != nil {
- t.Fatal(err)
- }
- logFile, err := os.Create(logFilePath)
- if err != nil{
- t.Errorf("e2_setup_request_notification_handler_test.TestE2SetupRequestNotificationHandler_HandleNewGnbSuccess - failed to create file, error: %s", err)
- }
- oldStdout := os.Stdout
- defer changeStdout(oldStdout)
- defer removeLogFile(t)
- os.Stdout = logFile
+func TestE2SetupRequestNotificationHandler_HandleNewRanError(t *testing.T) {
+ xml := readXmlFile(t, GnbSetupRequestXmlPath)
+ handler, readerMock, writerMock, _, e2tInstancesManagerMock, _ := initMocks(t)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
+ e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
+ var gnb *entities.NodebInfo
+ readerMock.On("GetNodeb", nodebRanName).Return(gnb, common.NewResourceNotFoundError("Not found"))
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append([]byte(e2SetupMsgPrefix), xml...)}
+ nodebInfo := getExpectedNodebForNewRan(notificationRequest.Payload)
+ nbIdentity := &entities.NbIdentity{InventoryName: nodebRanName, GlobalNbId: nodebInfo.GlobalNbId}
+ writerMock.On("SaveNodeb", nbIdentity, nodebInfo).Return(common.NewInternalError(errors.New("error")))
- _, handler, _, _, _, _, _ := initMocks(t)
- prefBytes := []byte("invalid_prefix")
- notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlGnb...)}
handler.Handle(notificationRequest)
- assertParseErrorFlowLogs(t)
-}
-func TestE2SetupRequestNotificationHandler_HandleUnmarshalError(t *testing.T) {
- logFile, err := os.Create(logFilePath)
- if err != nil{
- t.Errorf("e2_setup_request_notification_handler_test.TestE2SetupRequestNotificationHandler_HandleNewGnbSuccess - failed to create file, error: %s", err)
- }
- oldStdout := os.Stdout
- defer changeStdout(oldStdout)
- defer removeLogFile(t)
- os.Stdout = logFile
-
- _, handler, _, _, _, _, _ := initMocks(t)
- prefBytes := []byte(prefix)
- notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, "xmlGnb"...)}
- handler.Handle(notificationRequest)
- assertUnmarshalErrorFlowLogs(t)
+ readerMock.AssertExpectations(t)
+ writerMock.AssertExpectations(t)
+ e2tInstancesManagerMock.AssertExpectations(t)
}
-func TestE2SetupRequestNotificationHandler_HandleGetE2TInstanceError(t *testing.T) {
- path, err :=filepath.Abs("../../tests/resources/setupRequest_gnb.xml")
- if err != nil {
- t.Fatal(err)
- }
- xmlGnb, err := ioutil.ReadFile(path)
- if err != nil {
- t.Fatal(err)
- }
+func testE2SetupRequestNotificationHandler_HandleNewRanSuccess(t *testing.T, xmlPath string) {
+ xml := readXmlFile(t, xmlPath)
+ handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
+ e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
+ var gnb *entities.NodebInfo
+ readerMock.On("GetNodeb", nodebRanName).Return(gnb, common.NewResourceNotFoundError("Not found"))
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append([]byte(e2SetupMsgPrefix), xml...)}
+ nodebInfo := getExpectedNodebForNewRan(notificationRequest.Payload)
+ nbIdentity := &entities.NbIdentity{InventoryName: nodebRanName, GlobalNbId: nodebInfo.GlobalNbId}
+ writerMock.On("SaveNodeb", nbIdentity, nodebInfo).Return(nil)
+ updatedNodebInfo := *nodebInfo
+ updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTED
+ writerMock.On("UpdateNodebInfoOnConnectionStatusInversion", &updatedNodebInfo, nodebRanName+"_CONNECTED").Return(nil)
+ routingManagerClientMock.On("AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything).Return(nil)
+ updatedNodebInfo2 := *nodebInfo
+ updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_CONNECTED
+ updatedNodebInfo2.AssociatedE2TInstanceAddress = e2tInstanceFullAddress
+ writerMock.On("UpdateNodebInfo", &updatedNodebInfo2).Return(nil)
+ e2tInstancesManagerMock.On("AddRansToInstance", e2tInstanceFullAddress, []string{nodebRanName}).Return(nil)
+ rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(&rmrCgo.MBuf{}, nil)
- logFile, err := os.Create(logFilePath)
- if err != nil{
- t.Errorf("e2_setup_request_notification_handler_test.TestE2SetupRequestNotificationHandler_HandleNewGnbSuccess - failed to create file, error: %s", err)
- }
- oldStdout := os.Stdout
- defer changeStdout(oldStdout)
- defer removeLogFile(t)
- os.Stdout = logFile
-
- _, handler, _, _, _, e2tInstancesManagerMock, _ := initMocks(t)
- var e2tInstance * entities.E2TInstance
- e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(e2tInstance, common.NewResourceNotFoundError("Not found"))
- prefBytes := []byte(prefix)
- notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlGnb...)}
handler.Handle(notificationRequest)
- assertGetE2TInstanceErrorLogs(t)
-}
-func TestE2SetupRequestNotificationHandler_HandleGetNodebError(t *testing.T) {
- path, err :=filepath.Abs("../../tests/resources/setupRequest_gnb.xml")
- if err != nil {
- t.Fatal(err)
- }
- xmlGnb, err := ioutil.ReadFile(path)
- if err != nil {
- t.Fatal(err)
- }
-
- logFile, err := os.Create(logFilePath)
- if err != nil{
- t.Errorf("e2_setup_request_notification_handler_test.TestE2SetupRequestNotificationHandler_HandleNewGnbSuccess - failed to create file, error: %s", err)
- }
- oldStdout := os.Stdout
- defer changeStdout(oldStdout)
- defer removeLogFile(t)
- os.Stdout = logFile
- _, handler, readerMock, _, _, e2tInstancesManagerMock, _ := initMocks(t)
- var e2tInstance = &entities.E2TInstance{}
- e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(e2tInstance, nil)
- var gnb *entities.NodebInfo
- readerMock.On("GetNodeb", mock.Anything).Return(gnb, common.NewInternalError(errors.New("Some error")))
- prefBytes := []byte(prefix)
- notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlGnb...)}
- handler.Handle(notificationRequest)
- assertGetNodebErrorLogs(t)
+ readerMock.AssertExpectations(t)
+ writerMock.AssertExpectations(t)
+ e2tInstancesManagerMock.AssertExpectations(t)
}
-func TestE2SetupRequestNotificationHandler_HandleAssociationError(t *testing.T) {
- path, err :=filepath.Abs("../../tests/resources/setupRequest_gnb.xml")
- if err != nil {
- t.Fatal(err)
- }
- xmlGnb, err := ioutil.ReadFile(path)
- if err != nil {
- t.Fatal(err)
- }
- logFile, err := os.Create(logFilePath)
- if err != nil{
- t.Errorf("e2_setup_request_notification_handler_test.TestE2SetupRequestNotificationHandler_HandleNewGnbSuccess - failed to create file, error: %s", err)
- }
- oldStdout := os.Stdout
- defer changeStdout(oldStdout)
- defer removeLogFile(t)
- os.Stdout = logFile
-
- _, handler, readerMock, writerMock, _, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
- var e2tInstance = &entities.E2TInstance{}
- e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(e2tInstance, nil)
- var gnb *entities.NodebInfo
- readerMock.On("GetNodeb", mock.Anything).Return(gnb, common.NewResourceNotFoundError("Not found"))
- writerMock.On("SaveNodeb", mock.Anything, mock.Anything).Return(nil)
- routingManagerClientMock.On("AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything).Return(errors.New("association error"))
- prefBytes := []byte(prefix)
- notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlGnb...)}
- handler.Handle(notificationRequest)
- assertAssociationErrorLogs(t)
+func TestE2SetupRequestNotificationHandler_HandleNewGnbSuccess(t *testing.T) {
+ testE2SetupRequestNotificationHandler_HandleNewRanSuccess(t, GnbSetupRequestXmlPath)
}
-func TestE2SetupRequestNotificationHandler_HandleExistingGnbInvalidStatusError(t *testing.T) {
- path, err :=filepath.Abs("../../tests/resources/setupRequest_gnb.xml")
- if err != nil {
- t.Fatal(err)
- }
- xmlGnb, err := ioutil.ReadFile(path)
- if err != nil {
- t.Fatal(err)
- }
-
- logFile, err := os.Create(logFilePath)
- if err != nil{
- t.Errorf("e2_setup_request_notification_handler_test.TestE2SetupRequestNotificationHandler_HandleNewGnbSuccess - failed to create file, error: %s", err)
- }
- oldStdout := os.Stdout
- defer changeStdout(oldStdout)
- defer removeLogFile(t)
- os.Stdout = logFile
-
- handler := stubMockInvalidStatusFlowExistingNodeb(t)
- prefBytes := []byte(prefix)
- notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlGnb...)}
- handler.Handle(notificationRequest)
- assertInvalidNodebStatusLogs(t)
+func TestE2SetupRequestNotificationHandler_HandleNewGnbWithoutFunctionsSuccess(t *testing.T) {
+ testE2SetupRequestNotificationHandler_HandleNewRanSuccess(t, GnbWithoutFunctionsSetupRequestXmlPath)
}
-func assertInvalidNodebStatusLogs(t *testing.T){
- buf := getLogFileBuffer(t)
- assertReceivedAndParsedLog(buf, t)
- assertInvalidNodebStatusLog(buf, t)
- assertNoMoreRecordsLog(buf, t)
+func TestE2SetupRequestNotificationHandler_HandleNewEnGnbSuccess(t *testing.T) {
+ testE2SetupRequestNotificationHandler_HandleNewRanSuccess(t, EnGnbSetupRequestXmlPath)
}
-func assertInvalidNodebStatusLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "#RnibDataService.GetNodeb")
- assert.Contains(t, record, "connection status: SHUTTING_DOWN")
- record, _ = buf.ReadString('\n')
- assert.Contains(t, record, "#E2SetupRequestNotificationHandler.Handle")
- assert.Contains(t, record, "connection status: SHUTTING_DOWN - nodeB entity in incorrect state")
- record, _ = buf.ReadString('\n')
- assert.Contains(t, record, "#E2SetupRequestNotificationHandler.Handle")
- assert.Contains(t, record, "Summary: elapsed time for receiving and handling setup request message from E2 terminator")
+func TestE2SetupRequestNotificationHandler_HandleNewNgEnbSuccess(t *testing.T) {
+ testE2SetupRequestNotificationHandler_HandleNewRanSuccess(t, NgEnbSetupRequestXmlPath)
}
-func assertAssociationErrorLogs(t *testing.T){
- buf := getLogFileBuffer(t)
- assertReceivedAndParsedLog(buf, t)
- assertNewNodebSavedLog(buf, t)
- assertAssociationErrorLog(buf, t)
- assertNoMoreRecordsLog(buf, t)
-}
+func testE2SetupRequestNotificationHandler_HandleExistingConnectedGnbSuccess(t *testing.T, withFunctions bool) {
+ xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
+ e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
+ var nodebInfo = &entities.NodebInfo{
+ RanName: nodebRanName,
+ AssociatedE2TInstanceAddress: e2tInstanceFullAddress,
+ ConnectionStatus: entities.ConnectionStatus_CONNECTED,
+ NodeType: entities.Node_GNB,
+ Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{}},
+ }
-func assertAssociationErrorLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "#E2TAssociationManager.AssociateRan - Associating RAN")
- record, _ = buf.ReadString('\n')
- assert.Contains(t, record, "#E2TAssociationManager.AssociateRan - RoutingManager failure: Failed to associate RAN")
- record, _ = buf.ReadString('\n')
- assert.Contains(t, record, "#E2SetupRequestNotificationHandler.Handle - RAN name:")
- assert.Contains(t, record, "failed to associate E2T to nodeB entity")
-}
+ if withFunctions {
+ gnb := nodebInfo.GetGnb()
+ gnb.RanFunctions = []*entities.RanFunction{{RanFunctionId: 2, RanFunctionRevision: 2}}
+ }
-func assertGetNodebErrorLogs(t *testing.T) {
- buf := getLogFileBuffer(t)
- assertReceivedAndParsedLog(buf, t)
- assertGetNodebErrorLog(buf, t)
- assertNoMoreRecordsLog(buf, t)
-}
+ readerMock.On("GetNodeb", nodebRanName).Return(nodebInfo, nil)
+ routingManagerClientMock.On("AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything).Return(nil)
-func assertGetNodebErrorLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "failed to retrieve nodebInfo entity")
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append([]byte(e2SetupMsgPrefix), xmlGnb...)}
+ gnbToUpdate := getExpectedNodebForExistingRan(*nodebInfo, notificationRequest.Payload)
+ writerMock.On("UpdateNodebInfo", gnbToUpdate).Return(nil)
+ e2tInstancesManagerMock.On("AddRansToInstance", e2tInstanceFullAddress, []string{nodebRanName}).Return(nil)
+ var errEmpty error
+ rmrMessengerMock.On("SendMsg", mock.Anything, true).Return(&rmrCgo.MBuf{}, errEmpty)
+ handler.Handle(notificationRequest)
+ readerMock.AssertExpectations(t)
+ writerMock.AssertExpectations(t)
+ writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 3)
+ e2tInstancesManagerMock.AssertExpectations(t)
+ rmrMessengerMock.AssertCalled(t, "SendMsg", mock.Anything, true)
}
-func assertGetE2TInstanceErrorLogs(t *testing.T) {
- buf := getLogFileBuffer(t)
- assertReceivedAndParsedLog(buf, t)
- assertGetE2TInstanceErrorLog(buf, t)
- assertNoMoreRecordsLog(buf, t)
+func TestE2SetupRequestNotificationHandler_HandleExistingConnectedGnbWithoutFunctionsSuccess(t *testing.T) {
+ testE2SetupRequestNotificationHandler_HandleExistingConnectedGnbSuccess(t, false)
}
-func assertGetE2TInstanceErrorLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "Failed retrieving E2TInstance")
+func TestE2SetupRequestNotificationHandler_HandleExistingConnectedGnbWithFunctionsSuccess(t *testing.T) {
+ testE2SetupRequestNotificationHandler_HandleExistingConnectedGnbSuccess(t, true)
}
-func removeLogFile(t *testing.T) {
- err := os.Remove(logFilePath)
- if err != nil {
- t.Errorf("e2_setup_request_notification_handler_test.TestE2SetupRequestNotificationHandler_HandleGnbSuccess - failed to remove file, error: %s", err)
+func TestE2SetupRequestNotificationHandler_HandleExistingDisconnectedGnbSuccess(t *testing.T) {
+ xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
+ e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
+ var nodebInfo = &entities.NodebInfo{
+ RanName: nodebRanName,
+ AssociatedE2TInstanceAddress: e2tInstanceFullAddress,
+ ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,
+ NodeType: entities.Node_GNB,
+ Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{}},
}
-}
-
-func assertParseErrorFlowLogs(t *testing.T) {
- buf := getLogFileBuffer(t)
- assertReceivedAndFailedParseLog(buf, t)
- assertNoMoreRecordsLog(buf, t)
-}
-func assertUnmarshalErrorFlowLogs(t *testing.T) {
- buf := getLogFileBuffer(t)
- assertReceivedAndFailedUnmarshalLog(buf, t)
- assertNoMoreRecordsLog(buf, t)
-}
+ readerMock.On("GetNodeb", nodebRanName).Return(nodebInfo, nil)
+ routingManagerClientMock.On("AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything).Return(nil)
-func assertSuccessFlowNewNodebLogs(t *testing.T){
- buf := getLogFileBuffer(t)
- assertReceivedAndParsedLog(buf, t)
- assertNewNodebSavedLog(buf, t)
- assertAssociatedLog(buf, t)
- assertRequestBuiltLog(buf, t)
- assertRequestSentLog(buf, t)
- assertNoMoreRecordsLog(buf, t)
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append([]byte(e2SetupMsgPrefix), xmlGnb...)}
+ gnbToUpdate := getExpectedNodebForExistingRan(*nodebInfo, notificationRequest.Payload)
+ writerMock.On("UpdateNodebInfo", gnbToUpdate).Return(nil)
+ gnbToUpdate2 := *gnbToUpdate
+ gnbToUpdate2.ConnectionStatus = entities.ConnectionStatus_CONNECTED
+ writerMock.On("UpdateNodebInfoOnConnectionStatusInversion", &gnbToUpdate2, nodebRanName+"_CONNECTED").Return(nil)
+ gnbToUpdate3 := *gnbToUpdate
+ gnbToUpdate3.ConnectionStatus = entities.ConnectionStatus_CONNECTED
+ gnbToUpdate3.AssociatedE2TInstanceAddress = e2tInstanceFullAddress
+ writerMock.On("UpdateNodebInfo", &gnbToUpdate3).Return(nil)
+ e2tInstancesManagerMock.On("AddRansToInstance", e2tInstanceFullAddress, []string{nodebRanName}).Return(nil)
+ var errEmpty error
+ rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(&rmrCgo.MBuf{}, errEmpty)
+ handler.Handle(notificationRequest)
+ readerMock.AssertExpectations(t)
+ writerMock.AssertExpectations(t)
+ writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2)
+ e2tInstancesManagerMock.AssertExpectations(t)
}
-func assertSuccessFlowExistingNodebLogs(t *testing.T){
- buf := getLogFileBuffer(t)
- assertReceivedAndParsedLog(buf, t)
- assertExistingNodebRetrievedLog(buf, t)
- assertAssociatedLog(buf, t)
- assertRequestBuiltLog(buf, t)
- assertRequestSentLog(buf, t)
- assertNoMoreRecordsLog(buf, t)
+func getExpectedNodebForExistingRan(nodeb entities.NodebInfo, payload []byte) *entities.NodebInfo {
+ pipInd := bytes.IndexByte(payload, '|')
+ setupRequest := &models.E2SetupRequestMessage{}
+ _ = xml.Unmarshal(normalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU)
+ nodeb.GetGnb().RanFunctions = setupRequest.ExtractRanFunctionsList()
+ return &nodeb
}
-func assertReceivedAndParsedLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "received E2 Setup Request")
- record, _ = buf.ReadString('\n')
- assert.Contains(t, record, "handling E2_SETUP_REQUEST")
-}
+func getExpectedNodebForNewRan(payload []byte) *entities.NodebInfo {
+ pipInd := bytes.IndexByte(payload, '|')
+ setupRequest := &models.E2SetupRequestMessage{}
+ _ = xml.Unmarshal(normalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU)
-func assertReceivedAndFailedParseLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "received E2 Setup Request")
- record, _ = buf.ReadString('\n')
- assert.Contains(t, record, "Error parsing E2 Setup Request")
-}
+ nodeb := &entities.NodebInfo{
+ AssociatedE2TInstanceAddress: e2tInstanceFullAddress,
+ RanName: nodebRanName,
+ NodeType: entities.Node_GNB,
+ Configuration: &entities.NodebInfo_Gnb{
+ Gnb: &entities.Gnb{
+ RanFunctions: setupRequest.ExtractRanFunctionsList(),
+ },
+ },
+ GlobalNbId: &entities.GlobalNbId{
+ PlmnId: setupRequest.GetPlmnId(),
+ NbId: setupRequest.GetNbId(),
+ },
+ }
-func assertReceivedAndFailedUnmarshalLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "received E2 Setup Request")
- record, _ = buf.ReadString('\n')
- assert.Contains(t, record, "Error unmarshalling E2 Setup Request")
+ return nodeb
}
-func assertNewNodebSavedLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "#RnibDataService.SaveNodeb - nbIdentity:")
+func TestE2SetupRequestNotificationHandler_HandleParseError(t *testing.T) {
+ xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append([]byte("invalid_prefix"), xmlGnb...)}
+ handler.Handle(notificationRequest)
+ readerMock.AssertNotCalled(t, "GetNodeb", mock.Anything)
+ writerMock.AssertNotCalled(t, "SaveNodeb", mock.Anything, mock.Anything)
+ routingManagerClientMock.AssertNotCalled(t, "AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything)
+ writerMock.AssertNotCalled(t, "UpdateNodebInfo", mock.Anything)
+ e2tInstancesManagerMock.AssertNotCalled(t, "AddRansToInstance", mock.Anything, mock.Anything)
+ rmrMessengerMock.AssertNotCalled(t, "SendMsg", mock.Anything, mock.Anything)
}
-func assertExistingNodebRetrievedLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "#RnibDataService.GetNodeb - RAN name:")
+func TestE2SetupRequestNotificationHandler_HandleUnmarshalError(t *testing.T) {
+ handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append([]byte(e2SetupMsgPrefix), "xmlGnb"...)}
+ handler.Handle(notificationRequest)
+ readerMock.AssertNotCalled(t, "GetNodeb", mock.Anything)
+ writerMock.AssertNotCalled(t, "SaveNodeb", mock.Anything, mock.Anything)
+ routingManagerClientMock.AssertNotCalled(t, "AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything)
+ writerMock.AssertNotCalled(t, "UpdateNodebInfo", mock.Anything)
+ e2tInstancesManagerMock.AssertNotCalled(t, "AddRansToInstance", mock.Anything, mock.Anything)
+ rmrMessengerMock.AssertNotCalled(t, "SendMsg", mock.Anything, mock.Anything)
}
-func assertAssociatedLog(buf *bytes.Buffer, t *testing.T){
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "#E2TAssociationManager.AssociateRan - Associating RAN")
- record, _ = buf.ReadString('\n')
- assert.Contains(t, record, "#RnibDataService.UpdateNodebInfo")
- record, _ = buf.ReadString('\n')
- assert.Contains(t, record, "#E2TAssociationManager.AssociateRan - successfully associated RAN")
+func TestE2SetupRequestNotificationHandler_HandleGetE2TInstanceError(t *testing.T) {
+ xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
+ e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, common.NewResourceNotFoundError("Not found"))
+ prefBytes := []byte(e2SetupMsgPrefix)
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlGnb...)}
+ handler.Handle(notificationRequest)
+ e2tInstancesManagerMock.AssertCalled(t, "GetE2TInstance", e2tInstanceFullAddress)
+ readerMock.AssertNotCalled(t, "GetNodeb", mock.Anything)
+ writerMock.AssertNotCalled(t, "SaveNodeb", mock.Anything, mock.Anything)
+ routingManagerClientMock.AssertNotCalled(t, "AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything)
+ writerMock.AssertNotCalled(t, "UpdateNodebInfo", mock.Anything)
+ e2tInstancesManagerMock.AssertNotCalled(t, "AddRansToInstance", mock.Anything, mock.Anything)
+ rmrMessengerMock.AssertNotCalled(t, "SendMsg", mock.Anything, mock.Anything)
}
-func assertRequestSentLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "uccessfully sent RMR message")
-}
-func assertRequestBuiltLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Contains(t, record, "E2 Setup Request has been built")
+func TestE2SetupRequestNotificationHandler_HandleGetNodebError(t *testing.T) {
+ xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ handler, readerMock, writerMock, routingManagerClientMock, e2tInstancesManagerMock, rmrMessengerMock := initMocks(t)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
+ e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
+ var gnb *entities.NodebInfo
+ readerMock.On("GetNodeb", mock.Anything).Return(gnb, common.NewInternalError(errors.New("some error")))
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append([]byte(e2SetupMsgPrefix), xmlGnb...)}
+ handler.Handle(notificationRequest)
+ e2tInstancesManagerMock.AssertCalled(t, "GetE2TInstance", e2tInstanceFullAddress)
+ readerMock.AssertCalled(t, "GetNodeb", mock.Anything)
+ writerMock.AssertNotCalled(t, "SaveNodeb", mock.Anything, mock.Anything)
+ routingManagerClientMock.AssertNotCalled(t, "AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything)
+ writerMock.AssertNotCalled(t, "UpdateNodebInfo", mock.Anything)
+ e2tInstancesManagerMock.AssertNotCalled(t, "AddRansToInstance", mock.Anything, mock.Anything)
+ rmrMessengerMock.AssertNotCalled(t, "SendMsg", mock.Anything, mock.Anything)
}
-func assertNoMoreRecordsLog(buf *bytes.Buffer, t *testing.T) {
- record, _ := buf.ReadString('\n')
- assert.Empty(t, record)
-}
+func TestE2SetupRequestNotificationHandler_HandleAssociationError(t *testing.T) {
+ xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
-func stubMockSuccessFlowNewNodeb(t *testing.T) E2SetupRequestNotificationHandler{
- _, handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
- var e2tInstance = &entities.E2TInstance{}
- e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(e2tInstance, nil)
+ handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
+ e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
var gnb *entities.NodebInfo
readerMock.On("GetNodeb", mock.Anything).Return(gnb, common.NewResourceNotFoundError("Not found"))
- writerMock.On("SaveNodeb", mock.Anything, mock.Anything).Return(nil)
- routingManagerClientMock.On("AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything).Return(nil)
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append([]byte(e2SetupMsgPrefix), xmlGnb...)}
+ nodebInfo := getExpectedNodebForNewRan(notificationRequest.Payload)
+ writerMock.On("SaveNodeb", mock.Anything, nodebInfo).Return(nil)
+ updatedNodebInfo := *nodebInfo
+ updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTED
+ writerMock.On("UpdateNodebInfoOnConnectionStatusInversion", &updatedNodebInfo, nodebRanName+"_CONNECTED").Return(nil)
writerMock.On("UpdateNodebInfo", mock.Anything).Return(nil)
e2tInstancesManagerMock.On("AddRansToInstance", mock.Anything, mock.Anything).Return(nil)
- var err error
- rmrMessage := &rmrCgo.MBuf{}
- rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(rmrMessage, err)
- return handler
+ routingManagerClientMock.On("AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything).Return(errors.New("association error"))
+ updatedNodebInfo2 := *nodebInfo
+ updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
+ writerMock.On("UpdateNodebInfoOnConnectionStatusInversion", &updatedNodebInfo2, nodebRanName+"_DISCONNECTED").Return(nil)
+ var errEmpty error
+ mbuf := getMbuf(rmrCgo.RIC_E2_SETUP_FAILURE, E2SetupFailureResponseWithTransportCause, notificationRequest)
+ rmrMessengerMock.On("WhSendMsg", mbuf, true).Return(&rmrCgo.MBuf{}, errEmpty)
+ handler.Handle(notificationRequest)
+ readerMock.AssertCalled(t, "GetNodeb", mock.Anything)
+ e2tInstancesManagerMock.AssertCalled(t, "GetE2TInstance", e2tInstanceFullAddress)
+ writerMock.AssertCalled(t, "SaveNodeb", mock.Anything, mock.Anything)
+ routingManagerClientMock.AssertCalled(t, "AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything)
+ e2tInstancesManagerMock.AssertNotCalled(t, "AddRansToInstance", mock.Anything, mock.Anything)
+ rmrMessengerMock.AssertCalled(t, "WhSendMsg", mbuf, true)
}
-func stubMockSuccessFlowExistingNodeb(t *testing.T) E2SetupRequestNotificationHandler{
- _, handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
- var e2tInstance = &entities.E2TInstance{}
- e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(e2tInstance, nil)
- var gnb = &entities.NodebInfo{
- RanName: nodebRanName,
- AssociatedE2TInstanceAddress: e2tAddress,
- ConnectionStatus: entities.ConnectionStatus_CONNECTED,
- NodeType: entities.Node_GNB,
- Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{}},
- }
- readerMock.On("GetNodeb", mock.Anything).Return(gnb, nil)
+func TestE2SetupRequestNotificationHandler_ConvertTo20BitStringError(t *testing.T) {
+ xmlEnGnb := readXmlFile(t, EnGnbSetupRequestXmlPath)
+ logger := tests.InitLog(t)
+ config := &configuration.Configuration{
+ RnibRetryIntervalMs: 10,
+ MaxRnibConnectionAttempts: 3,
+ RnibWriter: configuration.RnibWriterConfig{
+ StateChangeMessageChannel: StateChangeMessageChannel,
+ },
+ GlobalRicId: struct {
+ RicId string
+ Mcc string
+ Mnc string
+ }{Mcc: "327", Mnc: "94", RicId: "10011001101010101011"}}
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
+ rmrSender := tests.InitRmrSender(rmrMessengerMock, logger)
+ readerMock := &mocks.RnibReaderMock{}
+ writerMock := &mocks.RnibWriterMock{}
+ routingManagerClientMock := &mocks.RoutingManagerClientMock{}
+ rnibDataService := services.NewRnibDataService(logger, config, readerMock, writerMock)
+ e2tInstancesManagerMock := &mocks.E2TInstancesManagerMock{}
+ ranListManager := managers.NewRanListManager(logger)
+ ranAlarmService := services.NewRanAlarmService(logger, config)
+ ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(logger, rnibDataService, ranListManager, ranAlarmService)
+
+ e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManagerMock, routingManagerClientMock, ranConnectStatusChangeManager)
+ handler := NewE2SetupRequestNotificationHandler(logger, config, e2tInstancesManagerMock, rmrSender, rnibDataService, e2tAssociationManager, ranConnectStatusChangeManager)
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
+ e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
+ var gnb *entities.NodebInfo
+ readerMock.On("GetNodeb", mock.Anything).Return(gnb, common.NewResourceNotFoundError("Not found"))
+ writerMock.On("SaveNodeb", mock.Anything, mock.Anything).Return(nil)
+ writerMock.On("UpdateNodebInfoOnConnectionStatusInversion", mock.Anything, mock.Anything).Return(nil)
routingManagerClientMock.On("AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything).Return(nil)
writerMock.On("UpdateNodebInfo", mock.Anything).Return(nil)
e2tInstancesManagerMock.On("AddRansToInstance", mock.Anything, mock.Anything).Return(nil)
- var err error
+ var errEmpty error
rmrMessage := &rmrCgo.MBuf{}
- rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(rmrMessage, err)
- return handler
+ rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(rmrMessage, errEmpty)
+ prefBytes := []byte(e2SetupMsgPrefix)
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlEnGnb...)}
+ handler.Handle(notificationRequest)
+ readerMock.AssertCalled(t, "GetNodeb", mock.Anything)
+ e2tInstancesManagerMock.AssertCalled(t, "GetE2TInstance", e2tInstanceFullAddress)
+ writerMock.AssertCalled(t, "SaveNodeb", mock.Anything, mock.Anything)
+ routingManagerClientMock.AssertCalled(t, "AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything)
+ writerMock.AssertCalled(t, "UpdateNodebInfo", mock.Anything)
+ e2tInstancesManagerMock.AssertCalled(t, "AddRansToInstance", mock.Anything, mock.Anything)
+ rmrMessengerMock.AssertNotCalled(t, "SendMsg", mock.Anything, mock.Anything)
}
-func stubMockInvalidStatusFlowExistingNodeb(t *testing.T) E2SetupRequestNotificationHandler{
- _, handler, readerMock, _, _, e2tInstancesManagerMock, _ := initMocks(t)
- var e2tInstance = &entities.E2TInstance{}
- e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(e2tInstance, nil)
- var gnb = &entities.NodebInfo{RanName: nodebRanName, ConnectionStatus:entities.ConnectionStatus_SHUTTING_DOWN}
+func TestE2SetupRequestNotificationHandler_HandleExistingGnbInvalidStatusError(t *testing.T) {
+ xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ handler, readerMock, writerMock, routingManagerClientMock, e2tInstancesManagerMock, rmrMessengerMock := initMocks(t)
+ var gnb = &entities.NodebInfo{RanName: nodebRanName, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
readerMock.On("GetNodeb", mock.Anything).Return(gnb, nil)
- return handler
+ readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
+ e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
+ prefBytes := []byte(e2SetupMsgPrefix)
+ notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append(prefBytes, xmlGnb...)}
+ handler.Handle(notificationRequest)
+ readerMock.AssertCalled(t, "GetNodeb", mock.Anything)
+ e2tInstancesManagerMock.AssertCalled(t, "GetE2TInstance", e2tInstanceFullAddress)
+ writerMock.AssertNotCalled(t, "SaveNodeb", mock.Anything, mock.Anything)
+ routingManagerClientMock.AssertNotCalled(t, "AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything)
+ writerMock.AssertNotCalled(t, "UpdateNodebInfo", mock.Anything)
+ e2tInstancesManagerMock.AssertNotCalled(t, "AddRansToInstance", mock.Anything, mock.Anything)
+ rmrMessengerMock.AssertNotCalled(t, "SendMsg", mock.Anything, mock.Anything)
}
-func initMocks(t *testing.T) (*logger.Logger, E2SetupRequestNotificationHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.RmrMessengerMock, *mocks.E2TInstancesManagerMock, *mocks.RoutingManagerClientMock) {
+func initMocks(t *testing.T) (*E2SetupRequestNotificationHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.RmrMessengerMock, *mocks.E2TInstancesManagerMock, *mocks.RoutingManagerClientMock) {
logger := tests.InitLog(t)
- config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3}
+ config := &configuration.Configuration{
+ RnibRetryIntervalMs: 10,
+ MaxRnibConnectionAttempts: 3,
+ RnibWriter: configuration.RnibWriterConfig{
+ StateChangeMessageChannel: StateChangeMessageChannel,
+ },
+ GlobalRicId: struct {
+ RicId string
+ Mcc string
+ Mnc string
+ }{Mcc: "327", Mnc: "94", RicId: "AACCE"}}
rmrMessengerMock := &mocks.RmrMessengerMock{}
rmrSender := tests.InitRmrSender(rmrMessengerMock, logger)
readerMock := &mocks.RnibReaderMock{}
@@ -561,25 +520,10 @@ func initMocks(t *testing.T) (*logger.Logger, E2SetupRequestNotificationHandler,
routingManagerClientMock := &mocks.RoutingManagerClientMock{}
rnibDataService := services.NewRnibDataService(logger, config, readerMock, writerMock)
e2tInstancesManagerMock := &mocks.E2TInstancesManagerMock{}
- e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManagerMock, routingManagerClientMock)
- handler := NewE2SetupRequestNotificationHandler(logger, config, e2tInstancesManagerMock, rmrSender, rnibDataService, e2tAssociationManager)
- return logger, handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock
-}
-
-func changeStdout(old *os.File) {
- os.Stdout = old
+ ranListManager := managers.NewRanListManager(logger)
+ ranAlarmService := services.NewRanAlarmService(logger, config)
+ ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(logger, rnibDataService, ranListManager, ranAlarmService)
+ e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManagerMock, routingManagerClientMock, ranConnectStatusChangeManager)
+ handler := NewE2SetupRequestNotificationHandler(logger, config, e2tInstancesManagerMock, rmrSender, rnibDataService, e2tAssociationManager, ranConnectStatusChangeManager)
+ return handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock
}
-
-func getLogFileBuffer(t *testing.T) *bytes.Buffer {
- logFile, err := os.Open(logFilePath)
- if err != nil {
- t.Errorf("e2_setup_request_notification_handler_test.assertSuccessFlowNewNodebLogRecords - failed to open file, error: %s", err)
- }
- var buf bytes.Buffer
- _, err = io.Copy(&buf, logFile)
- if err != nil {
- t.Errorf("e2_setup_request_notification_handler_test.assertSuccessFlowNewNodebLogRecords - failed to copy bytes, error: %s", err)
- }
- return &buf
-}
-