aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-12-02 14:49:10 +0000
committerdanielhanrahan <daniel.hanrahan@est.tech>2024-12-03 15:49:03 +0000
commitcca2dc7d661fa6fbad66bfdde2638b7bfd6b9bcd (patch)
tree5dc4327ea1008a881bb059769537cf256a57e107 /cps-service
parent902d17332d3e5cebe545991e01a5e55f739f0f80 (diff)
Add tests of attribute-axis feature
Following TDD, functional acceptance tests are added for attribute-axis feature. This covers xpaths such as '//books/@title' - Add stub to CpsQueryService throwing UnsupportedOperationException - Add tests showing expected behaviour (tests currently ignored) - Implementation will be provided in following commmit for CPS-2416 Issue-ID: CPS-2416 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I71817e66b28dfc21e7b75243fd0135f3cceddb8e
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java15
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsQueryServiceImpl.java19
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy8
3 files changed, 36 insertions, 6 deletions
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 edd2d2ad32..34dcbb9e32 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2022 Nordix Foundation
+ * Copyright (C) 2020-2024 Nordix Foundation
* Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
package org.onap.cps.api;
import java.util.Collection;
+import java.util.Set;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.PaginationOption;
import org.onap.cps.spi.model.DataNode;
@@ -44,6 +45,18 @@ public interface CpsQueryService {
Collection<DataNode> queryDataNodes(String dataspaceName, String anchorName,
String cpsPath, FetchDescendantsOption fetchDescendantsOption);
+
+ /**
+ * Get data leaf for the given dataspace and anchor by cps path.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param cpsPath cps path
+ * @param targetClass class of the expected data type
+ * @return a collection of data objects of expected type
+ */
+ <T> Set<T> queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, Class<T> targetClass);
+
/**
* Get data nodes for the given dataspace across all anchors by cps path.
*
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 d1c98986e6..1de7c1733e 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation
+ * Copyright (C) 2021-2024 Nordix Foundation
* Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,7 @@ package org.onap.cps.api.impl;
import io.micrometer.core.annotation.Timed;
import java.util.Collection;
+import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.onap.cps.api.CpsQueryService;
import org.onap.cps.impl.utils.CpsValidator;
@@ -43,15 +44,23 @@ public class CpsQueryServiceImpl implements CpsQueryService {
@Timed(value = "cps.data.service.datanode.query",
description = "Time taken to query data nodes")
public Collection<DataNode> queryDataNodes(final String dataspaceName, final String anchorName,
- final String cpsPath, final FetchDescendantsOption fetchDescendantsOption) {
+ final String cpsPath,
+ final FetchDescendantsOption fetchDescendantsOption) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
return cpsDataPersistenceService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption);
}
@Override
- public Collection<DataNode> queryDataNodesAcrossAnchors(final String dataspaceName,
- final String cpsPath, final FetchDescendantsOption fetchDescendantsOption,
- final PaginationOption paginationOption) {
+ public <T> Set<T> queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath,
+ final Class<T> targetClass) {
+ cpsValidator.validateNameCharacters(dataspaceName, anchorName);
+ throw new UnsupportedOperationException("Query by attribute-axis not implemented yet!");
+ }
+
+ @Override
+ public Collection<DataNode> queryDataNodesAcrossAnchors(final String dataspaceName, final String cpsPath,
+ final FetchDescendantsOption fetchDescendantsOption,
+ final PaginationOption paginationOption) {
cpsValidator.validateNameCharacters(dataspaceName);
cpsValidator.validatePaginationOption(paginationOption);
return cpsDataPersistenceService.queryDataNodesAcrossAnchors(dataspaceName, cpsPath,
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 3b10669ddb..74127e095f 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
@@ -71,4 +71,12 @@ class CpsQueryServiceImplSpec extends Specification {
then: 'the persistence service is called once with the correct parameters'
1 * mockCpsDataPersistenceService.countAnchorsForDataspaceAndCpsPath("some-dataspace", "/cps-path")
}
+
+ // TODO will be implemented in CPS-2416
+ def 'Query data leaf.'() {
+ when: 'a query for a specific leaf is executed'
+ objectUnderTest.queryDataLeaf('some-dataspace', 'some-anchor', '/cps-path/@id', Object.class)
+ then: 'solution is not implemented yet'
+ thrown(UnsupportedOperationException)
+ }
}