From 048350463a68b774f42e80e94afe16a541711ae4 Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Thu, 23 Feb 2023 15:49:40 +0000 Subject: Expand CPS Service Integration Test (framework) - Created package structure - Created several test bases - Created complete test set for Admin service - Created first test for Data service - Added human-readable toString() to FetchDescendantsOption for test reporting and debuging purposes - Renamed fetch descendants (enum) direct children option for consistency with others options - TODO: Add sample performance test (and base) Issue-ID: CPS-475 Signed-off-by: ToineSiebelink Change-Id: I75317686161be41662b6bf81314a9cd425ddd6eb --- .../org/onap/cps/spi/FetchDescendantsOption.java | 22 +++++++++++++--- .../cps/api/impl/CpsQueryServiceImplSpec.groovy | 4 +-- .../onap/cps/spi/FetchDescendantsOptionSpec.groovy | 30 +++++++++++++++------- 3 files changed, 41 insertions(+), 15 deletions(-) (limited to 'cps-service') 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 0c8cddcd7..cf5e04dc4 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 @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2021 Pantheon.tech - * Copyright (C) 2022 Nordix Foundation + * Copyright (C) 2022-2023 Nordix Foundation * Modifications Copyright (C) 2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,15 +30,24 @@ import org.onap.cps.spi.exceptions.DataValidationException; @RequiredArgsConstructor public class FetchDescendantsOption { - public static final FetchDescendantsOption FETCH_DIRECT_CHILDREN_ONLY = new FetchDescendantsOption(1); - public static final FetchDescendantsOption OMIT_DESCENDANTS = new FetchDescendantsOption(0); - public static final FetchDescendantsOption INCLUDE_ALL_DESCENDANTS = new FetchDescendantsOption(-1); + public static final FetchDescendantsOption DIRECT_CHILDREN_ONLY + = new FetchDescendantsOption(1, "DirectChildrenOnly"); + public static final FetchDescendantsOption OMIT_DESCENDANTS + = new FetchDescendantsOption(0, "OmitDescendants"); + public static final FetchDescendantsOption INCLUDE_ALL_DESCENDANTS + = new FetchDescendantsOption(-1, "IncludeAllDescendants"); + + FetchDescendantsOption(final int depth) { + this(depth, "Depth=" + depth); + } private static final Pattern FETCH_DESCENDANTS_OPTION_PATTERN = Pattern.compile("^$|^all$|^none$|^[0-9]+$|^-1$"); private final int depth; + private final String optionName; + /** * Has next depth. * @@ -85,6 +94,11 @@ public class FetchDescendantsOption { } } + @Override + public String toString() { + return optionName; + } + private static void validateFetchDescendantsOption(final String fetchDescendantsOptionAsString) { if (Strings.isNullOrEmpty(fetchDescendantsOptionAsString)) { return; 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 60286b664..56c43d163 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 @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation + * Copyright (C) 2021-2023 Nordix Foundation * Modifications Copyright (C) 2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -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.FETCH_DIRECT_CHILDREN_ONLY, new FetchDescendantsOption(10)] + FetchDescendantsOption.DIRECT_CHILDREN_ONLY, new FetchDescendantsOption(10)] } } 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 c4d3dd8b7..24f3487d1 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 @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation + * Copyright (C) 2022-2023 Nordix Foundation * Modifications Copyright (C) 2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,15 +21,15 @@ package org.onap.cps.spi -import org.onap.cps.spi.exceptions.DataValidationException import spock.lang.Specification class FetchDescendantsOptionSpec extends Specification { - def 'Check has next descendant for fetch descendant option: #scenario'() { + + def 'Has next descendant for fetch descendant option: #scenario'() { when: 'fetch descendant option with #depth depth' def fetchDescendantsOption = new FetchDescendantsOption(depth) then: 'next level descendants available: #expectedHasNext' - fetchDescendantsOption.hasNext() == expectedHasNext + assert fetchDescendantsOption.hasNext() == expectedHasNext where: 'following parameters are used' scenario | depth || expectedHasNext 'omit descendants' | 0 || false @@ -38,7 +38,7 @@ class FetchDescendantsOptionSpec extends Specification { 'include all descendants' | -1 || true } - def 'Check has next descendant for fetch descendant option: invalid depth'() { + def 'Has next descendant for fetch descendant option: invalid depth'() { given: 'fetch descendant option with -2 depth' def fetchDescendantsOption = new FetchDescendantsOption(-2) when: 'next level descendants not available' @@ -47,7 +47,7 @@ class FetchDescendantsOptionSpec extends Specification { thrown IllegalArgumentException } - def 'Get next descendant for fetch descendant option: #scenario'() { + def 'Next descendant for fetch descendant option: #scenario.'() { when: 'fetch descendant option with #depth depth' def fetchDescendantsOption = new FetchDescendantsOption(depth) then: 'the next level of depth is as expected' @@ -58,14 +58,14 @@ class FetchDescendantsOptionSpec extends Specification { 'second child' | 2 } - def 'Get next descendant for fetch descendant option: include all descendants'() { + def 'Next descendant for fetch descendant option: include all descendants.'() { when: 'fetch descendant option with -1 depth' def fetchDescendantsOption = new FetchDescendantsOption(-1) then: 'the next level of depth is as expected' fetchDescendantsOption.next().depth == -1 } - def 'Get next descendant for fetch descendant option: omit descendants'() { + def 'Next descendant for fetch descendant option: omit descendants.'() { given: 'fetch descendant option with 0 depth' def fetchDescendantsOption = new FetchDescendantsOption(0) when: 'the next level of depth is not allowed' @@ -74,7 +74,7 @@ class FetchDescendantsOptionSpec extends Specification { thrown IllegalArgumentException } - def 'Create fetch descendant option with descendant using #scenario'() { + def 'Create fetch descendant option with descendant using #scenario.'() { when: 'the next level of depth is not allowed' def FetchDescendantsOption fetchDescendantsOption = FetchDescendantsOption.getFetchDescendantsOption(fetchDescendantsOptionAsString) then: 'fetch descendant object created' @@ -87,4 +87,16 @@ class FetchDescendantsOptionSpec extends Specification { 'No descendants using none' | 'none' || 0 'til 10th descendants using number' | '10' || 10 } + + def 'String values.'() { + expect: 'each fetch descendant option has the correct String value' + assert fetchDescendantsOption.toString() == expectedStringValue + where: 'the following option is used' + fetchDescendantsOption || expectedStringValue + FetchDescendantsOption.OMIT_DESCENDANTS || 'OmitDescendants' + FetchDescendantsOption.DIRECT_CHILDREN_ONLY || 'DirectChildrenOnly' + FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS || 'IncludeAllDescendants' + new FetchDescendantsOption(2) || 'Depth=2' + } + } -- cgit 1.2.3-korg