Add release yaml file for ric-plt-e2mgr:3.0.1
[ric-plt/e2mgr.git] / E2Manager / e2pdus / x2_setup_requests_test.go
index fd66480..12789ec 100644 (file)
@@ -1,5 +1,4 @@
-/*******************************************************************************
- *
+/*
  *   Copyright (c) 2019 AT&T Intellectual Property.
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *   See the License for the specific language governing permissions and
  *   limitations under the License.
- *
- *******************************************************************************/
- package e2pdus
+ */
+
+/*
+ * This source code is part of the near-RT RIC (RAN Intelligent Controller)
+ * platform project (RICP).
+ */
+
+package e2pdus
 
 import (
        "bytes"
+       "e2mgr/logger"
        "fmt"
        "strings"
        "testing"
 )
 
+func TestPreparePackedEndcX2SetupRequest(t *testing.T) {
+       _,err := logger.InitLogger(logger.InfoLevel)
+       if err!=nil{
+               t.Errorf("failed to initialize logger, error: %s", err)
+       }
+       packedPdu := "0024003100000100f4002a0000020015000800bbbccc00abcde000fa0017000001f700bbbcccabcde0000000bbbccc000000000001"
+       packedEndcX2setupRequest := PackedEndcX2setupRequest
+
+       tmp := fmt.Sprintf("%x", packedEndcX2setupRequest)
+       if len(tmp) != len(packedPdu) {
+               t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcX2setupRequest)/2)
+       }
+
+       if strings.Compare(tmp, packedPdu) != 0 {
+               t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
+       }
+}
+
+func TestPreparePackedX2SetupRequest(t *testing.T) {
+       _,err := logger.InitLogger(logger.InfoLevel)
+       if err!=nil{
+               t.Errorf("failed to initialize logger, error: %s", err)
+       }
+       packedPdu := "0006002a0000020015000800bbbccc00abcde000140017000001f700bbbcccabcde0000000bbbccc000000000001"
+       packedX2setupRequest := PackedX2setupRequest
+
+       tmp := fmt.Sprintf("%x", packedX2setupRequest)
+       if len(tmp) != len(packedPdu) {
+               t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedX2setupRequest)/2)
+       }
+
+       if strings.Compare(tmp, packedPdu) != 0 {
+               t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
+       }
+}
+
+func TestPreparePackedX2SetupRequestFailure(t *testing.T) {
+       _, err := logger.InitLogger(logger.InfoLevel)
+       if err != nil {
+               t.Errorf("failed to initialize logger, error: %s", err)
+       }
+
+       _, _, err  = preparePackedX2SetupRequest(1, 4096, pLMNId, eNBId, eNBIdBitqty, ricFlag)
+       if err == nil {
+               t.Errorf("want: error, got: success.\n")
+       }
+
+       expected:= "packing error: #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
+       if !strings.Contains(err.Error(), expected) {
+               t.Errorf("want :[%s], got: [%s]\n", expected, err)
+       }
+}
+
+func TestPreparePackedEndcSetupRequestFailure(t *testing.T) {
+       _, err := logger.InitLogger(logger.InfoLevel)
+       if err != nil {
+               t.Errorf("failed to initialize logger, error: %s", err)
+       }
+
+       _, _, err  = preparePackedEndcX2SetupRequest(1, 4096, pLMNId, eNBId, eNBIdBitqty, ricFlag)
+       if err == nil {
+               t.Errorf("want: error, got: success.\n")
+       }
+
+       expected:= "packing error: #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
+       if !strings.Contains(err.Error(), expected) {
+               t.Errorf("want :[%s], got: [%s]\n", expected, err)
+       }
+}
+
 func TestParseRicId(t *testing.T) {
        var testCases = []struct {
                ricId       string