2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
19 This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 platform project (RICP).
22 ==================================================================================
25 Mnemonic: httpgetter.go
26 Abstract: HTTPgetter unit tests
37 "routing-manager/pkg/sbi"
38 "routing-manager/pkg/sdl"
39 "routing-manager/pkg/rpe"
45 XMURL = "http://127.0.0.1:3000/ric/v1/xapps"
46 E2MURL = "http://127.0.0.1:8085/ric/v1/e2t/list"
49 func TestFetchXappListInvalidData(t *testing.T) {
50 var httpGetter = NewHttpGetter()
51 _, err := httpGetter.FetchAllXApps(XMURL)
53 t.Error("No XApp data received: " + err.Error())
57 func TestFetchXappListWithInvalidData(t *testing.T) {
59 b := []byte(`{"ID":"deadbeef1234567890", "Version":0, "EventType":"all"}`)
60 l, err := net.Listen("tcp", "127.0.0.1:3000")
62 t.Error("Failed to create listener: " + err.Error())
64 ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
67 if r.Method == "GET" && r.URL.String() == "/ric/v1/xapps" {
68 //t.Log("Sending reply")
69 w.Header().Add("Content-Type", "application/json")
70 w.WriteHeader(http.StatusOK)
79 var httpGetter = NewHttpGetter()
80 xapplist, err := httpGetter.FetchAllXApps(XMURL)
82 t.Error("Error occured: " + err.Error())
84 //t.Log(len(*xapplist))
85 if len(*xapplist) != expected {
86 t.Error("Invalid XApp data: got " + string(len(*xapplist)) + ", expected " + string(expected))
91 func TestFetchAllXAppsWithValidData(t *testing.T) {
95 "name":"xapp-01","status":"unknown","version":"1.2.3",
97 {"name":"xapp-01-instance-01","status":"pending","ip":"172.16.1.103","port":4555,
98 "txMessages":["ControlIndication"],
99 "rxMessages":["LoadIndication","Reset"]
101 {"name":"xapp-01-instance-02","status":"pending","ip":"10.244.1.12","port":4561,
102 "txMessages":["ControlIndication","SNStatusTransfer"],
103 "rxMessages":["LoadIndication","HandoverPreparation"]
108 l, err := net.Listen("tcp", "127.0.0.1:3000")
110 t.Error("Failed to create listener: " + err.Error())
112 ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
115 if r.Method == "GET" && r.URL.String() == "/ric/v1/xapps" {
116 //t.Log("Sending reply")
117 w.Header().Add("Content-Type", "application/json")
118 w.WriteHeader(http.StatusOK)
127 var httpGetter = NewHttpGetter()
128 xapplist, err := httpGetter.FetchAllXApps(XMURL)
130 t.Error("Error occured: " + err.Error())
132 if len(*xapplist) != expected {
133 t.Error("Invalid XApp data: got " + string(len(*xapplist)) + ", expected " + string(expected))
138 func TestHttpInstance1(t *testing.T) {
139 sdlEngine, _ := sdl.GetSdl("file")
140 rpeEngine, _ := rpe.GetRpe("rmrpush")
141 sbiEngine, _ := sbi.GetSbi("rmrpush")
142 httpinstance := NewHttpGetter()
143 err := httpinstance.Terminate()
145 fmt.Printf("sbiEngine = %v", sbiEngine)
147 createMockPlatformComponents()
148 //ts := createMockAppmgrWithData("127.0.0.1:3000", BasicXAppLists, nil)
152 err = httpinstance.Initialize(XMURL, "httpgetter", "rt.json", "config.json", E2MURL, sdlEngine, rpeEngine, &m)