Consumer O-DU slice assurance rApp
[nonrtric/rapp/ransliceassurance.git] / icsversion / internal / odusliceassurance / messageHandler_test.go
1 // -
2 //   ========================LICENSE_START=================================
3 //   O-RAN-SC
4 //   %%
5 //   Copyright (C) 2022: Nordix Foundation
6 //   %%
7 //   Licensed under the Apache License, Version 2.0 (the "License");
8 //   you may not use this file except in compliance with the License.
9 //   You may obtain a copy of the License at
10 //
11 //        http://www.apache.org/licenses/LICENSE-2.0
12 //
13 //   Unless required by applicable law or agreed to in writing, software
14 //   distributed under the License is distributed on an "AS IS" BASIS,
15 //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 //   See the License for the specific language governing permissions and
17 //   limitations under the License.
18 //   ========================LICENSE_END===================================
19 //
20
21 package sliceassurance
22
23 import (
24         "reflect"
25         "testing"
26
27         "oransc.org/usecase/oduclosedloop/icsversion/messages"
28 )
29
30 func TestGetStdDefinedMessages(t *testing.T) {
31         type args struct {
32                 messageStrings *[]string
33         }
34         tests := []struct {
35                 name string
36                 args args
37                 want []messages.StdDefinedMessage
38         }{
39                 {
40                         name: "",
41                         args: args{
42                                 messageStrings: &[]string{
43                                         `{"event":{"commonEventHeader":{"domain":"stnd","eventId":"pm-1","eventName":"stndDefined","eventType":"performanceMeasurementStreaming","sequence":825,"priority":"Low","reportingEntityId":"","reportingEntityName":"O-DU-1122","sourceId":"","sourceName":"O-DU-1122","stndDefinedNamespace":"o-ran-sc-du-hello-world","version":"4.1","vesEventListenerVersion":"7.2.1"},"stndDefinedFields":{"stndDefinedFieldsVersion":"1.0","schemaReference":"o-ran-sc-du-hello-world","data":{"id":"pm-1_123","administrative-state":"unlocked","operational-state":"enabled","user-label":"pm","job-tag":"my-job-tag","granularity-period":30,"measurements":[{"measurement-type-instance-reference":"reference","value":5861,"unit":"kbit/s"}]}}}}`,
44                                 },
45                         },
46                         want: []messages.StdDefinedMessage{{
47                                 Event: messages.Event{
48                                         CommonEventHeader: messages.CommonEventHeader{
49                                                 Domain:                  "stnd",
50                                                 EventId:                 "pm-1",
51                                                 EventName:               "stndDefined",
52                                                 EventType:               "performanceMeasurementStreaming",
53                                                 Sequence:                825,
54                                                 Priority:                "Low",
55                                                 ReportingEntityName:     "O-DU-1122",
56                                                 SourceName:              "O-DU-1122",
57                                                 StndDefinedNamespace:    "o-ran-sc-du-hello-world",
58                                                 Version:                 "4.1",
59                                                 VesEventListenerVersion: "7.2.1",
60                                         },
61                                         StndDefinedFields: messages.StndDefinedFields{
62                                                 StndDefinedFieldsVersion: "1.0",
63                                                 SchemaReference:          "o-ran-sc-du-hello-world",
64                                                 Data: messages.Data{
65                                                         DataId:              "pm-1_123",
66                                                         AdministrativeState: "unlocked",
67                                                         OperationalState:    "enabled",
68                                                         UserLabel:           "pm",
69                                                         JobTag:              "my-job-tag",
70                                                         GranularityPeriod:   30,
71                                                         Measurements: []messages.Measurement{{
72                                                                 MeasurementTypeInstanceReference: "reference",
73                                                                 Value:                            5861,
74                                                                 Unit:                             "kbit/s",
75                                                         }},
76                                                 },
77                                         },
78                                 },
79                         }},
80                 },
81         }
82         for _, tt := range tests {
83                 t.Run(tt.name, func(t *testing.T) {
84                         if got := getStdMessages(tt.args.messageStrings); !reflect.DeepEqual(got, tt.want) {
85                                 t.Errorf("getStdMessages() = %v, want %v", got, tt.want)
86                         }
87                 })
88         }
89 }