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 meid = "gnb123456"
21 var clientEndpoint = "localhost:4561"
22 var direction = int64(0)
23 var procedureCode = int64(27)
24 var typeOfMessage = int64(1)
26 var reportParams = apimodel.ReportParams{
28 RANFunctionID: &funId,
29 ClientEndpoint: &clientEndpoint,
30 EventTriggers: apimodel.EventTriggerList{
31 &apimodel.EventTrigger{
32 InterfaceDirection: direction,
33 ProcedureCode: procedureCode,
34 TypeOfMessage: typeOfMessage,
39 var policyParams = apimodel.PolicyParams{
41 RANFunctionID: &funId,
42 ClientEndpoint: &clientEndpoint,
43 EventTriggers: apimodel.EventTriggerList{
44 &apimodel.EventTrigger{
45 InterfaceDirection: direction,
46 ProcedureCode: procedureCode,
47 TypeOfMessage: typeOfMessage,
50 PolicyActionDefinitions: &apimodel.PolicyActionDefinition{},
53 func subscriptionHandler(stype models.SubscriptionType, params interface{}) (*models.SubscriptionResponse, error) {
55 case models.SubscriptionTypeReport:
56 p := params.(*models.ReportParams)
57 assert.Equal(suite, meid, p.Meid)
58 assert.Equal(suite, funId, *p.RANFunctionID)
59 assert.Equal(suite, clientEndpoint, *p.ClientEndpoint)
60 assert.Equal(suite, direction, p.EventTriggers[0].InterfaceDirection)
61 assert.Equal(suite, procedureCode, p.EventTriggers[0].ProcedureCode)
62 assert.Equal(suite, typeOfMessage, p.EventTriggers[0].TypeOfMessage)
63 case models.SubscriptionTypePolicy:
64 p := params.(*models.PolicyParams)
65 assert.Equal(suite, clientEndpoint, *p.ClientEndpoint)
70 instanceId := int64(22)
71 return &models.SubscriptionResponse{
72 SubscriptionID: &subId,
73 SubscriptionInstances: []*models.SubscriptionInstance{
74 &models.SubscriptionInstance{RequestorID: &reqId, InstanceID: &instanceId},
75 &models.SubscriptionInstance{RequestorID: &reqId, InstanceID: &instanceId},
80 func queryHandler() (models.SubscriptionList, error) {
81 resp := models.SubscriptionList{
82 &models.SubscriptionData{
85 Endpoint: []string{"127.0.0.1:4056"},
92 func deleteHandler(ep string) error {
93 assert.Equal(suite, clientEndpoint, ep)
98 func TestSetup(t *testing.T) {
101 // Start the server to simulate SubManager
102 go Subscription.Listen(subscriptionHandler, queryHandler, deleteHandler)
103 time.Sleep(time.Duration(2) * time.Second)
106 func TestSubscriptionQueryHandling(t *testing.T) {
107 resp, err := Subscription.QuerySubscriptions()
109 assert.Equal(t, err, nil)
110 assert.Equal(t, resp[0].SubscriptionID, int64(11))
111 assert.Equal(t, resp[0].Meid, "Test-Gnb")
112 assert.Equal(t, resp[0].Endpoint, []string{"127.0.0.1:4056"})
115 func TestSubscriptionReportHandling(t *testing.T) {
116 resp, err := Subscription.SubscribeReport(&reportParams)
118 assert.Equal(t, err, nil)
119 assert.Equal(t, len(resp.SubscriptionInstances), 2)
120 assert.Equal(t, *resp.SubscriptionInstances[0].RequestorID, int64(11))
121 assert.Equal(t, *resp.SubscriptionInstances[0].InstanceID, int64(22))
122 assert.Equal(t, *resp.SubscriptionInstances[1].RequestorID, int64(11))
123 assert.Equal(t, *resp.SubscriptionInstances[1].InstanceID, int64(22))
126 func TestSubscriptionPolicytHandling(t *testing.T) {
127 resp, err := Subscription.SubscribePolicy(&policyParams)
129 assert.Equal(t, err, nil)
130 assert.Equal(t, len(resp.SubscriptionInstances), 2)
131 assert.Equal(t, *resp.SubscriptionInstances[0].RequestorID, int64(11))
132 assert.Equal(t, *resp.SubscriptionInstances[0].InstanceID, int64(22))
135 func TestSubscriptionDeleteHandling(t *testing.T) {
136 err := Subscription.UnSubscribe(clientEndpoint)
138 assert.Equal(t, err, nil)