2 ==================================================================================
3 Copyright (c) 2019 Nokia
4 ==================================================================================
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"
19 var requestorId = int64(0x4EEC)
20 var direction = int64(0)
21 var procedureCode = int64(27)
22 var typeOfMessage = int64(1)
24 var reportParams = apimodel.ReportParams{
25 RequestorID: &requestorId,
26 EventTriggers: apimodel.EventTriggerList{
27 &apimodel.EventTrigger{
28 InterfaceDirection: &direction,
29 ProcedureCode: &procedureCode,
30 TypeOfMessage: &typeOfMessage,
35 var controlParams = apimodel.ControlParams{
36 RequestorID: requestorId,
39 var policyParams = apimodel.PolicyParams{
40 RequestorID: requestorId,
43 func subscriptionHandler(stype models.SubscriptionType, params interface{}) (models.SubscriptionResult, error) {
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)
59 return models.SubscriptionResult{11, 22, 33}, nil
62 func TestSetup(t *testing.T) {
65 // Start the server to simulate SubManager
66 go Subscription.Listen(subscriptionHandler)
67 time.Sleep(time.Duration(2) * time.Second)
70 func TestSubscriptionReportHandling(t *testing.T) {
71 result, err := Subscription.SubscribeReport(&reportParams)
73 assert.Equal(t, err, nil)
74 assert.Equal(t, len(result), 3)
75 assert.Equal(t, result[0], int64(11))
76 assert.Equal(t, result[1], int64(22))
77 assert.Equal(t, result[2], int64(33))
80 func TestSubscriptionControltHandling(t *testing.T) {
81 result, err := Subscription.SubscribeControl(&controlParams)
83 assert.Equal(t, err, nil)
84 assert.Equal(t, len(result), 3)
85 assert.Equal(t, result[0], int64(11))
88 func TestSubscriptionPolicytHandling(t *testing.T) {
89 result, err := Subscription.SubscribePolicy(&policyParams)
91 assert.Equal(t, err, nil)
92 assert.Equal(t, len(result), 3)
93 assert.Equal(t, result[0], int64(11))