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=e73f303774509d638d3f3356d4e06ddfa5249e67;hpb=2f9b55c1a2aac9f0865beb73b6619b106b32edb2;p=ric-plt%2Frtmgr.git diff --git a/pkg/nbi/httprestful_test.go b/pkg/nbi/httprestful_test.go index e73f303..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) { @@ -468,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) { @@ -519,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()) @@ -535,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() @@ -640,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() @@ -658,7 +686,7 @@ 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()) } @@ -667,29 +695,38 @@ 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()) }