From ad6021f2d7317b866ca983e355337a740d769c2f Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Wed, 4 Oct 2023 10:05:09 +0100 Subject: Adding NCMP Stubs documentation Issue-ID: CPS-1858 Change-Id: I90017d9d9c6e937292e9de45c0e8228357414e16 Signed-off-by: waqas.ikram --- .../cps-ncmp-rest-stub-service/pom.xml | 31 ++++++++ .../controller/NetworkCmProxyStubController.java | 23 +++--- .../ncmp/rest/stub/SampleCpsNcmpClientSpec.groovy | 82 ++++++++++++++++++++++ .../onap/cps/ncmp/rest/stub/TestApplication.groovy | 28 ++++++++ 4 files changed, 153 insertions(+), 11 deletions(-) create mode 100644 cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/SampleCpsNcmpClientSpec.groovy create mode 100644 cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/TestApplication.groovy (limited to 'cps-ncmp-rest-stub/cps-ncmp-rest-stub-service') diff --git a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/pom.xml b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/pom.xml index 83699b9349..d2cce87977 100644 --- a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/pom.xml +++ b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/pom.xml @@ -46,11 +46,42 @@ org.onap.cps cps-ncmp-rest + + org.eclipse.jetty + jetty-server + + + jakarta.servlet + jakarta.servlet-api + org.spockframework spock-core test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.spockframework + spock-spring + test + + + org.spockframework + spock-core + test + + \ No newline at end of file diff --git a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java index 198b14fc35..e33af45f9b 100644 --- a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java +++ b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java @@ -141,13 +141,13 @@ public class NetworkCmProxyStubController implements NetworkCmProxyApi { } @Override - public ResponseEntity createResourceDataRunningForCmHandle(@NotNull @Valid final String resourceIdentifier, - final String datastoreName, final String cmHandle, - @Valid final Object body, + public ResponseEntity createResourceDataRunningForCmHandle(final String datastoreName, final String cmHandle, + @NotNull @Valid final String resourceIdentifier, + @Valid final Object body, final String contentType) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } - + @Override public ResponseEntity deleteResourceDataRunningForCmHandle(final String datastoreName, final String cmHandle, @NotNull @Valid final String resourceIdentifier, @@ -183,13 +183,13 @@ public class NetworkCmProxyStubController implements NetworkCmProxyApi { } @Override - public ResponseEntity patchResourceDataRunningForCmHandle(@NotNull @Valid final String resourceIdentifier, - final String datastoreName, final String cmHandle, - @Valid final Object body, + public ResponseEntity patchResourceDataRunningForCmHandle(final String datastoreName, final String cmHandle, + @NotNull @Valid final String resourceIdentifier, + @Valid final Object body, final String contentType) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } - + @Override public ResponseEntity queryResourceDataForCmHandle(final String datastoreName, final String cmHandle, @Valid final String cpsPath, @Valid final String options, @@ -218,9 +218,10 @@ public class NetworkCmProxyStubController implements NetworkCmProxyApi { } @Override - public ResponseEntity updateResourceDataRunningForCmHandle(@NotNull @Valid final String resourceIdentifier, - final String datastoreName, - final String cmHandle, @Valid final Object body, + public ResponseEntity updateResourceDataRunningForCmHandle(final String datastoreName, + final String cmHandle, + @NotNull @Valid final String resourceIdentifier, + @Valid final Object body, final String contentType) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); diff --git a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/SampleCpsNcmpClientSpec.groovy b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/SampleCpsNcmpClientSpec.groovy new file mode 100644 index 0000000000..b36e25ada0 --- /dev/null +++ b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/SampleCpsNcmpClientSpec.groovy @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.stub + +import org.onap.cps.ncmp.api.impl.operations.DatastoreType +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.boot.test.context.SpringBootContextLoader +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.boot.test.web.client.TestRestTemplate +import org.springframework.boot.test.web.server.LocalServerPort +import org.springframework.http.HttpStatus +import org.springframework.test.context.ActiveProfiles +import org.springframework.test.context.ContextConfiguration + +import com.fasterxml.jackson.core.JsonProcessingException +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.databind.JsonMappingException +import com.fasterxml.jackson.databind.ObjectMapper + +import spock.lang.Shared +import spock.lang.Specification + +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +class SampleCpsNcmpClientSpec extends Specification { + + static final String CM_HANDLE = "anything" + + static final String DATA_STORE_NAME = DatastoreType.PASSTHROUGH_OPERATIONAL.getDatastoreName() + + @LocalServerPort + def port + + final def testRestTemplate = new TestRestTemplate() + + @Value('${rest.api.ncmp-stub-base-path}') + def stubBasePath + + @Autowired + ObjectMapper objectMapper + + def 'Test the invocation of the stub API' () throws JsonMappingException, JsonProcessingException { + + when: 'Get resource data for cm handle URL is invoked' + def url = "${getBaseUrl()}/v1/ch/${CM_HANDLE}/data/ds/${DATA_STORE_NAME}?resourceIdentifier=parent&options=(a=1,b=2)" + def response = testRestTemplate.getForEntity(url, String.class) + then: 'Response is OK' + response.getStatusCode() == HttpStatus.OK + + and: 'Response body contains customized stub response that contains correct bookstore category code' + def typeRef = new TypeReference>() {} + def map = objectMapper.readValue(response.getBody(), typeRef) + def obj1 = (Map) map.get("stores:bookstore") + def obj2 = (List) obj1.get("categories") + def obj3 = (Map) obj2.iterator().next() + + assert obj3.get("code") == "02" + } + + def String getBaseUrl() { + return "http://localhost:" + port + stubBasePath + } +} diff --git a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/TestApplication.groovy b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/TestApplication.groovy new file mode 100644 index 0000000000..79384239a6 --- /dev/null +++ b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/TestApplication.groovy @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.stub + +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.context.annotation.ComponentScan + +@SpringBootApplication +@ComponentScan(basePackages = ["org.onap.cps.ncmp.rest.stub", "org.onap.cps.ncmp.rest.stub.controller", "org.onap.cps.ncmp.rest.api"]) +class TestApplication { +} -- cgit 1.2.3-korg