Mohamed Abukar | 5120ec1 | 2020-02-04 11:01:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | ================================================================================== |
| 3 | Copyright (c) 2019 Nokia |
| 4 | ================================================================================== |
| 5 | */ |
| 6 | |
| 7 | package xapp |
| 8 | |
| 9 | import ( |
| 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 | |
| 17 | var suite *testing.T |
| 18 | |
| 19 | var requestorId = int64(0x4EEC) |
| 20 | var direction = int64(0) |
| 21 | var procedureCode = int64(27) |
| 22 | var typeOfMessage = int64(1) |
| 23 | |
| 24 | var 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 | |
| 35 | var controlParams = apimodel.ControlParams{ |
| 36 | RequestorID: requestorId, |
| 37 | } |
| 38 | |
| 39 | var policyParams = apimodel.PolicyParams{ |
| 40 | RequestorID: requestorId, |
| 41 | } |
| 42 | |
| 43 | func 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 Abukar | 9568a2d | 2020-02-18 16:50:32 +0200 | [diff] [blame^] | 62 | func 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 Abukar | 5120ec1 | 2020-02-04 11:01:24 +0200 | [diff] [blame] | 74 | func TestSetup(t *testing.T) { |
| 75 | suite = t |
| 76 | |
| 77 | // Start the server to simulate SubManager |
Mohamed Abukar | 9568a2d | 2020-02-18 16:50:32 +0200 | [diff] [blame^] | 78 | go Subscription.Listen(subscriptionHandler, queryHandler) |
Mohamed Abukar | 5120ec1 | 2020-02-04 11:01:24 +0200 | [diff] [blame] | 79 | time.Sleep(time.Duration(2) * time.Second) |
| 80 | } |
| 81 | |
Mohamed Abukar | 9568a2d | 2020-02-18 16:50:32 +0200 | [diff] [blame^] | 82 | func 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 Abukar | 5120ec1 | 2020-02-04 11:01:24 +0200 | [diff] [blame] | 91 | func 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 | |
| 101 | func 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 | |
| 109 | func 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 | } |