From cca2dc7d661fa6fbad66bfdde2638b7bfd6b9bcd Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Mon, 2 Dec 2024 14:49:10 +0000 Subject: 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 Change-Id: I71817e66b28dfc21e7b75243fd0135f3cceddb8e --- .../main/java/org/onap/cps/api/CpsQueryService.java | 15 ++++++++++++++- .../org/onap/cps/api/impl/CpsQueryServiceImpl.java | 19 ++++++++++++++----- .../onap/cps/api/impl/CpsQueryServiceImplSpec.groovy | 8 ++++++++ 3 files changed, 36 insertions(+), 6 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 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 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 + */ + Set queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, Class 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 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 queryDataNodesAcrossAnchors(final String dataspaceName, - final String cpsPath, final FetchDescendantsOption fetchDescendantsOption, - final PaginationOption paginationOption) { + public Set queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath, + final Class targetClass) { + cpsValidator.validateNameCharacters(dataspaceName, anchorName); + throw new UnsupportedOperationException("Query by attribute-axis not implemented yet!"); + } + + @Override + public Collection 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) + } } -- cgit 1.2.3-korg