2 ==================================================================================
3 Copyright (c) 2019 Nokia
4 ==================================================================================
10 apimodel "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientmodel"
11 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models"
12 "github.com/stretchr/testify/assert"
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 queryHandler() (models.SubscriptionList, error) {
63 resp := models.SubscriptionList{
64 &models.SubscriptionData{
67 Endpoint: []string{"127.0.0.1:4056"},
74 func TestSetup(t *testing.T) {
77 // Start the server to simulate SubManager
78 go Subscription.Listen(subscriptionHandler, queryHandler)
79 time.Sleep(time.Duration(2) * time.Second)
82 func TestSubscriptionQueryHandling(t *testing.T) {
83 resp, err := Subscription.QuerySubscriptions()
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"})
91 func TestSubscriptionReportHandling(t *testing.T) {
92 result, err := Subscription.SubscribeReport(&reportParams)
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))
101 func TestSubscriptionControltHandling(t *testing.T) {
102 result, err := Subscription.SubscribeControl(&controlParams)
104 assert.Equal(t, err, nil)
105 assert.Equal(t, len(result), 3)
106 assert.Equal(t, result[0], int64(11))
109 func TestSubscriptionPolicytHandling(t *testing.T) {
110 result, err := Subscription.SubscribePolicy(&policyParams)
112 assert.Equal(t, err, nil)
113 assert.Equal(t, len(result), 3)
114 assert.Equal(t, result[0], int64(11))