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 var req rtmgr_models.XappSubscriptionData
88 err := json.NewDecoder(r.Body).Decode(&req)
90 xapp.Logger.Error("%s", err.Error())
92 xapp.Logger.Info("(%s) handling Address=%s Port=%d SubscriptionID=%d", hc.desc, *req.Address, *req.Port, *req.SubscriptionID)
98 if hc.eventWaiter != nil {
99 if hc.eventWaiter.nextActionOk == false {
103 case http.MethodDelete:
105 if hc.eventWaiter != nil {
106 if hc.eventWaiter.nextActionOk == false {
114 waiter := hc.eventWaiter
117 waiter.SetResult(true)
119 xapp.Logger.Info("(%s) Method=%s Reply with code %d", hc.desc, r.Method, code)
124 func (hc *testingHttpRtmgrStub) run() {
125 http.HandleFunc("/", hc.http_handler)
126 http.ListenAndServe("localhost:"+hc.port, nil)
129 func createNewHttpRtmgrStub(desc string, port string) *testingHttpRtmgrStub {
130 hc := &testingHttpRtmgrStub{}