2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2022 Nordix Foundation
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
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.api.impl
23 import org.onap.cps.api.CpsAdminService
24 import org.onap.cps.api.CpsModuleService
25 import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
26 import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations
27 import org.onap.cps.ncmp.api.models.PersistenceCmHandle
28 import org.onap.cps.spi.model.ModuleReference
29 import org.onap.cps.utils.JsonObjectMapper
30 import spock.lang.Specification
32 class NetworkCmProxyDataServiceImplModelSyncSpec extends Specification {
34 def mockJsonObjectMapper = Mock(JsonObjectMapper)
35 def mockCpsModuleService = Mock(CpsModuleService)
36 def mockCpsAdminService = Mock(CpsAdminService)
37 def mockDmiModelOperations = Mock(DmiModelOperations)
38 def mockDmiDataOperations = Mock(DmiDataOperations)
40 def objectUnderTest = new NetworkCmProxyDataServiceImpl(null, mockJsonObjectMapper, mockDmiDataOperations, mockDmiModelOperations,
41 mockCpsModuleService, mockCpsAdminService)
43 def expectedDataspaceName = 'NFP-Operational'
45 def 'Sync model for a (new) cm handle with #scenario'() {
46 given: 'persistence cm handle is given'
47 def cmHandleForModelSync = new PersistenceCmHandle(id:'some cm handle', dmiServiceName: 'some service name')
48 and: 'additional properties are set as required'
49 if (additionalProperties!=null) {
50 cmHandleForModelSync.asAdditionalProperties(additionalProperties)
52 and: 'dmi operations returns some module references'
53 def moduleReferences = [ new ModuleReference(moduleName:'module1',revision:'1'),
54 new ModuleReference(moduleName:'module2',revision:'2') ]
55 mockDmiModelOperations.getModuleReferences(cmHandleForModelSync) >> moduleReferences
56 and: 'CPS-Core returns list of existing module resources'
57 mockCpsModuleService.getYangResourceModuleReferences(expectedDataspaceName) >> existingModuleResourcesInCps
58 and: 'DMI-Plugin returns resource(s) for "new" module(s)'
59 mockDmiModelOperations.getNewYangResourcesFromDmi(cmHandleForModelSync, [new ModuleReference('module1', '1')]) >> yangResourceToContentMap
60 when: 'module sync is triggered'
61 objectUnderTest.syncModulesAndCreateAnchor(cmHandleForModelSync)
62 then: 'the CPS module service is called once with the correct parameters'
63 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, cmHandleForModelSync.getId(), yangResourceToContentMap, expectedKnownModules)
64 and: 'admin service create anchor method has been called with correct parameters'
65 1 * mockCpsAdminService.createAnchor(expectedDataspaceName, cmHandleForModelSync.getId(), cmHandleForModelSync.getId())
66 where: 'the following parameters are used'
67 scenario | additionalProperties | existingModuleResourcesInCps | yangResourceToContentMap || expectedKnownModules | expectedJsonForAdditionalProperties
68 'one unknown module' | ['name1': 'value1'] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')] | '{"name1":"value1"}'
69 'no add. properties' | [:] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')] | '{}'
70 'additional properties is null' | null | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')] | '{}'
71 'no unknown module' | [:] | [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] | [:] || [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] | '{}'