2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
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.integration.functional.ncmp.inventory
23 import org.onap.cps.integration.base.CpsIntegrationSpecBase
25 import static org.hamcrest.Matchers.containsInAnyOrder
26 import static org.hamcrest.Matchers.emptyString
27 import static org.hamcrest.Matchers.everyItem
28 import static org.hamcrest.Matchers.equalTo
29 import static org.hamcrest.Matchers.hasSize
30 import static org.hamcrest.Matchers.is
31 import static org.hamcrest.Matchers.not
32 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
33 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
34 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
36 class ModulesRestApiSpec extends CpsIntegrationSpecBase {
39 dmiDispatcher1.moduleNamesPerCmHandleId['ch-1'] = ['M1', 'M2']
40 dmiDispatcher1.moduleNamesPerCmHandleId['ch-2'] = ['M1', 'M3']
41 dmiDispatcher1.moduleNamesPerCmHandleId['ch-3'] = ['M4']
42 registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, 'alt-1')
43 registerCmHandle(DMI1_URL, 'ch-2', NO_MODULE_SET_TAG, 'alt-2')
44 registerCmHandle(DMI1_URL, 'ch-3', 'my-module-set-tag', 'alt-3')
45 // Note DMI dispatcher is not configured to return modules for this handle, so module sync will fail
46 registerCmHandleWithoutWaitForReady(DMI1_URL, 'not-ready-id', NO_MODULE_SET_TAG, NO_ALTERNATE_ID)
50 deregisterCmHandles(DMI1_URL, ['ch-1', 'ch-2', 'ch-3', 'not-ready-id'])
53 def 'Get yang module references returns expected modules with #scenario.'() {
54 expect: 'get module references API to return expected modules'
55 mvc.perform(get("/ncmp/v1/ch/${cmHandleReference}/modules"))
56 .andExpect(status().is2xxSuccessful())
57 .andExpect(jsonPath('$', hasSize(expectedModuleNames.size())))
58 .andExpect(jsonPath('$[*].moduleName', containsInAnyOrder(expectedModuleNames.toArray())))
59 .andExpect(jsonPath('$[*].revision', everyItem(equalTo('2024-01-01'))))
60 where: 'following scenarios are applied'
61 scenario | cmHandleReference || expectedModuleNames
62 'cm-handle id' | 'ch-1' || ['M1', 'M2']
63 'alternate id' | 'alt-2' || ['M1', 'M3']
64 'CM handle with module set tag' | 'ch-3' || ['M4']
65 'not ready CM handle' | 'not-ready-id' || []
66 'non-existing CM handle' | 'non-existing' || []
69 def 'Get yang module definitions returns expected modules with #scenario.'() {
70 expect: 'get module definitions API to return expected module definitions'
71 mvc.perform(get("/ncmp/v1/ch/${cmHandleReference}/modules/definitions"))
72 .andExpect(status().is2xxSuccessful())
73 .andExpect(jsonPath('$', hasSize(expectedModuleNames.size())))
74 .andExpect(jsonPath('$[*].moduleName', containsInAnyOrder(expectedModuleNames.toArray())))
75 .andExpect(jsonPath('$[*].revision', everyItem(equalTo('2024-01-01'))))
76 .andExpect(jsonPath('$[*].content', not(is(emptyString()))))
77 where: 'following scenarios are applied'
78 scenario | cmHandleReference || expectedModuleNames
79 'cm-handle id' | 'ch-1' || ['M1', 'M2']
80 'alternate id' | 'alt-2' || ['M1', 'M3']
81 'CM handle with module set tag' | 'ch-3' || ['M4']
82 'not ready CM handle' | 'not-ready-id' || []
83 'non-existing CM handle' | 'non-existing' || []
86 def 'Get yang module definition for specific module with #scenario.'() {
87 expect: 'get module definition API to return definition of requested module name and revision'
88 mvc.perform(get("/ncmp/v1/ch/${cmHandleReference}/modules/definitions")
89 .queryParam('module-name', requestedModuleName)
90 .queryParam('revision', '2024-01-01'))
91 .andExpect(status().is2xxSuccessful())
92 .andExpect(jsonPath('$', hasSize(expectedModuleNames.size())))
93 .andExpect(jsonPath('$[*].moduleName', containsInAnyOrder(expectedModuleNames.toArray())))
94 .andExpect(jsonPath('$[*].revision', everyItem(equalTo('2024-01-01'))))
95 .andExpect(jsonPath('$[*].content', not(is(emptyString()))))
96 where: 'following scenarios are applied'
97 scenario | cmHandleReference | requestedModuleName || expectedModuleNames
98 'cm-handle id' | 'ch-1' | 'M1' || ['M1']
99 'alternate id' | 'alt-2' | 'M1' || ['M1']
100 'non-existing module' | 'ch-1' | 'non-existing' || []
101 'not ready CM handle' | 'not-ready-id' | 'not-relevant' || []
102 'non-existing CM handle' | 'non-existing' | 'not-relevant' || []