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"
40 func TestFetchXappListInvalidData(t *testing.T) {
41 var httpGetter = NewHttpGetter()
42 _, err := httpGetter.FetchAllXapps(XMURL)
44 t.Error("No XApp data received: "+err.Error())
49 func TestFetchXappListWithInvalidData(t *testing.T) {
51 rtmgr.SetLogLevel("debug")
52 b := []byte(`{"ID":"deadbeef1234567890", "Version":0, "EventType":"all"}`)
53 l, err := net.Listen("tcp", "127.0.0.1:3000")
55 t.Error("Failed to create listener: " + err.Error())
57 ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
60 if r.Method == "GET" && r.URL.String() == "/ric/v1/xapps" {
61 //t.Log("Sending reply")
62 w.Header().Add("Content-Type", "application/json")
63 w.WriteHeader(http.StatusOK)
72 var httpGetter = NewHttpGetter()
73 xapplist, err := httpGetter.FetchAllXapps(XMURL)
75 t.Error("Error occured: " + err.Error())
77 //t.Log(len(*xapplist))
78 if len(*xapplist) != expected {
79 t.Error("Invalid XApp data: got " + string(len(*xapplist)) + ", expected " + string(expected))
84 func TestFetchAllXappsWithValidData(t *testing.T) {
88 "name":"xapp-01","status":"unknown","version":"1.2.3",
90 {"name":"xapp-01-instance-01","status":"pending","ip":"172.16.1.103","port":4555,
91 "txMessages":["ControlIndication"],
92 "rxMessages":["LoadIndication","Reset"]
94 {"name":"xapp-01-instance-02","status":"pending","ip":"10.244.1.12","port":4561,
95 "txMessages":["ControlIndication","SNStatusTransfer"],
96 "rxMessages":["LoadIndication","HandoverPreparation"]
101 l, err := net.Listen("tcp", "127.0.0.1:3000")
103 t.Error("Failed to create listener: " + err.Error())
105 ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
108 if r.Method == "GET" && r.URL.String() == "/ric/v1/xapps" {
109 //t.Log("Sending reply")
110 w.Header().Add("Content-Type", "application/json")
111 w.WriteHeader(http.StatusOK)
120 var httpGetter = NewHttpGetter()
121 xapplist, err := httpGetter.FetchAllXapps(XMURL)
123 t.Error("Error occured: " + err.Error())
125 if len(*xapplist) != expected {
126 t.Error("Invalid XApp data: got " + string(len(*xapplist)) + ", expected " + string(expected))