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.
17 ==================================================================================
20 Mnemonic: httpgetter.go
21 Abstract: HTTPgetter unit tests
31 "routing-manager/pkg/rtmgr"
36 XMURL string = "http://127.0.0.1:3000/ric/v1/xapps"
39 func TestFetchXappListInvalidData(t *testing.T) {
40 var httpGetter = NewHttpGetter()
41 _, err := httpGetter.FetchAllXapps(XMURL)
43 t.Error("No XApp data received: " + err.Error())
47 func TestFetchXappListWithInvalidData(t *testing.T) {
49 rtmgr.SetLogLevel("debug")
50 b := []byte(`{"ID":"deadbeef1234567890", "Version":0, "EventType":"all"}`)
51 l, err := net.Listen("tcp", "127.0.0.1:3000")
53 t.Error("Failed to create listener: " + err.Error())
55 ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
58 if r.Method == "GET" && r.URL.String() == "/ric/v1/xapps" {
59 //t.Log("Sending reply")
60 w.Header().Add("Content-Type", "application/json")
61 w.WriteHeader(http.StatusOK)
70 var httpGetter = NewHttpGetter()
71 xapplist, err := httpGetter.FetchAllXapps(XMURL)
73 t.Error("Error occured: " + err.Error())
75 //t.Log(len(*xapplist))
76 if len(*xapplist) != expected {
77 t.Error("Invalid XApp data: got " + string(len(*xapplist)) + ", expected " + string(expected))
82 func TestFetchAllXappsWithValidData(t *testing.T) {
86 "name":"xapp-01","status":"unknown","version":"1.2.3",
88 {"name":"xapp-01-instance-01","status":"pending","ip":"172.16.1.103","port":4555,
89 "txMessages":["ControlIndication"],
90 "rxMessages":["LoadIndication","Reset"]
92 {"name":"xapp-01-instance-02","status":"pending","ip":"10.244.1.12","port":4561,
93 "txMessages":["ControlIndication","SNStatusTransfer"],
94 "rxMessages":["LoadIndication","HandoverPreparation"]
99 l, err := net.Listen("tcp", "127.0.0.1:3000")
101 t.Error("Failed to create listener: " + err.Error())
103 ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
106 if r.Method == "GET" && r.URL.String() == "/ric/v1/xapps" {
107 //t.Log("Sending reply")
108 w.Header().Add("Content-Type", "application/json")
109 w.WriteHeader(http.StatusOK)
118 var httpGetter = NewHttpGetter()
119 xapplist, err := httpGetter.FetchAllXapps(XMURL)
121 t.Error("Error occured: " + err.Error())
123 if len(*xapplist) != expected {
124 t.Error("Invalid XApp data: got " + string(len(*xapplist)) + ", expected " + string(expected))