RIC:1060: Change in PTL
[ric-plt/nodeb-rnib.git] / common / utils_test.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 //  platform project (RICP).
19
20 package common
21
22 import (
23         "github.com/stretchr/testify/assert"
24         "testing"
25 )
26
27 func TestValidateAndBuildCellKeySuccess(t *testing.T) {
28         cellId := "aaaa"
29         prefix := "CELL"
30         delimiter := ":"
31         key, err := ValidateAndBuildCellIdKey(cellId)
32         if err != nil{
33                 t.Errorf("#utils_test.TestValidateAndBuildCellKey - failed to validate key parameter")
34         }
35         assert.Contains(t, key, cellId)
36         assert.Contains(t, key, delimiter)
37         assert.Contains(t, key, prefix)
38 }
39
40 func TestValidateAndBuildNodeBNameKeySuccess(t *testing.T) {
41         name := "name"
42         prefix := "RAN"
43         delimiter := ":"
44         key, err := ValidateAndBuildNodeBNameKey(name)
45         if err != nil{
46                 t.Errorf("#utils_test.TestValidateAndBuildNodeBNameKey - failed to validate key parameter")
47         }
48         assert.Contains(t, key, name)
49         assert.Contains(t, key, delimiter)
50         assert.Contains(t, key, prefix)
51 }
52
53 func TestValidateAndBuildNodeBIdKeySuccess(t *testing.T) {
54         nodeType := "ENB"
55         plmnId := "bbbb"
56         nbId := "cccc"
57         delimiter := ":"
58         key, err := ValidateAndBuildNodeBIdKey(nodeType, plmnId, nbId)
59         if err != nil{
60                 t.Errorf("#utils_test.TestValidateAndBuildNodeBIdKey - failed to validate key parameter")
61         }
62         assert.Contains(t, key, nodeType)
63         assert.Contains(t, key, plmnId)
64         assert.Contains(t, key, nbId)
65         assert.Contains(t, key, delimiter)
66 }
67
68 func TestValidateAndBuildCellNamePciKeyNameValidationFailure(t *testing.T){
69         pci := 9999
70         _, err := ValidateAndBuildCellNamePciKey("", uint32(pci))
71         assert.NotNil(t, err)
72         assert.IsType(t, &ValidationError{}, err)
73         assert.Equal(t, "#utils.ValidateAndBuildCellNamePciKey - an empty inventory name received", err.Error())
74 }
75
76 func TestValidateAndBuildCellKeyCellidValidationFailure(t *testing.T) {
77         _, err := ValidateAndBuildCellIdKey("")
78         assert.NotNil(t, err)
79         assert.IsType(t, &ValidationError{}, err)
80         assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", err.Error())
81 }
82
83 func TestValidateAndBuildNodeBNameKeyNameValidationFailure(t *testing.T) {
84         _, err := ValidateAndBuildNodeBNameKey("")
85         assert.NotNil(t, err)
86         assert.IsType(t, &ValidationError{}, err)
87         assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", err.Error())
88 }
89
90 func TestValidateAndBuildNodeBIdKeyNodeTypeValidationFailure(t *testing.T) {
91         plmnId := "dddd"
92         nbId := "eeee"
93         _, err := ValidateAndBuildNodeBIdKey("", plmnId, nbId)
94         assert.NotNil(t, err)
95         assert.IsType(t, &ValidationError{}, err)
96         assert.Equal(t, "#utils.ValidateAndBuildNodeBIdKey - an empty node type received", err.Error())
97 }
98
99 func TestValidateAndBuildNodeBIdKeyPlmnIdValidationFailure(t *testing.T) {
100         nodeType := "ffff"
101         nbId := "aaaa"
102         _, err := ValidateAndBuildNodeBIdKey(nodeType, "", nbId)
103         assert.NotNil(t, err)
104         assert.IsType(t, &ValidationError{}, err)
105         assert.Equal(t, "#utils.ValidateAndBuildNodeBIdKey - an empty plmnId received", err.Error())
106 }
107
108 func TestValidateAndBuildNodeBIdKeyNbIdValidationFailure(t *testing.T) {
109         nodeType := "bbbb"
110         plmnId := "cccc"
111         _, err := ValidateAndBuildNodeBIdKey(nodeType, plmnId, "")
112         assert.NotNil(t, err)
113         assert.IsType(t, &ValidationError{}, err)
114         assert.Equal(t, "#utils.ValidateAndBuildNodeBIdKey - an empty nbId received", err.Error())
115 }
116
117 func TestValidateAndBuildCellNamePciKeySuccess(t *testing.T){
118         name := "name"
119         prefix := "PCI"
120         pci := 9999
121         delimiter := ":"
122         key, err := ValidateAndBuildCellNamePciKey(name, uint32(pci))
123         if err != nil{
124                 t.Errorf("#utils_test.TestValidateAndBuildCellNamePciKey - failed to validate key parameter")
125         }
126         assert.Contains(t, key, name)
127         assert.Contains(t, key, delimiter)
128         assert.Contains(t, key, prefix)
129         assert.Contains(t, key, "270f")
130 }
131
132
133 func TestValidateAndBuildRanLoadInformationKeySuccess(t *testing.T) {
134         name := "name"
135         prefix := "LOAD"
136         delimiter := ":"
137         key, err := ValidateAndBuildRanLoadInformationKey(name)
138         if err != nil{
139                 t.Errorf("#utils_test.TestValidateAndBuildRanLoadInformationKeySuccess - failed to validate key parameter")
140         }
141         assert.Contains(t, key, name)
142         assert.Contains(t, key, delimiter)
143         assert.Contains(t, key, prefix)
144 }
145
146 func TestValidateAndBuildRanLoadInformationKeyFailure(t *testing.T) {
147         name := ""
148         _, err := ValidateAndBuildRanLoadInformationKey(name)
149         assert.NotNil(t, err)
150         assert.IsType(t, &ValidationError{}, err)
151 }