2 // ========================LICENSE_START=================================
5 // Copyright (C) 2023: Nordix Foundation
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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===================================
21 package providermanagementapi
26 "github.com/stretchr/testify/assert"
30 domainID = "domain_id_rApp_domain"
31 otherDomainID = "domain_id_other_domain"
32 domainInfo = "rApp domain"
33 funcInfoAPF = "rApp as APF"
34 funcIdAPF = "APF_id_rApp_as_APF"
35 funcInfoAMF = "rApp as AMF"
36 funcIdAMF = "AMF_id_rApp_as_AMF"
37 funcInfoAEF = "rApp as AEF"
38 funcIdAEF = "AEF_id_rApp_as_AEF"
41 func TestValidateRegistrationInformation(t *testing.T) {
42 regInfoUnderTest := RegistrationInformation{}
43 err := regInfoUnderTest.Validate()
44 if assert.Error(t, err) {
45 assert.Contains(t, err.Error(), "missing")
46 assert.Contains(t, err.Error(), "apiProvPubKey")
49 regInfoUnderTest.ApiProvPubKey = "key"
50 err = regInfoUnderTest.Validate()
54 func TestValidateAPIProviderFunctionDetails(t *testing.T) {
55 funcDetailsUnderTest := APIProviderFunctionDetails{}
56 err := funcDetailsUnderTest.Validate()
57 if assert.Error(t, err) {
58 assert.Contains(t, err.Error(), "missing")
59 assert.Contains(t, err.Error(), "apiProvFuncRole")
62 funcDetailsUnderTest.ApiProvFuncRole = ApiProviderFuncRoleAEF
63 err = funcDetailsUnderTest.Validate()
64 if assert.Error(t, err) {
65 assert.Contains(t, err.Error(), "missing")
66 assert.Contains(t, err.Error(), "apiProvPubKey")
69 funcDetailsUnderTest.RegInfo = RegistrationInformation{
72 assert.Nil(t, funcDetailsUnderTest.Validate())
75 func TestValidateAPIProviderEnrolmentDetails(t *testing.T) {
76 providerDetailsUnderTest := APIProviderEnrolmentDetails{}
77 err := providerDetailsUnderTest.Validate()
78 if assert.Error(t, err) {
79 assert.Contains(t, err.Error(), "missing")
80 assert.Contains(t, err.Error(), "regSec")
83 providerDetailsUnderTest.RegSec = "sec"
84 funcs := []APIProviderFunctionDetails{{}}
85 providerDetailsUnderTest.ApiProvFuncs = &funcs
86 err = providerDetailsUnderTest.Validate()
87 if assert.Error(t, err) {
88 assert.Contains(t, err.Error(), "apiProvFuncs")
89 assert.Contains(t, err.Error(), "contains invalid")
92 (*providerDetailsUnderTest.ApiProvFuncs)[0] = APIProviderFunctionDetails{
93 ApiProvFuncRole: ApiProviderFuncRoleAEF,
94 RegInfo: RegistrationInformation{
98 assert.Nil(t, providerDetailsUnderTest.Validate())
101 func getProvider() APIProviderEnrolmentDetails {
102 testFuncs := []APIProviderFunctionDetails{
104 ApiProvFuncId: &funcIdAPF,
105 ApiProvFuncInfo: &funcInfoAPF,
106 ApiProvFuncRole: ApiProviderFuncRoleAPF,
109 ApiProvFuncId: &funcIdAMF,
110 ApiProvFuncInfo: &funcInfoAMF,
111 ApiProvFuncRole: ApiProviderFuncRoleAMF,
114 ApiProvFuncId: &funcIdAEF,
115 ApiProvFuncInfo: &funcInfoAEF,
116 ApiProvFuncRole: ApiProviderFuncRoleAEF,
119 return APIProviderEnrolmentDetails{
120 ApiProvDomId: &domainID,
121 ApiProvDomInfo: &domainInfo,
122 ApiProvFuncs: &testFuncs,