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 ==================================================================================
21 Abstract: NBI unit tests
31 "routing-manager/pkg/appmgr_model"
32 "github.com/go-openapi/swag"
38 func TestGetNbi(t *testing.T) {
39 var errtype = errors.New("")
40 var nbitype = new(HttpGetter)
41 var invalids = []string{"httpgetter", ""}
43 nbii, err := GetNbi("httpGetter")
45 t.Errorf("GetNbi(HttpGetter) was incorrect, got: %v, want: %v.", reflect.TypeOf(err), nil)
47 if reflect.TypeOf(nbii) != reflect.TypeOf(nbitype) {
48 t.Errorf("GetNbi(HttpGetter) was incorrect, got: %v, want: %v.", reflect.TypeOf(nbii), reflect.TypeOf(nbitype))
51 for _, arg := range invalids {
54 t.Errorf("GetNbi("+arg+") was incorrect, got: %v, want: %v.", reflect.TypeOf(err), reflect.TypeOf(errtype))
59 func TestCreateSubReq(t *testing.T) {
60 var subReq = appmgr_model.SubscriptionRequest{
61 TargetURL: swag.String("localhost:8000/ric/v1/handles/xapp-handle/"),
62 EventType: swag.String("all"),
63 MaxRetries: swag.Int64(5),
64 RetryTimer: swag.Int64(10),
66 subReq2 := CreateSubReq("localhost","8000")
67 if reflect.TypeOf(subReq) != reflect.TypeOf(*subReq2) {
68 t.Errorf("Invalid type, got: %v, want: %v.", reflect.TypeOf(subReq), reflect.TypeOf(*subReq2))
70 if *(subReq.TargetURL) != *(subReq2.TargetURL) {
71 t.Errorf("Invalid TargetURL generated, got %v, want %v", *subReq.TargetURL, *subReq2.TargetURL)
73 if *(subReq.EventType) != *(subReq2.EventType) {
74 t.Errorf("Invalid EventType generated, got %v, want %v", *subReq.EventType, *subReq2.EventType)
76 if *(subReq.MaxRetries) != *(subReq2.MaxRetries) {
77 t.Errorf("Invalid MaxRetries generated, got %v, want %v", *subReq.MaxRetries, *subReq2.MaxRetries)
79 if *(subReq.RetryTimer) != *(subReq2.RetryTimer) {
80 t.Errorf("Invalid RetryTimer generated, got %v, want %v", *subReq.RetryTimer, *subReq2.RetryTimer)
84 func TestPostSubReq(t *testing.T) {
85 b := []byte(`{"ID":"deadbeef1234567890", "Version":0, "EventType":"all"}`)
86 l, err := net.Listen("tcp", "127.0.0.1:3000")
88 t.Error("Failed to create listener: " + err.Error())
90 ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
93 if r.Method == "POST" && r.URL.String() == "/ric/v1/subscriptions" {
94 t.Log("Sending reply")
95 w.Header().Add("Content-Type", "application/json")
96 w.WriteHeader(http.StatusCreated)
105 err = PostSubReq("http://127.0.0.1:3000/ric/v1/subscription","localhost:8888")
107 t.Error("Error occured: "+err.Error())
111 func TestPostSubReqWithInvalidUrls(t *testing.T) {
112 // invalid Xapp Manager URL
113 err := PostSubReq("http://127.0","http://localhost:8888")
115 t.Error("Error occured: "+err.Error())
117 // invalid rest api url
118 err = PostSubReq("http://127.0.0.1:3000/","localhost:8888")
120 t.Error("Error occured: "+err.Error())