diff options
author | Toine Siebelink <toine.siebelink@est.tech> | 2022-06-08 10:03:11 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-06-08 10:03:11 +0000 |
commit | 1410509e33142c0c79ff0e111c63abc47f5936d3 (patch) | |
tree | e6cff729363085bc7052fc0ad00c9f3075b16e3c /cps-ncmp-rest | |
parent | 5e80e3776bb47483ca71bcc3fbe2cd8c2b9389e3 (diff) | |
parent | e9ed581de0a6090c513e6fca0052b69396cb3cc8 (diff) |
Merge "Merge 2 'query' end points in NCMP"
Diffstat (limited to 'cps-ncmp-rest')
8 files changed, 245 insertions, 134 deletions
diff --git a/cps-ncmp-rest/docs/openapi/components.yaml b/cps-ncmp-rest/docs/openapi/components.yaml index 5fe47e4b0f..248b1daa61 100644 --- a/cps-ncmp-rest/docs/openapi/components.yaml +++ b/cps-ncmp-rest/docs/openapi/components.yaml @@ -133,52 +133,7 @@ components: type: string example: my-property - Conditions: - type: object - properties: - conditions: - $ref: '#/components/schemas/ConditionsData' - ConditionsData: - type: array - items: - type: object - $ref: '#/components/schemas/ConditionProperties' - ConditionProperties: - properties: - name: - type: string - example: hasAllModules - conditionParameters: - $ref: '#/components/schemas/ModuleNamesAsJsonArray' - ModuleNamesAsJsonArray: - type: array - items: - type: object - $ref: '#/components/schemas/ModuleNameAsJsonObject' - example: [my-module-1, my-module-2, my-module-3] - ModuleNameAsJsonObject: - properties: - moduleName: - type: string - example: my-module - #Response Schemas - CmHandles: - type: object - properties: - cmHandles: - $ref: '#/components/schemas/CmHandleProperties' - CmHandleProperties: - type: array - items: - type: object - $ref: '#/components/schemas/CmHandleProperty' - CmHandleProperty: - properties: - cmHandleId: - type: string - example: my-cm-handle-id - RestModuleReference: type: object title: Module reference details @@ -190,15 +145,59 @@ components: type: string example: my-module-revision - CmHandleQueryRestParameters: + CmHandleQueryParameters: type: object title: Cm Handle query parameters for executing cm handle search properties: - publicCmHandleProperties: - type: object - additionalProperties: - type: string - example: Book Type + cmHandleQueryParameters: + type: array + items: + type: object + $ref: '#/components/schemas/ConditionProperties' + conditions: + deprecated: true + type: array + items: + type: object + $ref: '#/components/schemas/OldConditionProperties' + description: not necessary, it is just for backward compatibility + example: + cmHandleQueryParameters: + - conditionName: hasAllModules + conditionParameters: + - { "moduleName": "my-module-1" } + - { "moduleName": "my-module-2" } + - { "moduleName": "my-module-3" } + - conditionName: hasAllProperties + conditionParameters: + - { "Color": "yellow" } + - { "Shape": "circle" } + - { "Size": "small" } + ConditionProperties: + properties: + conditionName: + type: string + conditionParameters: + type: array + items: + type: object + additionalProperties: + type: string + OldConditionProperties: + deprecated: true + properties: + name: + type: string + conditionParameters: + type: array + items: + type: object + $ref: '#/components/schemas/ModuleNameAsJsonObject' + ModuleNameAsJsonObject: + properties: + moduleName: + type: string + example: my-module RestOutputCmHandle: type: object diff --git a/cps-ncmp-rest/docs/openapi/ncmp.yml b/cps-ncmp-rest/docs/openapi/ncmp.yml index 318e6e66d9..7a894f5196 100755 --- a/cps-ncmp-rest/docs/openapi/ncmp.yml +++ b/cps-ncmp-rest/docs/openapi/ncmp.yml @@ -246,26 +246,28 @@ fetchModuleReferencesByCmHandle: 500: $ref: 'components.yaml#/components/responses/InternalServerError' -executeCmHandleSearch: +searchCmHandles: post: - description: Execute cm handle searches using 'hasAllModules' condition to get all cm handles for the given module names + description: Execute cm handle query search, to be included in the result a cm-handle must fulfill ALL the conditions listed here tags: - network-cm-proxy summary: Execute cm handle search using the available conditions - operationId: executeCmHandleSearch + operationId: searchCmHandles requestBody: required: true content: application/json: schema: - $ref: 'components.yaml#/components/schemas/Conditions' + $ref: 'components.yaml#/components/schemas/CmHandleQueryParameters' responses: 200: description: OK content: application/json: schema: - $ref: 'components.yaml#/components/schemas/CmHandles' + type: array + items: + $ref: 'components.yaml#/components/schemas/RestOutputCmHandle' 400: $ref: 'components.yaml#/components/responses/BadRequest' 401: @@ -317,19 +319,19 @@ getCmHandlePropertiesById: 500: $ref: 'components.yaml#/components/responses/InternalServerError' -queryCmHandles: +searchCmHandleIds: post: - description: Execute cm handle query search + description: Execute cm handle query search, to be included in the result a cm-handle must fulfill ALL the conditions listed here tags: - network-cm-proxy summary: Execute cm handle query upon a given set of query parameters - operationId: queryCmHandles + operationId: searchCmHandleIds requestBody: required: true content: application/json: schema: - $ref: 'components.yaml#/components/schemas/CmHandleQueryRestParameters' + $ref: 'components.yaml#/components/schemas/CmHandleQueryParameters' responses: 200: description: OK diff --git a/cps-ncmp-rest/docs/openapi/openapi.yml b/cps-ncmp-rest/docs/openapi/openapi.yml index b4082918f6..81ebf05edd 100755 --- a/cps-ncmp-rest/docs/openapi/openapi.yml +++ b/cps-ncmp-rest/docs/openapi/openapi.yml @@ -36,7 +36,7 @@ paths: $ref: 'ncmp.yml#/fetchModuleReferencesByCmHandle' /v1/ch/searches: - $ref: 'ncmp.yml#/executeCmHandleSearch' + $ref: 'ncmp.yml#/searchCmHandles' /v1/ch/{cm-handle}: $ref: 'ncmp.yml#/retrieveCmHandleDetailsById' @@ -44,5 +44,5 @@ paths: /v1/ch/{cm-handle}/properties: $ref: 'ncmp.yml#/getCmHandlePropertiesById' - /v1/data/ch/searches: - $ref: 'ncmp.yml#/queryCmHandles' + /v1/ch/id-searches: + $ref: 'ncmp.yml#/searchCmHandleIds' diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java index 11517bcc9e..ccb1e9bbb8 100755 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java @@ -28,9 +28,6 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH; import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -48,18 +45,12 @@ import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi; import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor; import org.onap.cps.ncmp.rest.mapper.RestOutputCmHandleStateMapper; -import org.onap.cps.ncmp.rest.model.CmHandleProperties; -import org.onap.cps.ncmp.rest.model.CmHandleProperty; import org.onap.cps.ncmp.rest.model.CmHandlePublicProperties; -import org.onap.cps.ncmp.rest.model.CmHandleQueryRestParameters; -import org.onap.cps.ncmp.rest.model.CmHandles; -import org.onap.cps.ncmp.rest.model.ConditionProperties; -import org.onap.cps.ncmp.rest.model.Conditions; -import org.onap.cps.ncmp.rest.model.ModuleNameAsJsonObject; -import org.onap.cps.ncmp.rest.model.ModuleNamesAsJsonArray; +import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; import org.onap.cps.ncmp.rest.model.RestModuleReference; import org.onap.cps.ncmp.rest.model.RestOutputCmHandle; import org.onap.cps.ncmp.rest.model.RestOutputCmHandlePublicProperties; +import org.onap.cps.ncmp.rest.util.DeprecationHelper; import org.onap.cps.utils.CpsValidator; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.beans.factory.annotation.Value; @@ -79,6 +70,8 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { private static final String NO_TOPIC = null; private final NetworkCmProxyDataService networkCmProxyDataService; private final JsonObjectMapper jsonObjectMapper; + + private final DeprecationHelper deprecationHelper; private final NcmpRestInputMapper ncmpRestInputMapper; private final RestOutputCmHandleStateMapper restOutputCmHandleStateMapper; private final CpsNcmpTaskExecutor cpsNcmpTaskExecutor; @@ -212,30 +205,35 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { } /** - * Execute cm handle search. + * Query and return cm handles that match the given query parameters. * - * @param conditions the conditions - * @return cm handles returned from search. + * @param cmHandleQueryParameters the cm handle query parameters + * @return collection of cm handles */ @Override - public ResponseEntity<CmHandles> executeCmHandleSearch(final Conditions conditions) { - final List<ConditionProperties> conditionProperties = - conditions.getConditions().stream().collect(Collectors.toList()); - final CmHandles cmHandles = new CmHandles(); - cmHandles.setCmHandles(toCmHandleProperties(processConditions(conditionProperties))); - return ResponseEntity.ok(cmHandles); + public ResponseEntity<List<RestOutputCmHandle>> searchCmHandles( + final CmHandleQueryParameters cmHandleQueryParameters) { + final CmHandleQueryApiParameters cmHandleQueryApiParameters = + deprecationHelper.mapOldConditionProperties(cmHandleQueryParameters); + final Set<NcmpServiceCmHandle> cmHandles = networkCmProxyDataService + .executeCmHandleSearch(cmHandleQueryApiParameters); + final List<RestOutputCmHandle> outputCmHandles = + cmHandles.stream().map(this::toRestOutputCmHandle).collect(Collectors.toList()); + return ResponseEntity.ok(outputCmHandles); } /** - * Query and return cm handles that match the given query parameters. + * Query and return cm handle ids that match the given query parameters. * - * @param cmHandleQueryRestParameters the cm handle query parameters + * @param cmHandleQueryParameters the cm handle query parameters * @return collection of cm handle ids */ - public ResponseEntity<List<String>> queryCmHandles( - final CmHandleQueryRestParameters cmHandleQueryRestParameters) { - final Set<String> cmHandleIds = networkCmProxyDataService.queryCmHandles( - jsonObjectMapper.convertToValueType(cmHandleQueryRestParameters, CmHandleQueryApiParameters.class)); + @Override + public ResponseEntity<List<String>> searchCmHandleIds( + final CmHandleQueryParameters cmHandleQueryParameters) { + final CmHandleQueryApiParameters cmHandleQueryApiParameters = + jsonObjectMapper.convertToValueType(cmHandleQueryParameters, CmHandleQueryApiParameters.class); + final Set<String> cmHandleIds = networkCmProxyDataService.executeCmHandleIdSearch(cmHandleQueryApiParameters); return ResponseEntity.ok(List.copyOf(cmHandleIds)); } @@ -281,41 +279,6 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { return new ResponseEntity<>(restModuleReferences, HttpStatus.OK); } - private Collection<String> processConditions(final List<ConditionProperties> conditionProperties) { - for (final ConditionProperties conditionProperty : conditionProperties) { - if (conditionProperty.getName().equals("hasAllModules")) { - return executeCmHandleSearchesForModuleNames(conditionProperty); - } else { - log.warn("Unrecognized condition name {}.", conditionProperty.getName()); - } - } - log.warn("No valid conditions found {}.", conditionProperties); - return Collections.emptyList(); - } - - private Collection<String> executeCmHandleSearchesForModuleNames(final ConditionProperties conditionProperties) { - return networkCmProxyDataService - .executeCmHandleHasAllModulesSearch(getModuleNames(conditionProperties.getConditionParameters())); - } - - private Collection<String> getModuleNames(final ModuleNamesAsJsonArray moduleNamesAsJsonArray) { - final Collection<String> moduleNames = new ArrayList<>(moduleNamesAsJsonArray.size()); - for (final ModuleNameAsJsonObject moduleNameAsJsonObject : moduleNamesAsJsonArray) { - moduleNames.add(moduleNameAsJsonObject.getModuleName()); - } - return moduleNames; - } - - private CmHandleProperties toCmHandleProperties(final Collection<String> cmHandleIdentifiers) { - final CmHandleProperties cmHandleProperties = new CmHandleProperties(); - for (final String cmHandleIdentifier : cmHandleIdentifiers) { - final CmHandleProperty cmHandleProperty = new CmHandleProperty(); - cmHandleProperty.setCmHandleId(cmHandleIdentifier); - cmHandleProperties.add(cmHandleProperty); - } - return cmHandleProperties; - } - private RestOutputCmHandle toRestOutputCmHandle(final NcmpServiceCmHandle ncmpServiceCmHandle) { final RestOutputCmHandle restOutputCmHandle = new RestOutputCmHandle(); final CmHandlePublicProperties cmHandlePublicProperties = new CmHandlePublicProperties(); diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java new file mode 100644 index 0000000000..fc992da41a --- /dev/null +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DeprecationHelper.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.ncmp.rest.util; + +import java.util.ArrayList; +import java.util.Collections; +import lombok.RequiredArgsConstructor; +import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters; +import org.onap.cps.ncmp.api.models.ConditionApiProperties; +import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; +import org.onap.cps.utils.JsonObjectMapper; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class DeprecationHelper { + + private final JsonObjectMapper jsonObjectMapper; + + /** + * Convert the old condition properties to the new schema. + * !!! remove it after the old condition removed !!! + * it only works for module names + * + * @param cmHandleQueryParameters the original input parameter + */ + @Deprecated //this method wil be removed in Release 12 (No Name know yet) + public CmHandleQueryApiParameters mapOldConditionProperties( + final CmHandleQueryParameters cmHandleQueryParameters) { + final CmHandleQueryApiParameters cmHandleQueryApiParameters = + jsonObjectMapper.convertToValueType(cmHandleQueryParameters, CmHandleQueryApiParameters.class); + if (cmHandleQueryParameters.getConditions() != null + && cmHandleQueryApiParameters.getCmHandleQueryParameters().isEmpty()) { + cmHandleQueryApiParameters.setCmHandleQueryParameters(new ArrayList<>()); + cmHandleQueryParameters.getConditions().parallelStream().forEach( + oldConditionProperty -> { + if (oldConditionProperty.getConditionParameters() != null + && oldConditionProperty.getName() != null) { + final ConditionApiProperties conditionApiProperties = new ConditionApiProperties(); + conditionApiProperties.setConditionName(oldConditionProperty.getName()); + conditionApiProperties.setConditionParameters(new ArrayList<>()); + oldConditionProperty.getConditionParameters().parallelStream().forEach( + oldConditionParameter -> + conditionApiProperties.getConditionParameters().add(Collections + .singletonMap("moduleName", oldConditionParameter.getModuleName())) + ); + cmHandleQueryApiParameters.getCmHandleQueryParameters().add(conditionApiProperties); + } + } + ); + } + + return cmHandleQueryApiParameters; + } +} diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy index 60ea736d72..036928fe35 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy @@ -29,6 +29,7 @@ import org.onap.cps.ncmp.api.inventory.CompositeState import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle import org.onap.cps.ncmp.rest.mapper.RestOutputCmHandleStateMapper import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor +import org.onap.cps.ncmp.rest.util.DeprecationHelper import spock.lang.Shared import java.time.OffsetDateTime @@ -86,6 +87,9 @@ class NetworkCmProxyControllerSpec extends Specification { @SpringBean CpsNcmpTaskExecutor spiedCpsTaskExecutor = Spy() + @SpringBean + DeprecationHelper stubbedDeprecationHelper = Stub() + @Value('${rest.api.ncmp-base-path}/v1') def ncmpBasePathV1 @@ -239,8 +243,14 @@ class NetworkCmProxyControllerSpec extends Specification { given: 'an endpoint and json data' def searchesEndpoint = "$ncmpBasePathV1/ch/searches" String jsonString = TestUtils.getResourceFileContent('cmhandle-search.json') - and: 'the service method is invoked with module names and returns two cm handle ids' - mockNetworkCmProxyDataService.executeCmHandleHasAllModulesSearch(['module1', 'module2']) >> ['some-cmhandle-id1', 'some-cmhandle-id2'] + and: 'the service method is invoked with module names and returns two cm handles' + def cmHandle1 = new NcmpServiceCmHandle() + cmHandle1.cmHandleId = 'some-cmhandle-id1' + cmHandle1.publicProperties = [color:'yellow'] + def cmHandle2 = new NcmpServiceCmHandle() + cmHandle2.cmHandleId = 'some-cmhandle-id2' + cmHandle2.publicProperties = [color:'green'] + mockNetworkCmProxyDataService.executeCmHandleSearch(_) >> [cmHandle1, cmHandle2] when: 'the searches api is invoked' def response = mvc.perform(post(searchesEndpoint) .contentType(MediaType.APPLICATION_JSON) @@ -248,7 +258,7 @@ class NetworkCmProxyControllerSpec extends Specification { then: 'response status returns OK' response.status == HttpStatus.OK.value() and: 'the expected response content is returned' - response.contentAsString == '{"cmHandles":[{"cmHandleId":"some-cmhandle-id1"},{"cmHandleId":"some-cmhandle-id2"}]}' + response.contentAsString == '[{"cmHandle":"some-cmhandle-id1","publicCmHandleProperties":[{"color":"yellow"}],"state":null},{"cmHandle":"some-cmhandle-id2","publicCmHandleProperties":[{"color":"green"}],"state":null}]' } def 'Get Cm Handle details by Cm Handle id.'() { @@ -290,31 +300,38 @@ class NetworkCmProxyControllerSpec extends Specification { given: 'an endpoint and json data' def searchesEndpoint = "$ncmpBasePathV1/ch/searches" String jsonString = TestUtils.getResourceFileContent('invalid-cmhandle-search.json') + and: 'the service method is invoked with module names and returns two cm handles' + def cmHandel1 = new NcmpServiceCmHandle() + cmHandel1.cmHandleId = 'some-cmhandle-id1' + cmHandel1.publicProperties = [color:'yellow'] + def cmHandel2 = new NcmpServiceCmHandle() + cmHandel2.cmHandleId = 'some-cmhandle-id2' + cmHandel2.publicProperties = [color:'green'] + mockNetworkCmProxyDataService.executeCmHandleSearch(_) >> [cmHandel1, cmHandel2] when: 'the searches api is invoked' def response = mvc.perform(post(searchesEndpoint) .contentType(MediaType.APPLICATION_JSON) .content(jsonString)).andReturn().response then: 'an empty cm handle identifier is returned' - response.contentAsString == '{"cmHandles":[]}' + response.contentAsString == '[{"cmHandle":"some-cmhandle-id1","publicCmHandleProperties":[{"color":"yellow"}],"state":null},{"cmHandle":"some-cmhandle-id2","publicCmHandleProperties":[{"color":"green"}],"state":null}]' } def 'Query for cm handles matching query parameters'() { given: 'an endpoint and json data' - def searchesEndpoint = "$ncmpBasePathV1/data/ch/searches" - String jsonString = '{"publicCmHandleProperties": {"name": "Contact", "value": "newemailforstore@bookstore.com"}}' + def searchesEndpoint = "$ncmpBasePathV1/ch/id-searches" and: 'the service method is invoked with module names and returns cm handle ids' - 1 * mockNetworkCmProxyDataService.queryCmHandles(_) >> ['some-cmhandle-id1', 'some-cmhandle-id2'] + 1 * mockNetworkCmProxyDataService.executeCmHandleIdSearch(_) >> ['some-cmhandle-id1', 'some-cmhandle-id2'] when: 'the searches api is invoked' def response = mvc.perform(post(searchesEndpoint) .contentType(MediaType.APPLICATION_JSON) - .content(jsonString)).andReturn().response + .content('{}')).andReturn().response then: 'cm handle ids are returned' response.contentAsString == '["some-cmhandle-id1","some-cmhandle-id2"]' } def 'Query for cm handles with invalid request payload'() { when: 'the searches api is invoked' - def searchesEndpoint = "$ncmpBasePathV1/data/ch/searches" + def searchesEndpoint = "$ncmpBasePathV1/ch/id-searches" def invalidInputData = '{invalidJson}' def response = mvc.perform(post(searchesEndpoint) .contentType(MediaType.APPLICATION_JSON) diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy index 45ed3d3070..1563c75b3f 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy @@ -31,6 +31,7 @@ import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException import org.onap.cps.ncmp.rest.controller.NcmpRestInputMapper import org.onap.cps.ncmp.rest.mapper.RestOutputCmHandleStateMapper import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor +import org.onap.cps.ncmp.rest.util.DeprecationHelper import org.onap.cps.spi.exceptions.CpsException import org.onap.cps.spi.exceptions.DataNodeNotFoundException import org.onap.cps.spi.exceptions.DataValidationException @@ -47,7 +48,6 @@ import spock.lang.Specification import static org.onap.cps.ncmp.rest.exceptions.NetworkCmProxyRestExceptionHandlerSpec.ApiType.NCMP import static org.onap.cps.ncmp.rest.exceptions.NetworkCmProxyRestExceptionHandlerSpec.ApiType.NCMPINVENTORY -import static org.springframework.http.HttpStatus.BAD_GATEWAY import static org.springframework.http.HttpStatus.BAD_REQUEST import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR import static org.springframework.http.HttpStatus.NOT_FOUND @@ -75,6 +75,9 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification { @SpringBean CpsNcmpTaskExecutor stubbedCpsTaskExecutor = Stub() + @SpringBean + DeprecationHelper stubbedDeprecationHelper = Stub() + @Value('${rest.api.ncmp-base-path}') def basePathNcmp diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/DeprecationHelperSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/DeprecationHelperSpec.groovy new file mode 100644 index 0000000000..8c212d3531 --- /dev/null +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/DeprecationHelperSpec.groovy @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.ncmp.rest.util + +import com.fasterxml.jackson.databind.ObjectMapper +import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters +import org.onap.cps.ncmp.api.models.ConditionApiProperties +import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters +import org.onap.cps.ncmp.rest.model.ConditionProperties +import org.onap.cps.ncmp.rest.model.ModuleNameAsJsonObject +import org.onap.cps.ncmp.rest.model.OldConditionProperties +import org.onap.cps.utils.JsonObjectMapper +import spock.lang.Specification + +class DeprecationHelperSpec extends Specification { + + DeprecationHelper deprecationHelper = new DeprecationHelper(new JsonObjectMapper(new ObjectMapper())) + + def 'Map deprecated condition properties - #scenario.'() { + given: 'a deprecated condition properties' + def cmHandleQueryParameters = new CmHandleQueryParameters() + cmHandleQueryParameters.conditions = oldConditionPropertiesArray + cmHandleQueryParameters.cmHandleQueryParameters = cmHandleQueryParametersArray + when: 'converted into the new format' + def result = deprecationHelper.mapOldConditionProperties(cmHandleQueryParameters) + then: 'result is the expected' + assert result == new CmHandleQueryApiParameters(cmHandleQueryParameters: expectedCmHandleQueryApiParametersArray) + where: + scenario | oldConditionPropertiesArray | cmHandleQueryParametersArray || expectedCmHandleQueryApiParametersArray + 'mapping old query' | [new OldConditionProperties(name: 'hasAllModule', conditionParameters: [new ModuleNameAsJsonObject(moduleName: 'module-1')])] | [] || [new ConditionApiProperties(conditionName: 'hasAllModule', conditionParameters: [[moduleName:'module-1']])] + 'old condition is null' | null | [] || [] + 'old condition parameters is null' | [new OldConditionProperties(name: 'hasAllModule', conditionParameters: null)] | [] || [] + 'old condition name is null' | [new OldConditionProperties(name: null, conditionParameters: [new ModuleNameAsJsonObject(moduleName: 'module-1')])] | [] || [] + 'new query parameters are filled' | [new OldConditionProperties(name: 'hasAllModule', conditionParameters: [new ModuleNameAsJsonObject(moduleName: 'module-1')])] | [new ConditionProperties(conditionName: 'hasAllModule', conditionParameters: [[moduleName:'module-2']])] || [new ConditionApiProperties(conditionName: 'hasAllModule', conditionParameters: [[moduleName:'module-2']])] + } +} |