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 ==================================================================================
24 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_models"
25 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 type HttpEventWaiter struct {
42 func (msg *HttpEventWaiter) SetResult(res bool) {
46 func (msg *HttpEventWaiter) WaitResult(t *testing.T) bool {
48 case result := <-msg.resultChan:
50 case <-time.After(15 * time.Second):
51 msg.TestError(t, "Waiter not received result status from case within 15 secs")
54 msg.TestError(t, "Waiter error in default branch")
58 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 type testingHttpRtmgrStub struct {
65 eventWaiter *HttpEventWaiter
68 func (tc *testingHttpRtmgrStub) NextEvent(eventWaiter *HttpEventWaiter) {
71 tc.eventWaiter = eventWaiter
74 func (tc *testingHttpRtmgrStub) AllocNextEvent(nextAction bool) *HttpEventWaiter {
75 eventWaiter := &HttpEventWaiter{
76 resultChan: make(chan bool),
77 nextActionOk: nextAction,
79 eventWaiter.TestWrapper.Init("localhost:" + tc.port)
80 tc.NextEvent(eventWaiter)
84 func (tc *testingHttpRtmgrStub) http_handler(w http.ResponseWriter, r *http.Request) {
89 if r.Method == http.MethodPost || r.Method == http.MethodDelete {
90 var req rtmgr_models.XappSubscriptionData
91 err := json.NewDecoder(r.Body).Decode(&req)
93 tc.Logger.Error("%s", err.Error())
95 tc.Logger.Info("handling SubscriptionID=%d Address=%s Port=%d", *req.SubscriptionID, *req.Address, *req.Port)
97 if r.Method == http.MethodPut {
98 var req rtmgr_models.XappList
99 err := json.NewDecoder(r.Body).Decode(&req)
101 tc.Logger.Error("%s", err.Error())
103 tc.Logger.Info("handling put")
108 case http.MethodPost:
110 if tc.eventWaiter != nil {
111 if tc.eventWaiter.nextActionOk == false {
115 case http.MethodDelete:
117 if tc.eventWaiter != nil {
118 if tc.eventWaiter.nextActionOk == false {
124 if tc.eventWaiter != nil {
125 if tc.eventWaiter.nextActionOk == false {
133 waiter := tc.eventWaiter
136 waiter.SetResult(true)
138 tc.Logger.Info("Method=%s Reply with code %d", r.Method, code)
143 func (tc *testingHttpRtmgrStub) run() {
144 http.HandleFunc("/", tc.http_handler)
145 http.ListenAndServe("localhost:"+tc.port, nil)
148 func createNewHttpRtmgrStub(desc string, port string) *testingHttpRtmgrStub {
149 tc := &testingHttpRtmgrStub{}
151 tc.TestWrapper.Init(desc)