From f9c5e6c865640ef07db8406baa95a5fafceb109a Mon Sep 17 00:00:00 2001 From: "puthuparambil.aditya" Date: Thu, 12 May 2022 16:31:00 +0100 Subject: PoC Contract Stubs NCMP Rest Endpoints Stubs defined for cmHandleSearch and passthrough operational Issue-ID: CPS-919 Signed-off-by: puthuparambil.aditya Change-Id: I4fd7bee8fa70ed237f74c721068ffa39817d5c7a --- cps-ncmp-rest-stub/pom.xml | 190 +++++++++++++++++++++ .../org/onap/cps/ncmp/rest/stub/Application.java | 32 ++++ .../controller/NetworkCmProxyStubController.java | 172 +++++++++++++++++++ .../src/main/resources/application.yml | 39 +++++ .../src/main/resources/stubs/cmHandlesSearch.json | 10 ++ .../stubs/passthrough-operational-example.json | 45 +++++ .../test/java/org/onap/cps/TestApplication.java | 30 ++++ jacoco-report/pom.xml | 1 + 8 files changed, 519 insertions(+) create mode 100644 cps-ncmp-rest-stub/pom.xml create mode 100644 cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/Application.java create mode 100644 cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java create mode 100644 cps-ncmp-rest-stub/src/main/resources/application.yml create mode 100644 cps-ncmp-rest-stub/src/main/resources/stubs/cmHandlesSearch.json create mode 100644 cps-ncmp-rest-stub/src/main/resources/stubs/passthrough-operational-example.json create mode 100644 cps-ncmp-rest-stub/src/test/java/org/onap/cps/TestApplication.java diff --git a/cps-ncmp-rest-stub/pom.xml b/cps-ncmp-rest-stub/pom.xml new file mode 100644 index 000000000..976e21edb --- /dev/null +++ b/cps-ncmp-rest-stub/pom.xml @@ -0,0 +1,190 @@ + + + + + 4.0.0 + + org.onap.cps + cps-parent + 3.1.0-SNAPSHOT + ../cps-parent/pom.xml + + + cps-ncmp-rest-stub + + org.onap.cps.ncmp.rest.stub.Application + 11 + ${project.reporting.outputDirectory}/jacoco-aggregate + + ../jacoco-report/target/site/jacoco-aggregate/jacoco.xml + + 3.0.8 + https://nexus.onap.org + /content/repositories/releases/ + /content/repositories/snapshots/ + true + 1.4.2.Final + + + + + io.swagger.core.v3 + swagger-annotations + 2.1.4 + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-jetty + + + org.mapstruct + mapstruct + ${mapstruct.version} + + + org.mapstruct + mapstruct-processor + ${mapstruct.version} + + + + org.projectlombok + lombok + + + + org.slf4j + slf4j-simple + 1.8.0-beta4 + + + com.google.guava + guava + 20.0 + + + cglib + cglib-nodep + test + 3.1 + + + com.google.code.gson + gson + + + org.onap.cps + cps-ncmp-rest + + + org.onap.cps + cps-ncmp-service + + + true + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + ${java.version} + ${java.version} + + + + + org.apache.maven.plugins + maven-shade-plugin + + + org.springframework.boot + spring-boot-maven-plugin + 1.2.7.RELEASE + + + + true + true + + + *:* + + org/onap/cps/ncmp/rest/controller/** + + + + + + + package + + shade + + + + + META-INF/spring.handlers + + + META-INF/spring.factories + + + META-INF/spring.schemas + + + + org/onap/cps/ncmp/rest/stub/Application + + + + + + + + + diff --git a/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/Application.java b/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/Application.java new file mode 100644 index 000000000..0f0035dab --- /dev/null +++ b/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/Application.java @@ -0,0 +1,32 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Bell Canada. + * ================================================================================ + * 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.stub; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(final String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java b/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java new file mode 100644 index 000000000..6362cf1e1 --- /dev/null +++ b/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java @@ -0,0 +1,172 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Bell Canada + * ================================================================================ + * 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.stub.controller; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi; +import org.onap.cps.ncmp.rest.model.CmHandleQueryRestParameters; +import org.onap.cps.ncmp.rest.model.CmHandles; +import org.onap.cps.ncmp.rest.model.Conditions; +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.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Slf4j +@RestController +@RequestMapping("${rest.api.ncmp-stub-base-path}") +public class NetworkCmProxyStubController implements NetworkCmProxyApi { + + public static final String ASYNC_REQUEST_ID = "requestId"; + + @Value("${stub.path}") + private String pathToResponseFiles; + + @Override + public ResponseEntity createResourceDataRunningForCmHandle(@NotNull @Valid final String resourceIdentifier, + final String cmHandleId, @Valid final Object body, final String contentType) { + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @Override + public ResponseEntity deleteResourceDataRunningForCmHandle(final String cmHandleId, + @NotNull @Valid final String resourceIdentifier, final String contentType) { + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Override + public ResponseEntity executeCmHandleSearch(@Valid final Conditions body) { + final ObjectMapper mapper = new ObjectMapper(); + CmHandles cmHandles = new CmHandles(); + // read JSON file and map/convert to java POJO + final ClassPathResource resource = new ClassPathResource(pathToResponseFiles + "cmHandlesSearch.json"); + try (InputStream inputStream = resource.getInputStream()) { + final String string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); + cmHandles = mapper.readValue(string, CmHandles.class); + } catch (final IOException exception) { + log.error("Error reading the file.", exception); + } + return ResponseEntity.ok(cmHandles); + } + + @Override + public ResponseEntity getCmHandlePublicPropertiesByCmHandleId( + final String cmHandleId) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + @Override + public ResponseEntity> getModuleReferencesByCmHandle(final String cmHandleId) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + /** + * Get resource data from operational datastore. + * + * @param cmHandleId cm handle identifier + * @param resourceIdentifier resource identifier + * @param optionsParamInQuery options query parameter + * @param topicParamInQuery topic query parameter + * @return {@code ResponseEntity} response from dmi plugin + */ + @Override + public ResponseEntity getResourceDataOperationalForCmHandle(final String cmHandleId, + final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery) { + final ResponseEntity> asyncResponse = populateAsyncResponse(topicParamInQuery); + final Map asyncResponseData = asyncResponse.getBody(); + final ObjectMapper mapper = new ObjectMapper(); + Object responseObject = null; + // read JSON file and map/convert to java POJO + final ClassPathResource resource = new ClassPathResource(pathToResponseFiles + + "passthrough-operational-example.json"); + try (InputStream inputStream = resource.getInputStream()) { + final String string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); + responseObject = mapper.readValue(string, Object.class); + } catch (final IOException exception) { + log.error("Error reading the file.", exception); + } + if (asyncResponseData == null) { + return ResponseEntity.ok(responseObject); + } + return ResponseEntity.ok(asyncResponse); + + } + + @Override + public ResponseEntity getResourceDataRunningForCmHandle(final String cmHandleId, + final String resourceIdentifier, final String options, final String topic) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + @Override + public ResponseEntity patchResourceDataRunningForCmHandle(final String resourceIdentifier, + final String cmHandleId, final Object body, final String contentType) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + @Override + public ResponseEntity> queryCmHandles(final CmHandleQueryRestParameters body) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + @Override + public ResponseEntity retrieveCmHandleDetailsById(final String cmHandleId) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + @Override + public ResponseEntity updateResourceDataRunningForCmHandle(@NotNull @Valid final String resourceIdentifier, + final String cmHandleId, @Valid final Object body, final String contentType) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + private ResponseEntity> populateAsyncResponse(final String topicParamInQuery) { + final Map responseData; + if (topicParamInQuery != null) { + responseData = getAsyncResponseData(); + } else { + responseData = null; + } + return ResponseEntity.ok().body(responseData); + } + + private Map getAsyncResponseData() { + final Map asyncResponseData = new HashMap<>(1); + final String resourceDataRequestId = UUID.randomUUID().toString(); + asyncResponseData.put(ASYNC_REQUEST_ID, resourceDataRequestId); + return asyncResponseData; + } +} diff --git a/cps-ncmp-rest-stub/src/main/resources/application.yml b/cps-ncmp-rest-stub/src/main/resources/application.yml new file mode 100644 index 000000000..9fbd35965 --- /dev/null +++ b/cps-ncmp-rest-stub/src/main/resources/application.yml @@ -0,0 +1,39 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2022 Bell Canada +# ================================================================================ +# 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========================================================= +server: + port: 8091 + +rest: + api: + ncmp-stub-base-path: /ncmp + +spring: + main: + banner-mode: "off" + application: + name: "cps-ncmp-rest-stub" + +logging: + level: + org: + springframework: INFO + onap: + cps: INFO + +stub: + path: "/stubs/" \ No newline at end of file diff --git a/cps-ncmp-rest-stub/src/main/resources/stubs/cmHandlesSearch.json b/cps-ncmp-rest-stub/src/main/resources/stubs/cmHandlesSearch.json new file mode 100644 index 000000000..409d56fa4 --- /dev/null +++ b/cps-ncmp-rest-stub/src/main/resources/stubs/cmHandlesSearch.json @@ -0,0 +1,10 @@ +{ + "cmHandles": [ + { + "cmHandleId": "stub-cm-handle-id" + }, + { + "cmHandleId": "stub-cm-handle-id2" + } + ] +} \ No newline at end of file diff --git a/cps-ncmp-rest-stub/src/main/resources/stubs/passthrough-operational-example.json b/cps-ncmp-rest-stub/src/main/resources/stubs/passthrough-operational-example.json new file mode 100644 index 000000000..1838b47ca --- /dev/null +++ b/cps-ncmp-rest-stub/src/main/resources/stubs/passthrough-operational-example.json @@ -0,0 +1,45 @@ +{ + "stores:bookstore": { + "categories": [ + { + "code": "02", + "books": [ + { + "title": "A Horror book", + "price": "2000", + "pub_year": 2003, + "lang": "English", + "authors": [ + "Joe" + ] + }, + { + "title": "Another Horror Book", + "price": "2000", + "pub_year": 2003, + "lang": "English", + "authors": [ + "Joe" + ] + } + ], + "name": "Horror" + }, + { + "code": "100", + "books": [ + { + "title": "A Cook book", + "price": "2011", + "pub_year": 2019, + "lang": "English", + "authors": [ + "Rahul" + ] + } + ], + "name": "Cooking Books" + } + ] + } +} \ No newline at end of file diff --git a/cps-ncmp-rest-stub/src/test/java/org/onap/cps/TestApplication.java b/cps-ncmp-rest-stub/src/test/java/org/onap/cps/TestApplication.java new file mode 100644 index 000000000..a095edc42 --- /dev/null +++ b/cps-ncmp-rest-stub/src/test/java/org/onap/cps/TestApplication.java @@ -0,0 +1,30 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Bell Canada. + * ================================================================================ + * 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; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * The @SpringBootApplication annotated class is required in order to run tests + * marked with @SpringBootTest annotation. + */ +@SpringBootApplication +public class TestApplication { +} diff --git a/jacoco-report/pom.xml b/jacoco-report/pom.xml index b8f18e734..68a9f5555 100644 --- a/jacoco-report/pom.xml +++ b/jacoco-report/pom.xml @@ -70,6 +70,7 @@ org/onap/cps/ncmp/rest/controller/*MapperImpl.class org/onap/cps/rest/controller/*MapperImpl.class org/onap/cps/ncmp/api/impl/async/*MapperImpl.class + org/onap/cps/ncmp/rest/stub/* -- cgit 1.2.3-korg