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/xapp-frame/pkg/xapp"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 type httpEventWaiter struct {
41 func (msg *httpEventWaiter) SetResult(res bool) {
45 func (msg *httpEventWaiter) WaitResult(t *testing.T) bool {
47 case result := <-msg.resultChan:
49 case <-time.After(15 * time.Second):
50 testError(t, "Waiter not received result status from case within 15 secs")
53 testError(t, "Waiter error in default branch")
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
60 type testingHttpRtmgrStub struct {
64 eventWaiter *httpEventWaiter
67 func (hc *testingHttpRtmgrStub) NextEvent(eventWaiter *httpEventWaiter) {
70 hc.eventWaiter = eventWaiter
73 func (hc *testingHttpRtmgrStub) AllocNextEvent(nextAction bool) *httpEventWaiter {
74 eventWaiter := &httpEventWaiter{
75 resultChan: make(chan bool),
76 nextActionOk: nextAction,
78 hc.NextEvent(eventWaiter)
82 func (hc *testingHttpRtmgrStub) http_handler(w http.ResponseWriter, r *http.Request) {
87 if r.Method == http.MethodPost || r.Method == http.MethodDelete {
88 var req rtmgr_models.XappSubscriptionData
89 err := json.NewDecoder(r.Body).Decode(&req)
91 xapp.Logger.Error("%s", err.Error())
93 xapp.Logger.Info("(%s) handling SubscriptionID=%d Address=%s Port=%d", hc.desc, *req.SubscriptionID, *req.Address, *req.Port)
95 if r.Method == http.MethodPut {
96 var req rtmgr_models.XappList
97 err := json.NewDecoder(r.Body).Decode(&req)
99 xapp.Logger.Error("%s", err.Error())
101 xapp.Logger.Info("(%s) handling put", hc.desc)
106 case http.MethodPost:
108 if hc.eventWaiter != nil {
109 if hc.eventWaiter.nextActionOk == false {
113 case http.MethodDelete:
115 if hc.eventWaiter != nil {
116 if hc.eventWaiter.nextActionOk == false {
122 if hc.eventWaiter != nil {
123 if hc.eventWaiter.nextActionOk == false {
131 waiter := hc.eventWaiter
134 waiter.SetResult(true)
136 xapp.Logger.Info("(%s) Method=%s Reply with code %d", hc.desc, r.Method, code)
141 func (hc *testingHttpRtmgrStub) run() {
142 http.HandleFunc("/", hc.http_handler)
143 http.ListenAndServe("localhost:"+hc.port, nil)
146 func createNewHttpRtmgrStub(desc string, port string) *testingHttpRtmgrStub {
147 hc := &testingHttpRtmgrStub{}