X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fhandlers%2Fhttpmsghandlers%2Fhealth_check_handler_test.go;h=4bce41fda32a2f00d0ddb2facf56764e54c50009;hb=refs%2Fchanges%2F97%2F5097%2F1;hp=af21f04c27f284577506a881fa1b3b0662ac1eb2;hpb=d0513f4d08e81b760bf3309932f84ae63d5a3904;p=ric-plt%2Fe2mgr.git
diff --git a/E2Manager/handlers/httpmsghandlers/health_check_handler_test.go b/E2Manager/handlers/httpmsghandlers/health_check_handler_test.go
index af21f04..4bce41f 100644
--- a/E2Manager/handlers/httpmsghandlers/health_check_handler_test.go
+++ b/E2Manager/handlers/httpmsghandlers/health_check_handler_test.go
@@ -26,13 +26,12 @@ import (
"e2mgr/models"
"e2mgr/rmrCgo"
"e2mgr/services"
+ "e2mgr/utils"
"encoding/xml"
"errors"
"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"
"strings"
"testing"
"unsafe"
@@ -41,7 +40,7 @@ import (
const (
e2tInstanceFullAddress = "10.0.2.15:9999"
e2SetupMsgPrefix = e2tInstanceFullAddress + "|"
- GnbSetupRequestXmlPath = "../../tests/resources/setupRequest_gnb.xml"
+ GnbSetupRequestXmlPath = "../../tests/resources/setupRequest/setupRequest_gnb.xml"
)
func setupHealthCheckHandlerTest(t *testing.T) (*HealthCheckRequestHandler, services.RNibDataService, *mocks.RnibReaderMock, *mocks.RanListManagerMock, *mocks.RmrMessengerMock) {
@@ -76,8 +75,9 @@ func TestHealthCheckRequestHandlerArguementHasRanNameSuccess(t *testing.T) {
ranListManagerMock.On("UpdateHealthcheckTimeStampSent",nb1.RanName).Return(oldnbIdentity, newnbIdentity)
ranListManagerMock.On("UpdateNbIdentities",nb1.NodeType, []*entities.NbIdentity{oldnbIdentity}, []*entities.NbIdentity{newnbIdentity}).Return(nil)
- _, err := handler.Handle(models.HealthCheckRequest{ranNames})
+ resp, err := handler.Handle(models.HealthCheckRequest{ranNames})
+ assert.IsType(t, &models.HealthCheckSuccessResponse{}, resp)
assert.Nil(t, err)
readerMock.AssertExpectations(t)
}
@@ -104,9 +104,10 @@ func TestHealthCheckRequestHandlerArguementHasNoRanNameSuccess(t *testing.T) {
nb2 := &entities.NodebInfo{RanName: "RanName_2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}
readerMock.On("GetNodeb", "RanName_2").Return(nb2, nil)
- _, err := handler.Handle(models.HealthCheckRequest{[]string{}})
+ resp, err := handler.Handle(models.HealthCheckRequest{[]string{}})
assert.Nil(t, err)
+ assert.IsType(t, &models.HealthCheckSuccessResponse{}, resp)
}
@@ -150,7 +151,9 @@ func TestHealthCheckRequestHandlerArguementHasRanNameDBErrorFailure(t *testing.T
func createRMRMbuf(t *testing.T, nodebInfo *entities.NodebInfo) *rmrCgo.MBuf{
serviceQuery := models.NewRicServiceQueryMessage(nodebInfo.GetGnb().RanFunctions)
payLoad, err := xml.Marshal(&serviceQuery.E2APPDU)
- payLoad = normalizeXml(payLoad)
+ payLoad = utils.NormalizeXml(payLoad)
+ tagsToReplace := []string{"reject","ignore","protocolIEs"}
+ payLoad = utils.ReplaceEmptyTagsWithSelfClosing(payLoad, tagsToReplace)
if err != nil {
t.Fatal(err)
@@ -164,11 +167,11 @@ func createRMRMbuf(t *testing.T, nodebInfo *entities.NodebInfo) *rmrCgo.MBuf{
}
func createNbIdentity(t *testing.T, RanName string, connectionStatus entities.ConnectionStatus) *entities.NodebInfo {
- xmlgnb := readXmlFile(t, GnbSetupRequestXmlPath)
+ xmlgnb := utils.ReadXmlFile(t, GnbSetupRequestXmlPath)
payload := append([]byte(e2SetupMsgPrefix), xmlgnb...)
pipInd := bytes.IndexByte(payload, '|')
setupRequest := &models.E2SetupRequestMessage{}
- err := xml.Unmarshal(normalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU)
+ err := xml.Unmarshal(utils.NormalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU)
if err != nil {
t.Fatal(err)
}
@@ -200,16 +203,3 @@ func normalizeXml(payload []byte) []byte {
"","").Replace(xmlStr)
return []byte(normalized)
}
-
-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
-}