2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
28 "github.com/stretchr/testify/assert"
35 func TestNewSetupRequestHandler(t *testing.T) {
37 rnibWriterProvider := func() rNibWriter.RNibWriter {
38 return &mocks.RnibWriterMock{}
41 h := NewSetupRequestHandler(rnibWriterProvider)
45 func TestCreateMessageSuccess(t *testing.T) {
46 log, err := logger.InitLogger(logger.InfoLevel)
48 t.Errorf("#setup_request_handler_test.TestCreateMessageSuccess - failed to initialize logger, error: %s", err)
50 messageChannel := make(chan *models.E2RequestMessage)
51 assert.NotPanics(t, func() { createMsg(log, messageChannel) })
52 assert.NotEmpty(t, <-messageChannel)
55 func TestParseRicId(t *testing.T) {
56 var testCases = []struct {
64 ricId: "bbbccc-abcd02/18",
65 pLMNId: []byte{0xbb, 0xbc, 0xcc},
66 eNBId: []byte{0xab, 0xcd, 0x2}, /*00000010 -> 10000000*/
67 eNBIdBitqty: shortMacro_eNB_ID,
70 ricId: "bbbccc-abcd0e/20",
71 pLMNId: []byte{0xbb, 0xbc, 0xcc},
72 eNBId: []byte{0xab, 0xcd, 0xe},
73 eNBIdBitqty: macro_eNB_ID,
76 ricId: "bbbccc-abcd07/21",
77 pLMNId: []byte{0xbb, 0xbc, 0xcc},
78 eNBId: []byte{0xab, 0xcd, 0x7}, /*00000111 -> 00111000*/
79 eNBIdBitqty: longMacro_eNB_ID,
82 ricId: "bbbccc-abcdef08/28",
83 pLMNId: []byte{0xbb, 0xbc, 0xcc},
84 eNBId: []byte{0xab, 0xcd, 0xef, 0x8},
85 eNBIdBitqty: home_eNB_ID,
89 failure: fmt.Errorf("unable to extract the value of RIC_ID: EOF"),
94 failure: fmt.Errorf("unable to extract the value of RIC_ID: unexpected EOF"),
98 failure: fmt.Errorf("unable to extract the value of RIC_ID: EOF"),
102 failure: fmt.Errorf("%s", "unable to extract the value of RIC_ID: no hex data for %x string"),
106 failure: fmt.Errorf("%s", "unable to extract the value of RIC_ID: no hex data for %x string"),
109 ricId: "bbbcccdd-abcdef08/28", // pLMNId too long
110 failure: fmt.Errorf("unable to extract the value of RIC_ID: input does not match format"),
113 ricId: "bbbccc-abcdef0809/28", // eNBId too long
114 failure: fmt.Errorf("unable to extract the value of RIC_ID: input does not match format"),
118 ricId: "bbbc-abcdef08/28", // pLMNId too short
119 failure: fmt.Errorf("invalid value for RIC_ID, len(pLMNId:[187 188]) != 3"),
122 ricId: "bbbccc-abcd/28", // eNBId too short
123 failure: fmt.Errorf("invalid value for RIC_ID, len(eNBId:[171 205]) != 3 or 4"),
126 ricId: "bbbccc-abcdef08/239", // bit quantity too long - no error, will return 23 (which is invalid)
127 failure: fmt.Errorf("invalid value for RIC_ID, eNBIdBitqty: 23"),
131 for _, tc := range testCases {
132 t.Run(tc.ricId, func(t *testing.T) {
134 err := parseRicID(tc.ricId)
136 if tc.failure == nil {
137 t.Errorf("want: success, got: parse failed. Error: %v\n", err)
139 if strings.Compare(err.Error(), tc.failure.Error()) != 0 {
140 t.Errorf("want: %s, got: %s\n", err, tc.failure)
144 if bytes.Compare(tc.pLMNId, pLMNId) != 0 {
145 t.Errorf("want: pLMNId = %v, got: pLMNId = %v", tc.pLMNId, pLMNId)
148 if bytes.Compare(tc.eNBId, eNBId) != 0 {
149 t.Errorf("want: eNBId = %v, got: eNBId = %v", tc.eNBId, eNBId)
152 if tc.eNBIdBitqty != eNBIdBitqty {
153 t.Errorf("want: eNBIdBitqty = %d, got: eNBIdBitqty = %d", tc.eNBIdBitqty, eNBIdBitqty)
159 func createMsg(log *logger.Logger, messageChannel chan *models.E2RequestMessage) {
160 h := SetupRequestHandler{}
161 E2Sessions := make(sessions.E2Sessions)
162 var wg sync.WaitGroup
163 var rd models.RequestDetails
164 go h.CreateMessage(log, &rd, messageChannel, E2Sessions, time.Now(), wg)