Updates for G Maintenance release
[nonrtric/plt/sme.git] / capifcore / internal / providermanagementapi / typeupdate_test.go
1 // -
2 //   ========================LICENSE_START=================================
3 //   O-RAN-SC
4 //   %%
5 //   Copyright (C) 2023: Nordix Foundation
6 //   %%
7 //   Licensed under the Apache License, Version 2.0 (the "License");
8 //   you may not use this file except in compliance with the License.
9 //   You may obtain a copy of the License at
10 //
11 //        http://www.apache.org/licenses/LICENSE-2.0
12 //
13 //   Unless required by applicable law or agreed to in writing, software
14 //   distributed under the License is distributed on an "AS IS" BASIS,
15 //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 //   See the License for the specific language governing permissions and
17 //   limitations under the License.
18 //   ========================LICENSE_END===================================
19 //
20
21 package providermanagementapi
22
23 import (
24         "testing"
25
26         "github.com/stretchr/testify/assert"
27 )
28
29 func TestPrepareNewProvider(t *testing.T) {
30         domainInfo := "domain info"
31         funcInfo := "func info"
32         providerUnderTest := APIProviderEnrolmentDetails{
33                 ApiProvDomInfo: &domainInfo,
34                 ApiProvFuncs: &[]APIProviderFunctionDetails{
35                         {
36                                 ApiProvFuncRole: ApiProviderFuncRoleAPF,
37                                 ApiProvFuncInfo: &funcInfo,
38                         },
39                         {
40                                 ApiProvFuncRole: ApiProviderFuncRoleAEF,
41                         },
42                 },
43         }
44         uuidFunc = func() string {
45                 return "1"
46         }
47
48         providerUnderTest.PrepareNewProvider()
49
50         assert.Equal(t, "domain_id_domain_info", *providerUnderTest.ApiProvDomId)
51         assert.Equal(t, "APF_id_func_info", *(*providerUnderTest.ApiProvFuncs)[0].ApiProvFuncId)
52         assert.Equal(t, "AEF_id_1", *(*providerUnderTest.ApiProvFuncs)[1].ApiProvFuncId)
53
54         providerUnderTest = APIProviderEnrolmentDetails{}
55
56         providerUnderTest.PrepareNewProvider()
57
58         assert.Equal(t, "domain_id_1", *providerUnderTest.ApiProvDomId)
59 }
60
61 func TestUpdateFuncs(t *testing.T) {
62         registeredProvider := getProvider()
63
64         funcInfo := "func info"
65         updatedFuncs := []APIProviderFunctionDetails{
66                 (*registeredProvider.ApiProvFuncs)[0],
67                 (*registeredProvider.ApiProvFuncs)[2],
68                 {
69                         ApiProvFuncRole: ApiProviderFuncRoleAEF,
70                         ApiProvFuncInfo: &funcInfo,
71                 },
72         }
73         providerUnderTest := APIProviderEnrolmentDetails{
74                 ApiProvFuncs: &updatedFuncs,
75         }
76         err := providerUnderTest.UpdateFuncs(registeredProvider)
77
78         assert.Nil(t, err)
79         assert.Len(t, *providerUnderTest.ApiProvFuncs, 3)
80         assert.Equal(t, funcIdAPF, *(*providerUnderTest.ApiProvFuncs)[0].ApiProvFuncId)
81         assert.Equal(t, funcIdAEF, *(*providerUnderTest.ApiProvFuncs)[1].ApiProvFuncId)
82         assert.Equal(t, "AEF_id_func_info", *(*providerUnderTest.ApiProvFuncs)[2].ApiProvFuncId)
83 }