RIC-547 - E2M publish SDL event - Automation
[ric-plt/e2mgr.git] / E2Manager / e2pdus / configuration_update_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
19 /*
20 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
21 * platform project (RICP).
22 */
23
24 package e2pdus
25
26 import (
27         "e2mgr/logger"
28         "fmt"
29         "strings"
30         "testing"
31 )
32
33 func TestPrepareEndcConfigurationUpdateFailurePDU(t *testing.T) {
34         _,err := logger.InitLogger(logger.InfoLevel)
35         if err!=nil{
36                 t.Errorf("failed to initialize logger, error: %s", err)
37         }
38         packedPdu := "402500080000010005400142"
39         packedEndcConfigurationUpdateFailure := PackedEndcConfigurationUpdateFailure
40
41         tmp := fmt.Sprintf("%x", packedEndcConfigurationUpdateFailure)
42         if len(tmp) != len(packedPdu) {
43                 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcConfigurationUpdateFailure)/2)
44         }
45
46         if strings.Compare(tmp, packedPdu) != 0 {
47                 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
48         }
49 }
50
51 func TestPrepareEndcConfigurationUpdateFailurePDUFailure(t *testing.T) {
52         _, err := logger.InitLogger(logger.InfoLevel)
53         if err != nil {
54                 t.Errorf("failed to initialize logger, error: %s", err)
55         }
56
57         err  = prepareEndcConfigurationUpdateFailurePDU(1, 4096)
58         if err == nil {
59                 t.Errorf("want: error, got: success.\n")
60         }
61
62         expected:= "#configuration_update.prepareEndcConfigurationUpdateFailurePDU - failed to build and pack the endc configuration update failure message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
63         if !strings.Contains(err.Error(), expected) {
64                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
65         }
66 }
67
68 func TestPrepareX2EnbConfigurationUpdateFailurePDU(t *testing.T) {
69         _,err := logger.InitLogger(logger.InfoLevel)
70         if err!=nil{
71                 t.Errorf("failed to initialize logger, error: %s", err)
72         }
73         packedPdu := "400800080000010005400142"
74         packedEndcX2ConfigurationUpdateFailure := PackedX2EnbConfigurationUpdateFailure
75
76         tmp := fmt.Sprintf("%x", packedEndcX2ConfigurationUpdateFailure)
77         if len(tmp) != len(packedPdu) {
78                 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcX2ConfigurationUpdateFailure)/2)
79         }
80
81         if strings.Compare(tmp, packedPdu) != 0 {
82                 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
83         }
84 }
85
86 func TestPrepareX2EnbConfigurationUpdateFailurePDUFailure(t *testing.T) {
87         _, err := logger.InitLogger(logger.InfoLevel)
88         if err != nil {
89                 t.Errorf("failed to initialize logger, error: %s", err)
90         }
91
92         err  = prepareX2EnbConfigurationUpdateFailurePDU(1, 4096)
93         if err == nil {
94                 t.Errorf("want: error, got: success.\n")
95         }
96
97         expected:= "#configuration_update.prepareX2EnbConfigurationUpdateFailurePDU - failed to build and pack the x2 configuration update failure message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
98         if !strings.Contains(err.Error(), expected) {
99                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
100         }
101 }
102
103 func TestPrepareEndcConfigurationUpdateAckPDU(t *testing.T) {
104         _,err := logger.InitLogger(logger.InfoLevel)
105         if err!=nil{
106                 t.Errorf("failed to initialize logger, error: %s", err)
107         }
108         packedPdu := "2025000a00000100f70003000000"
109         packedEndcConfigurationUpdateAck := PackedEndcConfigurationUpdateAck
110
111         tmp := fmt.Sprintf("%x", packedEndcConfigurationUpdateAck)
112         if len(tmp) != len(packedPdu) {
113                 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcConfigurationUpdateAck)/2)
114         }
115
116         if strings.Compare(tmp, packedPdu) != 0 {
117                 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
118         }
119 }
120
121 func TestPrepareEndcConfigurationUpdateAckPDUFailure(t *testing.T) {
122         _, err := logger.InitLogger(logger.InfoLevel)
123         if err != nil {
124                 t.Errorf("failed to initialize logger, error: %s", err)
125         }
126
127         err  = prepareEndcConfigurationUpdateAckPDU(1, 4096)
128         if err == nil {
129                 t.Errorf("want: error, got: success.\n")
130         }
131
132         expected:= "#configuration_update.prepareEndcConfigurationUpdateAckPDU - failed to build and pack the endc configuration update ack message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
133         if !strings.Contains(err.Error(), expected) {
134                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
135         }
136 }
137
138 func TestPrepareX2EnbConfigurationUpdateAckPDU(t *testing.T) {
139         _,err := logger.InitLogger(logger.InfoLevel)
140         if err!=nil{
141                 t.Errorf("failed to initialize logger, error: %s", err)
142         }
143         packedPdu := "200800080000010011400100"
144         packedEndcX2ConfigurationUpdateAck := PackedX2EnbConfigurationUpdateAck
145
146         tmp := fmt.Sprintf("%x", packedEndcX2ConfigurationUpdateAck)
147         if len(tmp) != len(packedPdu) {
148                 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcX2ConfigurationUpdateAck)/2)
149         }
150
151         if strings.Compare(tmp, packedPdu) != 0 {
152                 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
153         }
154 }
155
156 func TestPrepareX2EnbConfigurationUpdateAckPDUFailure(t *testing.T) {
157         _, err := logger.InitLogger(logger.InfoLevel)
158         if err != nil {
159                 t.Errorf("failed to initialize logger, error: %s", err)
160         }
161
162         err  = prepareX2EnbConfigurationUpdateAckPDU(1, 4096)
163         if err == nil {
164                 t.Errorf("want: error, got: success.\n")
165         }
166
167         expected:= "#configuration_update.prepareX2EnbConfigurationUpdateAckPDU - failed to build and pack the x2 configuration update ack message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
168         if !strings.Contains(err.Error(), expected) {
169                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
170         }
171 }