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 ==================================================================================
26 Abstract: NBI unit tests
38 "routing-manager/pkg/appmgr_model"
41 "github.com/go-openapi/swag"
44 func TestGetNbi(t *testing.T) {
45 var errtype = errors.New("")
46 var nbitype = new(HttpGetter)
47 var invalids = []string{"httpgetter", ""}
49 nbii, err := GetNbi("httpGetter")
51 t.Errorf("GetNbi(HttpGetter) was incorrect, got: %v, want: %v.", reflect.TypeOf(err), nil)
53 if reflect.TypeOf(nbii) != reflect.TypeOf(nbitype) {
54 t.Errorf("GetNbi(HttpGetter) was incorrect, got: %v, want: %v.", reflect.TypeOf(nbii), reflect.TypeOf(nbitype))
57 for _, arg := range invalids {
60 t.Errorf("GetNbi("+arg+") was incorrect, got: %v, want: %v.", reflect.TypeOf(err), reflect.TypeOf(errtype))
64 func TestCreateSubReq(t *testing.T) {
65 var subData = appmgr_model.SubscriptionData{
66 TargetURL: swag.String("localhost:8000/ric/v1/handles/xapp-handle/"),
67 EventType: appmgr_model.EventTypeAll,
68 MaxRetries: swag.Int64(5),
69 RetryTimer: swag.Int64(10),
71 subReq := appmgr_model.SubscriptionRequest{
74 subReq2 := CreateSubReq("localhost", "8000")
75 if reflect.TypeOf(subReq) != reflect.TypeOf(*subReq2) {
76 t.Errorf("Invalid type, got: %v, want: %v.", reflect.TypeOf(subReq), reflect.TypeOf(*subReq2))
78 if *(subReq.Data.TargetURL) != *(subReq2.Data.TargetURL) {
79 t.Errorf("Invalid TargetURL generated, got %v, want %v", *subReq.Data.TargetURL, *subReq2.Data.TargetURL)
82 if (subReq.Data.EventType) != (subReq2.Data.EventType) {
83 t.Errorf("Invalid EventType generated, got %v, want %v", subReq.Data.EventType, subReq2.Data.EventType)
86 if *(subReq.Data.MaxRetries) != *(subReq2.Data.MaxRetries) {
87 t.Errorf("Invalid MaxRetries generated, got %v, want %v", *subReq.Data.MaxRetries, *subReq2.Data.MaxRetries)
89 if *(subReq.Data.RetryTimer) != *(subReq2.Data.RetryTimer) {
90 t.Errorf("Invalid RetryTimer generated, got %v, want %v", *subReq.Data.RetryTimer, *subReq2.Data.RetryTimer)
95 func TestPostSubReq(t *testing.T) {
96 b := []byte(`{"ID":"deadbeef1234567890", "Version":0, "EventType":"all"}`)
97 l, err := net.Listen("tcp", "127.0.0.1:3000")
99 t.Error("Failed to create listener: " + err.Error())
101 ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
104 if r.Method == "POST" && r.URL.String() == "/ric/v1/subscriptions" {
105 t.Log("Sending reply")
106 w.Header().Add("Content-Type", "application/json")
107 w.WriteHeader(http.StatusCreated)
116 err = PostSubReq("http://127.0.0.1:3000/ric/v1/subscription", "localhost:8888")
118 t.Error("Error occured: " + err.Error())
122 func TestPostSubReqWithInvalidUrls(t *testing.T) {
123 // invalid Xapp Manager URL
124 err := PostSubReq("http://127.0", "http://localhost:8888")
126 t.Error("Error occured: " + err.Error())
128 // invalid rest api url
129 err = PostSubReq("http://127.0.0.1:3000/", "localhost:8888")
131 t.Error("Error occured: " + err.Error())