X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fnbi%2Fhttprestful_test.go;h=5a9ae8cd08a641c5d9b0dcb8ea29c9c8318a8f30;hb=b177846d915b7a70c97a74ca73c26d0964fd6a49;hp=e0bfb28761cbe088396844323cc8d2240820c2b3;hpb=51db0122302c9d72e1de6f8a8e250d219b8b44d8;p=ric-plt%2Frtmgr.git diff --git a/pkg/nbi/httprestful_test.go b/pkg/nbi/httprestful_test.go index e0bfb28..5a9ae8c 100644 --- a/pkg/nbi/httprestful_test.go +++ b/pkg/nbi/httprestful_test.go @@ -66,6 +66,10 @@ var BasicXAppLists = []byte(`[ var SubscriptionResp = []byte(`{"ID":"deadbeef1234567890", "Version":0, "EventType":"all"}`) +var E2TListResp = []byte(`[{"e2tAddress":"127.0.0.1:0","ranNames":["RanM0","RanN0"]},{"e2tAddress":"127.0.0.1:1","ranNames":["RanM1","RanN1"]},{"e2tAddress":"127.0.0.1:2","ranNames":["RanM2","RanN2"]},{"e2tAddress":"127.0.0.1:3","ranNames":["RanM3","RanN3"]}]`) + +var SubscriptionList = []byte(`[{"SubscriptionId":11,"Meid":"Test-Gnb","Endpoint":["127.0.0.1:4056"]}]`) + var InvalidSubResp = []byte(`{"Version":0, "EventType":all}`) func TestValidateXappCallbackData_1(t *testing.T) { @@ -81,6 +85,13 @@ func TestValidateXappCallbackData_1(t *testing.T) { } } +func TestValidateXappCallbackDataInvalid (t *testing.T) { + data := models.XappCallbackData{} + err := validateXappCallbackData(&data) + t.Log(err) +} + + func TestValidateXappSubscriptionsData(t *testing.T) { ep := make(map[string]*rtmgr.Endpoint) @@ -138,6 +149,14 @@ func TestValidateE2tDataEmpty(t *testing.T) { t.Log(err) } +func TestValidateE2tDataDNSLookUPfails(t *testing.T) { + data := models.E2tData{ + E2TAddress: swag.String("e2t.1com:1234"), + } + err := validateE2tData(&data) + t.Log(err) +} + func TestValidateE2tDataInvalid(t *testing.T) { data := models.E2tData{ E2TAddress: swag.String("10.101.01.1"), @@ -439,6 +458,7 @@ func TestAddSubscriptions(t *testing.T) { t.Log(yes_no) } + func TestHttpInstance(t *testing.T) { sdlEngine, _ := sdl.GetSdl("file") rpeEngine, _ := rpe.GetRpe("rmrpush") @@ -452,7 +472,7 @@ func TestHttpInstance(t *testing.T) { //ts.Start() //defer ts.Close() var m sync.Mutex - err = httpinstance.Initialize(XMURL, "httpgetter", "rt.json", "config.json", sdlEngine, rpeEngine, triggerSBI, &m) + err = httpinstance.Initialize(XMURL, "httpgetter", "rt.json", "config.json", E2MURL, sdlEngine, rpeEngine, triggerSBI, &m) } func TestXappCallbackDataChannelwithdata(t *testing.T) { @@ -474,7 +494,8 @@ func TestXappCallbackDataChannelNodata(t *testing.T) { func TestE2TChannelwithData(t *testing.T) { data2 := models.E2tData{ - E2TAddress: swag.String(""), + E2TAddress: swag.String("1.2.3.4"), + RanNamelist: []string{"ran1","ran2"}, } dataChannel := make(chan *models.E2tData, 10) go func() { _, _,_ = recvNewE2Tdata(dataChannel) }() @@ -502,7 +523,7 @@ func TestProvideXappSubscriptionHandleImpl(t *testing.T) { //subdel test } -func createMockAppmgrWithData(url string, g []byte, p []byte) *httptest.Server { +func createMockAppmgrWithData(url string, g []byte, p []byte, t []byte) *httptest.Server { l, err := net.Listen("tcp", url) if err != nil { fmt.Println("Failed to create listener: " + err.Error()) @@ -518,6 +539,30 @@ func createMockAppmgrWithData(url string, g []byte, p []byte) *httptest.Server { w.WriteHeader(http.StatusCreated) w.Write(p) } + if r.Method == "GET" && r.URL.String() == "/ric/v1/e2t/list" { + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + w.Write(t) + } + + })) + ts.Listener.Close() + ts.Listener = l + return ts +} + +func createMockSubmgrWithData(url string, t []byte) *httptest.Server { + l, err := net.Listen("tcp", url) + if err != nil { + fmt.Println("Failed to create listener: " + err.Error()) + } + ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + + if r.Method == "GET" && r.URL.String() == "//ric/v1/subscriptions" { + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + w.Write(t) + } })) ts.Listener.Close() @@ -582,6 +627,10 @@ func TestProvideXappHandleHandlerImpl(t *testing.T) { } } } + + //Empty XappCallbackdata + data1 := models.XappCallbackData{} + err = httpRestful.(*HttpRestful).ProvideXappHandleHandlerImpl(datach, &data1) } func TestValidateXappCallbackData(t *testing.T) { @@ -619,7 +668,7 @@ func TestHttpGetXAppsInvalidData(t *testing.T) { func TestHttpGetXAppsWithValidData(t *testing.T) { var expected = 1 - ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, nil) + ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, nil, nil) ts.Start() defer ts.Close() @@ -632,10 +681,12 @@ func TestHttpGetXAppsWithValidData(t *testing.T) { } } } + + func TestRetrieveStartupDataTimeout(t *testing.T) { sdlEngine, _ := sdl.GetSdl("file") createMockPlatformComponents() - err := retrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", sdlEngine) + err := retrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", E2MURL, sdlEngine) if err == nil { t.Error("Cannot retrieve startup data: " + err.Error()) } @@ -644,32 +695,46 @@ func TestRetrieveStartupDataTimeout(t *testing.T) { } func TestRetrieveStartupData(t *testing.T) { - ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, SubscriptionResp) + ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, SubscriptionResp, nil) ts.Start() defer ts.Close() + + ts1 := createMockAppmgrWithData("127.0.0.1:8080", nil, nil, E2TListResp) + ts1.Start() + defer ts1.Close() + + ts2 := createMockSubmgrWithData("127.0.0.1:8089", SubscriptionList) + ts2.Start() + defer ts2.Close() + sdlEngine, _ := sdl.GetSdl("file") var httpRestful, _ = GetNbi("httpRESTful") createMockPlatformComponents() - err := httpRestful.(*HttpRestful).RetrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", sdlEngine) + httpRestful.(*HttpRestful).RetrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", E2MURL, sdlEngine) //err := retrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", sdlEngine) - if err != nil { + /*if err != nil { t.Error("Cannot retrieve startup data: " + err.Error()) - } + }*/ os.Remove("rt.json") os.Remove("config.json") } func TestRetrieveStartupDataWithInvalidSubResp(t *testing.T) { - ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, InvalidSubResp) + ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, InvalidSubResp, nil) ts.Start() defer ts.Close() sdlEngine, _ := sdl.GetSdl("file") var httpRestful, _ = GetNbi("httpRESTful") createMockPlatformComponents() - err := httpRestful.(*HttpRestful).RetrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", sdlEngine) + err := httpRestful.(*HttpRestful).RetrieveStartupData(XMURL, "httpgetter", "rt.json", "config.json", E2MURL, sdlEngine) if err == nil { t.Error("Cannot retrieve startup data: " + err.Error()) } os.Remove("rt.json") os.Remove("config.json") } + +func TestInvalidarguments(t *testing.T) { + _ = PostSubReq("\n","nbifinterface") + _ = PostSubReq("xmurl","\n") +}