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         _, err := logger.InitLogger(logger.InfoLevel)
33         if err != nil {
34                 t.Errorf("failed to initialize logger, error: %s", err)
35         }
36         var testCases = []struct {
37                 cause     string
38                 packedPdu string
39         }{
40                 {
41                         cause:     OmInterventionCause,
42                         packedPdu: "000700080000010005400164",
43                 },
44                 {
45                         cause:     "PROTOCOL:transfer-syntax-error",
46                         packedPdu: "000700080000010005400140",
47                 },
48                 {
49                         cause:     "transport:transport-RESOURCE-unavailable",
50                         packedPdu: "000700080000010005400120",
51                 },
52
53                 {
54                         cause:     "radioNetwork:invalid-MME-groupid",
55                         packedPdu: "00070009000001000540020680",
56                 },
57         }
58
59         for _, tc := range testCases {
60                 t.Run(tc.packedPdu, func(t *testing.T) {
61
62                         payload, ok := KnownCausesToX2ResetPDU(tc.cause)
63                         if !ok {
64                                 t.Errorf("want: success, got: not found.\n")
65                         } else {
66                                 tmp := fmt.Sprintf("%x", payload)
67                                 if len(tmp) != len(tc.packedPdu) {
68                                         t.Errorf("want packed len:%d, got: %d\n", len(tc.packedPdu)/2, len(payload)/2)
69                                 }
70
71                                 if strings.Compare(tmp, tc.packedPdu) != 0 {
72                                         t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", tc.packedPdu, tmp)
73                                 }
74                         }
75                 })
76         }
77 }
78
79 func TestKnownCausesToX2ResetPDUFailure(t *testing.T) {
80         _, err := logger.InitLogger(logger.InfoLevel)
81         if err != nil {
82                 t.Errorf("failed to initialize logger, error: %s", err)
83         }
84
85         _, ok := KnownCausesToX2ResetPDU("xxxx")
86         if ok {
87                 t.Errorf("want: not found, got: success.\n")
88         }
89 }
90
91 func TestPrepareX2ResetPDUsFailure(t *testing.T) {
92         _, err := logger.InitLogger(logger.InfoLevel)
93         if err != nil {
94                 t.Errorf("failed to initialize logger, error: %s", err)
95         }
96
97         err = prepareX2ResetPDUs(1, 4096)
98         if err == nil {
99                 t.Errorf("want: error, got: success.\n")
100         }
101
102         expected := "failed to build and pack the reset message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big:"
103         if !strings.Contains(err.Error(), expected) {
104                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
105         }
106 }