X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=E2Manager%2Fhandlers%2Frmrmsghandlers%2Fe2_setup_request_notification_handler_test.go;h=d3a7ae269258c4e248c4fa426c8b4e25b00b24d8;hb=5f208b14c6685e2f70897c16da848f8f0ef73a90;hp=0d58a3ba2fcc40f793a18d02bedaaacdc0963bc1;hpb=d0513f4d08e81b760bf3309932f84ae63d5a3904;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 0d58a3b..d3a7ae2 100644
--- a/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler_test.go
+++ b/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler_test.go
@@ -1,6 +1,7 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
+// Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -28,14 +29,13 @@ import (
"e2mgr/rmrCgo"
"e2mgr/services"
"e2mgr/tests"
+ "e2mgr/utils"
"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/ioutil"
- "path/filepath"
"testing"
)
@@ -44,12 +44,12 @@ const (
e2SetupMsgPrefix = e2tInstanceFullAddress + "|"
gnbNodebRanName = "gnb:310-410-b5c67788"
enbNodebRanName = "enB_macro:P310-410-b5c67788"
- GnbSetupRequestXmlPath = "../../tests/resources/setupRequest_gnb.xml"
- GnbWithZeroFunctionsSetupRequestXmlPath = "../../tests/resources/setupRequest_gnb_with_zero_functions.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"
+ GnbSetupRequestXmlPath = "../../tests/resources/setupRequest/setupRequest_gnb.xml"
+ GnbWithZeroFunctionsSetupRequestXmlPath = "../../tests/resources/setupRequest/setupRequest_gnb_with_zero_functions.xml"
+ EnGnbSetupRequestXmlPath = "../../tests/resources/setupRequest/setupRequest_en-gNB.xml"
+ NgEnbSetupRequestXmlPath = "../../tests/resources/setupRequest/setupRequest_ng-eNB.xml"
+ EnbSetupRequestXmlPath = "../../tests/resources/setupRequest/setupRequest_enb.xml"
+ GnbWithoutFunctionsSetupRequestXmlPath = "../../tests/resources/setupRequest/setupRequest_gnb_without_functions.xml"
E2SetupFailureResponseWithMiscCause = "1131"
E2SetupFailureResponseWithTransportCause = "1131"
E2SetupFailureResponseWithRicCause = "1131"
@@ -90,21 +90,8 @@ func getMbuf(ranName string, msgType int, payloadStr string, request *models.Not
return mbuf
}
-func readXmlFile(t *testing.T, xmlPath string) []byte {
- path, err := filepath.Abs(xmlPath)
- if err != nil {
- t.Fatal(err)
- }
- xmlAsBytes, err := ioutil.ReadFile(path)
- if err != nil {
- t.Fatal(err)
- }
-
- return xmlAsBytes
-}
-
func TestParseGnbSetupRequest_Success(t *testing.T) {
- xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlGnb := utils.ReadXmlFile(t, GnbSetupRequestXmlPath)
handler, _, _, _, _, _, _ := initMocks(t)
prefBytes := []byte(e2SetupMsgPrefix)
request, _, err := handler.parseSetupRequest(append(prefBytes, xmlGnb...))
@@ -114,7 +101,7 @@ func TestParseGnbSetupRequest_Success(t *testing.T) {
}
func TestParseEnGnbSetupRequest_Success(t *testing.T) {
- enGnbXml := readXmlFile(t, EnGnbSetupRequestXmlPath)
+ enGnbXml := utils.ReadXmlFile(t, EnGnbSetupRequestXmlPath)
handler, _, _, _, _, _, _ := initMocks(t)
prefBytes := []byte(e2SetupMsgPrefix)
request, _, err := handler.parseSetupRequest(append(prefBytes, enGnbXml...))
@@ -124,7 +111,7 @@ func TestParseEnGnbSetupRequest_Success(t *testing.T) {
}
func TestParseNgEnbSetupRequest_Success(t *testing.T) {
- ngEnbXml := readXmlFile(t, NgEnbSetupRequestXmlPath)
+ ngEnbXml := utils.ReadXmlFile(t, NgEnbSetupRequestXmlPath)
handler, _, _, _, _, _, _ := initMocks(t)
prefBytes := []byte(e2SetupMsgPrefix)
request, _, err := handler.parseSetupRequest(append(prefBytes, ngEnbXml...))
@@ -134,7 +121,7 @@ func TestParseNgEnbSetupRequest_Success(t *testing.T) {
}
func TestParseEnbSetupRequest_Success(t *testing.T) {
- enbXml := readXmlFile(t, EnbSetupRequestXmlPath)
+ enbXml := utils.ReadXmlFile(t, EnbSetupRequestXmlPath)
handler, _, _, _, _, _, _ := initMocks(t)
prefBytes := []byte(e2SetupMsgPrefix)
request, _, err := handler.parseSetupRequest(append(prefBytes, enbXml...))
@@ -144,7 +131,7 @@ func TestParseEnbSetupRequest_Success(t *testing.T) {
}
func TestParseSetupRequest_PipFailure(t *testing.T) {
- xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlGnb := utils.ReadXmlFile(t, GnbSetupRequestXmlPath)
handler, _, _, _, _, _, _ := initMocks(t)
prefBytes := []byte("10.0.2.15:9999")
request, _, err := handler.parseSetupRequest(append(prefBytes, xmlGnb...))
@@ -163,7 +150,7 @@ func TestParseSetupRequest_UnmarshalFailure(t *testing.T) {
}
func TestE2SetupRequestNotificationHandler_HandleParseError(t *testing.T) {
- xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlGnb := utils.ReadXmlFile(t, GnbSetupRequestXmlPath)
handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock, _ := initMocks(t)
readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
notificationRequest := &models.NotificationRequest{RanName: gnbNodebRanName, Payload: append([]byte("invalid_prefix"), xmlGnb...)}
@@ -190,7 +177,7 @@ func TestE2SetupRequestNotificationHandler_HandleUnmarshalError(t *testing.T) {
}
func TestE2SetupRequestNotificationHandler_ConvertTo20BitStringError(t *testing.T) {
- xmlEnGnb := readXmlFile(t, EnGnbSetupRequestXmlPath)
+ xmlEnGnb := utils.ReadXmlFile(t, EnGnbSetupRequestXmlPath)
logger := tests.InitLog(t)
config := &configuration.Configuration{
RnibRetryIntervalMs: 10,
@@ -259,7 +246,7 @@ func TestExtractionOfNodeTypeFromRanName(t *testing.T) {
}
func TestE2SetupRequestNotificationHandler_GetGeneralConfigurationFailure(t *testing.T) {
- xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlGnb := utils.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: gnbNodebRanName, Payload: append([]byte(e2SetupMsgPrefix), xmlGnb...)}
@@ -272,7 +259,7 @@ func TestE2SetupRequestNotificationHandler_GetGeneralConfigurationFailure(t *tes
}
func TestE2SetupRequestNotificationHandler_EnableRicFalse(t *testing.T) {
- xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlGnb := utils.ReadXmlFile(t, GnbSetupRequestXmlPath)
handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock, _ := initMocks(t)
readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: false}, nil)
notificationRequest := &models.NotificationRequest{RanName: gnbNodebRanName, Payload: append([]byte(e2SetupMsgPrefix), xmlGnb...)}
@@ -287,7 +274,7 @@ func TestE2SetupRequestNotificationHandler_EnableRicFalse(t *testing.T) {
}
func TestE2SetupRequestNotificationHandler_HandleGetE2TInstanceError(t *testing.T) {
- xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlGnb := utils.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"))
@@ -304,7 +291,7 @@ func TestE2SetupRequestNotificationHandler_HandleGetE2TInstanceError(t *testing.
}
func TestE2SetupRequestNotificationHandler_HandleGetNodebError(t *testing.T) {
- xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlGnb := utils.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)
@@ -324,7 +311,7 @@ func TestE2SetupRequestNotificationHandler_HandleGetNodebError(t *testing.T) {
/* New Ran UTs - BEGIN */
func TestE2SetupRequestNotificationHandler_HandleNewRanSaveNodebFailure(t *testing.T) {
- xml := readXmlFile(t, GnbSetupRequestXmlPath)
+ xml := utils.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)
@@ -341,7 +328,7 @@ func TestE2SetupRequestNotificationHandler_HandleNewRanSaveNodebFailure(t *testi
}
func TestE2SetupRequestNotificationHandler_HandleNewRan_invalidRanName(t *testing.T) {
- xml := readXmlFile(t, EnbSetupRequestXmlPath)
+ xml := utils.ReadXmlFile(t, EnbSetupRequestXmlPath)
handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, _, _ := initMocks(t)
readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
@@ -360,7 +347,7 @@ func TestE2SetupRequestNotificationHandler_HandleNewRan_invalidRanName(t *testin
}
func TestE2SetupRequestNotificationHandler_HandleNewRanAddNbIdentityFailure(t *testing.T) {
- xml := readXmlFile(t, GnbSetupRequestXmlPath)
+ xml := utils.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)
@@ -378,7 +365,7 @@ func TestE2SetupRequestNotificationHandler_HandleNewRanAddNbIdentityFailure(t *t
}
func TestE2SetupRequestNotificationHandler_HandleNewRanRoutingManagerError(t *testing.T) {
- xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlGnb := utils.ReadXmlFile(t, GnbSetupRequestXmlPath)
handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock, _ := initMocks(t)
readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
@@ -407,7 +394,7 @@ func TestE2SetupRequestNotificationHandler_HandleNewRanRoutingManagerError(t *te
}
func testE2SetupRequestNotificationHandler_HandleNewRanSuccess(t *testing.T, xmlPath string, nodeType entities.Node_Type) {
- xml := readXmlFile(t, xmlPath)
+ xml := utils.ReadXmlFile(t, xmlPath)
var ranName string
if nodeType == entities.Node_GNB {
ranName = gnbNodebRanName
@@ -470,7 +457,7 @@ func TestE2SetupRequestNotificationHandler_HandleNewNgEnbSuccess(t *testing.T) {
func getExpectedGnbNodebForNewRan(payload []byte) *entities.NodebInfo {
pipInd := bytes.IndexByte(payload, '|')
setupRequest := &models.E2SetupRequestMessage{}
- _ = xml.Unmarshal(normalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU)
+ _ = xml.Unmarshal(utils.NormalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU)
nodeb := &entities.NodebInfo{
AssociatedE2TInstanceAddress: e2tInstanceFullAddress,
@@ -495,7 +482,7 @@ func getExpectedGnbNodebForNewRan(payload []byte) *entities.NodebInfo {
func getExpectedEnbNodebForNewRan(payload []byte) *entities.NodebInfo {
pipInd := bytes.IndexByte(payload, '|')
setupRequest := &models.E2SetupRequestMessage{}
- _ = xml.Unmarshal(normalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU)
+ _ = xml.Unmarshal(utils.NormalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU)
nodeb := &entities.NodebInfo{
AssociatedE2TInstanceAddress: e2tInstanceFullAddress,
@@ -523,7 +510,7 @@ func getExpectedEnbNodebForNewRan(payload []byte) *entities.NodebInfo {
func getExpectedNodebForExistingRan(nodeb *entities.NodebInfo, payload []byte) *entities.NodebInfo {
pipInd := bytes.IndexByte(payload, '|')
setupRequest := &models.E2SetupRequestMessage{}
- _ = xml.Unmarshal(normalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU)
+ _ = xml.Unmarshal(utils.NormalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU)
nb := *nodeb
@@ -541,7 +528,7 @@ func getExpectedNodebForExistingRan(nodeb *entities.NodebInfo, payload []byte) *
}
func TestE2SetupRequestNotificationHandler_HandleExistingConnectedEnbSuccess(t *testing.T) {
- xmlEnb := readXmlFile(t, EnbSetupRequestXmlPath)
+ xmlEnb := utils.ReadXmlFile(t, EnbSetupRequestXmlPath)
handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock, ranListManager := initMocks(t)
oldNbIdentity := &entities.NbIdentity{InventoryName: enbNodebRanName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
@@ -581,7 +568,7 @@ func TestE2SetupRequestNotificationHandler_HandleExistingConnectedEnbSuccess(t *
}
func TestE2SetupRequestNotificationHandler_HandleExistingDisconnectedEnbSuccess(t *testing.T) {
- xmlEnb := readXmlFile(t, EnbSetupRequestXmlPath)
+ xmlEnb := utils.ReadXmlFile(t, EnbSetupRequestXmlPath)
handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock, ranListManager := initMocks(t)
oldNbIdentity := &entities.NbIdentity{InventoryName: enbNodebRanName, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
@@ -631,7 +618,7 @@ func TestE2SetupRequestNotificationHandler_HandleExistingDisconnectedEnbSuccess(
}
func testE2SetupRequestNotificationHandler_HandleExistingConnectedGnbSuccess(t *testing.T, withFunctions bool, xmlToRead string) {
- xmlGnb := readXmlFile(t, xmlToRead)
+ xmlGnb := utils.ReadXmlFile(t, xmlToRead)
handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock, ranListManager := initMocks(t)
oldNbIdentity := &entities.NbIdentity{InventoryName: gnbNodebRanName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
@@ -680,7 +667,7 @@ func testE2SetupRequestNotificationHandler_HandleExistingConnectedGnbSuccess(t *
}
func TestE2SetupRequestNotificationHandler_HandleExistingConnectedGnbRoutingManagerError(t *testing.T) {
- xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlGnb := utils.ReadXmlFile(t, GnbSetupRequestXmlPath)
handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock, ranListManager := initMocks(t)
readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
@@ -724,7 +711,7 @@ func TestE2SetupRequestNotificationHandler_HandleExistingConnectedGnbRoutingMana
}
func TestE2SetupRequestNotificationHandler_HandleExistingGnbInvalidConnectionStatusError(t *testing.T) {
- xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlGnb := utils.ReadXmlFile(t, GnbSetupRequestXmlPath)
handler, readerMock, writerMock, _, e2tInstancesManagerMock, rmrMessengerMock, _ := initMocks(t)
var gnb = &entities.NodebInfo{RanName: gnbNodebRanName, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
readerMock.On("GetNodeb", gnbNodebRanName).Return(gnb, nil)
@@ -752,7 +739,7 @@ func TestE2SetupRequestNotificationHandler_HandleExistingConnectedGnbWithZeroFun
}
func TestE2SetupRequestNotificationHandler_HandleExistingDisconnectedGnbSuccess(t *testing.T) {
- xmlGnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlGnb := utils.ReadXmlFile(t, GnbSetupRequestXmlPath)
handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock, ranListManager := initMocks(t)
oldNbIdentity := &entities.NbIdentity{InventoryName: gnbNodebRanName, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
readerMock.On("GetListNodebIds").Return([]*entities.NbIdentity{oldNbIdentity}, nil)