blob: 5ebb9c2ba56fb70cfbf1e91d754191fcbd1bb5e2 [file] [log] [blame]
Mohamed Abukar5120ec12020-02-04 11:01:24 +02001/*
2==================================================================================
3 Copyright (c) 2019 Nokia
4==================================================================================
5*/
6
7package xapp
8
9import (
10 "testing"
11 "time"
12 "github.com/stretchr/testify/assert"
13 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models"
14 apimodel "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientmodel"
15)
16
17var suite *testing.T
18
19var requestorId = int64(0x4EEC)
20var direction = int64(0)
21var procedureCode = int64(27)
22var typeOfMessage = int64(1)
23
24var reportParams = apimodel.ReportParams{
25 RequestorID: &requestorId,
26 EventTriggers: apimodel.EventTriggerList{
27 &apimodel.EventTrigger{
28 InterfaceDirection: &direction,
29 ProcedureCode: &procedureCode,
30 TypeOfMessage: &typeOfMessage,
31 },
32 },
33}
34
35var controlParams = apimodel.ControlParams{
36 RequestorID: requestorId,
37}
38
39var policyParams = apimodel.PolicyParams{
40 RequestorID: requestorId,
41}
42
43func subscriptionHandler(stype models.SubscriptionType, params interface{}) (models.SubscriptionResult, error) {
44 switch stype {
45 case models.SubscriptionTypeReport:
46 p := params.(*models.ReportParams)
47 assert.Equal(suite, requestorId, *p.RequestorID)
48 assert.Equal(suite, direction, *p.EventTriggers[0].InterfaceDirection)
49 assert.Equal(suite, procedureCode, *p.EventTriggers[0].ProcedureCode)
50 assert.Equal(suite, typeOfMessage, *p.EventTriggers[0].TypeOfMessage)
51 case models.SubscriptionTypeControl:
52 p := params.(*models.ControlParams)
53 assert.Equal(suite, requestorId, p.RequestorID)
54 case models.SubscriptionTypePolicy:
55 p := params.(*models.PolicyParams)
56 assert.Equal(suite, requestorId, p.RequestorID)
57 }
58
59 return models.SubscriptionResult{11, 22, 33}, nil
60}
61
Mohamed Abukar9568a2d2020-02-18 16:50:32 +020062func queryHandler() (models.SubscriptionList, error) {
63 resp := models.SubscriptionList{
64 &models.SubscriptionData{
65 SubscriptionID: 11,
66 Meid: "Test-Gnb",
67 Endpoint: []string{"127.0.0.1:4056"},
68 },
69 }
70
71 return resp, nil
72}
73
Mohamed Abukar5120ec12020-02-04 11:01:24 +020074func TestSetup(t *testing.T) {
75 suite = t
76
77 // Start the server to simulate SubManager
Mohamed Abukar9568a2d2020-02-18 16:50:32 +020078 go Subscription.Listen(subscriptionHandler, queryHandler)
Mohamed Abukar5120ec12020-02-04 11:01:24 +020079 time.Sleep(time.Duration(2) * time.Second)
80}
81
Mohamed Abukar9568a2d2020-02-18 16:50:32 +020082func TestSubscriptionQueryHandling(t *testing.T) {
83 resp, err := Subscription.QuerySubscriptions()
84
85 assert.Equal(t, err, nil)
86 assert.Equal(t, resp[0].SubscriptionID, int64(11))
87 assert.Equal(t, resp[0].Meid, "Test-Gnb")
88 assert.Equal(t, resp[0].Endpoint, []string{"127.0.0.1:4056"})
89}
90
Mohamed Abukar5120ec12020-02-04 11:01:24 +020091func TestSubscriptionReportHandling(t *testing.T) {
92 result, err := Subscription.SubscribeReport(&reportParams)
93
94 assert.Equal(t, err, nil)
95 assert.Equal(t, len(result), 3)
96 assert.Equal(t, result[0], int64(11))
97 assert.Equal(t, result[1], int64(22))
98 assert.Equal(t, result[2], int64(33))
99}
100
101func TestSubscriptionControltHandling(t *testing.T) {
102 result, err := Subscription.SubscribeControl(&controlParams)
103
104 assert.Equal(t, err, nil)
105 assert.Equal(t, len(result), 3)
106 assert.Equal(t, result[0], int64(11))
107}
108
109func TestSubscriptionPolicytHandling(t *testing.T) {
110 result, err := Subscription.SubscribePolicy(&policyParams)
111
112 assert.Equal(t, err, nil)
113 assert.Equal(t, len(result), 3)
114 assert.Equal(t, result[0], int64(11))
115}