From 32446dce35b5bf9d2c84751718cb4ece7f96fa72 Mon Sep 17 00:00:00 2001 From: niamhcore Date: Mon, 1 Mar 2021 13:25:13 +0000 Subject: CPS-265 - updating cps path to support include-descendants option. Issue-ID: CPS-265 Signed-off-by: niamhcore Change-Id: I9e9b84760dbc8b5eb4b31ab972fdb2d186c6bb48 --- .../src/main/java/org/onap/cps/api/CpsQueryService.java | 5 ++++- .../main/java/org/onap/cps/api/impl/CpsQueryServiceImpl.java | 5 +++-- .../java/org/onap/cps/spi/CpsDataPersistenceService.java | 4 +++- .../org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy | 12 +++++++++--- 4 files changed, 19 insertions(+), 7 deletions(-) (limited to 'cps-service') diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java b/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java index b432af800..0f4bf2dc4 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java @@ -21,6 +21,7 @@ package org.onap.cps.api; import java.util.Collection; import org.checkerframework.checker.nullness.qual.NonNull; +import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; /* @@ -34,9 +35,11 @@ public interface CpsQueryService { * @param dataspaceName dataspace name * @param anchorName anchor name * @param cpsPath cps path + * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be + * included in the output * @return a collection of data nodes */ Collection queryDataNodes(@NonNull String dataspaceName, @NonNull String anchorName, - @NonNull String cpsPath); + @NonNull String cpsPath, @NonNull FetchDescendantsOption fetchDescendantsOption); } diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsQueryServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsQueryServiceImpl.java index 63d0a0fbb..79fa6c717 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsQueryServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsQueryServiceImpl.java @@ -22,6 +22,7 @@ package org.onap.cps.api.impl; import java.util.Collection; import org.onap.cps.api.CpsQueryService; import org.onap.cps.spi.CpsDataPersistenceService; +import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -34,7 +35,7 @@ public class CpsQueryServiceImpl implements CpsQueryService { @Override public Collection queryDataNodes(final String dataspaceName, final String anchorName, - final String cpsPath) { - return cpsDataPersistenceService.queryDataNodes(dataspaceName, anchorName, cpsPath); + final String cpsPath, final FetchDescendantsOption fetchDescendantsOption) { + return cpsDataPersistenceService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption); } } \ No newline at end of file diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java index d2b6d45d6..48f9763ee 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java @@ -94,8 +94,10 @@ public interface CpsDataPersistenceService { * @param dataspaceName dataspace name * @param anchorName anchor name * @param cpsPath cps path + * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be + * included in the output * @return the data nodes found i.e. 0 or more data nodes */ Collection queryDataNodes(@NonNull String dataspaceName, @NonNull String anchorName, - @NonNull String cpsPath); + @NonNull String cpsPath, @NonNull FetchDescendantsOption fetchDescendantsOption); } 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 6e044b044..99d25ecfc 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 @@ -20,7 +20,10 @@ package org.onap.cps.api.impl import org.onap.cps.spi.CpsDataPersistenceService +import org.onap.cps.spi.FetchDescendantsOption import spock.lang.Specification +import spock.lang.Unroll + class CpsQueryServiceImplSpec extends Specification { def mockCpsDataPersistenceService = Mock(CpsDataPersistenceService) @@ -31,14 +34,17 @@ class CpsQueryServiceImplSpec extends Specification { objectUnderTest.cpsDataPersistenceService = mockCpsDataPersistenceService } - def 'Query data nodes by cps path.'() { + @Unroll + def 'Query data nodes by cps path with #fetchDescendantsOption.'() { given: 'a dataspace name, an anchor name and a cps path' def dataspaceName = 'some dataspace' def anchorName = 'some anchor' def cpsPath = '/cps-path' when: 'queryDataNodes is invoked' - objectUnderTest.queryDataNodes(dataspaceName, anchorName, cpsPath) + objectUnderTest.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption) then: 'the persistence service is called once with the correct parameters' - 1 * mockCpsDataPersistenceService.queryDataNodes(dataspaceName, anchorName, cpsPath) + 1 * mockCpsDataPersistenceService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption) + where: 'all fetch descendants options are supported' + fetchDescendantsOption << FetchDescendantsOption.values() } } \ No newline at end of file -- cgit 1.2.3-korg