[RICPLT-2837] Fix UT to use real E2tInstanceManager instead of mock
[ric-plt/e2mgr.git] / E2Manager / converters / endc_setup_failure_response_converter_test.go
1 /*******************************************************************************
2  *
3  *   Copyright (c) 2019 AT&T Intellectual Property.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  *
17  *******************************************************************************/
18 package converters
19
20 import (
21         "e2mgr/logger"
22         "fmt"
23         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
24         "strings"
25         "testing"
26 )
27
28 /*
29 Test permutations of x2 setup response to protobuf enb
30 */
31
32 func TestUnpackEndcX2SetupFailureResponseAndExtract(t *testing.T) {
33         logger, _ := logger.InitLogger(logger.InfoLevel)
34
35         var testCases = []struct {
36                 response  string
37                 packedPdu string
38                 failure   error
39         }{
40                 {
41                         response: "CONNECTED_SETUP_FAILED network_layer_cause:HANDOVER_DESIRABLE_FOR_RADIO_REASONS time_to_wait:V1S criticality_diagnostics:<procedure_code:33 triggering_message:UNSUCCESSFUL_OUTCOME procedure_criticality:NOTIFY information_element_criticality_diagnostics:<ie_criticality:REJECT ie_id:128 type_of_error:MISSING > > ",
42                         /*
43                                 E2AP-PDU:
44                                  unsuccessfulOutcome_t
45                                   procedureCode_t = 0x24
46                                   criticality_t = 0
47                                   ENDCX2SetupFailure
48                                    protocolIEs_t:
49                                     ProtocolIE_Container_elm
50                                      id_t = 0x5
51                                      criticality_t = 0x1
52                                      Cause:
53                                       radioNetwork_t = 0
54                                     ProtocolIE_Container_elm
55                                      id_t = 0x16
56                                      criticality_t = 0x1
57                                      TimeToWait = 0
58                                     ProtocolIE_Container_elm
59                                      id_t = 0x11
60                                      criticality_t = 0x1
61                                      CriticalityDiagnostics
62                                       procedureCode_t = 0x21
63                                       triggeringMessage_t = 0x2
64                                       procedureCriticality_t = 0x2
65                                       iEsCriticalityDiagnostics_t:
66                                        CriticalityDiagnostics_IE_List_elm
67                                         iECriticality_t = 0
68                                         iE_ID_t = 0x80
69                                         typeOfError_t = 0x1
70                         */
71                         packedPdu: "4024001a0000030005400200000016400100001140087821a00000008040"},
72
73                 /**** shares the same code with x2setup failure response to protobuf ****/
74         }
75
76         converter := NewEndcSetupFailureResponseConverter(logger)
77
78         for _, tc := range testCases {
79                 t.Run(tc.packedPdu, func(t *testing.T) {
80
81                         var payload []byte
82                         _, err := fmt.Sscanf(tc.packedPdu, "%x", &payload)
83                         if err != nil {
84                                 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
85                         }
86
87                         response, err := converter.UnpackEndcSetupFailureResponseAndExtract(payload)
88
89                         if err != nil {
90                                 if tc.failure == nil {
91                                         t.Errorf("want: success, got: error: %v\n", err)
92                                 } else {
93                                         if strings.Compare(err.Error(), tc.failure.Error()) != 0 {
94                                                 t.Errorf("want: %s, got: %s", tc.failure, err)
95                                         }
96                                 }
97                         }
98
99                         if response == nil {
100                                 if tc.failure == nil {
101                                         t.Errorf("want: response=%s, got: empty response", tc.response)
102                                 }
103                         } else {
104                                 nb := &entities.NodebInfo{}
105                                 nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED_SETUP_FAILED
106                                 nb.SetupFailure = response
107                                 nb.FailureType = entities.Failure_X2_SETUP_FAILURE
108                                 respStr := fmt.Sprintf("%s %s", nb.ConnectionStatus, response)
109                                 if !strings.EqualFold(respStr, tc.response) {
110                                         t.Errorf("want: response=[%s], got: [%s]", tc.response, respStr)
111                                 }
112
113                         }
114                 })
115         }
116 }