2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Nordix Foundation
4 * Modifications Copyright (C) 2023 TechMahindra Ltd.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.spi
24 import org.onap.cps.spi.exceptions.DataValidationException
25 import spock.lang.Specification
27 class FetchDescendantsOptionSpec extends Specification {
28 def 'Check has next descendant for fetch descendant option: #scenario'() {
29 when: 'fetch descendant option with #depth depth'
30 def fetchDescendantsOption = new FetchDescendantsOption(depth)
31 then: 'next level descendants available: #expectedHasNext'
32 fetchDescendantsOption.hasNext() == expectedHasNext
33 where: 'following parameters are used'
34 scenario | depth || expectedHasNext
35 'omit descendants' | 0 || false
36 'first child' | 1 || true
37 'second child' | 2 || true
38 'include all descendants' | -1 || true
41 def 'Check has next descendant for fetch descendant option: invalid depth'() {
42 given: 'fetch descendant option with -2 depth'
43 def fetchDescendantsOption = new FetchDescendantsOption(-2)
44 when: 'next level descendants not available'
45 fetchDescendantsOption.hasNext()
46 then: 'exception thrown'
47 thrown IllegalArgumentException
50 def 'Get next descendant for fetch descendant option: #scenario'() {
51 when: 'fetch descendant option with #depth depth'
52 def fetchDescendantsOption = new FetchDescendantsOption(depth)
53 then: 'the next level of depth is as expected'
54 fetchDescendantsOption.next().depth == depth - 1
55 where: 'following parameters are used'
61 def 'Get next descendant for fetch descendant option: include all descendants'() {
62 when: 'fetch descendant option with -1 depth'
63 def fetchDescendantsOption = new FetchDescendantsOption(-1)
64 then: 'the next level of depth is as expected'
65 fetchDescendantsOption.next().depth == -1
68 def 'Get next descendant for fetch descendant option: omit descendants'() {
69 given: 'fetch descendant option with 0 depth'
70 def fetchDescendantsOption = new FetchDescendantsOption(0)
71 when: 'the next level of depth is not allowed'
72 fetchDescendantsOption.next()
73 then: 'exception thrown'
74 thrown IllegalArgumentException
77 def 'Create fetch descendant option with descendant using #scenario'() {
78 when: 'the next level of depth is not allowed'
79 def FetchDescendantsOption fetchDescendantsOption = FetchDescendantsOption.getFetchDescendantsOption(fetchDescendantsOptionAsString)
80 then: 'fetch descendant object created'
81 assert fetchDescendantsOption.depth == expectedDepth
82 where: 'following parameters are used'
83 scenario | fetchDescendantsOptionAsString || expectedDepth
84 'all descendants using number' | '-1' || -1
85 'all descendants using all' | 'all' || -1
86 'No descendants by default' | '' || 0
87 'No descendants using none' | 'none' || 0
88 'til 10th descendants using number' | '10' || 10