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
40 XMURL = "http://127.0.0.1:3000/ric/v1/xapps"
41 E2MURL = "http://127.0.0.1:8080/ric/v1/e2t/list"
44 func TestFetchXappListInvalidData(t *testing.T) {
45 var httpGetter = NewHttpGetter()
46 _, err := httpGetter.FetchAllXApps(XMURL)
48 t.Error("No XApp data received: " + err.Error())
52 func TestFetchXappListWithInvalidData(t *testing.T) {
54 b := []byte(`{"ID":"deadbeef1234567890", "Version":0, "EventType":"all"}`)
55 l, err := net.Listen("tcp", "127.0.0.1:3000")
57 t.Error("Failed to create listener: " + err.Error())
59 ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
62 if r.Method == "GET" && r.URL.String() == "/ric/v1/xapps" {
63 //t.Log("Sending reply")
64 w.Header().Add("Content-Type", "application/json")
65 w.WriteHeader(http.StatusOK)
74 var httpGetter = NewHttpGetter()
75 xapplist, err := httpGetter.FetchAllXApps(XMURL)
77 t.Error("Error occured: " + err.Error())
79 //t.Log(len(*xapplist))
80 if len(*xapplist) != expected {
81 t.Error("Invalid XApp data: got " + string(len(*xapplist)) + ", expected " + string(expected))
86 func TestFetchAllXAppsWithValidData(t *testing.T) {
90 "name":"xapp-01","status":"unknown","version":"1.2.3",
92 {"name":"xapp-01-instance-01","status":"pending","ip":"172.16.1.103","port":4555,
93 "txMessages":["ControlIndication"],
94 "rxMessages":["LoadIndication","Reset"]
96 {"name":"xapp-01-instance-02","status":"pending","ip":"10.244.1.12","port":4561,
97 "txMessages":["ControlIndication","SNStatusTransfer"],
98 "rxMessages":["LoadIndication","HandoverPreparation"]
103 l, err := net.Listen("tcp", "127.0.0.1:3000")
105 t.Error("Failed to create listener: " + err.Error())
107 ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
110 if r.Method == "GET" && r.URL.String() == "/ric/v1/xapps" {
111 //t.Log("Sending reply")
112 w.Header().Add("Content-Type", "application/json")
113 w.WriteHeader(http.StatusOK)
122 var httpGetter = NewHttpGetter()
123 xapplist, err := httpGetter.FetchAllXApps(XMURL)
125 t.Error("Error occured: " + err.Error())
127 if len(*xapplist) != expected {
128 t.Error("Invalid XApp data: got " + string(len(*xapplist)) + ", expected " + string(expected))