aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src
diff options
context:
space:
mode:
authorRudrangi Anupriya <ra00745022@techmahindra.com>2023-07-28 14:28:54 +0530
committerRudrangi Anupriya <ra00745022@techmahindra.com>2023-07-28 14:29:10 +0530
commit8126f03d255341973112daaec2efaf90e3a40832 (patch)
tree4f903b2a8495186d6a48c02e277a40bd26f44148 /cps-service/src
parent16e9ea97a6a46f3e59cf600a528953c9c0e8e48c (diff)
Add 'direct' keyword to descendants option to query direct children (ep1)
-added 'direct' keyword also to Fetch Descendants Option along with 'all' and 'none' to Query direct child. -added unit tests to test direct keyword Issue-ID:CPS-1784 Change-Id: Iab7f59fbeebb03703626132c6d5c2afde0e5ab4d Signed-off-by: Rudrangi Anupriya <ra00745022@techmahindra.com>
Diffstat (limited to 'cps-service/src')
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/FetchDescendantsOption.java8
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy2
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/spi/FetchDescendantsOptionSpec.groovy4
3 files changed, 9 insertions, 5 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/spi/FetchDescendantsOption.java b/cps-service/src/main/java/org/onap/cps/spi/FetchDescendantsOption.java
index 02574995d..76d9bba7e 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/FetchDescendantsOption.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/FetchDescendantsOption.java
@@ -30,8 +30,8 @@ import org.onap.cps.spi.exceptions.DataValidationException;
@RequiredArgsConstructor
public class FetchDescendantsOption {
- public static final FetchDescendantsOption DIRECT_CHILDREN_ONLY
- = new FetchDescendantsOption(1, "DirectChildrenOnly");
+ public static final FetchDescendantsOption DIRECT_CHILD_ONLY
+ = new FetchDescendantsOption(1, "DirectChildOnly");
public static final FetchDescendantsOption OMIT_DESCENDANTS
= new FetchDescendantsOption(0, "OmitDescendants");
public static final FetchDescendantsOption INCLUDE_ALL_DESCENDANTS
@@ -42,7 +42,7 @@ public class FetchDescendantsOption {
}
private static final Pattern FETCH_DESCENDANTS_OPTION_PATTERN =
- Pattern.compile("^$|^all$|^none$|^[0-9]+$|^-1$");
+ Pattern.compile("^$|^all$|^none$|^direct$|^[0-9]+$|^-1$|^1$");
private final int depth;
@@ -96,6 +96,8 @@ public class FetchDescendantsOption {
return FetchDescendantsOption.OMIT_DESCENDANTS;
} else if ("-1".equals(fetchDescendantsOptionAsString) || "all".equals(fetchDescendantsOptionAsString)) {
return FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
+ } else if ("1".equals(fetchDescendantsOptionAsString) || "direct".equals(fetchDescendantsOptionAsString)) {
+ return FetchDescendantsOption.DIRECT_CHILD_ONLY;
} else {
final Integer depth = Integer.valueOf(fetchDescendantsOptionAsString);
return new FetchDescendantsOption(depth);
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy
index 553027a4b..4e3d27964 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy
@@ -45,7 +45,7 @@ class CpsQueryServiceImplSpec extends Specification {
1 * mockCpsValidator.validateNameCharacters(dataspaceName, anchorName)
where: 'all fetch descendants options are supported'
fetchDescendantsOption << [FetchDescendantsOption.OMIT_DESCENDANTS, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS,
- FetchDescendantsOption.DIRECT_CHILDREN_ONLY, new FetchDescendantsOption(10)]
+ FetchDescendantsOption.DIRECT_CHILD_ONLY, new FetchDescendantsOption(10)]
}
def 'Query data nodes across all anchors by cps path with #fetchDescendantsOption.'() {
diff --git a/cps-service/src/test/groovy/org/onap/cps/spi/FetchDescendantsOptionSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/spi/FetchDescendantsOptionSpec.groovy
index 24f3487d1..b095bfd3d 100644
--- a/cps-service/src/test/groovy/org/onap/cps/spi/FetchDescendantsOptionSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/spi/FetchDescendantsOptionSpec.groovy
@@ -85,6 +85,8 @@ class FetchDescendantsOptionSpec extends Specification {
'all descendants using all' | 'all' || -1
'No descendants by default' | '' || 0
'No descendants using none' | 'none' || 0
+ 'direct child using number' | '1' || 1
+ 'direct child using direct' | 'direct' || 1
'til 10th descendants using number' | '10' || 10
}
@@ -94,7 +96,7 @@ class FetchDescendantsOptionSpec extends Specification {
where: 'the following option is used'
fetchDescendantsOption || expectedStringValue
FetchDescendantsOption.OMIT_DESCENDANTS || 'OmitDescendants'
- FetchDescendantsOption.DIRECT_CHILDREN_ONLY || 'DirectChildrenOnly'
+ FetchDescendantsOption.DIRECT_CHILD_ONLY || 'DirectChildOnly'
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS || 'IncludeAllDescendants'
new FetchDescendantsOption(2) || 'Depth=2'
}