Adding Unit Test cases
[ric-plt/appmgr.git] / pkg / resthooks / resthooks_test.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
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
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
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 ==================================================================================
18 */
19
20 package resthooks
21
22 import (
23         "encoding/json"
24         "errors"
25         "fmt"
26         "github.com/stretchr/testify/assert"
27         "github.com/stretchr/testify/mock"
28         "net"
29         "net/http"
30         "net/http/httptest"
31         "os"
32         "time"
33         "strconv"
34         "testing"
35
36         "gerrit.o-ran-sc.org/r/ric-plt/appmgr/pkg/appmgr"
37         "gerrit.o-ran-sc.org/r/ric-plt/appmgr/pkg/models"
38 )
39
40 var rh *Resthook
41 var resp models.SubscriptionResponse
42 var mockedSdl *SdlMock
43 var mockedSdl2 *SdlMock
44
45 // Test cases
46 func TestMain(m *testing.M) {
47         appmgr.Init()
48         appmgr.Logger.SetLevel(0)
49
50         mockedSdl = new(SdlMock)
51         mockedSdl2 = new(SdlMock)
52         NewResthook(false)
53         rh = createResthook(false, mockedSdl,mockedSdl2)
54         code := m.Run()
55         os.Exit(code)
56 }
57
58 func TestAddSubscriptionSuccess(t *testing.T) {
59         var mockSdlRetOk error
60         subsReq := createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")
61
62         mockedSdl.expectDbSet(t, subsReq, mockSdlRetOk)
63         resp := rh.AddSubscription(subsReq)
64         assert.Equal(t, resp.Version, int64(0))
65         assert.Equal(t, resp.EventType, models.EventTypeCreated)
66 }
67
68 func TestAddSubscriptionExists(t *testing.T) {
69         resp := rh.AddSubscription(createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook"))
70         assert.Equal(t, resp.Version, int64(0))
71         assert.Equal(t, resp.EventType, models.EventTypeCreated)
72 }
73
74 func TestDeletesubscriptionSuccess(t *testing.T) {
75         var mockSdlRetOk error
76
77         mockedSdl.On("Set", mock.Anything).Return(mockSdlRetOk)
78         resp := rh.AddSubscription(createSubscription(models.EventTypeDeleted, int64(5), int64(10), "http://localhost:8087/xapps_hook2"))
79         assert.Equal(t, resp.Version, int64(0))
80         assert.Equal(t, resp.EventType, models.EventTypeDeleted)
81
82         resp, ok := rh.DeleteSubscription(resp.ID)
83         assert.Equal(t, ok, true)
84         assert.Equal(t, resp.Version, int64(0))
85         assert.Equal(t, resp.EventType, models.EventTypeDeleted)
86 }
87
88 func TestDeletesubscriptionInvalid(t *testing.T) {
89         resp, ok := rh.DeleteSubscription("Non-existent-ID")
90         assert.Equal(t, ok, false)
91         assert.Equal(t, resp.Version, int64(0))
92         assert.Equal(t, resp.EventType, models.EventType(""))
93 }
94
95 func TestModifySubscriptionSuccess(t *testing.T) {
96         resp := rh.AddSubscription(createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook2"))
97         assert.Equal(t, resp.Version, int64(0))
98         assert.Equal(t, resp.EventType, models.EventTypeCreated)
99
100         resp, ok := rh.ModifySubscription(resp.ID, createSubscription(models.EventTypeModified, int64(5), int64(10), "http://localhost:8087/xapps_hook2"))
101         assert.Equal(t, ok, true)
102         assert.Equal(t, resp.Version, int64(0))
103         assert.Equal(t, resp.EventType, models.EventTypeModified)
104 }
105
106 func TestModifySubscriptionForNonExistingSubscription(t *testing.T) {
107         resp, ok := rh.ModifySubscription("Non-existent-ID", createSubscription(models.EventTypeModified, int64(5), int64(10), "http://localhost:8087/xapps_hook2"))
108         assert.Equal(t, ok, false)
109         assert.Equal(t, *resp, models.SubscriptionResponse{})
110 }
111
112 func TestDeleteSubscriptionForNonExistingSubscription(t *testing.T) {
113         resp, ok := rh.DeleteSubscription("Non-existent-ID")
114         assert.Equal(t, ok, false)
115         assert.Equal(t, resp.Version, int64(0))
116         assert.Equal(t, resp.EventType, models.EventType(""))
117 }
118
119 func TestGetAllSubscriptionSuccess(t *testing.T) {
120         flushExistingSubscriptions()
121         subscriptions := rh.GetAllSubscriptions()
122         assert.Equal(t, len(subscriptions), 0)
123
124         rh.AddSubscription(createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook"))
125         rh.AddSubscription(createSubscription(models.EventTypeModified, int64(5), int64(10), "http://localhost:8087/xapps_hook2"))
126
127         subscriptions = rh.GetAllSubscriptions()
128         assert.Equal(t, len(subscriptions), 2)
129 }
130
131 func TestGetSubscriptionByIdSuccess(t *testing.T) {
132         flushExistingSubscriptions()
133
134         sub1 := createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")
135         sub2 := createSubscription(models.EventTypeModified, int64(5), int64(10), "http://localhost:8087/xapps_hook2")
136         r1 := rh.AddSubscription(sub1)
137         r2 := rh.AddSubscription(sub2)
138
139         resp1, ok := rh.GetSubscriptionById(r1.ID)
140         assert.Equal(t, ok, true)
141         assert.Equal(t, resp1.Data, sub1.Data)
142
143         resp2, ok := rh.GetSubscriptionById(r2.ID)
144         assert.Equal(t, ok, true)
145         assert.Equal(t, resp2.Data, sub2.Data)
146 }
147
148 func TestGetSubscriptionByIdForNonExistingSubscription(t *testing.T) {
149         resp, ok := rh.GetSubscriptionById("Non-existent-ID")
150         assert.Equal(t, ok, false)
151         assert.Equal(t, resp, models.Subscription{})
152 }
153
154 func TestNotifyClientsNoXapp(t *testing.T) {
155         rh.NotifyClients(models.AllDeployedXapps{}, models.EventTypeUndeployed)
156 }
157
158 func TestNotifySuccess(t *testing.T) {
159         flushExistingSubscriptions()
160
161         sub := createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")
162         resp := rh.AddSubscription(sub)
163
164         xapp := getDummyXapp()
165         ts := createHTTPServer(t, "POST", "/xapps_hook", 8087, http.StatusOK, nil)
166         defer ts.Close()
167
168         v, ok := rh.subscriptions.Get(resp.ID)
169         assert.True(t, ok)
170         err := rh.notify(models.AllDeployedXapps{&xapp}, models.EventTypeUndeployed, v.(SubscriptionInfo), 1)
171         assert.Nil(t, err)
172 }
173
174 func TestNotifySuccessIfHttpErrorResponse(t *testing.T) {
175         flushExistingSubscriptions()
176
177         sub := createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")
178         resp := rh.AddSubscription(sub)
179
180         xapp := getDummyXapp()
181         ts := createHTTPServer(t, "POST", "/xapps_hook", 8087, http.StatusInternalServerError, nil)
182         defer ts.Close()
183
184         v, ok := rh.subscriptions.Get(resp.ID)
185         assert.True(t, ok)
186         err := rh.notify(models.AllDeployedXapps{&xapp}, models.EventTypeUndeployed, v.(SubscriptionInfo), 1)
187         assert.Nil(t, err)
188 }
189
190 func TestNotifyReturnsErrorAfterRetriesIfNoHttpServer(t *testing.T) {
191         flushExistingSubscriptions()
192
193         sub := createSubscription(models.EventTypeCreated, int64(2), int64(1), "http://localhost:8087/xapps_hook")
194         resp := rh.AddSubscription(sub)
195
196         xapp := getDummyXapp()
197
198         v, ok := rh.subscriptions.Get(resp.ID)
199         assert.True(t, ok)
200         err := rh.notify(models.AllDeployedXapps{&xapp}, models.EventTypeUndeployed, v.(SubscriptionInfo), 1)
201         assert.NotNil(t, err)
202         assert.Equal(t, 0, len(rh.subscriptions.Items()))
203 }
204
205 func TestRestoreSubscriptionsSuccess(t *testing.T) {
206         var mockSdlRetOk error
207         mSdl := new(SdlMock)
208         mSdl2 := new(SdlMock)
209         key := "key-1"
210
211         subsReq := createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")
212         serializedSubsReq, err := json.Marshal(subsReq)
213         assert.Nil(t, err)
214
215         mockSdlGetRetVal := make(map[string]interface{})
216         //Cast data to string to act like a real SDL/Redis client
217         mockSdlGetRetVal[key] = string(serializedSubsReq)
218         mSdl.On("GetAll").Return([]string{key}, mockSdlRetOk).Twice()
219         mSdl.On("Get", []string{key}).Return(mockSdlGetRetVal, mockSdlRetOk).Once()
220         restHook := createResthook(true, mSdl,mSdl2)
221
222         val, found := restHook.subscriptions.Get(key)
223         assert.True(t, found)
224         assert.Equal(t, subsReq, val.(SubscriptionInfo).req)
225 }
226
227 func TestRestoreSubscriptionsFailsIfSdlGetAllFails(t *testing.T) {
228         var mockSdlRetStatus error
229         mSdl := new(SdlMock)
230         mSdl2 := new(SdlMock)
231         getCalled := 0
232         mGetAllCall := mSdl.On("GetAll")
233         mGetAllCall.RunFn = func(args mock.Arguments) {
234                 if getCalled > 0 {
235                         mockSdlRetStatus = errors.New("some SDL error")
236                 }
237                 getCalled++
238                 mGetAllCall.ReturnArguments = mock.Arguments{[]string{}, mockSdlRetStatus}
239         }
240
241         restHook := createResthook(true, mSdl,mSdl2)
242         assert.Equal(t, 0, len(restHook.subscriptions.Items()))
243 }
244
245 func TestRestoreSubscriptionsFailsIfSdlGetFails(t *testing.T) {
246         var mockSdlRetOk error
247         mSdl := new(SdlMock)
248         mSdl2 := new(SdlMock)
249         mockSdlRetNok := errors.New("some SDL error")
250         key := "key-1"
251         subsReq := createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")
252         serializedSubsReq, err := json.Marshal(subsReq)
253         assert.Nil(t, err)
254
255         mockSdlGetRetVal := make(map[string]interface{})
256         mockSdlGetRetVal[key] = serializedSubsReq
257
258         mSdl.On("GetAll").Return([]string{key}, mockSdlRetOk).Twice()
259         mSdl.On("Get", []string{key}).Return(mockSdlGetRetVal, mockSdlRetNok).Once()
260
261         restHook := createResthook(true, mSdl,mSdl2)
262         assert.Equal(t, 0, len(restHook.subscriptions.Items()))
263 }
264
265 func TestTeardown(t *testing.T) {
266         var mockSdlRetOk error
267         mockedSdl.On("RemoveAll").Return(mockSdlRetOk).Once()
268
269         rh.FlushSubscriptions()
270 }
271
272 func TestUpdateAppDataFail1(t *testing.T) {
273         var reg models.RegisterRequest
274         var tEndpoint string = "10.104.237.59"
275         reg.HTTPEndpoint = &tEndpoint
276         rh.UpdateAppData(reg, false)
277 }
278
279 func TestUpdateAppDataFail2(t *testing.T) {
280         var mockSdlRetOk error
281         var params models.RegisterRequest
282
283         mSdl := new(SdlMock)
284         mSdl2 := new(SdlMock)
285         mockSdlRetNok := errors.New("some SDL error")
286         var tEndpoint1 string = "10.104.237.59:8087"
287         params.HTTPEndpoint = &tEndpoint1
288         serializedSubsReq2, err := json.Marshal(params)
289         if err != nil {
290                 t.Logf("error in marshal .. %v", err)
291         }
292
293         subsReq := createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")
294         serializedSubsReq, err := json.Marshal(subsReq)
295         assert.Nil(t, err)
296
297         key := "key-1"
298         value := "endpoints"
299         mockSdlGetRetVal := make(map[string]interface{})
300         mockSdlGetRetVal[key] = serializedSubsReq
301
302         mockSdlGetRetVal2 := make(map[string]interface{})
303         mockSdlGetRetVal2[value] = serializedSubsReq2
304         mSdl.On("GetAll").Return([]string{key}, mockSdlRetOk).Twice()
305         mSdl.On("Get", []string{key}).Return(mockSdlGetRetVal, mockSdlRetNok).Once()
306         mSdl2.On("Get", []string{value}).Return(mockSdlGetRetVal2, mockSdlRetOk).Once()
307
308         restHook := createResthook(false, mSdl,mSdl2)
309
310         mSdl2.On("Get", []string{value}).Return(mockSdlGetRetVal2, mockSdlRetOk).Once()
311
312         ret := restHook.GetAppsInSDL()
313         if ret == nil {
314                 assert.Nil(t, ret)
315         }
316 }
317
318 func TestGetAppsInSDLFail3(t *testing.T) {
319         var mockSdlRetOk error
320         var params models.RegisterRequest
321
322         mSdl := new(SdlMock)
323         mSdl2 := new(SdlMock)
324         mockSdlRetNok := errors.New("some SDL error")
325
326         serializedSubsReq1, err := json.Marshal(params)
327         if err != nil {
328                 t.Logf("error in marshal .. %v", err)
329         }
330
331         subsReq := createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")
332         serializedSubsReq, err := json.Marshal(subsReq)
333         assert.Nil(t, err)
334
335         key := "key-1"
336         value := "endpoints"
337         mockSdlGetRetVal := make(map[string]interface{})
338         mockSdlGetRetVal[key] = serializedSubsReq
339
340         mockSdlGetRetVal1 := make(map[string]interface{})
341         mockSdlGetRetVal1[key] = serializedSubsReq1
342
343         mSdl.On("GetAll").Return([]string{key}, mockSdlRetOk).Twice()
344         mSdl.On("Get", []string{key}).Return(mockSdlGetRetVal, mockSdlRetNok).Once()
345         mSdl2.On("Get", []string{value}).Return(mockSdlGetRetVal1, mockSdlRetOk).Once()
346
347         restHook := createResthook(false, mSdl,mSdl2)
348
349         mSdl2.On("Get", []string{value}).Return(mockSdlGetRetVal1, mockSdlRetOk).Once()
350         ret2 := restHook.GetAppsInSDL()
351         if ret2 != nil {
352                 t.Logf("SDL Returning: %s \n",*ret2)
353         }else{
354                 assert.Nil(t, ret2)
355         }
356 }
357
358 func TestUpdateAppDataSucc(t *testing.T) {
359         var mockSdlRetOk error
360         var params models.RegisterRequest
361
362         mSdl := new(SdlMock)
363         mSdl2 := new(SdlMock)
364         mockSdlRetNok := errors.New("some SDL error")
365
366         var tEndpoint1 string = "10.104.237.59:8087"
367         params.HTTPEndpoint = &tEndpoint1
368         serializedSubsReq1, err := json.Marshal(params)
369         if err != nil {
370                 t.Logf("error in marshal .. %v", err)
371         }
372         subsReq := createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")
373         serializedSubsReq, err := json.Marshal(subsReq)
374         assert.Nil(t, err)
375
376         key := "key-1"
377         value := "endpoints"
378         mockSdlGetRetVal := make(map[string]interface{})
379         mockSdlGetRetVal[key] = serializedSubsReq
380
381         mockSdlGetRetVal1 := make(map[string]interface{})
382         mockSdlGetRetVal1[key] = serializedSubsReq1
383
384         mSdl.On("GetAll").Return([]string{key}, mockSdlRetOk).Twice()
385         mSdl.On("Get", []string{key}).Return(mockSdlGetRetVal, mockSdlRetNok).Once()
386         mSdl2.On("Get", []string{value}).Return(mockSdlGetRetVal1, mockSdlRetOk).Once()
387
388         restHook := createResthook(false, mSdl,mSdl2)
389
390         mSdl2.On("Get", []string{value}).Return(mockSdlGetRetVal1, mockSdlRetOk).Once()
391         mSdl2.On("Set", mock.Anything).Return(mockSdlRetOk)
392         restHook.UpdateAppData(params, true)
393 }
394
395 func TestUpdateAppDataSucc1(t *testing.T) {
396         var mockSdlRetOk error
397         var params models.RegisterRequest
398
399         mSdl := new(SdlMock)
400         mSdl2 := new(SdlMock)
401         mockSdlRetNok := errors.New("some SDL error")
402
403         var tEndpoint1 string = "10.104.237.59:8087"
404         params.HTTPEndpoint = &tEndpoint1
405         appsindb := []string{ "10.104.237.59:8088 " , " ", " "," 10.104.237.59:8087"}
406         serializedSubsReq1, err := json.Marshal(appsindb)
407         if err != nil {
408                 t.Logf("error in marshal .. %v", err)
409         }
410         subsReq := createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")
411         serializedSubsReq, err := json.Marshal(subsReq)
412         assert.Nil(t, err)
413
414         key := "key-1"
415         value := "endpoints"
416         mockSdlGetRetVal := make(map[string]interface{})
417         mockSdlGetRetVal[key] = serializedSubsReq
418
419         mockSdlGetRetVal1 := make(map[string]interface{})
420         mockSdlGetRetVal1[value] = serializedSubsReq1
421
422         mSdl.On("GetAll").Return([]string{key}, mockSdlRetOk).Twice()
423         mSdl.On("Get", []string{key}).Return(mockSdlGetRetVal, mockSdlRetNok).Once()
424         mSdl2.On("Get", []string{value}).Return(mockSdlGetRetVal1, mockSdlRetOk).Once()
425
426         restHook := createResthook(false, mSdl,mSdl2)
427
428         mSdl2.On("Get", []string{value}).Return(mockSdlGetRetVal1, mockSdlRetOk).Once()
429         mSdl2.On("Set", []string{value}).Return(mockSdlRetOk).Twice()
430
431         mSdl2.On("Remove").Return(mockSdlRetOk)
432         mSdl2.On("Set", mock.Anything).Return(mockSdlRetOk)
433         restHook.UpdateAppData(params, true)
434 }
435
436
437 func TestUpdateAppDataSucc2(t *testing.T) {
438         var mockSdlRetOk error
439         var params models.RegisterRequest
440
441         mSdl := new(SdlMock)
442         mSdl2 := new(SdlMock)
443         mockSdlRetNok := errors.New("some SDL error")
444
445         var tEndpoint1 string = "10.104.237.59:8087"
446         params.Config = "/temp/config.yaml"
447         params.HTTPEndpoint = &tEndpoint1
448         serializedSubsReq1, err := json.Marshal(tEndpoint1)
449         if err != nil {
450                 t.Logf("error in marshal .. %v", err)
451         }
452         subsReq := createSubscription(models.EventTypeCreated, int64(5), int64(10), "http://localhost:8087/xapps_hook")
453         serializedSubsReq, err := json.Marshal(subsReq)
454         assert.Nil(t, err)
455
456         key := "key-1"
457         value := "endpoints"
458         mockSdlGetRetVal := make(map[string]interface{})
459         mockSdlGetRetVal[key] = serializedSubsReq
460
461         mockSdlGetRetVal1 := make(map[string]interface{})
462         mockSdlGetRetVal1[value] = serializedSubsReq1
463
464         mSdl.On("GetAll").Return([]string{key}, mockSdlRetOk).Twice()
465         mSdl.On("Get", []string{key}).Return(mockSdlGetRetVal, mockSdlRetNok).Once()
466         mSdl2.On("Get", []string{value}).Return(mockSdlGetRetVal1, mockSdlRetOk).Once()
467
468         restHook := createResthook(false, mSdl,mSdl2)
469
470         mSdl2.On("Get", []string{value}).Return(mockSdlGetRetVal1, mockSdlRetOk).Once()
471         mSdl2.On("Set", []string{value}).Return(mockSdlRetOk).Twice()
472
473         mSdl2.On("Remove").Return(mockSdlRetOk)
474         mSdl2.On("Set", mock.Anything).Return(mockSdlRetOk)
475         restHook.UpdateAppData(params, true)
476 }
477 func createSubscription(et models.EventType, maxRetries, retryTimer int64, targetUrl string) models.SubscriptionRequest {
478         return models.SubscriptionRequest{&models.SubscriptionData{et, &maxRetries, &retryTimer, &targetUrl}}
479 }
480
481 func getDummyXapp() models.Xapp {
482         return generateXapp("dummy-xapp", "deployed", "1.0", "dummy-xapp-8984fc9fd-bkcbp", "running", "service-ricxapp-dummy-xapp-rmr.ricxapp", "4560")
483 }
484
485 func generateXapp(name, status, ver, iname, istatus, ip, port string) (x models.Xapp) {
486         x.Name = &name
487         x.Status = status
488         x.Version = ver
489         p, _ := strconv.Atoi(port)
490         var msgs appmgr.RtmData
491
492         instance := &models.XappInstance{
493                 Name:       &iname,
494                 Status:     istatus,
495                 IP:         ip,
496                 Port:       int64(p),
497                 TxMessages: msgs.TxMessages,
498                 RxMessages: msgs.RxMessages,
499         }
500         x.Instances = append(x.Instances, instance)
501         return
502 }
503
504 func flushExistingSubscriptions() {
505         var mockSdlRetOk error
506         mockedSdl.On("RemoveAll").Return(mockSdlRetOk).Once()
507         rh.FlushSubscriptions()
508 }
509
510 func createHTTPServer(t *testing.T, method, url string, port, status int, respData interface{}) *httptest.Server {
511         l, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", port))
512         if err != nil {
513                 t.Error("Failed to create listener: " + err.Error())
514         }
515         ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
516                 assert.Equal(t, r.Method, method)
517                 assert.Equal(t, r.URL.String(), url)
518                 w.Header().Add("Content-Type", "application/json")
519                 w.WriteHeader(status)
520                 b, _ := json.Marshal(respData)
521                 w.Write(b)
522         }))
523         ts.Listener.Close()
524         ts.Listener = l
525
526         ts.Start()
527         time.Sleep(time.Duration(1 * time.Second))
528         return ts
529 }
530
531 func (m *SdlMock) expectDbSet(t *testing.T, subsReq models.SubscriptionRequest, mockRet error) {
532         serializedSubReq, _ := json.Marshal(subsReq)
533         m.On("Set", mock.Anything).Run(
534                 func(args mock.Arguments) {
535                         sdlKVs := args.Get(0).([]interface{})
536                         assert.Equal(t, 2, len(sdlKVs))
537                         //Validate that subscription request is set to SDL
538                         assert.Equal(t, serializedSubReq, sdlKVs[1])
539                 }).Return(mockRet).Once()
540 }
541
542 func TestPublishSubscription(t *testing.T) {
543         sub := createSubscription(models.EventTypeCreated, int64(2), int64(1), "http://localhost:8087/xapps_hook")
544         resp := rh.AddSubscription(sub)
545
546         xapp := getDummyXapp()
547
548         v, ok := rh.subscriptions.Get(resp.ID)
549         assert.True(t, ok)
550         if v == nil {
551                 t.Logf("value : %+v",v) 
552         }
553         rh.PublishSubscription(xapp,models.EventTypeUndeployed)
554 }
555
556 type SdlMock struct {
557         mock.Mock
558 }
559
560 func (m *SdlMock) Set(pairs ...interface{}) error {
561         a := m.Called(pairs)
562         return a.Error(0)
563 }
564
565 func (m *SdlMock) Get(keys []string) (map[string]interface{}, error) {
566         a := m.Called(keys)
567         return a.Get(0).(map[string]interface{}), a.Error(1)
568 }
569
570 func (m *SdlMock) GetAll() ([]string, error) {
571         a := m.Called()
572         return a.Get(0).([]string), a.Error(1)
573 }
574
575 func (m *SdlMock) RemoveAll() error {
576         a := m.Called()
577         return a.Error(0)
578 }
579
580 func (m *SdlMock) Remove(keys []string) error {
581         a := m.Called()
582         return a.Error(0)
583 }