Merge "Changing status to connected state after timeout."
[ric-plt/e2mgr.git] / E2Manager / e2pdus / x2_reset_known_causes_test.go
1 /*
2  *   Copyright (c) 2019 AT&T Intellectual Property.
3  *
4  *   Licensed under the Apache License, Version 2.0 (the "License");
5  *   you may not use this file except in compliance with the License.
6  *   You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *   Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *   See the License for the specific language governing permissions and
14  *   limitations under the License.
15  */
16
17 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20  */
21
22 package e2pdus
23
24 import (
25         "e2mgr/logger"
26         "fmt"
27         "strings"
28         "testing"
29 )
30
31 func TestKnownCausesToX2ResetPDU(t *testing.T) {
32         InfoLevel := int8(3)
33         _, err := logger.InitLogger(InfoLevel)
34         if err != nil {
35                 t.Errorf("failed to initialize logger, error: %s", err)
36         }
37         var testCases = []struct {
38                 cause     string
39                 packedPdu string
40         }{
41                 {
42                         cause:     OmInterventionCause,
43                         packedPdu: "000700080000010005400164",
44                 },
45                 {
46                         cause:     "PROTOCOL:transfer-syntax-error",
47                         packedPdu: "000700080000010005400140",
48                 },
49                 {
50                         cause:     "transport:transport-RESOURCE-unavailable",
51                         packedPdu: "000700080000010005400120",
52                 },
53
54                 {
55                         cause:     "radioNetwork:invalid-MME-groupid",
56                         packedPdu: "00070009000001000540020680",
57                 },
58         }
59
60         for _, tc := range testCases {
61                 t.Run(tc.packedPdu, func(t *testing.T) {
62
63                         payload, ok := KnownCausesToX2ResetPDU(tc.cause)
64                         if !ok {
65                                 t.Errorf("want: success, got: not found.\n")
66                         } else {
67                                 tmp := fmt.Sprintf("%x", payload)
68                                 if len(tmp) != len(tc.packedPdu) {
69                                         t.Errorf("want packed len:%d, got: %d\n", len(tc.packedPdu)/2, len(payload)/2)
70                                 }
71
72                                 if strings.Compare(tmp, tc.packedPdu) != 0 {
73                                         t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", tc.packedPdu, tmp)
74                                 }
75                         }
76                 })
77         }
78 }
79
80 func TestKnownCausesToX2ResetPDUFailure(t *testing.T) {
81          InfoLevel := int8(3)
82          _, err := logger.InitLogger(InfoLevel)
83         if err != nil {
84                 t.Errorf("failed to initialize logger, error: %s", err)
85         }
86
87         _, ok := KnownCausesToX2ResetPDU("xxxx")
88         if ok {
89                 t.Errorf("want: not found, got: success.\n")
90         }
91 }
92
93 func TestPrepareX2ResetPDUsFailure(t *testing.T) {
94         InfoLevel := int8(3)
95         _, err := logger.InitLogger(InfoLevel)
96         if err != nil {
97                 t.Errorf("failed to initialize logger, error: %s", err)
98         }
99
100         err = prepareX2ResetPDUs(1, 4096)
101         if err == nil {
102                 t.Errorf("want: error, got: success.\n")
103         }
104
105         expected := "failed to build and pack the reset message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big:"
106         if !strings.Contains(err.Error(), expected) {
107                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
108         }
109 }