diff options
Diffstat (limited to 'cps-rest')
14 files changed, 544 insertions, 182 deletions
diff --git a/cps-rest/docs/openapi/components.yml b/cps-rest/docs/openapi/components.yml index fb0947e54a..e700da6ea1 100644 --- a/cps-rest/docs/openapi/components.yml +++ b/cps-rest/docs/openapi/components.yml @@ -2,6 +2,7 @@ # Copyright (c) 2021-2022 Bell Canada. # Modifications Copyright (C) 2021-2022 Nordix Foundation # Modifications Copyright (C) 2022 TechMahindra Ltd. +# Modifications Copyright (C) 2022 Deutsche Telekom AG # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -106,6 +107,17 @@ components: name: SciFi - code: 02 name: kids + dataSampleXml: + value: + <stores xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> + <bookstore xmlns="org:onap:ccsdk:sample"> + <bookstore-name>Chapters</bookstore-name> + <categories> + <code>1</code> + <name>SciFi</name> + </categories> + </bookstore> + </stores> parameters: dataspaceNameInQuery: @@ -211,6 +223,23 @@ components: schema: type: string example: '2021-03-21T00:10:34.030-0100' + apiVersionInPath: + name: apiVersion + in: path + description: apiVersion + required: true + schema: + type: string + enum: [v1, v2] + default: v2 + contentTypeHeader: + name: Content-Type + in: header + description: Content type header + schema: + type: string + example: 'application/json' + required: true responses: NotFound: @@ -279,6 +308,8 @@ components: schema: type: string example: my-resource + CreatedV2: + description: Created without response body InternalServerError: description: Internal Server Error content: diff --git a/cps-rest/docs/openapi/cpsAdmin.yml b/cps-rest/docs/openapi/cpsAdmin.yml index e887ef2c07..f60a9be6ff 100644 --- a/cps-rest/docs/openapi/cpsAdmin.yml +++ b/cps-rest/docs/openapi/cpsAdmin.yml @@ -19,27 +19,6 @@ # ============LICENSE_END========================================================= dataspaces: - post: - description: Create a new dataspace - tags: - - cps-admin - summary: Create a dataspace - operationId: createDataspace - parameters: - - $ref: 'components.yml#/components/parameters/dataspaceNameInQuery' - responses: - '201': - $ref: 'components.yml#/components/responses/Created' - '400': - $ref: 'components.yml#/components/responses/BadRequest' - '401': - $ref: 'components.yml#/components/responses/Unauthorized' - '403': - $ref: 'components.yml#/components/responses/Forbidden' - '409': - $ref: 'components.yml#/components/responses/Conflict' - '500': - $ref: 'components.yml#/components/responses/InternalServerError' delete: description: Delete a dataspace tags: @@ -47,6 +26,7 @@ dataspaces: summary: Delete a dataspace operationId: deleteDataspace parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInQuery' responses: '204': @@ -63,32 +43,30 @@ dataspaces: $ref: 'components.yml#/components/responses/InternalServerError' schemaSet: - post: - description: Create a new schema set in the given dataspace + get: + description: Read all schema sets, given a dataspace tags: - cps-admin - summary: Create a schema set - operationId: createSchemaSet + summary: Get schema sets + operationId: getSchemaSets parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - - $ref: 'components.yml#/components/parameters/schemaSetNameInQuery' - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: 'components.yml#/components/schemas/MultipartFile' responses: - '201': - $ref: 'components.yml#/components/responses/Created' + '200': + description: OK + content: + application/json: + schema: + type: array + items: + $ref: 'components.yml#/components/schemas/SchemaSetDetails' '400': $ref: 'components.yml#/components/responses/BadRequest' '401': $ref: 'components.yml#/components/responses/Unauthorized' '403': $ref: 'components.yml#/components/responses/Forbidden' - '409': - $ref: 'components.yml#/components/responses/Conflict' '500': $ref: 'components.yml#/components/responses/InternalServerError' @@ -100,6 +78,7 @@ schemaSetBySchemaSetName: summary: Get a schema set operationId: getSchemaSet parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/schemaSetNameInPath' responses: @@ -124,6 +103,7 @@ schemaSetBySchemaSetName: summary: Delete a schema set operationId: deleteSchemaSet parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/schemaSetNameInPath' responses: @@ -148,6 +128,7 @@ anchorsByDataspace: summary: Get anchors operationId: getAnchors parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' responses: '200': @@ -166,29 +147,6 @@ anchorsByDataspace: $ref: 'components.yml#/components/responses/Forbidden' '500': $ref: 'components.yml#/components/responses/InternalServerError' - post: - description: Create a new anchor in the given dataspace - tags: - - cps-admin - summary: Create an anchor - operationId: createAnchor - parameters: - - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - - $ref: 'components.yml#/components/parameters/schemaSetNameInQuery' - - $ref: 'components.yml#/components/parameters/anchorNameInQuery' - responses: - '201': - $ref: 'components.yml#/components/responses/Created' - '400': - $ref: 'components.yml#/components/responses/BadRequest' - '401': - $ref: 'components.yml#/components/responses/Unauthorized' - '403': - $ref: 'components.yml#/components/responses/Forbidden' - '409': - $ref: 'components.yml#/components/responses/Conflict' - '500': - $ref: 'components.yml#/components/responses/InternalServerError' anchorByDataspaceAndAnchorName: get: @@ -198,6 +156,7 @@ anchorByDataspaceAndAnchorName: summary: Get an anchor operationId: getAnchor parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/anchorNameInPath' responses: @@ -222,6 +181,7 @@ anchorByDataspaceAndAnchorName: summary: Delete an anchor operationId: deleteAnchor parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/anchorNameInPath' responses: @@ -243,6 +203,8 @@ adminDataspaces: - cps-admin summary: Get all dataspaces operationId: getAllDataspaces + parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' responses: '200': description: OK @@ -269,6 +231,7 @@ adminDataspace: summary: Get a dataspace operationId: getDataspace parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' responses: '200': diff --git a/cps-rest/docs/openapi/cpsAdminV1Deprecated.yml b/cps-rest/docs/openapi/cpsAdminV1Deprecated.yml new file mode 100644 index 0000000000..56f7f1b4fc --- /dev/null +++ b/cps-rest/docs/openapi/cpsAdminV1Deprecated.yml @@ -0,0 +1,98 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2022 TechMahindra Ltd. +# ================================================================================ +# 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========================================================= + +dataspaces: + post: + deprecated: true + description: Create a new dataspace + tags: + - cps-admin + summary: Create a dataspace + operationId: createDataspace + parameters: + - $ref: 'components.yml#/components/parameters/dataspaceNameInQuery' + responses: + '201': + $ref: 'components.yml#/components/responses/Created' + '400': + $ref: 'components.yml#/components/responses/BadRequest' + '401': + $ref: 'components.yml#/components/responses/Unauthorized' + '403': + $ref: 'components.yml#/components/responses/Forbidden' + '409': + $ref: 'components.yml#/components/responses/Conflict' + '500': + $ref: 'components.yml#/components/responses/InternalServerError' + +anchorsByDataspace: + post: + deprecated: true + description: Create a new anchor in the given dataspace + tags: + - cps-admin + summary: Create an anchor + operationId: createAnchor + parameters: + - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' + - $ref: 'components.yml#/components/parameters/schemaSetNameInQuery' + - $ref: 'components.yml#/components/parameters/anchorNameInQuery' + responses: + '201': + $ref: 'components.yml#/components/responses/Created' + '400': + $ref: 'components.yml#/components/responses/BadRequest' + '401': + $ref: 'components.yml#/components/responses/Unauthorized' + '403': + $ref: 'components.yml#/components/responses/Forbidden' + '409': + $ref: 'components.yml#/components/responses/Conflict' + '500': + $ref: 'components.yml#/components/responses/InternalServerError' + +schemaSet: + post: + deprecated: true + description: Create a new schema set in the given dataspace + tags: + - cps-admin + summary: Create a schema set + operationId: createSchemaSet + parameters: + - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' + - $ref: 'components.yml#/components/parameters/schemaSetNameInQuery' + requestBody: + required: true + content: + multipart/form-data: + schema: + $ref: 'components.yml#/components/schemas/MultipartFile' + responses: + '201': + $ref: 'components.yml#/components/responses/Created' + '400': + $ref: 'components.yml#/components/responses/BadRequest' + '401': + $ref: 'components.yml#/components/responses/Unauthorized' + '403': + $ref: 'components.yml#/components/responses/Forbidden' + '409': + $ref: 'components.yml#/components/responses/Conflict' + '500': + $ref: 'components.yml#/components/responses/InternalServerError' diff --git a/cps-rest/docs/openapi/cpsAdminV2.yml b/cps-rest/docs/openapi/cpsAdminV2.yml new file mode 100644 index 0000000000..14e2cfe047 --- /dev/null +++ b/cps-rest/docs/openapi/cpsAdminV2.yml @@ -0,0 +1,95 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2022 TechMahindra Ltd. +# ================================================================================ +# 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========================================================= + +dataspaces: + post: + description: Create a new dataspace + tags: + - cps-admin + summary: Create a dataspace + operationId: createDataspaceV2 + parameters: + - $ref: 'components.yml#/components/parameters/dataspaceNameInQuery' + responses: + '201': + $ref: 'components.yml#/components/responses/CreatedV2' + '400': + $ref: 'components.yml#/components/responses/BadRequest' + '401': + $ref: 'components.yml#/components/responses/Unauthorized' + '403': + $ref: 'components.yml#/components/responses/Forbidden' + '409': + $ref: 'components.yml#/components/responses/Conflict' + '500': + $ref: 'components.yml#/components/responses/InternalServerError' + +anchorsByDataspace: + post: + description: Create a new anchor in the given dataspace + tags: + - cps-admin + summary: Create an anchor + operationId: createAnchorV2 + parameters: + - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' + - $ref: 'components.yml#/components/parameters/schemaSetNameInQuery' + - $ref: 'components.yml#/components/parameters/anchorNameInQuery' + responses: + '201': + $ref: 'components.yml#/components/responses/CreatedV2' + '400': + $ref: 'components.yml#/components/responses/BadRequest' + '401': + $ref: 'components.yml#/components/responses/Unauthorized' + '403': + $ref: 'components.yml#/components/responses/Forbidden' + '409': + $ref: 'components.yml#/components/responses/Conflict' + '500': + $ref: 'components.yml#/components/responses/InternalServerError' + +schemaSet: + post: + description: Create a new schema set in the given dataspace + tags: + - cps-admin + summary: Create a schema set + operationId: createSchemaSetV2 + parameters: + - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' + - $ref: 'components.yml#/components/parameters/schemaSetNameInQuery' + requestBody: + required: true + content: + multipart/form-data: + schema: + $ref: 'components.yml#/components/schemas/MultipartFile' + responses: + '201': + $ref: 'components.yml#/components/responses/CreatedV2' + '400': + $ref: 'components.yml#/components/responses/BadRequest' + '401': + $ref: 'components.yml#/components/responses/Unauthorized' + '403': + $ref: 'components.yml#/components/responses/Forbidden' + '409': + $ref: 'components.yml#/components/responses/Conflict' + '500': + $ref: 'components.yml#/components/responses/InternalServerError' diff --git a/cps-rest/docs/openapi/cpsData.yml b/cps-rest/docs/openapi/cpsData.yml index 265ee23ad1..0dc388706c 100644 --- a/cps-rest/docs/openapi/cpsData.yml +++ b/cps-rest/docs/openapi/cpsData.yml @@ -1,6 +1,8 @@ # ============LICENSE_START======================================================= # Copyright (c) 2021-2022 Bell Canada. # Modifications Copyright (C) 2021-2022 Nordix Foundation +# Modifications Copyright (C) 2022 TechMahindra Ltd. +# Modifications Copyright (C) 2022 Deutsche Telekom AG # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,6 +27,7 @@ nodeByDataspaceAndAnchor: summary: Get a node operationId: getNodeByDataspaceAndAnchor parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/anchorNameInPath' - $ref: 'components.yml#/components/parameters/xpathInQuery' @@ -57,6 +60,7 @@ listElementByDataspaceAndAnchor: summary: Add list element(s) operationId: addListElements parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/anchorNameInPath' - $ref: 'components.yml#/components/parameters/requiredXpathInQuery' @@ -88,6 +92,7 @@ listElementByDataspaceAndAnchor: summary: Replace list content operationId: replaceListContent parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/anchorNameInPath' - $ref: 'components.yml#/components/parameters/requiredXpathInQuery' @@ -112,29 +117,6 @@ listElementByDataspaceAndAnchor: $ref: 'components.yml#/components/responses/Forbidden' '500': $ref: 'components.yml#/components/responses/InternalServerError' - delete: - description: Delete one or all list element(s) for a given anchor and dataspace - deprecated: true - tags: - - cps-data - summary: Delete one or all list element(s) - operationId: deleteListOrListElement - parameters: - - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - - $ref: 'components.yml#/components/parameters/anchorNameInPath' - - $ref: 'components.yml#/components/parameters/requiredXpathInQuery' - - $ref: 'components.yml#/components/parameters/observedTimestampInQuery' - responses: - '204': - $ref: 'components.yml#/components/responses/NoContent' - '400': - $ref: 'components.yml#/components/responses/BadRequest' - '401': - $ref: 'components.yml#/components/responses/Unauthorized' - '403': - $ref: 'components.yml#/components/responses/Forbidden' - '500': - $ref: 'components.yml#/components/responses/InternalServerError' nodesByDataspaceAndAnchor: post: @@ -144,19 +126,30 @@ nodesByDataspaceAndAnchor: summary: Create a node operationId: createNode parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/anchorNameInPath' - $ref: 'components.yml#/components/parameters/xpathInQuery' - $ref: 'components.yml#/components/parameters/observedTimestampInQuery' + - $ref: 'components.yml#/components/parameters/contentTypeHeader' requestBody: required: true content: application/json: schema: - type: object + type: string examples: dataSample: $ref: 'components.yml#/components/examples/dataSample' + application/xml: + schema: + type: object # Workaround to show example + xml: + name: stores + examples: + dataSample: + $ref: 'components.yml#/components/examples/dataSampleXml' + responses: '201': $ref: 'components.yml#/components/responses/Created' @@ -177,6 +170,7 @@ nodesByDataspaceAndAnchor: summary: Update node leaves operationId: updateNodeLeaves parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/anchorNameInPath' - $ref: 'components.yml#/components/parameters/xpathInQuery' @@ -208,6 +202,7 @@ nodesByDataspaceAndAnchor: summary: Delete a data node operationId: deleteDataNode parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/anchorNameInPath' - $ref: 'components.yml#/components/parameters/xpathInQuery' @@ -230,6 +225,7 @@ nodesByDataspaceAndAnchor: summary: Replace a node with descendants operationId: replaceNode parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/anchorNameInPath' - $ref: 'components.yml#/components/parameters/xpathInQuery' diff --git a/cps-rest/docs/openapi/cpsDataV1Deprecated.yml b/cps-rest/docs/openapi/cpsDataV1Deprecated.yml new file mode 100644 index 0000000000..194ca3e079 --- /dev/null +++ b/cps-rest/docs/openapi/cpsDataV1Deprecated.yml @@ -0,0 +1,42 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2022 TechMahindra Ltd. +# ================================================================================ +# 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========================================================= + +listElementByDataspaceAndAnchor: + delete: + description: Delete one or all list element(s) for a given anchor and dataspace + deprecated: true + tags: + - cps-data + summary: Delete one or all list element(s) + operationId: deleteListOrListElement + parameters: + - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' + - $ref: 'components.yml#/components/parameters/anchorNameInPath' + - $ref: 'components.yml#/components/parameters/requiredXpathInQuery' + - $ref: 'components.yml#/components/parameters/observedTimestampInQuery' + responses: + '204': + $ref: 'components.yml#/components/responses/NoContent' + '400': + $ref: 'components.yml#/components/responses/BadRequest' + '401': + $ref: 'components.yml#/components/responses/Unauthorized' + '403': + $ref: 'components.yml#/components/responses/Forbidden' + '500': + $ref: 'components.yml#/components/responses/InternalServerError' diff --git a/cps-rest/docs/openapi/cpsQuery.yml b/cps-rest/docs/openapi/cpsQuery.yml index dc0402d03e..45fc70c861 100644 --- a/cps-rest/docs/openapi/cpsQuery.yml +++ b/cps-rest/docs/openapi/cpsQuery.yml @@ -1,6 +1,7 @@ # ============LICENSE_START======================================================= # Copyright (C) 2021 Nordix Foundation # Modifications Copyright (c) 2022 Bell Canada. +# Modifications Copyright (c) 2022 TechMahindra Ltd. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,6 +26,7 @@ nodesByDataspaceAndAnchorAndCpsPath: summary: Query data nodes operationId: getNodesByDataspaceAndAnchorAndCpsPath parameters: + - $ref: 'components.yml#/components/parameters/apiVersionInPath' - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/anchorNameInPath' - $ref: 'components.yml#/components/parameters/cpsPathInQuery' diff --git a/cps-rest/docs/openapi/openapi.yml b/cps-rest/docs/openapi/openapi.yml index e170295504..0918b56c3d 100644 --- a/cps-rest/docs/openapi/openapi.yml +++ b/cps-rest/docs/openapi/openapi.yml @@ -51,37 +51,58 @@ tags: paths: /v1/dataspaces: + $ref: 'cpsAdminV1Deprecated.yml#/dataspaces' + + /{apiVersion}/dataspaces: $ref: 'cpsAdmin.yml#/dataspaces' - /v1/admin/dataspaces: + /v2/dataspaces: + $ref: 'cpsAdminV2.yml#/dataspaces' + + /{apiVersion}/admin/dataspaces: $ref: 'cpsAdmin.yml#/adminDataspaces' - /v1/admin/dataspaces/{dataspace-name}: + /{apiVersion}/admin/dataspaces/{dataspace-name}: $ref: 'cpsAdmin.yml#/adminDataspace' /v1/dataspaces/{dataspace-name}/anchors: + $ref: 'cpsAdminV1Deprecated.yml#/anchorsByDataspace' + + /v2/dataspaces/{dataspace-name}/anchors: + $ref: 'cpsAdminV2.yml#/anchorsByDataspace' + + /{apiVersion}/dataspaces/{dataspace-name}/anchors: $ref: 'cpsAdmin.yml#/anchorsByDataspace' - /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}: + /{apiVersion}/dataspaces/{dataspace-name}/anchors/{anchor-name}: $ref: 'cpsAdmin.yml#/anchorByDataspaceAndAnchorName' /v1/dataspaces/{dataspace-name}/schema-sets: + $ref: 'cpsAdminV1Deprecated.yml#/schemaSet' + + /v2/dataspaces/{dataspace-name}/schema-sets: + $ref: 'cpsAdminV2.yml#/schemaSet' + + /{apiVersion}/dataspaces/{dataspace-name}/schema-sets: $ref: 'cpsAdmin.yml#/schemaSet' - /v1/dataspaces/{dataspace-name}/schema-sets/{schema-set-name}: + /{apiVersion}/dataspaces/{dataspace-name}/schema-sets/{schema-set-name}: $ref: 'cpsAdmin.yml#/schemaSetBySchemaSetName' - /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/node: + /{apiVersion}/dataspaces/{dataspace-name}/anchors/{anchor-name}/node: $ref: 'cpsData.yml#/nodeByDataspaceAndAnchor' - /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes: + /{apiVersion}/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes: $ref: 'cpsData.yml#/nodesByDataspaceAndAnchor' /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/list-nodes: + $ref: 'cpsDataV1Deprecated.yml#/listElementByDataspaceAndAnchor' + + /{apiVersion}/dataspaces/{dataspace-name}/anchors/{anchor-name}/list-nodes: $ref: 'cpsData.yml#/listElementByDataspaceAndAnchor' - /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes/query: + /{apiVersion}/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes/query: $ref: 'cpsQuery.yml#/nodesByDataspaceAndAnchorAndCpsPath' security: - - basicAuth: []
\ No newline at end of file + - basicAuth: [] diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java index a29f8d2969..b8ba08915c 100755 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java @@ -69,13 +69,25 @@ public class AdminRestController implements CpsAdminApi { } /** + * Create a dataspace without returning any response body. + * + * @param dataspaceName dataspace name + * @return a {@Link ResponseEntity} of created dataspace name & {@link HttpStatus} CREATED + */ + @Override + public ResponseEntity<Void> createDataspaceV2(@NotNull @Valid final String dataspaceName) { + cpsAdminService.createDataspace(dataspaceName); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + /** * Delete a dataspace. * * @param dataspaceName name of dataspace to be deleted * @return a {@Link ResponseEntity} of {@link HttpStatus} NO_CONTENT */ @Override - public ResponseEntity<Void> deleteDataspace(final String dataspaceName) { + public ResponseEntity<Void> deleteDataspace(final String apiVersion, final String dataspaceName) { cpsAdminService.deleteDataspace(dataspaceName); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -96,28 +108,62 @@ public class AdminRestController implements CpsAdminApi { } /** + * Create a {@link SchemaSet}. + * + * @param multipartFile multipart file + * @param schemaSetName schemaset name + * @param dataspaceName dataspace name + * @return a {@Link ResponseEntity} of created schema set without any response body & {@link HttpStatus} CREATED + */ + @Override + public ResponseEntity<Void> createSchemaSetV2(@NotNull @Valid final String schemaSetName, + final String dataspaceName, @Valid final MultipartFile multipartFile) { + cpsModuleService.createSchemaSet(dataspaceName, schemaSetName, extractYangResourcesMap(multipartFile)); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + /** * Get {@link SchemaSetDetails} based on dataspace name & {@link SchemaSet} name. * + * @param apiVersion api version * @param dataspaceName dataspace name * @param schemaSetName schemaset name * @return a {@Link ResponseEntity} of {@Link SchemaSetDetails} & {@link HttpStatus} OK */ @Override - public ResponseEntity<SchemaSetDetails> getSchemaSet(final String dataspaceName, final String schemaSetName) { + public ResponseEntity<SchemaSetDetails> getSchemaSet(final String apiVersion, + final String dataspaceName, final String schemaSetName) { final var schemaSet = cpsModuleService.getSchemaSet(dataspaceName, schemaSetName); final var schemaSetDetails = cpsRestInputMapper.toSchemaSetDetails(schemaSet); return new ResponseEntity<>(schemaSetDetails, HttpStatus.OK); } /** + * Get list of schema sets for a given dataspace name. + * + * @param apiVersion api version + * @param dataspaceName dataspace name + * @return a {@Link ResponseEntity} of schema sets & {@link HttpStatus} OK + */ + @Override + public ResponseEntity<List<SchemaSetDetails>> getSchemaSets(final String apiVersion, final String dataspaceName) { + final Collection<SchemaSet> schemaSets = cpsModuleService.getSchemaSets(dataspaceName); + final List<SchemaSetDetails> schemaSetDetails = schemaSets.stream().map(cpsRestInputMapper::toSchemaSetDetails) + .collect(Collectors.toList()); + return new ResponseEntity<>(schemaSetDetails, HttpStatus.OK); + } + + /** * Delete a {@link SchemaSet} based on given dataspace name & schemaset name. * + * @param apiVersion api version * @param dataspaceName dataspace name * @param schemaSetName schemaset name * @return a {@Link ResponseEntity} of {@link HttpStatus} NO_CONTENT */ @Override - public ResponseEntity<Void> deleteSchemaSet(final String dataspaceName, final String schemaSetName) { + public ResponseEntity<Void> deleteSchemaSet(final String apiVersion, + final String dataspaceName, final String schemaSetName) { cpsModuleService.deleteSchemaSet(dataspaceName, schemaSetName, CASCADE_DELETE_PROHIBITED); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -138,14 +184,31 @@ public class AdminRestController implements CpsAdminApi { } /** + * Create an anchor. + * + * @param dataspaceName dataspace name + * @param schemaSetName schema set name + * @param anchorName anchorName + * @return a ResponseEntity without response body & {@link HttpStatus} CREATED + */ + @Override + public ResponseEntity<Void> createAnchorV2(final String dataspaceName, @NotNull @Valid final String schemaSetName, + @NotNull @Valid final String anchorName) { + cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + /** * Delete an {@link Anchor} based on given dataspace name & anchor name. * + * @param apiVersion api version * @param dataspaceName dataspace name * @param anchorName anchor name * @return a {@Link ResponseEntity} of {@link HttpStatus} NO_CONTENT */ @Override - public ResponseEntity<Void> deleteAnchor(final String dataspaceName, final String anchorName) { + public ResponseEntity<Void> deleteAnchor(final String apiVersion, + final String dataspaceName, final String anchorName) { cpsAdminService.deleteAnchor(dataspaceName, anchorName); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -153,12 +216,14 @@ public class AdminRestController implements CpsAdminApi { /** * Get an {@link Anchor} based on given dataspace name & anchor name. * + * @param apiVersion api version * @param dataspaceName dataspace name * @param anchorName anchor name * @return a {@Link ResponseEntity} of an {@Link AnchorDetails} & {@link HttpStatus} OK */ @Override - public ResponseEntity<AnchorDetails> getAnchor(final String dataspaceName, final String anchorName) { + public ResponseEntity<AnchorDetails> getAnchor(final String apiVersion, + final String dataspaceName, final String anchorName) { final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); final var anchorDetails = cpsRestInputMapper.toAnchorDetails(anchor); return new ResponseEntity<>(anchorDetails, HttpStatus.OK); @@ -167,11 +232,13 @@ public class AdminRestController implements CpsAdminApi { /** * Get all {@link Anchor} based on given dataspace name. * + * @param apiVersion api version * @param dataspaceName dataspace name * @return a {@Link ResponseEntity} of all {@Link AnchorDetails} & {@link HttpStatus} OK */ @Override - public ResponseEntity<List<AnchorDetails>> getAnchors(final String dataspaceName) { + public ResponseEntity<List<AnchorDetails>> getAnchors(final String apiVersion, + final String dataspaceName) { final Collection<Anchor> anchors = cpsAdminService.getAnchors(dataspaceName); final List<AnchorDetails> anchorDetails = anchors.stream().map(cpsRestInputMapper::toAnchorDetails) .collect(Collectors.toList()); @@ -179,7 +246,7 @@ public class AdminRestController implements CpsAdminApi { } @Override - public ResponseEntity<List<DataspaceDetails>> getAllDataspaces() { + public ResponseEntity<List<DataspaceDetails>> getAllDataspaces(final String apiVersion) { final Collection<Dataspace> dataspaces = cpsAdminService.getAllDataspaces(); final List<DataspaceDetails> dataspaceDetails = dataspaces.stream().map(cpsRestInputMapper::toDataspaceDetails) .collect(Collectors.toList()); @@ -187,7 +254,7 @@ public class AdminRestController implements CpsAdminApi { } @Override - public ResponseEntity<DataspaceDetails> getDataspace(final String dataspaceName) { + public ResponseEntity<DataspaceDetails> getDataspace(final String apiVersion, final String dataspaceName) { final Dataspace dataspace = cpsAdminService.getDataspace(dataspaceName); final DataspaceDetails dataspaceDetails = cpsRestInputMapper.toDataspaceDetails(dataspace); return new ResponseEntity<>(dataspaceDetails, HttpStatus.OK); diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java index fdce9bee6b..30bed12775 100755 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java @@ -3,6 +3,8 @@ * Copyright (C) 2020-2022 Bell Canada. * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2021-2022 Nordix Foundation + * Modifications Copyright (C) 2022 TechMahindra Ltd. + * Modifications Copyright (C) 2022 Deutsche Telekom AG * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,11 +33,14 @@ import org.onap.cps.api.CpsDataService; import org.onap.cps.rest.api.CpsDataApi; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; +import org.onap.cps.utils.ContentType; import org.onap.cps.utils.DataMapUtils; import org.onap.cps.utils.JsonObjectMapper; import org.onap.cps.utils.PrefixResolver; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -53,21 +58,26 @@ public class DataRestController implements CpsDataApi { private final PrefixResolver prefixResolver; @Override - public ResponseEntity<String> createNode(final String dataspaceName, final String anchorName, - final Object jsonData, final String parentNodeXpath, final String observedTimestamp) { - final String jsonDataAsString = jsonObjectMapper.asJsonString(jsonData); + public ResponseEntity<String> createNode(@RequestHeader(value = "Content-Type") final String contentTypeHeader, + final String apiVersion, + final String dataspaceName, final String anchorName, + final String nodeData, final String parentNodeXpath, + final String observedTimestamp) { + final ContentType contentType = contentTypeHeader.contains(MediaType.APPLICATION_XML_VALUE) ? ContentType.XML + : ContentType.JSON; if (isRootXpath(parentNodeXpath)) { - cpsDataService.saveData(dataspaceName, anchorName, jsonDataAsString, - toOffsetDateTime(observedTimestamp)); + cpsDataService.saveData(dataspaceName, anchorName, nodeData, + toOffsetDateTime(observedTimestamp), contentType); } else { cpsDataService.saveData(dataspaceName, anchorName, parentNodeXpath, - jsonDataAsString, toOffsetDateTime(observedTimestamp)); + nodeData, toOffsetDateTime(observedTimestamp), contentType); } return new ResponseEntity<>(HttpStatus.CREATED); } @Override - public ResponseEntity<Void> deleteDataNode(final String dataspaceName, final String anchorName, + public ResponseEntity<Void> deleteDataNode(final String apiVersion, + final String dataspaceName, final String anchorName, final String xpath, final String observedTimestamp) { cpsDataService.deleteDataNode(dataspaceName, anchorName, xpath, toOffsetDateTime(observedTimestamp)); @@ -75,7 +85,7 @@ public class DataRestController implements CpsDataApi { } @Override - public ResponseEntity<String> addListElements(final String parentNodeXpath, + public ResponseEntity<String> addListElements(final String parentNodeXpath, final String apiVersion, final String dataspaceName, final String anchorName, final Object jsonData, final String observedTimestamp) { cpsDataService.saveListElements(dataspaceName, anchorName, parentNodeXpath, jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp)); @@ -83,8 +93,8 @@ public class DataRestController implements CpsDataApi { } @Override - public ResponseEntity<Object> getNodeByDataspaceAndAnchor(final String dataspaceName, final String anchorName, - final String xpath, final Boolean includeDescendants) { + public ResponseEntity<Object> getNodeByDataspaceAndAnchor(final String apiVersion, + final String dataspaceName, final String anchorName, final String xpath, final Boolean includeDescendants) { final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants) ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS; final DataNode dataNode = cpsDataService.getDataNode(dataspaceName, anchorName, xpath, @@ -94,7 +104,7 @@ public class DataRestController implements CpsDataApi { } @Override - public ResponseEntity<Object> updateNodeLeaves(final String dataspaceName, + public ResponseEntity<Object> updateNodeLeaves(final String apiVersion, final String dataspaceName, final String anchorName, final Object jsonData, final String parentNodeXpath, final String observedTimestamp) { cpsDataService.updateNodeLeaves(dataspaceName, anchorName, parentNodeXpath, jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp)); @@ -102,7 +112,8 @@ public class DataRestController implements CpsDataApi { } @Override - public ResponseEntity<Object> replaceNode(final String dataspaceName, final String anchorName, + public ResponseEntity<Object> replaceNode(final String apiVersion, + final String dataspaceName, final String anchorName, final Object jsonData, final String parentNodeXpath, final String observedTimestamp) { cpsDataService .updateDataNodeAndDescendants(dataspaceName, anchorName, parentNodeXpath, @@ -112,7 +123,7 @@ public class DataRestController implements CpsDataApi { @Override public ResponseEntity<Object> replaceListContent(final String parentNodeXpath, - final String dataspaceName, final String anchorName, final Object jsonData, + final String apiVersion, final String dataspaceName, final String anchorName, final Object jsonData, final String observedTimestamp) { cpsDataService.replaceListContent(dataspaceName, anchorName, parentNodeXpath, jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp)); diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java index 577ad9c262..3e162ae683 100644 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2021-2022 Nordix Foundation * Modifications Copyright (C) 2022 Bell Canada. + * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,8 +49,8 @@ public class QueryRestController implements CpsQueryApi { private final PrefixResolver prefixResolver; @Override - public ResponseEntity<Object> getNodesByDataspaceAndAnchorAndCpsPath(final String dataspaceName, - final String anchorName, final String cpsPath, final Boolean includeDescendants) { + public ResponseEntity<Object> getNodesByDataspaceAndAnchorAndCpsPath(final String apiVersion, + final String dataspaceName, final String anchorName, final String cpsPath, final Boolean includeDescendants) { final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants) ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS; final Collection<DataNode> dataNodes = diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy index e9612fc395..f81efd6698 100755 --- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy +++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy @@ -73,21 +73,23 @@ class AdminRestControllerSpec extends Specification { def anchor = new Anchor(name: anchorName, dataspaceName: dataspaceName, schemaSetName: schemaSetName) def dataspace = new Dataspace(name: dataspaceName) - def 'Create new dataspace.'() { - given: 'an endpoint' - def createDataspaceEndpoint = "$basePath/v1/dataspaces" + def 'Create new dataspace with #scenario.'() { when: 'post is invoked' def response = mvc.perform( - post(createDataspaceEndpoint) + post("/cps/api/${apiVersion}/dataspaces") .param('dataspace-name', dataspaceName)) .andReturn().response then: 'service method is invoked with expected parameters' 1 * mockCpsAdminService.createDataspace(dataspaceName) and: 'dataspace is create successfully' response.status == HttpStatus.CREATED.value() - } - + assert response.getContentAsString() == expectedResponseBody + where: 'following cases are tested' + scenario | apiVersion || expectedResponseBody + 'V1 API' | 'v1' || 'my_dataspace' + 'V2 API' | 'v2' || '' + } def 'Create dataspace over existing with same name.'() { given: 'an endpoint' def createDataspaceEndpoint = "$basePath/v1/dataspaces" @@ -129,16 +131,14 @@ class AdminRestControllerSpec extends Specification { response.getContentAsString().contains("dataspace-test2") } - def 'Create schema set from yang file.'() { + def 'Create schema set from yang file with #scenario.'() { def yangResourceMapCapture given: 'single yang file' def multipartFile = createMultipartFile("filename.yang", "content") - and: 'an endpoint' - def schemaSetEndpoint = "$basePath/v1/dataspaces/$dataspaceName/schema-sets" when: 'file uploaded with schema set create request' def response = mvc.perform( - multipart(schemaSetEndpoint) + multipart("/cps/api/${apiVersion}/dataspaces/my_dataspace/schema-sets") .file(multipartFile) .param('schema-set-name', schemaSetName)) .andReturn().response @@ -147,19 +147,22 @@ class AdminRestControllerSpec extends Specification { { args -> yangResourceMapCapture = args[2] } yangResourceMapCapture['filename.yang'] == 'content' and: 'response code indicates success' - response.status == HttpStatus.CREATED.value() + assert response.status == HttpStatus.CREATED.value() + assert response.getContentAsString() == expectedResponseBody + where: 'following cases are tested' + scenario | apiVersion || expectedResponseBody + 'V1 API' | 'v1' || 'my_schema_set' + 'V2 API' | 'v2' || '' } - def 'Create schema set from zip archive.'() { + def 'Create schema set from zip archive with #scenario.'() { def yangResourceMapCapture given: 'zip archive with multiple .yang files inside' def multipartFile = createZipMultipartFileFromResource("/yang-files-set.zip") - and: 'an endpoint' - def schemaSetEndpoint = "$basePath/v1/dataspaces/$dataspaceName/schema-sets" when: 'file uploaded with schema set create request' def response = mvc.perform( - multipart(schemaSetEndpoint) + multipart("/cps/api/${apiVersion}/dataspaces/my_dataspace/schema-sets") .file(multipartFile) .param('schema-set-name', schemaSetName)) .andReturn().response @@ -169,25 +172,33 @@ class AdminRestControllerSpec extends Specification { yangResourceMapCapture['assembly.yang'] == "fake assembly content 1\n" yangResourceMapCapture['component.yang'] == "fake component content 1\n" and: 'response code indicates success' - response.status == HttpStatus.CREATED.value() + assert response.status == HttpStatus.CREATED.value() + assert response.getContentAsString() == expectedResponseBody + where: 'following cases are tested' + scenario | apiVersion || expectedResponseBody + 'V1 API' | 'v1' || 'my_schema_set' + 'V2 API' | 'v2' || '' } - def 'Create a schema set from a yang file that is greater than 1MB.'() { + def 'Create a schema set from a yang file that is greater than 1MB #scenario.'() { given: 'a yang file greater than 1MB' def multipartFile = createMultipartFileFromResource("/model-over-1mb.yang") - and: 'an endpoint' - def schemaSetEndpoint = "$basePath/v1/dataspaces/$dataspaceName/schema-sets" when: 'a file is uploaded to the create schema set endpoint' def response = mvc.perform( - multipart(schemaSetEndpoint) + multipart("/cps/api/${apiVersion}/dataspaces/my_dataspace/schema-sets") .file(multipartFile) .param('schema-set-name', schemaSetName)) .andReturn().response then: 'the associated service method is invoked' 1 * mockCpsModuleService.createSchemaSet(dataspaceName, schemaSetName, _) and: 'the response code indicates success' - response.status == HttpStatus.CREATED.value() + assert response.status == HttpStatus.CREATED.value() + assert response.getContentAsString() == expectedResponseBody + where: 'following cases are tested' + scenario | apiVersion || expectedResponseBody + 'V1 API' | 'v1' || 'my_schema_set' + 'V2 API' | 'v2' || '' } def 'Create schema set from zip archive having #caseDescriptor.'() { @@ -278,23 +289,41 @@ class AdminRestControllerSpec extends Specification { response.getContentAsString().contains(schemaSetName) } - def 'Create Anchor.'() { + def 'Get all schema sets for a given dataspace name.'() { + given: 'service method returns all schema sets for a dataspace' + mockCpsModuleService.getSchemaSets(dataspaceName) >> + [new SchemaSet(name: schemaSetName, dataspaceName: dataspaceName), + new SchemaSet(name: "test-schemaset", dataspaceName: dataspaceName)] + and: 'an endpoint' + def schemaSetEndpoint = "$basePath/v1/dataspaces/$dataspaceName/schema-sets" + when: 'get schema sets API is invoked' + def response = mvc.perform(get(schemaSetEndpoint)).andReturn().response + then: 'the correct schema sets is returned' + assert response.status == HttpStatus.OK.value() + assert response.getContentAsString() == '[{"dataspaceName":"my_dataspace","moduleReferences":[],"name":' + + '"my_schema_set"},{"dataspaceName":"my_dataspace","moduleReferences":[],"name":"test-schemaset"}]' + } + + def 'Create Anchor with #scenario.'() { given: 'request parameters' def requestParams = new LinkedMultiValueMap<>() requestParams.add('schema-set-name', schemaSetName) requestParams.add('anchor-name', anchorName) - and: 'an endpoint' - def anchorEndpoint = "$basePath/v1/dataspaces/$dataspaceName/anchors" when: 'post is invoked' def response = mvc.perform( - post(anchorEndpoint).contentType(MediaType.APPLICATION_JSON) + post("/cps/api/${apiVersion}/dataspaces/my_dataspace/anchors") + .contentType(MediaType.APPLICATION_JSON) .params(requestParams as MultiValueMap)) - .andReturn().response + .andReturn().response then: 'anchor is created successfully' 1 * mockCpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName) - response.status == HttpStatus.CREATED.value() - response.getContentAsString().contains(anchorName) + assert response.status == HttpStatus.CREATED.value() + assert response.getContentAsString() == expectedResponseBody + where: 'following cases are tested' + scenario | apiVersion || expectedResponseBody + 'V1 API' | 'v1' || 'my_anchor' + 'V2 API' | 'v2' || '' } def 'Get existing anchor.'() { diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy index 53da3e6599..94f62f8c22 100755 --- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy +++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy @@ -3,6 +3,7 @@ * Copyright (C) 2021-2022 Nordix Foundation * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2021-2022 Bell Canada. + * Modifications Copyright (C) 2022 Deutsche Telekom AG * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +27,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.api.CpsDataService import org.onap.cps.spi.model.DataNode import org.onap.cps.spi.model.DataNodeBuilder +import org.onap.cps.utils.ContentType import org.onap.cps.utils.DateTimeUtility import org.onap.cps.utils.JsonObjectMapper import org.onap.cps.utils.PrefixResolver @@ -69,10 +71,20 @@ class DataRestControllerSpec extends Specification { def dataspaceName = 'my_dataspace' def anchorName = 'my_anchor' def noTimestamp = null - def requestBody = '{"some-key" : "some-value","categories":[{"books":[{"authors":["Iain M. Banks"]}]}]}' + + @Shared + def requestBodyJson = '{"some-key":"some-value","categories":[{"books":[{"authors":["Iain M. Banks"]}]}]}' + + @Shared def expectedJsonData = '{"some-key":"some-value","categories":[{"books":[{"authors":["Iain M. Banks"]}]}]}' @Shared + def requestBodyXml = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<bookstore xmlns="org:onap:ccsdk:sample">\n</bookstore>' + + @Shared + def expectedXmlData = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<bookstore xmlns="org:onap:ccsdk:sample">\n</bookstore>' + + @Shared static DataNode dataNodeWithLeavesNoChildren = new DataNodeBuilder().withXpath('/xpath') .withLeaves([leaf: 'value', leafList: ['leaveListElement1', 'leaveListElement2']]).build() @@ -91,18 +103,20 @@ class DataRestControllerSpec extends Specification { def response = mvc.perform( post(endpoint) - .contentType(MediaType.APPLICATION_JSON) + .contentType(contentType) .param('xpath', parentNodeXpath) .content(requestBody) ).andReturn().response then: 'a created response is returned' response.status == HttpStatus.CREATED.value() then: 'the java API was called with the correct parameters' - 1 * mockCpsDataService.saveData(dataspaceName, anchorName, expectedJsonData, noTimestamp) + 1 * mockCpsDataService.saveData(dataspaceName, anchorName, expectedData, noTimestamp, expectedContentType) where: 'following xpath parameters are are used' - scenario | parentNodeXpath - 'no xpath parameter' | '' - 'xpath parameter point root' | '/' + scenario | parentNodeXpath | contentType | expectedContentType | requestBody | expectedData + 'JSON content: no xpath parameter' | '' | MediaType.APPLICATION_JSON | ContentType.JSON | requestBodyJson | expectedJsonData + 'JSON content: xpath parameter point root' | '/' | MediaType.APPLICATION_JSON | ContentType.JSON | requestBodyJson | expectedJsonData + 'XML content: no xpath parameter' | '' | MediaType.APPLICATION_XML | ContentType.XML | requestBodyXml | expectedXmlData + 'XML content: xpath parameter point root' | '/' | MediaType.APPLICATION_XML | ContentType.XML | requestBodyXml | expectedXmlData } def 'Create a node with observed-timestamp'() { @@ -112,30 +126,31 @@ class DataRestControllerSpec extends Specification { def response = mvc.perform( post(endpoint) - .contentType(MediaType.APPLICATION_JSON) + .contentType(contentType) .param('xpath', '') .param('observed-timestamp', observedTimestamp) - .content(requestBody) + .content(content) ).andReturn().response then: 'a created response is returned' response.status == expectedHttpStatus.value() then: 'the java API was called with the correct parameters' - expectedApiCount * mockCpsDataService.saveData(dataspaceName, anchorName, expectedJsonData, - { it == DateTimeUtility.toOffsetDateTime(observedTimestamp) }) + expectedApiCount * mockCpsDataService.saveData(dataspaceName, anchorName, expectedData, + { it == DateTimeUtility.toOffsetDateTime(observedTimestamp) }, expectedContentType) where: - scenario | observedTimestamp || expectedApiCount | expectedHttpStatus - 'with observed-timestamp' | '2021-03-03T23:59:59.999-0400' || 1 | HttpStatus.CREATED - 'with invalid observed-timestamp' | 'invalid' || 0 | HttpStatus.BAD_REQUEST + scenario | observedTimestamp | contentType | content || expectedApiCount | expectedHttpStatus | expectedData | expectedContentType + 'with observed-timestamp JSON' | '2021-03-03T23:59:59.999-0400' | MediaType.APPLICATION_JSON | requestBodyJson || 1 | HttpStatus.CREATED | expectedJsonData | ContentType.JSON + 'with observed-timestamp XML' | '2021-03-03T23:59:59.999-0400' | MediaType.APPLICATION_XML | requestBodyXml || 1 | HttpStatus.CREATED | expectedXmlData | ContentType.XML + 'with invalid observed-timestamp' | 'invalid' | MediaType.APPLICATION_JSON | requestBodyJson || 0 | HttpStatus.BAD_REQUEST | expectedJsonData | ContentType.JSON } - def 'Create a child node'() { + def 'Create a child node #scenario'() { given: 'endpoint to create a node' def endpoint = "$dataNodeBaseEndpoint/anchors/$anchorName/nodes" and: 'parent node xpath' def parentNodeXpath = 'some xpath' when: 'post is invoked with datanode endpoint and json' def postRequestBuilder = post(endpoint) - .contentType(MediaType.APPLICATION_JSON) + .contentType(contentType) .param('xpath', parentNodeXpath) .content(requestBody) if (observedTimestamp != null) @@ -145,12 +160,14 @@ class DataRestControllerSpec extends Specification { then: 'a created response is returned' response.status == HttpStatus.CREATED.value() then: 'the java API was called with the correct parameters' - 1 * mockCpsDataService.saveData(dataspaceName, anchorName, parentNodeXpath, expectedJsonData, - DateTimeUtility.toOffsetDateTime(observedTimestamp)) + 1 * mockCpsDataService.saveData(dataspaceName, anchorName, parentNodeXpath, expectedData, + DateTimeUtility.toOffsetDateTime(observedTimestamp), expectedContentType) where: - scenario | observedTimestamp - 'with observed-timestamp' | '2021-03-03T23:59:59.999-0400' - 'without observed-timestamp' | null + scenario | observedTimestamp | contentType | requestBody | expectedData | expectedContentType + 'with observed-timestamp JSON' | '2021-03-03T23:59:59.999-0400' | MediaType.APPLICATION_JSON | requestBodyJson | expectedJsonData | ContentType.JSON + 'with observed-timestamp XML' | '2021-03-03T23:59:59.999-0400' | MediaType.APPLICATION_XML | requestBodyXml | expectedXmlData | ContentType.XML + 'without observed-timestamp JSON' | null | MediaType.APPLICATION_JSON | requestBodyJson | expectedJsonData | ContentType.JSON + 'without observed-timestamp XML' | null | MediaType.APPLICATION_XML | requestBodyXml | expectedXmlData | ContentType.XML } def 'Save list elements #scenario.'() { @@ -160,7 +177,7 @@ class DataRestControllerSpec extends Specification { def postRequestBuilder = post("$dataNodeBaseEndpoint/anchors/$anchorName/list-nodes") .contentType(MediaType.APPLICATION_JSON) .param('xpath', parentNodeXpath) - .content(requestBody) + .content(requestBodyJson) if (observedTimestamp != null) postRequestBuilder.param('observed-timestamp', observedTimestamp) def response = mvc.perform(postRequestBuilder).andReturn().response @@ -228,7 +245,7 @@ class DataRestControllerSpec extends Specification { mvc.perform( patch(endpoint) .contentType(MediaType.APPLICATION_JSON) - .content(requestBody) + .content(requestBodyJson) .param('xpath', inputXpath) ).andReturn().response then: 'the service method is invoked with expected parameters' @@ -250,7 +267,7 @@ class DataRestControllerSpec extends Specification { mvc.perform( patch(endpoint) .contentType(MediaType.APPLICATION_JSON) - .content(requestBody) + .content(requestBodyJson) .param('xpath', '/') .param('observed-timestamp', observedTimestamp) ).andReturn().response @@ -273,7 +290,7 @@ class DataRestControllerSpec extends Specification { mvc.perform( put(endpoint) .contentType(MediaType.APPLICATION_JSON) - .content(requestBody) + .content(requestBodyJson) .param('xpath', inputXpath)) .andReturn().response then: 'the service method is invoked with expected parameters' @@ -295,7 +312,7 @@ class DataRestControllerSpec extends Specification { mvc.perform( put(endpoint) .contentType(MediaType.APPLICATION_JSON) - .content(requestBody) + .content(requestBodyJson) .param('xpath', '') .param('observed-timestamp', observedTimestamp)) .andReturn().response @@ -315,7 +332,7 @@ class DataRestControllerSpec extends Specification { def putRequestBuilder = put("$dataNodeBaseEndpoint/anchors/$anchorName/list-nodes") .contentType(MediaType.APPLICATION_JSON) .param('xpath', 'parent xpath') - .content(requestBody) + .content(requestBodyJson) if (observedTimestamp != null) putRequestBuilder.param('observed-timestamp', observedTimestamp) def response = mvc.perform(putRequestBuilder).andReturn().response diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy index ece3507f2d..0821b6bebc 100644 --- a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy +++ b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy @@ -4,6 +4,7 @@ * Modifications Copyright (C) 2021-2022 Nordix Foundation * Modifications Copyright (C) 2021 Bell Canada. * Modifications Copyright (C) 2022 TechMahindra Ltd. + * Modifications Copyright (C) 2022 Deutsche Telekom AG * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -167,13 +168,13 @@ class CpsRestExceptionHandlerSpec extends Specification { def 'Post request with #exceptionThrown.class.simpleName returns HTTP Status Bad Request.'() { given: '#exception is thrown the service indicating data is not found' - mockCpsDataService.saveData(_, _, _, _, _) >> { throw exceptionThrown } + mockCpsDataService.saveData(*_) >> { throw exceptionThrown } when: 'data update request is performed' def response = mvc.perform( post("$basePath/v1/dataspaces/dataspace-name/anchors/anchor-name/nodes") .contentType(MediaType.APPLICATION_JSON) .param('xpath', 'parent node xpath') - .content(groovy.json.JsonOutput.toJson('{"some-key" : "some-value"}')) + .content('{"some-key" : "some-value"}') ).andReturn().response then: 'response code indicates bad input parameters' response.status == BAD_REQUEST.value() @@ -181,18 +182,6 @@ class CpsRestExceptionHandlerSpec extends Specification { exceptionThrown << [new DataNodeNotFoundException('', ''), new NotFoundInDataspaceException('', '')] } - def 'Post request with invalid JSON payload returns HTTP Status Bad Request.'() { - when: 'data post request is performed' - def response = mvc.perform( - post("$basePath/v1/dataspaces/dataspace-name/anchors/anchor-name/nodes") - .contentType(MediaType.APPLICATION_JSON) - .param('xpath', 'parent node xpath') - .content('{') - ).andReturn().response - then: 'response code indicates bad input parameters' - response.status == BAD_REQUEST.value() - } - /* * NB. The test uses 'get anchors' endpoint and associated service method invocation * to test the exception handling. The endpoint chosen is not a subject of test. |